diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt index 42c7165..547983b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/adapters/RecyclerAdapter.kt @@ -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, val listener: AppLaunchersListener?, val itemClick: (AppLauncher) -> Unit) : @@ -91,7 +89,7 @@ class RecyclerAdapter(val activity: SimpleActivity, val launchers: List 0) { - listener?.refreshLaunchers() - dismiss() - } else { - activity.toast(R.string.unknown_error_occurred) - } - } else { - activity.toast(R.string.enter_launcher_name) - } - } - } + EditDialog(activity, launchers[selectedPositions.first()]) { + actMode?.finish() + listener?.refreshLaunchers() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt new file mode 100644 index 0000000..c37e7d8 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/dialogs/EditDialog.kt @@ -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) + } + } + } + } +} diff --git a/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt b/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt index db2cfad..da04c2e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/applauncher/helpers/DBHelper.kt @@ -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 { diff --git a/app/src/main/res/layout/dialog_edit_launcher.xml b/app/src/main/res/layout/dialog_edit_launcher.xml index 20d1f00..5a0f65c 100644 --- a/app/src/main/res/layout/dialog_edit_launcher.xml +++ b/app/src/main/res/layout/dialog_edit_launcher.xml @@ -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"/>