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