Refactor: Refactor keyboard handling and UI consistency
Details: Refactored keyboard handling methods in AppHelper.kt to improve code clarity. Removed redundant showSoftKeyboard() and hideKeyboard() functions from AppHelper.kt and adjusted references accordingly. Also, ensured UI consistency by renaming search_view1 to search_view_text in fragment_draw.xml for better readability and maintained uniformity in variable naming conventions. Additionally, updated the draw_search_button FloatingActionButton attributes for visual consistency and clarity. Closes #8
This commit is contained in:
@@ -16,6 +16,11 @@ All notable changes to this project will be documented in this file. See [conven
|
|||||||
|
|
||||||
- Updated Language Files. ([#7](https://github.com/DroidWorksStudio/mLauncher/issues/7)) - ([89ef870](https://github.com/DroidWorksStudio/mLauncher/commit/89ef870cf40846216ff366e96d9f2ebb766e4a89))
|
- Updated Language Files. ([#7](https://github.com/DroidWorksStudio/mLauncher/issues/7)) - ([89ef870](https://github.com/DroidWorksStudio/mLauncher/commit/89ef870cf40846216ff366e96d9f2ebb766e4a89))
|
||||||
|
|
||||||
|
### Refactoring:
|
||||||
|
|
||||||
|
- Refactor keyboard handling and UI consistency - ([0c59747](https://github.com/DroidWorksStudio/mLauncher/commit/0c59747ff9f583e2d90c412b1c3d1f3e99751412))
|
||||||
|
- Refactored keyboard handling methods in AppHelper.kt to improve code clarity. Removed redundant showSoftKeyboard() and hideKeyboard() functions from AppHelper.kt and adjusted references accordingly. Also, ensured UI consistency by renaming search_view1 to search_view_text in fragment_draw.xml for better readability and maintained uniformity in variable naming conventions. Additionally, updated the draw_search_button FloatingActionButton attributes for visual consistency and clarity. - ([0c59747](https://github.com/DroidWorksStudio/mLauncher/commit/0c59747ff9f583e2d90c412b1c3d1f3e99751412))
|
||||||
|
|
||||||
## [0.0.1](https://github.com/DroidWorksStudio/mLauncher/tree/0.0.1) - (08, May 2024)
|
## [0.0.1](https://github.com/DroidWorksStudio/mLauncher/tree/0.0.1) - (08, May 2024)
|
||||||
|
|
||||||
### Implemented Enhancements:
|
### Implemented Enhancements:
|
||||||
|
|||||||
@@ -253,24 +253,11 @@ class AppHelper @Inject constructor() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.showSoftKeyboard() {
|
|
||||||
if (this.requestFocus()) {
|
|
||||||
val inputMethodManager: InputMethodManager =
|
|
||||||
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
||||||
inputMethodManager.showSoftInput(this, InputMethodManager.SHOW_IMPLICIT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun hideKeyboard(context: Context, view: View) {
|
fun hideKeyboard(context: Context, view: View) {
|
||||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||||
imm.hideSoftInputFromWindow(view.windowToken, 0)
|
imm.hideSoftInputFromWindow(view.windowToken, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun View.hideKeyboard() {
|
|
||||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
|
||||||
imm.hideSoftInputFromWindow(this.windowToken, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun wordOfTheDay(resources: Resources): String {
|
fun wordOfTheDay(resources: Resources): String {
|
||||||
val dailyWordsArray = resources.getStringArray(R.array.settings_appearance_daily_word_default)
|
val dailyWordsArray = resources.getStringArray(R.array.settings_appearance_daily_word_default)
|
||||||
val dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR)
|
val dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.github.droidworksstudio.launcher.ui.activities
|
package com.github.droidworksstudio.launcher.ui.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
||||||
@@ -10,7 +11,6 @@ import androidx.lifecycle.lifecycleScope
|
|||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.findNavController
|
import androidx.navigation.findNavController
|
||||||
import androidx.navigation.fragment.NavHostFragment
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.navigation.fragment.findNavController
|
|
||||||
import androidx.navigation.ui.AppBarConfiguration
|
import androidx.navigation.ui.AppBarConfiguration
|
||||||
import androidx.navigation.ui.navigateUp
|
import androidx.navigation.ui.navigateUp
|
||||||
import com.github.droidworksstudio.launcher.R
|
import com.github.droidworksstudio.launcher.R
|
||||||
@@ -74,6 +74,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun observeUI() {
|
private fun observeUI() {
|
||||||
|
binding.pager.currentItem = 0
|
||||||
preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar)
|
preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar)
|
||||||
preferenceViewModel.showStatusBarLiveData.observe(this) {
|
preferenceViewModel.showStatusBarLiveData.observe(this) {
|
||||||
if (it) appHelper.showStatusBar(this.window)
|
if (it) appHelper.showStatusBar(this.window)
|
||||||
@@ -133,6 +134,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
@Deprecated("Deprecated in Java")
|
@Deprecated("Deprecated in Java")
|
||||||
override fun onBackPressed() {
|
override fun onBackPressed() {
|
||||||
val currentItem = binding.pager.currentItem
|
val currentItem = binding.pager.currentItem
|
||||||
|
Log.d("currentItem","$currentItem")
|
||||||
val navHostFragment =
|
val navHostFragment =
|
||||||
supportFragmentManager.findFragmentById(R.id.nav_host_fragment_content_main) as NavHostFragment
|
supportFragmentManager.findFragmentById(R.id.nav_host_fragment_content_main) as NavHostFragment
|
||||||
val currentFragment = navHostFragment.childFragmentManager.fragments[0]
|
val currentFragment = navHostFragment.childFragmentManager.fragments[0]
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
|
|||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.lifecycle.coroutineScope
|
import androidx.lifecycle.coroutineScope
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.navigation.fragment.NavHostFragment
|
||||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||||
import com.github.droidworksstudio.launcher.R
|
import com.github.droidworksstudio.launcher.R
|
||||||
import com.github.droidworksstudio.launcher.data.entities.AppInfo
|
import com.github.droidworksstudio.launcher.data.entities.AppInfo
|
||||||
@@ -84,6 +85,7 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
private fun observeDrawerApps() {
|
private fun observeDrawerApps() {
|
||||||
viewModel.compareInstalledAppInfo()
|
viewModel.compareInstalledAppInfo()
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
|
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
|
||||||
viewModel.drawApps.collect{
|
viewModel.drawApps.collect{
|
||||||
drawAdapter.submitList(it)
|
drawAdapter.submitList(it)
|
||||||
@@ -93,7 +95,7 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupSearch() {
|
private fun setupSearch() {
|
||||||
binding.searchView1.addTextChangedListener(object: TextWatcher {
|
binding.searchViewText.addTextChangedListener(object: TextWatcher {
|
||||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||||
// Do Nothing
|
// Do Nothing
|
||||||
}
|
}
|
||||||
@@ -109,19 +111,20 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun observeClickListener(){
|
private fun observeClickListener(){
|
||||||
binding.drawSearchButton.setOnClickListener {appHelper.showSoftKeyboard(context, binding.searchView1)}
|
binding.drawSearchButton.setOnClickListener {appHelper.showSoftKeyboard(context, binding.searchViewText)}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchApp(query: String?) {
|
private fun searchApp(query: String?) {
|
||||||
|
|
||||||
val searchQuery = "%$query%"
|
val searchQuery = "%$query%"
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
viewLifecycleOwner.lifecycle.coroutineScope.launchWhenCreated {
|
viewLifecycleOwner.lifecycle.coroutineScope.launchWhenCreated {
|
||||||
viewModel.searchAppInfo(searchQuery).collect { drawAdapter.submitList(it) }
|
viewModel.searchAppInfo(searchQuery).collect { drawAdapter.submitList(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSelectedApp(appInfo: AppInfo) {
|
private fun showSelectedApp(appInfo: AppInfo) {
|
||||||
binding.searchView1.text?.clear()
|
binding.searchViewText.text?.clear()
|
||||||
|
|
||||||
val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo)
|
val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo)
|
||||||
bottomSheetFragment.setOnBottomSheetDismissedListener(this)
|
bottomSheetFragment.setOnBottomSheetDismissedListener(this)
|
||||||
@@ -136,18 +139,19 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
binding.searchView1.text?.clear()
|
binding.searchViewText.text?.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
observeDrawerApps()
|
observeDrawerApps()
|
||||||
binding.drawAdapter.scrollToPosition(0)
|
binding.drawAdapter.scrollToPosition(0)
|
||||||
appHelper.hideKeyboard(context, binding.searchView1)
|
appHelper.hideKeyboard(context, binding.searchView)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
|
appHelper.hideKeyboard(context, binding.searchView)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAppClicked(appInfo: AppInfo) {
|
override fun onAppClicked(appInfo: AppInfo) {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import androidx.annotation.RequiresApi
|
|||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.viewModels
|
import androidx.fragment.app.viewModels
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.navigation.findNavController
|
||||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||||
import com.github.droidworksstudio.launcher.R
|
import com.github.droidworksstudio.launcher.R
|
||||||
import com.github.droidworksstudio.launcher.accessibility.MyAccessibilityService
|
import com.github.droidworksstudio.launcher.accessibility.MyAccessibilityService
|
||||||
@@ -94,6 +95,7 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun initializeInjectedDependencies() {
|
private fun initializeInjectedDependencies() {
|
||||||
context = requireContext()
|
context = requireContext()
|
||||||
|
appHelper.hideKeyboard(context, binding.mainView)
|
||||||
|
|
||||||
binding.nestScrollView.scrollEventListener = this
|
binding.nestScrollView.scrollEventListener = this
|
||||||
|
|
||||||
@@ -153,6 +155,8 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun observeUserInterfaceSettings() {
|
private fun observeUserInterfaceSettings() {
|
||||||
|
appHelper.hideKeyboard(context, binding.mainView)
|
||||||
|
|
||||||
preferenceViewModel.setShowTime(preferenceHelper.showTime)
|
preferenceViewModel.setShowTime(preferenceHelper.showTime)
|
||||||
preferenceViewModel.setShowDate(preferenceHelper.showDate)
|
preferenceViewModel.setShowDate(preferenceHelper.showDate)
|
||||||
preferenceViewModel.setShowDailyWord(preferenceHelper.showDailyWord)
|
preferenceViewModel.setShowDailyWord(preferenceHelper.showDailyWord)
|
||||||
@@ -250,10 +254,12 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
|||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
|
appHelper.hideKeyboard(context, binding.mainView)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
appHelper.hideKeyboard(context, binding.mainView)
|
||||||
observeUserInterfaceSettings()
|
observeUserInterfaceSettings()
|
||||||
observeFavoriteAppList()
|
observeFavoriteAppList()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
tools:ignore="DuplicateClickableBoundsCheck">
|
tools:ignore="DuplicateClickableBoundsCheck">
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatEditText
|
<androidx.appcompat.widget.AppCompatEditText
|
||||||
android:id="@+id/search_view1"
|
android:id="@+id/search_view_text"
|
||||||
style="@style/TextDefaultStyle"
|
style="@style/TextDefaultStyle"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="64dp"
|
android:layout_height="64dp"
|
||||||
@@ -33,7 +33,8 @@
|
|||||||
android:hint="@string/search"
|
android:hint="@string/search"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:textSize="@dimen/text_super_large"
|
android:textSize="@dimen/text_super_large"
|
||||||
android:textStyle="normal">
|
android:textStyle="normal"
|
||||||
|
tools:ignore="VisualLintTextFieldSize">
|
||||||
|
|
||||||
</androidx.appcompat.widget.AppCompatEditText>
|
</androidx.appcompat.widget.AppCompatEditText>
|
||||||
|
|
||||||
@@ -54,16 +55,16 @@
|
|||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/draw_search_button"
|
android:id="@+id/draw_search_button"
|
||||||
|
style="@style/Widget.MaterialComponents.FloatingActionButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
style="@style/Widget.MaterialComponents.FloatingActionButton"
|
android:layout_margin="32dp"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
app:backgroundTint="@color/search_button_background"
|
|
||||||
android:src="?android:attr/actionModeWebSearchDrawable"
|
android:src="?android:attr/actionModeWebSearchDrawable"
|
||||||
|
app:backgroundTint="@color/search_button_background"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:layout_margin="32dp"
|
tools:ignore="ContentDescription,SpeakableTextPresentCheck" />
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
Reference in New Issue
Block a user