Refactor RecyclerView files

Move Fragment-Specific adapters to their own files, keep the viewholders in the generic recycler package.
This commit is contained in:
OxygenCobalt 2020-09-09 16:58:53 -06:00
parent 4e57a94d3e
commit fe7557addb
9 changed files with 15 additions and 28 deletions

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.library
package org.oxycblt.auxio
import android.Manifest
import android.content.pm.PackageManager
@ -13,7 +13,6 @@ import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentLoadingBinding
import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.music.processing.MusicLoaderResponse

View file

@ -17,9 +17,9 @@ import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import org.oxycblt.auxio.databinding.ActivityMainBinding
import org.oxycblt.auxio.library.LibraryFragment
import org.oxycblt.auxio.library.SongsFragment
import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.music.processing.MusicLoaderResponse
import org.oxycblt.auxio.songs.SongsFragment
import org.oxycblt.auxio.theme.accent
import org.oxycblt.auxio.theme.getInactiveAlpha
import org.oxycblt.auxio.theme.getTransparentAccent
@ -103,8 +103,6 @@ class MainActivity : AppCompatActivity() {
}
)
Log.d(this::class.simpleName, musicModel.done.toString())
musicModel.response.observe(
this,
{

View file

@ -10,9 +10,9 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentLibraryBinding
import org.oxycblt.auxio.library.adapters.ArtistAdapter
import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.recycler.ClickListener
import org.oxycblt.auxio.recycler.adapters.ArtistAdapter
import org.oxycblt.auxio.recycler.applyDivider
class LibraryFragment : Fragment() {

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.recycler.adapters
package org.oxycblt.auxio.library.adapters
import android.view.LayoutInflater
import android.view.ViewGroup

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.recycler.adapters
package org.oxycblt.auxio.library.adapters
import android.view.LayoutInflater
import android.view.ViewGroup

View file

@ -42,6 +42,9 @@ class MusicViewModel(private val app: Application) : ViewModel() {
private val mSongs = MutableLiveData<List<Song>>()
val songs: LiveData<List<Song>> get() = mSongs
private val mResponse = MutableLiveData<MusicLoaderResponse>()
val response: LiveData<MusicLoaderResponse> get() = mResponse
// UI control
private val mRedo = MutableLiveData<Boolean>()
val doReload: LiveData<Boolean> get() = mRedo
@ -49,22 +52,10 @@ class MusicViewModel(private val app: Application) : ViewModel() {
private val mDoGrant = MutableLiveData<Boolean>()
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
// 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() {
if (!started) {
started = true
@ -98,8 +89,6 @@ class MusicViewModel(private val app: Application) : ViewModel() {
mAlbums.value = sorter.albums.toList()
mArtists.value = sorter.artists.toList()
mGenres.value = sorter.genres.toList()
mDone = true
}
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() {
mRedo.value = true
mDone = false
doLoad()
}

View file

@ -19,7 +19,6 @@ enum class MusicLoaderResponse {
}
// Class that loads music from the FileSystem.
// FIXME: This thing probably has some memory leaks *somewhere*
class MusicLoader(private val resolver: ContentResolver) {
var genres = mutableListOf<Genre>()

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.recycler.adapters
package org.oxycblt.auxio.songs
import android.view.LayoutInflater
import android.view.ViewGroup

View file

@ -1,4 +1,4 @@
package org.oxycblt.auxio.library
package org.oxycblt.auxio.songs
import android.os.Bundle
import android.util.Log
@ -12,7 +12,6 @@ import org.oxycblt.auxio.R
import org.oxycblt.auxio.databinding.FragmentSongsBinding
import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.recycler.ClickListener
import org.oxycblt.auxio.recycler.adapters.SongAdapter
import org.oxycblt.auxio.recycler.applyDivider
class SongsFragment : Fragment() {