From 56ffc7284f55309591a2ec1b9cdcb9e8dcf51cc5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 11 Nov 2017 17:17:29 +0100 Subject: [PATCH] rewriting the Pick Launchers dialog --- .../applauncher/activities/MainActivity.kt | 17 ++---- .../applauncher/dialogs/AddAppDialog.kt | 52 ++++++------------- .../applauncher/helpers/DBHelper.kt | 2 +- ...launcher.xml => dialog_pick_launchers.xml} | 2 +- 4 files changed, 23 insertions(+), 50 deletions(-) rename app/src/main/res/layout/{dialog_pick_launcher.xml => dialog_pick_launchers.xml} (91%) diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt index 44cdde1..f6066d2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/activities/MainActivity.kt @@ -23,7 +23,7 @@ import com.simplemobiletools.commons.models.Release import kotlinx.android.synthetic.main.activity_main.* import java.util.* -class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, RecyclerAdapter.RecyclerInterface { +class MainActivity : SimpleActivity(), RecyclerAdapter.RecyclerInterface { private var launchers = ArrayList() private var remainingLaunchers = ArrayList() @@ -34,7 +34,9 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc checkWhatsNewDialog() fab.setOnClickListener { - AddAppDialog.newInstance(this, remainingLaunchers).show(fragmentManager, "") + AddAppDialog(this, getNotDisplayedLaunchers()) { + + } } } @@ -114,13 +116,6 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc launchers = launchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList } - override fun addLaunchers(launchers: ArrayList) { - for ((id, name, pkgName) in launchers) { - //dbHelper.addAppLauncher(name, pkgName) - } - refreshLaunchers() - } - override fun launchersDeleted(indexes: List, deletedLaunchers: List) { val reversed = indexes.reversed() for (index in reversed) { @@ -136,10 +131,6 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc refreshLaunchers() } - override fun updateLaunchers() { - refreshLaunchers() - } - private fun refreshLaunchers() { (launchers_holder.adapter as RecyclerAdapter).finishActionMode() setupLaunchers() diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddAppDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddAppDialog.kt index 34af819..29df292 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddAppDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/AddAppDialog.kt @@ -1,49 +1,31 @@ package com.simplemobiletools.applauncher.dialogs -import android.app.Dialog -import android.app.DialogFragment -import android.os.Bundle +import android.app.Activity import android.support.v7.app.AlertDialog -import android.view.View +import android.view.ViewGroup import com.simplemobiletools.applauncher.R import com.simplemobiletools.applauncher.adapters.RecyclerDialogAdapter import com.simplemobiletools.applauncher.models.AppLauncher -import kotlinx.android.synthetic.main.dialog_pick_launcher.view.* +import com.simplemobiletools.commons.extensions.setupDialogStuff +import kotlinx.android.synthetic.main.dialog_pick_launchers.view.* import java.util.* -class AddAppDialog : DialogFragment() { - companion object { - lateinit var launchers: ArrayList - var callback: AddLaunchersInterface? = null +class AddAppDialog(val activity: Activity, val availableLaunchers: ArrayList, val callback: () -> Unit) { + var dialog: AlertDialog + var view = (activity.layoutInflater.inflate(R.layout.dialog_pick_launchers, null) as ViewGroup) - fun newInstance(cb: AddLaunchersInterface, appLaunchers: ArrayList): AddAppDialog { - callback = cb - launchers = appLaunchers - return AddAppDialog() + init { + dialog = AlertDialog.Builder(activity) + .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmSelection() }) + .setNegativeButton(R.string.cancel, null) + .create().apply { + activity.setupDialogStuff(view, this) + view.pick_launchers_holder.adapter = RecyclerDialogAdapter(activity, availableLaunchers) } } - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val builder = AlertDialog.Builder(activity) - - val recyclerView = View.inflate(activity, R.layout.dialog_pick_launcher, null) - recyclerView.launchers_holder.adapter = RecyclerDialogAdapter(activity, launchers) - builder.setView(recyclerView) - - builder.setPositiveButton(R.string.ok, { dialogInterface, i -> - val selectedApps = launchers.filter { it.isChecked } as ArrayList - callback?.addLaunchers(selectedApps) - }) - - builder.setNegativeButton(R.string.cancel, { dialogInterface, i -> - callback?.updateLaunchers() - }) - return builder.create() - } - - interface AddLaunchersInterface { - fun addLaunchers(launchers: ArrayList) - - fun updateLaunchers() + private fun confirmSelection() { + //val selectedApps = availableLaunchers.filter { it.isChecked } as ArrayList + callback() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt index efc868e..f441079 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt @@ -91,7 +91,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont } } - fun addAppLauncher(appLauncher: AppLauncher, db: SQLiteDatabase) { + private fun addAppLauncher(appLauncher: AppLauncher, db: SQLiteDatabase) { insertAppLauncher(appLauncher, db) } diff --git a/app/src/main/res/layout/dialog_pick_launcher.xml b/app/src/main/res/layout/dialog_pick_launchers.xml similarity index 91% rename from app/src/main/res/layout/dialog_pick_launcher.xml rename to app/src/main/res/layout/dialog_pick_launchers.xml index ce51f86..0fa23cb 100644 --- a/app/src/main/res/layout/dialog_pick_launcher.xml +++ b/app/src/main/res/layout/dialog_pick_launchers.xml @@ -2,7 +2,7 @@