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:
@@ -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) {
|
||||
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
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 {
|
||||
val dailyWordsArray = resources.getStringArray(R.array.settings_appearance_daily_word_default)
|
||||
val dayOfYear = Calendar.getInstance().get(Calendar.DAY_OF_YEAR)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.github.droidworksstudio.launcher.ui.activities
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
||||
@@ -10,7 +11,6 @@ import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.NavController
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.ui.AppBarConfiguration
|
||||
import androidx.navigation.ui.navigateUp
|
||||
import com.github.droidworksstudio.launcher.R
|
||||
@@ -74,6 +74,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun observeUI() {
|
||||
binding.pager.currentItem = 0
|
||||
preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar)
|
||||
preferenceViewModel.showStatusBarLiveData.observe(this) {
|
||||
if (it) appHelper.showStatusBar(this.window)
|
||||
@@ -133,6 +134,7 @@ class MainActivity : AppCompatActivity() {
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onBackPressed() {
|
||||
val currentItem = binding.pager.currentItem
|
||||
Log.d("currentItem","$currentItem")
|
||||
val navHostFragment =
|
||||
supportFragmentManager.findFragmentById(R.id.nav_host_fragment_content_main) as NavHostFragment
|
||||
val currentFragment = navHostFragment.childFragmentManager.fragments[0]
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.NavHostFragment
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.github.droidworksstudio.launcher.R
|
||||
import com.github.droidworksstudio.launcher.data.entities.AppInfo
|
||||
@@ -84,6 +85,7 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
private fun observeDrawerApps() {
|
||||
viewModel.compareInstalledAppInfo()
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
|
||||
viewModel.drawApps.collect{
|
||||
drawAdapter.submitList(it)
|
||||
@@ -93,7 +95,7 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
}
|
||||
|
||||
private fun setupSearch() {
|
||||
binding.searchView1.addTextChangedListener(object: TextWatcher {
|
||||
binding.searchViewText.addTextChangedListener(object: TextWatcher {
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
|
||||
// Do Nothing
|
||||
}
|
||||
@@ -109,19 +111,20 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
}
|
||||
|
||||
private fun observeClickListener(){
|
||||
binding.drawSearchButton.setOnClickListener {appHelper.showSoftKeyboard(context, binding.searchView1)}
|
||||
binding.drawSearchButton.setOnClickListener {appHelper.showSoftKeyboard(context, binding.searchViewText)}
|
||||
}
|
||||
|
||||
private fun searchApp(query: String?) {
|
||||
|
||||
val searchQuery = "%$query%"
|
||||
@Suppress("DEPRECATION")
|
||||
viewLifecycleOwner.lifecycle.coroutineScope.launchWhenCreated {
|
||||
viewModel.searchAppInfo(searchQuery).collect { drawAdapter.submitList(it) }
|
||||
}
|
||||
}
|
||||
|
||||
private fun showSelectedApp(appInfo: AppInfo) {
|
||||
binding.searchView1.text?.clear()
|
||||
binding.searchViewText.text?.clear()
|
||||
|
||||
val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo)
|
||||
bottomSheetFragment.setOnBottomSheetDismissedListener(this)
|
||||
@@ -136,18 +139,19 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
binding.searchView1.text?.clear()
|
||||
binding.searchViewText.text?.clear()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
observeDrawerApps()
|
||||
binding.drawAdapter.scrollToPosition(0)
|
||||
appHelper.hideKeyboard(context, binding.searchView1)
|
||||
appHelper.hideKeyboard(context, binding.searchView)
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
appHelper.hideKeyboard(context, binding.searchView)
|
||||
}
|
||||
|
||||
override fun onAppClicked(appInfo: AppInfo) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.findNavController
|
||||
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||
import com.github.droidworksstudio.launcher.R
|
||||
import com.github.droidworksstudio.launcher.accessibility.MyAccessibilityService
|
||||
@@ -94,6 +95,7 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun initializeInjectedDependencies() {
|
||||
context = requireContext()
|
||||
appHelper.hideKeyboard(context, binding.mainView)
|
||||
|
||||
binding.nestScrollView.scrollEventListener = this
|
||||
|
||||
@@ -153,6 +155,8 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
}
|
||||
|
||||
private fun observeUserInterfaceSettings() {
|
||||
appHelper.hideKeyboard(context, binding.mainView)
|
||||
|
||||
preferenceViewModel.setShowTime(preferenceHelper.showTime)
|
||||
preferenceViewModel.setShowDate(preferenceHelper.showDate)
|
||||
preferenceViewModel.setShowDailyWord(preferenceHelper.showDailyWord)
|
||||
@@ -250,10 +254,12 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener,
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
appHelper.hideKeyboard(context, binding.mainView)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
appHelper.hideKeyboard(context, binding.mainView)
|
||||
observeUserInterfaceSettings()
|
||||
observeFavoriteAppList()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user