Browse Source

Added track details from Now Playing view. Should fix #30.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
159685bcc1
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 4
      app/build.gradle.kts
  2. 5
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  3. 81
      app/src/main/java/com/github/apognu/otter/fragments/TrackInfoDetailsFragment.kt
  4. 16
      app/src/main/java/com/github/apognu/otter/utils/Util.kt
  5. 22
      app/src/main/res/layout/fragment_track_info_details.xml
  6. 12
      app/src/main/res/menu/track_info.xml
  7. 14
      app/src/main/res/values-fr/strings.xml
  8. 14
      app/src/main/res/values/strings.xml
  9. 8
      app/src/main/res/values/styles.xml

4
app/build.gradle.kts

@ -96,7 +96,7 @@ play { @@ -96,7 +96,7 @@ play {
dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar"))))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.60")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2")
@ -111,7 +111,7 @@ dependencies { @@ -111,7 +111,7 @@ dependencies {
implementation("com.google.android.exoplayer:exoplayer:2.10.5")
implementation("com.google.android.exoplayer:extension-mediasession:2.10.6")
implementation("com.google.android.exoplayer:extension-cast:2.10.6")
// implementation("com.google.android.exoplayer:extension-cast:2.10.6")
implementation("com.github.PaulWoitaschek.ExoPlayer-Extensions:extension-flac:2.10.5") {
isTransitive = false
}

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

@ -319,8 +319,9 @@ class MainActivity : AppCompatActivity() { @@ -319,8 +319,9 @@ class MainActivity : AppCompatActivity() {
setOnMenuItemClickListener {
when (it.itemId) {
R.id.go_to_artist -> ArtistsFragment.openAlbums(this@MainActivity, track.artist, art = track.album.cover.original)
R.id.go_to_album -> AlbumsFragment.openTracks(this@MainActivity, track.album)
R.id.track_info_artist -> ArtistsFragment.openAlbums(this@MainActivity, track.artist, art = track.album.cover.original)
R.id.track_info_album -> AlbumsFragment.openTracks(this@MainActivity, track.album)
R.id.track_info_details -> TrackInfoDetailsFragment.new(track).show(supportFragmentManager, "dialog")
}
now_playing.close()

81
app/src/main/java/com/github/apognu/otter/fragments/TrackInfoDetailsFragment.kt

@ -0,0 +1,81 @@ @@ -0,0 +1,81 @@
package com.github.apognu.otter.fragments
import android.net.Uri
import android.os.Bundle
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams
import android.widget.TextView
import androidx.core.os.bundleOf
import androidx.fragment.app.DialogFragment
import com.github.apognu.otter.R
import com.github.apognu.otter.utils.Track
import com.github.apognu.otter.utils.mustNormalizeUrl
import com.github.apognu.otter.utils.toDurationString
import kotlinx.android.synthetic.main.fragment_track_info_details.*
class TrackInfoDetailsFragment : DialogFragment() {
companion object {
fun new(track: Track): TrackInfoDetailsFragment {
return TrackInfoDetailsFragment().apply {
arguments = bundleOf(
"artistName" to track.artist.name,
"albumTitle" to track.album.title,
"trackTitle" to track.title,
"trackPosition" to track.position,
"trackDuration" to track.bestUpload()?.duration?.toLong()?.let { toDurationString(it, showSeconds = true) },
"trackBitrate" to track.bestUpload()?.bitrate?.let { "${it / 1000} Kbps" },
"trackInstance" to track.bestUpload()?.listen_url?.let { Uri.parse(mustNormalizeUrl(it)).authority }
)
}
}
}
var properties: MutableList<Pair<Int, String?>> = mutableListOf()
override fun onStart() {
super.onStart()
dialog?.window?.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.apply {
properties.add(Pair(R.string.track_info_details_artist, getString("artistName")))
properties.add(Pair(R.string.track_info_details_album, getString("albumTitle")))
properties.add(Pair(R.string.track_info_details_track_title, getString("trackTitle")))
properties.add(Pair(R.string.track_info_details_track_duration, getString("trackDuration")))
properties.add(Pair(R.string.track_info_details_track_position, getString("trackPosition")))
properties.add(Pair(R.string.track_info_details_track_bitrate, getString("trackBitrate")))
properties.add(Pair(R.string.track_info_details_track_instance, getString("trackInstance")))
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_track_info_details, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
properties.forEach { (label, value) ->
val labelTextView = TextView(context).apply {
text = getString(label)
setTextAppearance(R.style.AppTheme_TrackDetailsLabel)
}
val valueTextView = TextView(context).apply {
text = value ?: "N/A"
setTextAppearance(R.style.AppTheme_TrackDetailsValue)
setPadding(0, 0, 0, TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16f, resources.displayMetrics).toInt())
}
infos.addView(labelTextView)
infos.addView(valueTextView)
}
}
}

16
app/src/main/java/com/github/apognu/otter/utils/Util.kt

@ -36,16 +36,18 @@ fun mustNormalizeUrl(url: String): String { @@ -36,16 +36,18 @@ fun mustNormalizeUrl(url: String): String {
}.toString()
}
fun toDurationString(seconds: Long): String {
val days = (seconds / 86400)
val hours = (seconds % 86400) / 3600
val minutes = (seconds % 86400 % 3600) / 60
fun toDurationString(duration: Long, showSeconds: Boolean = false): String {
val days = (duration / 86400)
val hours = (duration % 86400) / 3600
val minutes = (duration % 86400 % 3600) / 60
val seconds = duration % 86400 % 3600 % 60
val ret = StringBuilder()
if (days > 0) ret.append("${days}d")
if (hours > 0) ret.append(" ${hours}h")
if (minutes > 0) ret.append(" ${minutes}m")
if (days > 0) ret.append("${days}d ")
if (hours > 0) ret.append("${hours}h ")
if (minutes > 0) ret.append("${minutes}m ")
if (showSeconds && seconds > 0) ret.append("${seconds}s")
return ret.toString()
}

22
app/src/main/res/layout/fragment_track_info_details.xml

@ -0,0 +1,22 @@ @@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/infos"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
style="@style/AppTheme.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/track_info_details_title" />
</LinearLayout>
</ScrollView>

12
app/src/main/res/menu/track_info.xml

@ -2,11 +2,15 @@ @@ -2,11 +2,15 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/go_to_artist"
android:title="@string/go_to_artist" />
android:id="@+id/track_info_artist"
android:title="@string/track_info_artist" />
<item
android:id="@+id/go_to_album"
android:title="@string/go_to_album" />
android:id="@+id/track_info_album"
android:title="@string/track_info_album" />
<item
android:id="@+id/track_info_details"
android:title="@string/track_info_details" />
</menu>

14
app/src/main/res/values-fr/strings.xml

@ -86,8 +86,18 @@ @@ -86,8 +86,18 @@
<string name="alt_more_options">Plus d\'options</string>
<string name="alt_track_info">Informations sur cette piste</string>
<string name="go_to_artist">Voir l\'artist</string>
<string name="go_to_album">Voir l\'album</string>
<string name="track_info_artist">Voir l\'artist</string>
<string name="track_info_album">Voir l\'album</string>
<string name="track_info_details">Informations</string>
<string name="track_info_details_title">Détails de la piste</string>
<string name="track_info_details_artist">Artiste</string>
<string name="track_info_details_album">Album</string>
<string name="track_info_details_track_title">Nom de piste</string>
<string name="track_info_details_track_duration">Durée</string>
<string name="track_info_details_track_position">Position dans l\'album</string>
<string name="track_info_details_track_bitrate">Bitrate</string>
<string name="track_info_details_track_instance">Instance Funkwhale</string>
<string name="logout_title">Déconnexion</string>
<string name="logout_content">Etes-vous certains de vouloir vous déconnecter de votre instance Funkwhale ?</string>

14
app/src/main/res/values/strings.xml

@ -86,8 +86,18 @@ @@ -86,8 +86,18 @@
<string name="alt_more_options">More options</string>
<string name="alt_track_info">Information about track</string>
<string name="go_to_artist">Go to artist</string>
<string name="go_to_album">Go to album</string>
<string name="track_info_artist">Go to artist</string>
<string name="track_info_album">Go to album</string>
<string name="track_info_details">Information</string>
<string name="track_info_details_title">Track details</string>
<string name="track_info_details_artist">Artist</string>
<string name="track_info_details_album">Album</string>
<string name="track_info_details_track_title">Track title</string>
<string name="track_info_details_track_duration">Duration</string>
<string name="track_info_details_track_position">Album position</string>
<string name="track_info_details_track_bitrate">Bitrate</string>
<string name="track_info_details_track_instance">Funkwhale instance</string>
<string name="logout_title">Sign out</string>
<string name="logout_content">Are you sure you want to sign out of your Funkwhale instance?</string>

8
app/src/main/res/values/styles.xml

@ -78,4 +78,12 @@ @@ -78,4 +78,12 @@
<item name="android:background">@android:color/transparent</item>
</style>
<style name="AppTheme.TrackDetailsLabel" parent="TextAppearance.MaterialComponents.Overline">
<item name="android:textSize">12sp</item>
</style>
<style name="AppTheme.TrackDetailsValue">
<item name="android:textSize">16sp</item>
</style>
</resources>

Loading…
Cancel
Save