Skip to content

Commit

Permalink
small update 10
Browse files Browse the repository at this point in the history
  • Loading branch information
queuejw committed Mar 8, 2024
1 parent a670aba commit c7c8bc2
Show file tree
Hide file tree
Showing 18 changed files with 342 additions and 388 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ android {
applicationId "ru.dimon6018.metrolauncher"
minSdk 23
targetSdk 34
versionCode 10
versionName "1.0 Pre-Alpha 3 (dev 1)"
versionCode 11
versionName "1.0 Pre-Alpha 3 (dev 2)"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled false
Expand Down
44 changes: 14 additions & 30 deletions app/src/main/java/ru/dimon6018/metrolauncher/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ class Application : Application() {
R.string.color_pink, R.string.color_magenta, R.string.color_crimson, R.string.color_red, R.string.color_orange, R.string.color_amber, R.string.color_yellow, R.string.color_brown,
R.string.color_olive, R.string.color_steel, R.string.color_mauve, R.string.color_taupe
)
private val themeStyles = intArrayOf(
R.style.AppTheme_Lime, R.style.AppTheme_Green, R.style.AppTheme_Emerald,
R.style.AppTheme_Cyan, R.style.AppTheme_Teal, R.style.AppTheme_Cobalt,
R.style.AppTheme_Indigo, R.style.AppTheme_Violet, R.style.AppTheme_Pink,
R.style.AppTheme_Magenta, R.style.AppTheme_Crimson, R.style.AppTheme_Red,
R.style.AppTheme_Orange, R.style.AppTheme_Amber, R.style.AppTheme_Yellow,
R.style.AppTheme_Brown, R.style.AppTheme_Olive, R.style.AppTheme_Steel,
R.style.AppTheme_Mauve, R.style.AppTheme_Taupe
)
fun accentColorFromPrefs(context: Context): Int {
val selectedColor = Prefs(context).accentColor
return if (selectedColor >= 0 && selectedColor < accentColors.size) {
Expand All @@ -72,27 +81,11 @@ class Application : Application() {
}
}
fun getTileColorFromPrefs(tileColor: Int, context: Context): Int {
// 0 - use accent color
// 1 - lime
// 2 - green
// 3 - emerald
// 4 - cyan
// 5 - teal
// 6 - cobalt
// 7 - indigo
// 8 - violet
// 9 - pink
// 10 - magenta
// 11 - crimson
// 12 - red
// 13 - orange
// 14 - amber
// 15 - yellow
// 16 - brown
// 17 - olive
// 18 - steel
// 19 - mauve
// 20 - taupe
// 0 - use accent color // 1 - lime // 2 - green // 3 - emerald // 4 - cyan
// 5 - teal // 6 - cobalt // 7 - indigo // 8 - violet
// 9 - pink // 10 - magenta // 11 - crimson // 12 - red
// 13 - orange // 14 - amber // 15 - yellow // 16 - brown
// 17 - olive // 18 - steel // 19 - mauve // 20 - taupe
return if (tileColor >= 0 && tileColor < accentColors.size) {
context.getColor(accentColors[tileColor])
} else {
Expand All @@ -102,15 +95,6 @@ class Application : Application() {
}

fun launcherAccentTheme(): Int {
val themeStyles = intArrayOf(
R.style.AppTheme_Lime, R.style.AppTheme_Green, R.style.AppTheme_Emerald,
R.style.AppTheme_Cyan, R.style.AppTheme_Teal, R.style.AppTheme_Cobalt,
R.style.AppTheme_Indigo, R.style.AppTheme_Violet, R.style.AppTheme_Pink,
R.style.AppTheme_Magenta, R.style.AppTheme_Crimson, R.style.AppTheme_Red,
R.style.AppTheme_Orange, R.style.AppTheme_Amber, R.style.AppTheme_Yellow,
R.style.AppTheme_Brown, R.style.AppTheme_Olive, R.style.AppTheme_Steel,
R.style.AppTheme_Mauve, R.style.AppTheme_Taupe
)
val selectedColor = PREFS!!.accentColor
return if (selectedColor >= 0 && selectedColor < themeStyles.size) {
themeStyles[selectedColor]
Expand Down
77 changes: 38 additions & 39 deletions app/src/main/java/ru/dimon6018/metrolauncher/content/NewAllApps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import android.widget.PopupWindow
import android.widget.TextView
import androidx.core.graphics.drawable.toBitmap
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool
Expand All @@ -30,6 +31,7 @@ import com.google.android.material.textview.MaterialTextView
import ir.alirezabdn.wp7progress.WP7ProgressBar
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import me.everything.android.ui.overscroll.OverScrollDecoratorHelper
Expand All @@ -56,6 +58,7 @@ class NewAllApps: Fragment() {
private var appList: MutableList<App>? = null

private var isSearching = false
private var pm: PackageManager? = null

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view: View = inflater.inflate(R.layout.all_apps_screen, container, false)
Expand All @@ -64,6 +67,7 @@ class NewAllApps: Fragment() {
return view
}

@OptIn(ExperimentalCoroutinesApi::class)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
recyclerView = view.findViewById(R.id.app_list)
Expand All @@ -73,11 +77,12 @@ class NewAllApps: Fragment() {
loadingHolder = view.findViewById(R.id.loadingHolder)
searchBtn!!.setOnClickListener { searchFunction() }
setRecyclerPadding(resources.getDimensionPixelSize(R.dimen.recyclerViewPadding))
CoroutineScope(Dispatchers.Default).launch {
CoroutineScope(Dispatchers.Default.limitedParallelism(2)).launch {
val dbCall = AppData.getAppData(requireContext()).getAppDao()
appList = getHeaderListLatter(Application.setUpApps(requireContext().packageManager))
adapter = AppAdapter(appList!!, resources, requireContext().packageManager, dbCall)
val lm = LinearLayoutManager(context)
pm = requireContext().packageManager
appList = getHeaderListLatter(Application.setUpApps(pm!!))
adapter = AppAdapter(appList!!, requireActivity().resources, pm!!, dbCall)
val lm = LinearLayoutManager(requireContext())
requireActivity().runOnUiThread {
recyclerView!!.layoutManager = lm
recyclerView!!.adapter = adapter
Expand Down Expand Up @@ -111,10 +116,13 @@ class NewAllApps: Fragment() {
searchBtnBack!!.visibility = View.GONE
setRecyclerPadding(resources.getDimensionPixelSize(R.dimen.recyclerViewPadding))
CoroutineScope(Dispatchers.IO).launch {
appList = getHeaderListLatter(Application.setUpApps(requireContext().packageManager))
if(pm == null) {
pm = requireActivity().packageManager
}
appList = getHeaderListLatter(Application.setUpApps(pm!!))
runBlocking {
requireActivity().runOnUiThread {
adapter?.setData(appList!!)
adapter?.setData(appList!!, false)
}
}
}
Expand Down Expand Up @@ -150,7 +158,7 @@ class NewAllApps: Fragment() {
}
}
if (filteredlist.isNotEmpty()) {
adapter?.setData(filteredlist)
adapter?.setData(filteredlist, true)
}
}
private fun removeHeaders() {
Expand All @@ -162,7 +170,7 @@ class NewAllApps: Fragment() {
appList!!.remove(item)
}
}
adapter?.setData(appList!!)
adapter?.setData(appList!!,true)
}
private fun getHeaderListLatter(newApps: MutableList<App>): MutableList<App> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Expand All @@ -186,25 +194,20 @@ class NewAllApps: Fragment() {
}
return list
}
inner class AppAdapter(private var list: MutableList<App>, resources: Resources, private val packageManager: PackageManager, private val dbCall: AppDao): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
inner class AppAdapter(private var list: MutableList<App>, resources: Resources, private val pmAdapter: PackageManager, private val dbCall: AppDao): RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private val letter: Int = 0
private val app: Int = 1

private val maxPoolSize: Int = 32

private var iconSize = resources.getDimensionPixelSize(R.dimen.iconAppsListSize)

private var viewPool: RecycledViewPool? = null
@OptIn(ExperimentalCoroutinesApi::class)
private val dispatcher = Dispatchers.IO.limitedParallelism(6)

init {
viewPool = RecycledViewPool()
viewPool!!.setMaxRecycledViews(app, maxPoolSize)
recyclerView!!.setRecycledViewPool(viewPool)
}
fun setData(new: MutableList<App>) {
fun setData(new: MutableList<App>, refresh: Boolean) {
list = new
notifyDataSetChanged()
if(refresh) {
notifyDataSetChanged()
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return if (viewType == letter) {
Expand All @@ -220,11 +223,16 @@ class NewAllApps: Fragment() {
return
}
holder as AppHolder
holder.label.text = app.appLabel
holder.icon.load(packageManager.getApplicationIcon(app.appPackage!!).toBitmap(iconSize, iconSize, Application.PREFS!!.iconBitmapConfig())) {
crossfade(true)
placeholder(R.drawable.ic_clock)
try {
holder.icon.load(pmAdapter.getApplicationIcon(app.appPackage!!).toBitmap(iconSize, iconSize, Application.PREFS!!.iconBitmapConfig())) {
crossfade(true)
dispatcher(dispatcher)
}
} catch (e: PackageManager.NameNotFoundException) {
list.remove(app)
notifyItemRemoved(position)
}
holder.label.text = app.appLabel
holder.itemView.setOnClickListener {
runApp(app.appPackage!!)
}
Expand Down Expand Up @@ -263,26 +271,18 @@ class NewAllApps: Fragment() {
startActivity(Intent(requireActivity(), SettingsActivity::class.java))
}
else -> {
startActivity(Intent(packageManager.getLaunchIntentForPackage(packag)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
startActivity(Intent(pmAdapter.getLaunchIntentForPackage(packag)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
}
}
}
private fun insertNewApp(text: String, packag: String) {
CoroutineScope(Dispatchers.IO).launch {
val dBlist = dbCall.getJustApps()
var pos = dbCall.getJustAppsWithoutPlaceholders(false).size
if(dBlist[pos - 1].isPlaceholder == true) {
pos -= 1
}
if(dBlist[pos + 1].isPlaceholder == true) {
pos += 1
}
else {
for (i in 0..<dBlist.size) {
if(dBlist[i].isPlaceholder == true) {
pos = i
break
}
var pos = 0
for (i in 0..<dBlist.size) {
if (dBlist[i].isPlaceholder == true) {
pos = i
break
}
}
val id = Random.nextLong(1000, 2000000)
Expand All @@ -304,7 +304,6 @@ class NewAllApps: Fragment() {
class AppHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val icon: ImageView
val label: TextView

init {
icon = itemView.findViewById(R.id.app_icon)
label = itemView.findViewById(R.id.app_label)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.fragment.app.FragmentManager
import com.google.android.material.button.MaterialButton
import com.google.android.material.card.MaterialCardView
import com.google.android.material.materialswitch.MaterialSwitch
import com.google.android.material.textview.MaterialTextView
import ru.dimon6018.metrolauncher.Application
import ru.dimon6018.metrolauncher.Application.Companion.PREFS
import ru.dimon6018.metrolauncher.Main
Expand All @@ -31,7 +32,8 @@ import kotlin.system.exitProcess
class ThemeSettingsActivity : AppCompatActivity() {
private var themeMenu: MaterialCardView? = null
private var chooseThemeBtn: MaterialButton? = null
private var chooseAccentBtn: MaterialButton? = null
private var chooseAccentBtn: MaterialCardView? = null
private var accentNameTextView: MaterialTextView? = null
private var light: TextView? = null
private var dark: TextView? = null
private var accentTip: TextView? = null
Expand All @@ -47,6 +49,7 @@ class ThemeSettingsActivity : AppCompatActivity() {
chooseThemeBtn = findViewById(R.id.chooseTheme)
accentTip = findViewById(R.id.accentTip)
chooseAccentBtn = findViewById(R.id.chooseAccent)
accentNameTextView = findViewById(R.id.choosedAccentName)
themeMenu = findViewById(R.id.chooseThemeMenu)
light = findViewById(R.id.chooseLight)
dark = findViewById(R.id.chooseDark)
Expand All @@ -58,7 +61,7 @@ class ThemeSettingsActivity : AppCompatActivity() {
val moreTilesSwitch: MaterialSwitch = findViewById(R.id.moreTilesSwitch)
val fastIconsSwitch: MaterialSwitch = findViewById(R.id.fastIcons)
val wallpaperSwitch: MaterialSwitch = findViewById(R.id.wallpaperShowSwtich)
chooseAccentBtn!!.text = Application.accentName(this)
accentNameTextView!!.text = Application.accentName(this)
val themeButtonLabel: String = if (PREFS!!.isLightThemeUsed) {
getString(R.string.light)
} else {
Expand Down
Loading

0 comments on commit c7c8bc2

Please # to comment.