Skip to content

Commit

Permalink
fix: extra activities in main launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
agronick committed May 8, 2024
1 parent ea837fb commit 1097483
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 0 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
Expand All @@ -54,8 +52,6 @@
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/agronick/launcher/AppListProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.io.FileWriter
class AppListProvider(appList: List<PInfo>, context: Context) {

val positions = HashMap<Int, HashMap<Int, PInfo?>>().withDefault { HashMap() }
val filePath = "${context.dataDir}/appPositions2.json"
val filePath = "${context.dataDir}/appPositions.json"
val mapping = appList.map {
it.asKey() to it
}.toMap().toMutableMap()
Expand Down
31 changes: 23 additions & 8 deletions app/src/main/java/com/agronick/launcher/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,36 @@ class MainActivity : Activity(), GestureDetector.OnGestureListener {
private fun getInstalledApps(): List<PInfo> {
val mainIntent = Intent(Intent.ACTION_MAIN, null)
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER)
return packageManager.queryIntentActivities(mainIntent, 0).mapNotNull {
/* This is commented out because the line of code hides both the launcher and settings
application. This bug would need to be fixed before uncommenting */

// if (it.activityInfo.packageName.startsWith("com.agronick.launcher")) {
// return@mapNotNull null
// }
val appName = applicationContext.packageName
val packages = packageManager.queryIntentActivities(mainIntent, 0).mapNotNull {
if (it.activityInfo.packageName == appName) {
return@mapNotNull null
}

PInfo(
appname = it.activityInfo.packageName,
pname = it.activityInfo.packageName,
icon = it.activityInfo.loadIcon(packageManager),
activityName = it.activityInfo.name,
)
}
}.toMutableList()
packages.add(
PInfo(
appname = appName,
pname = appName,
icon = getDrawable(R.mipmap.clock),
activityName = "${appName}.presentation.BackToClock",
)
)
packages.add(
PInfo(
appname = appName,
pname = appName,
icon = getDrawable(R.mipmap.ic_settings),
activityName = "${appName}.presentation.LauncherSettings",
)
)
return packages
}

override fun onSaveInstanceState(outState: Bundle) {
Expand Down

0 comments on commit 1097483

Please sign in to comment.