mirror of
https://github.com/SimpleMobileTools/Simple-App-Launcher.git
synced 2025-04-25 23:28:46 +02:00
rewriting EditDialog
This commit is contained in:
parent
c3f1dad0aa
commit
f5ddb72a6f
@ -1,6 +1,5 @@
|
||||
package com.simplemobiletools.applauncher.adapters
|
||||
|
||||
import android.app.AlertDialog
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Resources
|
||||
import android.support.v7.view.ActionMode
|
||||
@ -12,6 +11,7 @@ import com.bignerdranch.android.multiselector.MultiSelector
|
||||
import com.bignerdranch.android.multiselector.SwappingHolder
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.activities.SimpleActivity
|
||||
import com.simplemobiletools.applauncher.dialogs.EditDialog
|
||||
import com.simplemobiletools.applauncher.extensions.config
|
||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||
import com.simplemobiletools.applauncher.extensions.getLauncherDrawable
|
||||
@ -20,10 +20,8 @@ import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.applyColorFilter
|
||||
import com.simplemobiletools.commons.extensions.beGone
|
||||
import com.simplemobiletools.commons.extensions.beVisibleIf
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.interfaces.MyAdapterListener
|
||||
import kotlinx.android.synthetic.main.app_launcher_item.view.*
|
||||
import kotlinx.android.synthetic.main.dialog_edit_launcher.view.*
|
||||
import java.util.*
|
||||
|
||||
class RecyclerAdapter(val activity: SimpleActivity, val launchers: List<AppLauncher>, val listener: AppLaunchersListener?, val itemClick: (AppLauncher) -> Unit) :
|
||||
@ -91,7 +89,7 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List<AppLaunc
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(actionMode: ActionMode?, menu: Menu): Boolean {
|
||||
menu.findItem(R.id.cab_edit).isVisible = multiSelector.selectedPositions.size == 1
|
||||
menu.findItem(R.id.cab_edit).isVisible = selectedPositions.size == 1
|
||||
return true
|
||||
}
|
||||
|
||||
@ -117,32 +115,9 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List<AppLaunc
|
||||
override fun getItemCount() = launchers.count()
|
||||
|
||||
private fun showEditDialog() {
|
||||
val selectedLauncher = launchers[multiSelector.selectedPositions[0]]
|
||||
val editView = activity.layoutInflater.inflate(R.layout.dialog_edit_launcher, null)
|
||||
editView.edit_launcher_edittext.setText(selectedLauncher.name)
|
||||
|
||||
AlertDialog.Builder(activity).apply {
|
||||
setTitle(activity.getString(R.string.rename))
|
||||
setView(editView)
|
||||
setPositiveButton(R.string.ok, null)
|
||||
setNegativeButton(R.string.cancel, null)
|
||||
create().apply {
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
||||
show()
|
||||
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val newName = editView.edit_launcher_edittext.text.toString().trim()
|
||||
if (!newName.isEmpty()) {
|
||||
if (activity.dbHelper.updateLauncherName(selectedLauncher.id, newName) > 0) {
|
||||
EditDialog(activity, launchers[selectedPositions.first()]) {
|
||||
actMode?.finish()
|
||||
listener?.refreshLaunchers()
|
||||
dismiss()
|
||||
} else {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.enter_launcher_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
package com.simplemobiletools.applauncher.dialogs
|
||||
|
||||
import android.app.Activity
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.view.ViewGroup
|
||||
import android.view.WindowManager
|
||||
import com.simplemobiletools.applauncher.R
|
||||
import com.simplemobiletools.applauncher.extensions.dbHelper
|
||||
import com.simplemobiletools.applauncher.models.AppLauncher
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import kotlinx.android.synthetic.main.dialog_edit_launcher.view.*
|
||||
|
||||
class EditDialog(val activity: Activity, val appLauncher: AppLauncher, val callback: () -> Unit) {
|
||||
var dialog: AlertDialog
|
||||
var view = (activity.layoutInflater.inflate(R.layout.dialog_edit_launcher, null) as ViewGroup)
|
||||
|
||||
init {
|
||||
view.edit_launcher_edittext.setText(appLauncher.name)
|
||||
|
||||
dialog = AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.create().apply {
|
||||
activity.setupDialogStuff(view, this, R.string.rename)
|
||||
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
|
||||
show()
|
||||
getButton(android.app.AlertDialog.BUTTON_POSITIVE).setOnClickListener {
|
||||
val newName = view.edit_launcher_edittext.value
|
||||
if (!newName.isEmpty()) {
|
||||
if (activity.dbHelper.updateLauncherName(appLauncher.id, newName)) {
|
||||
callback()
|
||||
dismiss()
|
||||
} else {
|
||||
activity.toast(R.string.unknown_error_occurred)
|
||||
}
|
||||
} else {
|
||||
activity.toast(R.string.enter_launcher_name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -86,12 +86,12 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
||||
mDb.delete(MAIN_TABLE_NAME, selection, null)
|
||||
}
|
||||
|
||||
fun updateLauncherName(id: Int, newName: String): Int {
|
||||
fun updateLauncherName(id: Int, newName: String): Boolean {
|
||||
val values = ContentValues()
|
||||
values.put(COL_NAME, newName)
|
||||
val selection = "$COL_ID = ?"
|
||||
val selectionArgs = Array(1) { id.toString() }
|
||||
return mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs)
|
||||
return mDb.update(MAIN_TABLE_NAME, values, selection, selectionArgs) == 1
|
||||
}
|
||||
|
||||
fun getLaunchers(): ArrayList<AppLauncher> {
|
||||
|
@ -11,6 +11,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:inputType="textCapWords"
|
||||
android:textCursorDrawable="@null"/>
|
||||
android:textCursorDrawable="@null"
|
||||
android:textSize="@dimen/normal_text_size"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user