Fixed bugs with shortcut selection:

- Incorrect drawable alignment
- Action menu working in shortcut selection view
This commit is contained in:
ottoptj 2024-08-10 21:27:01 +03:00
commit 3b3f9d716a
4 changed files with 85 additions and 60 deletions

View file

@ -22,14 +22,14 @@ class Animations (context: Context) {
fun fadeViewOut(view: View, duration: Long = 100) { fun fadeViewOut(view: View, duration: Long = 100) {
view.fadeOut(duration) view.fadeOut(duration)
} }
fun showHome(binding: ActivityMainBinding) { fun showHome(homeView: View, appView: View) {
binding.appView.slideOutToBottom() appView.slideOutToBottom()
binding.homeView.fadeIn() homeView.fadeIn()
} }
fun showApps(binding: ActivityMainBinding) { fun showApps(homeView: View, appView: View) {
binding.appView.slideInFromBottom() appView.slideInFromBottom()
binding.homeView.fadeOut() homeView.fadeOut()
} }
fun backgroundIn(activity: Activity, duration: Long = 100) { fun backgroundIn(activity: Activity, duration: Long = 100) {

View file

@ -52,7 +52,8 @@ class AppMenuAdapter(
textView: TextView, textView: TextView,
actionMenuLayout: LinearLayout, actionMenuLayout: LinearLayout,
editView: LinearLayout, editView: LinearLayout,
position: Int position: Int,
shortcutTextView: TextView?
) )
} }
@ -78,25 +79,24 @@ class AppMenuAdapter(
} }
} }
if (shortcutTextView == null) {
textView.setOnLongClickListener {
val position = bindingAdapterPosition
val app = apps[position].first
itemLongClickListener.onItemLongClick(
app,
apps[position].second.first,
apps[position].second.second,
textView,
actionMenuLayout,
editView,
position
)
return@setOnLongClickListener true
}
textView.setOnLongClickListener {
val position = bindingAdapterPosition
val app = apps[position].first
itemLongClickListener.onItemLongClick(
app,
apps[position].second.first,
apps[position].second.second,
textView,
actionMenuLayout,
editView,
position,
shortcutTextView
)
return@setOnLongClickListener true
} }
} }
} }

View file

@ -155,7 +155,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
uiUtils.setClockSize(clock) uiUtils.setClockSize(clock)
uiUtils.setDateSize(dateText) uiUtils.setDateSize(dateText)
uiUtils.setShortcutSize(binding.homeView) uiUtils.setShortcutsSize(binding.homeView)
uiUtils.setSearchSize(searchView) uiUtils.setSearchSize(searchView)
uiUtils.setStatusBar(window) uiUtils.setStatusBar(window)
@ -188,7 +188,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
setShortcutSetup(textView, savedView) setShortcutSetup(textView, savedView)
} }
uiUtils.setShortcutAlignment(binding.homeView) uiUtils.setShortcutsAlignment(binding.homeView)
} }
} }
@ -223,7 +223,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
private fun toAppMenu() { private fun toAppMenu() {
animations.showApps(binding) animations.showApps(binding.homeView, binding.appView)
animations.backgroundIn(this@MainActivity) animations.backgroundIn(this@MainActivity)
if (sharedPreferenceManager.isAutoKeyboardEnabled()) { if (sharedPreferenceManager.isAutoKeyboardEnabled()) {
val imm = val imm =
@ -309,7 +309,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
"shortcutAlignment" -> { "shortcutAlignment" -> {
uiUtils.setShortcutAlignment(binding.homeView) uiUtils.setShortcutsAlignment(binding.homeView)
} }
"searchAlignment" -> { "searchAlignment" -> {
@ -325,7 +325,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
} }
"shortcutSize" -> { "shortcutSize" -> {
uiUtils.setShortcutSize(binding.homeView) uiUtils.setShortcutsSize(binding.homeView)
} }
"searchSize" -> { "searchSize" -> {
@ -368,7 +368,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
fun backToHome() { fun backToHome() {
closeKeyboard() closeKeyboard()
animations.showHome(binding) animations.showHome(binding.homeView, binding.appView)
animations.backgroundOut(this@MainActivity) animations.backgroundOut(this@MainActivity)
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
handler.postDelayed({ handler.postDelayed({
@ -623,6 +623,7 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
appInfo.applicationInfo.packageName, appInfo.applicationInfo.packageName,
userProfile userProfile
) )
uiUtils.setShortcutDrawables(shortcutView, sharedPreferenceManager.getShortcutAlignment())
backToHome() backToHome()
} }
@ -634,8 +635,13 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
textView: TextView, textView: TextView,
actionMenuLayout: LinearLayout, actionMenuLayout: LinearLayout,
editView: LinearLayout, editView: LinearLayout,
position: Int position: Int,
shortcutTextView: TextView?
) { ) {
if (shortcutTextView != null) {
onShortcut(appInfo, userHandle, textView, userProfile, shortcutTextView)
return
}
textView.visibility = View.INVISIBLE textView.visibility = View.INVISIBLE
animations.fadeViewIn(actionMenuLayout) animations.fadeViewIn(actionMenuLayout)
val mainActivity = val mainActivity =

View file

@ -94,45 +94,64 @@ class UIUtils(private val context: Context) {
setTextAlignment(dateText, alignment) setTextAlignment(dateText, alignment)
} }
fun setShortcutAlignment(shortcuts: LinearLayout) { fun setShortcutsAlignment(shortcuts: LinearLayout) {
val alignment = sharedPreferenceManager.getShortcutAlignment()
shortcuts.children.forEach { shortcuts.children.forEach {
if (it is TextView) { if (it is TextView) {
try { try {
when (sharedPreferenceManager.getShortcutAlignment()) { setShortcutAlignment(it, alignment)
"left" -> { setShortcutDrawables(it, alignment)
it.setCompoundDrawablesWithIntrinsicBounds(
it.compoundDrawables.filterNotNull().first(), null, null, null
)
it.gravity = Gravity.CENTER_VERTICAL or Gravity.START
}
"center" -> {
it.setCompoundDrawablesWithIntrinsicBounds(
it.compoundDrawables.filterNotNull().first(),
null,
it.compoundDrawables.filterNotNull().first(),
null
)
it.gravity = Gravity.CENTER
}
"right" -> {
it.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
it.compoundDrawables.filterNotNull().first(),
null
)
it.gravity = Gravity.CENTER_VERTICAL or Gravity.END
}
}
} catch(_: Exception) {} } catch(_: Exception) {}
} }
} }
} }
fun setShortcutAlignment(shortcut: TextView, alignment: String?) {
when (alignment) {
"left" -> {
shortcut.gravity = Gravity.CENTER_VERTICAL or Gravity.START
}
"center" -> {
shortcut.gravity = Gravity.CENTER
}
"right" -> {
shortcut.gravity = Gravity.CENTER_VERTICAL or Gravity.END
}
}
}
fun setShortcutDrawables(shortcut: TextView, alignment: String?) {
when (alignment) {
"left" -> {
shortcut.setCompoundDrawablesWithIntrinsicBounds(
shortcut.compoundDrawables.filterNotNull().first(), null, null, null
)
}
"center" -> {
shortcut.setCompoundDrawablesWithIntrinsicBounds(
shortcut.compoundDrawables.filterNotNull().first(),
null,
shortcut.compoundDrawables.filterNotNull().first(),
null
)
}
"right" -> {
shortcut.setCompoundDrawablesWithIntrinsicBounds(
null,
null,
shortcut.compoundDrawables.filterNotNull().first(),
null
)
}
}
}
fun setAppAlignment( fun setAppAlignment(
textView: TextView, textView: TextView,
editText: TextInputEditText? = null, editText: TextInputEditText? = null,
@ -207,7 +226,7 @@ class UIUtils(private val context: Context) {
setTextSize(dateText, sharedPreferenceManager.getDateSize(), 17F, 20F, 23F) setTextSize(dateText, sharedPreferenceManager.getDateSize(), 17F, 20F, 23F)
} }
fun setShortcutSize(shortcuts: LinearLayout) { fun setShortcutsSize(shortcuts: LinearLayout) {
val viewTreeObserver = shortcuts.viewTreeObserver val viewTreeObserver = shortcuts.viewTreeObserver
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener { val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {