Filter music according to own music setting (should close #33).
This commit is contained in:
parent
746ae8897d
commit
a0e201e68f
|
@ -159,6 +159,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
true -> PowerPreference.getDefaultFile().set("scope", "me")
|
true -> PowerPreference.getDefaultFile().set("scope", "me")
|
||||||
false -> PowerPreference.getDefaultFile().set("scope", "all")
|
false -> PowerPreference.getDefaultFile().set("scope", "all")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EventBus.send(Event.ListingsChanged)
|
||||||
}
|
}
|
||||||
R.id.settings -> startActivityForResult(Intent(this, SettingsActivity::class.java), 0)
|
R.id.settings -> startActivityForResult(Intent(this, SettingsActivity::class.java), 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,16 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.github.apognu.otter.repositories.HttpUpstream
|
import com.github.apognu.otter.repositories.HttpUpstream
|
||||||
import com.github.apognu.otter.repositories.Repository
|
import com.github.apognu.otter.repositories.Repository
|
||||||
import com.github.apognu.otter.utils.Cache
|
import com.github.apognu.otter.utils.*
|
||||||
import com.github.apognu.otter.utils.untilNetwork
|
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import kotlinx.android.synthetic.main.fragment_artists.*
|
import kotlinx.android.synthetic.main.fragment_artists.*
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
import kotlinx.coroutines.Dispatchers.Main
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.flow.collect
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
abstract class FunkwhaleAdapter<D, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
|
abstract class FunkwhaleAdapter<D, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>() {
|
||||||
var data: MutableList<D> = mutableListOf()
|
var data: MutableList<D> = mutableListOf()
|
||||||
|
@ -31,6 +33,7 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
|
||||||
lateinit var adapter: A
|
lateinit var adapter: A
|
||||||
|
|
||||||
private var initialFetched = false
|
private var initialFetched = false
|
||||||
|
private var listener: Job? = null
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
return inflater.inflate(viewRes, container, false)
|
return inflater.inflate(viewRes, container, false)
|
||||||
|
@ -65,6 +68,19 @@ abstract class FunkwhaleFragment<D : Any, A : FunkwhaleAdapter<D, *>> : Fragment
|
||||||
swiper?.setOnRefreshListener {
|
swiper?.setOnRefreshListener {
|
||||||
fetch(Repository.Origin.Network.origin)
|
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>) {}
|
open fun onDataFetched(data: List<D>) {}
|
||||||
|
|
|
@ -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 page = ceil(size / AppContext.PAGE_SIZE.toDouble()).toInt() + 1
|
||||||
|
|
||||||
val offsetUrl =
|
val url =
|
||||||
Uri.parse(url)
|
Uri.parse(url)
|
||||||
.buildUpon()
|
.buildUpon()
|
||||||
.appendQueryParameter("page_size", AppContext.PAGE_SIZE.toString())
|
.appendQueryParameter("page_size", AppContext.PAGE_SIZE.toString())
|
||||||
.appendQueryParameter("page", page.toString())
|
.appendQueryParameter("page", page.toString())
|
||||||
|
.appendQueryParameter("scope", Settings.getScope())
|
||||||
.build()
|
.build()
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
get(offsetUrl).fold(
|
get(url).fold(
|
||||||
{ response ->
|
{ response ->
|
||||||
val data = response.getData()
|
val data = response.getData()
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ sealed class Event {
|
||||||
class StateChanged(val playing: Boolean) : Event()
|
class StateChanged(val playing: Boolean) : Event()
|
||||||
object QueueChanged : Event()
|
object QueueChanged : Event()
|
||||||
object RadioStarted : Event()
|
object RadioStarted : Event()
|
||||||
|
object ListingsChanged : Event()
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Request(var channel: Channel<Response>? = null) {
|
sealed class Request(var channel: Channel<Response>? = null) {
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
android:title="@string/toolbar_search"
|
android:title="@string/toolbar_search"
|
||||||
app:showAsAction="ifRoom" />
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/nav_only_my_music"
|
||||||
|
android:checkable="true"
|
||||||
|
android:title="@string/only_my_music"
|
||||||
|
app:showAsAction="never" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/settings"
|
android:id="@+id/settings"
|
||||||
android:icon="@drawable/settings"
|
android:icon="@drawable/settings"
|
||||||
|
|
Loading…
Reference in New Issue