Glimpse: Get rid of CommonNavigationArguments

Change-Id: I0936fc9c1411930081299ff36583b09b71f188e0
This commit is contained in:
Sebastiano Barezzi 2023-08-05 23:59:38 +02:00 committed by LuK1337
parent d74cd06a79
commit 10a5c8ff04
6 changed files with 14 additions and 57 deletions

View File

@ -8,15 +8,8 @@ package org.lineageos.glimpse
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.WindowCompat import androidx.core.view.WindowCompat
import androidx.navigation.fragment.NavHostFragment
import org.lineageos.glimpse.utils.CommonNavigationArguments
class MainActivity : AppCompatActivity() { class MainActivity : AppCompatActivity() {
// Fragments
private val navHostFragment by lazy { supportFragmentManager.findFragmentById(R.id.navHostFragment) as NavHostFragment }
private val navController by lazy { navHostFragment.navController }
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -28,11 +21,5 @@ class MainActivity : AppCompatActivity() {
WindowCompat.getInsetsController(window, window.decorView) WindowCompat.getInsetsController(window, window.decorView)
windowInsetsController.isAppearanceLightNavigationBars = true windowInsetsController.isAppearanceLightNavigationBars = true
navController.addOnDestinationChangedListener { _, _, bundle ->
val commonNavigationArguments = bundle?.let {
CommonNavigationArguments.fromBundle(it)
} ?: CommonNavigationArguments()
}
} }
} }

View File

@ -13,6 +13,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
@ -34,7 +35,6 @@ import org.lineageos.glimpse.ext.getViewProperty
import org.lineageos.glimpse.models.Album import org.lineageos.glimpse.models.Album
import org.lineageos.glimpse.thumbnail.ThumbnailAdapter import org.lineageos.glimpse.thumbnail.ThumbnailAdapter
import org.lineageos.glimpse.thumbnail.ThumbnailLayoutManager import org.lineageos.glimpse.thumbnail.ThumbnailLayoutManager
import org.lineageos.glimpse.utils.CommonNavigationArguments
import org.lineageos.glimpse.utils.MediaStoreRequests import org.lineageos.glimpse.utils.MediaStoreRequests
import org.lineageos.glimpse.utils.PermissionsUtils import org.lineageos.glimpse.utils.PermissionsUtils
@ -184,9 +184,9 @@ class AlbumFragment : Fragment(R.layout.fragment_album), LoaderManager.LoaderCal
fun createBundle( fun createBundle(
album: Album, album: Album,
) = CommonNavigationArguments().toBundle().apply { ) = bundleOf(
putParcelable(KEY_ALBUM_ID, album) KEY_ALBUM_ID to album,
} )
/** /**
* Use this factory method to create a new instance of * Use this factory method to create a new instance of

View File

@ -14,6 +14,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewGroup.MarginLayoutParams import android.view.ViewGroup.MarginLayoutParams
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
@ -29,7 +30,6 @@ import org.lineageos.glimpse.R
import org.lineageos.glimpse.ext.getViewProperty import org.lineageos.glimpse.ext.getViewProperty
import org.lineageos.glimpse.models.Album import org.lineageos.glimpse.models.Album
import org.lineageos.glimpse.thumbnail.AlbumThumbnailAdapter import org.lineageos.glimpse.thumbnail.AlbumThumbnailAdapter
import org.lineageos.glimpse.utils.CommonNavigationArguments
import org.lineageos.glimpse.utils.MediaStoreRequests import org.lineageos.glimpse.utils.MediaStoreRequests
/** /**
@ -166,7 +166,7 @@ class AlbumsFragment : Fragment(), LoaderManager.LoaderCallbacks<Cursor> {
} }
companion object { companion object {
private fun createBundle() = CommonNavigationArguments().toBundle() private fun createBundle() = bundleOf()
/** /**
* Use this factory method to create a new instance of * Use this factory method to create a new instance of

View File

@ -19,6 +19,7 @@ import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
@ -37,7 +38,6 @@ import org.lineageos.glimpse.ext.*
import org.lineageos.glimpse.models.Album import org.lineageos.glimpse.models.Album
import org.lineageos.glimpse.models.Media import org.lineageos.glimpse.models.Media
import org.lineageos.glimpse.thumbnail.MediaViewerAdapter import org.lineageos.glimpse.thumbnail.MediaViewerAdapter
import org.lineageos.glimpse.utils.CommonNavigationArguments
import org.lineageos.glimpse.utils.MediaStoreRequests import org.lineageos.glimpse.utils.MediaStoreRequests
import org.lineageos.glimpse.utils.PermissionsUtils import org.lineageos.glimpse.utils.PermissionsUtils
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
@ -311,11 +311,11 @@ class MediaViewerFragment : Fragment(
album: Album?, album: Album?,
media: Media, media: Media,
position: Int, position: Int,
) = CommonNavigationArguments().toBundle().apply { ) = bundleOf(
putParcelable(KEY_ALBUM, album) KEY_ALBUM to album,
putParcelable(KEY_MEDIA, media) KEY_MEDIA to media,
putInt(KEY_POSITION, position) KEY_POSITION to position,
} )
/** /**
* Use this factory method to create a new instance of * Use this factory method to create a new instance of

View File

@ -13,6 +13,7 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
@ -27,7 +28,6 @@ import org.lineageos.glimpse.R
import org.lineageos.glimpse.ext.getViewProperty import org.lineageos.glimpse.ext.getViewProperty
import org.lineageos.glimpse.thumbnail.ThumbnailAdapter import org.lineageos.glimpse.thumbnail.ThumbnailAdapter
import org.lineageos.glimpse.thumbnail.ThumbnailLayoutManager import org.lineageos.glimpse.thumbnail.ThumbnailLayoutManager
import org.lineageos.glimpse.utils.CommonNavigationArguments
import org.lineageos.glimpse.utils.MediaStoreRequests import org.lineageos.glimpse.utils.MediaStoreRequests
import org.lineageos.glimpse.utils.PermissionsUtils import org.lineageos.glimpse.utils.PermissionsUtils
@ -155,7 +155,7 @@ class ReelsFragment : Fragment(R.layout.fragment_reels), LoaderManager.LoaderCal
} }
companion object { companion object {
private fun createBundle() = CommonNavigationArguments().toBundle() private fun createBundle() = bundleOf()
/** /**
* Use this factory method to create a new instance of * Use this factory method to create a new instance of

View File

@ -1,30 +0,0 @@
/*
* SPDX-FileCopyrightText: 2023 The LineageOS Project
* SPDX-License-Identifier: Apache-2.0
*/
package org.lineageos.glimpse.utils
import android.os.Bundle
import androidx.core.os.bundleOf
/**
* Common navigation arguments for all fragments.
* It is recommended to create a bundle from there and then add fragment-specific
* arguments to it.
*/
data class CommonNavigationArguments(
var title: String? = null,
) {
fun toBundle() = bundleOf(
KEY_TITLE to title,
)
companion object {
private const val KEY_TITLE = "title"
fun fromBundle(bundle: Bundle) = CommonNavigationArguments(
bundle.getString(KEY_TITLE),
)
}
}