Skip to content

Commit

Permalink
returned wallpaper and animation in edit mode, fixed some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
queuejw committed Nov 29, 2024
1 parent df148d0 commit 3bc64cc
Show file tree
Hide file tree
Showing 58 changed files with 1,813 additions and 546 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId "ru.dimon6018.metrolauncher"
minSdk 21
targetSdk 35
versionCode 58
versionName "1.0 Pre-Alpha 5.1.3"
versionCode 59
versionName "Exp. 7743"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled false
Expand Down Expand Up @@ -48,7 +48,7 @@ dependencies {

implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'androidx.annotation:annotation:1.9.1'
implementation 'com.google.android.material:material:1.13.0-alpha07'
implementation 'com.google.android.material:material:1.13.0-alpha08'
implementation 'androidx.recyclerview:recyclerview:1.4.0-rc01'
implementation 'androidx.core:core-ktx:1.15.0'
implementation 'androidx.fragment:fragment-ktx:1.8.5'
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/java/ru/dimon6018/metrolauncher/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ import ru.dimon6018.metrolauncher.helpers.utils.Utils.Companion.launcherAccentTh
class Application : Application() {

override fun onCreate() {
if(applicationContext == null) {
if (applicationContext == null) {
super.onCreate()
return
}
BsodDetector.setContext(applicationContext)
Thread.setDefaultUncaughtExceptionHandler(BsodDetector())
PREFS = Prefs(applicationContext)
//EXP_PREFS = ExperimentPrefs(applicationContext)
if(PREFS.accentColor == 21 && DynamicColors.isDynamicColorAvailable()) DynamicColors.applyToActivitiesIfAvailable(this)
if (PREFS.accentColor == 21 && DynamicColors.isDynamicColorAvailable()) DynamicColors.applyToActivitiesIfAvailable(
this
)
setupCustomFont()
setupCustomLightFont()
setupCustomBoldFont()
Expand All @@ -35,12 +37,16 @@ class Application : Application() {
@SuppressLint("SourceLockedOrientationActivity")
override fun onActivityPreCreated(activity: Activity, savedInstanceState: Bundle?) {
activity.setTheme(launcherAccentTheme())
when(PREFS.orientation) {
"p" -> activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
"l" -> activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
when (PREFS.orientation) {
"p" -> activity.requestedOrientation =
ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT

"l" -> activity.requestedOrientation =
ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
}
super.onActivityPreCreated(activity, savedInstanceState)
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
override fun onActivityStarted(activity: Activity) {}
override fun onActivityResumed(activity: Activity) {}
Expand All @@ -50,9 +56,11 @@ class Application : Application() {
override fun onActivityDestroyed(activity: Activity) {}
})
}

companion object {
lateinit var PREFS: Prefs
// var EXP_PREFS: ExperimentPrefs? = null

// var EXP_PREFS: ExperimentPrefs? = null
var isUpdateDownloading = false
var isAppOpened = false
var isStartMenuOpened = false
Expand All @@ -64,9 +72,11 @@ class Application : Application() {
fun setupCustomFont() {
customFont = getCustomFont()
}

fun setupCustomLightFont() {
customLightFont = getCustomLightFont()
}

fun setupCustomBoldFont() {
customBoldFont = getCustomBoldFont()
}
Expand Down
57 changes: 50 additions & 7 deletions app/src/main/java/ru/dimon6018/metrolauncher/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.text.TextWatcher
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.widget.AutoCompleteTextView
import android.widget.ImageView
Expand Down Expand Up @@ -66,6 +67,7 @@ import ru.dimon6018.metrolauncher.helpers.utils.Utils.Companion.sendCrash
import ru.dimon6018.metrolauncher.helpers.utils.Utils.Companion.setUpApps
import ru.dimon6018.metrolauncher.helpers.utils.Utils.Companion.unregisterPackageReceiver

// Main application screen (tiles, apps)
class Main : AppCompatActivity() {

private lateinit var pagerAdapter: FragmentStateAdapter
Expand All @@ -87,17 +89,20 @@ class Main : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
isDarkMode = resources.getBoolean(R.bool.isDark) && PREFS.appTheme != 2
when(PREFS.appTheme) {
when (PREFS.appTheme) {
0 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
1 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
2 -> AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
handleDevMode()
super.onCreate(savedInstanceState)

// If MPL has never run before, open OOBE
if (PREFS.launcherState == 0) {
runOOBE()
return
}

binding = LauncherMainScreenBinding.inflate(layoutInflater)
mainViewModel = ViewModelProvider(this)[MainViewModel::class.java]
setContentView(binding.root)
Expand All @@ -112,6 +117,7 @@ class Main : AppCompatActivity() {
}
}

// Turn off animations if developer mode is enabled to prevent some animation issues
private fun handleDevMode() {
if (isDevMode(this) && PREFS.isAutoShutdownAnimEnabled) {
disableAnims()
Expand All @@ -134,6 +140,13 @@ class Main : AppCompatActivity() {

private fun setupUI() {
WindowCompat.setDecorFitsSystemWindows(window, false)
if (PREFS.isWallpaperEnabled) {
window?.setFlags(
WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER,
WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
)
window?.setBackgroundDrawableResource(android.R.color.transparent)
}
ViewCompat.setOnApplyWindowInsetsListener(binding.mainBottomBar.navigationFrame) { view, insets ->
val systemBarInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(
Expand All @@ -143,15 +156,20 @@ class Main : AppCompatActivity() {
)
insets
}
if(PREFS.isSearchBarEnabled) applyWindowInsets(binding.mainSearchResults.searchBarResultsLayout)
if (PREFS.isSearchBarEnabled) applyWindowInsets(binding.mainSearchResults.searchBarResultsLayout)
isLandscape = resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
registerPackageReceiver(this, packageReceiver)
otherTasks()
}

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 {
isAAllAppsAnimEnabled = false
Expand Down Expand Up @@ -186,6 +204,7 @@ class Main : AppCompatActivity() {
super.onPageSelected(position)
updateNavigationBarColors(position)
}

private fun updateNavigationBarColors(position: Int) {
if (!PREFS.isSearchBarEnabled && PREFS.navBarColor != 2) {
val (startColor, searchColor) = when {
Expand All @@ -196,19 +215,31 @@ class Main : AppCompatActivity() {
binding.mainBottomBar.navigationSearchBtn.setColorFilter(searchColor)
}
}

override fun onPageScrollStateChanged(state: Int) {
when (state) {
ViewPager2.SCROLL_STATE_DRAGGING -> isViewPagerScrolling = true
ViewPager2.SCROLL_STATE_SETTLING -> isViewPagerScrolling = true
ViewPager2.SCROLL_STATE_IDLE -> isViewPagerScrolling = false
}
}
}

override fun onResume() {
// restart MPL if some settings have been changed
if (PREFS.isPrefsChanged) restart()

super.onResume()
}

private fun restart() {
PREFS.isPrefsChanged = false
val componentName = Intent(this, this::class.java).component
val intent = Intent.makeRestartActivityTask(componentName)
startActivity(intent)
Runtime.getRuntime().exit(0)
}

override fun onDestroy() {
super.onDestroy()
unregisterPackageReceiver(this, packageReceiver)
Expand Down Expand Up @@ -237,7 +268,7 @@ class Main : AppCompatActivity() {
private suspend fun regenerateIcons() {
val isCustomIconsInstalled = PREFS.iconPackPackage != "null"
var diskCache = initDiskCache(this)
if(isCustomIconsInstalled) {
if (isCustomIconsInstalled) {
checkIconPack(diskCache)
}
if (PREFS.iconPackChanged) {
Expand Down Expand Up @@ -282,6 +313,7 @@ class Main : AppCompatActivity() {
}
}

// Icon generation for cache
fun generateIcon(appPackage: String, isCustomIconsInstalled: Boolean) {
val icon = if (!isCustomIconsInstalled) {
packageManager.getApplicationIcon(appPackage)
Expand Down Expand Up @@ -316,6 +348,7 @@ class Main : AppCompatActivity() {
}
}

// If 5 seconds after the crash is successful, display an error message
private fun crashCheck() {
if (PREFS.prefs.getBoolean("app_crashed", false)) {
lifecycleScope.launch(Dispatchers.Default) {
Expand Down Expand Up @@ -367,6 +400,7 @@ class Main : AppCompatActivity() {
binding.mainBottomBar.navigationFrame.visibility = View.GONE
return ContextCompat.getColor(this, android.R.color.transparent)
}

else -> launcherSurfaceColor(theme)
}
}
Expand Down Expand Up @@ -418,6 +452,7 @@ class Main : AppCompatActivity() {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
filterSearchText(s.toString(), mainViewModel.getAppList())
}

override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {}
})
Expand All @@ -436,6 +471,7 @@ class Main : AppCompatActivity() {
fun hideSearch() {
hideSearchResults()
}

private fun hideSearchResults() {
lifecycleScope.launch {
searching = false
Expand Down Expand Up @@ -464,16 +500,20 @@ class Main : AppCompatActivity() {
val defaultLocale = getDefaultLocale()
filteredList.clear()

appList.filter { it.appLabel!!.lowercase(defaultLocale).contains(text.lowercase(defaultLocale)) }
appList.filter {
it.appLabel!!.lowercase(defaultLocale).contains(text.lowercase(defaultLocale))
}
.take(max)
.let { filteredList.addAll(it) }

filteredList.sortWith(compareBy { it.appLabel })
searchAdapter?.setData(filteredList)
}

companion object {
var isLandscape: Boolean = false
var isDarkMode: Boolean = false
var isViewPagerScrolling: Boolean = false
}

inner class WinAdapter(fragment: FragmentActivity) : FragmentStateAdapter(fragment) {
Expand All @@ -489,10 +529,13 @@ class Main : AppCompatActivity() {
}
}

inner class SearchAdapter(private var dataList: MutableList<App>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
inner class SearchAdapter(private var dataList: MutableList<App>) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return AppSearchHolder(LayoutInflater.from(parent.context).inflate(R.layout.app, parent, false))
return AppSearchHolder(
LayoutInflater.from(parent.context).inflate(R.layout.app, parent, false)
)
}

override fun getItemCount(): Int = dataList.size
Expand Down
11 changes: 9 additions & 2 deletions app/src/main/java/ru/dimon6018/metrolauncher/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,33 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
private var appList: MutableList<App> = ArrayList()

fun addIconToCache(appPackage: String, bitmap: Bitmap?) {
if(icons[appPackage.hashCode()] == null) icons.append(appPackage.hashCode(), bitmap)
if (icons[appPackage.hashCode()] == null) icons.append(appPackage.hashCode(), bitmap)
}

fun removeIconFromCache(appPackage: String) {
icons.remove(appPackage.hashCode())
}

fun getIconFromCache(appPackage: String): Bitmap? {
return icons[appPackage.hashCode()]
}

fun addAppToList(app: App) {
if(!appList.contains(app)) appList.add(app)
if (!appList.contains(app)) appList.add(app)
}

fun removeAppFromList(app: App) {
appList.remove(app)
}

fun getAppList(): MutableList<App> {
return appList
}

fun setAppList(list: MutableList<App>) {
appList = list
}

fun getTileDao(): TileDao {
return tileDao
}
Expand Down
Loading

0 comments on commit 3bc64cc

Please sign in to comment.