Skip to content

Commit

Permalink
Implement UI features
Browse files Browse the repository at this point in the history
  • Loading branch information
Reco1I committed Dec 13, 2024
1 parent 8e07328 commit 465b361
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 25 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
33 changes: 24 additions & 9 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,26 @@ 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 {
Config.setInt("beatmapMirror", it as Int)
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 @@ -282,7 +297,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
2 changes: 1 addition & 1 deletion src/com/reco1l/osu/beatmaplisting/BeatmapMirror.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ enum class BeatmapMirror(
OSU_DIRECT(
homeUrl = "https://osu.direct",
description = "osu.direct",
logoResource = R.drawable.powered_by_osudirect,
logoResource = R.drawable.osudirect,

search = BeatmapMirrorActionWithResponse(
request = OsuDirectSearchRequestModel(),
Expand Down
19 changes: 15 additions & 4 deletions src/com/reco1l/osu/ui/ListDialog.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.reco1l.osu.ui

import android.graphics.Color
import android.graphics.drawable.Drawable
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.core.view.forEach
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.reco1l.toolkt.android.cornerRadius
import com.reco1l.toolkt.android.dp
import com.reco1l.toolkt.android.drawableLeft
import com.reco1l.toolkt.android.drawableRight
import ru.nsu.ccfit.zuev.osuplus.R

Expand All @@ -21,12 +24,17 @@ data class Option(
/**
* The text to be displayed in the option.
*/
val text: String,
val text: CharSequence,

/**
* The value to be returned when the option is selected.
*/
val value: Any
val value: Any,

/**
* The icon to be displayed in the option.
*/
val icon: Drawable? = null
)


Expand Down Expand Up @@ -71,8 +79,8 @@ open class SelectDialog : MessageDialog() {
}


fun setOptions(options: MutableList<Option>): SelectDialog {
this.options = options
fun setOptions(options: List<Option>): SelectDialog {
this.options = options.toMutableList()
return this
}

Expand Down Expand Up @@ -134,6 +142,9 @@ open class SelectDialog : MessageDialog() {

fun bind(option: Option) {
text.text = option.text
text.drawableLeft = option.icon
text.compoundDrawablePadding = 12.dp

text.setOnClickListener {

unselectAll()
Expand Down
2 changes: 1 addition & 1 deletion src/com/reco1l/osu/ui/entity/BeatmapButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BeatmapButton : Sprite(0f, 0f, ResourceManager.getInstance().getTexture("m
if (parentSetID == null)
return true

val url = BeatmapListing.mirror.downloadEndpoint(parentSetID!!)
val url = BeatmapListing.mirror.download.request(parentSetID!!).toString()

async {
try {
Expand Down

0 comments on commit 465b361

Please sign in to comment.