diff --git a/app/build.gradle b/app/build.gradle index f08d53c..02c7629 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { applicationId "ru.dimon6018.metrolauncher" minSdk 21 targetSdk 35 - versionCode 50 - versionName "1.0 Pre-Alpha 5.1.2" + versionCode 51 + versionName "1.0 Pre-Alpha 5.1.2.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled false diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/Application.kt b/app/src/main/java/ru/dimon6018/metrolauncher/Application.kt index 4ba809a..c31ce85 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/Application.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/Application.kt @@ -25,7 +25,7 @@ class Application : Application() { PREFS = Prefs(applicationContext) //EXP_PREFS = ExperimentPrefs(applicationContext) setNightMode() - if(PREFS!!.accentColor == 21 && DynamicColors.isDynamicColorAvailable()) { + if(PREFS.accentColor == 21 && DynamicColors.isDynamicColorAvailable()) { DynamicColors.applyToActivitiesIfAvailable(this) } super.onCreate() @@ -33,7 +33,7 @@ class Application : Application() { @SuppressLint("SourceLockedOrientationActivity") override fun onActivityPreCreated(activity: Activity, savedInstanceState: Bundle?) { activity.setTheme(launcherAccentTheme()) - when(PREFS!!.orientation) { + when(PREFS.orientation) { "p" -> { activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT } @@ -55,7 +55,7 @@ class Application : Application() { fun setNightMode() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val uiMan: UiModeManager = (applicationContext.getSystemService(UI_MODE_SERVICE) as UiModeManager) - if(PREFS!!.isLightThemeUsed) { + if(PREFS.isLightThemeUsed) { uiMan.setApplicationNightMode(UiModeManager.MODE_NIGHT_NO) } else { uiMan.setApplicationNightMode(UiModeManager.MODE_NIGHT_YES) @@ -63,7 +63,7 @@ class Application : Application() { } } companion object { - var PREFS: Prefs? = null + lateinit var PREFS: Prefs //var EXP_PREFS: ExperimentPrefs? = null var isUpdateDownloading = false diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/Main.kt b/app/src/main/java/ru/dimon6018/metrolauncher/Main.kt index d7cfa3a..aba5193 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/Main.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/Main.kt @@ -85,7 +85,7 @@ class Main : AppCompatActivity() { handleDevMode() super.onCreate(savedInstanceState) - if (PREFS!!.launcherState == 0) { + if (PREFS.launcherState == 0) { runOOBE() return } @@ -106,7 +106,7 @@ class Main : AppCompatActivity() { } private fun handleDevMode() { - if (isDevMode(this) && PREFS!!.isAutoShutdownAnimEnabled) { + if (isDevMode(this) && PREFS.isAutoShutdownAnimEnabled) { disableAnims() } } @@ -134,12 +134,12 @@ class Main : AppCompatActivity() { } private fun checkUpdate() { - if (PREFS!!.prefs.getBoolean("updateInstalled", false) && PREFS!!.versionCode == VERSION_CODE) { - PREFS!!.updateState = 3 + if (PREFS.prefs.getBoolean("updateInstalled", false) && PREFS.versionCode == VERSION_CODE) { + PREFS.updateState = 3 } } private fun disableAnims() { - PREFS!!.apply { + PREFS.apply { isAAllAppsAnimEnabled = false isAlphabetAnimEnabled = false isTransitionAnimEnabled = false @@ -154,7 +154,7 @@ class Main : AppCompatActivity() { override fun handleOnBackPressed() { if (binding.pager.currentItem != 0) { binding.pager.currentItem -= 1 - } else if (searching && PREFS!!.isSearchBarEnabled) { + } else if (searching && PREFS.isSearchBarEnabled) { hideSearch() } } @@ -178,15 +178,15 @@ class Main : AppCompatActivity() { } private fun updateNavigationBarColors(position: Int) { - if (!PREFS!!.isSearchBarEnabled && PREFS!!.navBarColor != 2) { + if (!PREFS.isSearchBarEnabled && PREFS.navBarColor != 2) { val (startColor, searchColor) = when { - position == 0 && (PREFS!!.navBarColor == 1 || PREFS!!.isLightThemeUsed) -> { + position == 0 && (PREFS.navBarColor == 1 || PREFS.isLightThemeUsed) -> { launcherAccentColor(this@Main.theme) to blackColor } position == 0 -> { launcherAccentColor(this@Main.theme) to whiteColor } - (PREFS!!.navBarColor == 1 || PREFS!!.isLightThemeUsed) -> { + (PREFS.navBarColor == 1 || PREFS.isLightThemeUsed) -> { blackColor to launcherAccentColor(this@Main.theme) } else -> { @@ -200,13 +200,13 @@ class Main : AppCompatActivity() { } override fun onResume() { - if (PREFS!!.isPrefsChanged) { + if (PREFS.isPrefsChanged) { restart() } super.onResume() } private fun restart() { - PREFS!!.isPrefsChanged = false + PREFS.isPrefsChanged = false val componentName = Intent(this, this::class.java).component val intent = Intent.makeRestartActivityTask(componentName) startActivity(intent) @@ -238,13 +238,13 @@ class Main : AppCompatActivity() { } private suspend fun regenerateIcons() { - val isCustomIconsInstalled = PREFS!!.iconPackPackage != "null" + val isCustomIconsInstalled = PREFS.iconPackPackage != "null" var diskCache = initDiskCache(this) if(isCustomIconsInstalled) { checkIconPack(diskCache) } - if (PREFS!!.iconPackChanged) { - PREFS!!.iconPackChanged = false + if (PREFS.iconPackChanged) { + PREFS.iconPackChanged = false diskCache?.apply { delete() close() @@ -269,10 +269,10 @@ class Main : AppCompatActivity() { private fun checkIconPack(disk: DiskLruCache?): Boolean { return runCatching { - packageManager.getApplicationInfo(PREFS!!.iconPackPackage!!, 0) + packageManager.getApplicationInfo(PREFS.iconPackPackage!!, 0) true }.getOrElse { - PREFS!!.iconPackPackage = "null" + PREFS.iconPackPackage = "null" disk?.apply { delete() close() @@ -285,7 +285,7 @@ class Main : AppCompatActivity() { val icon = if (!isCustomIconsInstalled) { packageManager.getApplicationIcon(appPackage) } else { - iconPackManager.getIconPackWithName(PREFS!!.iconPackPackage) + iconPackManager.getIconPackWithName(PREFS.iconPackPackage) ?.getDrawableIconForPackage(appPackage, null) ?: packageManager.getApplicationIcon(appPackage) } @@ -298,9 +298,9 @@ class Main : AppCompatActivity() { } private fun otherTasks() { - if (PREFS!!.prefs.getBoolean("tip1Enabled", true)) { + if (PREFS.prefs.getBoolean("tip1Enabled", true)) { showTipDialog() - PREFS!!.prefs.edit().putBoolean("tip1Enabled", false).apply() + PREFS.prefs.edit().putBoolean("tip1Enabled", false).apply() } crashCheck() } @@ -316,15 +316,15 @@ class Main : AppCompatActivity() { } private fun crashCheck() { - if (PREFS!!.prefs.getBoolean("app_crashed", false)) { + if (PREFS.prefs.getBoolean("app_crashed", false)) { lifecycleScope.launch(Dispatchers.Default) { delay(5000) - PREFS!!.prefs.edit().apply { + PREFS.prefs.edit().apply { putBoolean("app_crashed", false) putInt("crashCounter", 0) apply() } - if (PREFS!!.isFeedbackEnabled) { + if (PREFS.isFeedbackEnabled) { handleCrashFeedback() } } @@ -359,7 +359,7 @@ class Main : AppCompatActivity() { } private fun getNavBarColor(): Int { - return when (PREFS!!.navBarColor) { + return when (PREFS.navBarColor) { 0 -> ContextCompat.getColor(this, android.R.color.background_dark) 1 -> ContextCompat.getColor(this, android.R.color.background_light) 2 -> accentColorFromPrefs(this) @@ -372,7 +372,7 @@ class Main : AppCompatActivity() { } private fun configureBottomBar() { - if (!PREFS!!.isSearchBarEnabled) { + if (!PREFS.isSearchBarEnabled) { setupNavigationBarButtons() } else { setupSearchBar() @@ -386,7 +386,7 @@ class Main : AppCompatActivity() { setOnClickListener { binding.pager.setCurrentItem(0, true) } } binding.navigationSearchBtn.setOnClickListener { - if (PREFS!!.isAllAppsEnabled) { + if (PREFS.isAllAppsEnabled) { binding.pager.setCurrentItem(1, true) } } @@ -394,7 +394,7 @@ class Main : AppCompatActivity() { private fun getNavBarIconDrawable(): Drawable? { return ContextCompat.getDrawable( - this, when (PREFS!!.navBarIconValue) { + this, when (PREFS.navBarIconValue) { 0 -> R.drawable.ic_os_windows_8 1 -> R.drawable.ic_os_windows 2 -> R.drawable.ic_os_android @@ -444,7 +444,7 @@ class Main : AppCompatActivity() { lifecycleScope.launch { searching = false binding.searchBarResults.apply { - if (PREFS!!.isTransitionAnimEnabled) { + if (PREFS.isTransitionAnimEnabled) { ObjectAnimator.ofFloat(this, "alpha", 1f, 0f).start() } visibility = View.GONE @@ -455,7 +455,7 @@ class Main : AppCompatActivity() { private fun showSearchResults() { searching = true binding.searchBarResults.apply { - if (PREFS!!.isTransitionAnimEnabled) { + if (PREFS.isTransitionAnimEnabled) { ObjectAnimator.ofFloat(this, "alpha", 0f, 1f).setDuration(100).start() } visibility = View.VISIBLE @@ -469,7 +469,7 @@ class Main : AppCompatActivity() { showSearchResults() } - val max = PREFS!!.maxResultsSearchBar + val max = PREFS.maxResultsSearchBar val defaultLocale = getDefaultLocale() filteredList.clear() @@ -483,7 +483,7 @@ class Main : AppCompatActivity() { private fun setAppTheme() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) { - val nightMode = if (PREFS!!.isLightThemeUsed) { + val nightMode = if (PREFS.isLightThemeUsed) { AppCompatDelegate.MODE_NIGHT_NO } else { AppCompatDelegate.MODE_NIGHT_YES @@ -498,11 +498,11 @@ class Main : AppCompatActivity() { inner class WinAdapter(fragment: FragmentActivity) : FragmentStateAdapter(fragment) { - override fun getItemCount(): Int = if (PREFS!!.isAllAppsEnabled) 2 else 1 + override fun getItemCount(): Int = if (PREFS.isAllAppsEnabled) 2 else 1 override fun createFragment(position: Int): Fragment { return when { - !PREFS!!.isAllAppsEnabled -> NewStart() + !PREFS.isAllAppsEnabled -> NewStart() position == 1 -> NewAllApps() else -> NewStart() } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/NewAllApps.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/NewAllApps.kt index 5ddfc48..5191cea 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/NewAllApps.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/NewAllApps.kt @@ -108,7 +108,7 @@ class NewAllApps: Fragment() { binding.settingsBtn.setOnClickListener { activity?.apply { startActivity(Intent(this, SettingsActivity::class.java)) } } - if(!PREFS!!.isSettingsBtnEnabled) { + if(!PREFS.isSettingsBtnEnabled) { binding.settingsBtn.visibility = View.GONE } else { binding.settingsBtn.visibility = View.VISIBLE @@ -135,7 +135,7 @@ class NewAllApps: Fragment() { appAdapter = AppAdapter(data) recyclerViewLM = LinearLayoutManager(requireActivity()) setAlphabetRecyclerView(requireContext()) - if (PREFS!!.prefs.getBoolean("tip2Enabled", true)) { + if (PREFS.prefs.getBoolean("tip2Enabled", true)) { withContext(mainDispatcher) { WPDialog(requireContext()).setTopDialog(true) .setTitle(getString(R.string.tip)) @@ -143,7 +143,7 @@ class NewAllApps: Fragment() { .setPositiveButton(getString(android.R.string.ok), null) .show() } - PREFS!!.prefs.edit().putBoolean("tip2Enabled", false).apply() + PREFS.prefs.edit().putBoolean("tip2Enabled", false).apply() } withContext(mainDispatcher) { configureRecyclerView() @@ -179,7 +179,7 @@ class NewAllApps: Fragment() { packageName.apply { when(action) { PackageChangesReceiver.PACKAGE_INSTALLED -> { - val bool = PREFS!!.iconPackPackage != "null" + val bool = PREFS.iconPackPackage != "null" (requireActivity() as Main).generateIcon(packageName, bool) broadcastListUpdater(context) } @@ -250,22 +250,22 @@ class NewAllApps: Fragment() { } private fun showAlphabet() { adapterAlphabet!!.setNewData(getAlphabetList()) - if(PREFS!!.isAlphabetAnimEnabled) { + if(PREFS.isAlphabetAnimEnabled) { ObjectAnimator.ofFloat(binding.appList, "alpha", 1f, 0.7f).setDuration(300).start() } isAlphabetVisible = true - if(PREFS!!.isAlphabetAnimEnabled) { + if(PREFS.isAlphabetAnimEnabled) { binding.alphabetLayout.visibility = View.VISIBLE } else { binding.alphabetLayout.visibility = View.VISIBLE } } private fun hideAlphabet() { - if(PREFS!!.isAlphabetAnimEnabled) { + if(PREFS.isAlphabetAnimEnabled) { ObjectAnimator.ofFloat(binding.appList, "alpha", 0.7f, 1f).setDuration(300).start() } isAlphabetVisible = false - if(PREFS!!.isAlphabetAnimEnabled) { + if(PREFS.isAlphabetAnimEnabled) { binding.alphabetLayout.visibility = View.INVISIBLE binding.alphabetList.scrollToPosition(0) } else { @@ -306,7 +306,7 @@ class NewAllApps: Fragment() { return resultList } override fun onPause() { - if(isSearching && !PREFS!!.showKeyboardWhenOpeningAllApps) { + if(isSearching && !PREFS.showKeyboardWhenOpeningAllApps) { disableSearch() } if(isAlphabetVisible) { @@ -329,7 +329,7 @@ class NewAllApps: Fragment() { binding.appList.visibility = View.VISIBLE } if(binding.appList.alpha != 1f) { - if (PREFS!!.isAAllAppsAnimEnabled) { + if (PREFS.isAAllAppsAnimEnabled) { binding.appList.apply { val anim = ObjectAnimator.ofFloat(this, "alpha", 0f, 1f) anim.duration = 100 @@ -342,7 +342,7 @@ class NewAllApps: Fragment() { binding.appList.alpha = 1f } } - if(PREFS!!.showKeyboardWhenOpeningAllApps) { + if(PREFS.showKeyboardWhenOpeningAllApps) { searchFunction() } } @@ -364,7 +364,7 @@ class NewAllApps: Fragment() { animate().alpha(1f).setDuration(200).start() } }.start() - settingsBtn.visibility = if(!PREFS!!.isSettingsBtnEnabled) View.GONE else View.VISIBLE + settingsBtn.visibility = if(!PREFS.isSettingsBtnEnabled) View.GONE else View.VISIBLE appList.apply { alpha = 0.5f animate().translationX(0f).setDuration(200).start() @@ -397,7 +397,7 @@ class NewAllApps: Fragment() { isVerticalScrollBarEnabled = false } } - if(PREFS!!.showKeyboardWhenSearching) { + if(PREFS.showKeyboardWhenSearching) { showKeyboard(binding.search.editText as? AutoCompleteTextView) } viewLifecycleOwner.lifecycleScope.launch(defaultDispatcher) { @@ -535,7 +535,7 @@ class NewAllApps: Fragment() { inner class LetterHolder(val binding: AbcBinding) : RecyclerView.ViewHolder(binding.root) { init { - if (PREFS!!.isAAllAppsAnimEnabled) { + if (PREFS.isAAllAppsAnimEnabled) { setViewInteractAnimation(itemView) } itemView.setOnClickListener { @@ -548,7 +548,7 @@ class NewAllApps: Fragment() { setViewInteractAnimation(itemView) itemView.setOnClickListener { visualFeedback(itemView) - if(PREFS!!.isAAllAppsAnimEnabled) { + if(PREFS.isAAllAppsAnimEnabled) { startDismissAnim(list[absoluteAdapterPosition]) } else { if(context != null) { @@ -717,7 +717,7 @@ class NewAllApps: Fragment() { } } private fun startDismissAnim(item: App) { - if (appAdapter == null || !PREFS!!.isAAllAppsAnimEnabled) { + if (appAdapter == null || !PREFS.isAAllAppsAnimEnabled) { startAppDelay(item) return } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/NewStart.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/NewStart.kt index ee9950d..f2c2d1c 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/NewStart.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/NewStart.kt @@ -112,7 +112,7 @@ class NewStart: Fragment(), OnStartDragListener { _binding = StartScreenBinding.inflate(inflater, container, false) val view = binding.root mainViewModel = ViewModelProvider(requireActivity())[MainViewModel::class.java] - if(PREFS!!.isWallpaperUsed) { + if(PREFS.isWallpaperUsed && activity != null) { setWallpaper() } binding.startFrame.setOnClickListener { @@ -145,8 +145,8 @@ class NewStart: Fragment(), OnStartDragListener { dismiss() } setNegativeButton(getString(R.string.deny)) { - PREFS!!.isWallpaperUsed = false - PREFS!!.isParallaxEnabled = false + PREFS.isWallpaperUsed = false + PREFS.isParallaxEnabled = false dismiss() requireActivity().recreate() } @@ -189,8 +189,7 @@ class NewStart: Fragment(), OnStartDragListener { super.onViewCreated(view, savedInstanceState) if(context != null) { viewLifecycleOwner.lifecycleScope.launch(defaultDispatcher) { - lastItemPos = mainViewModel.getTileDao().getUserTiles().last().appPos!! + 6 - Log.d("start", lastItemPos.toString()) + lastItemPos = mainViewModel.getTileDao().getUserTiles().size + 6 tiles = mainViewModel.getTileDao().getTilesList() setupRecyclerViewLayoutManager(requireContext()) setupAdapter() @@ -217,11 +216,11 @@ class NewStart: Fragment(), OnStartDragListener { binding.startAppsTiles.apply { layoutManager = mSpannedLayoutManager adapter = mAdapter - if (PREFS!!.isWallpaperUsed && !PREFS!!.isParallaxEnabled) { + if (PREFS.isWallpaperUsed && !PREFS.isParallaxEnabled) { addItemDecoration(Utils.MarginItemDecoration(this.context.resources.getDimensionPixelSize(R.dimen.tileMargin))) } mItemTouchHelper.attachToRecyclerView(this) - if(PREFS!!.isWallpaperUsed && checkStoragePermissions(requireActivity())) { + if(PREFS.isWallpaperUsed && checkStoragePermissions(requireActivity())) { binding.backgroundWallpaper.visibility = View.VISIBLE addOnScrollListener(ParallaxScroll(binding.backgroundWallpaper, mAdapter!!)) } @@ -237,8 +236,8 @@ class NewStart: Fragment(), OnStartDragListener { // phone mSpannedLayoutManager = SpannedGridLayoutManager( orientation = RecyclerView.VERTICAL, - rowCount = if(!PREFS!!.isMoreTilesEnabled) 8 else 12, - columnCount = if(!PREFS!!.isMoreTilesEnabled) 4 else 6 + rowCount = if(!PREFS.isMoreTilesEnabled) 8 else 12, + columnCount = if(!PREFS.isMoreTilesEnabled) 4 else 6 ) } else { // Landscape orientation @@ -247,15 +246,15 @@ class NewStart: Fragment(), OnStartDragListener { // tablet SpannedGridLayoutManager( orientation = RecyclerView.VERTICAL, - rowCount = if(!PREFS!!.isMoreTilesEnabled) 2 else 3, - columnCount = if(!PREFS!!.isMoreTilesEnabled) 4 else 6 + rowCount = if(!PREFS.isMoreTilesEnabled) 2 else 3, + columnCount = if(!PREFS.isMoreTilesEnabled) 4 else 6 ) } else { // phone but landscape SpannedGridLayoutManager( orientation = RecyclerView.VERTICAL, rowCount = 3, - columnCount = if(!PREFS!!.isMoreTilesEnabled) 4 else 6 + columnCount = if(!PREFS.isMoreTilesEnabled) 4 else 6 ) } } @@ -317,7 +316,7 @@ class NewStart: Fragment(), OnStartDragListener { } } private fun runAnim() { - if(PREFS!!.isTilesAnimEnabled) { + if(PREFS.isTilesAnimEnabled) { if (!mAdapter!!.isTopRight && !mAdapter!!.isTopLeft && !mAdapter!!.isBottomRight && !mAdapter!!.isBottomLeft) { mAdapter!!.isTopRight = true } @@ -363,15 +362,15 @@ class NewStart: Fragment(), OnStartDragListener { } private fun setEnterAnim() { mAdapter ?: return + val rotationY = when { + mAdapter!!.isTopLeft || mAdapter!!.isBottomLeft -> -90f + mAdapter!!.isBottomRight -> 90f + else -> 0f + } for (i in 0 until binding.startAppsTiles.childCount) { val holder = binding.startAppsTiles.findViewHolderForAdapterPosition(i) ?: continue if(holder.itemViewType == mAdapter!!.spaceType) continue val animatorSet = AnimatorSet() - val rotationY = when { - mAdapter!!.isTopLeft || mAdapter!!.isBottomLeft -> -90f - mAdapter!!.isBottomRight -> 90f - else -> 0f - } val rotation = when { mAdapter!!.isTopLeft || mAdapter!!.isBottomRight -> Random.nextInt(25, 45).toFloat() mAdapter!!.isTopRight || mAdapter!!.isBottomLeft -> Random.nextInt(-45, -25).toFloat() @@ -389,17 +388,13 @@ class NewStart: Fragment(), OnStartDragListener { } private fun hideTiles(showTiles: Boolean) { CoroutineScope(mainDispatcher).launch { - if (mAdapter == null || !PREFS!!.isTilesAnimEnabled) { + if (mAdapter == null || !PREFS.isTilesAnimEnabled) { cancel() return@launch } for (i in 0.. { Log.d("Start", "pkg installed") - val bool = PREFS!!.iconPackPackage != "null" + val bool = PREFS.iconPackPackage != "null" (requireActivity() as Main).generateIcon(packageName, bool) mainViewModel.addAppToList( App( @@ -440,7 +435,7 @@ class NewStart: Fragment(), OnStartDragListener { appPackage = packageName, id = Random.nextInt() )) - if (PREFS!!.pinNewApps) { + if (PREFS.pinNewApps) { pinApp(packageName) } } @@ -528,20 +523,20 @@ class NewStart: Fragment(), OnStartDragListener { Log.d("Start", "unregisterBroadcast() was called to a null receiver.") } } - override fun onDestroy() { super.onDestroy() unregisterBroadcast() } - - private suspend fun destroyTile(it: Tile) { - it.tileType = -1 - it.tileSize = "small" - it.appPackage = "" - it.tileColor = -1 - it.appLabel = "" - it.id = it.id!! / 2 - mainViewModel.getTileDao().updateTile(it) + private suspend fun destroyTile(tile: Tile) { + tile.apply { + tileType = -1 + tileSize = "small" + appPackage = "" + tileColor = -1 + appLabel = "" + id = this.id!! / 2 + mainViewModel.getTileDao().updateTile(this) + } } inner class ScrollListener(): RecyclerView.OnScrollListener() { @@ -595,12 +590,10 @@ class NewStart: Fragment(), OnStartDragListener { (requireActivity() as Main).configureViewPagerScroll(false) binding.startAppsTiles.animate().scaleX(0.9f).scaleY(0.9f).setDuration(300).start() binding.backgroundWallpaper.animate().scaleX(0.9f).scaleY(0.82f).setDuration(300).start() - if(PREFS!!.isParallaxEnabled || !PREFS!!.isWallpaperUsed) { - binding.startFrame.setBackgroundColor( - if (PREFS!!.isLightThemeUsed) ContextCompat.getColor( - context, - android.R.color.background_light - ) else ContextCompat.getColor(context, android.R.color.background_dark) + if(PREFS.isParallaxEnabled || !PREFS.isWallpaperUsed) { + binding.startFrame.setBackgroundColor(ContextCompat.getColor( + context, if(PREFS.isLightThemeUsed) android.R.color.background_light else android.R.color.background_dark + ) ) } for(anim in animList) { @@ -613,7 +606,7 @@ class NewStart: Fragment(), OnStartDragListener { (requireActivity() as Main).configureViewPagerScroll(true) binding.startAppsTiles.animate().scaleX(1f).scaleY(1f).setDuration(300).start() binding.backgroundWallpaper.animate().scaleX(1f).scaleY(1f).setDuration(300).start() - if(PREFS!!.isParallaxEnabled || !PREFS!!.isWallpaperUsed) { + if(PREFS.isParallaxEnabled || !PREFS.isWallpaperUsed) { binding.startFrame.background = null } isEditMode = false @@ -719,34 +712,25 @@ class NewStart: Fragment(), OnStartDragListener { imageView.layoutParams.apply { when (tileSize) { "small" -> { - width = - if (PREFS!!.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_small_moreTiles_on) else res.getDimensionPixelSize( - R.dimen.tile_small_moreTiles_off - ) - height = - if (PREFS!!.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_small_moreTiles_on) else res.getDimensionPixelSize( - R.dimen.tile_small_moreTiles_off - ) + val size = if (PREFS.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_small_moreTiles_on) else res.getDimensionPixelSize( + R.dimen.tile_small_moreTiles_off + ) + width = size + height = size } "medium" -> { - width = - if (PREFS!!.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_medium_moreTiles_on) else res.getDimensionPixelSize( - R.dimen.tile_medium_moreTiles_off - ) - height = - if (PREFS!!.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_medium_moreTiles_on) else res.getDimensionPixelSize( - R.dimen.tile_medium_moreTiles_off - ) + val size = if (PREFS.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_medium_moreTiles_on) else res.getDimensionPixelSize( + R.dimen.tile_medium_moreTiles_off + ) + width = size + height = size } "big" -> { - width = - if (PREFS!!.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_big_moreTiles_on) else res.getDimensionPixelSize( - R.dimen.tile_big_moreTiles_off - ) - height = - if (PREFS!!.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_big_moreTiles_on) else res.getDimensionPixelSize( - R.dimen.tile_big_moreTiles_off - ) + val size = if (PREFS.isMoreTilesEnabled) res.getDimensionPixelSize(R.dimen.tile_big_moreTiles_on) else res.getDimensionPixelSize( + R.dimen.tile_big_moreTiles_off + ) + width = size + height = size } else -> { width = res.getDimensionPixelSize(R.dimen.tile_medium_moreTiles_off) @@ -764,9 +748,9 @@ class NewStart: Fragment(), OnStartDragListener { ) ) } else { - if (PREFS!!.isWallpaperUsed) { + if (PREFS.isWallpaperUsed) { holder.binding.container.setBackgroundColor( - if (PREFS!!.isParallaxEnabled) ContextCompat.getColor( + if (PREFS.isParallaxEnabled) ContextCompat.getColor( context, R.color.transparent ) else accentColorFromPrefs(context) @@ -800,7 +784,7 @@ class NewStart: Fragment(), OnStartDragListener { mTextView.text = null } "medium" -> { - if (PREFS!!.isMoreTilesEnabled) { + if (PREFS.isMoreTilesEnabled) { mTextView.text = null } else { mTextView.text = item.appLabel @@ -858,7 +842,7 @@ class NewStart: Fragment(), OnStartDragListener { private fun showPopupWindow(holder: TileViewHolder, item: Tile, position: Int) { binding.startAppsTiles.isScrollEnabled = false val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater - val popupView: View = if(item.tileSize == "small" && PREFS!!.isMoreTilesEnabled) inflater.inflate(R.layout.tile_window_small, holder.itemView as ViewGroup, false) else inflater.inflate(R.layout.tile_window, holder.itemView as ViewGroup, false) + val popupView: View = inflater.inflate(if(item.tileSize == "small" && PREFS.isMoreTilesEnabled) R.layout.tile_window_small else R.layout.tile_window, holder.itemView as ViewGroup, false) val width = holder.itemView.width val height = holder.itemView.height val popupWindow = PopupWindow(popupView, width, height, true) @@ -1050,11 +1034,11 @@ class NewStart: Fragment(), OnStartDragListener { }) init { binding.cardContainer.apply { - if (PREFS!!.coloredStroke) strokeColor = Utils.launcherAccentColor(requireActivity().theme) - strokeWidth = if (PREFS!!.isWallpaperUsed && !PREFS!!.isParallaxEnabled) context?.resources?.getDimensionPixelSize(R.dimen.tileStrokeWidthDisabled)!! else context.resources?.getDimensionPixelSize(R.dimen.tileStrokeWidth)!! + if (PREFS.coloredStroke) strokeColor = Utils.launcherAccentColor(requireActivity().theme) + strokeWidth = if (PREFS.isWallpaperUsed && !PREFS.isParallaxEnabled) context?.resources?.getDimensionPixelSize(R.dimen.tileStrokeWidthDisabled)!! else context.resources?.getDimensionPixelSize(R.dimen.tileStrokeWidth)!! } binding.container.apply { - alpha = PREFS!!.tilesTransparency + alpha = PREFS.tilesTransparency setOnTouchListener { view, event -> val x = event.x val y = event.y @@ -1087,12 +1071,12 @@ class NewStart: Fragment(), OnStartDragListener { item.isSelected = true mainViewModel.getTileDao().updateTile(item) withContext(mainDispatcher) { - showPopupWindow(this@TileViewHolder, item, absoluteAdapterPosition) notifyItemChanged(absoluteAdapterPosition) + showPopupWindow(this@TileViewHolder, item, absoluteAdapterPosition) } } } else { - if(PREFS!!.isTilesAnimEnabled) { + if(PREFS.isTilesAnimEnabled) { mAdapter?.startDismissTilesAnim(item) } else { startApp(item.appPackage) @@ -1101,7 +1085,7 @@ class NewStart: Fragment(), OnStartDragListener { } private fun handleLongClick() { - if(!isEditMode && !PREFS!!.isStartBlocked) { + if(!isEditMode && !PREFS.isStartBlocked) { enableEditMode() } } @@ -1135,7 +1119,7 @@ class NewStart: Fragment(), OnStartDragListener { }**/ inner class SpaceViewHolder(binding: SpaceBinding) : RecyclerView.ViewHolder(binding.root) { init { - if(PREFS!!.isWallpaperUsed && !PREFS!!.isParallaxEnabled) { + if(PREFS.isWallpaperUsed && !PREFS.isParallaxEnabled) { itemView.setBackgroundColor(transparentColor) } itemView.setOnClickListener { @@ -1310,7 +1294,7 @@ class ParallaxScroll(private val wallpaper: ImageView, private val adapter: NewS @Suppress("DEPRECATION") class BackgroundDecoration() : RecyclerView.ItemDecoration() { - private val backgroundColor = if(PREFS!!.isLightThemeUsed) Color.WHITE else Color.BLACK + private val backgroundColor = if(PREFS.isLightThemeUsed) Color.WHITE else Color.BLACK override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) { super.onDraw(c, parent, state) diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/WelcomeActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/WelcomeActivity.kt index e4f3874..bd46996 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/WelcomeActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/WelcomeActivity.kt @@ -21,7 +21,7 @@ class WelcomeActivity: AppCompatActivity() { binding = OobeBinding.inflate(layoutInflater) setContentView(binding.root) applyWindowInsets(binding.coordinator) - if (PREFS!!.launcherState != 2) { + if (PREFS.launcherState != 2) { supportFragmentManager.commit { replace(R.id.fragment_container_view, WelcomeFragment(), "oobe") } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AdFragment.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AdFragment.kt deleted file mode 100644 index 4acb08c..0000000 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AdFragment.kt +++ /dev/null @@ -1,109 +0,0 @@ -package ru.dimon6018.metrolauncher.content.oobe.fragments - -import android.animation.AnimatorSet -import android.animation.ObjectAnimator -import android.content.Intent -import android.net.Uri -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.widget.ImageView -import androidx.fragment.app.Fragment -import androidx.fragment.app.commit -import androidx.lifecycle.lifecycleScope -import coil3.load -import com.google.android.material.dialog.MaterialAlertDialogBuilder -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch -import ru.dimon6018.metrolauncher.R -import ru.dimon6018.metrolauncher.content.oobe.WelcomeActivity -import ru.dimon6018.metrolauncher.databinding.OobeFragmentAdBinding - - -class AdFragment: Fragment() { - - private var _binding: OobeFragmentAdBinding? = null - private val binding get() = _binding!! - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View { - _binding = OobeFragmentAdBinding.inflate(inflater, container, false) - (requireActivity() as WelcomeActivity).setText(getString(R.string.advertisement)) - binding.back.setOnClickListener { - lifecycleScope.launch { - enterAnimation(true) - delay(200) - requireActivity().supportFragmentManager.commit { - replace(R.id.fragment_container_view, ConfigureFragment(), "oobe") - } - } - } - binding.next.setOnClickListener { - lifecycleScope.launch { - enterAnimation(true) - delay(200) - requireActivity().supportFragmentManager.commit { - replace(R.id.fragment_container_view, AppsFragment(), "oobe") - } - } - } - binding.openN11.setOnClickListener { - lifecycleScope.launch { - enterAnimation(true) - delay(200) - startActivity( - Intent( - Intent.ACTION_VIEW, - Uri.parse("https://github.com/queuejw/neko11") - ) - ) - } - } - binding.screenshotsAdButtonNeko11.setOnClickListener { - val dialog = MaterialAlertDialogBuilder(requireActivity()) - val dialogView: View = inflater.inflate(R.layout.ad, null) - dialog.setView(dialogView) - dialog.setPositiveButton(getString(android.R.string.ok), null) - val adImg1 = dialogView.findViewById(R.id.ad_img1) - val adImg2 = dialogView.findViewById(R.id.ad_img2) - val adImg3 = dialogView.findViewById(R.id.ad_img3) - adImg1.load("https://raw.githubusercontent.com/queuejw/Neko11/neko11-stable/screenshots/photo_2024-01-16_16-49-28.jpg") - adImg2.load("https://raw.githubusercontent.com/queuejw/Neko11/neko11-stable/screenshots/photo_2024-01-16_16-56-34%20(3).jpg") - adImg3.load("https://raw.githubusercontent.com/queuejw/Neko11/neko11-stable/screenshots/photo_2024-01-16_16-56-34.jpg") - dialog.show() - } - return binding.root - } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - private fun enterAnimation(exit: Boolean) { - val main = binding.root - val animatorSet = AnimatorSet() - if(exit) { - animatorSet.playTogether( - ObjectAnimator.ofFloat(main, "translationX", 0f, -1000f), - ObjectAnimator.ofFloat(main, "alpha", 1f, 0f), - ) - } else { - animatorSet.playTogether( - ObjectAnimator.ofFloat(main, "translationX", 1000f, 0f), - ObjectAnimator.ofFloat(main, "alpha", 0f, 1f), - ) - } - animatorSet.setDuration(300) - animatorSet.start() - } - - override fun onResume() { - enterAnimation(false) - super.onResume() - } - - override fun onPause() { - enterAnimation(true) - super.onPause() - } -} \ No newline at end of file diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AlmostDoneFragment.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AlmostDoneFragment.kt index 9a3c8de..c8b7e0f 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AlmostDoneFragment.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AlmostDoneFragment.kt @@ -19,7 +19,7 @@ class AlmostDoneFragment: Fragment() { private val binding get() = _binding!! override fun onCreate(savedInstanceState: Bundle?) { - PREFS!!.launcherState = 2 + PREFS.launcherState = 2 super.onCreate(savedInstanceState) } @@ -28,7 +28,7 @@ class AlmostDoneFragment: Fragment() { _binding = OobeFragmentAlmostdoneBinding.inflate(inflater, container, false) (requireActivity() as WelcomeActivity).setText(getString(R.string.welcomeAlmostDone)) binding.next.setOnClickListener { - PREFS!!.launcherState = 1 + PREFS.launcherState = 1 exitProcess(0) } return binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AppsFragment.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AppsFragment.kt index 9ea4da3..0b66c80 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AppsFragment.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/AppsFragment.kt @@ -63,7 +63,7 @@ class AppsFragment: Fragment() { val lm = LinearLayoutManager(requireContext()) var iconManager: IconPackManager? = null var isCustomIconsInstalled = false - if (PREFS!!.iconPackPackage != "null") { + if (PREFS.iconPackPackage != "null") { iconManager = IconPackManager(requireContext()) isCustomIconsInstalled = true } @@ -74,7 +74,7 @@ class AppsFragment: Fragment() { val bmp = if (!isCustomIconsInstalled) pm.getApplicationIcon(it.appPackage!!) else - iconManager?.getIconPackWithName(PREFS!!.iconPackPackage) + iconManager?.getIconPackWithName(PREFS.iconPackPackage) ?.getDrawableIconForPackage(it.appPackage!!, null) hashCache.append(it.id, bmp) } @@ -89,7 +89,7 @@ class AppsFragment: Fragment() { enterAnimation(true) delay(200) requireActivity().supportFragmentManager.commit { - replace(R.id.fragment_container_view, AdFragment(), "oobe") + replace(R.id.fragment_container_view, ConfigureFragment(), "oobe") } } } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/ConfigureFragment.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/ConfigureFragment.kt index ac47e52..892f280 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/ConfigureFragment.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/ConfigureFragment.kt @@ -47,7 +47,7 @@ class ConfigureFragment: Fragment() { enterAnimation(true) delay(200) requireActivity().supportFragmentManager.commit { - replace(R.id.fragment_container_view, AdFragment(), "oobe") + replace(R.id.fragment_container_view, AppsFragment(), "oobe") } } } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/CustomSettingsFragment.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/CustomSettingsFragment.kt index f223466..d2be4cf 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/CustomSettingsFragment.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/CustomSettingsFragment.kt @@ -38,7 +38,7 @@ class CustomSettingsFragment: Fragment() { enterAnimation(true) delay(200) requireActivity().supportFragmentManager.commit { - replace(R.id.fragment_container_view, AdFragment(), "oobe") + replace(R.id.fragment_container_view, AppsFragment(), "oobe") } } } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/WelcomeFragment.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/WelcomeFragment.kt index a045844..facbc94 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/WelcomeFragment.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/oobe/fragments/WelcomeFragment.kt @@ -42,9 +42,9 @@ class WelcomeFragment : Fragment() { } } } - if(!Application.PREFS!!.prefs.getBoolean("channelConfigured", false)) { + if(!Application.PREFS.prefs.getBoolean("channelConfigured", false)) { UpdateWorker.setupNotificationChannels(requireActivity()) - Application.PREFS!!.prefs.edit().putBoolean("channelConfigured", true).apply() + Application.PREFS.prefs.edit().putBoolean("channelConfigured", true).apply() } return binding.root } @@ -58,7 +58,7 @@ class WelcomeFragment : Fragment() { } private fun generatePlaceholders() { placeholderCoroutine.launch { - Application.PREFS!!.prefs.edit().putBoolean("placeholdersGenerated", true).apply() + Application.PREFS.prefs.edit().putBoolean("placeholdersGenerated", true).apply() generatePlaceholder(TileData.getTileData(requireContext()).getTileDao(), 84) cancel() } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/Reset.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/Reset.kt index e873ef4..e638a54 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/Reset.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/Reset.kt @@ -35,8 +35,8 @@ class Reset : AppCompatActivity() { lifecycleScope.launch(Dispatchers.IO) { dbApps!!.clearAllTables() dbBsod!!.clearAllTables() - PREFS!!.reset() - PREFS!!.launcherState = 0 + PREFS.reset() + PREFS.launcherState = 0 delay(3000) }.invokeOnCompletion { exitProcess(0) diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/SettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/SettingsActivity.kt index 7e42c52..a2a4b31 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/SettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/SettingsActivity.kt @@ -92,7 +92,7 @@ class SettingsActivity : AppCompatActivity() { } } private fun prepareMessage() { - if(!PREFS!!.prefs.getBoolean("tipSettingsEnabled", true) && Random.nextFloat() < 0.08 && PREFS!!.prefs.getBoolean("messageEnabled", true)) { + if(!PREFS.prefs.getBoolean("tipSettingsEnabled", true) && Random.nextFloat() < 0.08 && PREFS.prefs.getBoolean("messageEnabled", true)) { WPDialog(this).apply { setTopDialog(true) setTitle(getString(R.string.developer)) @@ -103,7 +103,7 @@ class SettingsActivity : AppCompatActivity() { dismiss() } setNeutralButton(getString(R.string.not_show_again)) { - PREFS!!.prefs.edit().putBoolean("messageEnabled", false).apply() + PREFS.prefs.edit().putBoolean("messageEnabled", false).apply() dismiss() } show() @@ -116,7 +116,7 @@ class SettingsActivity : AppCompatActivity() { setTitle(getString(R.string.developer)) setMessage(getString(R.string.dev_p2)) setPositiveButton(getString(R.string.hide)) { - PREFS!!.prefs.edit().putBoolean("messageEnabled", false).apply() + PREFS.prefs.edit().putBoolean("messageEnabled", false).apply() dismiss() } setNegativeButton(getString(R.string.support)) { @@ -127,13 +127,13 @@ class SettingsActivity : AppCompatActivity() { } } private fun prepareTip() { - if(PREFS!!.prefs.getBoolean("tipSettingsEnabled", true)) { + if(PREFS.prefs.getBoolean("tipSettingsEnabled", true)) { WPDialog(this).setTopDialog(true) .setTitle(getString(R.string.tip)) .setMessage(getString(R.string.tipSettings)) .setPositiveButton(getString(android.R.string.ok), null) .show() - PREFS!!.prefs.edit().putBoolean("tipSettingsEnabled", false).apply() + PREFS.prefs.edit().putBoolean("tipSettingsEnabled", false).apply() } } private fun setOnClickers() { @@ -156,7 +156,7 @@ class SettingsActivity : AppCompatActivity() { isEnter = true job?.cancel() job = lifecycleScope.launch { - if (PREFS!!.isTransitionAnimEnabled) { + if (PREFS.isTransitionAnimEnabled) { startAnim() } startActivity(intent) @@ -170,7 +170,7 @@ class SettingsActivity : AppCompatActivity() { } } private fun setupAnimForViews(view: View, dur: Long) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val animatorSet = AnimatorSet().apply { @@ -198,7 +198,7 @@ class SettingsActivity : AppCompatActivity() { setViewInteractAnimation(binding.settingsInclude.expSetting) } private suspend fun startAnim() { - if (PREFS!!.isTransitionAnimEnabled) { + if (PREFS.isTransitionAnimEnabled) { setupAnimations() CoroutineScope(Dispatchers.Main).launch { delay(200) @@ -214,20 +214,20 @@ class SettingsActivity : AppCompatActivity() { } } private fun hideViews() { - if (PREFS!!.isTransitionAnimEnabled) { + if (PREFS.isTransitionAnimEnabled) { viewList.forEach { (view, _) -> hideAnim(view) } } } private fun hideAnim(view: View?) { - if(view == null || !PREFS!!.isTransitionAnimEnabled) { + if(view == null || !PREFS.isTransitionAnimEnabled) { return } ObjectAnimator.ofFloat(view, "alpha", 1f, 0f).start() } private fun setAppTheme() { - if (PREFS!!.isLightThemeUsed) { + if (PREFS.isLightThemeUsed) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { (application as Application).setNightMode() } else { @@ -251,7 +251,7 @@ class SettingsActivity : AppCompatActivity() { override fun onResume() { super.onResume() binding.settingsInclude.themeSub.text = accentName(this) - binding.settingsInclude.navbarSub.text = when (PREFS!!.navBarColor) { + binding.settingsInclude.navbarSub.text = when (PREFS.navBarColor) { 0 -> getString(R.string.always_dark) 1 -> getString(R.string.always_light) 2 -> getString(R.string.matches_accent_color) @@ -260,11 +260,11 @@ class SettingsActivity : AppCompatActivity() { else -> getString(R.string.navigation_bar_2) } binding.settingsInclude.iconsSub.text = runCatching { - if (PREFS!!.iconPackPackage == "null") getString(R.string.iconPackNotSelectedSub) - else packageManager.getApplicationLabel(packageManager.getApplicationInfo(PREFS!!.iconPackPackage!!, 0)) + if (PREFS.iconPackPackage == "null") getString(R.string.iconPackNotSelectedSub) + else packageManager.getApplicationLabel(packageManager.getApplicationInfo(PREFS.iconPackPackage!!, 0)) }.getOrElse { getString(R.string.iconPackNotSelectedSub) } - if(PREFS!!.isPrefsChanged) { + if(PREFS.isPrefsChanged) { job?.cancel() restartDialog() } else { @@ -300,7 +300,7 @@ class SettingsActivity : AppCompatActivity() { val componentName = Intent(this, this::class.java).component val intent = Intent.makeRestartActivityTask(componentName) startActivity(intent) - PREFS!!.isPrefsChanged = false + PREFS.isPrefsChanged = false Runtime.getRuntime().exit(0) } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AboutSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AboutSettingsActivity.kt index 3929bea..b18fcbf 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AboutSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AboutSettingsActivity.kt @@ -80,7 +80,7 @@ class AboutSettingsActivity : AppCompatActivity() { startActivity(intent) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AllAppsSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AllAppsSettingsActivity.kt index f0bdb95..947a5fd 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AllAppsSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AllAppsSettingsActivity.kt @@ -18,52 +18,52 @@ class AllAppsSettingsActivity: AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(binding.root) binding.settingsInclude.settingsBtnSwitch.apply { - isChecked = PREFS!!.isSettingsBtnEnabled - text = if(PREFS!!.isSettingsBtnEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isSettingsBtnEnabled + text = if(PREFS.isSettingsBtnEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isSettingsBtnEnabled = isChecked - PREFS!!.isPrefsChanged = true - text = if(PREFS!!.isSettingsBtnEnabled) getString(R.string.on) else getString(R.string.off) + PREFS.isSettingsBtnEnabled = isChecked + PREFS.isPrefsChanged = true + text = if(PREFS.isSettingsBtnEnabled) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.alphabetSwitch.apply { - isChecked = PREFS!!.isAlphabetEnabled - text = if(PREFS!!.isAlphabetEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isAlphabetEnabled + text = if(PREFS.isAlphabetEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isAlphabetEnabled = isChecked - PREFS!!.isPrefsChanged = true - text = if(PREFS!!.isAlphabetEnabled) getString(R.string.on) else getString(R.string.off) + PREFS.isAlphabetEnabled = isChecked + PREFS.isPrefsChanged = true + text = if(PREFS.isAlphabetEnabled) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.disableAllAppsSwitch.apply { - isChecked = PREFS!!.isAllAppsEnabled - text = if(PREFS!!.isAllAppsEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isAllAppsEnabled + text = if(PREFS.isAllAppsEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isAllAppsEnabled = isChecked - PREFS!!.isPrefsChanged = true - text = if(PREFS!!.isAllAppsEnabled) getString(R.string.on) else getString(R.string.off) + PREFS.isAllAppsEnabled = isChecked + PREFS.isPrefsChanged = true + text = if(PREFS.isAllAppsEnabled) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.keyboardWhenSearchingSwitch.apply { - isChecked = PREFS!!.showKeyboardWhenSearching - text = if(PREFS!!.showKeyboardWhenSearching) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.showKeyboardWhenSearching + text = if(PREFS.showKeyboardWhenSearching) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.showKeyboardWhenSearching = isChecked - text = if(PREFS!!.showKeyboardWhenSearching) getString(R.string.on) else getString(R.string.off) + PREFS.showKeyboardWhenSearching = isChecked + text = if(PREFS.showKeyboardWhenSearching) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.keyboardWhenAllAppsOpened.apply { - isChecked = PREFS!!.showKeyboardWhenOpeningAllApps - text = if(PREFS!!.showKeyboardWhenOpeningAllApps) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.showKeyboardWhenOpeningAllApps + text = if(PREFS.showKeyboardWhenOpeningAllApps) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.showKeyboardWhenOpeningAllApps = isChecked - text = if(PREFS!!.showKeyboardWhenOpeningAllApps) getString(R.string.on) else getString(R.string.off) + PREFS.showKeyboardWhenOpeningAllApps = isChecked + text = if(PREFS.showKeyboardWhenOpeningAllApps) getString(R.string.on) else getString(R.string.off) } } applyWindowInsets(binding.root) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AnimationSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AnimationSettingsActivity.kt index 970c01a..bf01652 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AnimationSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/AnimationSettingsActivity.kt @@ -21,57 +21,57 @@ class AnimationSettingsActivity: AppCompatActivity() { setContentView(binding.root) applyWindowInsets(binding.root) setupLayout() - if(isDevMode(this) && PREFS!!.isAutoShutdownAnimEnabled) { + if(isDevMode(this) && PREFS.isAutoShutdownAnimEnabled) { WPDialog(this).setTopDialog(true).setTitle(getString(R.string.tip)).setMessage(getString(R.string.animations_dev_mode)).setPositiveButton(getString(android.R.string.ok), null).show() } } private fun setupLayout() { binding.settingsInclude.tilesAnimCheckbox.apply { - isChecked = PREFS!!.isTilesAnimEnabled + isChecked = PREFS.isTilesAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isTilesAnimEnabled = isChecked + PREFS.isTilesAnimEnabled = isChecked } } binding.settingsInclude.liveTilesAnimCheckbox.apply { - isChecked = PREFS!!.isLiveTilesAnimEnabled + isChecked = PREFS.isLiveTilesAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isLiveTilesAnimEnabled = isChecked + PREFS.isLiveTilesAnimEnabled = isChecked } } binding.settingsInclude.allAppsAnimCheckbox.apply { - isChecked = PREFS!!.isAAllAppsAnimEnabled + isChecked = PREFS.isAAllAppsAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isAAllAppsAnimEnabled = isChecked + PREFS.isAAllAppsAnimEnabled = isChecked } } binding.settingsInclude.transitionAnimCheckbox.apply { - isChecked = PREFS!!.isTransitionAnimEnabled + isChecked = PREFS.isTransitionAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isTransitionAnimEnabled = isChecked - PREFS!!.isPrefsChanged = true + PREFS.isTransitionAnimEnabled = isChecked + PREFS.isPrefsChanged = true } } binding.settingsInclude.alphabetAnimCheckbox.apply { - isChecked = PREFS!!.isAlphabetAnimEnabled + isChecked = PREFS.isAlphabetAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isAlphabetAnimEnabled = isChecked + PREFS.isAlphabetAnimEnabled = isChecked } } binding.settingsInclude.tilesPhoneStartAnimCheckbox.apply { - isChecked = PREFS!!.isTilesScreenAnimEnabled + isChecked = PREFS.isTilesScreenAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isTilesScreenAnimEnabled = isChecked + PREFS.isTilesScreenAnimEnabled = isChecked } } binding.settingsInclude.autoShutdownAnimsCheckbox.apply { - isChecked = PREFS!!.isAutoShutdownAnimEnabled + isChecked = PREFS.isAutoShutdownAnimEnabled setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isAutoShutdownAnimEnabled = isChecked + PREFS.isAutoShutdownAnimEnabled = isChecked } } } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ExperimentsSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ExperimentsSettingsActivity.kt index 4be341d..9e6eb9d 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ExperimentsSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ExperimentsSettingsActivity.kt @@ -19,7 +19,7 @@ class ExperimentsSettingsActivity: AppCompatActivity() { applyWindowInsets(binding.root) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackBsodListActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackBsodListActivity.kt index e918367..31dc997 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackBsodListActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackBsodListActivity.kt @@ -53,7 +53,7 @@ class FeedbackBsodListActivity: AppCompatActivity() { } } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackSettingsActivity.kt index f93b506..4a5885f 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/FeedbackSettingsActivity.kt @@ -45,25 +45,25 @@ class FeedbackSettingsActivity: AppCompatActivity() { }.start() } binding.settingsInclude.sendFeedbackSwitch.apply { - isChecked = PREFS!!.isFeedbackEnabled - text = if(PREFS!!.isFeedbackEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isFeedbackEnabled + text = if(PREFS.isFeedbackEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isFeedbackEnabled = isChecked + PREFS.isFeedbackEnabled = isChecked text = if(isChecked) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.setCrashLogLimitBtn.apply { - setButtonText(PREFS!!, this) + setButtonText(PREFS, this) setOnClickListener { binding.settingsInclude.chooseBsodInfoLimit.visibility = View.VISIBLE visibility = View.GONE } } binding.settingsInclude.showErrorDetailsOnBsodSwitch.apply { - PREFS!!.bsodOutputEnabled - text = if(PREFS!!.bsodOutputEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.bsodOutputEnabled + text = if(PREFS.bsodOutputEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.bsodOutputEnabled = isChecked + PREFS.bsodOutputEnabled = isChecked text = if(isChecked) getString(R.string.on) else getString(R.string.off) } } @@ -71,10 +71,10 @@ class FeedbackSettingsActivity: AppCompatActivity() { private fun updateMaxLogsSize(view: View, value: Int) { view.setOnClickListener { - PREFS!!.maxCrashLogs = value + PREFS.maxCrashLogs = value binding.settingsInclude.chooseBsodInfoLimit.visibility = View.GONE binding.settingsInclude.setCrashLogLimitBtn.visibility = View.VISIBLE - setButtonText(PREFS!!, binding.settingsInclude.setCrashLogLimitBtn) + setButtonText(PREFS, binding.settingsInclude.setCrashLogLimitBtn) } } private fun setButtonText(prefs: Prefs, button: MaterialButton) { @@ -87,7 +87,7 @@ class FeedbackSettingsActivity: AppCompatActivity() { } } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/IconSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/IconSettingsActivity.kt index c940d91..4ea15a0 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/IconSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/IconSettingsActivity.kt @@ -3,7 +3,6 @@ package ru.dimon6018.metrolauncher.content.settings.activities import android.animation.AnimatorSet import android.animation.ObjectAnimator import android.content.Intent -import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.view.LayoutInflater @@ -76,13 +75,15 @@ class IconSettingsActivity: AppCompatActivity() { setUi() } binding.settingsInclude.removeIconPack.setOnClickListener { - PREFS!!.iconPackPackage = "null" - PREFS!!.isPrefsChanged = true - PREFS!!.iconPackChanged = true + PREFS.apply { + iconPackPackage = "null" + iconPackChanged = true + isPrefsChanged = true + } setUi() } binding.settingsInclude.downloadIconPacks.setOnClickListener { - startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/queuejw/lawnicons-m/releases/latest"))) + startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/queuejw/mpl_updates/releases/download/release/Lawnicons.apk"))) } } private fun setIconPacks() { @@ -118,7 +119,7 @@ class IconSettingsActivity: AppCompatActivity() { } binding.settingsInclude.removeIconPack.visibility = View.GONE } else { - val label = if(PREFS!!.iconPackPackage == "null") { + val label = if(PREFS.iconPackPackage == "null") { binding.settingsInclude.currentIconPackText.visibility = View.GONE binding.settingsInclude.removeIconPack.visibility = View.GONE binding.settingsInclude.currentIconPackError.apply { @@ -127,12 +128,12 @@ class IconSettingsActivity: AppCompatActivity() { } "null" } else { - try { + runCatching { binding.settingsInclude.currentIconPackText.visibility = View.VISIBLE binding.settingsInclude.currentIconPackError.visibility = View.GONE binding.settingsInclude.removeIconPack.visibility = View.VISIBLE - packageManager!!.getApplicationLabel(packageManager.getApplicationInfo(PREFS!!.iconPackPackage!!, 0)) - } catch (e: PackageManager.NameNotFoundException) { + packageManager!!.getApplicationLabel(packageManager.getApplicationInfo(PREFS.iconPackPackage!!, 0)).toString() + }.getOrElse { binding.settingsInclude.currentIconPackText.visibility = View.GONE binding.settingsInclude.currentIconPackError.apply { visibility = View.VISIBLE @@ -146,7 +147,7 @@ class IconSettingsActivity: AppCompatActivity() { binding.settingsInclude.chooseIconPack.text = if(isListVisible) getString(android.R.string.cancel) else getString(R.string.choose_icon_pack) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root @@ -193,9 +194,11 @@ class IconSettingsActivity: AppCompatActivity() { holder.label.text = item.name holder.icon.setImageBitmap(packageManager.getApplicationIcon(item.appPackage).toBitmap(iconSize, iconSize)) holder.itemView.setOnClickListener { - PREFS!!.iconPackPackage = item.appPackage - PREFS!!.iconPackChanged = true - PREFS!!.isPrefsChanged = true + PREFS.apply { + iconPackPackage = item.appPackage + iconPackChanged = true + isPrefsChanged = true + } binding.settingsInclude.iconPackList.visibility = View.GONE isListVisible = false setUi() diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/NavBarSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/NavBarSettingsActivity.kt index bd3960d..edd6dad 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/NavBarSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/NavBarSettingsActivity.kt @@ -24,7 +24,35 @@ class NavBarSettingsActivity: AppCompatActivity() { super.onCreate(savedInstanceState) WindowCompat.setDecorFitsSystemWindows(window, false) setContentView(binding.root) - when(PREFS!!.navBarColor) { + setNavBarColorRadioGroup() + binding.settingsInclude.navbarRadioGroup.setOnCheckedChangeListener { _, checkedId -> + changeNavBarColor(checkedId) + PREFS.isPrefsChanged = true + } + applyWindowInsets(binding.root) + updateCurrentIcon() + + binding.settingsInclude.chooseStartIconBtn.setOnClickListener { + iconsBottomSheet() + } + binding.settingsInclude.searchBarSwitch.apply { + isChecked = PREFS.isSearchBarEnabled + text = if(PREFS.isSearchBarEnabled) getString(R.string.on) else getString(R.string.off) + setOnCheckedChangeListener { _, isChecked -> + PREFS.isSearchBarEnabled = isChecked + text = if(isChecked) getString(R.string.on) else getString(R.string.off) + PREFS.isPrefsChanged = true + } + } + binding.settingsInclude.maxResultsSlider.apply { + value = PREFS.maxResultsSearchBar.toFloat() + addOnChangeListener(Slider.OnChangeListener { _: Slider?, value: Float, _: Boolean -> + PREFS.maxResultsSearchBar = value.toInt() + }) + } + } + private fun setNavBarColorRadioGroup() { + when(PREFS.navBarColor) { 0 -> { binding.settingsInclude.alwaysDark.isChecked = true binding.settingsInclude.alwaysLight.isChecked = false @@ -61,72 +89,9 @@ class NavBarSettingsActivity: AppCompatActivity() { binding.settingsInclude.auto.isChecked = true } } - binding.settingsInclude.navbarRadioGroup.setOnCheckedChangeListener { _, checkedId -> - when(checkedId) { - binding.settingsInclude.alwaysDark.id -> { - PREFS!!.navBarColor = 0 - } - binding.settingsInclude.alwaysLight.id -> { - PREFS!!.navBarColor = 1 - } - binding.settingsInclude.byTheme.id -> { - PREFS!!.navBarColor = 2 - } - binding.settingsInclude.hidden.id -> { - PREFS!!.navBarColor = 3 - } - binding.settingsInclude.auto.id -> { - PREFS!!.navBarColor = 4 - } - } - PREFS!!.isPrefsChanged = true - } - applyWindowInsets(binding.root) - updateCurrentIcon() - - binding.settingsInclude.chooseStartIconBtn.setOnClickListener { - val bottomSheet = BottomSheetDialog(this) - val bBidding = NavbarIconChooseBinding.inflate(LayoutInflater.from(this)) - bottomSheet.setContentView(bBidding.root) - bottomSheet.dismissWithAnimation = true - bBidding.icon0.setOnClickListener { - PREFS!!.navBarIconValue = 1 - updateCurrentIcon() - PREFS!!.isPrefsChanged = true - bottomSheet.dismiss() - } - bBidding.icon1.setOnClickListener { - PREFS!!.navBarIconValue = 0 - updateCurrentIcon() - PREFS!!.isPrefsChanged = true - bottomSheet.dismiss() - } - bBidding.icon2.setOnClickListener { - PREFS!!.navBarIconValue = 2 - updateCurrentIcon() - PREFS!!.isPrefsChanged = true - bottomSheet.dismiss() - } - bottomSheet.show() - } - binding.settingsInclude.searchBarSwitch.apply { - isChecked = PREFS!!.isSearchBarEnabled - text = if(PREFS!!.isSearchBarEnabled) getString(R.string.on) else getString(R.string.off) - setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isSearchBarEnabled = isChecked - text = if(isChecked) getString(R.string.on) else getString(R.string.off) - PREFS!!.isPrefsChanged = true - } - } - binding.settingsInclude.maxResultsSlider.apply { - value = PREFS!!.maxResultsSearchBar.toFloat() - addOnChangeListener(Slider.OnChangeListener { _: Slider?, value: Float, _: Boolean -> - PREFS!!.maxResultsSearchBar = value.toInt() - }) - } } private fun updateCurrentIcon() { - binding.settingsInclude.currentStartIcon.setImageDrawable(when(PREFS!!.navBarIconValue) { + binding.settingsInclude.currentStartIcon.setImageDrawable(when(PREFS.navBarIconValue) { 0 -> { ContextCompat.getDrawable(this, R.drawable.ic_os_windows_8) } @@ -142,7 +107,7 @@ class NavBarSettingsActivity: AppCompatActivity() { }) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root @@ -170,4 +135,50 @@ class NavBarSettingsActivity: AppCompatActivity() { enterAnimation(true) super.onPause() } + + fun changeNavBarColor(checkedId: Int) { + when(checkedId) { + binding.settingsInclude.alwaysDark.id -> { + PREFS.navBarColor = 0 + } + binding.settingsInclude.alwaysLight.id -> { + PREFS.navBarColor = 1 + } + binding.settingsInclude.byTheme.id -> { + PREFS.navBarColor = 2 + } + binding.settingsInclude.hidden.id -> { + PREFS.navBarColor = 3 + } + binding.settingsInclude.auto.id -> { + PREFS.navBarColor = 4 + } + } + } + + fun iconsBottomSheet() { + val bottomSheet = BottomSheetDialog(this) + val bBidding = NavbarIconChooseBinding.inflate(LayoutInflater.from(this)) + bottomSheet.setContentView(bBidding.root) + bottomSheet.dismissWithAnimation = true + bBidding.icon0.setOnClickListener { + PREFS.navBarIconValue = 1 + updateCurrentIcon() + PREFS.isPrefsChanged = true + bottomSheet.dismiss() + } + bBidding.icon1.setOnClickListener { + PREFS.navBarIconValue = 0 + updateCurrentIcon() + PREFS.isPrefsChanged = true + bottomSheet.dismiss() + } + bBidding.icon2.setOnClickListener { + PREFS.navBarIconValue = 2 + updateCurrentIcon() + PREFS.isPrefsChanged = true + bottomSheet.dismiss() + } + bottomSheet.show() + } } \ No newline at end of file diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ThemeSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ThemeSettingsActivity.kt index fae684b..e98fc07 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ThemeSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/ThemeSettingsActivity.kt @@ -51,52 +51,58 @@ class ThemeSettingsActivity : AppCompatActivity() { private fun configure() { binding.settingsInclude.choosedAccentName.text = accentName(this) binding.settingsInclude.chooseTheme.apply { - text = if (PREFS!!.isLightThemeUsed) getString(R.string.light) else getString(R.string.dark) + text = if (PREFS.isLightThemeUsed) getString(R.string.light) else getString(R.string.dark) setOnClickListener { visibility = View.GONE binding.settingsInclude.chooseThemeMenu.visibility = View.VISIBLE } } binding.settingsInclude.chooseLight.setOnClickListener { - PREFS!!.isLightThemeUsed = true - PREFS!!.isPrefsChanged = true + PREFS.apply { + isLightThemeUsed = true + isPrefsChanged = true + } restoreThemeButtonsAndApplyChanges() } binding.settingsInclude.chooseDark.setOnClickListener { - PREFS!!.isLightThemeUsed = false - PREFS!!.isPrefsChanged = true + PREFS.apply { + isLightThemeUsed = false + isPrefsChanged = true + } restoreThemeButtonsAndApplyChanges() } binding.settingsInclude.chooseAccent.setOnClickListener { AccentDialog.display(supportFragmentManager) } binding.settingsInclude.moreTilesSwitch.apply { - isChecked = PREFS!!.isMoreTilesEnabled - text = if(PREFS!!.isMoreTilesEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isMoreTilesEnabled + text = if(PREFS.isMoreTilesEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isMoreTilesEnabled = isChecked + PREFS.apply { + isMoreTilesEnabled = isChecked + isPrefsChanged = true + } text = if (isChecked) getString(R.string.on) else getString(R.string.off) - PREFS!!.isPrefsChanged = true setImg() } } binding.settingsInclude.newAppsToStartSwitch.apply { - isChecked = PREFS!!.pinNewApps - text = if(PREFS!!.pinNewApps) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.pinNewApps + text = if(PREFS.pinNewApps) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.pinNewApps = isChecked + PREFS.pinNewApps = isChecked text = if (isChecked) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.parallaxSwitch.apply { - isChecked = PREFS!!.isParallaxEnabled - text = if(PREFS!!.isParallaxEnabled) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isParallaxEnabled + text = if(PREFS.isParallaxEnabled) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, chk -> - if (PREFS!!.isWallpaperUsed) { - PREFS!!.isParallaxEnabled = chk - PREFS!!.isPrefsChanged = true + if (PREFS.isWallpaperUsed) { + PREFS.isParallaxEnabled = chk + PREFS.isPrefsChanged = true text = if (chk) getString(R.string.on) else getString(R.string.off) } else { if (chk) { - if(PREFS!!.isTransitionAnimEnabled) { + if(PREFS.isTransitionAnimEnabled) { binding.root.animate().alpha(0.7f).setDuration(200).start() } isChecked = false @@ -106,11 +112,11 @@ class ThemeSettingsActivity : AppCompatActivity() { } } binding.settingsInclude.wallpaperShowSwtich.apply { - isChecked = PREFS!!.isWallpaperUsed - text = if(PREFS!!.isWallpaperUsed) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isWallpaperUsed + text = if(PREFS.isWallpaperUsed) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, check -> - PREFS!!.isWallpaperUsed = check - PREFS!!.isPrefsChanged = true + PREFS.isWallpaperUsed = check + PREFS.isPrefsChanged = true text = if(check) getString(R.string.on) else getString(R.string.off) } } @@ -118,14 +124,14 @@ class ThemeSettingsActivity : AppCompatActivity() { if(!DynamicColors.isDynamicColorAvailable()) { isEnabled = false } - setChecked(PREFS!!.accentColor == 20) - text = if(PREFS!!.accentColor == 20) getString(R.string.on) else getString(R.string.off) + setChecked(PREFS.accentColor == 20) + text = if(PREFS.accentColor == 20) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> if (DynamicColors.isDynamicColorAvailable()) { if (isChecked) { - PREFS!!.accentColor = 20 + PREFS.accentColor = 20 } else { - PREFS!!.accentColor = PREFS!!.prefs.getInt("previous_accent_color", 5) + PREFS.accentColor = PREFS.prefs.getInt("previous_accent_color", 5) } recreate() } else { @@ -138,20 +144,20 @@ class ThemeSettingsActivity : AppCompatActivity() { } } binding.settingsInclude.blockStartSwitch.apply { - isChecked = PREFS!!.isStartBlocked - text = if(PREFS!!.isStartBlocked) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.isStartBlocked + text = if(PREFS.isStartBlocked) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isStartBlocked = isChecked + PREFS.isStartBlocked = isChecked text = if(isChecked) getString(R.string.on) else getString(R.string.off) } } binding.settingsInclude.coloredStrokeSwitch.apply { - isChecked = PREFS!!.coloredStroke - text = if(PREFS!!.coloredStroke) getString(R.string.on) else getString(R.string.off) + isChecked = PREFS.coloredStroke + text = if(PREFS.coloredStroke) getString(R.string.on) else getString(R.string.off) setOnCheckedChangeListener { _, isChecked -> - PREFS!!.coloredStroke = isChecked + PREFS.coloredStroke = isChecked text = if(isChecked) getString(R.string.on) else getString(R.string.off) - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true } } setOrientationButtons() @@ -164,17 +170,17 @@ class ThemeSettingsActivity : AppCompatActivity() { binding.settingsInclude.accentTip.setText(spannable, TextView.BufferType.SPANNABLE) } private fun prepareTip() { - if(PREFS!!.prefs.getBoolean("tipSettingsThemeEnabled", true)) { + if(PREFS.prefs.getBoolean("tipSettingsThemeEnabled", true)) { WPDialog(this).setTopDialog(true) .setTitle(getString(R.string.tip)) .setMessage(getString(R.string.tipSettingsTheme)) .setPositiveButton(getString(android.R.string.ok), null) .show() - PREFS!!.prefs.edit().putBoolean("tipSettingsThemeEnabled", false).apply() + PREFS.prefs.edit().putBoolean("tipSettingsThemeEnabled", false).apply() } } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root @@ -202,7 +208,7 @@ class ThemeSettingsActivity : AppCompatActivity() { enterAnimation(false) } private fun setImg() { - binding.settingsInclude.moreTilesImage.setImageResource(if(PREFS!!.isMoreTilesEnabled) R.mipmap.tiles_small else R.mipmap.tiles_default) + binding.settingsInclude.moreTilesImage.setImageResource(if(PREFS.isMoreTilesEnabled) R.mipmap.tiles_small else R.mipmap.tiles_default) } private fun restoreThemeButtonsAndApplyChanges() { binding.settingsInclude.chooseTheme.visibility = View.VISIBLE @@ -210,7 +216,7 @@ class ThemeSettingsActivity : AppCompatActivity() { setAppTheme() } private fun setAppTheme() { - if (Prefs(this).isLightThemeUsed) { + if (PREFS.isLightThemeUsed) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { (application as Application).setNightMode() } else { @@ -253,140 +259,140 @@ class ThemeSettingsActivity : AppCompatActivity() { lime.setOnClickListener { prefs.accentColor = 0 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val green = view.findViewById(R.id.choose_color_green) green.setOnClickListener { prefs.accentColor = 1 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val emerald = view.findViewById(R.id.choose_color_emerald) emerald.setOnClickListener { prefs.accentColor = 2 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val cyan = view.findViewById(R.id.choose_color_cyan) cyan.setOnClickListener { prefs.accentColor = 3 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val teal = view.findViewById(R.id.choose_color_teal) teal.setOnClickListener { prefs.accentColor = 4 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val cobalt = view.findViewById(R.id.choose_color_cobalt) cobalt.setOnClickListener { prefs.accentColor = 5 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val indigo = view.findViewById(R.id.choose_color_indigo) indigo.setOnClickListener { prefs.accentColor = 6 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val violet = view.findViewById(R.id.choose_color_violet) violet.setOnClickListener { prefs.accentColor = 7 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val pink = view.findViewById(R.id.choose_color_pink) pink.setOnClickListener { prefs.accentColor = 8 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val magenta = view.findViewById(R.id.choose_color_magenta) magenta.setOnClickListener { prefs.accentColor = 9 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val crimson = view.findViewById(R.id.choose_color_crimson) crimson.setOnClickListener { prefs.accentColor = 10 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val red = view.findViewById(R.id.choose_color_red) red.setOnClickListener { prefs.accentColor = 11 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val orange = view.findViewById(R.id.choose_color_orange) orange.setOnClickListener { prefs.accentColor = 12 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val amber = view.findViewById(R.id.choose_color_amber) amber.setOnClickListener { prefs.accentColor = 13 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val yellow = view.findViewById(R.id.choose_color_yellow) yellow.setOnClickListener { prefs.accentColor = 14 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val brown = view.findViewById(R.id.choose_color_brown) brown.setOnClickListener { prefs.accentColor = 15 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val olive = view.findViewById(R.id.choose_color_olive) olive.setOnClickListener { prefs.accentColor = 16 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val steel = view.findViewById(R.id.choose_color_steel) steel.setOnClickListener { prefs.accentColor = 17 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val mauve = view.findViewById(R.id.choose_color_mauve) mauve.setOnClickListener { prefs.accentColor = 18 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } val taupe = view.findViewById(R.id.choose_color_taupe) taupe.setOnClickListener { prefs.accentColor = 19 dismiss() - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true requireActivity().recreate() } } @@ -404,24 +410,23 @@ class ThemeSettingsActivity : AppCompatActivity() { "p" to Triple(true, false, false), "l" to Triple(false, true, false) ) - val (portrait, landscape, default) = orientations[PREFS!!.orientation] ?: Triple(false, false, true) + val (portrait, landscape, default) = orientations[PREFS.orientation] ?: Triple(false, false, true) binding.settingsInclude.portraitOrientation.isChecked = portrait binding.settingsInclude.landscapeOrientation.isChecked = landscape binding.settingsInclude.defaultOrientation.isChecked = default - binding.settingsInclude.orientationRadioGroup.setOnCheckedChangeListener { _, checkedId -> when(checkedId) { binding.settingsInclude.portraitOrientation.id -> { - PREFS!!.orientation = "p" + PREFS.orientation = "p" } binding.settingsInclude.landscapeOrientation.id -> { - PREFS!!.orientation = "l" + PREFS.orientation = "l" } binding.settingsInclude.defaultOrientation.id -> { - PREFS!!.orientation = "default" + PREFS.orientation = "default" } } - PREFS!!.isPrefsChanged = true + PREFS.isPrefsChanged = true } } @@ -430,21 +435,21 @@ class ThemeSettingsActivity : AppCompatActivity() { setTitle(getString(R.string.tip)) setMessage(context.getString(R.string.parallax_warn)) setPositiveButton(getString(R.string.yes)) { - PREFS!!.isWallpaperUsed = true - PREFS!!.isParallaxEnabled = true - PREFS!!.isPrefsChanged = true + PREFS.apply { + isWallpaperUsed = true + isParallaxEnabled = true + isPrefsChanged = true + } switch.isChecked = true binding.settingsInclude.wallpaperShowSwtich.isChecked = true dismiss() - switch.text = if (PREFS!!.isParallaxEnabled) getString(R.string.on) else getString( - R.string.off - ) + switch.text = getString(R.string.on) } setNegativeButton(getString(android.R.string.cancel)) { dismiss() } setDismissListener { - if(PREFS!!.isTransitionAnimEnabled) { + if(PREFS.isTransitionAnimEnabled) { binding.root.animate().alpha(1f).setDuration(200).start() } } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/TileSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/TileSettingsActivity.kt index ce0718f..23386e0 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/TileSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/TileSettingsActivity.kt @@ -22,10 +22,10 @@ class TileSettingsActivity: AppCompatActivity() { } private fun initView() { binding.settingsInclude.alphaSlider.apply { - value = PREFS!!.tilesTransparency + value = PREFS.tilesTransparency addOnChangeListener(Slider.OnChangeListener { _: Slider?, value: Float, _: Boolean -> - PREFS!!.tilesTransparency = value - PREFS!!.isPrefsChanged = true + PREFS.tilesTransparency = value + PREFS.isPrefsChanged = true }) } } @@ -34,7 +34,7 @@ class TileSettingsActivity: AppCompatActivity() { enterAnimation(false) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/UpdateActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/UpdateActivity.kt index 185ce11..a68054a 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/UpdateActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/UpdateActivity.kt @@ -70,11 +70,11 @@ class UpdateActivity: AppCompatActivity() { } private fun setOnClickers() { binding.settingsInclude.AutoUpdateCheckBox.setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isAutoUpdateEnabled = isChecked + PREFS.isAutoUpdateEnabled = isChecked refreshUi() } binding.settingsInclude.UpdateNotifyCheckBox.setOnCheckedChangeListener { _, isChecked -> - PREFS!!.isUpdateNotificationEnabled = isChecked + PREFS.isUpdateNotificationEnabled = isChecked if (isChecked) { UpdateWorker.scheduleWork(this) } else { @@ -90,21 +90,21 @@ class UpdateActivity: AppCompatActivity() { } binding.settingsInclude.checkForUpdatesBtn.setOnClickListener { if(!checkStoragePermissions(this)) { - PREFS!!.updateState = 5 + PREFS.updateState = 5 refreshUi() showPermsDialog() return@setOnClickListener } - when(PREFS!!.updateState) { + when(PREFS.updateState) { 4 -> { try { val file = File(Environment.getExternalStorageDirectory().toString() + "/Download/", "MPL_update.apk") val uri = FileProvider.getUriForFile(this, applicationContext.packageName + ".provider", file) - PREFS!!.prefs.edit().putBoolean("updateInstalled", true).apply() + PREFS.prefs.edit().putBoolean("updateInstalled", true).apply() openFile(uri, this) } catch (e: Exception) { Log.i("InstallAPK", "error: $e") - PREFS!!.updateState = 5 + PREFS.updateState = 5 refreshUi() saveError(e.toString(), db!!) } @@ -114,7 +114,7 @@ class UpdateActivity: AppCompatActivity() { checkDownload() } else -> { - PREFS!!.updateState = 1 + PREFS.updateState = 1 refreshUi() checkForUpdates() } @@ -122,16 +122,16 @@ class UpdateActivity: AppCompatActivity() { } binding.settingsInclude.cancelButton.setOnClickListener { val ver = if (UpdateDataParser.verCode == null) { - PREFS!!.versionCode + PREFS.versionCode } else { UpdateDataParser.verCode } if (ver == VERSION_CODE) { - PREFS!!.updateState = 3 + PREFS.updateState = 3 } else { - PREFS!!.updateState = 0 + PREFS.updateState = 0 } - if (PREFS!!.updateState == 1) { + if (PREFS.updateState == 1) { return@setOnClickListener } isUpdateDownloading = false @@ -139,22 +139,22 @@ class UpdateActivity: AppCompatActivity() { deleteUpdateFile(this) refreshUi() } - if(PREFS!!.prefs.getBoolean("permsDialogUpdateScreenEnabled", true) && !checkStoragePermissions(this)) { + if(PREFS.prefs.getBoolean("permsDialogUpdateScreenEnabled", true) && !checkStoragePermissions(this)) { showPermsDialog() } } private fun prepareTip() { - if(PREFS!!.prefs.getBoolean("tipSettingsUpdatesEnabled", true)) { + if(PREFS.prefs.getBoolean("tipSettingsUpdatesEnabled", true)) { WPDialog(this).setTopDialog(true) .setTitle(getString(R.string.tip)) .setMessage(getString(R.string.tipSettingsUpdates)) .setPositiveButton(getString(android.R.string.ok), null) .show() - PREFS!!.prefs.edit().putBoolean("tipSettingsUpdatesEnabled", false).apply() + PREFS.prefs.edit().putBoolean("tipSettingsUpdatesEnabled", false).apply() } } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root @@ -202,7 +202,7 @@ class UpdateActivity: AppCompatActivity() { } private fun getUpdateMessage(): String { return if(UpdateDataParser.updateMsg == null) { - PREFS!!.updateMessage + PREFS.updateMessage } else { UpdateDataParser.updateMsg!! } @@ -213,7 +213,7 @@ class UpdateActivity: AppCompatActivity() { super.onDestroy() } private fun hideDialogForever() { - PREFS!!.prefs.edit().putBoolean("permsDialogUpdateScreenEnabled", false).apply() + PREFS.prefs.edit().putBoolean("permsDialogUpdateScreenEnabled", false).apply() } private fun getPermission() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { @@ -231,11 +231,11 @@ class UpdateActivity: AppCompatActivity() { } private fun refreshUi() { binding.settingsInclude.AutoUpdateCheckBox.apply { - isChecked = PREFS!!.isAutoUpdateEnabled - isEnabled = PREFS!!.isUpdateNotificationEnabled + isChecked = PREFS.isAutoUpdateEnabled + isEnabled = PREFS.isUpdateNotificationEnabled } - binding.settingsInclude.UpdateNotifyCheckBox.isChecked = PREFS!!.isUpdateNotificationEnabled - when (PREFS!!.updateState) { + binding.settingsInclude.UpdateNotifyCheckBox.isChecked = PREFS.isUpdateNotificationEnabled + when (PREFS.updateState) { 1 -> { //checking for updates state binding.settingsInclude.checkForUpdatesBtn.visibility = View.GONE @@ -254,8 +254,8 @@ class UpdateActivity: AppCompatActivity() { binding.settingsInclude.updateIndicator.visibility = View.VISIBLE binding.settingsInclude.cancelButton.visibility = View.VISIBLE val progressString = if(isUpdateDownloading) { - binding.settingsInclude.progress.progress = PREFS!!.updateProgressLevel - getString(R.string.preparing_to_install, PREFS!!.updateProgressLevel) + "%" + binding.settingsInclude.progress.progress = PREFS.updateProgressLevel + getString(R.string.preparing_to_install, PREFS.updateProgressLevel) + "%" } else { getString(R.string.preparing_to_install, 0) + "%" } @@ -387,18 +387,18 @@ class UpdateActivity: AppCompatActivity() { private fun checkUpdateInfo() { coroutineXmlScope.launch { if (UpdateDataParser.verCode == null) { - PREFS!!.updateState = 5 + PREFS.updateState = 5 return@launch } if (UpdateDataParser.verCode == VERSION_CODE) { - PREFS!!.updateState = 3 + PREFS.updateState = 3 } else if (VERSION_CODE > UpdateDataParser.verCode!!) { - PREFS!!.updateState = 8 + PREFS.updateState = 8 } else if(UpdateDataParser.verCode!! > VERSION_CODE) { if (UpdateDataParser.isBeta == true) { - PREFS!!.updateState = 7 + PREFS.updateState = 7 } else { - PREFS!!.updateState = 6 + PREFS.updateState = 6 } } withContext(mainDispatcher) { @@ -424,7 +424,7 @@ class UpdateActivity: AppCompatActivity() { deleteUpdateFile(this@UpdateActivity) } catch (e: IOException) { saveError(e.toString(), db!!) - PREFS!!.updateState = 5 + PREFS.updateState = 5 refreshUi() withContext(mainDispatcher) { WPDialog(this@UpdateActivity).setTopDialog(true) @@ -444,7 +444,7 @@ class UpdateActivity: AppCompatActivity() { manager = getSystemService(DOWNLOAD_SERVICE) as DownloadManager downloadId = manager?.enqueue(request) isUpdateDownloading = true - PREFS!!.updateState = 2 + PREFS.updateState = 2 withContext(mainDispatcher) { refreshUi() } @@ -459,7 +459,7 @@ class UpdateActivity: AppCompatActivity() { val total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) val progress: Int = ((downloaded * 100L / total)).toInt() val progressString = getString(R.string.preparing_to_install, progress) + "%" - PREFS!!.updateProgressLevel = progress + PREFS.updateProgressLevel = progress withContext(mainDispatcher) { binding.settingsInclude.progessText.text = progressString if (isGreaterThanN) { @@ -470,14 +470,14 @@ class UpdateActivity: AppCompatActivity() { } if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) { isUpdateDownloading = false - PREFS!!.updateState = 4 + PREFS.updateState = 4 withContext(mainDispatcher) { refreshUi() } } if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_FAILED) { isUpdateDownloading = false - PREFS!!.updateState = 5 + PREFS.updateState = 5 withContext(mainDispatcher) { refreshUi() } @@ -486,7 +486,7 @@ class UpdateActivity: AppCompatActivity() { } else { cursor.close() isUpdateDownloading = false - PREFS!!.updateState = 0 + PREFS.updateState = 0 withContext(mainDispatcher) { this@UpdateActivity.recreate() } @@ -498,7 +498,7 @@ class UpdateActivity: AppCompatActivity() { manager?.remove(downloadId!!) } isUpdateDownloading = false - PREFS!!.updateState = 5 + PREFS.updateState = 5 withContext(mainDispatcher) { refreshUi() WPDialog(this@UpdateActivity).setTopDialog(true) @@ -526,7 +526,7 @@ class UpdateActivity: AppCompatActivity() { } } catch (e: Exception) { Log.e("CheckForUpdates", "something went wrong: $e") - PREFS!!.updateState = 5 + PREFS.updateState = 5 withContext(mainDispatcher) { refreshUi() } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/WeatherSettingsActivity.kt b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/WeatherSettingsActivity.kt index 3095427..c01b9b1 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/WeatherSettingsActivity.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/content/settings/activities/WeatherSettingsActivity.kt @@ -19,7 +19,7 @@ class WeatherSettingsActivity: AppCompatActivity() { applyWindowInsets(binding.root) } private fun enterAnimation(exit: Boolean) { - if (!PREFS!!.isTransitionAnimEnabled) { + if (!PREFS.isTransitionAnimEnabled) { return } val main = binding.root diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/IconPackManager.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/IconPackManager.kt index f3b3647..7c6111a 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/IconPackManager.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/IconPackManager.kt @@ -56,7 +56,7 @@ class IconPackManager(context: Context) { factory.isNamespaceAware = true xpp = factory.newPullParser() xpp.setInput(appFilterStream, "utf-8") - } catch (e1: IOException) { + } catch (_: IOException) { //Ln.d("No appfilter.xml file"); } } @@ -112,9 +112,9 @@ class IconPackManager(context: Context) { } mLoaded = true } catch (e: PackageManager.NameNotFoundException) { - //Ln.d("Cannot load icon pack"); + e.printStackTrace() } catch (e: XmlPullParserException) { - //Ln.d("Cannot parse icon pack appfilter.xml"); + e.printStackTrace() } catch (e: IOException) { e.printStackTrace() } @@ -193,7 +193,7 @@ class IconPackManager(context: Context) { if (mBackImages.size() == 0) return defaultBitmap val r = Random() val backImageInd = r.nextInt(mBackImages.size()) - val backImage = mBackImages.get(backImageInd) + val backImage = mBackImages[backImageInd] val w = backImage!!.getWidth() val h = backImage.getHeight() diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ItemTouchCallback.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ItemTouchCallback.kt index aac59e4..2914a04 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ItemTouchCallback.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ItemTouchCallback.kt @@ -16,7 +16,7 @@ class ItemTouchCallback(private val mAdapter: NewStart.NewStartAdapter) : ItemTo } override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean { Log.d("moved", "move") - if(!PREFS!!.isStartBlocked && mAdapter.isEditMode && viewHolder.itemViewType != mAdapter.spaceType) { + if(!PREFS.isStartBlocked && mAdapter.isEditMode && viewHolder.itemViewType != mAdapter.spaceType) { mAdapter.onItemMove(viewHolder.bindingAdapterPosition, target.bindingAdapterPosition) return true } else { diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/BsodScreen.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/BsodScreen.kt index 2c2c33f..ed2146d 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/BsodScreen.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/BsodScreen.kt @@ -30,10 +30,10 @@ class BsodScreen : AppCompatActivity() { private var db: BSOD? = null override fun onCreate(savedInstanceState: Bundle?) { - var counter = PREFS!!.prefs.getInt("crashCounter", 0) + var counter = PREFS.prefs.getInt("crashCounter", 0) counter += 1 - PREFS!!.prefs.edit().putBoolean("app_crashed", true).apply() - PREFS!!.prefs.edit().putInt("crashCounter", counter).apply() + PREFS.prefs.edit().putBoolean("app_crashed", true).apply() + PREFS.prefs.edit().putInt("crashCounter", counter).apply() setTheme(R.style.bsod) super.onCreate(savedInstanceState) setContentView(R.layout.bsod) @@ -49,7 +49,7 @@ class BsodScreen : AppCompatActivity() { val error = "Your launcher ran into a problem and needs to restart. We're just collecting some error info, and then we'll restart for you.\n " + model + brand + android + name + intent.extras?.getString("stacktrace") + errCode Log.e("BSOD", error) saveError(error, db!!) - if(PREFS!!.bsodOutputEnabled) { + if(PREFS.bsodOutputEnabled) { withContext(Dispatchers.Main) { val errorTextView = findViewById(R.id.bsodDetailsText) errorTextView.text = error diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/recovery/RecoveryOptions.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/recovery/RecoveryOptions.kt index 8356b7c..9957c48 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/recovery/RecoveryOptions.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/bsod/recovery/RecoveryOptions.kt @@ -37,7 +37,7 @@ class RecoveryOptions: AppCompatActivity() { } refresh.setOnClickListener { if(checkStoragePermissions()) { - PREFS!!.reset() + PREFS.reset() downloadUpdate(this) } else { getPermission() diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ui/WPDialog.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ui/WPDialog.kt index 7de56ee..82cfbc2 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ui/WPDialog.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/ui/WPDialog.kt @@ -36,7 +36,7 @@ class WPDialog(private val mContext: Context) { private var dismissListener: DialogInterface.OnDismissListener? = null //Show方法 fun show(): WPDialog { - if(PREFS!!.isLightThemeUsed) { + if(PREFS.isLightThemeUsed) { setLightTheme() } Builder() diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateDataParser.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateDataParser.kt index b9f0851..a60ede7 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateDataParser.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateDataParser.kt @@ -54,13 +54,13 @@ class UpdateDataParser { "ru" -> { if(valueKey == "message_ru") { updateMsg = name - PREFS!!.updateMessage = name + PREFS.updateMessage = name } } else -> { if(valueKey == "message") { updateMsg = name - PREFS!!.updateMessage = name + PREFS.updateMessage = name } } @@ -104,7 +104,7 @@ class UpdateDataParser { val valueKey = parser.getAttributeValue(null, "name") if(valueKey == "versionCode") { verCode = valueData.toInt() - PREFS!!.versionCode = valueData.toInt() + PREFS.versionCode = valueData.toInt() } parser.nextTag() Log.i("parserInt", "key: $valueKey value: $valueData") diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateWorker.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateWorker.kt index 23c6874..ccb197e 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateWorker.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/update/UpdateWorker.kt @@ -90,7 +90,7 @@ class UpdateWorker(context: Context, workerParams: WorkerParameters) : Worker(co val state: Result = try { downloadXml(URL) if(isUpdateAvailable()) { - if(PREFS!!.isAutoUpdateEnabled) { + if(PREFS.isAutoUpdateEnabled) { val name = if(UpdateDataParser.isBeta == true) "MPL BETA" else "MPL" val link = if(UpdateDataParser.isBeta == true) URL_BETA_FILE else URL_RELEASE_FILE downloadFile(name, link, context) @@ -109,7 +109,7 @@ class UpdateWorker(context: Context, workerParams: WorkerParameters) : Worker(co prefs.updateState = 3 } Result.success() - } catch (e: Exception) { + } catch (_: Exception) { Result.failure() } scheduleWork(context) @@ -122,7 +122,7 @@ class UpdateWorker(context: Context, workerParams: WorkerParameters) : Worker(co deleteUpdateFile(context) } catch (e: IOException) { Log.e("Background Update", "Error: $e") - PREFS!!.updateState = 5 + PREFS.updateState = 5 cancel() return@launch } @@ -135,7 +135,7 @@ class UpdateWorker(context: Context, workerParams: WorkerParameters) : Worker(co val manager = context.getSystemService(DOWNLOAD_SERVICE) as DownloadManager val downloadId = manager.enqueue(request) isUpdateDownloading = true - PREFS!!.updateState = 2 + PREFS.updateState = 2 val q = DownloadManager.Query() q.setFilterById(downloadId) var cursor: Cursor? @@ -146,26 +146,26 @@ class UpdateWorker(context: Context, workerParams: WorkerParameters) : Worker(co val downloaded = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_BYTES_DOWNLOADED_SO_FAR)) val total = cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_TOTAL_SIZE_BYTES)) val progress: Int = ((downloaded * 100L / total)).toInt() - PREFS!!.updateProgressLevel = progress + PREFS.updateProgressLevel = progress if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_SUCCESSFUL) { isUpdateDownloading = false - PREFS!!.updateState = 4 + PREFS.updateState = 4 } if (cursor.getInt(cursor.getColumnIndex(DownloadManager.COLUMN_STATUS)) == DownloadManager.STATUS_FAILED) { isUpdateDownloading = false - PREFS!!.updateState = 5 + PREFS.updateState = 5 } cursor.close() } else { cursor.close() isUpdateDownloading = false - PREFS!!.updateState = 0 + PREFS.updateState = 0 } } } catch (e: Exception) { Log.e("Background Update", "Error: $e") isUpdateDownloading = false - PREFS!!.updateState = 5 + PREFS.updateState = 5 } } } diff --git a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/utils/Utils.kt b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/utils/Utils.kt index 48242fd..ec3fe77 100644 --- a/app/src/main/java/ru/dimon6018/metrolauncher/helpers/utils/Utils.kt +++ b/app/src/main/java/ru/dimon6018/metrolauncher/helpers/utils/Utils.kt @@ -143,7 +143,7 @@ class Utils { } fun launcherAccentTheme(): Int { - val selectedColor = PREFS!!.accentColor + val selectedColor = PREFS.accentColor return if (selectedColor >= 0 && selectedColor < themeStyles.size) { themeStyles[selectedColor] } else { @@ -170,7 +170,7 @@ class Utils { return typedValue.data } fun accentName(context: Context): String { - val selectedColor = PREFS!!.accentColor + val selectedColor = PREFS.accentColor return if (selectedColor >= 0 && selectedColor < accentNames.size) { context.getString(accentNames[selectedColor]) } else { @@ -274,14 +274,14 @@ class Utils { fun saveError(e: String, db: BSOD) { CoroutineScope(Dispatchers.IO).launch { - if (PREFS!!.isFeedbackEnabled) { + if (PREFS.isFeedbackEnabled) { Log.e("BSOD", e) val entity = BSODEntity() entity.date = Calendar.getInstance().time.toString() entity.log = e val dao = db.getDao() val pos: Int - when (PREFS!!.maxCrashLogs) { + when (PREFS.maxCrashLogs) { 0 -> { db.clearAllTables() pos = 0 @@ -432,7 +432,7 @@ class Utils { return alphabet } suspend fun generatePlaceholder(call: TileDao, value: Int) { - val size = if(PREFS!!.isMoreTilesEnabled) value * 2 else value + val size = if(PREFS.isMoreTilesEnabled) value * 2 else value val startFrom = call.getTilesList().size val end = startFrom + size for (i in startFrom..end) { diff --git a/app/src/main/res/layout/ad.xml b/app/src/main/res/layout/ad.xml deleted file mode 100644 index 0566a5c..0000000 --- a/app/src/main/res/layout/ad.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/oobe_fragment_ad.xml b/app/src/main/res/layout/oobe_fragment_ad.xml deleted file mode 100644 index db24cdf..0000000 --- a/app/src/main/res/layout/oobe_fragment_ad.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file