Skip to content

Commit c5f3293

Browse files
committed
allow renaming icons on the home screen
1 parent c59bfc9 commit c5f3293

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.simplemobiletools.commons.helpers.isQPlus
3535
import com.simplemobiletools.commons.helpers.isRPlus
3636
import com.simplemobiletools.launcher.BuildConfig
3737
import com.simplemobiletools.launcher.R
38+
import com.simplemobiletools.launcher.dialogs.RenameItemDialog
3839
import com.simplemobiletools.launcher.extensions.*
3940
import com.simplemobiletools.launcher.fragments.AllAppsFragment
4041
import com.simplemobiletools.launcher.fragments.MyFragment
@@ -484,8 +485,10 @@ class MainActivity : SimpleActivity(), FlingListener {
484485
}
485486

486487
private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu {
487-
var visibleMenuButtons = 4
488-
if (gridItem.type != ITEM_TYPE_ICON) {
488+
var visibleMenuButtons = 5
489+
if (gridItem.type == ITEM_TYPE_ICON) {
490+
visibleMenuButtons -= 1
491+
} else {
489492
visibleMenuButtons -= 2
490493
}
491494

@@ -507,13 +510,15 @@ class MainActivity : SimpleActivity(), FlingListener {
507510
}
508511

509512
inflate(R.menu.menu_app_icon)
513+
menu.findItem(R.id.rename).isVisible = gridItem.type == ITEM_TYPE_ICON && !isOnAllAppsFragment
510514
menu.findItem(R.id.resize).isVisible = gridItem.type == ITEM_TYPE_WIDGET
511515
menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON
512516
menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON
513517
menu.findItem(R.id.remove).isVisible = !isOnAllAppsFragment
514518
setOnMenuItemClickListener { item ->
515519
resetFragmentTouches()
516520
when (item.itemId) {
521+
R.id.rename -> renameItem(gridItem)
517522
R.id.resize -> home_screen_grid.widgetLongPressed(gridItem)
518523
R.id.app_info -> launchAppInfo(gridItem.packageName)
519524
R.id.remove -> home_screen_grid.removeAppIcon(gridItem)
@@ -547,6 +552,12 @@ class MainActivity : SimpleActivity(), FlingListener {
547552
showFragment(widgets_fragment)
548553
}
549554

555+
private fun renameItem(homeScreenGridItem: HomeScreenGridItem) {
556+
RenameItemDialog(this, homeScreenGridItem) {
557+
home_screen_grid.fetchGridItems()
558+
}
559+
}
560+
550561
private fun launchWallpapersIntent() {
551562
try {
552563
Intent(Intent.ACTION_SET_WALLPAPER).apply {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.simplemobiletools.launcher.dialogs
2+
3+
import android.app.Activity
4+
import android.app.AlertDialog
5+
import android.view.ViewGroup
6+
import com.simplemobiletools.commons.extensions.*
7+
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
8+
import com.simplemobiletools.commons.helpers.mydebug
9+
import com.simplemobiletools.launcher.R
10+
import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB
11+
import com.simplemobiletools.launcher.models.HomeScreenGridItem
12+
import kotlinx.android.synthetic.main.dialog_rename_item.view.*
13+
14+
class RenameItemDialog(val activity: Activity, val item: HomeScreenGridItem, val callback: () -> Unit) {
15+
16+
init {
17+
val view = (activity.layoutInflater.inflate(R.layout.dialog_rename_item, null) as ViewGroup)
18+
view.rename_item_edittext.setText(item.title)
19+
20+
activity.getAlertDialogBuilder()
21+
.setPositiveButton(R.string.ok, null)
22+
.setNegativeButton(R.string.cancel, null)
23+
.apply {
24+
activity.setupDialogStuff(view, this, R.string.rename) { alertDialog ->
25+
alertDialog.showKeyboard(view.rename_item_edittext)
26+
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
27+
val newTitle = view.rename_item_edittext.value
28+
if (!newTitle.isEmpty()) {
29+
ensureBackgroundThread {
30+
val result = activity.homeScreenGridItemsDB.updateItemTitle(newTitle, item.id!!)
31+
if (result == 1) {
32+
callback()
33+
alertDialog.dismiss()
34+
} else {
35+
activity.toast(R.string.unknown_error_occurred)
36+
}
37+
}
38+
} else {
39+
activity.toast(R.string.value_cannot_be_empty)
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}

app/src/main/kotlin/com/simplemobiletools/launcher/interfaces/HomeScreenGridItemsDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ interface HomeScreenGridItemsDao {
2020
@Query("UPDATE home_screen_grid_items SET title = :title WHERE package_name = :packageName")
2121
fun updateAppTitle(title: String, packageName: String)
2222

23+
@Query("UPDATE home_screen_grid_items SET title = :title WHERE id = :id")
24+
fun updateItemTitle(title: String, id: Long): Int
25+
2326
@Query("UPDATE home_screen_grid_items SET `left` = :left, `top` = :top, `right` = :right, `bottom` = :bottom WHERE id = :id")
2427
fun updateItemPosition(left: Int, top: Int, right: Int, bottom: Int, id: Long)
2528

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:id="@+id/rename_item_holder"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:padding="@dimen/activity_margin">
7+
8+
<com.simplemobiletools.commons.views.MyTextInputLayout
9+
android:id="@+id/rename_item_hint"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:hint="@string/label">
13+
14+
<com.google.android.material.textfield.TextInputEditText
15+
android:id="@+id/rename_item_edittext"
16+
android:layout_width="match_parent"
17+
android:layout_height="wrap_content"
18+
android:inputType="textCapWords"
19+
android:textSize="@dimen/bigger_text_size" />
20+
21+
</com.simplemobiletools.commons.views.MyTextInputLayout>
22+
</FrameLayout>

app/src/main/res/menu/menu_app_icon.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
android:icon="@drawable/ic_resize_vector"
1212
android:title="@string/resize"
1313
app:showAsAction="always" />
14+
<item
15+
android:id="@+id/rename"
16+
android:icon="@drawable/ic_rename_vector"
17+
android:title="@string/rename"
18+
app:showAsAction="always" />
1419
<item
1520
android:id="@+id/remove"
1621
android:icon="@drawable/ic_cross_vector"

0 commit comments

Comments
 (0)