mirror of
				https://github.com/SimpleMobileTools/Simple-App-Launcher.git
				synced 2025-06-05 21:49:21 +02:00 
			
		
		
		
	rewriting the Pick Launchers dialog
This commit is contained in:
		| @@ -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<AppLauncher>() | ||||
|     private var remainingLaunchers = ArrayList<AppLauncher>() | ||||
|  | ||||
| @@ -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<AppLauncher> | ||||
|     } | ||||
|  | ||||
|     override fun addLaunchers(launchers: ArrayList<AppLauncher>) { | ||||
|         for ((id, name, pkgName) in launchers) { | ||||
|             //dbHelper.addAppLauncher(name, pkgName) | ||||
|         } | ||||
|         refreshLaunchers() | ||||
|     } | ||||
|  | ||||
|     override fun launchersDeleted(indexes: List<Int>, deletedLaunchers: List<AppLauncher>) { | ||||
|         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() | ||||
|   | ||||
| @@ -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<AppLauncher> | ||||
|         var callback: AddLaunchersInterface? = null | ||||
| class AddAppDialog(val activity: Activity, val availableLaunchers: ArrayList<AppLauncher>, 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<AppLauncher>): 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<AppLauncher> | ||||
|             callback?.addLaunchers(selectedApps) | ||||
|         }) | ||||
|  | ||||
|         builder.setNegativeButton(R.string.cancel, { dialogInterface, i -> | ||||
|             callback?.updateLaunchers() | ||||
|         }) | ||||
|         return builder.create() | ||||
|     } | ||||
|  | ||||
|     interface AddLaunchersInterface { | ||||
|         fun addLaunchers(launchers: ArrayList<AppLauncher>) | ||||
|  | ||||
|         fun updateLaunchers() | ||||
|     private fun confirmSelection() { | ||||
|         //val selectedApps = availableLaunchers.filter { it.isChecked } as ArrayList<AppLauncher> | ||||
|         callback() | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -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) | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -2,7 +2,7 @@ | ||||
| <android.support.v7.widget.RecyclerView | ||||
|     xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     android:id="@+id/launchers_holder" | ||||
|     android:id="@+id/pick_launchers_holder" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" | ||||
|     android:clipToPadding="false" | ||||
		Reference in New Issue
	
	Block a user