mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-03-06 12:17:56 +01:00
implement launcher adding
This commit is contained in:
parent
1dfd1c5673
commit
d184370fb3
@ -41,6 +41,14 @@ class RecyclerDialogAdapter(activity: Activity, val launchers: List<AppLauncher>
|
||||
itemViews[pos]?.launcher_check?.beVisibleIf(select)
|
||||
}
|
||||
|
||||
fun getSelectedLaunchers(): ArrayList<AppLauncher> {
|
||||
val selectedLaunchers = ArrayList<AppLauncher>()
|
||||
selectedPositions.forEach {
|
||||
selectedLaunchers.add(launchers[it])
|
||||
}
|
||||
return selectedLaunchers
|
||||
}
|
||||
|
||||
private val adapterListener = object : MyAdapterListener {
|
||||
override fun toggleItemSelectionAdapter(select: Boolean, position: Int) {
|
||||
toggleItemSelection(select, position)
|
||||
|
@ -5,6 +5,7 @@ import android.support.v7.app.AlertDialog
|
||||
import android.view.ViewGroup
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.adapters.RecyclerDialogAdapter
|
||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import kotlinx.android.synthetic.main.dialog_pick_launchers.view.*
|
||||
@ -13,6 +14,7 @@ import java.util.*
|
||||
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)
|
||||
lateinit var adapter: RecyclerDialogAdapter
|
||||
|
||||
init {
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
@ -20,12 +22,16 @@ class AddAppDialog(val activity: Activity, val availableLaunchers: ArrayList<App
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this)
|
||||
view.pick_launchers_holder.adapter = RecyclerDialogAdapter(activity, availableLaunchers)
|
||||
adapter = RecyclerDialogAdapter(activity, availableLaunchers)
|
||||
view.pick_launchers_holder.adapter = adapter
|
||||
}
|
||||
}
|
||||
|
||||
private fun confirmSelection() {
|
||||
//val selectedApps = availableLaunchers.filter { it.isChecked } as ArrayList<AppLauncher>
|
||||
adapter.getSelectedLaunchers().forEach {
|
||||
activity.dbHelper.insertAppLauncher(it)
|
||||
}
|
||||
callback()
|
||||
dialog.dismiss()
|
||||
}
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
insertAppLauncher(appLauncher, db)
|
||||
}
|
||||
|
||||
private fun insertAppLauncher(appLauncher: AppLauncher, db: SQLiteDatabase = mDb): Int {
|
||||
fun insertAppLauncher(appLauncher: AppLauncher, db: SQLiteDatabase = mDb): Int {
|
||||
val values = fillAppLauncherValues(appLauncher)
|
||||
return db.insert(MAIN_TABLE_NAME, null, values).toInt()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user