implement launcher adding

This commit is contained in:
tibbi 2017-11-12 16:29:28 +01:00
parent 1dfd1c5673
commit d184370fb3
3 changed files with 17 additions and 3 deletions

View File

@ -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)

View File

@ -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()
}
}

View File

@ -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()
}