Skip to content

Commit 4aaab7c

Browse files
Refactor: Rename Favorite Apps
1 parent 8a49f4f commit 4aaab7c

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,28 @@ import androidx.lifecycle.ViewModelProvider
3030
import com.github.droidworksstudio.mlauncher.MainViewModel
3131
import com.github.droidworksstudio.mlauncher.R
3232
import com.github.droidworksstudio.mlauncher.data.Prefs
33-
import com.github.droidworksstudio.mlauncher.databinding.FragmentReorderHomeAppsBinding
33+
import com.github.droidworksstudio.mlauncher.databinding.FragmentFavoriteBinding
3434
import com.github.droidworksstudio.mlauncher.helper.getHexFontColor
3535
import com.github.droidworksstudio.mlauncher.helper.getHexForOpacity
3636
import com.github.droidworksstudio.mlauncher.helper.hideStatusBar
3737
import com.github.droidworksstudio.mlauncher.helper.showStatusBar
3838

39-
class ReorderHomeAppsFragment : Fragment() {
39+
class FavoriteFragment : Fragment() {
4040

4141
private lateinit var prefs: Prefs
4242
private lateinit var viewModel: MainViewModel
4343
private lateinit var deviceManager: DevicePolicyManager
4444
private lateinit var vibrator: Vibrator
4545

46-
private var _binding: FragmentReorderHomeAppsBinding? = null
46+
private var _binding: FragmentFavoriteBinding? = null
4747
private val binding get() = _binding!!
4848

4949
override fun onCreateView(
5050
inflater: LayoutInflater,
5151
container: ViewGroup?,
5252
savedInstanceState: Bundle?
5353
): View {
54-
_binding = FragmentReorderHomeAppsBinding.inflate(inflater, container, false)
54+
_binding = FragmentFavoriteBinding.inflate(inflater, container, false)
5555

5656
val view = binding.root
5757
prefs = Prefs(requireContext())
@@ -110,35 +110,41 @@ class ReorderHomeAppsFragment : Fragment() {
110110
// Indicate that we accept drag events
111111
return true
112112
}
113+
113114
DragEvent.ACTION_DRAG_ENTERED -> {
114115
// Highlight the target view as the drag enters
115116
targetView.setBackgroundResource(R.drawable.reorder_apps_background)
116117
return true
117118
}
119+
118120
DragEvent.ACTION_DRAG_EXITED -> {
119121
// Remove highlighting when the drag exits
120122
targetView.background = null
121123
return true
122124
}
125+
123126
DragEvent.ACTION_DROP -> {
124127
// Remove highlighting
125128
targetView.background = null
126-
129+
127130
// Extract the dragged TextView
128131
val draggedTextView = event.localState as TextView
129132

130133
// Reorder apps based on the drop position
131-
val draggedIndex = (draggedTextView.parent as ViewGroup).indexOfChild(draggedTextView)
134+
val draggedIndex =
135+
(draggedTextView.parent as ViewGroup).indexOfChild(draggedTextView)
132136
val targetIndex = (targetView.parent as ViewGroup).indexOfChild(targetView)
133137
reorderApps(draggedIndex, targetIndex)
134138

135139
return true
136140
}
141+
137142
DragEvent.ACTION_DRAG_ENDED -> {
138143
// Remove highlighting when the drag ends
139144
targetView.background = null
140145
return true
141146
}
147+
142148
else -> return false
143149
}
144150
}
@@ -149,7 +155,10 @@ class ReorderHomeAppsFragment : Fragment() {
149155
targetIndex < 0 || targetIndex >= binding.homeAppsLayout.childCount
150156
) {
151157
// Handle out of bounds indices gracefully, or log an error
152-
Log.e("ReorderApps", "Invalid indices: draggedIndex=$draggedIndex, targetIndex=$targetIndex")
158+
Log.e(
159+
"ReorderApps",
160+
"Invalid indices: draggedIndex=$draggedIndex, targetIndex=$targetIndex"
161+
)
153162
return
154163
}
155164

@@ -182,12 +191,14 @@ class ReorderHomeAppsFragment : Fragment() {
182191
if (diff in 1 until oldAppsNum) { // 1 <= diff <= oldNumApps
183192
binding.homeAppsLayout.children.drop(diff)
184193
} else if (diff < 0) {
185-
val prefixDrawable: Drawable? = context?.let { ContextCompat.getDrawable(it, R.drawable.ic_prefix_drawable) }
194+
val prefixDrawable: Drawable? =
195+
context?.let { ContextCompat.getDrawable(it, R.drawable.ic_prefix_drawable) }
186196
// add all missing apps to list
187197
for (i in oldAppsNum until newAppsNum) {
188198
val view = layoutInflater.inflate(R.layout.home_app_button, null) as TextView
189199
view.apply {
190-
val appLabel = prefs.getHomeAppModel(i).activityLabel.ifEmpty { getString(R.string.app) }
200+
val appLabel =
201+
prefs.getHomeAppModel(i).activityLabel.ifEmpty { getString(R.string.app) }
191202
textSize = prefs.appSize.toFloat()
192203
id = i
193204
text = " $appLabel"
@@ -201,7 +212,7 @@ class ReorderHomeAppsFragment : Fragment() {
201212
}
202213
val padding: Int = prefs.textPaddingSize
203214
view.setPadding(0, padding, 0, padding)
204-
binding.pageName.text = getString(R.string.reorder_apps)
215+
binding.pageName.text = getString(R.string.favorite_apps)
205216
binding.pageName.textSize = prefs.appSize * 1.5f
206217

207218
if (prefs.followAccentColors) {

app/src/main/res/layout/fragment_reorder_home_apps.xml renamed to app/src/main/res/layout/fragment_favorite.xml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
android:layout_height="match_parent"
77
android:animateLayoutChanges="true"
88
android:orientation="vertical"
9-
tools:context=".ui.ReorderHomeAppsFragment">
9+
tools:context=".ui.FavoriteFragment">
1010

1111
<FrameLayout
1212
android:id="@+id/touchArea"
13-
android:layout_marginTop="50dp"
14-
android:layout_marginBottom="50dp"
1513
android:layout_width="match_parent"
16-
android:layout_height="match_parent"/>
14+
android:layout_height="match_parent"
15+
android:layout_marginTop="50dp"
16+
android:layout_marginBottom="50dp" />
1717

1818
<LinearLayout
1919
android:id="@+id/pageLayout"
@@ -46,8 +46,8 @@
4646
android:gravity="center_vertical"
4747
android:orientation="vertical"
4848
android:paddingHorizontal="20dp"
49-
android:paddingBottom="80dp"
50-
android:paddingTop="112dp" />
49+
android:paddingTop="112dp"
50+
android:paddingBottom="80dp" />
5151

5252
</ScrollView>
5353
</LinearLayout>

app/src/main/res/navigation/nav_graph.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444

4545
<fragment
4646
android:id="@+id/appListReorderFragment"
47-
android:name="com.github.droidworksstudio.mlauncher.ui.ReorderHomeAppsFragment"
47+
android:name="com.github.droidworksstudio.mlauncher.ui.FavoriteFragment"
4848
android:label="app_list_fragment"
49-
tools:layout="@layout/fragment_reorder_home_apps">
50-
</fragment>
49+
tools:layout="@layout/fragment_favorite"></fragment>
5150

5251
<fragment
5352
android:id="@+id/settingsFragment"

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<!-- Home Strings -->
1818
<string name="hidden_apps">Hidden Apps</string>
19-
<string name="reorder_apps">Re-Order Apps</string>
19+
<string name="favorite_apps">Re-Order Apps</string>
2020
<string name="set_as_default_launcher">Set as Default Launcher</string>
2121
<string name="change_default_launcher">Change Default Launcher</string>
2222

0 commit comments

Comments
 (0)