add a menu button for repeating the current song

This commit is contained in:
tibbi 2016-10-09 18:10:35 +02:00
parent b6f4d8e205
commit 96b5c6f49b
10 changed files with 43 additions and 1 deletions

View file

@ -11,7 +11,7 @@ public class Config {
return new Config(context);
}
public Config(Context context) {
private Config(Context context) {
mPrefs = context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE);
}
@ -62,4 +62,12 @@ public class Config {
public void setEqualizer(int equalizer) {
mPrefs.edit().putInt(Constants.EQUALIZER, equalizer).apply();
}
public boolean getRepeatSong() {
return mPrefs.getBoolean(Constants.REPEAT_SONG, false);
}
public void setRepeatSong(boolean repeat) {
mPrefs.edit().putBoolean(Constants.REPEAT_SONG, repeat).apply();
}
}

View file

@ -34,4 +34,5 @@ public class Constants {
public static final String NUMERIC_PROGRESS = "numeric_progress";
public static final String SORTING = "sorting";
public static final String EQUALIZER = "equalizer";
public static final String REPEAT_SONG = "repeat_song";
}

View file

@ -109,6 +109,8 @@ public class MainActivity extends SimpleActivity
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
menu.findItem(R.id.enable_song_repetition).setVisible(!mConfig.getRepeatSong());
menu.findItem(R.id.disable_song_repetition).setVisible(mConfig.getRepeatSong());
return true;
}
@ -121,6 +123,12 @@ public class MainActivity extends SimpleActivity
case R.id.about:
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
return true;
case R.id.enable_song_repetition:
toggleSongRepetition(true);
return true;
case R.id.disable_song_repetition:
toggleSongRepetition(false);
return true;
default:
return super.onOptionsItemSelected(item);
}
@ -139,6 +147,11 @@ public class MainActivity extends SimpleActivity
}
}
private void toggleSongRepetition(boolean enable) {
mConfig.setRepeatSong(enable);
invalidateOptionsMenu();
}
private void initializePlayer() {
mToBeDeleted = new ArrayList<>();
mSongsList.setMultiChoiceModeListener(this);

View file

@ -1,6 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/enable_song_repetition"
android:title="@string/enable_song_repetition"
app:showAsAction="never"/>
<item
android:id="@+id/disable_song_repetition"
android:title="@string/disable_song_repetition"
app:showAsAction="never"/>
<item
android:id="@+id/settings"
android:title="@string/settings"

View file

@ -15,6 +15,8 @@
<string name="rename_song_empty">Fülle bitte alle Felder aus</string>
<string name="ok">OK</string>
<string name="cancel">Abbrechen</string>
<string name="enable_song_repetition">Repeat current song</string>
<string name="disable_song_repetition">Stop repeating current song</string>
<plurals name="songs_deleted">
<item quantity="one">1 Titel gelöscht</item>

View file

@ -15,6 +15,8 @@
<string name="rename_song_empty">Completa tutti i campi</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="enable_song_repetition">Repeat current song</string>
<string name="disable_song_repetition">Stop repeating current song</string>
<plurals name="songs_deleted">
<item quantity="one">1 canzone eliminata</item>

View file

@ -15,6 +15,8 @@
<string name="rename_song_empty">すべてのフィールドを入力してください</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="enable_song_repetition">Repeat current song</string>
<string name="disable_song_repetition">Stop repeating current song</string>
<plurals name="songs_deleted">
<item quantity="one">1 曲削除しました</item>

View file

@ -15,6 +15,8 @@
<string name="rename_song_empty">Por favor preencha todos os campos</string>
<string name="ok">OK</string>
<string name="cancel">Cancelar</string>
<string name="enable_song_repetition">Repeat current song</string>
<string name="disable_song_repetition">Stop repeating current song</string>
<plurals name="songs_deleted">
<item quantity="one">1 música eliminada</item>

View file

@ -15,6 +15,8 @@
<string name="rename_song_empty">Alla fält måste fyllas i</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="enable_song_repetition">Repeat current song</string>
<string name="disable_song_repetition">Stop repeating current song</string>
<plurals name="songs_deleted">
<item quantity="one">1 låt borttagen</item>

View file

@ -16,6 +16,8 @@
<string name="progress" translatable="false">%1$s / %2$s</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="enable_song_repetition">Repeat current song</string>
<string name="disable_song_repetition">Stop repeating current song</string>
<plurals name="songs_deleted">
<item quantity="one">1 song deleted</item>