Remove 'seconds' and 'hours' options from sleep timer (#6148)
This commit is contained in:
parent
fe2195f051
commit
c171ab6823
|
@ -6,12 +6,10 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
|
@ -30,7 +28,6 @@ import org.greenrobot.eventbus.ThreadMode;
|
|||
public class SleepTimerDialog extends DialogFragment {
|
||||
private PlaybackController controller;
|
||||
private EditText etxtTime;
|
||||
private Spinner spTimeUnit;
|
||||
private LinearLayout timeSetup;
|
||||
private LinearLayout timeDisplay;
|
||||
private TextView time;
|
||||
|
@ -70,7 +67,6 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
builder.setPositiveButton(R.string.close_label, null);
|
||||
|
||||
etxtTime = content.findViewById(R.id.etxtTime);
|
||||
spTimeUnit = content.findViewById(R.id.spTimeUnit);
|
||||
timeSetup = content.findViewById(R.id.timeSetup);
|
||||
timeDisplay = content.findViewById(R.id.timeDisplay);
|
||||
timeDisplay.setVisibility(View.GONE);
|
||||
|
@ -103,16 +99,6 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
imm.showSoftInput(etxtTime, InputMethodManager.SHOW_IMPLICIT);
|
||||
}, 100);
|
||||
|
||||
String[] spinnerContent = new String[] {
|
||||
getString(R.string.time_seconds),
|
||||
getString(R.string.time_minutes),
|
||||
getString(R.string.time_hours) };
|
||||
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
|
||||
android.R.layout.simple_spinner_item, spinnerContent);
|
||||
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spTimeUnit.setAdapter(spinnerAdapter);
|
||||
spTimeUnit.setSelection(SleepTimerPreferences.lastTimerTimeUnit());
|
||||
|
||||
CheckBox cbShakeToReset = content.findViewById(R.id.cbShakeToReset);
|
||||
CheckBox cbVibrate = content.findViewById(R.id.cbVibrate);
|
||||
CheckBox chAutoEnable = content.findViewById(R.id.chAutoEnable);
|
||||
|
@ -145,7 +131,7 @@ public class SleepTimerDialog extends DialogFragment {
|
|||
if (time == 0) {
|
||||
throw new NumberFormatException("Timer must not be zero");
|
||||
}
|
||||
SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(), spTimeUnit.getSelectedItemPosition());
|
||||
SleepTimerPreferences.setLastTimer(etxtTime.getText().toString());
|
||||
if (controller != null) {
|
||||
controller.setSleepTimer(SleepTimerPreferences.timerMillis());
|
||||
}
|
||||
|
|
|
@ -5,7 +5,10 @@ import android.content.SharedPreferences;
|
|||
import android.view.KeyEvent;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import de.danoeh.antennapod.BuildConfig;
|
||||
import de.danoeh.antennapod.core.preferences.SleepTimerPreferences;
|
||||
import de.danoeh.antennapod.error.CrashReportWriter;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
|
@ -116,6 +119,13 @@ public class PreferenceUpgrader {
|
|||
if (feedCounterSetting.equals("0")) {
|
||||
prefs.edit().putString(UserPreferences.PREF_DRAWER_FEED_COUNTER, "2").apply();
|
||||
}
|
||||
|
||||
SharedPreferences sleepTimerPreferences =
|
||||
context.getSharedPreferences(SleepTimerPreferences.PREF_NAME, Context.MODE_PRIVATE);
|
||||
TimeUnit[] timeUnits = { TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS };
|
||||
long value = Long.parseLong(SleepTimerPreferences.lastTimerValue());
|
||||
TimeUnit unit = timeUnits[sleepTimerPreferences.getInt("LastTimeUnit", 1)];
|
||||
SleepTimerPreferences.setLastTimer(String.valueOf(unit.toMinutes(value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,10 +30,10 @@
|
|||
android:inputType="number"
|
||||
android:maxLength="3" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spTimeUnit"
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/time_minutes"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginTop="8dp" />
|
||||
|
||||
|
|
|
@ -11,17 +11,14 @@ public class SleepTimerPreferences {
|
|||
|
||||
private static final String TAG = "SleepTimerPreferences";
|
||||
|
||||
private static final String PREF_NAME = "SleepTimerDialog";
|
||||
public static final String PREF_NAME = "SleepTimerDialog";
|
||||
private static final String PREF_VALUE = "LastValue";
|
||||
private static final String PREF_TIME_UNIT = "LastTimeUnit";
|
||||
|
||||
private static final String PREF_VIBRATE = "Vibrate";
|
||||
private static final String PREF_SHAKE_TO_RESET = "ShakeToReset";
|
||||
private static final String PREF_AUTO_ENABLE = "AutoEnable";
|
||||
|
||||
private static final TimeUnit[] UNITS = { TimeUnit.SECONDS, TimeUnit.MINUTES, TimeUnit.HOURS };
|
||||
|
||||
private static final String DEFAULT_VALUE = "15";
|
||||
private static final int DEFAULT_TIME_UNIT = 1;
|
||||
|
||||
private static SharedPreferences prefs;
|
||||
|
||||
|
@ -35,21 +32,17 @@ public class SleepTimerPreferences {
|
|||
SleepTimerPreferences.prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static void setLastTimer(String value, int timeUnit) {
|
||||
prefs.edit().putString(PREF_VALUE, value).putInt(PREF_TIME_UNIT, timeUnit).apply();
|
||||
public static void setLastTimer(String value) {
|
||||
prefs.edit().putString(PREF_VALUE, value).apply();
|
||||
}
|
||||
|
||||
public static String lastTimerValue() {
|
||||
return prefs.getString(PREF_VALUE, DEFAULT_VALUE);
|
||||
}
|
||||
|
||||
public static int lastTimerTimeUnit() {
|
||||
return prefs.getInt(PREF_TIME_UNIT, DEFAULT_TIME_UNIT);
|
||||
}
|
||||
|
||||
public static long timerMillis() {
|
||||
long value = Long.parseLong(lastTimerValue());
|
||||
return UNITS[lastTimerTimeUnit()].toMillis(value);
|
||||
return TimeUnit.MINUTES.toMillis(value);
|
||||
}
|
||||
|
||||
public static void setVibrate(boolean vibrate) {
|
||||
|
|
Loading…
Reference in New Issue