mirror of
				https://github.com/SimpleMobileTools/Simple-App-Launcher.git
				synced 2025-06-05 21:49:21 +02:00 
			
		
		
		
	Show a placeholder when no items are available
This commit is contained in:
		| @@ -33,6 +33,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|     private var mStoredPrimaryColor = 0 | ||||
|     private var mStoredTextColor = 0 | ||||
|  | ||||
|     private val emptyViews by lazy { arrayOf(add_icons_placeholder, no_items_placeholder) } | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|         setContentView(R.layout.activity_main) | ||||
| @@ -43,13 +45,9 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|         setupGridLayoutManager() | ||||
|  | ||||
|         fab.setOnClickListener { | ||||
|             if (allLaunchers != null) { | ||||
|                 val shownLaunchers = (launchers_grid.adapter as LaunchersAdapter).launchers | ||||
|                 AddLaunchersDialog(this, allLaunchers!!, shownLaunchers) { | ||||
|                     setupLaunchers() | ||||
|                 } | ||||
|             } | ||||
|             fabClicked() | ||||
|         } | ||||
|         setupEmptyView() | ||||
|     } | ||||
|  | ||||
|     override fun onResume() { | ||||
| @@ -58,7 +56,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|             getGridAdapter()?.updateTextColor(getProperTextColor()) | ||||
|         } | ||||
|  | ||||
|         if (mStoredPrimaryColor != getProperPrimaryColor()) { | ||||
|         val properPrimaryColor = getProperPrimaryColor() | ||||
|         if (mStoredPrimaryColor != properPrimaryColor) { | ||||
|             getGridAdapter()?.apply { | ||||
|                 updatePrimaryColor() | ||||
|                 notifyDataSetChanged() | ||||
| @@ -66,7 +65,8 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|         } | ||||
|  | ||||
|         updateTextColors(coordinator_layout) | ||||
|         launchers_fastscroller.updateColors(getProperPrimaryColor()) | ||||
|         add_icons_placeholder.setTextColor(properPrimaryColor) | ||||
|         launchers_fastscroller.updateColors(properPrimaryColor) | ||||
|     } | ||||
|  | ||||
|     override fun onPause() { | ||||
| @@ -126,13 +126,20 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|         checkInvalidApps() | ||||
|         initZoomListener() | ||||
|         setupAdapter(displayedLaunchers) | ||||
|         maybeShowEmptyView(displayedLaunchers) | ||||
|     } | ||||
|  | ||||
|     private fun setupAdapter(launchers: ArrayList<AppLauncher>) { | ||||
|         AppLauncher.sorting = config.sorting | ||||
|         launchers.sort() | ||||
|  | ||||
|         LaunchersAdapter(this, launchers, this, launchers_grid) { | ||||
|         LaunchersAdapter( | ||||
|             activity = this, | ||||
|             launchers = launchers, | ||||
|             listener = this, | ||||
|             recyclerView = launchers_grid, | ||||
|             onItemsRemoved = ::onItemsRemoved, | ||||
|         ) { | ||||
|             hideKeyboard() | ||||
|             val launchIntent = packageManager.getLaunchIntentForPackage((it as AppLauncher).packageName) | ||||
|             if (launchIntent != null) { | ||||
| @@ -256,4 +263,36 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { | ||||
|             checkWhatsNew(this, BuildConfig.VERSION_CODE) | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun fabClicked() { | ||||
|         if (allLaunchers != null) { | ||||
|             val shownLaunchers = (launchers_grid.adapter as LaunchersAdapter).launchers | ||||
|             AddLaunchersDialog(this, allLaunchers!!, shownLaunchers) { | ||||
|                 setupLaunchers() | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun setupEmptyView() { | ||||
|         val properPrimaryColor = getProperPrimaryColor() | ||||
|         add_icons_placeholder.underlineText() | ||||
|         add_icons_placeholder.setTextColor(properPrimaryColor) | ||||
|         add_icons_placeholder.setOnClickListener { | ||||
|             fabClicked() | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun onItemsRemoved() { | ||||
|         maybeShowEmptyView() | ||||
|     } | ||||
|  | ||||
|     private fun maybeShowEmptyView(displayedLaunchers: ArrayList<AppLauncher> = dbHelper.getLaunchers()) { | ||||
|         if (displayedLaunchers.isEmpty()) { | ||||
|             launchers_fastscroller.fadeOut() | ||||
|             emptyViews.forEach { it.fadeIn() } | ||||
|         } else { | ||||
|             emptyViews.forEach { it.fadeOut() } | ||||
|             launchers_fastscroller.fadeIn() | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -27,8 +27,12 @@ import kotlinx.android.synthetic.main.item_launcher_label.view.* | ||||
| import java.util.* | ||||
|  | ||||
| class LaunchersAdapter( | ||||
|     activity: SimpleActivity, val launchers: ArrayList<AppLauncher>, val listener: RefreshRecyclerViewListener?, | ||||
|     recyclerView: MyRecyclerView, itemClick: (Any) -> Unit | ||||
|     activity: SimpleActivity, | ||||
|     val launchers: ArrayList<AppLauncher>, | ||||
|     val listener: RefreshRecyclerViewListener?, | ||||
|     recyclerView: MyRecyclerView, | ||||
|     var onItemsRemoved: (() -> Unit)? = null, | ||||
|     itemClick: (Any) -> Unit | ||||
| ) : MyRecyclerViewAdapter(activity, recyclerView, itemClick), ItemTouchHelperContract, RecyclerViewFastScroller.OnPopupTextUpdate { | ||||
|  | ||||
|     private var isChangingOrder = false | ||||
| @@ -171,10 +175,11 @@ class LaunchersAdapter( | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         launchers.removeAll(removeLaunchers) | ||||
|         launchers.removeAll(removeLaunchers.toSet()) | ||||
|         activity.dbHelper.deleteLaunchers(removeIds) | ||||
|         positions.sortDescending() | ||||
|         removeSelectedItems(positions) | ||||
|         onItemsRemoved?.invoke() | ||||
|     } | ||||
|  | ||||
|     private fun setupView(view: View, launcher: AppLauncher, holder: ViewHolder) { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:id="@+id/coordinator_layout" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent"> | ||||
| @@ -10,6 +11,36 @@ | ||||
|         android:layout_width="match_parent" | ||||
|         android:layout_height="wrap_content"> | ||||
|  | ||||
|         <com.simplemobiletools.commons.views.MyTextView | ||||
|             android:id="@+id/no_items_placeholder" | ||||
|             android:layout_width="match_parent" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_centerHorizontal="true" | ||||
|             android:alpha="0.8" | ||||
|             android:gravity="center" | ||||
|             android:paddingStart="@dimen/activity_margin" | ||||
|             android:paddingTop="@dimen/activity_margin" | ||||
|             android:paddingEnd="@dimen/activity_margin" | ||||
|             android:text="@string/no_items_found" | ||||
|             android:textSize="@dimen/bigger_text_size" | ||||
|             android:textStyle="italic" | ||||
|             android:visibility="gone" | ||||
|             tools:visibility="visible" /> | ||||
|  | ||||
|         <com.simplemobiletools.commons.views.MyTextView | ||||
|             android:id="@+id/add_icons_placeholder" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:layout_below="@+id/no_items_placeholder" | ||||
|             android:layout_centerHorizontal="true" | ||||
|             android:background="?attr/selectableItemBackground" | ||||
|             android:gravity="center" | ||||
|             android:padding="@dimen/activity_margin" | ||||
|             android:text="@string/manage_visible_app_icons" | ||||
|             android:textSize="@dimen/bigger_text_size" | ||||
|             android:visibility="gone" | ||||
|             tools:visibility="visible" /> | ||||
|  | ||||
|         <com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller | ||||
|             android:id="@+id/launchers_fastscroller" | ||||
|             android:layout_width="match_parent" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user