From 0b14415e1ed51bdaf26eeac7ca23faa7c68f711b Mon Sep 17 00:00:00 2001 From: Antoine POPINEAU Date: Mon, 21 Oct 2019 19:49:48 +0200 Subject: [PATCH] Linting. --- .../apognu/otter/activities/MainActivity.kt | 8 ++-- .../apognu/otter/activities/SearchActivity.kt | 3 +- .../apognu/otter/adapters/FavoritesAdapter.kt | 4 +- .../apognu/otter/adapters/PlaylistsAdapter.kt | 3 +- .../apognu/otter/adapters/TracksAdapter.kt | 5 +- .../github/apognu/otter/utils/Extensions.kt | 6 +++ .../com/github/apognu/otter/utils/Util.kt | 14 ++++++ app/src/main/res/layout/activity_licences.xml | 6 ++- app/src/main/res/layout/activity_login.xml | 10 ++-- app/src/main/res/layout/activity_search.xml | 6 ++- app/src/main/res/layout/activity_settings.xml | 6 ++- app/src/main/res/layout/fragment_albums.xml | 47 +++++++++---------- .../main/res/layout/fragment_albums_grid.xml | 6 ++- app/src/main/res/layout/fragment_artists.xml | 13 ++--- .../main/res/layout/fragment_favorites.xml | 3 +- .../main/res/layout/fragment_playlists.xml | 6 ++- app/src/main/res/layout/fragment_queue.xml | 6 ++- app/src/main/res/layout/fragment_tracks.xml | 9 ++-- .../main/res/layout/partial_now_playing.xml | 3 +- app/src/main/res/layout/row_album.xml | 6 ++- app/src/main/res/layout/row_artist.xml | 6 ++- app/src/main/res/layout/row_playlist.xml | 6 ++- app/src/main/res/layout/row_track.xml | 7 ++- app/src/main/res/values-fr/strings.xml | 3 ++ app/src/main/res/values/strings.xml | 3 ++ 25 files changed, 121 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt b/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt index 427373b..3c66ee4 100644 --- a/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt +++ b/app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt @@ -241,8 +241,8 @@ class MainActivity : AppCompatActivity() { track.favorite = favorites.contains(track.id) when (track.favorite) { - true -> now_playing_details_favorite.setColorFilter(resources.getColor(R.color.colorFavorite)) - false -> now_playing_details_favorite.setColorFilter(resources.getColor(R.color.controlForeground)) + true -> now_playing_details_favorite.setColorFilter(getColor(R.color.colorFavorite)) + false -> now_playing_details_favorite.setColorFilter(getColor(R.color.controlForeground)) } } } @@ -251,12 +251,12 @@ class MainActivity : AppCompatActivity() { when (track.favorite) { true -> { favoriteRepository.deleteFavorite(track.id) - now_playing_details_favorite.setColorFilter(resources.getColor(R.color.controlForeground)) + now_playing_details_favorite.setColorFilter(getColor(R.color.controlForeground)) } false -> { favoriteRepository.addFavorite(track.id) - now_playing_details_favorite.setColorFilter(resources.getColor(R.color.colorFavorite)) + now_playing_details_favorite.setColorFilter(getColor(R.color.colorFavorite)) } } diff --git a/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt b/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt index c7fd556..2616748 100644 --- a/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt +++ b/app/src/main/java/com/github/apognu/otter/activities/SearchActivity.kt @@ -10,6 +10,7 @@ import com.github.apognu.otter.repositories.Repository import com.github.apognu.otter.repositories.SearchRepository import com.github.apognu.otter.utils.untilNetwork import kotlinx.android.synthetic.main.activity_search.* +import java.util.* class SearchActivity : AppCompatActivity() { private lateinit var adapter: TracksAdapter @@ -35,7 +36,7 @@ class SearchActivity : AppCompatActivity() { search.setOnQueryTextListener(object : androidx.appcompat.widget.SearchView.OnQueryTextListener { override fun onQueryTextSubmit(query: String?): Boolean { query?.let { - repository = SearchRepository(this@SearchActivity, it.toLowerCase()) + repository = SearchRepository(this@SearchActivity, it.toLowerCase(Locale.ROOT)) search_spinner.visibility = View.VISIBLE search_no_results.visibility = View.GONE diff --git a/app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt b/app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt index 5c0af21..a82b3b1 100644 --- a/app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt +++ b/app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt @@ -71,8 +71,8 @@ class FavoritesAdapter(private val context: Context?, private val favoriteListen context?.let { when (favorite.track.favorite) { - true -> holder.favorite.setColorFilter(context.resources.getColor(R.color.colorFavorite)) - false -> holder.favorite.setColorFilter(context.resources.getColor(R.color.colorSelected)) + true -> holder.favorite.setColorFilter(context.getColor(R.color.colorFavorite)) + false -> holder.favorite.setColorFilter(context.getColor(R.color.colorSelected)) } holder.favorite.setOnClickListener { diff --git a/app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt b/app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt index 7e22931..b17fc50 100644 --- a/app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt +++ b/app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt @@ -8,6 +8,7 @@ import androidx.recyclerview.widget.RecyclerView import com.github.apognu.otter.R import com.github.apognu.otter.fragments.FunkwhaleAdapter import com.github.apognu.otter.utils.Playlist +import com.github.apognu.otter.utils.toDurationString import com.squareup.picasso.Picasso import kotlinx.android.synthetic.main.row_playlist.view.* @@ -32,7 +33,7 @@ class PlaylistsAdapter(val context: Context?, private val listener: OnPlaylistCl val playlist = data[position] holder.name.text = playlist.name - holder.summary.text = "${playlist.tracks_count} tracks • ${playlist.duration} seconds" + holder.summary.text = context?.getString(R.string.playlist_description, playlist.tracks_count, toDurationString(playlist.duration.toLong())) ?: "" playlist.album_covers.shuffled().take(4).forEachIndexed { index, url -> val imageView = when (index) { diff --git a/app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt b/app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt index 432a7ec..ef23f89 100644 --- a/app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt +++ b/app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt @@ -184,13 +184,10 @@ class TracksAdapter(private val context: Context?, private val favoriteListener: override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {} - @SuppressLint("NewApi") override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) { if (actionState == ItemTouchHelper.ACTION_STATE_DRAG) { context?.let { - Build.VERSION_CODES.M.onApi( - { viewHolder?.itemView?.background = ColorDrawable(context.resources.getColor(R.color.colorSelected, null)) }, - { viewHolder?.itemView?.background = ColorDrawable(context.resources.getColor(R.color.colorSelected)) }) + viewHolder?.itemView?.background = ColorDrawable(context.getColor(R.color.colorSelected)) } } diff --git a/app/src/main/java/com/github/apognu/otter/utils/Extensions.kt b/app/src/main/java/com/github/apognu/otter/utils/Extensions.kt index c99dc23..29ae82f 100644 --- a/app/src/main/java/com/github/apognu/otter/utils/Extensions.kt +++ b/app/src/main/java/com/github/apognu/otter/utils/Extensions.kt @@ -1,6 +1,8 @@ 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.fragments.BrowseFragment import com.github.apognu.otter.repositories.Repository @@ -10,6 +12,10 @@ import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.launch import kotlin.coroutines.CoroutineContext +fun Context.getColor(colorRes: Int): Int { + return ContextCompat.getColor(this, colorRes) +} + inline fun Channel>.await(context: CoroutineContext = Main, crossinline callback: (data: List) -> Unit) { GlobalScope.launch(context) { this@await.receive().also { diff --git a/app/src/main/java/com/github/apognu/otter/utils/Util.kt b/app/src/main/java/com/github/apognu/otter/utils/Util.kt index ba40f9e..57e12a8 100644 --- a/app/src/main/java/com/github/apognu/otter/utils/Util.kt +++ b/app/src/main/java/com/github/apognu/otter/utils/Util.kt @@ -24,3 +24,17 @@ fun normalizeUrl(url: String): String { URI("https", host, path, query, null) }.toString() } + +fun toDurationString(seconds: Long): String { + val days = (seconds / 86400) + val hours = (seconds % 86400) / 3600 + val minutes = (seconds % 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") + + return ret.toString() +} \ No newline at end of file diff --git a/app/src/main/res/layout/activity_licences.xml b/app/src/main/res/layout/activity_licences.xml index 52bfd76..e0ca964 100644 --- a/app/src/main/res/layout/activity_licences.xml +++ b/app/src/main/res/layout/activity_licences.xml @@ -15,8 +15,10 @@ style="@style/AppTheme.Title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" - android:layout_marginVertical="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" android:text="@string/title_oss_licences" /> + android:text="@string/login_submit" + android:textColor="@android:color/white" /> diff --git a/app/src/main/res/layout/activity_search.xml b/app/src/main/res/layout/activity_search.xml index 454acda..c19bbbd 100644 --- a/app/src/main/res/layout/activity_search.xml +++ b/app/src/main/res/layout/activity_search.xml @@ -35,8 +35,9 @@ android:id="@+id/search_empty" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" + android:layout_marginStart="16dp" android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" android:drawableTop="@drawable/ottericon" android:drawablePadding="16dp" android:drawableTint="#525252" @@ -48,8 +49,9 @@ android:id="@+id/search_no_results" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" + android:layout_marginStart="16dp" android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" android:drawableTop="@drawable/ottericon" android:drawablePadding="16dp" android:drawableTint="#525252" diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 8cdb7b6..d256dd7 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -9,8 +9,10 @@ style="@style/AppTheme.Title" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" - android:layout_marginVertical="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" android:text="@string/title_settings" /> + android:orientation="vertical"> - + + - - - - - - + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" + tools:text="Muse" /> diff --git a/app/src/main/res/layout/fragment_albums_grid.xml b/app/src/main/res/layout/fragment_albums_grid.xml index 019b2b4..cfdb690 100644 --- a/app/src/main/res/layout/fragment_albums_grid.xml +++ b/app/src/main/res/layout/fragment_albums_grid.xml @@ -25,8 +25,10 @@ style="@style/AppTheme.Title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" - android:layout_marginVertical="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" android:text="@string/albums" /> - + android:clipToPadding="false"> diff --git a/app/src/main/res/layout/fragment_playlists.xml b/app/src/main/res/layout/fragment_playlists.xml index b85c10c..74046c4 100644 --- a/app/src/main/res/layout/fragment_playlists.xml +++ b/app/src/main/res/layout/fragment_playlists.xml @@ -27,8 +27,10 @@ style="@style/AppTheme.Title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" - android:layout_marginVertical="16dp" + android:layout_marginStart="16dp" + android:layout_marginTop="16dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="16dp" android:text="@string/playlists" /> @@ -170,7 +171,8 @@ style="@style/AppTheme.Title" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="16dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" android:layout_marginBottom="16dp" tools:text="Absolution" /> @@ -182,7 +184,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginHorizontal="16dp" + android:layout_marginStart="16dp" + android:layout_marginEnd="16dp" android:text="@string/playback_queue" app:icon="@drawable/add" /> diff --git a/app/src/main/res/layout/partial_now_playing.xml b/app/src/main/res/layout/partial_now_playing.xml index 8a34c4d..e48cb61 100644 --- a/app/src/main/res/layout/partial_now_playing.xml +++ b/app/src/main/res/layout/partial_now_playing.xml @@ -126,7 +126,8 @@ android:id="@+id/now_playing_details_controls" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginHorizontal="32dp" + android:layout_marginStart="32dp" + android:layout_marginEnd="32dp" android:orientation="vertical" android:paddingTop="32dp"> diff --git a/app/src/main/res/layout/row_album.xml b/app/src/main/res/layout/row_album.xml index 01b5b96..01ca7c1 100644 --- a/app/src/main/res/layout/row_album.xml +++ b/app/src/main/res/layout/row_album.xml @@ -3,11 +3,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginTop="12dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="12dp" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" - android:paddingHorizontal="16dp" - android:paddingVertical="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_albums"> diff --git a/app/src/main/res/layout/row_artist.xml b/app/src/main/res/layout/row_artist.xml index 028a9e6..16cf2f1 100644 --- a/app/src/main/res/layout/row_artist.xml +++ b/app/src/main/res/layout/row_artist.xml @@ -3,11 +3,13 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginTop="12dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="12dp" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" - android:paddingHorizontal="16dp" - android:paddingVertical="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_artists"> diff --git a/app/src/main/res/layout/row_playlist.xml b/app/src/main/res/layout/row_playlist.xml index f59f6f9..70fd08c 100644 --- a/app/src/main/res/layout/row_playlist.xml +++ b/app/src/main/res/layout/row_playlist.xml @@ -4,10 +4,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_marginStart="16dp" + android:layout_marginTop="12dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="12dp" android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" - android:paddingHorizontal="16dp" - android:paddingVertical="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_playlists"> diff --git a/app/src/main/res/layout/row_track.xml b/app/src/main/res/layout/row_track.xml index 712e0d3..7bb6177 100644 --- a/app/src/main/res/layout/row_track.xml +++ b/app/src/main/res/layout/row_track.xml @@ -6,8 +6,10 @@ android:background="?android:attr/selectableItemBackground" android:gravity="center_vertical" android:orientation="horizontal" - android:paddingHorizontal="16dp" - android:paddingVertical="12dp" + android:layout_marginStart="16dp" + android:layout_marginTop="12dp" + android:layout_marginEnd="16dp" + android:layout_marginBottom="12dp" android:transitionGroup="true" tools:showIn="@layout/fragment_tracks"> @@ -67,6 +69,7 @@ style="@style/IconButton" android:layout_width="48dp" android:layout_height="48dp" + android:contentDescription="@string/alt_more_options" android:src="@drawable/more" /> \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 586bd8e..c70d8e8 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -71,7 +71,10 @@ Logo de l\'application Image de l\'artiste Couverture de l\'album + Plus d\'options Déconnexion Etes-vous certains de vouloir vous déconnecter de votre instance Funkwhale ? + + %d tracks • %s" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5269a06..7b985dd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -71,7 +71,10 @@ Application logo Artist art Album cover + More options Sign out Are you sure you want to sign out of your Funkwhale instance? + + %d tracks • %s"