Kill global map

This commit is contained in:
tarsin committed 2023-04-30 12:56:14 +08:00
1 parent 3f2184766c
commit bac07abf1f
6 files changed
+15 -53

No files matched your search

@@ -42,7 +42,6 @@ import com.hippo.ehviewer.ui.EhActivity
import com.hippo.ehviewer.ui.keepNoMediaFileStatus
import com.hippo.util.ReadableTime
import com.hippo.yorozuya.FileUtils
import com.hippo.yorozuya.IntIdGenerator
import eu.kanade.tachiyomi.core.preference.AndroidPreferenceStore
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import eu.kanade.tachiyomi.util.lang.launchIO
@@ -59,8 +58,6 @@ import javax.net.ssl.TrustManagerFactory
import javax.net.ssl.X509TrustManager
class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
private val mIdGenerator = IntIdGenerator()
private val mGlobalStuffMap = HashMap<Int, Any>()
private val mActivityList = ArrayList<Activity>()
val topActivity: EhActivity?
get() = if (mActivityList.isNotEmpty()) {
@@ -113,7 +110,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
}
}
cleanObsoleteCache(this)
mIdGenerator.setNextId(Settings.getInt(KEY_GLOBAL_STUFF_NEXT_ID, 0))
}
private suspend fun cleanupDownload() {
@@ -147,17 +143,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
}
}
fun putGlobalStuff(o: Any): Int {
val id = mIdGenerator.nextId()
mGlobalStuffMap[id] = o
Settings.putInt(KEY_GLOBAL_STUFF_NEXT_ID, mIdGenerator.nextId())
return id
}
fun removeGlobalStuff(id: Int): Any? {
return mGlobalStuffMap.remove(id)
}
fun registerActivity(activity: Activity) {
mActivityList.add(activity)
}
@@ -185,7 +170,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor
}
companion object {
private const val KEY_GLOBAL_STUFF_NEXT_ID = "global_stuff_next_id"
var locked = true
var locked_last_leave_time: Long = 0
@@ -979,8 +979,8 @@ class FavoritesScene :
showSearchBar()
}
override fun isDuplicate(d1: GalleryInfo?, d2: GalleryInfo?): Boolean {
return d1?.gid == d2?.gid && d1 != null && d2 != null
override fun isDuplicate(d1: GalleryInfo, d2: GalleryInfo): Boolean {
return d1.gid == d2.gid
}
override fun onScrollToPosition(position: Int) {
@@ -1338,8 +1338,8 @@ class GalleryListScene :
showActionFab()
}
override fun isDuplicate(d1: GalleryInfo?, d2: GalleryInfo?): Boolean {
return d1?.gid == d2?.gid && d1 != null && d2 != null
override fun isDuplicate(d1: GalleryInfo, d2: GalleryInfo): Boolean {
return d1.gid == d2.gid
}
override fun onScrollToPosition(position: Int) {
@@ -28,7 +28,7 @@ import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.Locale
abstract class GalleryInfoContentHelper : ContentHelper<GalleryInfo?>() {
abstract class GalleryInfoContentHelper : ContentHelper<GalleryInfo>() {
@JvmField
var jumpTo: String? = null
private val listener: FavouriteStatusRouter.Listener
@@ -50,18 +50,12 @@ abstract class GalleryInfoContentHelper : ContentHelper<GalleryInfo?>() {
EhApplication.favouriteStatusRouter.removeListener(listener)
}
override fun onAddData(data: List<GalleryInfo?>) {
for (info in data) {
info?.let {
map[info.gid] = info
}
}
override fun onAddData(data: List<GalleryInfo>) {
data.forEach { map[it.gid] = it }
}
override fun onRemoveData(data: List<GalleryInfo?>) {
for (info in data) {
info?.let { map.remove(info.gid) }
}
override fun onRemoveData(data: List<GalleryInfo>) {
data.forEach { map.remove(it.gid) }
}
override fun onClearData() {
@@ -7,4 +7,5 @@ import androidx.core.content.IntentCompat
import androidx.core.os.BundleCompat
inline fun <reified T : Parcelable> Bundle.getParcelableCompat(key: String?): T? = BundleCompat.getParcelable(this, key, T::class.java)
inline fun <reified T : Parcelable> Bundle.getParcelableArrayListCompat(key: String?): ArrayList<T>? = BundleCompat.getParcelableArrayList(this, key, T::class.java)
inline fun <reified T : Parcelable> Intent.getParcelableExtraCompat(key: String?): T? = IntentCompat.getParcelableExtra(this, key, T::class.java)
@@ -30,7 +30,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener
import com.hippo.easyrecyclerview.HandlerDrawable
import com.hippo.easyrecyclerview.LayoutManagerUtils
import com.hippo.easyrecyclerview.LayoutManagerUtils.OnScrollToPositionListener
import com.hippo.ehviewer.EhApplication
import com.hippo.ehviewer.R
import com.hippo.ehviewer.databinding.WidgetContentLayoutBinding
import com.hippo.util.ExceptionUtils
@@ -130,7 +129,7 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
super.onRestoreInstanceState(mContentHelper.restoreInstanceState(state))
}
abstract class ContentHelper<E : Parcelable?> : OnShowViewListener {
abstract class ContentHelper<E : Parcelable> : OnShowViewListener {
/**
* Generate task id
*/
@@ -236,7 +235,6 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
}
}
}
private var mSavedDataId = IntIdGenerator.INVALID_ID
fun init(contentLayout: ContentLayout) {
binding = contentLayout.binding
mNextPageScrollSize = LayoutUtils.dp2pix(contentLayout.context, 48f)
@@ -733,15 +731,7 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
val shownView = mViewTransition.shownViewIndex
bundle.putInt(KEY_SHOWN_VIEW, shownView)
bundle.putString(KEY_TIP, binding.tip.text.toString())
// TODO It's a bad design
val app = EhApplication.application
if (mSavedDataId != IntIdGenerator.INVALID_ID) {
app.removeGlobalStuff(mSavedDataId)
mSavedDataId = IntIdGenerator.INVALID_ID
}
mSavedDataId = app.putGlobalStuff(mData)
bundle.putInt(KEY_DATA, mSavedDataId)
bundle.putParcelableArrayList(KEY_DATA, mData)
bundle.putInt(KEY_NEXT_ID, mIdGenerator.nextId())
bundle.putParcelable(KEY_PAGE_DIVIDER, mPageDivider)
bundle.putInt(KEY_START_PAGE, mStartPage)
@@ -756,16 +746,9 @@ class ContentLayout(context: Context, attrs: AttributeSet? = null) : FrameLayout
return if (state is Bundle) {
mViewTransition.showView(state.getInt(KEY_SHOWN_VIEW), false)
binding.tip.text = state.getString(KEY_TIP)
mSavedDataId = state.getInt(KEY_DATA)
var newData: ArrayList<E>? = null
val app = EhApplication.application
if (mSavedDataId != IntIdGenerator.INVALID_ID) {
newData = app.removeGlobalStuff(mSavedDataId) as ArrayList<E>?
mSavedDataId = IntIdGenerator.INVALID_ID
if (newData != null) {
mData = newData
}
}
@Suppress("DEPRECATION")
val newData = state.getParcelableArrayList<E>(KEY_DATA)
newData?.let { mData = it }
mIdGenerator.setNextId(state.getInt(KEY_NEXT_ID))
mPageDivider = state.getParcelableCompat(KEY_PAGE_DIVIDER)!!
mStartPage = state.getInt(KEY_START_PAGE)