Browse Source

Misc refactoring.

housekeeping/remove-warnings
Antoine POPINEAU 5 years ago
parent
commit
31063fb40f
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 1
      app/src/main/java/com/github/apognu/otter/activities/LoginActivity.kt
  2. 2
      app/src/main/java/com/github/apognu/otter/adapters/AlbumsAdapter.kt
  3. 4
      app/src/main/java/com/github/apognu/otter/adapters/AlbumsGridAdapter.kt
  4. 4
      app/src/main/java/com/github/apognu/otter/adapters/ArtistsAdapter.kt
  5. 44
      app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt
  6. 2
      app/src/main/java/com/github/apognu/otter/adapters/PlaylistTracksAdapter.kt
  7. 4
      app/src/main/java/com/github/apognu/otter/adapters/PlaylistsAdapter.kt
  8. 32
      app/src/main/java/com/github/apognu/otter/adapters/SearchResultsAdapter.kt
  9. 4
      app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt
  10. 2
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsFragment.kt
  11. 2
      app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt
  12. 8
      app/src/main/java/com/github/apognu/otter/fragments/TracksFragment.kt
  13. 5
      app/src/main/java/com/github/apognu/otter/playback/MediaControlsManager.kt
  14. 3
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  15. 2
      app/src/main/java/com/github/apognu/otter/repositories/SearchRepository.kt
  16. 30
      app/src/main/java/com/github/apognu/otter/utils/Extensions.kt
  17. 2
      app/src/main/java/com/github/apognu/otter/views/ExplodeReveal.kt

1
app/src/main/java/com/github/apognu/otter/activities/LoginActivity.kt

@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity @@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity
import com.github.apognu.otter.R
import com.github.apognu.otter.fragments.LoginDialog
import com.github.apognu.otter.utils.AppContext
import com.github.apognu.otter.utils.log
import com.github.kittinunf.fuel.Fuel
import com.github.kittinunf.fuel.coroutines.awaitObjectResult
import com.github.kittinunf.fuel.gson.gsonDeserializerOf

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

@ -43,7 +43,7 @@ class AlbumsAdapter(val context: Context?, val listener: OnAlbumClickListener) : @@ -43,7 +43,7 @@ class AlbumsAdapter(val context: Context?, val listener: OnAlbumClickListener) :
holder.artist.text = album.artist.name
}
inner class ViewHolder(view: View, val listener: OnAlbumClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
inner class ViewHolder(view: View, private val listener: OnAlbumClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
val art = view.art
val title = view.title
val artist = view.artist

4
app/src/main/java/com/github/apognu/otter/adapters/AlbumsGridAdapter.kt

@ -13,7 +13,7 @@ import com.squareup.picasso.Picasso @@ -13,7 +13,7 @@ import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_album_grid.view.*
class AlbumsGridAdapter(val context: Context?, val listener: OnAlbumClickListener) : FunkwhaleAdapter<Album, AlbumsGridAdapter.ViewHolder>() {
class AlbumsGridAdapter(val context: Context?, private val listener: OnAlbumClickListener) : FunkwhaleAdapter<Album, AlbumsGridAdapter.ViewHolder>() {
interface OnAlbumClickListener {
fun onClick(view: View?, album: Album)
}
@ -41,7 +41,7 @@ class AlbumsGridAdapter(val context: Context?, val listener: OnAlbumClickListene @@ -41,7 +41,7 @@ class AlbumsGridAdapter(val context: Context?, val listener: OnAlbumClickListene
holder.title.text = album.title
}
inner class ViewHolder(view: View, val listener: OnAlbumClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
inner class ViewHolder(view: View, private val listener: OnAlbumClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
val cover = view.cover
val title = view.title

4
app/src/main/java/com/github/apognu/otter/adapters/ArtistsAdapter.kt

@ -13,7 +13,7 @@ import com.squareup.picasso.Picasso @@ -13,7 +13,7 @@ import com.squareup.picasso.Picasso
import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_artist.view.*
class ArtistsAdapter(val context: Context?, val listener: OnArtistClickListener) : FunkwhaleAdapter<Artist, ArtistsAdapter.ViewHolder>() {
class ArtistsAdapter(val context: Context?, private val listener: OnArtistClickListener) : FunkwhaleAdapter<Artist, ArtistsAdapter.ViewHolder>() {
interface OnArtistClickListener {
fun onClick(holder: View?, artist: Artist)
}
@ -53,7 +53,7 @@ class ArtistsAdapter(val context: Context?, val listener: OnArtistClickListener) @@ -53,7 +53,7 @@ class ArtistsAdapter(val context: Context?, val listener: OnArtistClickListener)
}
}
inner class ViewHolder(view: View, val listener: OnArtistClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
inner class ViewHolder(view: View, private val listener: OnArtistClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
val art = view.art
val name = view.name
val albums = view.albums

44
app/src/main/java/com/github/apognu/otter/adapters/FavoritesAdapter.kt

@ -2,16 +2,13 @@ package com.github.apognu.otter.adapters @@ -2,16 +2,13 @@ package com.github.apognu.otter.adapters
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.ColorDrawable
import android.os.Build
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.RecyclerView
import com.github.apognu.otter.R
import com.github.apognu.otter.fragments.FunkwhaleAdapter
@ -21,7 +18,7 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation @@ -21,7 +18,7 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_track.view.*
import java.util.*
class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFavoriteListener, val fromQueue: Boolean = false) : FunkwhaleAdapter<Favorite, FavoritesAdapter.ViewHolder>() {
class FavoritesAdapter(private val context: Context?, private val favoriteListener: OnFavoriteListener, val fromQueue: Boolean = false) : FunkwhaleAdapter<Favorite, FavoritesAdapter.ViewHolder>() {
interface OnFavoriteListener {
fun onToggleFavorite(id: Int, state: Boolean)
}
@ -109,7 +106,7 @@ class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFa @@ -109,7 +106,7 @@ class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFa
fun onItemMove(oldPosition: Int, newPosition: Int) {
if (oldPosition < newPosition) {
for (i in oldPosition.rangeTo(newPosition - 1)) {
for (i in oldPosition.until(newPosition)) {
Collections.swap(data, i, i + 1)
}
} else {
@ -123,7 +120,6 @@ class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFa @@ -123,7 +120,6 @@ class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFa
}
inner class ViewHolder(view: View, val context: Context?) : RecyclerView.ViewHolder(view), View.OnClickListener {
val handle = view.handle
val cover = view.cover
val title = view.title
val artist = view.artist
@ -144,40 +140,4 @@ class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFa @@ -144,40 +140,4 @@ class FavoritesAdapter(private val context: Context?, val favoriteListener: OnFa
}
}
}
inner class TouchHelperCallback : ItemTouchHelper.Callback() {
override fun isLongPressDragEnabled() = false
override fun isItemViewSwipeEnabled() = false
override fun getMovementFlags(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) =
makeMovementFlags(ItemTouchHelper.UP or ItemTouchHelper.DOWN, 0)
override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
onItemMove(viewHolder.adapterPosition, target.adapterPosition)
return true
}
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)) })
}
}
super.onSelectedChanged(viewHolder, actionState)
}
override fun clearView(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder) {
viewHolder.itemView.background = ColorDrawable(Color.TRANSPARENT)
super.clearView(recyclerView, viewHolder)
}
}
}

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

@ -112,7 +112,7 @@ class PlaylistTracksAdapter(private val context: Context?, val fromQueue: Boolea @@ -112,7 +112,7 @@ class PlaylistTracksAdapter(private val context: Context?, val fromQueue: Boolea
fun onItemMove(oldPosition: Int, newPosition: Int) {
if (oldPosition < newPosition) {
for (i in oldPosition.rangeTo(newPosition - 1)) {
for (i in oldPosition.until(newPosition)) {
Collections.swap(data, i, i + 1)
}
} else {

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

@ -11,7 +11,7 @@ import com.github.apognu.otter.utils.Playlist @@ -11,7 +11,7 @@ import com.github.apognu.otter.utils.Playlist
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.row_playlist.view.*
class PlaylistsAdapter(val context: Context?, val listener: OnPlaylistClickListener) : FunkwhaleAdapter<Playlist, PlaylistsAdapter.ViewHolder>() {
class PlaylistsAdapter(val context: Context?, private val listener: OnPlaylistClickListener) : FunkwhaleAdapter<Playlist, PlaylistsAdapter.ViewHolder>() {
interface OnPlaylistClickListener {
fun onClick(holder: View?, playlist: Playlist)
}
@ -49,7 +49,7 @@ class PlaylistsAdapter(val context: Context?, val listener: OnPlaylistClickListe @@ -49,7 +49,7 @@ class PlaylistsAdapter(val context: Context?, val listener: OnPlaylistClickListe
}
}
inner class ViewHolder(view: View, val listener: OnPlaylistClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
inner class ViewHolder(view: View, private val listener: OnPlaylistClickListener) : RecyclerView.ViewHolder(view), View.OnClickListener {
val name = view.name
val summary = view.summary

32
app/src/main/java/com/github/apognu/otter/adapters/SearchResultsAdapter.kt

@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
package com.github.apognu.otter.adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.github.apognu.otter.R
import com.github.apognu.otter.utils.Track
import kotlinx.android.synthetic.main.row_track.view.*
class SearchResultsAdapter(val context: Context?) : RecyclerView.Adapter<SearchResultsAdapter.ViewHolder>() {
var tracks: List<Track> = listOf()
override fun getItemCount() = tracks.size
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.row_track, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val artist = tracks[position]
holder.title.text = artist.title
}
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val title = view.title
}
}

4
app/src/main/java/com/github/apognu/otter/adapters/TracksAdapter.kt

@ -18,7 +18,7 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation @@ -18,7 +18,7 @@ import jp.wasabeef.picasso.transformations.RoundedCornersTransformation
import kotlinx.android.synthetic.main.row_track.view.*
import java.util.*
class TracksAdapter(private val context: Context?, val favoriteListener: OnFavoriteListener? = null, val fromQueue: Boolean = false) : FunkwhaleAdapter<Track, TracksAdapter.ViewHolder>() {
class TracksAdapter(private val context: Context?, private val favoriteListener: OnFavoriteListener? = null, val fromQueue: Boolean = false) : FunkwhaleAdapter<Track, TracksAdapter.ViewHolder>() {
interface OnFavoriteListener {
fun onToggleFavorite(id: Int, state: Boolean)
}
@ -132,7 +132,7 @@ class TracksAdapter(private val context: Context?, val favoriteListener: OnFavor @@ -132,7 +132,7 @@ class TracksAdapter(private val context: Context?, val favoriteListener: OnFavor
fun onItemMove(oldPosition: Int, newPosition: Int) {
if (oldPosition < newPosition) {
for (i in oldPosition.rangeTo(newPosition - 1)) {
for (i in oldPosition.until(newPosition)) {
Collections.swap(data, i, i + 1)
}
} else {

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

@ -64,7 +64,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() { @@ -64,7 +64,7 @@ class AlbumsFragment : FunkwhaleFragment<Album, AlbumsAdapter>() {
}
inner class OnAlbumClickListener : AlbumsAdapter.OnAlbumClickListener {
override fun onClick(holder: View?, album: Album) {
override fun onClick(view: View?, album: Album) {
(context as? MainActivity)?.let { activity ->
exitTransition = Fade().apply {
duration = AppContext.TRANSITION_DURATION

2
app/src/main/java/com/github/apognu/otter/fragments/AlbumsGridFragment.kt

@ -29,7 +29,7 @@ class AlbumsGridFragment : FunkwhaleFragment<Album, AlbumsGridAdapter>() { @@ -29,7 +29,7 @@ class AlbumsGridFragment : FunkwhaleFragment<Album, AlbumsGridAdapter>() {
}
inner class OnAlbumClickListener : AlbumsGridAdapter.OnAlbumClickListener {
override fun onClick(holder: View?, album: Album) {
override fun onClick(view: View?, album: Album) {
(context as? MainActivity)?.let { activity ->
onViewPager {
exitTransition = Fade().apply {

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

@ -21,10 +21,10 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() { @@ -21,10 +21,10 @@ class TracksFragment : FunkwhaleFragment<Track, TracksAdapter>() {
lateinit var favoritesRepository: FavoritesRepository
var albumId = 0
var albumArtist = ""
var albumTitle = ""
var albumCover = ""
private var albumId = 0
private var albumArtist = ""
private var albumTitle = ""
private var albumCover = ""
companion object {
fun new(album: Album): TracksFragment {

5
app/src/main/java/com/github/apognu/otter/playback/MediaControlsManager.kt

@ -20,16 +20,15 @@ import kotlinx.coroutines.Dispatchers.IO @@ -20,16 +20,15 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class MediaControlsManager(val context: Service, val mediaSession: MediaSessionCompat) {
class MediaControlsManager(val context: Service, private val mediaSession: MediaSessionCompat) {
companion object {
const val NOTIFICATION_ACTION_OPEN_QUEUE = 0
const val NOTIFICATION_ACTION_PREVIOUS = 1
const val NOTIFICATION_ACTION_TOGGLE = 2
const val NOTIFICATION_ACTION_NEXT = 3
const val NOTIFICATION_ACTION_FAVORITE = 4
}
var notification: Notification? = null
private var notification: Notification? = null
fun updateNotification(track: Track?, playing: Boolean) {
if (notification == null && !playing) return

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

@ -9,6 +9,7 @@ import android.media.AudioAttributes @@ -9,6 +9,7 @@ import android.media.AudioAttributes
import android.media.AudioFocusRequest
import android.media.AudioManager
import android.os.Build
import android.os.IBinder
import android.support.v4.media.session.MediaSessionCompat
import android.view.KeyEvent
import com.github.apognu.otter.R
@ -214,7 +215,7 @@ class PlayerService : Service() { @@ -214,7 +215,7 @@ class PlayerService : Service() {
})
}
override fun onBind(intent: Intent?) = null
override fun onBind(intent: Intent?): IBinder? = null
@SuppressLint("NewApi")
override fun onDestroy() {

2
app/src/main/java/com/github/apognu/otter/repositories/SearchRepository.kt

@ -17,8 +17,6 @@ class SearchRepository(override val context: Context?, query: String) : Reposito @@ -17,8 +17,6 @@ class SearchRepository(override val context: Context?, query: String) : Reposito
override fun cache(data: List<Track>) = TracksCache(data)
override fun uncache(reader: BufferedReader) = gsonDeserializerOf(TracksCache::class.java).deserialize(reader)
var query: String? = null
override fun onDataFetched(data: List<Track>): List<Track> = runBlocking {
val favorites = FavoritesRepository(context).fetch(Origin.Network.origin).receive().data

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

@ -1,11 +1,7 @@ @@ -1,11 +1,7 @@
package com.github.apognu.otter.utils
import android.os.Build
import android.view.ViewGroup
import android.view.animation.Interpolator
import androidx.core.view.doOnPreDraw
import androidx.fragment.app.Fragment
import androidx.transition.TransitionSet
import com.github.apognu.otter.fragments.BrowseFragment
import com.github.apognu.otter.repositories.Repository
import kotlinx.coroutines.Dispatchers.Main
@ -35,14 +31,6 @@ inline fun <D> Channel<Repository.Response<D>>.untilNetwork(context: CoroutineCo @@ -35,14 +31,6 @@ inline fun <D> Channel<Repository.Response<D>>.untilNetwork(context: CoroutineCo
}
}
fun TransitionSet.setCommonInterpolator(interpolator: Interpolator): TransitionSet {
(0 until transitionCount)
.map { index -> getTransitionAt(index) }
.forEach { transition -> transition.interpolator = interpolator }
return this
}
fun Fragment.onViewPager(block: Fragment.() -> Unit) {
for (f in activity?.supportFragmentManager?.fragments ?: listOf()) {
if (f is BrowseFragment) {
@ -51,12 +39,6 @@ fun Fragment.onViewPager(block: Fragment.() -> Unit) { @@ -51,12 +39,6 @@ fun Fragment.onViewPager(block: Fragment.() -> Unit) {
}
}
fun Fragment.startTransitions() {
(view?.parent as? ViewGroup)?.doOnPreDraw {
startPostponedEnterTransition()
}
}
fun <T> Int.onApi(block: () -> T) {
if (Build.VERSION.SDK_INT >= this) {
block()
@ -72,17 +54,17 @@ fun <T, U> Int.onApi(block: () -> T, elseBlock: (() -> U)) { @@ -72,17 +54,17 @@ fun <T, U> Int.onApi(block: () -> T, elseBlock: (() -> U)) {
}
fun <T> Int.onApiForResult(block: () -> T, elseBlock: (() -> T)): T {
if (Build.VERSION.SDK_INT >= this) {
return block()
return if (Build.VERSION.SDK_INT >= this) {
block()
} else {
return elseBlock()
elseBlock()
}
}
fun <T> T.applyOnApi(api: Int, block: T.() -> T): T {
if (Build.VERSION.SDK_INT >= api) {
return block()
return if (Build.VERSION.SDK_INT >= api) {
block()
} else {
return this
this
}
}

2
app/src/main/java/com/github/apognu/otter/views/ExplodeReveal.kt

@ -9,7 +9,7 @@ import androidx.transition.TransitionValues @@ -9,7 +9,7 @@ import androidx.transition.TransitionValues
import androidx.transition.Visibility
class ExplodeReveal : Visibility() {
val SCREEN_BOUNDS = "screenBounds"
private val SCREEN_BOUNDS = "screenBounds"
private val locations = IntArray(2)

Loading…
Cancel
Save