mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-04-17 03:17:24 +02:00
do not display the already added launchers
This commit is contained in:
parent
cf0405b9c5
commit
1b17e70fcb
@ -30,6 +30,7 @@ dependencies {
|
||||
compile 'com.android.support:appcompat-v7:23.4.0'
|
||||
compile 'com.android.support:recyclerview-v7:23.4.0'
|
||||
compile 'com.android.support:design:23.4.0'
|
||||
compile 'com.google.code.gson:gson:2.7'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.simplemobiletools.applauncher.activities
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import com.google.gson.Gson
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||
import com.simplemobiletools.applauncher.databases.DbHelper
|
||||
@ -14,10 +16,12 @@ import com.simplemobiletools.applauncher.extensions.viewIntent
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.activity_main.*
|
||||
import java.util.*
|
||||
import kotlin.comparisons.compareBy
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
lateinit var dbHelper: DbHelper
|
||||
lateinit var launchers: ArrayList<AppLauncher>
|
||||
lateinit var remainingLaunchers: ArrayList<AppLauncher>
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -33,8 +37,14 @@ class MainActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
remainingLaunchers = getNotDisplayedLaunchers()
|
||||
|
||||
fab.setOnClickListener {
|
||||
AddAppDialog().show(fragmentManager, "")
|
||||
val dialog = AddAppDialog()
|
||||
val args = Bundle()
|
||||
args.putString(dialog.LAUNCHERS, Gson().toJson(remainingLaunchers))
|
||||
dialog.arguments = args
|
||||
dialog.show(fragmentManager, "")
|
||||
}
|
||||
}
|
||||
|
||||
@ -57,6 +67,24 @@ class MainActivity : SimpleActivity() {
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun getNotDisplayedLaunchers(): ArrayList<AppLauncher> {
|
||||
val apps = ArrayList<AppLauncher>()
|
||||
val intent = Intent(Intent.ACTION_MAIN, null)
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||
for (info in list) {
|
||||
val componentInfo = info.activityInfo.applicationInfo
|
||||
val label = componentInfo.loadLabel(packageManager).toString()
|
||||
val pkgName = componentInfo.packageName
|
||||
apps.add(AppLauncher(label, pkgName, 0))
|
||||
}
|
||||
|
||||
val sorted = apps.sortedWith(compareBy { it.name.toLowerCase() })
|
||||
val unique = sorted.distinctBy { it.pkgName }
|
||||
val filtered = unique.filter { !launchers.contains(it) }
|
||||
return filtered as ArrayList<AppLauncher>
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
preferences.isFirstRun = false
|
||||
|
@ -12,7 +12,6 @@ import com.simplemobiletools.applauncher.extensions.show
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.*
|
||||
|
||||
|
||||
class RecyclerAdapter(val cxt: Context, val displayChecks: Boolean, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
|
||||
RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {
|
||||
|
||||
|
@ -2,25 +2,34 @@ package com.simplemobiletools.applauncher.dialogs
|
||||
|
||||
import android.app.Dialog
|
||||
import android.app.DialogFragment
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.launcher_picker.view.*
|
||||
import java.util.*
|
||||
import kotlin.comparisons.compareBy
|
||||
|
||||
class AddAppDialog() : DialogFragment() {
|
||||
val LAUNCHERS = "launchers"
|
||||
lateinit var launchers: ArrayList<AppLauncher>
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
val builder = AlertDialog.Builder(activity)
|
||||
builder.setTitle(R.string.add_apps)
|
||||
|
||||
val json = arguments.getString(LAUNCHERS)
|
||||
val listType = object : TypeToken<ArrayList<AppLauncher>>() {}.type
|
||||
launchers = Gson().fromJson(json, listType)
|
||||
|
||||
val recyclerView = View.inflate(activity, R.layout.launcher_picker, null)
|
||||
fillGrid(recyclerView)
|
||||
recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, true, launchers) {
|
||||
|
||||
}
|
||||
|
||||
builder.setView(recyclerView)
|
||||
|
||||
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
||||
@ -30,24 +39,4 @@ class AddAppDialog() : DialogFragment() {
|
||||
builder.setNegativeButton(android.R.string.cancel, null)
|
||||
return builder.create()
|
||||
}
|
||||
|
||||
private fun fillGrid(recyclerView: View) {
|
||||
val apps = ArrayList<AppLauncher>()
|
||||
val packageManager = activity.packageManager
|
||||
val intent = Intent(Intent.ACTION_MAIN, null)
|
||||
intent.addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
val list = packageManager.queryIntentActivities(intent, PackageManager.PERMISSION_GRANTED)
|
||||
for (info in list) {
|
||||
val componentInfo = info.activityInfo.applicationInfo
|
||||
val label = componentInfo.loadLabel(packageManager).toString()
|
||||
val pkgName = componentInfo.packageName
|
||||
apps.add(AppLauncher(label, pkgName, 0))
|
||||
}
|
||||
|
||||
val sorted = apps.sortedWith(compareBy { it.name.toLowerCase() })
|
||||
val unique = sorted.distinctBy { it.pkgName }
|
||||
recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, true, unique) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user