ui: fix binding issues
Use viewLifecycleOwner for all fragments that rely on databinding. This should solve some possible memory leaks, as viewLifecycleOwner is tied to the lifecycle of the fragment views instead of the fragments them selves.
This commit is contained in:
parent
66be3da7e3
commit
d50d2f0b1e
12 changed files with 20 additions and 14 deletions
|
@ -57,7 +57,7 @@
|
||||||
android:roundIcon="@mipmap/ic_launcher_round" />
|
android:roundIcon="@mipmap/ic_launcher_round" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
android:name=".widget.MinimalWidgetProvider"
|
android:name=".widgets.MinimalWidgetProvider"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:enabled="@bool/widgets_supported">
|
android:enabled="@bool/widgets_supported">
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ class MainFragment : Fragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
// Speed up the slide-in effect on the controls view, solely to improve the UX
|
// Speed up the slide-in effect on the controls view, solely to improve the UX
|
||||||
// and maybe hide the problem where the main view will snap-shrink before the compact
|
// and maybe hide the problem where the main view will snap-shrink before the compact
|
||||||
|
|
|
@ -53,7 +53,7 @@ class AlbumDetailFragment : DetailFragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
setupToolbar(R.menu.menu_album_detail) { itemId ->
|
setupToolbar(R.menu.menu_album_detail) { itemId ->
|
||||||
if (itemId == R.id.action_queue_add) {
|
if (itemId == R.id.action_queue_add) {
|
||||||
|
|
|
@ -65,7 +65,7 @@ class ArtistDetailFragment : DetailFragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
setupToolbar()
|
setupToolbar()
|
||||||
setupRecycler(detailAdapter) { pos ->
|
setupRecycler(detailAdapter) { pos ->
|
||||||
|
|
|
@ -53,7 +53,7 @@ class GenreDetailFragment : DetailFragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
setupToolbar()
|
setupToolbar()
|
||||||
setupRecycler(detailAdapter) { pos ->
|
setupRecycler(detailAdapter) { pos ->
|
||||||
|
|
|
@ -43,6 +43,8 @@ class LibraryFragment : Fragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
binding.libraryToolbar.apply {
|
binding.libraryToolbar.apply {
|
||||||
menu.findItem(libraryModel.sortMode.toMenuId()).isChecked = true
|
menu.findItem(libraryModel.sortMode.toMenuId()).isChecked = true
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,7 @@ class LoadingFragment : Fragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
binding.loadingModel = loadingModel
|
binding.loadingModel = loadingModel
|
||||||
|
|
||||||
// --- VIEWMODEL SETUP ---
|
// --- VIEWMODEL SETUP ---
|
||||||
|
|
|
@ -44,6 +44,8 @@ class QueueFragment : Fragment() {
|
||||||
|
|
||||||
// --- UI SETUP ---
|
// --- UI SETUP ---
|
||||||
|
|
||||||
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
binding.queueToolbar.setNavigationOnClickListener {
|
binding.queueToolbar.setNavigationOnClickListener {
|
||||||
findNavController().navigateUp()
|
findNavController().navigateUp()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ import org.oxycblt.auxio.playback.state.LoopMode
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||||
import org.oxycblt.auxio.settings.SettingsManager
|
import org.oxycblt.auxio.settings.SettingsManager
|
||||||
import org.oxycblt.auxio.ui.getSystemServiceSafe
|
import org.oxycblt.auxio.ui.getSystemServiceSafe
|
||||||
import org.oxycblt.auxio.widget.BaseWidget
|
import org.oxycblt.auxio.widgets.BaseWidget
|
||||||
import org.oxycblt.auxio.widget.MinimalWidgetProvider
|
import org.oxycblt.auxio.widgets.MinimalWidgetProvider
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A service that manages the system-side aspects of playback, such as:
|
* A service that manages the system-side aspects of playback, such as:
|
||||||
|
|
|
@ -51,6 +51,8 @@ class SearchFragment : Fragment() {
|
||||||
|
|
||||||
// --- UI SETUP --
|
// --- UI SETUP --
|
||||||
|
|
||||||
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
binding.searchToolbar.apply {
|
binding.searchToolbar.apply {
|
||||||
menu.findItem(searchModel.filterMode.toId()).isChecked = true
|
menu.findItem(searchModel.filterMode.toId()).isChecked = true
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.widget
|
package org.oxycblt.auxio.widgets
|
||||||
|
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
|
@ -11,7 +11,6 @@ import android.widget.RemoteViews
|
||||||
import androidx.annotation.LayoutRes
|
import androidx.annotation.LayoutRes
|
||||||
import org.oxycblt.auxio.BuildConfig
|
import org.oxycblt.auxio.BuildConfig
|
||||||
import org.oxycblt.auxio.MainActivity
|
import org.oxycblt.auxio.MainActivity
|
||||||
import org.oxycblt.auxio.R
|
|
||||||
import org.oxycblt.auxio.logD
|
import org.oxycblt.auxio.logD
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||||
|
|
||||||
|
@ -96,7 +95,7 @@ abstract class BaseWidget : AppWidgetProvider() {
|
||||||
val ids = getAppWidgetIds(ComponentName(context, this::class.java))
|
val ids = getAppWidgetIds(ComponentName(context, this::class.java))
|
||||||
|
|
||||||
if (ids.isNotEmpty()) {
|
if (ids.isNotEmpty()) {
|
||||||
// Existing widgets found, update thoughs
|
// Existing widgets found, update those
|
||||||
ids.forEach { id ->
|
ids.forEach { id ->
|
||||||
updateAppWidget(id, views)
|
updateAppWidget(id, views)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.widget
|
package org.oxycblt.auxio.widgets
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
@ -9,9 +9,6 @@ import org.oxycblt.auxio.coil.loadBitmap
|
||||||
import org.oxycblt.auxio.logD
|
import org.oxycblt.auxio.logD
|
||||||
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
import org.oxycblt.auxio.playback.state.PlaybackStateManager
|
||||||
|
|
||||||
// Workaround to make studio shut up about perfectly valid layouts somehow
|
|
||||||
// being invalid for remote views.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimal widget. This widget only shows the album, song name, and artist without any
|
* The minimal widget. This widget only shows the album, song name, and artist without any
|
||||||
* controls. Because you know. Minimalism.
|
* controls. Because you know. Minimalism.
|
||||||
|
@ -67,6 +64,9 @@ class MinimalWidgetProvider : BaseWidget() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TYPE = 0xA0D0
|
const val TYPE = 0xA0D0
|
||||||
|
|
||||||
|
// Workaround to make studio shut up about perfectly valid layouts somehow
|
||||||
|
// being invalid for remote views.
|
||||||
const val LAYOUT = R.layout.widget_minimal
|
const val LAYOUT = R.layout.widget_minimal
|
||||||
|
|
||||||
fun new(): MinimalWidgetProvider? {
|
fun new(): MinimalWidgetProvider? {
|
Loading…
Reference in a new issue