Skip to content

Commit f876c62

Browse files
committed
bug fixes
1 parent 3a4a18a commit f876c62

File tree

12 files changed

+157
-152
lines changed

12 files changed

+157
-152
lines changed

app/src/main/java/ru/queuejw/mpl/Application.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ class Application : Application() {
5858
var customBoldFont: Typeface? = null
5959

6060
fun setupFonts() {
61-
customFont = Utils.getCustomFont()
62-
customLightFont = Utils.getCustomLightFont()
63-
customBoldFont = Utils.getCustomBoldFont()
61+
customFont = Utils.getCustomFont(0)
62+
customLightFont = Utils.getCustomFont(1)
63+
customBoldFont = Utils.getCustomFont(2)
6464
}
6565

6666
}

app/src/main/java/ru/queuejw/mpl/Main.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class Main : AppCompatActivity() {
270270
var icon = CacheUtils.loadIconFromDiskCache(diskCache!!, it.appPackage)
271271
if (icon == null) {
272272
icon = generateIcon(it.appPackage, isCustomIconsInstalled)
273-
CacheUtils.saveIconToDiskCache(diskCache!!, it.appPackage, icon)
273+
CacheUtils.saveIconToDiskCache(diskCache, it.appPackage, icon)
274274
}
275275
mainViewModel.addIconToCache(it.appPackage, icon)
276276
}

app/src/main/java/ru/queuejw/mpl/MainViewModel.kt

+13
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
2121
SparseArrayCompat<Bitmap?>()
2222
}
2323

24+
var userTileCount = 0
25+
2426
fun addIconToCache(appPackage: String, bitmap: Bitmap?) {
2527
icons.append(appPackage.hashCode(), bitmap)
2628
}
@@ -51,6 +53,17 @@ class MainViewModel(application: Application) : AndroidViewModel(application) {
5153

5254
fun setTileList(list: MutableList<Tile>) {
5355
tileList = list
56+
setUserTileCount(list)
57+
}
58+
59+
fun setUserTileCount(tiles: MutableList<Tile>) {
60+
var temp = ArrayList<Tile>()
61+
tiles.forEach {
62+
if(it.tileType != -1) {
63+
temp.add(it)
64+
}
65+
}
66+
userTileCount = temp.last().tilePosition!! + 1
5467
}
5568

5669
fun getTileList(): MutableList<Tile> {

app/src/main/java/ru/queuejw/mpl/content/Start.kt

+4-1
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ class Start : Fragment() {
786786
(requireActivity() as Main).configureViewPagerScroll(false)
787787
addCallback()
788788
isEditMode = true
789+
notifyItemRangeChanged(mainViewModel.userTileCount, list.size - mainViewModel.userTileCount)
789790
}
790791

791792

@@ -797,6 +798,7 @@ class Start : Fragment() {
797798
removeCallback()
798799
(requireActivity() as Main).configureViewPagerScroll(true)
799800
isEditMode = false
801+
notifyItemRangeRemoved(mainViewModel.userTileCount, list.size - mainViewModel.userTileCount)
800802
}
801803

802804
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
@@ -808,7 +810,7 @@ class Start : Fragment() {
808810
}
809811

810812
override fun getItemCount(): Int {
811-
return list.size
813+
return if(!isEditMode) mainViewModel.userTileCount else list.size
812814
}
813815

814816
override fun getItemId(position: Int): Long {
@@ -956,6 +958,7 @@ class Start : Fragment() {
956958
newData.add(item)
957959
}
958960
mainViewModel.getViewModelTileDao().updateAllTiles(newData)
961+
mainViewModel.setUserTileCount(newData)
959962
}
960963
}
961964

app/src/main/java/ru/queuejw/mpl/content/oobe/fragments/AppsFragment.kt

+6-4
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ class AppsFragment : Fragment() {
7474
appList.forEach {
7575
if (it.type != 1) {
7676
val bmp = if (!isCustomIconsInstalled)
77-
pm.getApplicationIcon(it.appPackage!!)
77+
pm.getApplicationIcon(it.appPackage)
7878
else
7979
iconManager?.getIconPackWithName(PREFS.iconPackPackage)
80-
?.getDrawableIconForPackage(it.appPackage!!, null)
80+
?.getDrawableIconForPackage(it.appPackage, null)
8181
hashCache.append(it.id, bmp)
8282
}
8383
}
@@ -113,16 +113,18 @@ class AppsFragment : Fragment() {
113113
selectedItems ?: return
114114
if (selectedItems!!.isEmpty()) return
115115
saveAppsCoroutine.launch {
116+
selectedItems
116117
val call = TileData.getTileData(requireContext()).getTileDao()
118+
generatePlaceholder(call, selectedItems!!.size * 2)
117119
var pos = 0
118120
for (i in selectedItems!!) {
119121
val id = Random.nextLong(1000, 2000000)
120122
val entity = Tile(
121123
pos, id, -1, 0,
122124
isSelected = false,
123125
tileSize = Utils.generateRandomTileSize(false),
124-
tileLabel = i.appLabel!!,
125-
tilePackage = i.appPackage!!
126+
tileLabel = i.appLabel,
127+
tilePackage = i.appPackage
126128
)
127129
call.updateTile(entity)
128130
pos += 1

app/src/main/java/ru/queuejw/mpl/content/oobe/fragments/WelcomeFragment.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7+
import androidx.core.content.edit
78
import androidx.fragment.app.Fragment
89
import androidx.lifecycle.lifecycleScope
910
import kotlinx.coroutines.delay
@@ -26,7 +27,7 @@ class WelcomeFragment : Fragment() {
2627
_binding = OobeFragmentWelcomeBinding.inflate(inflater, container, false)
2728
if (!Application.PREFS.prefs.getBoolean("channelConfigured", false)) {
2829
UpdateWorker.setupNotificationChannels(requireActivity())
29-
Application.PREFS.prefs.edit().putBoolean("channelConfigured", true).apply()
30+
Application.PREFS.prefs.edit { putBoolean("channelConfigured", true) }
3031
}
3132
return binding.root
3233
}

app/src/main/java/ru/queuejw/mpl/content/settings/fragments/IconSettingsFragment.kt

+14-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import ru.queuejw.mpl.R
1717
import ru.queuejw.mpl.content.settings.SettingsActivity
1818
import ru.queuejw.mpl.databinding.AppBinding
1919
import ru.queuejw.mpl.databinding.SettingsIconsBinding
20+
import ru.queuejw.mpl.helpers.disklru.CacheUtils
2021
import ru.queuejw.mpl.helpers.iconpack.IconPackManager
2122
import ru.queuejw.mpl.helpers.ui.WPDialog
2223

@@ -103,6 +104,7 @@ class IconSettingsFragment : Fragment() {
103104
iconPackChanged = true
104105
isPrefsChanged = true
105106
}
107+
context?.let { clearIconCache(it) }
106108
setUi()
107109
}
108110
binding.downloadIconPacks.setOnClickListener {
@@ -184,6 +186,14 @@ class IconSettingsFragment : Fragment() {
184186
if (isListVisible) getString(android.R.string.cancel) else getString(R.string.choose_icon_pack)
185187
}
186188

189+
private fun clearIconCache(context: Context) {
190+
val diskCache = CacheUtils.initDiskCache(context)
191+
diskCache?.let {
192+
it.delete()
193+
CacheUtils.closeDiskCache(it)
194+
}
195+
}
196+
187197
inner class IconPackAdapterList(
188198
private var list: MutableList<IconPackItem>,
189199
private val context: Context
@@ -216,6 +226,7 @@ class IconSettingsFragment : Fragment() {
216226
iconPackChanged = true
217227
isPrefsChanged = true
218228
}
229+
clearIconCache(context)
219230
binding.iconPackList.visibility = View.GONE
220231
isListVisible = false
221232
setUi()
@@ -226,7 +237,7 @@ class IconSettingsFragment : Fragment() {
226237

227238
class IconPackHolder(val holderBinding: AppBinding) : RecyclerView.ViewHolder(holderBinding.root)
228239

229-
class IconPackItem {
230-
var name: String = ""
240+
data class IconPackItem(
241+
var name: String = "",
231242
var appPackage: String = ""
232-
}
243+
)

app/src/main/java/ru/queuejw/mpl/helpers/utils/Utils.kt

+7-37
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,8 @@ class Utils {
359359
}
360360

361361
suspend fun generatePlaceholder(call: TileDao, value: Int) {
362-
val size = value
363362
val startFrom = call.getTilesList().size
364-
val end = startFrom + size
363+
val end = startFrom + value
365364
for (i in startFrom..end) {
366365
val placeholder = Tile(
367366
i, (i + 1).toLong(), -1, -1,
@@ -392,8 +391,12 @@ class Utils {
392391
}
393392
}
394393

395-
fun getCustomFont(): Typeface? {
396-
val path = PREFS.customFontPath
394+
fun getCustomFont(fontType: Int): Typeface? {
395+
val path = when(fontType) {
396+
1 -> PREFS.customLightFontPath
397+
2 -> PREFS.customBoldFontPath
398+
else -> PREFS.customFontPath
399+
}
397400
if (!PREFS.customFontInstalled || path == null) return null
398401
return path.let {
399402
val fontFile = File(it)
@@ -408,39 +411,6 @@ class Utils {
408411
}
409412
}
410413
}
411-
412-
fun getCustomLightFont(): Typeface? {
413-
val path = PREFS.customLightFontPath
414-
if (!PREFS.customFontInstalled || path == null) return null
415-
return path.let {
416-
val fontFile = File(it)
417-
if (fontFile.exists()) {
418-
val typeface = Typeface.createFromFile(fontFile)
419-
typeface
420-
} else {
421-
PREFS.customLightFontPath = null
422-
PREFS.customLightFontName = null
423-
null
424-
}
425-
}
426-
}
427-
428-
fun getCustomBoldFont(): Typeface? {
429-
val path = PREFS.customBoldFontPath
430-
if (!PREFS.customFontInstalled || path == null) return null
431-
return path.let {
432-
val fontFile = File(it)
433-
if (fontFile.exists()) {
434-
val typeface = Typeface.createFromFile(fontFile)
435-
typeface
436-
} else {
437-
PREFS.customBoldFontPath = null
438-
PREFS.customBoldFontName = null
439-
null
440-
}
441-
}
442-
}
443-
444414
fun getDefaultLocale(): Locale {
445415
return Locale.getDefault()
446416
}

app/src/main/res/layout/launcher_all_apps_screen.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
android:layout_gravity="center"
2929
android:layout_marginStart="12dp"
3030
app:cardBackgroundColor="?android:attr/colorBackground"
31-
app:cardCornerRadius="24dp"
31+
app:cardCornerRadius="20dp"
3232
app:strokeColor="?attr/colorOnBackground"
3333
app:strokeWidth="3dp">
3434

@@ -109,7 +109,7 @@
109109
android:layout_width="42dp"
110110
android:layout_height="42dp"
111111
app:cardBackgroundColor="?android:attr/colorBackground"
112-
app:cardCornerRadius="24dp"
112+
app:cardCornerRadius="20dp"
113113
app:strokeColor="?attr/colorOnBackground"
114114
app:strokeWidth="3dp">
115115

@@ -130,7 +130,7 @@
130130
android:layout_marginTop="12dp"
131131
android:visibility="gone"
132132
app:cardBackgroundColor="?android:attr/colorBackground"
133-
app:cardCornerRadius="24dp"
133+
app:cardCornerRadius="20dp"
134134
app:strokeColor="?attr/colorOnSurface"
135135
app:strokeWidth="3dp">
136136
<ImageView

0 commit comments

Comments
 (0)