lets allow any launcher name

This commit is contained in:
tibbi 2016-08-18 21:28:55 +02:00
parent 3fd432f53f
commit a8d186aa57
2 changed files with 3 additions and 9 deletions

View File

@ -18,7 +18,6 @@ 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 kotlinx.android.synthetic.main.edit_launcher.view.*
import java.util.* import java.util.*
import java.util.regex.Pattern
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) :
RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() { RecyclerView.Adapter<RecyclerAdapter.ViewHolder>() {
@ -88,7 +87,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
alertDialog.show() alertDialog.show()
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val newName = editView.edit_launcher_edittext.text.toString().trim() val newName = editView.edit_launcher_edittext.text.toString().trim()
if (isValidName(newName)) { if (!newName.isEmpty()) {
if (DbHelper(act).updateLauncherName(selectedLauncher.id, newName) > 0) { if (DbHelper(act).updateLauncherName(selectedLauncher.id, newName) > 0) {
(act as EditLaunchersInterface).launcherRenamed() (act as EditLaunchersInterface).launcherRenamed()
finishActionMode() finishActionMode()
@ -97,7 +96,7 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
Toast.makeText(act, act.resources.getString(R.string.unknown_error), Toast.LENGTH_SHORT).show() Toast.makeText(act, act.resources.getString(R.string.unknown_error), Toast.LENGTH_SHORT).show()
} }
} else { } else {
Toast.makeText(act, act.resources.getString(R.string.invalid_characters), Toast.LENGTH_SHORT).show() Toast.makeText(act, act.resources.getString(R.string.enter_launcher_name), Toast.LENGTH_SHORT).show()
} }
} }
} }
@ -106,11 +105,6 @@ class RecyclerAdapter(val act: Activity, val launchers: List<AppLauncher>, val i
actMode?.finish() actMode?.finish()
} }
private fun isValidName(newName: String): Boolean {
val pattern = Pattern.compile("[0-9a-zA-Z-_. ]+")
return pattern.matcher(newName).matches()
}
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

@ -5,7 +5,7 @@
<string name="rename_launcher">Rename launcher</string> <string name="rename_launcher">Rename launcher</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="invalid_characters">New launcher name contains invalid characters</string> <string name="enter_launcher_name">Please enter a launcher name</string>
<string name="unknown_error">An unknown error occurred</string> <string name="unknown_error">An unknown error occurred</string>
<!-- About --> <!-- About -->