@@ -152,7 +152,8 @@ fun getNextAlarm(context: Context, prefs: Prefs): CharSequence {
152152 val nextAlarmClock = alarmManager.nextAlarmClock ? : return " No alarm is set."
153153
154154 val alarmTime = nextAlarmClock.triggerTime
155- val timezone = prefs.appLanguage.locale() // Assuming this returns a string like "America/New_York"
155+ val timezone =
156+ prefs.appLanguage.locale() // Assuming this returns a string like "America/New_York"
156157 val formattedDate = DateFormat .getBestDateTimePattern(timezone, " eeeddMMM" )
157158 val best12 = DateFormat .getBestDateTimePattern(
158159 timezone,
@@ -211,7 +212,8 @@ fun ismlauncherDefault(context: Context): Boolean {
211212 val intent = Intent (Intent .ACTION_MAIN ).apply {
212213 addCategory(Intent .CATEGORY_HOME )
213214 }
214- val resolveInfo = context.packageManager.resolveActivity(intent, PackageManager .MATCH_DEFAULT_ONLY )
215+ val resolveInfo =
216+ context.packageManager.resolveActivity(intent, PackageManager .MATCH_DEFAULT_ONLY )
215217 val defaultLauncherPackage = resolveInfo?.activityInfo?.packageName
216218 return context.packageName == defaultLauncherPackage
217219 }
@@ -319,7 +321,8 @@ fun showStatusBar(window: Window) {
319321 window.decorView.let { decorView ->
320322 val flags = decorView.systemUiVisibility and
321323 (View .SYSTEM_UI_FLAG_FULLSCREEN .inv ()) // clear fullscreen flag
322- decorView.systemUiVisibility = flags or View .SYSTEM_UI_FLAG_LAYOUT_STABLE or View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
324+ decorView.systemUiVisibility =
325+ flags or View .SYSTEM_UI_FLAG_LAYOUT_STABLE or View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
323326 }
324327 }
325328}
@@ -360,7 +363,8 @@ fun showNavigationBar(window: Window) {
360363 (window.decorView.let { decorView ->
361364 val flags = decorView.systemUiVisibility and
362365 (View .SYSTEM_UI_FLAG_HIDE_NAVIGATION .inv ()) // clear hide nav flag
363- decorView.systemUiVisibility = flags or View .SYSTEM_UI_FLAG_LAYOUT_STABLE or View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
366+ decorView.systemUiVisibility =
367+ flags or View .SYSTEM_UI_FLAG_LAYOUT_STABLE or View .SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
364368 })
365369 }
366370}
@@ -538,11 +542,17 @@ fun Context.openFirstWeatherApp() {
538542 if (installedKnownApps.isNotEmpty()) {
539543 val intent = pm.getLaunchIntentForPackage(installedKnownApps.first())
540544 if (intent != null ) {
541- AppLogger .d(" WeatherAppLauncher" , " Launching known weather app: ${installedKnownApps.first()} " )
545+ AppLogger .d(
546+ " WeatherAppLauncher" ,
547+ " Launching known weather app: ${installedKnownApps.first()} "
548+ )
542549 this .startActivity(intent)
543550 return
544551 } else {
545- AppLogger .d(" WeatherAppLauncher" , " Launch intent null for: ${installedKnownApps.first()} " )
552+ AppLogger .d(
553+ " WeatherAppLauncher" ,
554+ " Launch intent null for: ${installedKnownApps.first()} "
555+ )
546556 }
547557 } else {
548558 AppLogger .d(" WeatherAppLauncher" , " No known weather apps installed." )
@@ -555,11 +565,17 @@ fun Context.openFirstWeatherApp() {
555565 val packageName = resolvedApps.first().activityInfo.packageName
556566 val intent = pm.getLaunchIntentForPackage(packageName)
557567 if (intent != null ) {
558- AppLogger .d(" WeatherAppLauncher" , " Launching app via generic weather intent: $packageName " )
568+ AppLogger .d(
569+ " WeatherAppLauncher" ,
570+ " Launching app via generic weather intent: $packageName "
571+ )
559572 this .startActivity(intent)
560573 return
561574 } else {
562- AppLogger .d(" WeatherAppLauncher" , " Launch intent null for generic weather app: $packageName " )
575+ AppLogger .d(
576+ " WeatherAppLauncher" ,
577+ " Launch intent null for generic weather app: $packageName "
578+ )
563579 }
564580 } else {
565581 AppLogger .d(" WeatherAppLauncher" , " No apps found via generic weather intent." )
@@ -570,18 +586,27 @@ fun Context.openFirstWeatherApp() {
570586 .filter { app ->
571587 val name = pm.getApplicationLabel(app).toString().lowercase()
572588 val containsWeather = name.contains(" weather" )
573- if (containsWeather) AppLogger .d(" WeatherAppLauncher" , " Found app by name: ${app.packageName} ($name )" )
589+ if (containsWeather) AppLogger .d(
590+ " WeatherAppLauncher" ,
591+ " Found app by name: ${app.packageName} ($name )"
592+ )
574593 containsWeather
575594 }
576595
577596 if (weatherAppsByName.isNotEmpty()) {
578597 val intent = pm.getLaunchIntentForPackage(weatherAppsByName.first().packageName)
579598 if (intent != null ) {
580- AppLogger .d(" WeatherAppLauncher" , " Launching first app found by name: ${weatherAppsByName.first().packageName} " )
599+ AppLogger .d(
600+ " WeatherAppLauncher" ,
601+ " Launching first app found by name: ${weatherAppsByName.first().packageName} "
602+ )
581603 this .startActivity(intent)
582604 return
583605 } else {
584- AppLogger .d(" WeatherAppLauncher" , " Launch intent null for: ${weatherAppsByName.first().packageName} " )
606+ AppLogger .d(
607+ " WeatherAppLauncher" ,
608+ " Launch intent null for: ${weatherAppsByName.first().packageName} "
609+ )
585610 }
586611 } else {
587612 AppLogger .d(" WeatherAppLauncher" , " No apps found by name containing 'weather'." )
@@ -607,7 +632,10 @@ fun Context.openFirstWeatherApp() {
607632 val intent = Intent (Intent .ACTION_VIEW , url.toUri())
608633 this .startActivity(intent)
609634
610- AppLogger .d(" WeatherAppLauncher" , " Opened weather.com for coordinates: $lat ,$lon with unit: $unitParam " )
635+ AppLogger .d(
636+ " WeatherAppLauncher" ,
637+ " Opened weather.com for coordinates: $lat ,$lon with unit: $unitParam "
638+ )
611639 } else {
612640 AppLogger .d(" WeatherAppLauncher" , " No coordinates found in prefs." )
613641 }
@@ -616,7 +644,7 @@ fun Context.openFirstWeatherApp() {
616644
617645
618646fun formatLongToCalendar (longTimestamp : Long ): String {
619- // Create a Calendar instance and set its time to the given timestamp (in milliseconds)
647+ // Create a Calendar instance and set it's time to the given timestamp (in milliseconds)
620648 val calendar = Calendar .getInstance().apply {
621649 timeInMillis = longTimestamp
622650 }
@@ -750,51 +778,77 @@ fun getDeviceInfoJson(context: Context): String {
750778 }
751779}
752780
753- fun getInstallSource (packageManager : PackageManager , packageName : String ): String {
754- try {
781+ fun getInstallSource (
782+ packageManager : PackageManager ,
783+ packageName : String
784+ ): String {
785+ return try {
755786 val installer = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
756- // For API level 30 and above
757- packageManager.getInstallSourceInfo(packageName).installingPackageName ? : " Unknown"
787+ packageManager
788+ .getInstallSourceInfo(packageName)
789+ .installingPackageName
758790 } else {
759- // For below API level 30
760791 @Suppress(" DEPRECATION" )
761- packageManager.getInstallerPackageName(packageName) ? : " Unknown "
792+ packageManager.getInstallerPackageName(packageName)
762793 }
763794
764- return when (installer) {
765- " com.android.vending" -> " Google Play Store"
766- " org.fdroid.fdroid" -> " F-Droid"
767- " dev.imranr.obtainium" -> " Obtanium"
768- " com.amazon.venezia" -> " Amazon Appstore"
769- " com.sec.android.app.samsungapps" -> " Samsung Galaxy Store"
770- " com.huawei.appmarket" -> " Huawei AppGallery"
771- " com.xiaomi.market" -> " Xiaomi GetApps"
772- " com.oppo.market" -> " OPPO App Market"
773- " com.vivo.appstore" -> " Vivo App Store"
774- " com.oneplus.mstore" -> " OnePlus Store"
775- " com.android.shell" -> " Android Studio (ADB)"
776-
777- // Popular browsers
778- " com.android.chrome" -> " Chrome"
779- " org.mozilla.firefox" -> " Firefox"
780- " com.brave.browser" -> " Brave"
781- " com.microsoft.emmx" -> " Edge"
782- " com.opera.browser" -> " Opera"
783- " com.sec.android.app.sbrowser" -> " Samsung Internet"
784-
785- // Popular file managers
786- " com.google.android.documentsui" -> " Files by Google"
787- " com.samsung.android.myfiles" -> " Samsung My Files"
788- " com.mi.android.globalFileexplorer" -> " Xiaomi File Manager"
789- " com.asus.filemanager" -> " ASUS File Manager"
790- " com.lonelycatgames.Xplore" -> " X-plore File Manager"
791- " nextapp.fx" -> " FX File Explorer"
792- " com.amazon.filemanager" -> " Amazon File Manager"
793-
794- else -> " Unknown"
795+ when (installer) {
796+ " com.android.vending" ->
797+ " Google Play Store"
798+
799+ " com.android.shell" ->
800+ " ADB / Android Studio"
801+
802+ " org.fdroid.fdroid" ->
803+ " F-Droid"
804+
805+ " dev.imranr.obtainium" ->
806+ " Obtainium"
807+
808+ " com.amazon.venezia" ->
809+ " Amazon Appstore"
810+
811+ " com.sec.android.app.samsungapps" ->
812+ " Samsung Galaxy Store"
813+
814+ " com.huawei.appmarket" ->
815+ " Huawei AppGallery"
816+
817+ " com.xiaomi.market" ->
818+ " Xiaomi GetApps"
819+
820+ " com.oppo.market" ->
821+ " OPPO App Market"
822+
823+ " com.vivo.appstore" ->
824+ " Vivo App Store"
825+
826+ else ->
827+ installer ? : " Unknown"
795828 }
829+
796830 } catch (_: Exception ) {
797- return " Unknown"
831+ " Unknown"
832+ }
833+ }
834+
835+ fun isInstalledFromGooglePlay (context : Context , packageName : String ): Boolean {
836+ return try {
837+ val pm = context.packageManager
838+ val packageInfo = pm.getPackageInfo(packageName, 0 )
839+
840+ val installer = if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .R ) {
841+ pm.getInstallSourceInfo(packageName).installingPackageName
842+ } else {
843+ @Suppress(" DEPRECATION" )
844+ pm.getInstallerPackageName(packageName)
845+ }
846+
847+ packageInfo.applicationInfo != null &&
848+ installer == " com.android.vending"
849+
850+ } catch (_: PackageManager .NameNotFoundException ) {
851+ false
798852 }
799853}
800854
@@ -842,7 +896,10 @@ fun updateWordWidget(context: Context) {
842896
843897fun updateFabWidget (context : Context ) {
844898 val appWidgetManager = AppWidgetManager .getInstance(context)
845- val componentName = ComponentName (context, HomeAppsWidgetProvider ::class .java) // Replace with your FAB widget class
899+ val componentName = ComponentName (
900+ context,
901+ HomeAppsWidgetProvider ::class .java
902+ ) // Replace with your FAB widget class
846903 val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
847904
848905 val intent = Intent (context, HomeAppsWidgetProvider ::class .java).apply {
0 commit comments