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 kotlinx.android.synthetic.main.activity_main.* | ||||||
| import java.util.* | import java.util.* | ||||||
|  |  | ||||||
| class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, RecyclerAdapter.RecyclerInterface { | class MainActivity : SimpleActivity(), RecyclerAdapter.RecyclerInterface { | ||||||
|     private var launchers = ArrayList<AppLauncher>() |     private var launchers = ArrayList<AppLauncher>() | ||||||
|     private var remainingLaunchers = ArrayList<AppLauncher>() |     private var remainingLaunchers = ArrayList<AppLauncher>() | ||||||
|  |  | ||||||
| @@ -34,7 +34,9 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc | |||||||
|         checkWhatsNewDialog() |         checkWhatsNewDialog() | ||||||
|  |  | ||||||
|         fab.setOnClickListener { |         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> |         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>) { |     override fun launchersDeleted(indexes: List<Int>, deletedLaunchers: List<AppLauncher>) { | ||||||
|         val reversed = indexes.reversed() |         val reversed = indexes.reversed() | ||||||
|         for (index in reversed) { |         for (index in reversed) { | ||||||
| @@ -136,10 +131,6 @@ class MainActivity : SimpleActivity(), AddAppDialog.AddLaunchersInterface, Recyc | |||||||
|         refreshLaunchers() |         refreshLaunchers() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun updateLaunchers() { |  | ||||||
|         refreshLaunchers() |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private fun refreshLaunchers() { |     private fun refreshLaunchers() { | ||||||
|         (launchers_holder.adapter as RecyclerAdapter).finishActionMode() |         (launchers_holder.adapter as RecyclerAdapter).finishActionMode() | ||||||
|         setupLaunchers() |         setupLaunchers() | ||||||
|   | |||||||
| @@ -1,49 +1,31 @@ | |||||||
| package com.simplemobiletools.applauncher.dialogs | package com.simplemobiletools.applauncher.dialogs | ||||||
|  |  | ||||||
| import android.app.Dialog | import android.app.Activity | ||||||
| import android.app.DialogFragment |  | ||||||
| import android.os.Bundle |  | ||||||
| import android.support.v7.app.AlertDialog | import android.support.v7.app.AlertDialog | ||||||
| import android.view.View | import android.view.ViewGroup | ||||||
| import com.simplemobiletools.applauncher.R | import com.simplemobiletools.applauncher.R | ||||||
| import com.simplemobiletools.applauncher.adapters.RecyclerDialogAdapter | import com.simplemobiletools.applauncher.adapters.RecyclerDialogAdapter | ||||||
| import com.simplemobiletools.applauncher.models.AppLauncher | 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.* | import java.util.* | ||||||
|  |  | ||||||
| class AddAppDialog : DialogFragment() { | class AddAppDialog(val activity: Activity, val availableLaunchers: ArrayList<AppLauncher>, val callback: () -> Unit) { | ||||||
|     companion object { |     var dialog: AlertDialog | ||||||
|         lateinit var launchers: ArrayList<AppLauncher> |     var view = (activity.layoutInflater.inflate(R.layout.dialog_pick_launchers, null) as ViewGroup) | ||||||
|         var callback: AddLaunchersInterface? = null |  | ||||||
|  |  | ||||||
|         fun newInstance(cb: AddLaunchersInterface, appLaunchers: ArrayList<AppLauncher>): AddAppDialog { |     init { | ||||||
|             callback = cb |         dialog = AlertDialog.Builder(activity) | ||||||
|             launchers = appLaunchers |                 .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmSelection() }) | ||||||
|             return AddAppDialog() |                 .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 { |     private fun confirmSelection() { | ||||||
|         val builder = AlertDialog.Builder(activity) |         //val selectedApps = availableLaunchers.filter { it.isChecked } as ArrayList<AppLauncher> | ||||||
|  |         callback() | ||||||
|         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() |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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) |         insertAppLauncher(appLauncher, db) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ | |||||||
| <android.support.v7.widget.RecyclerView | <android.support.v7.widget.RecyclerView | ||||||
|     xmlns:android="http://schemas.android.com/apk/res/android" |     xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" |     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_width="match_parent" | ||||||
|     android:layout_height="match_parent" |     android:layout_height="match_parent" | ||||||
|     android:clipToPadding="false" |     android:clipToPadding="false" | ||||||
		Reference in New Issue
	
	Block a user