mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-02-01 01:46:44 +01:00
really delete the selected launchers
This commit is contained in:
parent
223fcffee9
commit
755c1ca761
@ -9,10 +9,12 @@ import com.bignerdranch.android.multiselector.ModalMultiSelectorCallback
|
||||
import com.bignerdranch.android.multiselector.MultiSelector
|
||||
import com.bignerdranch.android.multiselector.SwappingHolder
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.databases.DbHelper
|
||||
import com.simplemobiletools.applauncher.extensions.hide
|
||||
import com.simplemobiletools.applauncher.extensions.show
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.*
|
||||
import java.util.*
|
||||
|
||||
class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
|
||||
RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {
|
||||
@ -27,6 +29,12 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
|
||||
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
|
||||
when (item?.itemId) {
|
||||
R.id.cab_delete -> {
|
||||
val positions = multiSelector.selectedPositions
|
||||
val deleteIds = ArrayList<String>(positions.size)
|
||||
for (i in positions) {
|
||||
deleteIds.add(launchers[i].id.toString())
|
||||
}
|
||||
DbHelper(act).deleteLaunchers(deleteIds)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.database.sqlite.SQLiteOpenHelper
|
||||
import android.text.TextUtils
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import java.util.*
|
||||
@ -44,6 +45,11 @@ class DbHelper(context: Context) : SQLiteOpenHelper(context, "launchers.db", nul
|
||||
db.insert(TABLE, null, contentValues)
|
||||
}
|
||||
|
||||
fun deleteLaunchers(ids: ArrayList<String>) {
|
||||
val args = TextUtils.join(", ", ids.toArray())
|
||||
writableDatabase.delete(TABLE, "$ID IN ($args)", null)
|
||||
}
|
||||
|
||||
fun getLaunchers(): ArrayList<AppLauncher> {
|
||||
val launchers = ArrayList<AppLauncher>()
|
||||
val cursor = readableDatabase.query(TABLE, arrayOf(ID, NAME, PKG_NAME, ICON_ID), null, null, null, null, NAME)
|
||||
|
Loading…
x
Reference in New Issue
Block a user