adding Thank You + improving handling of invalid packages
@ -11,6 +11,7 @@ import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||
import com.simplemobiletools.applauncher.dialogs.AddAppDialog
|
||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||
import com.simplemobiletools.applauncher.extensions.isAPredefinedApp
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.checkWhatsNew
|
||||
import com.simplemobiletools.commons.extensions.updateTextColors
|
||||
@ -23,7 +24,6 @@ import java.util.*
|
||||
|
||||
class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
||||
private var launchers = ArrayList<AppLauncher>()
|
||||
private var remainingLaunchers = ArrayList<AppLauncher>()
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -70,18 +70,16 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
||||
launchers = dbHelper.getLaunchers()
|
||||
checkInvalidApps()
|
||||
launchers_holder.adapter = RecyclerAdapter(this, launchers, this) {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(it.pkgName)
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(it.packageName)
|
||||
if (launchIntent != null) {
|
||||
startActivity(launchIntent)
|
||||
finish()
|
||||
} else {
|
||||
val url = "https://play.google.com/store/apps/details?id=${it.pkgName}"
|
||||
val url = "https://play.google.com/store/apps/details?id=${it.packageName}"
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
remainingLaunchers = getNotDisplayedLaunchers()
|
||||
}
|
||||
|
||||
private fun getNotDisplayedLaunchers(): ArrayList<AppLauncher> {
|
||||
@ -92,21 +90,20 @@ class MainActivity : SimpleActivity(), RecyclerAdapter.AppLaunchersListener {
|
||||
for (info in list) {
|
||||
val componentInfo = info.activityInfo.applicationInfo
|
||||
val label = componentInfo.loadLabel(packageManager).toString()
|
||||
val pkgName = componentInfo.packageName
|
||||
allApps.add(AppLauncher(0, label, pkgName, 0))
|
||||
allApps.add(AppLauncher(0, label, componentInfo.packageName))
|
||||
}
|
||||
|
||||
val sorted = allApps.sortedWith(compareBy { it.name.toLowerCase() })
|
||||
val unique = sorted.distinctBy { it.pkgName }
|
||||
val filtered = unique.filter { !launchers.contains(it) }
|
||||
val unique = sorted.distinctBy { it.packageName }
|
||||
val filtered = unique.filter { !launchers.contains(it) && it.packageName != "com.simplemobiletools.applauncher" }
|
||||
return filtered as ArrayList<AppLauncher>
|
||||
}
|
||||
|
||||
private fun checkInvalidApps() {
|
||||
val invalidIds = ArrayList<String>()
|
||||
for ((id, name, pkgName) in launchers) {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(pkgName)
|
||||
if (launchIntent == null && !pkgName.startsWith("com.simplemobiletools")) {
|
||||
for ((id, name, packageName) in launchers) {
|
||||
val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
|
||||
if (launchIntent == null && !packageName.isAPredefinedApp()) {
|
||||
invalidIds.add(id.toString())
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.activities.SimpleActivity
|
||||
import com.simplemobiletools.applauncher.extensions.config
|
||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||
import com.simplemobiletools.applauncher.extensions.getLauncherDrawable
|
||||
import com.simplemobiletools.applauncher.extensions.isAPredefinedApp
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
@ -165,7 +167,7 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List<AppLaunc
|
||||
|
||||
private fun getRealAppName(launcher: AppLauncher): String {
|
||||
return try {
|
||||
val applicationInfo = activity.packageManager.getApplicationInfo(launcher.pkgName, 0)
|
||||
val applicationInfo = activity.packageManager.getApplicationInfo(launcher.packageName, 0)
|
||||
activity.packageManager.getApplicationLabel(applicationInfo).toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
""
|
||||
@ -182,10 +184,10 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List<AppLaunc
|
||||
setOnClickListener { viewClicked(launcher) }
|
||||
setOnLongClickListener { viewLongClicked(); true }
|
||||
|
||||
val drawable = if (launcher.iconId != 0) {
|
||||
resources.getDrawable(launcher.iconId)
|
||||
val drawable = if (launcher.packageName.isAPredefinedApp()) {
|
||||
resources.getLauncherDrawable(launcher.packageName)
|
||||
} else {
|
||||
packageManager.getApplicationIcon(launcher.pkgName)
|
||||
packageManager.getApplicationIcon(launcher.packageName)
|
||||
}
|
||||
launcher_icon.setImageDrawable(drawable)
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.extensions.config
|
||||
import com.simplemobiletools.applauncher.extensions.getLauncherDrawable
|
||||
import com.simplemobiletools.applauncher.extensions.isAPredefinedApp
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
@ -67,10 +69,10 @@ class RecyclerDialogAdapter(activity: Activity, val launchers: List<AppLauncher>
|
||||
setOnClickListener { viewClicked() }
|
||||
setOnLongClickListener { viewClicked(); true }
|
||||
|
||||
val drawable = if (launcher.iconId != 0) {
|
||||
resources.getDrawable(launcher.iconId)
|
||||
val drawable = if (launcher.packageName.isAPredefinedApp()) {
|
||||
resources.getLauncherDrawable(launcher.packageName)
|
||||
} else {
|
||||
packageManager.getApplicationIcon(launcher.pkgName)
|
||||
packageManager.getApplicationIcon(launcher.packageName)
|
||||
}
|
||||
launcher_icon.setImageDrawable(drawable)
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.simplemobiletools.applauncher.extensions
|
||||
|
||||
import android.content.res.Resources
|
||||
import android.graphics.drawable.Drawable
|
||||
import com.simplemobiletools.applauncher.R
|
||||
|
||||
fun Resources.getLauncherDrawable(packageName: String): Drawable {
|
||||
return getDrawable(when (packageName) {
|
||||
"com.simplemobiletools.calculator" -> R.drawable.ic_launcher_calculator
|
||||
"com.simplemobiletools.calendar" -> R.drawable.ic_launcher_calendar
|
||||
"com.simplemobiletools.camera" -> R.drawable.ic_launcher_camera
|
||||
"com.simplemobiletools.draw" -> R.drawable.ic_launcher_draw
|
||||
"com.simplemobiletools.filemanager" -> R.drawable.ic_launcher_filemanager
|
||||
"com.simplemobiletools.flashlight" -> R.drawable.ic_launcher_flashlight
|
||||
"com.simplemobiletools.gallery" -> R.drawable.ic_launcher_gallery
|
||||
"com.simplemobiletools.musicplayer" -> R.drawable.ic_launcher_musicplayer
|
||||
"com.simplemobiletools.notes" -> R.drawable.ic_launcher_notes
|
||||
"com.simplemobiletools.thankyou" -> R.drawable.ic_launcher_thankyou
|
||||
else -> throw RuntimeException("Invalid launcher package name $packageName")
|
||||
})
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.simplemobiletools.applauncher.extensions
|
||||
|
||||
import com.simplemobiletools.applauncher.helpers.predefinedPackageNames
|
||||
|
||||
// treat apps like "com.simplemobiletools.notes.debug" as any third party app
|
||||
fun String.isAPredefinedApp() = predefinedPackageNames.contains(this)
|
@ -0,0 +1,14 @@
|
||||
package com.simplemobiletools.applauncher.helpers
|
||||
|
||||
val predefinedPackageNames = arrayListOf(
|
||||
"com.simplemobiletools.calculator",
|
||||
"com.simplemobiletools.calendar",
|
||||
"com.simplemobiletools.camera",
|
||||
"com.simplemobiletools.draw",
|
||||
"com.simplemobiletools.filemanager",
|
||||
"com.simplemobiletools.flashlight",
|
||||
"com.simplemobiletools.gallery",
|
||||
"com.simplemobiletools.musicplayer",
|
||||
"com.simplemobiletools.notes",
|
||||
"com.simplemobiletools.thankyou"
|
||||
)
|
@ -5,7 +5,6 @@ import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.getIntValue
|
||||
@ -17,7 +16,6 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
private val COL_ID = "id"
|
||||
private val COL_NAME = "name"
|
||||
private val COL_PKG_NAME = "pkgName"
|
||||
private val COL_ICON_ID = "icon"
|
||||
private val COL_POSITION = "position"
|
||||
|
||||
private val mDb = writableDatabase
|
||||
@ -36,14 +34,11 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
}
|
||||
|
||||
override fun onCreate(db: SQLiteDatabase) {
|
||||
Log.e("DEBUG", "create")
|
||||
db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_NAME TEXT, $COL_PKG_NAME TEXT UNIQUE, " +
|
||||
"$COL_ICON_ID INTEGER, $COL_POSITION INTEGER)")
|
||||
db.execSQL("CREATE TABLE $MAIN_TABLE_NAME ($COL_ID INTEGER PRIMARY KEY AUTOINCREMENT, $COL_NAME TEXT, $COL_PKG_NAME TEXT UNIQUE, $COL_POSITION INTEGER)")
|
||||
addInitialLaunchers(db)
|
||||
}
|
||||
|
||||
override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
||||
Log.e("DEBUG", "upgrade")
|
||||
}
|
||||
|
||||
private fun addInitialLaunchers(db: SQLiteDatabase) {
|
||||
@ -56,37 +51,15 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
R.string.flashlight,
|
||||
R.string.gallery,
|
||||
R.string.music_player,
|
||||
R.string.notes
|
||||
)
|
||||
|
||||
val packages = arrayListOf(
|
||||
"calculator",
|
||||
"calendar",
|
||||
"camera",
|
||||
"draw",
|
||||
"filemanager",
|
||||
"flashlight",
|
||||
"gallery",
|
||||
"musicplayer",
|
||||
"notes"
|
||||
)
|
||||
|
||||
val icons = arrayListOf(
|
||||
R.drawable.ic_launcher_calculator,
|
||||
R.drawable.ic_launcher_calendar,
|
||||
R.drawable.ic_launcher_camera,
|
||||
R.drawable.ic_launcher_draw,
|
||||
R.drawable.ic_launcher_filemanager,
|
||||
R.drawable.ic_launcher_flashlight,
|
||||
R.drawable.ic_launcher_gallery,
|
||||
R.drawable.ic_launcher_musicplayer,
|
||||
R.drawable.ic_launcher_notes
|
||||
R.string.notes,
|
||||
R.string.thank_you
|
||||
)
|
||||
|
||||
val cnt = titles.size
|
||||
val resources = context.resources
|
||||
val packages = predefinedPackageNames
|
||||
for (i in 0 until cnt) {
|
||||
val appLauncher = AppLauncher(0, resources.getString(titles[i]), "com.simplemobiletools.${packages[i]}", icons[i])
|
||||
val appLauncher = AppLauncher(0, resources.getString(titles[i]), packages[i])
|
||||
addAppLauncher(appLauncher, db)
|
||||
}
|
||||
}
|
||||
@ -103,8 +76,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
private fun fillAppLauncherValues(appLauncher: AppLauncher): ContentValues {
|
||||
return ContentValues().apply {
|
||||
put(COL_NAME, appLauncher.name)
|
||||
put(COL_PKG_NAME, appLauncher.pkgName)
|
||||
put(COL_ICON_ID, appLauncher.iconId)
|
||||
put(COL_PKG_NAME, appLauncher.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,15 +96,14 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
|
||||
fun getLaunchers(): ArrayList<AppLauncher> {
|
||||
val launchers = ArrayList<AppLauncher>()
|
||||
val cols = arrayOf(COL_ID, COL_NAME, COL_PKG_NAME, COL_ICON_ID)
|
||||
val cols = arrayOf(COL_ID, COL_NAME, COL_PKG_NAME)
|
||||
val cursor = mDb.query(MAIN_TABLE_NAME, cols, null, null, null, null, COL_NAME)
|
||||
cursor.use {
|
||||
while (cursor.moveToNext()) {
|
||||
val id = cursor.getIntValue(COL_ID)
|
||||
val name = cursor.getStringValue(COL_NAME)
|
||||
val pkgName = cursor.getStringValue(COL_PKG_NAME)
|
||||
val icon = cursor.getIntValue(COL_ICON_ID)
|
||||
val launcher = AppLauncher(id, name, pkgName, icon)
|
||||
val launcher = AppLauncher(id, name, pkgName)
|
||||
launchers.add(launcher)
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package com.simplemobiletools.applauncher.models
|
||||
|
||||
data class AppLauncher(val id: Int, var name: String, val pkgName: String, val iconId: Int) {
|
||||
data class AppLauncher(val id: Int, var name: String, val packageName: String) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return pkgName.equals((other as AppLauncher).pkgName, true)
|
||||
return packageName.equals((other as AppLauncher).packageName, true)
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.3 KiB |
BIN
app/src/main/res/drawable-hdpi/ic_launcher_thankyou.png
Normal file
After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.4 KiB |
BIN
app/src/main/res/drawable-xhdpi/ic_launcher_thankyou.png
Normal file
After Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.2 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_launcher_thankyou.png
Normal file
After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 2.4 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_launcher_thankyou.png
Normal file
After Width: | Height: | Size: 3.9 KiB |
@ -13,6 +13,7 @@
|
||||
<string name="gallery">Galerie</string>
|
||||
<string name="music_player">Musikplayer</string>
|
||||
<string name="notes">Notizblock</string>
|
||||
<string name="thank_you">Thank You</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="gallery">Galería</string>
|
||||
<string name="music_player">Reproductor de música</string>
|
||||
<string name="notes">Notas</string>
|
||||
<string name="thank_you">Thank You</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="gallery">ギャラリー</string>
|
||||
<string name="music_player">ミュージック プレイヤー</string>
|
||||
<string name="notes">メモ</string>
|
||||
<string name="thank_you">Thank You</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="gallery">Galeria</string>
|
||||
<string name="music_player">Odtwarzacz Muzyki</string>
|
||||
<string name="notes">Notatki</string>
|
||||
<string name="thank_you">Thank You</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="gallery">Galeria</string>
|
||||
<string name="music_player">Reprodutor de músicas</string>
|
||||
<string name="notes">Notas</string>
|
||||
<string name="thank_you">Thank You</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|
@ -13,6 +13,7 @@
|
||||
<string name="gallery">Gallery</string>
|
||||
<string name="music_player">Music Player</string>
|
||||
<string name="notes">Notes</string>
|
||||
<string name="thank_you">Thank You</string>
|
||||
|
||||
<!-- Strings displayed only on Google Playstore. Optional, but good to have -->
|
||||
<!-- Short description has to have less than 80 chars -->
|
||||
|