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) {
view.fadeOut(duration)
}
fun showHome(binding: ActivityMainBinding) {
binding.appView.slideOutToBottom()
binding.homeView.fadeIn()
fun showHome(homeView: View, appView: View) {
appView.slideOutToBottom()
homeView.fadeIn()
}
fun showApps(binding: ActivityMainBinding) {
binding.appView.slideInFromBottom()
binding.homeView.fadeOut()
fun showApps(homeView: View, appView: View) {
appView.slideInFromBottom()
homeView.fadeOut()
}
fun backgroundIn(activity: Activity, duration: Long = 100) {

View file

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

View file

@ -94,45 +94,64 @@ class UIUtils(private val context: Context) {
setTextAlignment(dateText, alignment)
}
fun setShortcutAlignment(shortcuts: LinearLayout) {
fun setShortcutsAlignment(shortcuts: LinearLayout) {
val alignment = sharedPreferenceManager.getShortcutAlignment()
shortcuts.children.forEach {
if (it is TextView) {
try {
when (sharedPreferenceManager.getShortcutAlignment()) {
"left" -> {
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
}
}
setShortcutAlignment(it, alignment)
setShortcutDrawables(it, alignment)
} 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(
textView: TextView,
editText: TextInputEditText? = null,
@ -207,7 +226,7 @@ class UIUtils(private val context: Context) {
setTextSize(dateText, sharedPreferenceManager.getDateSize(), 17F, 20F, 23F)
}
fun setShortcutSize(shortcuts: LinearLayout) {
fun setShortcutsSize(shortcuts: LinearLayout) {
val viewTreeObserver = shortcuts.viewTreeObserver
val globalLayoutListener = object : ViewTreeObserver.OnGlobalLayoutListener {