Fix: Memory Usage after app been closed

This commit is contained in:
LooKeR 2021-11-13 11:47:10 +05:30
parent 113f62954f
commit d2bec1e4b8
4 changed files with 31 additions and 18 deletions

View File

@ -32,6 +32,7 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Single
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.launch
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request
import java.net.URI
@ -239,7 +240,7 @@ class EditRepositoryFragment() : ScreenFragment() {
}
}
lifecycleScope.launchWhenCreated {
lifecycleScope.launch {
val list = Database.RepositoryAdapter.getAll(null)
takenAddresses = list.asSequence().filter { it.id != repositoryId }
.flatMap { (it.mirrors + it.address).asSequence() }

View File

@ -16,6 +16,8 @@ import androidx.core.net.toUri
import androidx.core.widget.NestedScrollView
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import com.google.android.material.circularreveal.CircularRevealFrameLayout
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@ -29,6 +31,7 @@ import com.looker.droidify.databinding.PreferenceItemBinding
import com.looker.droidify.utility.extension.resources.*
import com.topjohnwu.superuser.Shell
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
class SettingsFragment : ScreenFragment() {
@ -135,8 +138,10 @@ class SettingsFragment : ScreenFragment() {
)
}
lifecycleScope.launchWhenStarted {
Preferences.subject.collect { updatePreference(it) }
lifecycleScope.launch {
Preferences.subject
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.collect { updatePreference(it) }
}
updatePreference(null)
}

View File

@ -8,6 +8,8 @@ import android.view.animation.AccelerateInterpolator
import android.view.animation.DecelerateInterpolator
import androidx.appcompat.widget.SearchView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
@ -35,6 +37,7 @@ import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlin.math.*
class TabsFragment : ScreenFragment() {
@ -201,12 +204,12 @@ class TabsFragment : ScreenFragment() {
}
updateOrder()
lifecycleScope.launchWhenStarted {
Preferences.subject.collect {
if (it == Preferences.Key.SortOrder) {
updateOrder()
lifecycleScope.launch {
Preferences.subject
.flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
.collect {
if (it == Preferences.Key.SortOrder) updateOrder()
}
}
}
val content = fragmentBinding.fragmentContent
@ -531,7 +534,6 @@ class TabsFragment : ScreenFragment() {
itemView as MaterialTextView
itemView.gravity = Gravity.CENTER_VERTICAL
itemView.resources.sizeScaled(16).let { itemView.setPadding(it, 0, it, 0) }
itemView.setTextColor(context.getColorFromAttr(android.R.attr.textColor))
itemView.setTextSizeScaled(16)
itemView.background =
context.getDrawableFromAttr(android.R.attr.selectableItemBackground)

View File

@ -6,7 +6,9 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.looker.droidify.R
@ -21,6 +23,7 @@ import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
class AppListFragment() : BaseFragment(), CursorOwner.Callback {
@ -94,15 +97,17 @@ class AppListFragment() : BaseFragment(), CursorOwner.Callback {
override fun onCursorData(request: CursorOwner.Request, cursor: Cursor?) {
(recyclerView?.adapter as? AppListAdapter)?.apply {
this.cursor = cursor
viewLifecycleOwner.lifecycleScope.launchWhenCreated {
emptyText = when {
cursor == null -> ""
viewModel.searchQuery.first()
.isNotEmpty() -> getString(R.string.no_matching_applications_found)
else -> when (source) {
Source.AVAILABLE -> getString(R.string.no_applications_available)
Source.INSTALLED -> getString(R.string.no_applications_installed)
Source.UPDATES -> getString(R.string.all_applications_up_to_date)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) {
emptyText = when {
cursor == null -> ""
viewModel.searchQuery.first()
.isNotEmpty() -> getString(R.string.no_matching_applications_found)
else -> when (source) {
Source.AVAILABLE -> getString(R.string.no_applications_available)
Source.INSTALLED -> getString(R.string.no_applications_installed)
Source.UPDATES -> getString(R.string.all_applications_up_to_date)
}
}
}
}