mirror of
				https://github.com/SimpleMobileTools/Simple-Launcher.git
				synced 2025-06-05 21:59:15 +02:00 
			
		
		
		
	allow renaming icons on the home screen
This commit is contained in:
		| @@ -35,6 +35,7 @@ import com.simplemobiletools.commons.helpers.isQPlus | ||||
| import com.simplemobiletools.commons.helpers.isRPlus | ||||
| import com.simplemobiletools.launcher.BuildConfig | ||||
| import com.simplemobiletools.launcher.R | ||||
| import com.simplemobiletools.launcher.dialogs.RenameItemDialog | ||||
| import com.simplemobiletools.launcher.extensions.* | ||||
| import com.simplemobiletools.launcher.fragments.AllAppsFragment | ||||
| import com.simplemobiletools.launcher.fragments.MyFragment | ||||
| @@ -484,8 +485,10 @@ class MainActivity : SimpleActivity(), FlingListener { | ||||
|     } | ||||
|  | ||||
|     private fun handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridItem, isOnAllAppsFragment: Boolean): PopupMenu { | ||||
|         var visibleMenuButtons = 4 | ||||
|         if (gridItem.type != ITEM_TYPE_ICON) { | ||||
|         var visibleMenuButtons = 5 | ||||
|         if (gridItem.type == ITEM_TYPE_ICON) { | ||||
|             visibleMenuButtons -= 1 | ||||
|         } else { | ||||
|             visibleMenuButtons -= 2 | ||||
|         } | ||||
|  | ||||
| @@ -507,6 +510,7 @@ class MainActivity : SimpleActivity(), FlingListener { | ||||
|             } | ||||
|  | ||||
|             inflate(R.menu.menu_app_icon) | ||||
|             menu.findItem(R.id.rename).isVisible = gridItem.type == ITEM_TYPE_ICON && !isOnAllAppsFragment | ||||
|             menu.findItem(R.id.resize).isVisible = gridItem.type == ITEM_TYPE_WIDGET | ||||
|             menu.findItem(R.id.app_info).isVisible = gridItem.type == ITEM_TYPE_ICON | ||||
|             menu.findItem(R.id.uninstall).isVisible = gridItem.type == ITEM_TYPE_ICON | ||||
| @@ -514,6 +518,7 @@ class MainActivity : SimpleActivity(), FlingListener { | ||||
|             setOnMenuItemClickListener { item -> | ||||
|                 resetFragmentTouches() | ||||
|                 when (item.itemId) { | ||||
|                     R.id.rename -> renameItem(gridItem) | ||||
|                     R.id.resize -> home_screen_grid.widgetLongPressed(gridItem) | ||||
|                     R.id.app_info -> launchAppInfo(gridItem.packageName) | ||||
|                     R.id.remove -> home_screen_grid.removeAppIcon(gridItem) | ||||
| @@ -547,6 +552,12 @@ class MainActivity : SimpleActivity(), FlingListener { | ||||
|         showFragment(widgets_fragment) | ||||
|     } | ||||
|  | ||||
|     private fun renameItem(homeScreenGridItem: HomeScreenGridItem) { | ||||
|         RenameItemDialog(this, homeScreenGridItem) { | ||||
|             home_screen_grid.fetchGridItems() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun launchWallpapersIntent() { | ||||
|         try { | ||||
|             Intent(Intent.ACTION_SET_WALLPAPER).apply { | ||||
|   | ||||
| @@ -0,0 +1,45 @@ | ||||
| package com.simplemobiletools.launcher.dialogs | ||||
|  | ||||
| import android.app.Activity | ||||
| import android.app.AlertDialog | ||||
| import android.view.ViewGroup | ||||
| import com.simplemobiletools.commons.extensions.* | ||||
| import com.simplemobiletools.commons.helpers.ensureBackgroundThread | ||||
| import com.simplemobiletools.commons.helpers.mydebug | ||||
| import com.simplemobiletools.launcher.R | ||||
| import com.simplemobiletools.launcher.extensions.homeScreenGridItemsDB | ||||
| import com.simplemobiletools.launcher.models.HomeScreenGridItem | ||||
| import kotlinx.android.synthetic.main.dialog_rename_item.view.* | ||||
|  | ||||
| class RenameItemDialog(val activity: Activity, val item: HomeScreenGridItem, val callback: () -> Unit) { | ||||
|  | ||||
|     init { | ||||
|         val view = (activity.layoutInflater.inflate(R.layout.dialog_rename_item, null) as ViewGroup) | ||||
|         view.rename_item_edittext.setText(item.title) | ||||
|  | ||||
|         activity.getAlertDialogBuilder() | ||||
|             .setPositiveButton(R.string.ok, null) | ||||
|             .setNegativeButton(R.string.cancel, null) | ||||
|             .apply { | ||||
|                 activity.setupDialogStuff(view, this, R.string.rename) { alertDialog -> | ||||
|                     alertDialog.showKeyboard(view.rename_item_edittext) | ||||
|                     alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener { | ||||
|                         val newTitle = view.rename_item_edittext.value | ||||
|                         if (!newTitle.isEmpty()) { | ||||
|                             ensureBackgroundThread { | ||||
|                                 val result = activity.homeScreenGridItemsDB.updateItemTitle(newTitle, item.id!!) | ||||
|                                 if (result == 1) { | ||||
|                                     callback() | ||||
|                                     alertDialog.dismiss() | ||||
|                                 } else { | ||||
|                                     activity.toast(R.string.unknown_error_occurred) | ||||
|                                 } | ||||
|                             } | ||||
|                         } else { | ||||
|                             activity.toast(R.string.value_cannot_be_empty) | ||||
|                         } | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|     } | ||||
| } | ||||
| @@ -20,6 +20,9 @@ interface HomeScreenGridItemsDao { | ||||
|     @Query("UPDATE home_screen_grid_items SET title = :title WHERE package_name = :packageName") | ||||
|     fun updateAppTitle(title: String, packageName: String) | ||||
|  | ||||
|     @Query("UPDATE home_screen_grid_items SET title = :title WHERE id = :id") | ||||
|     fun updateItemTitle(title: String, id: Long): Int | ||||
|  | ||||
|     @Query("UPDATE home_screen_grid_items SET `left` = :left, `top` = :top, `right` = :right, `bottom` = :bottom WHERE id = :id") | ||||
|     fun updateItemPosition(left: Int, top: Int, right: Int, bottom: Int, id: Long) | ||||
|  | ||||
|   | ||||
							
								
								
									
										22
									
								
								app/src/main/res/layout/dialog_rename_item.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								app/src/main/res/layout/dialog_rename_item.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:id="@+id/rename_item_holder" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="wrap_content" | ||||
|     android:padding="@dimen/activity_margin"> | ||||
|  | ||||
|     <com.simplemobiletools.commons.views.MyTextInputLayout | ||||
|         android:id="@+id/rename_item_hint" | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:hint="@string/label"> | ||||
|  | ||||
|         <com.google.android.material.textfield.TextInputEditText | ||||
|             android:id="@+id/rename_item_edittext" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:inputType="textCapWords" | ||||
|             android:textSize="@dimen/bigger_text_size" /> | ||||
|  | ||||
|     </com.simplemobiletools.commons.views.MyTextInputLayout> | ||||
| </FrameLayout> | ||||
| @@ -11,6 +11,11 @@ | ||||
|         android:icon="@drawable/ic_resize_vector" | ||||
|         android:title="@string/resize" | ||||
|         app:showAsAction="always" /> | ||||
|     <item | ||||
|         android:id="@+id/rename" | ||||
|         android:icon="@drawable/ic_rename_vector" | ||||
|         android:title="@string/rename" | ||||
|         app:showAsAction="always" /> | ||||
|     <item | ||||
|         android:id="@+id/remove" | ||||
|         android:icon="@drawable/ic_cross_vector" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user