From b94f427434e9526f0d7331e7f62494abede87293 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 19 Apr 2021 16:12:18 -0400 Subject: [PATCH] Fix migration of grid size --- .../java/eu/kanade/tachiyomi/Migrations.kt | 19 --------------- .../tachiyomi/widget/AutofitRecyclerView.kt | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index 2ee8803f47..b4a97664e6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -110,25 +110,6 @@ object Migrations { remove("enable_doh") } } - - val oldGridSize = prefs.getInt("grid_size", -1) - // Migrate to float for grid size - if (oldGridSize != -1) { - prefs.edit { - putFloat( - PreferenceKeys.gridSize, - when (oldGridSize) { - 4 -> 3f - 3 -> 1.5f - 2 -> 1f - 1 -> 0f - 0 -> -.5f - else -> .5f - } - ) - remove("grid_size") - } - } } return true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt index 516cc0757d..65f5deb38c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/AutofitRecyclerView.kt @@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.widget import android.content.Context import android.util.AttributeSet +import androidx.core.content.edit +import androidx.preference.PreferenceManager import androidx.recyclerview.widget.GridLayoutManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.system.pxToDp @@ -54,6 +56,27 @@ class AutofitRecyclerView @JvmOverloads constructor(context: Context, attrs: Att } fun setGridSize(preferences: PreferencesHelper) { + // Migrate to float for grid size + if (preferences.gridSize().isNotSet()) { + val prefs = PreferenceManager.getDefaultSharedPreferences(context) + val oldGridSize = prefs.getInt("grid_size", -1) + if (oldGridSize != -1) { + preferences.gridSize().set( + when (oldGridSize) { + 4 -> 3f + 3 -> 1.5f + 2 -> 1f + 1 -> 0f + 0 -> -.5f + else -> .5f + } + ) + prefs.edit { + remove("grid_size") + } + } + } + val size = 1.5f.pow(preferences.gridSize().get()) val trueSize = MULTIPLE * ((size * 100 / MULTIPLE).roundToInt()) / 100f columnWidth = trueSize