Skip to content

Commit

Permalink
Improve default apply error message
Browse files Browse the repository at this point in the history
  • Loading branch information
jahirfiquitiva committed Feb 27, 2023
1 parent 126d29d commit 0021801
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ object SendIconRequest {
it.delete()
}
}
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand Down Expand Up @@ -266,12 +266,8 @@ object SendIconRequest {

val date = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date()).clean()

val (textFiles, jsonContent) = buildTextFiles(
context,
correctList,
date,
uploadToRequestManager
)
val (textFiles, jsonContent) =
buildTextFiles(context, correctList, date, uploadToRequestManager)
emailZipFiles.addAll(textFiles)

val zipFile = buildZipFile(date, requestLocation, emailZipFiles)
Expand Down Expand Up @@ -379,21 +375,14 @@ object SendIconRequest {
val apiKey = activity.string(R.string.request_manager_backend_api_key)
val uploadToRequestManager = apiKey.hasContent()

val (zipFile, jsonContent) = zipFiles(
activity,
selectedApps,
uploadToRequestManager
)
val (zipFile, jsonContent) =
zipFiles(activity, selectedApps, uploadToRequestManager)
cleanFiles(activity)

if (uploadToRequestManager) {
val baseUrl = activity.string(R.string.request_manager_base_url)
val (succeeded, message) = uploadToRequestManager(
zipFile,
jsonContent,
apiKey,
baseUrl
)
val (succeeded, message) =
uploadToRequestManager(zipFile, jsonContent, apiKey, baseUrl)
if (succeeded) theCallback.onRequestUploadFinished(true)
else theCallback.onRequestError(message)

Expand All @@ -405,9 +394,9 @@ object SendIconRequest {
theCallback.onRequestLimited(state, true)
requestInProgress = false
}
} ?: {
} ?: run {
theCallback.onRequestError()
requestInProgress = false
}()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) {
isInstalled = context.isAppInstalled(packageName)
intent =
context.packageManager.getLaunchIntentForPackage(packageName)
} catch (e: Exception) {
} catch (_: Exception) {
}
if (intent == null && isMarketUrl) {
intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$packageName")
)
intent =
Intent(
Intent.ACTION_VIEW,
Uri.parse("market://details?id=$packageName")
)
}
}
val openIcon = if (isAnApp)
Expand Down
72 changes: 42 additions & 30 deletions library/src/main/kotlin/dev/jahir/blueprint/extensions/Launchers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import dev.jahir.blueprint.R
import dev.jahir.blueprint.data.models.Launcher
import dev.jahir.frames.extensions.context.getAppName
import dev.jahir.frames.extensions.context.openLink
import dev.jahir.frames.extensions.context.string
import dev.jahir.frames.extensions.fragments.mdDialog
import dev.jahir.frames.extensions.fragments.message
import dev.jahir.frames.extensions.fragments.negativeButton
Expand Down Expand Up @@ -59,7 +60,7 @@ private fun Context.executeIconPacksNotSupportedIntent() {
}
negativeButton(android.R.string.cancel)
}.show()
} catch (e: Exception) {
} catch (_: Exception) {
}
}

Expand All @@ -73,31 +74,42 @@ internal fun Context.showLauncherNotInstalledDialog(launcher: Launcher) {
}
negativeButton(android.R.string.cancel)
}.show()
} catch (e: Exception) {
} catch (_: Exception) {
}
}

private fun Context.showLauncherApplyError(customContent: String? = null) {
private fun Context.showLauncherApplyError(
launcher: Launcher? = null,
customContent: String? = null
) {
try {
mdDialog {
title(R.string.error)
message(customContent ?: getString(R.string.coming_soon))
message(
customContent ?: launcher?.cleanAppName?.let {
string(R.string.direct_apply_not_supported, it, getAppName())
} ?: getString(R.string.coming_soon))
positiveButton(android.R.string.ok)
}.show()
} catch (e: Exception) {
} catch (_: Exception) {
}
}

private fun Context.attemptApply(customContent: String? = null, intent: (() -> Intent?)? = null) {
private fun Context.attemptApply(
launcher: Launcher?,
customContent: String? = null,
intent: (() -> Intent?)? = null
) {
try {
intent?.invoke()?.let { startActivity(it) } ?: showLauncherApplyError(customContent)
intent?.invoke()?.let { startActivity(it) }
?: showLauncherApplyError(launcher, customContent)
} catch (e: Exception) {
showLauncherApplyError(customContent)
showLauncherApplyError(launcher, customContent)
}
}

private fun Context.executeActionLauncherIntent() {
attemptApply {
attemptApply(Launcher.ACTION) {
packageManager
.getLaunchIntentForPackage("com.actionlauncher.playstore")?.apply {
putExtra("apply_icon_pack", packageName)
Expand All @@ -106,7 +118,7 @@ private fun Context.executeActionLauncherIntent() {
}

private fun Context.executeAdwLauncherIntent() {
attemptApply {
attemptApply(Launcher.ADW) {
Intent("org.adw.launcher.SET_THEME").apply {
putExtra("org.adw.launcher.theme.NAME", packageName)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -115,7 +127,7 @@ private fun Context.executeAdwLauncherIntent() {
}

private fun Context.executeAdwEXLauncherIntent() {
attemptApply {
attemptApply(Launcher.ADW_EX) {
Intent("org.adwfreak.launcher.SET_THEME").apply {
putExtra("org.adwfreak.launcher.theme.NAME", packageName)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -124,7 +136,7 @@ private fun Context.executeAdwEXLauncherIntent() {
}

private fun Context.executeApexLauncherIntent() {
attemptApply {
attemptApply(Launcher.APEX) {
Intent("com.anddoes.launcher.SET_THEME").apply {
putExtra("com.anddoes.launcher.THEME_PACKAGE_NAME", packageName)
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
Expand All @@ -133,7 +145,7 @@ private fun Context.executeApexLauncherIntent() {
}

private fun Context.executeGoLauncherIntent() {
attemptApply {
attemptApply(Launcher.GO) {
packageManager.getLaunchIntentForPackage("com.gau.go.launcherex").also {
val go = Intent("com.gau.go.launcherex.MyThemes.mythemeaction")
go.putExtra("type", 1)
Expand All @@ -144,15 +156,15 @@ private fun Context.executeGoLauncherIntent() {
}

private fun Context.executeHoloLauncherIntent() {
attemptApply {
attemptApply(Launcher.HOLO) {
Intent(Intent.ACTION_MAIN).apply {
component = ComponentName("com.mobint.hololauncher", "com.mobint.hololauncher.Settings")
}
}
}

private fun Context.executeHoloLauncherICSIntent() {
attemptApply {
attemptApply(Launcher.HOLO_ICS) {
Intent(Intent.ACTION_MAIN).apply {
component = ComponentName(
"com.mobint.hololauncher.hd", "com.mobint.hololauncher.SettingsActivity"
Expand All @@ -162,7 +174,7 @@ private fun Context.executeHoloLauncherICSIntent() {
}

private fun Context.executeLgHomeLauncherIntent() {
attemptApply {
attemptApply(Launcher.LG_HOME) {
Intent(Intent.ACTION_MAIN).apply {
component = ComponentName(
"com.lge.launcher2",
Expand All @@ -173,7 +185,7 @@ private fun Context.executeLgHomeLauncherIntent() {
}

private fun Context.executeLawnchairIntent() {
attemptApply {
attemptApply(Launcher.LAWNCHAIR) {
Intent("ch.deletescape.lawnchair.APPLY_ICONS", null).apply {
putExtra("packageName", packageName)
}
Expand All @@ -186,6 +198,7 @@ private fun Context.executeLineageOSThemeEngineIntent() {
isAppInstalled("com.cyngn.theme.chooser")

attemptApply(
Launcher.LINEAGE_OS,
if (themesAppInstalled) getString(R.string.impossible_open_themes)
else getString(R.string.themes_app_not_installed)
) {
Expand Down Expand Up @@ -217,15 +230,15 @@ private fun Context.executeLineageOSThemeEngineIntent() {
}

private fun Context.executeLucidLauncherIntent() {
attemptApply {
attemptApply(Launcher.LUCID) {
Intent("com.powerpoint45.action.APPLY_THEME", null).apply {
putExtra("icontheme", packageName)
}
}
}

private fun Context.executeNiagaraLauncherIntent() {
attemptApply {
attemptApply(Launcher.NIAGARA) {
Intent("bitpit.launcher.APPLY_ICONS").apply {
`package` = "bitpit.launcher"
putExtra("packageName", packageName)
Expand All @@ -234,7 +247,7 @@ private fun Context.executeNiagaraLauncherIntent() {
}

private fun Context.executeNovaLauncherIntent() {
attemptApply {
attemptApply(Launcher.NOVA) {
Intent("com.teslacoilsw.launcher.APPLY_ICON_THEME").apply {
`package` = "com.teslacoilsw.launcher"
putExtra("com.teslacoilsw.launcher.extra.ICON_THEME_TYPE", "GO")
Expand All @@ -245,7 +258,7 @@ private fun Context.executeNovaLauncherIntent() {
}

private fun Context.executeOnePlusLauncherIntent() {
attemptApply {
attemptApply(Launcher.ONEPLUS) {
Intent().apply {
component = ComponentName(
"net.oneplus.launcher",
Expand All @@ -256,7 +269,7 @@ private fun Context.executeOnePlusLauncherIntent() {
}

private fun Context.executePosidonLauncherIntent() {
attemptApply {
attemptApply(Launcher.POSIDON) {
Intent(Intent.ACTION_MAIN).apply {
component = ComponentName("posidon.launcher", "posidon.launcher.external.ApplyIcons")
putExtra("iconpack", packageName)
Expand All @@ -265,23 +278,23 @@ private fun Context.executePosidonLauncherIntent() {
}

private fun Context.executeSmartLauncherIntent() {
attemptApply {
attemptApply(Launcher.SMART) {
Intent("ginlemon.smartlauncher.setGSLTHEME").apply {
putExtra("package", packageName)
}
}
}

private fun Context.executeSmartLauncherProIntent() {
attemptApply {
attemptApply(Launcher.SMART_PRO) {
Intent("ginlemon.smartlauncher.setGSLTHEME").apply {
putExtra("package", packageName)
}
}
}

private fun Context.executeSoloLauncherIntent() {
attemptApply {
attemptApply(Launcher.SOLO) {
packageManager.getLaunchIntentForPackage("home.solo.launcher.free").also {
val solo = Intent("home.solo.launcher.free.APPLY_THEME")
solo.putExtra("EXTRA_PACKAGENAME", packageName)
Expand All @@ -292,7 +305,7 @@ private fun Context.executeSoloLauncherIntent() {
}

private fun Context.executeSquareHomeIntent() {
attemptApply {
attemptApply(Launcher.SQUARE) {
Intent("com.ss.squarehome2.ACTION_APPLY_ICONPACK").apply {
component =
ComponentName.unflattenFromString("com.ss.squarehome2/.ApplyThemeActivity")
Expand All @@ -302,7 +315,7 @@ private fun Context.executeSquareHomeIntent() {
}

private fun Context.executeTsfLauncherIntent() {
attemptApply {
attemptApply(Launcher.TSF) {
packageManager.getLaunchIntentForPackage("com.tsf.shell").also {
val tsf = Intent("android.action.MAIN")
tsf.component = ComponentName("com.tsf.shell", "com.tsf.shelShellActivity")
Expand All @@ -312,7 +325,7 @@ private fun Context.executeTsfLauncherIntent() {
}

private fun Context.executeMotoLauncherIntent() {
attemptApply {
attemptApply(Launcher.MOTO) {
Intent().apply {
component = ComponentName(
"com.motorola.personalize",
Expand All @@ -326,8 +339,7 @@ private fun Context.executeMotoLauncherIntent() {
internal val Context.defaultLauncher: Launcher?
get() = try {
val intent = Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_HOME)
val resolveInfo =
packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
val resolveInfo = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY)
val launcherPackage = resolveInfo?.activityInfo?.packageName
Launcher.getSupportedLaunchers(this)
.filter { it.first.isActuallySupported }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="impossible_open_themes">No se puede abrir la aplicación</string>
<string name="themes_app_not_installed">“Temas” no está instalado.</string>
<string name="coming_soon">Proximamente.</string>
<string name="direct_apply_not_supported">%1$s no soporta aplicar íconos directamente. Por favor intenta aplicar %2$s manualmente desde la configuración del launcher.</string>
<string name="quick_apply">Aplicar al inicio</string>
<string name="request_x_icons">Solicitar %1$s iconos</string>
<string name="request_icon">Solicitar icono</string>
Expand Down
1 change: 1 addition & 0 deletions library/src/main/res/values/translatable_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<string name="impossible_open_themes">Can’t Open App</string>
<string name="themes_app_not_installed">“Themes” isn’t installed.</string>
<string name="coming_soon">Coming soon.</string>
<string name="direct_apply_not_supported">%1$s does not support applying icons directly. Please try to apply %2$s manually from the launcher settings.</string>
<string name="quick_apply">Apply to Home</string>
<string name="request_x_icons">Request %1$s Icons</string>
<string name="request_icon">Request Icon</string>
Expand Down

0 comments on commit 0021801

Please sign in to comment.