Browse Source

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

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
a0e201e68f
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 2
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  2. 20
      app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt
  3. 5
      app/src/main/java/com/github/apognu/otter/repositories/HttpUpstream.kt
  4. 1
      app/src/main/java/com/github/apognu/otter/utils/EventBus.kt
  5. 6
      app/src/main/res/menu-land/toolbar.xml

2
app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt

@ -159,6 +159,8 @@ class MainActivity : AppCompatActivity() { @@ -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)
}

20
app/src/main/java/com/github/apognu/otter/fragments/FunkwhaleFragment.kt

@ -9,14 +9,16 @@ import androidx.recyclerview.widget.LinearLayoutManager @@ -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 @@ -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 @@ -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>) {}

5
app/src/main/java/com/github/apognu/otter/repositories/HttpUpstream.kt

@ -28,15 +28,16 @@ class HttpUpstream<D : Any, R : FunkwhaleResponse<D>>(val behavior: Behavior, pr @@ -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()

1
app/src/main/java/com/github/apognu/otter/utils/EventBus.kt

@ -43,6 +43,7 @@ sealed class Event { @@ -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) {

6
app/src/main/res/menu-land/toolbar.xml

@ -15,6 +15,12 @@ @@ -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"

Loading…
Cancel
Save