mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
Improve default app choice
Parsing it into a HashMap messed up the order. Now it is parsed into a Array.
This commit is contained in:
parent
08774dcf73
commit
f5a78a8e38
1 changed files with 9 additions and 16 deletions
|
@ -12,20 +12,6 @@ import android.os.Bundle
|
||||||
import android.provider.Settings
|
import android.provider.Settings
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
|
||||||
/** Parsing functions */
|
|
||||||
|
|
||||||
// Related question: https://stackoverflow.com/q/3013655/12787264
|
|
||||||
fun parseStringMap(stringArrayResourceId: Int, context: Context): HashMap<String, String>? {
|
|
||||||
val stringArray: Array<String> =
|
|
||||||
context.resources.getStringArray(stringArrayResourceId)
|
|
||||||
val outputArray = HashMap<String, String>(stringArray.size)
|
|
||||||
for (entry in stringArray) {
|
|
||||||
val splitResult = entry.split("|").toTypedArray()
|
|
||||||
outputArray.put(splitResult[0], splitResult[1])
|
|
||||||
}
|
|
||||||
return outputArray
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Activity related */
|
/** Activity related */
|
||||||
|
|
||||||
fun isInstalled(uri: String, context: Context): Boolean {
|
fun isInstalled(uri: String, context: Context): Boolean {
|
||||||
|
@ -150,7 +136,14 @@ fun pickDefaultApp(action: String, context: Context) : Pair<String, String>{
|
||||||
else -> return Pair(context.getString(R.string.none_found), "") // just prevent crashing on unknown input
|
else -> return Pair(context.getString(R.string.none_found), "") // just prevent crashing on unknown input
|
||||||
}
|
}
|
||||||
|
|
||||||
val defaultAppsMap = parseStringMap(arrayResource, context)
|
// Related question: https://stackoverflow.com/q/3013655/12787264 (Adjusted)
|
||||||
for (item in defaultAppsMap!!) if (isInstalled(item.key, context)) return Pair(item.value, item.key)
|
val list = context.resources.getStringArray(arrayResource)
|
||||||
|
for (entry in list!!){
|
||||||
|
val splitResult = entry.split("|").toTypedArray()
|
||||||
|
val pkgname = splitResult[0]
|
||||||
|
val name = splitResult[1]
|
||||||
|
|
||||||
|
if (isInstalled(pkgname, context)) return Pair(name, pkgname)
|
||||||
|
}
|
||||||
return Pair(context.getString(R.string.none_found), "")
|
return Pair(context.getString(R.string.none_found), "")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue