Refactor RecyclerView files
Move Fragment-Specific adapters to their own files, keep the viewholders in the generic recycler package.
This commit is contained in:
parent
4e57a94d3e
commit
fe7557addb
9 changed files with 15 additions and 28 deletions
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.library
|
package org.oxycblt.auxio
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
|
@ -13,7 +13,6 @@ import androidx.core.content.ContextCompat
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import org.oxycblt.auxio.R
|
|
||||||
import org.oxycblt.auxio.databinding.FragmentLoadingBinding
|
import org.oxycblt.auxio.databinding.FragmentLoadingBinding
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
|
@ -17,9 +17,9 @@ import com.google.android.material.tabs.TabLayout
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
import org.oxycblt.auxio.databinding.ActivityMainBinding
|
import org.oxycblt.auxio.databinding.ActivityMainBinding
|
||||||
import org.oxycblt.auxio.library.LibraryFragment
|
import org.oxycblt.auxio.library.LibraryFragment
|
||||||
import org.oxycblt.auxio.library.SongsFragment
|
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
|
||||||
|
import org.oxycblt.auxio.songs.SongsFragment
|
||||||
import org.oxycblt.auxio.theme.accent
|
import org.oxycblt.auxio.theme.accent
|
||||||
import org.oxycblt.auxio.theme.getInactiveAlpha
|
import org.oxycblt.auxio.theme.getInactiveAlpha
|
||||||
import org.oxycblt.auxio.theme.getTransparentAccent
|
import org.oxycblt.auxio.theme.getTransparentAccent
|
||||||
|
@ -103,8 +103,6 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
Log.d(this::class.simpleName, musicModel.done.toString())
|
|
||||||
|
|
||||||
musicModel.response.observe(
|
musicModel.response.observe(
|
||||||
this,
|
this,
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,9 +10,9 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import org.oxycblt.auxio.R
|
import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
|
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
|
||||||
|
import org.oxycblt.auxio.library.adapters.ArtistAdapter
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
import org.oxycblt.auxio.recycler.ClickListener
|
import org.oxycblt.auxio.recycler.ClickListener
|
||||||
import org.oxycblt.auxio.recycler.adapters.ArtistAdapter
|
|
||||||
import org.oxycblt.auxio.recycler.applyDivider
|
import org.oxycblt.auxio.recycler.applyDivider
|
||||||
|
|
||||||
class LibraryFragment : Fragment() {
|
class LibraryFragment : Fragment() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.recycler.adapters
|
package org.oxycblt.auxio.library.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.recycler.adapters
|
package org.oxycblt.auxio.library.adapters
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
|
@ -42,6 +42,9 @@ class MusicViewModel(private val app: Application) : ViewModel() {
|
||||||
private val mSongs = MutableLiveData<List<Song>>()
|
private val mSongs = MutableLiveData<List<Song>>()
|
||||||
val songs: LiveData<List<Song>> get() = mSongs
|
val songs: LiveData<List<Song>> get() = mSongs
|
||||||
|
|
||||||
|
private val mResponse = MutableLiveData<MusicLoaderResponse>()
|
||||||
|
val response: LiveData<MusicLoaderResponse> get() = mResponse
|
||||||
|
|
||||||
// UI control
|
// UI control
|
||||||
private val mRedo = MutableLiveData<Boolean>()
|
private val mRedo = MutableLiveData<Boolean>()
|
||||||
val doReload: LiveData<Boolean> get() = mRedo
|
val doReload: LiveData<Boolean> get() = mRedo
|
||||||
|
@ -49,22 +52,10 @@ class MusicViewModel(private val app: Application) : ViewModel() {
|
||||||
private val mDoGrant = MutableLiveData<Boolean>()
|
private val mDoGrant = MutableLiveData<Boolean>()
|
||||||
val doGrant: LiveData<Boolean> get() = mDoGrant
|
val doGrant: LiveData<Boolean> get() = mDoGrant
|
||||||
|
|
||||||
// Response Management
|
|
||||||
|
|
||||||
// The actual response from MusicLoader. This is set to null so that LoadingFragment doesn't
|
|
||||||
//
|
|
||||||
private val mResponse = MutableLiveData<MusicLoaderResponse>()
|
|
||||||
val response: LiveData<MusicLoaderResponse> get() = mResponse
|
|
||||||
|
|
||||||
// Whether MusicViewModel has finished the load [Used to hide LoadingFragment in MainActivity]
|
|
||||||
private var mDone = false
|
|
||||||
val done: Boolean get() = mDone
|
|
||||||
|
|
||||||
// Whether go() has ran. Used to prevent multiple loads from the recreation of LoadingFragment.
|
|
||||||
private var started = false
|
private var started = false
|
||||||
|
|
||||||
// Start the music loading sequence.
|
// Start the music loading sequence.
|
||||||
// This should only be ran once, use redo() for all other loads.
|
// This should only be ran once, use reload() for all other loads.
|
||||||
fun go() {
|
fun go() {
|
||||||
if (!started) {
|
if (!started) {
|
||||||
started = true
|
started = true
|
||||||
|
@ -98,8 +89,6 @@ class MusicViewModel(private val app: Application) : ViewModel() {
|
||||||
mAlbums.value = sorter.albums.toList()
|
mAlbums.value = sorter.albums.toList()
|
||||||
mArtists.value = sorter.artists.toList()
|
mArtists.value = sorter.artists.toList()
|
||||||
mGenres.value = sorter.genres.toList()
|
mGenres.value = sorter.genres.toList()
|
||||||
|
|
||||||
mDone = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mResponse.value = loader.response
|
mResponse.value = loader.response
|
||||||
|
@ -114,9 +103,12 @@ class MusicViewModel(private val app: Application) : ViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UI communication functions
|
||||||
|
// LoadingFragment uses these so that button presses can update the ViewModel.
|
||||||
|
// all doneWithX functions are to reset the value so that LoadingFragment doesn't
|
||||||
|
// repeat commands if the view is recreated.
|
||||||
fun reload() {
|
fun reload() {
|
||||||
mRedo.value = true
|
mRedo.value = true
|
||||||
mDone = false
|
|
||||||
|
|
||||||
doLoad()
|
doLoad()
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ enum class MusicLoaderResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class that loads music from the FileSystem.
|
// Class that loads music from the FileSystem.
|
||||||
// FIXME: This thing probably has some memory leaks *somewhere*
|
|
||||||
class MusicLoader(private val resolver: ContentResolver) {
|
class MusicLoader(private val resolver: ContentResolver) {
|
||||||
|
|
||||||
var genres = mutableListOf<Genre>()
|
var genres = mutableListOf<Genre>()
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.recycler.adapters
|
package org.oxycblt.auxio.songs
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
|
@ -1,4 +1,4 @@
|
||||||
package org.oxycblt.auxio.library
|
package org.oxycblt.auxio.songs
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
@ -12,7 +12,6 @@ import org.oxycblt.auxio.R
|
||||||
import org.oxycblt.auxio.databinding.FragmentSongsBinding
|
import org.oxycblt.auxio.databinding.FragmentSongsBinding
|
||||||
import org.oxycblt.auxio.music.MusicViewModel
|
import org.oxycblt.auxio.music.MusicViewModel
|
||||||
import org.oxycblt.auxio.recycler.ClickListener
|
import org.oxycblt.auxio.recycler.ClickListener
|
||||||
import org.oxycblt.auxio.recycler.adapters.SongAdapter
|
|
||||||
import org.oxycblt.auxio.recycler.applyDivider
|
import org.oxycblt.auxio.recycler.applyDivider
|
||||||
|
|
||||||
class SongsFragment : Fragment() {
|
class SongsFragment : Fragment() {
|
Loading…
Reference in a new issue