Skip to content

Commit

Permalink
Merge pull request #467 from Reco1I/multi-bmap-mirror
Browse files Browse the repository at this point in the history
Implement multiple beatmap mirror support
  • Loading branch information
Rian8337 authored Dec 16, 2024
2 parents a2ba24d + b16fed7 commit fea3a44
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 128 deletions.
10 changes: 10 additions & 0 deletions res/drawable/arrow_drop_down_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M460.81,566.96L334.76,440.92Q332.16,438.31 330.66,435.09Q329.16,431.88 329.16,428.2Q329.16,420.85 334.13,415.42Q339.1,410 347.23,410L612.77,410Q620.9,410 625.87,415.48Q630.84,420.95 630.84,428.25Q630.84,430.08 625.23,440.92L499.19,566.96Q494.85,571.31 490.21,573.31Q485.57,575.31 480,575.31Q474.43,575.31 469.79,573.31Q465.15,571.31 460.81,566.96Z"/>
</vector>
Binary file added res/drawable/osudirect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed res/drawable/powered_by_osudirect.png
Binary file not shown.
30 changes: 20 additions & 10 deletions res/layout/beatmap_downloader_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

<EditText
android:id="@+id/search"
android:layout_width="300dp"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/rounded_rect"
android:layout_toRightOf="@id/close"
android:layout_toLeftOf="@id/indicator"
android:backgroundTint="#363653"
android:drawableRight="@drawable/search_24px"
android:drawableTint="#8C8CB4"
Expand All @@ -43,23 +45,31 @@
android:textColorHint="#8C8CB4"
android:textSize="14dp" />

<ImageView
<Button
android:id="@+id/logo"
android:layout_width="100dp"
android:layout_height="36dp"
android:layout_marginRight="12dp"
android:src="@drawable/powered_by_osudirect"
style="@style/button_borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:drawableRight="@drawable/arrow_drop_down_24px"
android:layout_marginHorizontal="12dp"
android:maxHeight="36dp"
android:layout_alignParentRight="true"
android:background="@drawable/click_effect"
android:clickable="true"/>
android:layout_toLeftOf="@id/logo"
android:drawableLeft="@drawable/osudirect"
android:drawablePadding="8dp"
android:paddingVertical="16dp"
android:paddingLeft="16dp"
android:paddingRight="2dp"
android:text="osu.direct"
android:textColor="#FFF" />

<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:layout_marginLeft="12dp"
android:layout_toLeftOf="@id/refresh"
android:indeterminate="true"
app:indicatorColor="#FFF"
Expand All @@ -72,8 +82,8 @@
style="@style/button_borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_centerVertical="true"
android:layout_marginRight="12dp"
android:layout_toLeftOf="@id/logo"
android:drawableLeft="@drawable/refresh_24px"
android:drawablePadding="8dp"
Expand Down
68 changes: 43 additions & 25 deletions src/com/reco1l/osu/beatmaplisting/BeatmapListing.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.reco1l.osu.beatmaplisting

import android.content.Intent
import android.graphics.BitmapFactory
import android.net.Uri
import android.util.Log
import android.view.Choreographer
import android.view.Choreographer.FrameCallback
Expand Down Expand Up @@ -37,6 +35,8 @@ import com.reco1l.framework.bass.URLBassStream
import com.reco1l.framework.net.IDownloaderObserver
import com.reco1l.framework.net.JsonArrayRequest
import com.reco1l.osu.*
import com.reco1l.osu.ui.Option
import com.reco1l.osu.ui.SelectDialog
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -98,7 +98,7 @@ class BeatmapListing : BaseFragment(),

private lateinit var searchBox: EditText

private lateinit var logoView: ImageView
private lateinit var logoView: Button


init {
Expand Down Expand Up @@ -133,11 +133,29 @@ class BeatmapListing : BaseFragment(),

logoView = findViewById(R.id.logo)!!
logoView.setOnClickListener {
val url = "https://osu.direct/browse"
val i = Intent(Intent.ACTION_VIEW)

i.data = Uri.parse(url)
startActivity(i)
SelectDialog()
.setOptions(BeatmapMirror.entries.map { mirror ->
Option(
text = buildSpannedString {
append(mirror.description)
appendLine()
color(0xBFFFFFFF.toInt()) { append(mirror.homeUrl) }
},
value = mirror.ordinal,
icon = requireContext().getDrawable(mirror.logoResource)
)
})
.setSelected(mirror.ordinal)
.setOnSelectListener { value ->
value as Int
if (value != mirror.ordinal) {
Config.setInt("beatmapMirror", value)
mirror = BeatmapMirror.entries[Config.getInt("beatmapMirror", 0)]
search(false)
}
}
.setTitle("Select a beatmap mirror")
.show()
}

findViewById<ImageButton>(R.id.close)!!.setOnClickListener {
Expand Down Expand Up @@ -195,21 +213,17 @@ class BeatmapListing : BaseFragment(),

ensureActive()

JsonArrayRequest(mirror.search.endpoint).use { request ->

request.buildUrl {

addQueryParameter("mode", "0")
addQueryParameter("query", searchBox.text.toString())
addQueryParameter("offset", offset.toString())
}
JsonArrayRequest(
mirror.search.request(
query = searchBox.text.toString(),
offset = offset
)
).use { request ->

request.buildRequest { header("User-Agent", "Chrome/Android") }

ensureActive()

val beatmapSets = mirror.search.mapResponse(request.execute().json)

val beatmapSets = mirror.search.response(request.execute().json)
ensureActive()

adapter.data.addAll(beatmapSets)
Expand Down Expand Up @@ -286,7 +300,7 @@ class BeatmapListing : BaseFragment(),
/**
* The current selected beatmap mirror.
*/
var mirror = BeatmapMirror.OSU_DIRECT
var mirror = BeatmapMirror.entries[Config.getInt("beatmapMirror", 0)]

/**
* Whether is a beatmap preview music playing or not.
Expand Down Expand Up @@ -393,8 +407,10 @@ class BeatmapSetDetails(val beatmapSet: BeatmapSetModel, val holder: BeatmapSetV
}

downloadButton.setOnClickListener {
val url = BeatmapListing.mirror.downloadEndpoint(beatmapSet.id)
BeatmapDownloader.download(url, "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}")
BeatmapDownloader.download(
url = BeatmapListing.mirror.download.request(beatmapSet.id).toString(),
suggestedFilename = "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}"
)
}

cover.setImageDrawable(holder.cover.drawable)
Expand Down Expand Up @@ -598,8 +614,10 @@ class BeatmapSetViewHolder(itemView: View, private val mediaScope: CoroutineScop
}

downloadButton.setOnClickListener {
val url = BeatmapListing.mirror.downloadEndpoint(beatmapSet.id)
BeatmapDownloader.download(url, "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}")
BeatmapDownloader.download(
url = BeatmapListing.mirror.download.request(beatmapSet.id).toString(),
suggestedFilename = "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}"
)
}


Expand All @@ -621,7 +639,7 @@ class BeatmapSetViewHolder(itemView: View, private val mediaScope: CoroutineScop
previewJob = mediaScope.launch {

try {
previewStream = URLBassStream(BeatmapListing.mirror.previewEndpoint(beatmapSet.beatmaps[0].id)) {
previewStream = URLBassStream(BeatmapListing.mirror.preview.request(beatmapSet.beatmaps[0].id).toString()) {
stopPreview(true)

if (BeatmapListing.isPlayingMusic) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,31 @@ import ru.nsu.ccfit.zuev.osu.RankedStatus
* Beatmap set response model for beatmaps mirrors.
*/
data class BeatmapSetModel(

val id: Long,

val title: String,

val titleUnicode: String,

val artist: String,

val artistUnicode: String,

val status: RankedStatus,

val creator: String,

val thumbnail: String?,

val beatmaps: List<BeatmapModel>

)

/**
* Beatmap response model for beatmaps mirrors.
*/
data class BeatmapModel(

val id: Long,

val version: String,

val starRating: Double,

val ar: Double,

val cs: Double,

val hp: Double,

val od: Double,

val bpm: Double,

val lengthSec: Long,

val circleCount: Int,

val sliderCount:Int,

val spinnerCount: Int

)
Loading

0 comments on commit fea3a44

Please sign in to comment.