Browse Source

Fixed some linting issues. Fixed two issues related to current track emphasis and landscape now playing cover background.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
cb43615cb1
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 3
      app/build.gradle.kts
  2. 4
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  3. 4
      app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt
  4. 2
      app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt
  5. 16
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt
  6. 6
      app/src/main/java/com/github/apognu/otter/fragments/ArtistsFragment.kt
  7. 19
      app/src/main/java/com/github/apognu/otter/fragments/FavoritesFragment.kt
  8. 1
      app/src/main/java/com/github/apognu/otter/fragments/LandscapeQueueFragment.kt
  9. 19
      app/src/main/java/com/github/apognu/otter/fragments/PlaylistTracksFragment.kt
  10. 1
      app/src/main/java/com/github/apognu/otter/fragments/QueueFragment.kt
  11. 19
      app/src/main/java/com/github/apognu/otter/fragments/TracksFragment.kt
  12. 8
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  13. 4
      app/src/main/java/com/github/apognu/otter/playback/QueueManager.kt
  14. 6
      app/src/main/java/com/github/apognu/otter/utils/Extensions.kt
  15. 4
      app/src/main/java/com/github/apognu/otter/views/NowPlayingView.kt
  16. 4
      app/src/main/res/layout-land/partial_now_playing.xml
  17. 1
      app/src/main/res/layout/row_radio.xml
  18. 11
      app/src/main/res/values-fr/strings.xml
  19. 1
      app/src/main/res/values/colors.xml
  20. 9
      app/src/main/res/values/strings.xml

3
app/build.gradle.kts

@ -15,8 +15,7 @@ plugins { @@ -15,8 +15,7 @@ plugins {
}
val props = Properties().apply {
try { load(FileInputStream(rootProject.file("local.properties"))) }
catch(e: Exception) {}
try { load(FileInputStream(rootProject.file("local.properties"))) } catch (e: Exception) {}
}
androidGitVersion {

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

@ -288,7 +288,7 @@ class MainActivity : AppCompatActivity() { @@ -288,7 +288,7 @@ class MainActivity : AppCompatActivity() {
}
private fun refreshCurrentTrack(track: Track?) {
track?.let { track ->
track?.let {
if (now_playing.visibility == View.GONE) {
now_playing.visibility = View.VISIBLE
now_playing.alpha = 0f
@ -455,7 +455,7 @@ class MainActivity : AppCompatActivity() { @@ -455,7 +455,7 @@ class MainActivity : AppCompatActivity() {
}
private fun incrementListenCount(track: Track?) {
track?.let { track ->
track?.let {
GlobalScope.launch(IO) {
Fuel
.post(mustNormalizeUrl("/api/v1/history/listenings/"))

4
app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt

@ -42,10 +42,10 @@ class SearchActivity : AppCompatActivity() { @@ -42,10 +42,10 @@ class SearchActivity : AppCompatActivity() {
search.requestFocus()
search.setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
override fun onQueryTextSubmit(rawQuery: String?): Boolean {
search.clearFocus()
query?.let {
rawQuery?.let {
val query = URLEncoder.encode(it, "UTF-8")
tracksRepository = TracksSearchRepository(this@SearchActivity, query.toLowerCase(Locale.ROOT))

2
app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt

@ -33,7 +33,7 @@ class PlaylistsAdapter(val context: Context?, private val listener: OnPlaylistCl @@ -33,7 +33,7 @@ class PlaylistsAdapter(val context: Context?, private val listener: OnPlaylistCl
val playlist = data[position]
holder.name.text = playlist.name
holder.summary.text = context?.getString(R.string.playlist_description, playlist.tracks_count, toDurationString(playlist.duration.toLong())) ?: ""
holder.summary.text = context?.resources?.getQuantityString(R.plurals.playlist_description, playlist.tracks_count, playlist.tracks_count, toDurationString(playlist.duration.toLong())) ?: ""
playlist.album_covers.shuffled().take(4).forEachIndexed { index, url ->
val imageView = when (index) {

16
app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt

@ -35,8 +35,8 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -35,8 +35,8 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
var artistArt = ""
companion object {
fun new(artist: Artist, art: String? = null): AlbumsFragment {
val art = art ?: if (artist.albums?.isNotEmpty() == true) artist.albums[0].cover.original else ""
fun new(artist: Artist, _art: String? = null): AlbumsFragment {
val art = _art ?: if (artist.albums?.isNotEmpty() == true) artist.albums[0].cover.original else ""
return AlbumsFragment().apply {
arguments = bundleOf(
@ -48,7 +48,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -48,7 +48,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
}
fun openTracks(context: Context?, album: Album, fragment: Fragment? = null) {
(context as? MainActivity)?.let { activity ->
(context as? MainActivity)?.let {
fragment?.let { fragment ->
fragment.onViewPager {
exitTransition = Fade().apply {
@ -64,7 +64,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -64,7 +64,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
}
(context as? AppCompatActivity)?.let { activity ->
val fragment = TracksFragment.new(album).apply {
val nextFragment = TracksFragment.new(album).apply {
enterTransition = Slide().apply {
duration = AppContext.TRANSITION_DURATION
interpolator = AccelerateDecelerateInterpolator()
@ -73,7 +73,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -73,7 +73,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
activity.supportFragmentManager
.beginTransaction()
.replace(R.id.container, fragment)
.replace(R.id.container, nextFragment)
.addToBackStack(null)
.commit()
}
@ -105,7 +105,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -105,7 +105,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
.into(cover)
}
cover_background?.let {
cover_background?.let { background ->
activity?.let { activity ->
GlobalScope.launch(Dispatchers.IO) {
val width = DisplayMetrics().apply {
@ -116,14 +116,14 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -116,14 +116,14 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
.maybeLoad(maybeNormalizeUrl(artistArt))
.get()
.run { Bitmap.createScaledBitmap(this, width, width, false) }
.run { Bitmap.createBitmap(this, 0, 0, width, cover_background.height).toDrawable(resources) }
.run { Bitmap.createBitmap(this, 0, 0, width, background.height).toDrawable(resources) }
.apply {
alpha = 20
gravity = Gravity.CENTER
}
withContext(Dispatchers.Main) {
cover_background.background = backgroundCover
background.background = backgroundCover
}
}
}

6
app/src/main/java/com/github/apognu/otter/fragments/ArtistsFragment.kt

@ -24,7 +24,7 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() { @@ -24,7 +24,7 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() {
companion object {
fun openAlbums(context: Context?, artist: Artist, fragment: Fragment? = null, art: String? = null) {
(context as? MainActivity)?.let { activity ->
(context as? MainActivity)?.let {
fragment?.let { fragment ->
fragment.onViewPager {
exitTransition = Fade().apply {
@ -40,7 +40,7 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() { @@ -40,7 +40,7 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() {
}
(context as? AppCompatActivity)?.let { activity ->
val fragment = AlbumsFragment.new(artist, art).apply {
val nextFragment = AlbumsFragment.new(artist, art).apply {
enterTransition = Slide().apply {
duration = AppContext.TRANSITION_DURATION
interpolator = AccelerateDecelerateInterpolator()
@ -49,7 +49,7 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() { @@ -49,7 +49,7 @@ class ArtistsFragment : FunkwhaleFragment<Artist, ArtistsAdapter>() {
activity.supportFragmentManager
.beginTransaction()
.replace(R.id.container, fragment)
.replace(R.id.container, nextFragment)
.addToBackStack(null)
.commit()
}

19
app/src/main/java/com/github/apognu/otter/fragments/FavoritesFragment.kt

@ -44,19 +44,22 @@ class FavoritesFragment : FunkwhaleFragment<Track, FavoritesAdapter>() { @@ -44,19 +44,22 @@ class FavoritesFragment : FunkwhaleFragment<Track, FavoritesAdapter>() {
GlobalScope.launch(Main) {
EventBus.get().collect { message ->
when (message) {
is Event.TrackPlayed -> {
GlobalScope.launch(Main) {
RequestBus.send(Request.GetCurrentTrack).wait<Response.CurrentTrack>()?.let { response ->
adapter.currentTrack = response.track
adapter.notifyDataSetChanged()
}
}
}
is Event.TrackPlayed -> refreshCurrentTrack()
is Event.RefreshTrack -> refreshCurrentTrack()
}
}
}
}
private fun refreshCurrentTrack() {
GlobalScope.launch(Main) {
RequestBus.send(Request.GetCurrentTrack).wait<Response.CurrentTrack>()?.let { response ->
adapter.currentTrack = response.track
adapter.notifyDataSetChanged()
}
}
}
inner class FavoriteListener : FavoritesAdapter.OnFavoriteListener {
override fun onToggleFavorite(id: Int, state: Boolean) {
(repository as? FavoritesRepository)?.let { repository ->

1
app/src/main/java/com/github/apognu/otter/fragments/LandscapeQueueFragment.kt

@ -67,6 +67,7 @@ class LandscapeQueueFragment : Fragment() { @@ -67,6 +67,7 @@ class LandscapeQueueFragment : Fragment() {
EventBus.get().collect { message ->
when (message) {
is Event.TrackPlayed -> refresh()
is Event.RefreshTrack -> refresh()
is Event.QueueChanged -> refresh()
}
}

19
app/src/main/java/com/github/apognu/otter/fragments/PlaylistTracksFragment.kt

@ -114,19 +114,22 @@ class PlaylistTracksFragment : FunkwhaleFragment<PlaylistTrack, PlaylistTracksAd @@ -114,19 +114,22 @@ class PlaylistTracksFragment : FunkwhaleFragment<PlaylistTrack, PlaylistTracksAd
GlobalScope.launch(Main) {
EventBus.get().collect { message ->
when (message) {
is Event.TrackPlayed -> {
GlobalScope.launch(Main) {
RequestBus.send(Request.GetCurrentTrack).wait<Response.CurrentTrack>()?.let { response ->
adapter.currentTrack = response.track
adapter.notifyDataSetChanged()
}
}
}
is Event.TrackPlayed -> refreshCurrentTrack()
is Event.RefreshTrack -> refreshCurrentTrack()
}
}
}
}
private fun refreshCurrentTrack() {
GlobalScope.launch(Main) {
RequestBus.send(Request.GetCurrentTrack).wait<Response.CurrentTrack>()?.let { response ->
adapter.currentTrack = response.track
adapter.notifyDataSetChanged()
}
}
}
inner class FavoriteListener : PlaylistTracksAdapter.OnFavoriteListener {
override fun onToggleFavorite(id: Int, state: Boolean) {
when (state) {

1
app/src/main/java/com/github/apognu/otter/fragments/QueueFragment.kt

@ -91,6 +91,7 @@ class QueueFragment : BottomSheetDialogFragment() { @@ -91,6 +91,7 @@ class QueueFragment : BottomSheetDialogFragment() {
EventBus.get().collect { message ->
when (message) {
is Event.TrackPlayed -> refresh()
is Event.RefreshTrack -> refresh()
is Event.QueueChanged -> refresh()
}
}

19
app/src/main/java/com/github/apognu/otter/fragments/TracksFragment.kt

@ -98,19 +98,22 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() { @@ -98,19 +98,22 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() {
GlobalScope.launch(Main) {
EventBus.get().collect { message ->
when (message) {
is Event.TrackPlayed -> {
GlobalScope.launch(Main) {
RequestBus.send(Request.GetCurrentTrack).wait<Response.CurrentTrack>()?.let { response ->
adapter.currentTrack = response.track
adapter.notifyDataSetChanged()
}
}
}
is Event.TrackPlayed -> refreshCurrentTrack()
is Event.RefreshTrack -> refreshCurrentTrack()
}
}
}
}
private fun refreshCurrentTrack() {
GlobalScope.launch(Main) {
RequestBus.send(Request.GetCurrentTrack).wait<Response.CurrentTrack>()?.let { response ->
adapter.currentTrack = response.track
adapter.notifyDataSetChanged()
}
}
}
inner class FavoriteListener : TracksAdapter.OnFavoriteListener {
override fun onToggleFavorite(id: Int, state: Boolean) {
when (state) {

8
app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt

@ -163,7 +163,7 @@ class PlayerService : Service() { @@ -163,7 +163,7 @@ class PlayerService : Service() {
state(true)
EventBus.send(Event.RefreshTrack(queue.current(),true))
EventBus.send(Event.RefreshTrack(queue.current(), true))
}
is Command.ToggleState -> toggle()
@ -259,7 +259,7 @@ class PlayerService : Service() { @@ -259,7 +259,7 @@ class PlayerService : Service() {
if (!state) {
val (progress, _, _) = progress()
Cache.set(this@PlayerService,"progress", progress.toString().toByteArray())
Cache.set(this@PlayerService, "progress", progress.toString().toByteArray())
}
if (state && player.playbackState == Player.STATE_IDLE) {
@ -380,9 +380,9 @@ class PlayerService : Service() { @@ -380,9 +380,9 @@ class PlayerService : Service() {
}
}
Cache.set(this@PlayerService,"current", queue.current.toString().toByteArray() )
Cache.set(this@PlayerService, "current", queue.current.toString().toByteArray())
EventBus.send(Event.RefreshTrack(queue.current(),true) )
EventBus.send(Event.RefreshTrack(queue.current(), true))
}
override fun onPositionDiscontinuity(reason: Int) {

4
app/src/main/java/com/github/apognu/otter/playback/QueueManager.kt

@ -88,9 +88,9 @@ class QueueManager(val context: Context) { @@ -88,9 +88,9 @@ class QueueManager(val context: Context) {
fun append(tracks: List<Track>) {
val factory = factory()
val tracks = tracks.filter { metadata.indexOf(it) == -1 }
val missingTracks = tracks.filter { metadata.indexOf(it) == -1 }
val sources = tracks.map { track ->
val sources = missingTracks.map { track ->
val url = mustNormalizeUrl(track.bestUpload()?.listen_url ?: "")
ProgressiveMediaSource.Factory(factory).createMediaSource(Uri.parse(url))

6
app/src/main/java/com/github/apognu/otter/utils/Extensions.kt

@ -1,8 +1,6 @@ @@ -1,8 +1,6 @@
package com.github.apognu.otter.utils
import android.content.Context
import android.os.Build
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import com.github.apognu.otter.R
import com.github.apognu.otter.fragments.BrowseFragment
@ -17,10 +15,6 @@ import kotlinx.coroutines.flow.collect @@ -17,10 +15,6 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import kotlin.coroutines.CoroutineContext
fun Context.getColor(colorRes: Int): Int {
return ContextCompat.getColor(this, colorRes)
}
inline fun <D> Flow<Repository.Response<D>>.untilNetwork(context: CoroutineContext = Main, crossinline callback: (data: List<D>, isCache: Boolean, hasMore: Boolean) -> Unit) {
GlobalScope.launch(context) {
collect { data ->

4
app/src/main/java/com/github/apognu/otter/views/NowPlayingView.kt

@ -52,7 +52,7 @@ class NowPlayingView : MaterialCardView { @@ -52,7 +52,7 @@ class NowPlayingView : MaterialCardView {
if (motionEvent.actionMasked == MotionEvent.ACTION_UP) {
if (gestureDetectorCallback?.isScrolling == true) {
gestureDetectorCallback?.onUp(motionEvent)
gestureDetectorCallback?.onUp()
}
}
@ -105,7 +105,7 @@ class NowPlayingView : MaterialCardView { @@ -105,7 +105,7 @@ class NowPlayingView : MaterialCardView {
return true
}
fun onUp(event: MotionEvent): Boolean {
fun onUp(): Boolean {
isScrolling = false
layoutParams.let {

4
app/src/main/res/layout-land/partial_now_playing.xml

@ -97,8 +97,8 @@ @@ -97,8 +97,8 @@
android:id="@+id/now_playing_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:orientation="vertical"
android:paddingTop="16dp">

1
app/src/main/res/layout/row_radio.xml

@ -18,6 +18,7 @@ @@ -18,6 +18,7 @@
android:layout_width="48dp"
android:layout_height="32dp"
android:layout_marginEnd="16dp"
android:contentDescription="@string/alt_album_cover"
android:scaleType="fitCenter"
android:src="@drawable/cover"
android:visibility="gone"

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

@ -1,7 +1,5 @@ @@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Otter</string>
<string name="login_welcome">Veuillez saisir les détails de votre instance Funkwhale pour accéder à son contenu</string>
<string name="login_hostname">Nom d\'hôte</string>
<string name="login_anonymous">Authentification anonyme</string>
@ -13,7 +11,6 @@ @@ -13,7 +11,6 @@
<string name="login_error_hostname">Cela ne semble pas être un nom d\hôte valide</string>
<string name="login_error_hostname_https">Le nom d\'hôte Funkwhale devrait être sécurisé à travers HTTPS</string>
<string name="toolbar_cast">Cast</string>
<string name="toolbar_search">Rechercher</string>
<string name="title_settings">Paramètres</string>
@ -48,7 +45,7 @@ @@ -48,7 +45,7 @@
<string name="settings_information_repository_description">Otter par Antoine POPINEAU (apognu)</string>
<string name="settings_version_title">Version</string>
<string name="settings_information_license_title">Licence</string>
<string name="settings_information_license_description">MIT license</string>
<string name="settings_information_license_description">Licence MIT</string>
<string name="settings_logout">Déconnexion</string>
<string name="artists">Artistes</string>
@ -67,7 +64,6 @@ @@ -67,7 +64,6 @@
<string name="playback_queue_add_item">Ajouter à la liste de lecture</string>
<string name="playback_queue_play_next">Prochaine écoute</string>
<string name="manage_add_to_playlist">Ajouter à une playlist</string>
<string name="manage_add_to_favorites">Add to favorites</string>
<string name="control_toggle">Lecture / pause</string>
@ -109,5 +105,8 @@ @@ -109,5 +105,8 @@
<string name="logout_title">Déconnexion</string>
<string name="logout_content">Etes-vous certains de vouloir vous déconnecter de votre instance Funkwhale ?</string>
<string name="playlist_description">%d tracks • %s"</string>
<plurals name="playlist_description">
<item quantity="one">%1$d pistes • %2$s"</item>
<item quantity="other">%1$d pistes • %2$s"</item>
</plurals>
</resources>

1
app/src/main/res/values/colors.xml

@ -1,6 +1,5 @@ @@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="surfaceAccent">@android:color/background_light</color>
<color name="surface">@android:color/background_light</color>
<color name="colorPrimary">#327eae</color>

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

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Otter</string>
<string name="app_name" translatable="false">Otter</string>
<string name="login_welcome">Please enter the details of your Funkwhale instance to access its content</string>
<string name="login_hostname">Host name</string>
@ -13,7 +13,6 @@ @@ -13,7 +13,6 @@
<string name="login_error_hostname">This could not be understood as a valid URL</string>
<string name="login_error_hostname_https">The Funkwhale hostname should be secure through HTTPS</string>
<string name="toolbar_cast">Cast</string>
<string name="toolbar_search">Search</string>
<string name="title_settings">Settings</string>
@ -67,7 +66,6 @@ @@ -67,7 +66,6 @@
<string name="playback_queue_add_item">Add to queue</string>
<string name="playback_queue_play_next">Play next</string>
<string name="manage_add_to_playlist">Add to playlist</string>
<string name="manage_add_to_favorites">Ajouter aux favoris</string>
<string name="control_toggle">Toggle playback</string>
@ -109,5 +107,8 @@ @@ -109,5 +107,8 @@
<string name="logout_title">Sign out</string>
<string name="logout_content">Are you sure you want to sign out of your Funkwhale instance?</string>
<string name="playlist_description">%d tracks • %s"</string>
<plurals name="playlist_description">
<item quantity="one">%1$d track • %2$s"</item>
<item quantity="other">%1$d tracks • %2$s"</item>
</plurals>
</resources>

Loading…
Cancel
Save