Browse Source

Added a toggle for repeat mode on the Now Playing view. Should fix #26.

housekeeping/remove-warnings
Antoine POPINEAU 4 years ago
parent
commit
cf4cd16bed
No known key found for this signature in database
GPG Key ID: A78AC64694F84063
  1. 48
      app/src/main/java/com/github/apognu/otter/activities/MainActivity.kt
  2. 2
      app/src/main/java/com/github/apognu/otter/playback/PlayerService.kt
  3. 2
      app/src/main/java/com/github/apognu/otter/utils/EventBus.kt
  4. 9
      app/src/main/res/drawable/repeat.xml
  5. 9
      app/src/main/res/drawable/repeat_one.xml
  6. 9
      app/src/main/res/drawable/shuffle.xml
  7. 15
      app/src/main/res/layout-land/partial_now_playing.xml
  8. 46
      app/src/main/res/layout/partial_now_playing.xml
  9. 10
      app/src/main/res/layout/row_track.xml
  10. 2
      app/src/main/res/values/styles.xml

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

@ -14,6 +14,7 @@ import android.view.animation.AccelerateDecelerateInterpolator @@ -14,6 +14,7 @@ import android.view.animation.AccelerateDecelerateInterpolator
import android.widget.SeekBar
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.PopupMenu
import androidx.core.content.ContextCompat
import androidx.core.graphics.drawable.toDrawable
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
@ -26,6 +27,7 @@ import com.github.apognu.otter.repositories.FavoritedRepository @@ -26,6 +27,7 @@ import com.github.apognu.otter.repositories.FavoritedRepository
import com.github.apognu.otter.repositories.FavoritesRepository
import com.github.apognu.otter.repositories.Repository
import com.github.apognu.otter.utils.*
import com.google.android.exoplayer2.Player
import com.preference.PowerPreference
import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.activity_main.*
@ -300,6 +302,16 @@ class MainActivity : AppCompatActivity() { @@ -300,6 +302,16 @@ class MainActivity : AppCompatActivity() {
}
}
now_playing_details_repeat?.let { now_playing_details_repeat ->
changeRepeatMode(Cache.get(this@MainActivity, "repeat")?.readLine()?.toInt() ?: 0)
now_playing_details_repeat.setOnClickListener {
val current = Cache.get(this@MainActivity, "repeat")?.readLine()?.toInt() ?: 0
changeRepeatMode((current + 1) % 3)
}
}
now_playing_details_info?.let { now_playing_details_info ->
now_playing_details_info.setOnClickListener {
PopupMenu(this@MainActivity, now_playing_details_info, Gravity.START, R.attr.actionOverflowMenuStyle, 0).apply {
@ -397,4 +409,40 @@ class MainActivity : AppCompatActivity() { @@ -397,4 +409,40 @@ class MainActivity : AppCompatActivity() {
}
}
}
private fun changeRepeatMode(index: Int) {
when (index) {
// From no repeat to repeat all
0 -> {
Cache.set(this@MainActivity, "repeat", "0".toByteArray())
now_playing_details_repeat?.setImageResource(R.drawable.repeat)
now_playing_details_repeat?.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimaryDark))
now_playing_details_repeat?.alpha = 0.4f
CommandBus.send(Command.SetRepeatMode(Player.REPEAT_MODE_OFF))
}
// From repeat all to repeat one
1 -> {
Cache.set(this@MainActivity, "repeat", "1".toByteArray())
now_playing_details_repeat?.setImageResource(R.drawable.repeat)
now_playing_details_repeat?.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary))
now_playing_details_repeat?.alpha = 1.0f
CommandBus.send(Command.SetRepeatMode(Player.REPEAT_MODE_ALL))
}
// From repeat one to no repeat
2 -> {
Cache.set(this@MainActivity, "repeat", "2".toByteArray())
now_playing_details_repeat?.setImageResource(R.drawable.repeat_one)
now_playing_details_repeat?.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary))
now_playing_details_repeat?.alpha = 1.0f
CommandBus.send(Command.SetRepeatMode(Player.REPEAT_MODE_ONE))
}
}
}
}

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

@ -182,6 +182,8 @@ class PlayerService : Service() { @@ -182,6 +182,8 @@ class PlayerService : Service() {
is Command.Seek -> progress(message.progress)
is Command.ClearQueue -> queue.clear()
is Command.SetRepeatMode -> player.repeatMode = message.mode
}
if (player.playWhenReady) {

2
app/src/main/java/com/github/apognu/otter/utils/EventBus.kt

@ -25,6 +25,8 @@ sealed class Command { @@ -25,6 +25,8 @@ sealed class Command {
class MoveFromQueue(val oldPosition: Int, val newPosition: Int) : Command()
object ClearQueue : Command()
class SetRepeatMode(val mode: Int) : Command()
class PlayTrack(val index: Int) : Command()
}

9
app/src/main/res/drawable/repeat.xml

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4z"/>
</vector>

9
app/src/main/res/drawable/repeat_one.xml

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M7,7h10v3l4,-4 -4,-4v3L5,5v6h2L7,7zM17,17L7,17v-3l-4,4 4,4v-3h12v-6h-2v4zM13,15L13,9h-1l-2,1v1h1.5v4L13,15z"/>
</vector>

9
app/src/main/res/drawable/shuffle.xml

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10.59,9.17L5.41,4 4,5.41l5.17,5.17 1.42,-1.41zM14.5,4l2.04,2.04L4,18.59 5.41,20 17.96,7.46 20,9.5L20,4h-5.5zM14.83,13.41l-1.41,1.41 3.13,3.13L14.5,20L20,20v-5.5l-2.04,2.04 -3.13,-3.13z"/>
</vector>

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

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<FrameLayout
@ -76,13 +77,15 @@ @@ -76,13 +77,15 @@
style="@style/AppTheme.OutlinedButton"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
app:icon="@drawable/play" />
<ImageButton
android:id="@+id/now_playing_next"
style="@style/IconButton"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="16dp"
android:contentDescription="@string/control_next"
android:src="@drawable/next" />
@ -160,8 +163,8 @@ @@ -160,8 +163,8 @@
<ImageButton
android:id="@+id/now_playing_details_previous"
style="@style/IconButton"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="16dp"
android:contentDescription="@string/control_previous"
android:src="@drawable/previous" />
@ -178,8 +181,8 @@ @@ -178,8 +181,8 @@
<ImageButton
android:id="@+id/now_playing_details_next"
style="@style/IconButton"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:contentDescription="@string/control_next"
android:src="@drawable/next" />

46
app/src/main/res/layout/partial_now_playing.xml

@ -26,6 +26,7 @@ @@ -26,6 +26,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<FrameLayout
@ -81,13 +82,15 @@ @@ -81,13 +82,15 @@
style="@style/AppTheme.OutlinedButton"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
app:icon="@drawable/play" />
<ImageButton
android:id="@+id/now_playing_next"
style="@style/IconButton"
android:layout_width="?attr/actionBarSize"
android:layout_height="match_parent"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="16dp"
android:contentDescription="@string/control_next"
android:src="@drawable/next" />
@ -118,8 +121,8 @@ @@ -118,8 +121,8 @@
<ImageButton
android:id="@+id/now_playing_details_info"
style="@style/IconButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="top|end"
android:layout_margin="8dp"
android:contentDescription="@string/alt_track_info"
@ -128,8 +131,8 @@ @@ -128,8 +131,8 @@
<ImageButton
android:id="@+id/now_playing_details_favorite"
style="@style/IconButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_gravity="bottom|end"
android:layout_margin="8dp"
android:contentDescription="@string/alt_album_cover"
@ -144,7 +147,7 @@ @@ -144,7 +147,7 @@
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
android:orientation="vertical"
android:paddingTop="32dp">
android:paddingTop="16dp">
<TextView
android:id="@+id/now_playing_details_title"
@ -173,7 +176,7 @@ @@ -173,7 +176,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginBottom="0dp"
android:orientation="horizontal">
<TextView
@ -194,15 +197,15 @@ @@ -194,15 +197,15 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_marginBottom="16dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="@+id/now_playing_details_previous"
style="@style/IconButton"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginEnd="16dp"
android:contentDescription="@string/control_previous"
android:src="@drawable/previous" />
@ -219,14 +222,31 @@ @@ -219,14 +222,31 @@
<ImageButton
android:id="@+id/now_playing_details_next"
style="@style/IconButton"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:contentDescription="@string/control_next"
android:src="@drawable/next" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="@+id/now_playing_details_repeat"
style="@style/IconButton"
android:layout_width="28dp"
android:layout_height="28dp"
android:contentDescription="@string/control_next"
android:src="@drawable/repeat" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

10
app/src/main/res/layout/row_track.xml

@ -59,16 +59,18 @@ @@ -59,16 +59,18 @@
<ImageButton
android:id="@+id/favorite"
style="@style/IconButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="4dp"
android:layout_marginEnd="8dp"
android:contentDescription="@string/manage_add_to_favorites"
android:src="@drawable/favorite" />
<ImageButton
android:id="@+id/actions"
style="@style/IconButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/alt_more_options"
android:src="@drawable/more" />

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

@ -59,7 +59,7 @@ @@ -59,7 +59,7 @@
<style name="IconButton" parent="Widget.AppCompat.ActionButton">
<item name="android:tint">@color/controlForeground</item>
<item name="android:adjustViewBounds">true</item>
<item name="android:scaleType">fitCenter</item>
<item name="android:scaleType">centerCrop</item>
</style>
<style name="AppTheme.AppBar" parent="ThemeOverlay.MaterialComponents.Toolbar.Primary">

Loading…
Cancel
Save