Skip to content

Commit e049de0

Browse files
Feature: Added the ability for home app to be at bottom.
1 parent 02b778a commit e049de0

File tree

10 files changed

+79
-6
lines changed

10 files changed

+79
-6
lines changed

app/src/main/java/com/github/droidworksstudio/launcher/helper/BottomDialogHelper.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import javax.inject.Inject
1010

1111
class BottomDialogHelper @Inject constructor() {
1212

13+
@Suppress("DEPRECATION")
1314
fun setupDialogStyle(dialog: Dialog?) {
1415

1516
val window = dialog?.window
1617
if (window != null) {
1718
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
18-
@Suppress("DEPRECATION")
1919
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
2020
window.statusBarColor = Color.TRANSPARENT
2121
}

app/src/main/java/com/github/droidworksstudio/launcher/helper/PreferenceHelper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ class PreferenceHelper @Inject constructor(@ApplicationContext context: Context)
175175
get() = prefs.getInt(Constants.WIDGET_BATTERY, 2)
176176
set(value) = prefs.edit().putInt(Constants.WIDGET_BATTERY, value).apply()
177177

178+
var homeAlignmentBottom: Boolean
179+
get() = prefs.getBoolean(Constants.HOME_ALLIGNMENT_BOTTOM, false)
180+
set(value) = prefs.edit().putBoolean(Constants.HOME_ALLIGNMENT_BOTTOM, value).apply()
181+
178182
var settingsLock: Boolean
179183
get() = prefs.getBoolean(Constants.TOGGLE_SETTING_LOCK, false)
180184
set(value) = prefs.edit().putBoolean(Constants.TOGGLE_SETTING_LOCK, value).apply()

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.Context
66
import android.content.Intent
77
import android.content.IntentFilter
88
import android.content.pm.PackageManager
9+
import android.graphics.Color
910
import android.os.BatteryManager
1011
import android.os.Build
1112
import android.os.Bundle
@@ -188,8 +189,26 @@ class HomeFragment : Fragment(),
188189
ViewGroup.LayoutParams.WRAP_CONTENT
189190
)
190191

191-
// Set the bottom margin instead of top
192-
layoutParams.topMargin = marginInPixels.toInt()
192+
// Determine the gravity and margin based on the alignment preference
193+
val gravity = if (preferenceHelper.homeAlignmentBottom)
194+
Gravity.BOTTOM
195+
else
196+
Gravity.TOP
197+
198+
// Apply the margin and gravity
199+
val parentLayout = binding.appListTouchArea
200+
val params = parentLayout.layoutParams.apply {
201+
height = ViewGroup.LayoutParams.MATCH_PARENT
202+
}
203+
parentLayout.layoutParams = params
204+
parentLayout.gravity = gravity
205+
206+
// Set the appropriate margin based on the alignment
207+
if (preferenceHelper.homeAlignmentBottom)
208+
layoutParams.bottomMargin = marginInPixels.toInt()
209+
else
210+
layoutParams.topMargin = marginInPixels.toInt()
211+
193212

194213
// Set gravity to align RecyclerView to the bottom
195214
layoutParams.gravity = when (preferenceHelper.homeAppAlignment) {
@@ -231,6 +250,9 @@ class HomeFragment : Fragment(),
231250
clock.setOnClickListener { context.launchClock() }
232251
date.setOnClickListener { context.launchCalendar() }
233252
battery.setOnClickListener { context.openBatteryManager() }
253+
254+
touchArea.setBackgroundColor(Color.parseColor("#00FFFF"))
255+
appListTouchArea.setBackgroundColor(Color.parseColor("#FF00FF"))
234256
}
235257
}
236258

app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeViewHolder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.droidworksstudio.launcher.ui.home
22

33
import android.annotation.SuppressLint
44
import android.content.pm.PackageManager
5+
import android.graphics.Color
56
import android.graphics.drawable.Drawable
67
import android.view.Gravity
78
import android.view.View
@@ -27,6 +28,7 @@ class HomeViewHolder @Inject constructor(
2728
@SuppressLint("ClickableViewAccessibility")
2829
fun bind(appInfo: AppInfo) {
2930
binding.apply {
31+
itemView.setBackgroundColor(Color.parseColor("#0000FF"))
3032
// Get the current LayoutParams of appHiddenName
3133
val layoutAppNameParams = appHomeName.layoutParams as LinearLayoutCompat.LayoutParams
3234

app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsFeaturesFragment.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,12 @@ class SettingsFeaturesFragment : Fragment(),
363363
appHelper.triggerHapticFeedback(context, feedbackType)
364364
}
365365

366+
homeAlignmentBottomSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
367+
preferenceViewModel.setHomeAlignmentBottom(isChecked)
368+
val feedbackType = if (isChecked) "on" else "off"
369+
appHelper.triggerHapticFeedback(context, feedbackType)
370+
}
371+
366372
disableAnimationsSwitchCompat.setOnCheckedChangeListener { _, isChecked ->
367373
preferenceViewModel.setDisableAnimations(isChecked)
368374
val feedbackType = if (isChecked) "on" else "off"

app/src/main/java/com/github/droidworksstudio/launcher/utils/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ object Constants {
6363
const val AUTOMATIC_OPEN_APP = "AUTOMATIC_OPEN_APP"
6464
const val SEARCH_FROM_START = "SEARCH_FROM_START"
6565
const val FILTER_STRENGTH = "FILTER_STRENGTH"
66+
const val HOME_ALLIGNMENT_BOTTOM = "HOME_ALLIGNMENT_BOTTOM"
6667
const val TOGGLE_SETTING_LOCK = "TOGGLE_SETTING_LOCK"
6768
const val DISABLE_ANIMATIONS = "DISABLE_ANIMATIONS"
6869

app/src/main/java/com/github/droidworksstudio/launcher/viewmodel/PreferenceViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class PreferenceViewModel @Inject constructor(
4444
private val dailyWordTextSizeLiveData: MutableLiveData<Float> = MutableLiveData()
4545
private val autoOpenAppsLiveData: MutableLiveData<Boolean> = MutableLiveData()
4646
private val searchFromStartLiveData: MutableLiveData<Boolean> = MutableLiveData()
47+
private val homeAlignmentBottomLiveData: MutableLiveData<Boolean> = MutableLiveData()
4748
private val autoKeyboardLiveData: MutableLiveData<Boolean> = MutableLiveData()
4849
private val lockSettingsLiveData: MutableLiveData<Boolean> = MutableLiveData()
4950
private val disableAnimationsLiveData: MutableLiveData<Boolean> = MutableLiveData()
@@ -269,6 +270,11 @@ class PreferenceViewModel @Inject constructor(
269270
autoOpenAppsLiveData.postValue((preferenceHelper.automaticOpenApp))
270271
}
271272

273+
fun setHomeAlignmentBottom(homeAlignmentBottom: Boolean) {
274+
preferenceHelper.homeAlignmentBottom = homeAlignmentBottom
275+
homeAlignmentBottomLiveData.postValue((preferenceHelper.homeAlignmentBottom))
276+
}
277+
272278
fun setSearchFromStart(searchFromStart: Boolean) {
273279
preferenceHelper.searchFromStart = searchFromStart
274280
searchFromStartLiveData.postValue((preferenceHelper.searchFromStart))

app/src/main/res/layout/fragment_home.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<com.github.droidworksstudio.launcher.view.GestureNestedScrollView
1919
android:id="@+id/nestScrollView"
2020
android:layout_width="match_parent"
21-
android:layout_height="wrap_content"
21+
android:layout_height="match_parent"
2222
android:clipChildren="false"
2323
android:clipToPadding="false"
2424
android:fadingEdgeLength="48dp"
@@ -34,7 +34,6 @@
3434
android:id="@+id/mainView"
3535
android:layout_width="match_parent"
3636
android:layout_height="match_parent"
37-
android:layout_marginHorizontal="20dp"
3837
android:layout_marginVertical="32dp"
3938
android:orientation="vertical">
4039

@@ -105,7 +104,8 @@
105104
<androidx.recyclerview.widget.RecyclerView
106105
android:id="@+id/appListAdapter"
107106
android:layout_width="wrap_content"
108-
android:layout_height="wrap_content" />
107+
android:layout_height="wrap_content"
108+
android:layout_marginHorizontal="20dp" />
109109

110110
</androidx.appcompat.widget.LinearLayoutCompat>
111111
</androidx.appcompat.widget.LinearLayoutCompat>

app/src/main/res/layout/fragment_settings_features.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,37 @@
153153

154154
</androidx.appcompat.widget.LinearLayoutCompat>
155155

156+
<androidx.appcompat.widget.LinearLayoutCompat
157+
android:layout_width="match_parent"
158+
android:layout_height="wrap_content"
159+
android:orientation="horizontal"
160+
tools:ignore="MissingConstraints">
161+
162+
<androidx.appcompat.widget.AppCompatTextView
163+
android:id="@+id/homeAlignmentBottom_text"
164+
style="@style/TextDefaultStyle"
165+
android:layout_width="0dp"
166+
android:layout_height="wrap_content"
167+
android:layout_weight="1"
168+
android:gravity="left|center"
169+
android:text="@string/settings_home_alignment_bottom"
170+
android:textSize="@dimen/text_large"
171+
app:layout_constraintStart_toStartOf="parent"
172+
app:layout_constraintTop_toTopOf="parent"
173+
tools:ignore="RtlHardcoded" />
174+
175+
<androidx.appcompat.widget.SwitchCompat
176+
android:id="@+id/homeAlignmentBottom_switchCompat"
177+
android:layout_width="wrap_content"
178+
android:layout_height="wrap_content"
179+
android:scaleX="0.7"
180+
android:scaleY="0.8"
181+
android:thumb="@drawable/shape_switch_thumb"
182+
app:track="@drawable/selector_switch"
183+
tools:ignore="TouchTargetSizeCheck" />
184+
185+
</androidx.appcompat.widget.LinearLayoutCompat>
186+
156187
<androidx.appcompat.widget.LinearLayoutCompat
157188
android:layout_width="match_parent"
158189
android:layout_height="wrap_content"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
<string name="settings_display_app_icons">Show App Icons</string>
101101
<string name="settings_display_automatic_keyboard">Auto Show Keyboard</string>
102102
<string name="settings_display_auto_open_apps">Auto Open Last App</string>
103+
<string name="settings_home_alignment_bottom">Home Alignment Bottom</string>
103104
<string name="settings_search_from_start">Search From Start</string>
104105
<string name="settings_display_lock_settings">Lock Settings</string>
105106
<string name="settings_display_disable_animations">Disable Animations</string>

0 commit comments

Comments
 (0)