Added ability to not fetch on create for fragments. Added animation on queue change.

This commit is contained in:
Antoine POPINEAU 2019-10-24 12:35:34 +02:00
parent 2d5e73dcd4
commit a63f3f7e68
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
6 changed files with 42 additions and 12 deletions

View File

@ -2,6 +2,7 @@ package com.github.apognu.otter.activities
import android.animation.Animator
import android.animation.AnimatorListenerAdapter
import android.animation.ObjectAnimator
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
@ -9,6 +10,7 @@ import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
@ -298,6 +300,16 @@ class MainActivity : AppCompatActivity() {
}
}
}
is Event.QueueChanged -> {
findViewById<View>(R.id.nav_queue)?.let { view ->
ObjectAnimator.ofFloat(view, View.ROTATION, 0f, 360f).let {
it.duration = 500
it.interpolator = AccelerateDecelerateInterpolator()
it.start()
}
}
}
}
}
}

View File

@ -24,7 +24,7 @@ class BrowseFragment : Fragment() {
tabs.getTabAt(0)?.select()
pager.adapter = adapter
pager.offscreenPageLimit = 4
pager.offscreenPageLimit = 3
}
}

View File

@ -17,6 +17,8 @@ class FavoritesFragment : FunkwhaleFragment<Track, FavoritesAdapter>() {
lateinit var favoritesRepository: FavoritesRepository
override var fetchOnCreate = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

View File

@ -24,6 +24,9 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
lateinit var repository: Repository<D, *>
lateinit var adapter: A
open var fetchOnCreate = true
private var initialFetched = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(viewRes, container, false)
}
@ -49,14 +52,7 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
swiper?.isRefreshing = true
repository.fetch().untilNetwork {
swiper?.isRefreshing = false
onDataFetched(it)
adapter.data = it.toMutableList()
adapter.notifyDataSetChanged()
}
if (fetchOnCreate) fetch()
}
override fun onResume() {
@ -74,7 +70,24 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
adapter.notifyDataSetChanged()
}
}
if (!fetchOnCreate) fetch()
}
open fun onDataFetched(data: List<D>) {}
private fun fetch() {
if (!initialFetched) {
initialFetched = true
repository.fetch().untilNetwork {
swiper?.isRefreshing = false
onDataFetched(it)
adapter.data = it.toMutableList()
adapter.notifyDataSetChanged()
}
}
}
}

View File

@ -20,9 +20,8 @@ class FavoritesRepository(override val context: Context?) : Repository<Track, Tr
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(TracksCache::class.java).deserialize(reader)
override fun onDataFetched(data: List<Track>) = data.map {
it.apply {
it.favorite = true
}
it.favorite = true
it
}
fun addFavorite(id: Int) {

View File

@ -51,6 +51,8 @@ class HttpUpstream<D : Any, R : FunkwhaleResponse<D>>(private val behavior: Beha
{ response ->
val data = data.plus(response.getData())
log(data.size.toString())
if (behavior == Behavior.Progressive || response.next == null) {
channel.offer(Repository.Response(Repository.Origin.Network, data))
} else {
@ -75,6 +77,8 @@ class HttpUpstream<D : Any, R : FunkwhaleResponse<D>>(private val behavior: Beha
}
suspend fun get(url: String): Result<R, FuelError> {
log(url)
val token = PowerPreference.getFileByName(AppContext.PREFS_CREDENTIALS).getString("access_token")
val (_, response, result) = Fuel