display a dialog for renaming launcher

This commit is contained in:
tibbi
2016-08-17 23:56:13 +02:00
parent 61494ff6d1
commit 3671a71cf0
3 changed files with 40 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package com.simplemobiletools.applauncher.adapters package com.simplemobiletools.applauncher.adapters
import android.app.Activity import android.app.Activity
import android.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.support.v7.view.ActionMode import android.support.v7.view.ActionMode
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
@ -14,6 +15,7 @@ import com.simplemobiletools.applauncher.extensions.hide
import com.simplemobiletools.applauncher.extensions.show import com.simplemobiletools.applauncher.extensions.show
import com.simplemobiletools.applauncher.models.AppLauncher import com.simplemobiletools.applauncher.models.AppLauncher
import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.* import kotlinx.android.synthetic.main.app_launcher_dialog_item.view.*
import kotlinx.android.synthetic.main.edit_launcher.view.*
import java.util.* import java.util.*
class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) : class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val itemClick: (AppLauncher) -> Unit) :
@ -29,7 +31,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean { override fun onActionItemClicked(mode: ActionMode?, item: MenuItem?): Boolean {
when (item?.itemId) { when (item?.itemId) {
R.id.cab_edit -> { R.id.cab_edit -> {
showEditDialog()
} }
R.id.cab_delete -> { R.id.cab_delete -> {
deleteSelectedItems() deleteSelectedItems()
@ -66,6 +68,25 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
return launchers.count() return launchers.count()
} }
private fun showEditDialog() {
val selectedLauncher = launchers[multiSelector.selectedPositions[0]]
val editView = act.layoutInflater.inflate(R.layout.edit_launcher, null)
editView.edit_launcher_edittext.setText(selectedLauncher.name)
val builder = AlertDialog.Builder(act)
builder.setTitle(act.getString(R.string.rename_launcher))
builder.setView(editView)
builder.setPositiveButton(R.string.ok, null)
builder.setNegativeButton(R.string.cancel, null)
val alertDialog = builder.create()
alertDialog.show()
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
alertDialog.dismiss()
}
}
private fun deleteSelectedItems() { private fun deleteSelectedItems() {
val positions = multiSelector.selectedPositions val positions = multiSelector.selectedPositions
val deleteIds = ArrayList<String>(positions.size) val deleteIds = ArrayList<String>(positions.size)

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="@+id/edit_launcher_holder"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/activity_margin">
<EditText
android:id="@+id/edit_launcher_edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textCapWords"/>
</FrameLayout>

View File

@ -2,6 +2,9 @@
<string name="app_name">Simple App Launcher</string> <string name="app_name">Simple App Launcher</string>
<string name="delete">Delete</string> <string name="delete">Delete</string>
<string name="edit">Edit</string> <string name="edit">Edit</string>
<string name="rename_launcher">Rename launcher</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<!-- About --> <!-- About -->
<string name="about">About</string> <string name="about">About</string>