Skip to content

Commit 9ada91e

Browse files
refactor(performance): Make AppViewHolder a static nested class
The `AppViewHolder` in `FavoriteAdapter` has been converted from an `inner` class to a static nested class. This is a performance optimization that prevents the `AppViewHolder` from holding an implicit reference to the outer `FavoriteAdapter` instance, reducing potential memory leaks. Additionally, a minor refinement has been made in `HomeFragment`: - A placeholder text "Select an app" is now displayed for newly added home screen app slots until an app is chosen. - The inflated `TextView` has been renamed from `view` to the more descriptive `homeAppLabel` for better code clarity.
1 parent 3217910 commit 9ada91e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/HomeFragment.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -987,11 +987,15 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
987987
if (diff > 0) {
988988
// Add new apps
989989
for (i in oldAppsNum until newAppsNum) {
990-
val view = layoutInflater.inflate(R.layout.home_app_button, null) as TextView
991-
view.apply {
990+
val homeAppLabel = layoutInflater.inflate(R.layout.home_app_button, null) as TextView
991+
homeAppLabel.apply {
992992
textSize = prefs.appSize.toFloat()
993993
id = i
994-
text = prefs.getHomeAppModel(i).activityLabel
994+
text = if (prefs.getHomeAppModel(i).activityPackage.isBlank()) {
995+
getLocalizedString(R.string.select_app)
996+
} else {
997+
prefs.getHomeAppModel(i).activityLabel
998+
}
995999
getHomeAppsGestureListener()
9961000
setOnClickListener(this@HomeFragment)
9971001

@@ -1140,7 +1144,7 @@ class HomeFragment : BaseFragment(), View.OnClickListener, View.OnLongClickListe
11401144
}
11411145
}
11421146
// Add the view to the layout
1143-
binding.homeAppsLayout.addView(view)
1147+
binding.homeAppsLayout.addView(homeAppLabel)
11441148
}
11451149
} else if (diff < 0) {
11461150
// Remove extra apps

app/src/main/java/com/github/droidworksstudio/mlauncher/ui/adapter/FavoriteAdapter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class FavoriteAdapter(
2222
private val prefs: Prefs
2323
) : RecyclerView.Adapter<FavoriteAdapter.AppViewHolder>() {
2424

25-
inner class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
25+
class AppViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
2626
val appTextView: TextView = itemView.findViewById(R.id.homeAppLabel)
2727
}
2828

0 commit comments

Comments
 (0)