Filter music according to own music setting (should close #33).

This commit is contained in:
Antoine POPINEAU 2020-06-13 19:34:57 +02:00
parent 746ae8897d
commit a0e201e68f
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
5 changed files with 30 additions and 4 deletions

View File

@ -159,6 +159,8 @@ class MainActivity : AppCompatActivity() {
true -> PowerPreference.getDefaultFile().set("scope", "me")
false -> PowerPreference.getDefaultFile().set("scope", "all")
}
EventBus.send(Event.ListingsChanged)
}
R.id.settings -> startActivityForResult(Intent(this, SettingsActivity::class.java), 0)
}

View File

@ -9,14 +9,16 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.apognu.otter.repositories.HttpUpstream
import com.github.apognu.otter.repositories.Repository
import com.github.apognu.otter.utils.Cache
import com.github.apognu.otter.utils.untilNetwork
import com.github.apognu.otter.utils.*
import com.google.gson.Gson
import kotlinx.android.synthetic.main.fragment_artists.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
abstract class FunkwhaleAdapter<D, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
var data: MutableList<D> = mutableListOf()
@ -31,6 +33,7 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
lateinit var adapter: A
private var initialFetched = false
private var listener: Job? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(viewRes, container, false)
@ -65,6 +68,19 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
swiper?.setOnRefreshListener {
fetch(Repository.Origin.Network.origin)
}
if (listener == null) {
listener = GlobalScope.launch(IO) {
EventBus.get().collect { event ->
if (event is Event.ListingsChanged) {
withContext(Main) {
swiper?.isRefreshing = true
fetch(Repository.Origin.Network.origin)
}
}
}
}
}
}
open fun onDataFetched(data: List<D>) {}

View File

@ -28,15 +28,16 @@ class HttpUpstream<D : Any, R : FunkwhaleResponse<D>>(val behavior: Behavior, pr
val page = ceil(size / AppContext.PAGE_SIZE.toDouble()).toInt() + 1
val offsetUrl =
val url =
Uri.parse(url)
.buildUpon()
.appendQueryParameter("page_size", AppContext.PAGE_SIZE.toString())
.appendQueryParameter("page", page.toString())
.appendQueryParameter("scope", Settings.getScope())
.build()
.toString()
get(offsetUrl).fold(
get(url).fold(
{ response ->
val data = response.getData()

View File

@ -43,6 +43,7 @@ sealed class Event {
class StateChanged(val playing: Boolean) : Event()
object QueueChanged : Event()
object RadioStarted : Event()
object ListingsChanged : Event()
}
sealed class Request(var channel: Channel<Response>? = null) {

View File

@ -15,6 +15,12 @@
android:title="@string/toolbar_search"
app:showAsAction="ifRoom" />
<item
android:id="@+id/nav_only_my_music"
android:checkable="true"
android:title="@string/only_my_music"
app:showAsAction="never" />
<item
android:id="@+id/settings"
android:icon="@drawable/settings"