Allow to swap previous/next keys from the player

Some bluetooth headphones have the prev/next button swapped
This commit is contained in:
Pawel 2018-10-03 00:10:06 +02:00
parent 2f2e04ad18
commit 565b55d651
25 changed files with 66 additions and 2 deletions

View file

@ -34,6 +34,7 @@ class SettingsActivity : SimpleActivity() {
setupAvoidWhatsNew()
setupShowInfoBubble()
setupShowAlbumCover()
setupSwapPrevNext()
setupEqualizer()
setupReplaceTitle()
updateTextColors(settings_scrollview)
@ -101,6 +102,15 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupSwapPrevNext() {
settings_swap_prev_next.isChecked = config.swapPrevNext
settings_swap_prev_next_holder.setOnClickListener {
settings_swap_prev_next.toggle()
config.swapPrevNext = settings_swap_prev_next.isChecked
}
}
private fun setupEqualizer() {
val equalizer = MusicService.mEqualizer ?: return
val items = arrayListOf<RadioItem>()

View file

@ -50,4 +50,8 @@ class Config(context: Context) : BaseConfig(context) {
var wereSongsMigrated: Boolean
get() = prefs.getBoolean(WERE_SONGS_MIGRATED, false)
set(wereSongsMigrated) = prefs.edit().putBoolean(WERE_SONGS_MIGRATED, wereSongsMigrated).apply()
var swapPrevNext: Boolean
get() = prefs.getBoolean(SWAP_PREV_NEXT, false)
set(swapPrevNext) = prefs.edit().putBoolean(SWAP_PREV_NEXT, swapPrevNext).apply()
}

View file

@ -38,6 +38,7 @@ const val CURRENT_PLAYLIST = "current_playlist"
const val SHOW_FILENAME = "show_filename"
const val SHOW_ALBUM_COVER = "show_album_cover"
const val WERE_SONGS_MIGRATED = "were_songs_migrated" // check migration from old sqlite to Room
const val SWAP_PREV_NEXT = "swap_prev_next"
const val LIST_HEADERS_COUNT = 2
const val LOWER_ALPHA = 0.5f

View file

@ -5,10 +5,12 @@ import android.content.Context
import android.content.Intent
import android.os.Handler
import android.view.KeyEvent
import com.simplemobiletools.musicplayer.extensions.config
import com.simplemobiletools.musicplayer.extensions.sendIntent
import com.simplemobiletools.musicplayer.helpers.NEXT
import com.simplemobiletools.musicplayer.helpers.PLAYPAUSE
import com.simplemobiletools.musicplayer.helpers.PREVIOUS
import kotlinx.android.synthetic.main.activity_settings.view.*
class RemoteControlReceiver : BroadcastReceiver() {
companion object {
@ -37,12 +39,15 @@ class RemoteControlReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
mContext = context
if (intent.action == Intent.ACTION_MEDIA_BUTTON) {
val swapPrevNext = context.config.swapPrevNext
val intentNext = if (swapPrevNext) PREVIOUS else NEXT
val intentPrevious = if (swapPrevNext) NEXT else PREVIOUS
val event = intent.getParcelableExtra<KeyEvent>(Intent.EXTRA_KEY_EVENT)
if (event.action == KeyEvent.ACTION_UP) {
when (event.keyCode) {
KeyEvent.KEYCODE_MEDIA_PLAY, KeyEvent.KEYCODE_MEDIA_PAUSE -> context.sendIntent(PLAYPAUSE)
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> context.sendIntent(PREVIOUS)
KeyEvent.KEYCODE_MEDIA_NEXT -> context.sendIntent(NEXT)
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> context.sendIntent(intentPrevious)
KeyEvent.KEYCODE_MEDIA_NEXT -> context.sendIntent(intentNext)
KeyEvent.KEYCODE_HEADSETHOOK -> {
mClicksCnt++

View file

@ -196,6 +196,30 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_swap_prev_next_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingBottom="@dimen/activity_margin"
android:paddingLeft="@dimen/normal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_swap_prev_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingLeft="@dimen/medium_margin"
android:paddingStart="@dimen/medium_margin"
android:text="@string/swap_prev_next"/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_equalizer_holder"
android:layout_width="match_parent"

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Qarışdırıcı</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Equalizer</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Wie kann ich Songs vorspulen?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ecualizador</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ekualizadorea</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Nola aurreratu ditzaket azkar abestiak?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ecualizador</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ekvilajzer</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Kako mogu premotati pjesme?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Hangszínszabályzó</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Equalizzatore</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">イコライザー</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">曲を早送りするにはどうすればよいですか?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">이퀄라이저</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ekvalaizeris</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Equalizer</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Hoe kan ik een nummer vooruitspoelen?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Korektor</string>
<string name="swap_prev_next">Zamień kody przycisków poprzedni/następny</string>
<!-- FAQ -->
<string name="faq_1_title">Jak mogę przewijać piosenki?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Equalizador</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Эквалайзер</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Как я могу перемотать композицию?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ekvalizér</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Ako viem posunúť skladbu vpred?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Equalizer</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Ekolayzır</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">Şarkıları nasıl hızlıca ileri sarabilirim?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">等化器</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">我如何快轉歌曲?</string>

View file

@ -51,6 +51,7 @@
<!-- Settings -->
<string name="equalizer">Equalizer</string>
<string name="swap_prev_next">Swap previous/next keycodes</string>
<!-- FAQ -->
<string name="faq_1_title">How can I fast-forward songs?</string>