From 2ab8bec8c066fe8542838970788f90937f439fcb Mon Sep 17 00:00:00 2001 From: Finn M Glas Date: Wed, 17 Jun 2020 09:14:20 +0200 Subject: [PATCH] Make fa icons visible for chosen actions In the actions / apps fragment of the launchers settings. The terminology has to be improved and kept the same everywhere in the app, as it also improves the codes readability and quality. I shall do that soon. --- .../launcher/choose/other/OtherInfo.kt | 3 +- .../choose/other/OtherRecyclerAdapter.kt | 14 +++-- .../actions/ActionsRecyclerAdapter.kt | 53 ++++++++++++------- .../main/res/layout/recycler_actions_row.xml | 12 +++++ .../main/res/layout/recycler_other_row.xml | 41 +++++++------- 5 files changed, 78 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/com/finnmglas/launcher/choose/other/OtherInfo.kt b/app/src/main/java/com/finnmglas/launcher/choose/other/OtherInfo.kt index 7d39b23..e93c275 100644 --- a/app/src/main/java/com/finnmglas/launcher/choose/other/OtherInfo.kt +++ b/app/src/main/java/com/finnmglas/launcher/choose/other/OtherInfo.kt @@ -1,6 +1,7 @@ package com.finnmglas.launcher.choose.other -class OtherInfo(label: String, data: String) { +class OtherInfo(label: String, data: String, icon: String) { var label: CharSequence? = label var data: CharSequence? = data + var icon: CharSequence? = icon } \ No newline at end of file diff --git a/app/src/main/java/com/finnmglas/launcher/choose/other/OtherRecyclerAdapter.kt b/app/src/main/java/com/finnmglas/launcher/choose/other/OtherRecyclerAdapter.kt index 7cc6329..36ab5dc 100644 --- a/app/src/main/java/com/finnmglas/launcher/choose/other/OtherRecyclerAdapter.kt +++ b/app/src/main/java/com/finnmglas/launcher/choose/other/OtherRecyclerAdapter.kt @@ -20,6 +20,7 @@ class OtherRecyclerAdapter(val activity: Activity): inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener { var textView: TextView = itemView.findViewById(R.id.row_other_name) + var iconView: FontAwesome = itemView.findViewById(R.id.row_other_fa_icon) override fun onClick(v: View) { @@ -34,9 +35,10 @@ class OtherRecyclerAdapter(val activity: Activity): override fun onBindViewHolder(viewHolder: ViewHolder, i: Int) { val otherLabel = othersList[i].label.toString() - val otherData = othersList[i].data.toString() + val icon = othersList[i].icon.toString() viewHolder.textView.text = otherLabel + viewHolder.iconView.text = icon } override fun getItemCount(): Int { return othersList.size } @@ -49,8 +51,14 @@ class OtherRecyclerAdapter(val activity: Activity): init { othersList = ArrayList() - othersList.add(OtherInfo("Launcher Settings", "launcher:settings")) - othersList.add(OtherInfo("Launcher AppsList", "launcher:choose")) + othersList.add( + OtherInfo("Launcher Settings", + "launcher:settings", + activity.getString(R.string.fas_settings))) + othersList.add( + OtherInfo("Launcher AppsList", + "launcher:choose", + activity.getString(R.string.fas_bars))) } /* */ diff --git a/app/src/main/java/com/finnmglas/launcher/settings/actions/ActionsRecyclerAdapter.kt b/app/src/main/java/com/finnmglas/launcher/settings/actions/ActionsRecyclerAdapter.kt index e6ceaa9..68649fe 100644 --- a/app/src/main/java/com/finnmglas/launcher/settings/actions/ActionsRecyclerAdapter.kt +++ b/app/src/main/java/com/finnmglas/launcher/settings/actions/ActionsRecyclerAdapter.kt @@ -27,6 +27,7 @@ class ActionsRecyclerAdapter(val activity: Activity): inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener { var textView: TextView = itemView.findViewById(R.id.row_action_name) + var fontAwesome: FontAwesome = itemView.findViewById(R.id.row_app_fa_icon) var img: ImageView = itemView.findViewById(R.id.row_app_icon) as ImageView var chooseButton: Button = itemView.findViewById(R.id.row_choose_button) var removeAction: FontAwesome = itemView.findViewById(R.id.row_remove_action) @@ -48,20 +49,44 @@ class ActionsRecyclerAdapter(val activity: Activity): val content = actionsList[i].content viewHolder.textView.text = actionText - try { - viewHolder.img.setImageDrawable(activity.packageManager.getApplicationIcon(content.toString())) - viewHolder.img.setOnClickListener{ chooseApp(actionName.toString()) } - if (getSavedTheme(activity) == "dark") transformGrayscale(viewHolder.img) + viewHolder.removeAction.setOnClickListener{ + val sharedPref = activity.getSharedPreferences( + activity.getString(R.string.preference_file_key), Context.MODE_PRIVATE) - viewHolder.removeAction.setOnClickListener{ - val sharedPref = activity.getSharedPreferences( - activity.getString(R.string.preference_file_key), Context.MODE_PRIVATE) + val editor : SharedPreferences.Editor = sharedPref.edit() + editor.putString("action_$actionName", "") // clear it + editor.apply() - val editor : SharedPreferences.Editor = sharedPref.edit() - editor.putString("action_$actionName", "") // clear it - editor.apply() + viewHolder.fontAwesome.visibility = View.INVISIBLE + viewHolder.img.visibility = View.INVISIBLE + viewHolder.removeAction.visibility = View.GONE + viewHolder.chooseButton.visibility = View.VISIBLE + viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) } + if (getSavedTheme(activity) =="custom") + setButtonColor(viewHolder.chooseButton, vibrantColor) + } + if (content!!.startsWith("launcher")) { + // Set fontAwesome icon + viewHolder.fontAwesome.visibility = View.VISIBLE + viewHolder.fontAwesome.setOnClickListener{ chooseApp(actionName.toString()) } + + when (content.split(":")[1]) { + "settings" -> + viewHolder.fontAwesome.text = activity.getString(R.string.fas_settings) + "choose" -> + viewHolder.fontAwesome.text = activity.getString(R.string.fas_bars) + } + } else { + // Set image icon (by packageName) + try { + viewHolder.img.setImageDrawable(activity.packageManager.getApplicationIcon(content.toString())) + viewHolder.img.setOnClickListener{ chooseApp(actionName.toString()) } + + if (getSavedTheme(activity) == "dark") transformGrayscale(viewHolder.img) + + } catch (e : Exception) { // the button is shown, user asked to select an action viewHolder.img.visibility = View.INVISIBLE viewHolder.removeAction.visibility = View.GONE viewHolder.chooseButton.visibility = View.VISIBLE @@ -69,14 +94,6 @@ class ActionsRecyclerAdapter(val activity: Activity): if (getSavedTheme(activity) =="custom") setButtonColor(viewHolder.chooseButton, vibrantColor) } - - } catch (e : Exception) { - viewHolder.img.visibility = View.INVISIBLE - viewHolder.removeAction.visibility = View.GONE - viewHolder.chooseButton.visibility = View.VISIBLE - viewHolder.chooseButton.setOnClickListener{ chooseApp(actionName.toString()) } - if (getSavedTheme(activity) =="custom") - setButtonColor(viewHolder.chooseButton, vibrantColor) } } diff --git a/app/src/main/res/layout/recycler_actions_row.xml b/app/src/main/res/layout/recycler_actions_row.xml index 46b7561..ac26954 100644 --- a/app/src/main/res/layout/recycler_actions_row.xml +++ b/app/src/main/res/layout/recycler_actions_row.xml @@ -30,6 +30,18 @@ app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent" /> + + + android:layout_height="wrap_content" + android:layout_margin="15sp"> + + -