mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-07 23:38:54 +01:00
return the selected launchers to the activity
This commit is contained in:
parent
8c6062180f
commit
dbd27b7baf
@ -5,7 +5,6 @@ import android.content.pm.PackageManager
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.simplemobiletools.applauncher.R
|
import com.simplemobiletools.applauncher.R
|
||||||
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||||
import com.simplemobiletools.applauncher.databases.DbHelper
|
import com.simplemobiletools.applauncher.databases.DbHelper
|
||||||
@ -18,7 +17,7 @@ import kotlinx.android.synthetic.main.activity_main.*
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.comparisons.compareBy
|
import kotlin.comparisons.compareBy
|
||||||
|
|
||||||
class MainActivity : SimpleActivity() {
|
class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface {
|
||||||
lateinit var dbHelper: DbHelper
|
lateinit var dbHelper: DbHelper
|
||||||
lateinit var launchers: ArrayList<AppLauncher>
|
lateinit var launchers: ArrayList<AppLauncher>
|
||||||
lateinit var remainingLaunchers: ArrayList<AppLauncher>
|
lateinit var remainingLaunchers: ArrayList<AppLauncher>
|
||||||
@ -40,11 +39,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
remainingLaunchers = getNotDisplayedLaunchers()
|
remainingLaunchers = getNotDisplayedLaunchers()
|
||||||
|
|
||||||
fab.setOnClickListener {
|
fab.setOnClickListener {
|
||||||
val dialog = AddAppDialog()
|
AddAppDialog.newInstance(this, remainingLaunchers).show(fragmentManager, "")
|
||||||
val args = Bundle()
|
|
||||||
args.putString(dialog.LAUNCHERS, Gson().toJson(remainingLaunchers))
|
|
||||||
dialog.arguments = args
|
|
||||||
dialog.show(fragmentManager, "")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,6 +80,10 @@ class MainActivity : SimpleActivity() {
|
|||||||
return filtered as ArrayList<AppLauncher>
|
return filtered as ArrayList<AppLauncher>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun selectedLaunchers(launchers: ArrayList<AppLauncher>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
preferences.isFirstRun = false
|
preferences.isFirstRun = false
|
||||||
|
@ -5,8 +5,6 @@ import android.app.DialogFragment
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AlertDialog
|
import android.support.v7.app.AlertDialog
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.reflect.TypeToken
|
|
||||||
import com.simplemobiletools.applauncher.R
|
import com.simplemobiletools.applauncher.R
|
||||||
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
import com.simplemobiletools.applauncher.adapters.RecyclerAdapter
|
||||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||||
@ -14,17 +12,20 @@ import kotlinx.android.synthetic.main.launcher_picker.view.*
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class AddAppDialog() : DialogFragment() {
|
class AddAppDialog() : DialogFragment() {
|
||||||
val LAUNCHERS = "launchers"
|
companion object {
|
||||||
lateinit var launchers: ArrayList<AppLauncher>
|
lateinit var launchers: ArrayList<AppLauncher>
|
||||||
|
var callback: AddLaunchersInterface? = null
|
||||||
|
fun newInstance(cb: AddLaunchersInterface, appLaunchers: ArrayList<AppLauncher>): AddAppDialog {
|
||||||
|
callback = cb
|
||||||
|
launchers = appLaunchers
|
||||||
|
return AddAppDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val builder = AlertDialog.Builder(activity)
|
val builder = AlertDialog.Builder(activity)
|
||||||
builder.setTitle(R.string.add_apps)
|
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)
|
val recyclerView = View.inflate(activity, R.layout.launcher_picker, null)
|
||||||
recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, true, launchers) {
|
recyclerView.launchers_holder.adapter = RecyclerAdapter(activity, true, launchers) {
|
||||||
|
|
||||||
@ -33,10 +34,15 @@ class AddAppDialog() : DialogFragment() {
|
|||||||
builder.setView(recyclerView)
|
builder.setView(recyclerView)
|
||||||
|
|
||||||
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
builder.setPositiveButton(android.R.string.ok, { dialogInterface, i ->
|
||||||
|
val selectedApps = launchers.filter { it.isChecked } as ArrayList<AppLauncher>
|
||||||
|
callback?.selectedLaunchers(selectedApps)
|
||||||
})
|
})
|
||||||
|
|
||||||
builder.setNegativeButton(android.R.string.cancel, null)
|
builder.setNegativeButton(android.R.string.cancel, null)
|
||||||
return builder.create()
|
return builder.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AddLaunchersInterface {
|
||||||
|
fun selectedLaunchers(launchers: ArrayList<AppLauncher>)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user