From 8b1c0a390de1bf3ab7bb9f6162adfb68257ba1fc Mon Sep 17 00:00:00 2001 From: HeCodes2Much Date: Sat, 25 May 2024 17:47:02 +0100 Subject: [PATCH] Refactor: Worked out a better way for moving around the app. Changed from using ViewPager2 for changing apps of the app. Added animations for changing to different fragments of the app --- app/src/main/AndroidManifest.xml | 16 ++-- .../droidworksstudio/launcher/Constants.kt | 1 - ...cessibilityService.kt => ActionService.kt} | 9 ++- .../launcher/helper/AppHelper.kt | 10 +-- .../launcher/helper/FingerprintHelper.kt | 66 ++++++++++------ .../launcher/listener/OnSwipeTouchListener.kt | 1 + .../launcher/ui/activities/MainActivity.kt | 5 +- .../ui/activities/SettingsActivity.kt | 74 ----------------- .../launcher/ui/drawer/DrawAdapter.kt | 16 ++-- .../launcher/ui/drawer/DrawFragment.kt | 6 +- .../launcher/ui/drawer/DrawViewHolder.kt | 10 ++- .../launcher/ui/favorite/FavoriteAdapter.kt | 7 +- .../launcher/ui/favorite/FavoriteFragment.kt | 35 ++++++-- .../ui/favorite/FavoriteViewHolder.kt | 9 ++- .../launcher/ui/hidden/HiddenFragment.kt | 26 +++++- .../launcher/ui/hidden/HiddenViewHolder.kt | 30 +++---- .../launcher/ui/home/HomeAdapter.kt | 18 +++-- .../launcher/ui/home/HomeFragment.kt | 53 +++++++------ .../launcher/ui/home/HomeViewHolder.kt | 24 ++++-- .../launcher/ui/settings/SettingsFragment.kt | 30 ++++++- .../ui/widgetmanager/WidgetManagerFragment.kt | 79 ++++++++++--------- .../WidgetOptionsDialogFragment.kt | 7 +- .../launcher/view/GestureNestedScrollView.kt | 3 +- app/src/main/res/layout/activity_settings.xml | 11 --- app/src/main/res/layout/content_settings.xml | 20 ----- app/src/main/res/layout/fragment_draw.xml | 12 ++- app/src/main/res/layout/fragment_favorite.xml | 15 +++- app/src/main/res/layout/fragment_hidden.xml | 14 +++- app/src/main/res/layout/fragment_home.xml | 14 +++- app/src/main/res/layout/fragment_settings.xml | 9 ++- .../res/layout/fragment_widget_manager.xml | 16 ++-- app/src/main/res/values/strings.xml | 6 +- 32 files changed, 361 insertions(+), 291 deletions(-) rename app/src/main/java/com/github/droidworksstudio/launcher/accessibility/{MyAccessibilityService.kt => ActionService.kt} (90%) delete mode 100644 app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/SettingsActivity.kt delete mode 100644 app/src/main/res/layout/activity_settings.xml delete mode 100644 app/src/main/res/layout/content_settings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c08fa852..903025bb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,7 +4,8 @@ - @@ -13,11 +14,11 @@ tools:ignore="QueryAllPackagesPermission" /> - - @@ -34,10 +35,6 @@ android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/Theme.Launcher"> - - + = WeakReference(null) - fun instance(): MyAccessibilityService? { + private var mInstance: WeakReference = WeakReference(null) + fun instance(): ActionService? { return mInstance.get() } } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt b/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt index cc02f9a9..0516837a 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt @@ -27,7 +27,7 @@ import androidx.appcompat.widget.LinearLayoutCompat import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.github.droidworksstudio.launcher.Constants import com.github.droidworksstudio.launcher.R -import com.github.droidworksstudio.launcher.accessibility.MyAccessibilityService +import com.github.droidworksstudio.launcher.accessibility.ActionService import com.github.droidworksstudio.launcher.data.entities.AppInfo import com.github.droidworksstudio.launcher.ui.activities.FakeHomeActivity import java.util.Calendar @@ -95,8 +95,8 @@ class AppHelper @Inject constructor() { .invoke(context.getSystemService(Constants.NOTIFICATION_SERVICE)) } catch (exception: Exception) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - MyAccessibilityService.runAccessibilityMode(context) - MyAccessibilityService.instance()?.openNotifications() + ActionService.runAccessibilityMode(context) + ActionService.instance()?.openNotifications() } exception.printStackTrace() } @@ -110,8 +110,8 @@ class AppHelper @Inject constructor() { .invoke(context.getSystemService(Constants.QUICKSETTINGS_SERVICE)) } catch (exception: Exception) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { - MyAccessibilityService.runAccessibilityMode(context) - MyAccessibilityService.instance()?.openQuickSettings() + ActionService.runAccessibilityMode(context) + ActionService.instance()?.openQuickSettings() } exception.printStackTrace() } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/helper/FingerprintHelper.kt b/app/src/main/java/com/github/droidworksstudio/launcher/helper/FingerprintHelper.kt index 697e2cfe..a4023d4d 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/helper/FingerprintHelper.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/helper/FingerprintHelper.kt @@ -1,10 +1,10 @@ package com.github.droidworksstudio.launcher.helper -import android.content.Intent import androidx.biometric.BiometricManager import androidx.biometric.BiometricPrompt import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment +import androidx.navigation.fragment.findNavController import com.github.droidworksstudio.launcher.R import com.github.droidworksstudio.launcher.data.entities.AppInfo import javax.inject.Inject @@ -56,32 +56,46 @@ class FingerprintHelper @Inject constructor(private val fragment: Fragment) { } } - fun startFingerprintSettingsAuth(targetClass: Class<*>) { + fun startFingerprintSettingsAuth(runNavigation: Int) { val executor = ContextCompat.getMainExecutor(fragment.requireContext()) - val biometricPrompt = BiometricPrompt(fragment, executor, object : BiometricPrompt.AuthenticationCallback() { - override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { - sendToTargetActivity(targetClass) - } + val biometricPrompt = + BiometricPrompt(fragment, executor, object : BiometricPrompt.AuthenticationCallback() { + override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { + fragment.findNavController().navigate(runNavigation) + } - override fun onAuthenticationFailed() { - appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_failed)) - } + override fun onAuthenticationFailed() { + appHelper.showToast( + fragment.requireContext(), + fragment.getString(R.string.authentication_failed) + ) + } - override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence) { - when (errorCode) { - BiometricPrompt.ERROR_USER_CANCELED -> appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_cancel)) - else -> appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_error).format(errorMessage, errorCode)) + override fun onAuthenticationError(errorCode: Int, errorMessage: CharSequence) { + when (errorCode) { + BiometricPrompt.ERROR_USER_CANCELED -> appHelper.showToast( + fragment.requireContext(), + fragment.getString(R.string.authentication_cancel) + ) + + else -> appHelper.showToast( + fragment.requireContext(), + fragment.getString(R.string.authentication_error) + .format(errorMessage, errorCode) + ) + } } - } - }) + }) val promptInfoBuilder = BiometricPrompt.PromptInfo.Builder() .setTitle(fragment.getString(R.string.authentication_title)) .setSubtitle(fragment.getString(R.string.authentication_subtitle)) - val authenticators = BiometricManager.Authenticators.BIOMETRIC_WEAK or BiometricManager.Authenticators.DEVICE_CREDENTIAL - val canAuthenticate = BiometricManager.from(fragment.requireContext()).canAuthenticate(authenticators) + val authenticators = + BiometricManager.Authenticators.BIOMETRIC_WEAK or BiometricManager.Authenticators.DEVICE_CREDENTIAL + val canAuthenticate = + BiometricManager.from(fragment.requireContext()).canAuthenticate(authenticators) if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) { promptInfoBuilder.setAllowedAuthenticators(authenticators) @@ -95,17 +109,23 @@ class FingerprintHelper @Inject constructor(private val fragment: Fragment) { BiometricManager.BIOMETRIC_SUCCESS -> biometricPrompt.authenticate(promptInfo) BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE, BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE, - BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> sendToTargetActivity(targetClass) - else -> appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_failed)) + BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> sendToTarget(runNavigation) + + else -> appHelper.showToast( + fragment.requireContext(), + fragment.getString(R.string.authentication_failed) + ) } } - fun sendToTargetActivity(targetClass: Class<*>) { + private fun sendToTarget(runNavigation: Int) { try { - val intent = Intent(fragment.requireActivity(), targetClass) - fragment.requireActivity().startActivity(intent) + fragment.findNavController().navigate(runNavigation) } catch (e: Exception) { - appHelper.showToast(fragment.requireContext(), fragment.getString(R.string.authentication_failed)) + appHelper.showToast( + fragment.requireContext(), + fragment.getString(R.string.authentication_failed) + ) } } } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/listener/OnSwipeTouchListener.kt b/app/src/main/java/com/github/droidworksstudio/launcher/listener/OnSwipeTouchListener.kt index f4938f27..0e86824f 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/listener/OnSwipeTouchListener.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/listener/OnSwipeTouchListener.kt @@ -96,6 +96,7 @@ internal open class OnSwipeTouchListener(c: Context?) : OnTouchListener { open fun onLongClick() {} open fun onDoubleClick() {} open fun onTripleClick() {} + init { gestureDetector = GestureDetector(c, GestureListener()) } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/MainActivity.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/MainActivity.kt index 2decdb3e..c042d94b 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/MainActivity.kt @@ -1,12 +1,15 @@ package com.github.droidworksstudio.launcher.ui.activities import android.annotation.SuppressLint +import android.app.admin.DevicePolicyManager +import android.content.Intent import android.content.pm.ActivityInfo import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS +import android.widget.Toast import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.lifecycleScope @@ -15,6 +18,7 @@ import androidx.navigation.findNavController import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.AppBarConfiguration import androidx.navigation.ui.navigateUp +import com.github.droidworksstudio.launcher.Constants import com.github.droidworksstudio.launcher.R import com.github.droidworksstudio.launcher.databinding.ActivityMainBinding import com.github.droidworksstudio.launcher.helper.AppHelper @@ -143,5 +147,4 @@ class MainActivity : AppCompatActivity() { if (navController.currentDestination?.id != R.id.HomeFragment) navController.popBackStack(R.id.HomeFragment, false) } - } \ No newline at end of file diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/SettingsActivity.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/SettingsActivity.kt deleted file mode 100644 index ce676700..00000000 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/activities/SettingsActivity.kt +++ /dev/null @@ -1,74 +0,0 @@ -package com.github.droidworksstudio.launcher.ui.activities - -import android.os.Bundle -import android.view.WindowManager -import androidx.activity.viewModels -import androidx.appcompat.app.AppCompatActivity -import androidx.navigation.findNavController -import androidx.navigation.fragment.NavHostFragment -import androidx.navigation.ui.AppBarConfiguration -import androidx.navigation.ui.navigateUp -import com.github.droidworksstudio.launcher.R -import com.github.droidworksstudio.launcher.databinding.ActivitySettingsBinding -import com.github.droidworksstudio.launcher.helper.AppHelper -import com.github.droidworksstudio.launcher.helper.PreferenceHelper -import com.github.droidworksstudio.launcher.viewmodel.PreferenceViewModel -import dagger.hilt.android.AndroidEntryPoint -import javax.inject.Inject - -@AndroidEntryPoint -class SettingsActivity : AppCompatActivity() { - - private lateinit var binding: ActivitySettingsBinding - - private lateinit var appBarConfiguration: AppBarConfiguration - - private val preferenceViewModel: PreferenceViewModel by viewModels() - - @Inject - lateinit var preferenceHelper: PreferenceHelper - - @Inject - lateinit var appHelper: AppHelper - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - binding = ActivitySettingsBinding.inflate(layoutInflater) - setContentView(binding.root) - - // Find the NavHostFragment - val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_content_settings) as NavHostFragment - - // Retrieve the NavController - val navController = navHostFragment.navController - appBarConfiguration = AppBarConfiguration(navController.graph) - - initializeDependencies() - - } - - override fun onSupportNavigateUp(): Boolean { - val navController = findNavController(R.id.nav_host_fragment_content_settings) - return navController.navigateUp(appBarConfiguration) - || super.onSupportNavigateUp() - } - - private fun initializeDependencies() { - - preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar) - } - private fun observeUI(){ - window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) - - preferenceViewModel.setShowStatusBar(preferenceHelper.showStatusBar) - preferenceViewModel.showStatusBarLiveData.observe(this) { - if (it) appHelper.showStatusBar(this.window) - else appHelper.hideStatusBar(this.window) } - } - - override fun onResume() { - super.onResume() - observeUI() - } -} \ No newline at end of file diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawAdapter.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawAdapter.kt index 27fa0caf..5ab4f788 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawAdapter.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawAdapter.kt @@ -10,9 +10,10 @@ import com.github.droidworksstudio.launcher.databinding.ItemDrawBinding import com.github.droidworksstudio.launcher.helper.PreferenceHelper import com.github.droidworksstudio.launcher.listener.OnItemClickedListener -class DrawAdapter(private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, - private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, - private val preferenceHelperProvider: PreferenceHelper +class DrawAdapter( + private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, + private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, + private val preferenceHelperProvider: PreferenceHelper ) : ListAdapter(DiffCallback()) { @@ -27,7 +28,12 @@ class DrawAdapter(private val onAppClickedListener: OnItemClickedListener.OnApps ) val preferenceHelper = preferenceHelperProvider - return DrawViewHolder(binding, onAppClickedListener, onAppLongClickedListener, preferenceHelper) + return DrawViewHolder( + binding, + onAppClickedListener, + onAppLongClickedListener, + preferenceHelper + ) } override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { @@ -36,7 +42,7 @@ class DrawAdapter(private val onAppClickedListener: OnItemClickedListener.OnApps (holder as DrawViewHolder).bind(appInfo) } - class DiffCallback : DiffUtil.ItemCallback() { + class DiffCallback : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: AppInfo, newItem: AppInfo) = oldItem.id == newItem.id diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt index 8bfcc13b..2a7aee22 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt @@ -39,7 +39,8 @@ import javax.inject.Inject * A simple [Fragment] subclass as the second destination in the navigation. */ @AndroidEntryPoint -class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, +class DrawFragment : Fragment(), + OnItemClickedListener.OnAppsClickedListener, OnItemClickedListener.OnAppLongClickedListener, OnItemClickedListener.BottomSheetDismissListener, OnItemClickedListener.OnAppStateClickListener, @@ -143,7 +144,8 @@ class DrawFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, @SuppressLint("ClickableViewAccessibility") private fun observeSwipeTouchListener() { - binding.mainView.setOnTouchListener(getSwipeGestureListener(context)) + binding.touchArea.setOnTouchListener(getSwipeGestureListener(context)) + binding.drawAdapter.setOnTouchListener(getSwipeGestureListener(context)) } private fun getSwipeGestureListener(context: Context): View.OnTouchListener { diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawViewHolder.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawViewHolder.kt index 0e6f5147..010f4957 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawViewHolder.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawViewHolder.kt @@ -8,10 +8,12 @@ import com.github.droidworksstudio.launcher.databinding.ItemDrawBinding import com.github.droidworksstudio.launcher.helper.PreferenceHelper import com.github.droidworksstudio.launcher.listener.OnItemClickedListener -class DrawViewHolder(private val binding: ItemDrawBinding, - private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, - private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, - private val preferenceHelper: PreferenceHelper): +class DrawViewHolder( + private val binding: ItemDrawBinding, + private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, + private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, + private val preferenceHelper: PreferenceHelper +) : RecyclerView.ViewHolder(binding.root) { fun bind(appInfo: AppInfo) { binding.apply { diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteAdapter.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteAdapter.kt index 5e47d3e8..c8b93564 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteAdapter.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteAdapter.kt @@ -10,8 +10,11 @@ import com.github.droidworksstudio.launcher.databinding.ItemFavoriteBinding import com.github.droidworksstudio.launcher.listener.OnItemClickedListener import com.github.droidworksstudio.launcher.listener.OnItemMoveListener -class FavoriteAdapter(private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, -) : ListAdapter(DiffCallback()) ,OnItemMoveListener.OnItemActionListener{ +class FavoriteAdapter( + private val onAppClickedListener: + OnItemClickedListener.OnAppsClickedListener, +) : ListAdapter(DiffCallback()), + OnItemMoveListener.OnItemActionListener { private lateinit var touchHelper: ItemTouchHelper diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteFragment.kt index d0d75899..793df7f3 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteFragment.kt @@ -13,6 +13,7 @@ import androidx.annotation.RequiresApi import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope +import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.StaggeredGridLayoutManager @@ -24,6 +25,7 @@ import com.github.droidworksstudio.launcher.helper.FingerprintHelper import com.github.droidworksstudio.launcher.helper.PreferenceHelper import com.github.droidworksstudio.launcher.listener.OnItemClickedListener import com.github.droidworksstudio.launcher.listener.OnItemMoveListener +import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener import com.github.droidworksstudio.launcher.viewmodel.AppViewModel import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.launch @@ -32,7 +34,8 @@ import javax.inject.Inject @AndroidEntryPoint -class FavoriteFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, +class FavoriteFragment : Fragment(), + OnItemClickedListener.OnAppsClickedListener, OnItemClickedListener.BottomSheetDismissListener, OnItemClickedListener.OnAppStateClickListener, OnItemMoveListener.OnItemActionListener, @@ -77,6 +80,7 @@ class FavoriteFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener setupRecyclerView() observeFavorite() observeHomeAppOrder() + observeSwipeTouchListener() } private fun setupRecyclerView() { @@ -101,6 +105,14 @@ class FavoriteFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener } } + private fun observeFavorite() { + viewModel.compareInstalledAppInfo() + viewLifecycleOwner.lifecycleScope.launch { + viewModel.favoriteApps.collect { + favoriteAdapter.submitList(it) + } + } + } private fun observeHomeAppOrder() { binding.favoriteAdapter.adapter = favoriteAdapter @@ -165,11 +177,22 @@ class FavoriteFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener itemTouchHelper.attachToRecyclerView(binding.favoriteAdapter) } - private fun observeFavorite() { - viewModel.compareInstalledAppInfo() - viewLifecycleOwner.lifecycleScope.launch { - viewModel.favoriteApps.collect { - favoriteAdapter.submitList(it) + @SuppressLint("ClickableViewAccessibility") + private fun observeSwipeTouchListener() { + binding.touchArea.setOnTouchListener(getSwipeGestureListener(context)) + binding.favoriteAdapter.setOnTouchListener(getSwipeGestureListener(context)) + } + + private fun getSwipeGestureListener(context: Context): View.OnTouchListener { + return object : OnSwipeTouchListener(context) { + override fun onSwipeLeft() { + super.onSwipeLeft() + findNavController().popBackStack() + } + + override fun onSwipeRight() { + super.onSwipeRight() + findNavController().popBackStack() } } } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteViewHolder.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteViewHolder.kt index cb612e32..f206fb8a 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteViewHolder.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/favorite/FavoriteViewHolder.kt @@ -10,11 +10,12 @@ import com.github.droidworksstudio.launcher.databinding.ItemFavoriteBinding import com.github.droidworksstudio.launcher.listener.OnItemClickedListener @SuppressLint("ClickableViewAccessibility") -class FavoriteViewHolder(private val binding: ItemFavoriteBinding, - private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, - private val touchHelper: ItemTouchHelper, +class FavoriteViewHolder( + private val binding: ItemFavoriteBinding, + private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, + private val touchHelper: ItemTouchHelper, ) : - RecyclerView.ViewHolder(binding.root){ + RecyclerView.ViewHolder(binding.root) { init { binding.appFavoriteDragIcon.setOnTouchListener { _, event -> diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenFragment.kt index 399f2b27..fc300fe0 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenFragment.kt @@ -12,6 +12,7 @@ import androidx.annotation.RequiresApi import androidx.fragment.app.Fragment import androidx.fragment.app.viewModels import androidx.lifecycle.lifecycleScope +import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.StaggeredGridLayoutManager import com.github.droidworksstudio.launcher.R import com.github.droidworksstudio.launcher.data.entities.AppInfo @@ -19,13 +20,15 @@ import com.github.droidworksstudio.launcher.databinding.FragmentHiddenBinding import com.github.droidworksstudio.launcher.helper.AppHelper import com.github.droidworksstudio.launcher.helper.FingerprintHelper import com.github.droidworksstudio.launcher.listener.OnItemClickedListener +import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.AppInfoBottomSheetFragment import com.github.droidworksstudio.launcher.viewmodel.AppViewModel import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint -class HiddenFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, +class HiddenFragment : Fragment(), + OnItemClickedListener.OnAppsClickedListener, OnItemClickedListener.OnAppLongClickedListener, OnItemClickedListener.BottomSheetDismissListener, OnItemClickedListener.OnAppStateClickListener, @@ -65,6 +68,7 @@ class HiddenFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, setupRecyclerView() observeHiddenApps() + observeSwipeTouchListener() } private fun setupRecyclerView() { @@ -86,6 +90,26 @@ class HiddenFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, } } + @SuppressLint("ClickableViewAccessibility") + private fun observeSwipeTouchListener() { + binding.touchArea.setOnTouchListener(getSwipeGestureListener(context)) + binding.hiddenAdapter.setOnTouchListener(getSwipeGestureListener(context)) + } + + private fun getSwipeGestureListener(context: Context): View.OnTouchListener { + return object : OnSwipeTouchListener(context) { + override fun onSwipeLeft() { + super.onSwipeLeft() + findNavController().popBackStack() + } + + override fun onSwipeRight() { + super.onSwipeRight() + findNavController().popBackStack() + } + } + } + private fun observeBioAuthCheck(appInfo: AppInfo) { if (!appInfo.lock) { appHelper.launchApp(context, appInfo) diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenViewHolder.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenViewHolder.kt index f77189b5..2c2a7ff0 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenViewHolder.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/hidden/HiddenViewHolder.kt @@ -6,23 +6,25 @@ import com.github.droidworksstudio.launcher.data.entities.AppInfo import com.github.droidworksstudio.launcher.databinding.ItemHiddenBinding import com.github.droidworksstudio.launcher.listener.OnItemClickedListener -class HiddenViewHolder(private val binding: ItemHiddenBinding, - private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, - private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener) : +class HiddenViewHolder( + private val binding: ItemHiddenBinding, + private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, + private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener +) : RecyclerView.ViewHolder(binding.root) { fun bind(appInfo: AppInfo) { - binding.apply { - appHiddenName.text = appInfo.appName - Log.d("Tag", "Draw Adapter: ${appInfo.appName}") - } + binding.apply { + appHiddenName.text = appInfo.appName + Log.d("Tag", "Draw Adapter: ${appInfo.appName}") + } - itemView.setOnClickListener { - onAppClickedListener.onAppClicked(appInfo) - } + itemView.setOnClickListener { + onAppClickedListener.onAppClicked(appInfo) + } - itemView.setOnLongClickListener { - onAppLongClickedListener.onAppLongClicked(appInfo) - true - } + itemView.setOnLongClickListener { + onAppLongClickedListener.onAppLongClicked(appInfo) + true + } } } \ No newline at end of file diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeAdapter.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeAdapter.kt index 0f4c2fd6..20e8b26f 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeAdapter.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeAdapter.kt @@ -11,11 +11,12 @@ import com.github.droidworksstudio.launcher.helper.PreferenceHelper import com.github.droidworksstudio.launcher.listener.OnItemClickedListener import javax.inject.Inject -class HomeAdapter @Inject constructor(private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, - private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, - private val preferenceHelperProvider: PreferenceHelper +class HomeAdapter @Inject constructor( + private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, + private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, + private val preferenceHelperProvider: PreferenceHelper ) : - ListAdapter(DiffCallback()) { + ListAdapter(DiffCallback()) { override fun onCreateViewHolder( parent: android.view.ViewGroup, @@ -28,7 +29,12 @@ class HomeAdapter @Inject constructor(private val onAppClickedListener: OnItemCl ) val preferenceHelper = preferenceHelperProvider - return HomeViewHolder(binding, onAppClickedListener, onAppLongClickedListener, preferenceHelper) + return HomeViewHolder( + binding, + onAppClickedListener, + onAppLongClickedListener, + preferenceHelper + ) } override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { @@ -37,7 +43,7 @@ class HomeAdapter @Inject constructor(private val onAppClickedListener: OnItemCl (holder as HomeViewHolder).bind(appInfo) } - class DiffCallback : DiffUtil.ItemCallback() { + class DiffCallback : DiffUtil.ItemCallback() { override fun areItemsTheSame(oldItem: AppInfo, newItem: AppInfo) = oldItem.id == newItem.id diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeFragment.kt index 5652018f..f257600b 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeFragment.kt @@ -20,7 +20,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.StaggeredGridLayoutManager import com.github.droidworksstudio.launcher.R -import com.github.droidworksstudio.launcher.accessibility.MyAccessibilityService +import com.github.droidworksstudio.launcher.accessibility.ActionService import com.github.droidworksstudio.launcher.data.entities.AppInfo import com.github.droidworksstudio.launcher.databinding.FragmentHomeBinding import com.github.droidworksstudio.launcher.helper.AppHelper @@ -30,7 +30,6 @@ import com.github.droidworksstudio.launcher.helper.hideKeyboard import com.github.droidworksstudio.launcher.listener.OnItemClickedListener import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener import com.github.droidworksstudio.launcher.listener.ScrollEventListener -import com.github.droidworksstudio.launcher.ui.activities.SettingsActivity import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.AppInfoBottomSheetFragment import com.github.droidworksstudio.launcher.viewmodel.AppViewModel import com.github.droidworksstudio.launcher.viewmodel.PreferenceViewModel @@ -46,7 +45,8 @@ import javax.inject.Inject * A simple [Fragment] subclass as the default destination in the navigation. */ @AndroidEntryPoint -class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, +class HomeFragment : Fragment(), + OnItemClickedListener.OnAppsClickedListener, OnItemClickedListener.OnAppLongClickedListener, OnItemClickedListener.BottomSheetDismissListener, OnItemClickedListener.OnAppStateClickListener, @@ -91,16 +91,16 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, super.onViewCreated(view, savedInstanceState) initializeInjectedDependencies() - initSwipeTouchListener() setupBattery() setupRecyclerView() + observeSwipeTouchListener() observeUserInterfaceSettings() } @SuppressLint("ClickableViewAccessibility") private fun initializeInjectedDependencies() { context = requireContext() - binding.mainView.hideKeyboard() + binding.nestScrollView.hideKeyboard() binding.nestScrollView.scrollEventListener = this @@ -111,15 +111,6 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, preferenceViewModel.setShowDailyWord(preferenceHelper.showDailyWord) } - @SuppressLint("ClickableViewAccessibility") - private fun initSwipeTouchListener() { - binding.nestScrollView.setOnTouchListener(getSwipeGestureListener(context)) - - binding.clock.setOnClickListener { appHelper.launchClock(context) } - binding.date.setOnClickListener { appHelper.launchCalendar(context) } - binding.battery.setOnClickListener { appHelper.openBatteryManager(context) } - } - private fun setupBattery() { batteryReceiver = object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { @@ -163,8 +154,18 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, } } + @SuppressLint("ClickableViewAccessibility") + private fun observeSwipeTouchListener() { + binding.touchArea.setOnTouchListener(getSwipeGestureListener(context)) + binding.nestScrollView.setOnTouchListener(getSwipeGestureListener(context)) + + binding.clock.setOnClickListener { appHelper.launchClock(context) } + binding.date.setOnClickListener { appHelper.launchCalendar(context) } + binding.battery.setOnClickListener { appHelper.openBatteryManager(context) } + } + private fun observeUserInterfaceSettings() { - binding.mainView.hideKeyboard() + binding.nestScrollView.hideKeyboard() preferenceViewModel.setShowTime(preferenceHelper.showTime) preferenceViewModel.setShowDate(preferenceHelper.showDate) @@ -226,10 +227,13 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, } private fun observeBioAuthCheck(appInfo: AppInfo) { - if (!appInfo.lock) appHelper.launchApp( - context, - appInfo - ) else fingerHelper.startFingerprintAuth(appInfo, this) + if (!appInfo.lock) + appHelper.launchApp( + context, + appInfo + ) + else + fingerHelper.startFingerprintAuth(appInfo, this) } private fun showSelectedApp(appInfo: AppInfo) { @@ -252,8 +256,8 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, override fun onDoubleClick() { super.onDoubleClick() if (preferenceHelper.tapLockScreen) { - MyAccessibilityService.runAccessibilityMode(context) - MyAccessibilityService.instance()?.lockScreen() + ActionService.runAccessibilityMode(context) + ActionService.instance()?.lockScreen() } else { return } @@ -267,7 +271,6 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, override fun onSwipeRight() { super.onSwipeRight() findNavController().navigate(R.id.action_HomeFragment_to_FavoriteFragment) - } override fun onSwipeDown() { @@ -320,7 +323,7 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, }) if (preferenceHelper.settingsLock) { - fingerHelper.startFingerprintSettingsAuth(SettingsActivity::class.java) + fingerHelper.startFingerprintSettingsAuth(R.id.action_HomeFragment_to_SettingsFragment) } else { findNavController().navigate(R.id.action_HomeFragment_to_SettingsFragment) } @@ -335,12 +338,12 @@ class HomeFragment : Fragment(), OnItemClickedListener.OnAppsClickedListener, override fun onPause() { super.onPause() - binding.mainView.hideKeyboard() + binding.nestScrollView.hideKeyboard() } override fun onResume() { super.onResume() - binding.mainView.hideKeyboard() + binding.nestScrollView.hideKeyboard() observeUserInterfaceSettings() observeFavoriteAppList() } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeViewHolder.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeViewHolder.kt index 1f771636..04216870 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeViewHolder.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/home/HomeViewHolder.kt @@ -1,5 +1,6 @@ package com.github.droidworksstudio.launcher.ui.home +import android.annotation.SuppressLint import android.util.Log import android.view.Gravity import android.view.View @@ -11,13 +12,13 @@ import com.github.droidworksstudio.launcher.helper.PreferenceHelper import com.github.droidworksstudio.launcher.listener.OnItemClickedListener import javax.inject.Inject - class HomeViewHolder @Inject constructor( private val binding: ItemHomeBinding, private val onAppClickedListener: OnItemClickedListener.OnAppsClickedListener, private val onAppLongClickedListener: OnItemClickedListener.OnAppLongClickedListener, private val preferenceHelper: PreferenceHelper, ) : RecyclerView.ViewHolder(binding.root) { + @SuppressLint("ClickableViewAccessibility") fun bind(appInfo: AppInfo) { binding.apply { val layoutParams = LinearLayoutCompat.LayoutParams( @@ -36,26 +37,33 @@ class HomeViewHolder @Inject constructor( Log.d("Tag", "Home Adapter Color: ${preferenceHelper.appColor}") if (preferenceHelper.showAppIcon) { - val appIcon = binding.root.context.packageManager.getApplicationIcon(appInfo.packageName) + val appIcon = + binding.root.context.packageManager.getApplicationIcon(appInfo.packageName) when (preferenceHelper.homeAppAlignment) { Gravity.START -> { appHomeLeftIcon.setImageDrawable(appIcon) - appHomeLeftIcon.layoutParams.width = preferenceHelper.appTextSize.toInt() * 3 - appHomeLeftIcon.layoutParams.height = preferenceHelper.appTextSize.toInt() * 3 + appHomeLeftIcon.layoutParams.width = + preferenceHelper.appTextSize.toInt() * 3 + appHomeLeftIcon.layoutParams.height = + preferenceHelper.appTextSize.toInt() * 3 appHomeLeftIcon.visibility = View.VISIBLE } + Gravity.END -> { appHomeRightIcon.setImageDrawable(appIcon) - appHomeRightIcon.layoutParams.width = preferenceHelper.appTextSize.toInt() * 3 - appHomeRightIcon.layoutParams.height = preferenceHelper.appTextSize.toInt() * 3 + appHomeRightIcon.layoutParams.width = + preferenceHelper.appTextSize.toInt() * 3 + appHomeRightIcon.layoutParams.height = + preferenceHelper.appTextSize.toInt() * 3 appHomeRightIcon.visibility = View.VISIBLE } } - } } - itemView.setOnClickListener { onAppClickedListener.onAppClicked(appInfo) } + itemView.setOnClickListener { + onAppClickedListener.onAppClicked(appInfo) + } itemView.setOnLongClickListener { onAppLongClickedListener.onAppLongClicked(appInfo) diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsFragment.kt index 0093e949..5f14b642 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/settings/SettingsFragment.kt @@ -1,6 +1,7 @@ package com.github.droidworksstudio.launcher.ui.settings import android.annotation.SuppressLint +import android.content.Context import android.content.Intent import android.os.Bundle import android.view.LayoutInflater @@ -16,6 +17,7 @@ import com.github.droidworksstudio.launcher.databinding.FragmentSettingsBinding import com.github.droidworksstudio.launcher.helper.AppHelper import com.github.droidworksstudio.launcher.helper.PreferenceHelper import com.github.droidworksstudio.launcher.helper.restartApp +import com.github.droidworksstudio.launcher.listener.OnSwipeTouchListener import com.github.droidworksstudio.launcher.listener.ScrollEventListener import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.AlignmentBottomSheetDialogFragment import com.github.droidworksstudio.launcher.ui.bottomsheetdialog.ColorBottomSheetDialogFragment @@ -26,7 +28,8 @@ import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject @AndroidEntryPoint -class SettingsFragment : Fragment(), ScrollEventListener { +class SettingsFragment : Fragment(), + ScrollEventListener { private var _binding: FragmentSettingsBinding? = null private val binding get() = _binding!! @@ -41,6 +44,8 @@ class SettingsFragment : Fragment(), ScrollEventListener { private lateinit var navController: NavController + private lateinit var context: Context + override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -59,8 +64,11 @@ class SettingsFragment : Fragment(), ScrollEventListener { appHelper.dayNightMod(requireContext(), binding.nestScrollView) super.onViewCreated(view, savedInstanceState) + context = requireContext() + initializeInjectedDependencies() observeClickListener() + observeSwipeTouchListener() val packageInfo = requireContext().packageManager.getPackageInfo(requireContext().packageName, 0) @@ -217,4 +225,24 @@ class SettingsFragment : Fragment(), ScrollEventListener { preferenceViewModel.setLockSettings(isChecked) } } + + @SuppressLint("ClickableViewAccessibility") + private fun observeSwipeTouchListener() { + binding.touchArea.setOnTouchListener(getSwipeGestureListener(context)) + } + + private fun getSwipeGestureListener(context: Context): View.OnTouchListener { + return object : OnSwipeTouchListener(context) { + override fun onSwipeLeft() { + super.onSwipeLeft() + findNavController().popBackStack() + } + + override fun onSwipeRight() { + super.onSwipeRight() + findNavController().popBackStack() + } + + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetManagerFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetManagerFragment.kt index 6936db2c..edaf472e 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetManagerFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetManagerFragment.kt @@ -24,7 +24,8 @@ import javax.inject.Inject * A simple [Fragment] subclass as the second destination in the navigation. */ @AndroidEntryPoint -class WidgetManagerFragment : Fragment(), WidgetOptionsDialogFragment.WidgetOptionsListener { +class WidgetManagerFragment : Fragment(), + WidgetOptionsDialogFragment.WidgetOptionsListener { private var _binding: FragmentWidgetManagerBinding? = null @@ -78,47 +79,51 @@ class WidgetManagerFragment : Fragment(), WidgetOptionsDialogFragment.WidgetOpti } // Initialize the ActivityResultLaunchers - pickWidgetLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - if (result.resultCode == Activity.RESULT_OK) { - val data = result.data - data?.let { - val appWidgetId = it.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) - if (appWidgetId != -1) { - val appWidgetInfo = appWidgetManager.getAppWidgetInfo(appWidgetId) - if (appWidgetInfo?.configure != null) { - val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE) - intent.component = appWidgetInfo.configure - intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) - createWidgetLauncher.launch(intent) - } else { - addWidget(appWidgetId) + pickWidgetLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + val data = result.data + data?.let { + val appWidgetId = it.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) + if (appWidgetId != -1) { + val appWidgetInfo = appWidgetManager.getAppWidgetInfo(appWidgetId) + if (appWidgetInfo?.configure != null) { + val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE) + intent.component = appWidgetInfo.configure + intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) + createWidgetLauncher.launch(intent) + } else { + addWidget(appWidgetId) + } } } - } - } else if (result.resultCode == Activity.RESULT_CANCELED) { - val appWidgetId = result.data?.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) - if (appWidgetId != null && appWidgetId != -1) { - appWidgetHost.deleteAppWidgetId(appWidgetId) + } else if (result.resultCode == Activity.RESULT_CANCELED) { + val appWidgetId = + result.data?.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) + if (appWidgetId != null && appWidgetId != -1) { + appWidgetHost.deleteAppWidgetId(appWidgetId) + } } } - } - createWidgetLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> - if (result.resultCode == Activity.RESULT_OK) { - val data = result.data - data?.let { - val appWidgetId = it.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) - if (appWidgetId != -1) { - addWidget(appWidgetId) + createWidgetLauncher = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + if (result.resultCode == Activity.RESULT_OK) { + val data = result.data + data?.let { + val appWidgetId = it.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) + if (appWidgetId != -1) { + addWidget(appWidgetId) + } + } + } else if (result.resultCode == Activity.RESULT_CANCELED) { + val appWidgetId = + result.data?.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) + if (appWidgetId != null && appWidgetId != -1) { + appWidgetHost.deleteAppWidgetId(appWidgetId) } - } - } else if (result.resultCode == Activity.RESULT_CANCELED) { - val appWidgetId = result.data?.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) - if (appWidgetId != null && appWidgetId != -1) { - appWidgetHost.deleteAppWidgetId(appWidgetId) } } - } // Set long-click listener on the root view binding.widgetParent.setOnLongClickListener { @@ -161,7 +166,8 @@ class WidgetManagerFragment : Fragment(), WidgetOptionsDialogFragment.WidgetOpti } private fun saveWidgetIds(widgetIds: List) { - val sharedPreferences = requireContext().getSharedPreferences(Constants.WIDGETS_PREFS, Activity.MODE_PRIVATE) + val sharedPreferences = + requireContext().getSharedPreferences(Constants.WIDGETS_PREFS, Activity.MODE_PRIVATE) val editor = sharedPreferences.edit() val widgetIdsSet = widgetIds.map { it.toString() }.toSet() editor.putStringSet(Constants.APP_WIDGETS_ID, widgetIdsSet) @@ -169,7 +175,8 @@ class WidgetManagerFragment : Fragment(), WidgetOptionsDialogFragment.WidgetOpti } private fun loadWidgetIds(): List { - val sharedPreferences = requireContext().getSharedPreferences(Constants.WIDGETS_PREFS, Activity.MODE_PRIVATE) + val sharedPreferences = + requireContext().getSharedPreferences(Constants.WIDGETS_PREFS, Activity.MODE_PRIVATE) val widgetIdsSet = sharedPreferences.getStringSet(Constants.APP_WIDGETS_ID, emptySet()) return widgetIdsSet?.map { it.toInt() } ?: emptyList() } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetOptionsDialogFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetOptionsDialogFragment.kt index 2bcc6265..6b361f92 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetOptionsDialogFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/widgetmanager/WidgetOptionsDialogFragment.kt @@ -1,14 +1,10 @@ package com.github.droidworksstudio.launcher.ui.widgetmanager -import android.annotation.SuppressLint import android.app.Dialog import android.os.Bundle -import android.view.LayoutInflater -import android.widget.Button import androidx.appcompat.app.AlertDialog import androidx.fragment.app.DialogFragment import com.github.droidworksstudio.launcher.Constants -import com.github.droidworksstudio.launcher.R class WidgetOptionsDialogFragment : DialogFragment() { @@ -18,7 +14,8 @@ class WidgetOptionsDialogFragment : DialogFragment() { } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - val appWidgetId = arguments?.getInt(ARG_APP_WIDGET_ID) ?: return super.onCreateDialog(savedInstanceState) + val appWidgetId = + arguments?.getInt(ARG_APP_WIDGET_ID) ?: return super.onCreateDialog(savedInstanceState) val builder = AlertDialog.Builder(requireContext()) builder.setTitle("Widget Options") diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/view/GestureNestedScrollView.kt b/app/src/main/java/com/github/droidworksstudio/launcher/view/GestureNestedScrollView.kt index 554b5078..666b98e9 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/view/GestureNestedScrollView.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/view/GestureNestedScrollView.kt @@ -6,7 +6,8 @@ import androidx.core.widget.NestedScrollView import androidx.recyclerview.widget.RecyclerView import com.github.droidworksstudio.launcher.listener.ScrollEventListener -class GestureNestedScrollView(context: Context, attrs: AttributeSet) : NestedScrollView(context, attrs){ +class GestureNestedScrollView(context: Context, attrs: AttributeSet) : + NestedScrollView(context, attrs) { var scrollEventListener: ScrollEventListener? = null diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml deleted file mode 100644 index 140c9872..00000000 --- a/app/src/main/res/layout/activity_settings.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/content_settings.xml b/app/src/main/res/layout/content_settings.xml deleted file mode 100644 index 19064c48..00000000 --- a/app/src/main/res/layout/content_settings.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_draw.xml b/app/src/main/res/layout/fragment_draw.xml index 11eedbb8..1dd6e706 100644 --- a/app/src/main/res/layout/fragment_draw.xml +++ b/app/src/main/res/layout/fragment_draw.xml @@ -7,6 +7,13 @@ android:id="@+id/draw_background" tools:context=".ui.drawer.DrawFragment"> + + + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:layout_constraintTop_toBottomOf="@id/search_view_text" /> diff --git a/app/src/main/res/layout/fragment_favorite.xml b/app/src/main/res/layout/fragment_favorite.xml index 976b51bd..18327be5 100644 --- a/app/src/main/res/layout/fragment_favorite.xml +++ b/app/src/main/res/layout/fragment_favorite.xml @@ -7,6 +7,13 @@ android:id="@+id/favorite_view" tools:context=".ui.favorite.FavoriteFragment"> + + + diff --git a/app/src/main/res/layout/fragment_hidden.xml b/app/src/main/res/layout/fragment_hidden.xml index 440cc4a1..584edb98 100644 --- a/app/src/main/res/layout/fragment_hidden.xml +++ b/app/src/main/res/layout/fragment_hidden.xml @@ -7,6 +7,13 @@ android:id="@+id/hidden_view" tools:context=".ui.hidden.HiddenFragment"> + + diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 5bbaec7f..987c5d88 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -2,14 +2,24 @@ + + diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml index 8d78a2ba..c920c5e9 100644 --- a/app/src/main/res/layout/fragment_settings.xml +++ b/app/src/main/res/layout/fragment_settings.xml @@ -6,9 +6,16 @@ android:layout_height="match_parent" tools:context=".ui.settings.SettingsFragment"> + + + + - - - - \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 91780157..15cb8ce9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,10 @@ Settings Fragment Widgets Fragment + + Favorite Apps + Hidden Apps + %s%% Search @@ -26,7 +30,6 @@ Launcher Settings %s Version: %s - Home Display Behavior @@ -101,6 +104,7 @@ Enable Disable + Easy Launcher Actions Service Please turn on accessibility service to use double tap to lock feature in Easy Launcher.\n\nThis permission is used only to turn off your screen.Our accessibility service does not collect or share any data. Easy launcher promises to use lock screen permission responsibly. Easy launcher does not collect or share any data.