diff options
author | H. Lehmann <ByteHamster@users.noreply.github.com> | 2020-05-20 14:56:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 14:56:51 +0200 |
commit | 3de98ca89901251500d1c829e513aab7f98d5466 (patch) | |
tree | bdba1d8e8be7b4bfba5d8bb2b8c649aa5d990c99 /app/src/main | |
parent | 20678a94cd7595aa8faa6116af7b2e2103c8f45a (diff) | |
parent | a6c55f1c0e1f7fe1c37a7f3c6aeda61dc38e2654 (diff) | |
download | AntennaPod-3de98ca89901251500d1c829e513aab7f98d5466.zip |
Merge pull request #4174 from ByteHamster/ui-adjustments
Ui adjustments
Diffstat (limited to 'app/src/main')
3 files changed, 37 insertions, 64 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 9e647bcaa..655049b2c 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -409,13 +409,7 @@ public class MainActivity extends CastEnabledActivity { public void onEventMainThread(MessageEvent event) { Log.d(TAG, "onEvent(" + event + ")"); - Snackbar snackbar; - if (getBottomSheet().getState() == BottomSheetBehavior.STATE_COLLAPSED) { - snackbar = showSnackbarAbovePlayer(event.message, Snackbar.LENGTH_SHORT); - } else { - snackbar = Snackbar.make(findViewById(android.R.id.content), event.message, Snackbar.LENGTH_SHORT); - snackbar.show(); - } + Snackbar snackbar = showSnackbarAbovePlayer(event.message, Snackbar.LENGTH_SHORT); if (event.action != null) { snackbar.setAction(getString(R.string.undo), v -> event.action.run()); } @@ -453,21 +447,21 @@ public class MainActivity extends CastEnabledActivity { setIntent(intent); } - public Snackbar showSnackbarAbovePlayer(int text, int duration) { - Snackbar s = Snackbar.make(findViewById(R.id.main_view), text, duration); - if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) { - s.setAnchorView(findViewById(R.id.audioplayerFragment)); + public Snackbar showSnackbarAbovePlayer(CharSequence text, int duration) { + Snackbar s; + if (getBottomSheet().getState() == BottomSheetBehavior.STATE_COLLAPSED) { + s = Snackbar.make(findViewById(R.id.main_view), text, duration); + if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) { + s.setAnchorView(findViewById(R.id.audioplayerFragment)); + } + } else { + s = Snackbar.make(findViewById(android.R.id.content), text, duration); } s.show(); return s; } - public Snackbar showSnackbarAbovePlayer(String text, int duration) { - Snackbar s = Snackbar.make(findViewById(R.id.main_view), text, duration); - if (findViewById(R.id.audioplayerFragment).getVisibility() == View.VISIBLE) { - s.setAnchorView(findViewById(R.id.audioplayerFragment)); - } - s.show(); - return s; + public Snackbar showSnackbarAbovePlayer(int text, int duration) { + return showSnackbarAbovePlayer(getResources().getText(text), duration); } } diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java index fafe888ee..a9c54e879 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/SleepTimerDialog.java @@ -2,9 +2,8 @@ package de.danoeh.antennapod.dialog; import android.app.Dialog; import android.content.Context; +import android.content.DialogInterface; import android.os.Bundle; -import android.text.Editable; -import android.text.TextWatcher; import android.view.View; import android.view.inputmethod.InputMethodManager; import android.widget.ArrayAdapter; @@ -14,7 +13,6 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; @@ -36,9 +34,6 @@ public class SleepTimerDialog extends DialogFragment { private EditText etxtTime; private Spinner spTimeUnit; - private CheckBox cbShakeToReset; - private CheckBox cbVibrate; - private CheckBox chAutoEnable; private LinearLayout timeSetup; private LinearLayout timeDisplay; private TextView time; @@ -85,33 +80,15 @@ public class SleepTimerDialog extends DialogFragment { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(R.string.sleep_timer_label); builder.setView(content); - builder.setPositiveButton(android.R.string.ok, null); + builder.setPositiveButton(R.string.close_label, null); etxtTime = content.findViewById(R.id.etxtTime); spTimeUnit = content.findViewById(R.id.spTimeUnit); - cbShakeToReset = content.findViewById(R.id.cbShakeToReset); - cbVibrate = content.findViewById(R.id.cbVibrate); - chAutoEnable = content.findViewById(R.id.chAutoEnable); timeSetup = content.findViewById(R.id.timeSetup); timeDisplay = content.findViewById(R.id.timeDisplay); time = content.findViewById(R.id.time); - AlertDialog dialog = builder.create(); etxtTime.setText(SleepTimerPreferences.lastTimerValue()); - etxtTime.addTextChangedListener(new TextWatcher() { - @Override - public void afterTextChanged(Editable s) { - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(s.length() > 0); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - } - }); etxtTime.postDelayed(() -> { InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(etxtTime, InputMethodManager.SHOW_IMPLICIT); @@ -127,12 +104,21 @@ public class SleepTimerDialog extends DialogFragment { 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); + cbShakeToReset.setChecked(SleepTimerPreferences.shakeToReset()); cbVibrate.setChecked(SleepTimerPreferences.vibrate()); chAutoEnable.setChecked(SleepTimerPreferences.autoEnable()); + cbShakeToReset.setOnCheckedChangeListener((buttonView, isChecked) + -> SleepTimerPreferences.setShakeToReset(isChecked)); + cbVibrate.setOnCheckedChangeListener((buttonView, isChecked) + -> SleepTimerPreferences.setVibrate(isChecked)); chAutoEnable.setOnCheckedChangeListener((compoundButton, isChecked) - -> SleepTimerPreferences.setAutoEnable(isChecked)); + -> SleepTimerPreferences.setAutoEnable(isChecked)); + Button disableButton = content.findViewById(R.id.disableSleeptimerButton); disableButton.setOnClickListener(v -> { if (controller != null) { @@ -143,27 +129,20 @@ public class SleepTimerDialog extends DialogFragment { setButton.setOnClickListener(v -> { if (!PlaybackService.isRunning) { Snackbar.make(content, R.string.no_media_playing_label, Snackbar.LENGTH_LONG).show(); + return; } try { - savePreferences(); + SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(), spTimeUnit.getSelectedItemPosition()); long time = SleepTimerPreferences.timerMillis(); if (controller != null) { - controller.setSleepTimer(time, cbShakeToReset.isChecked(), cbVibrate.isChecked()); + controller.setSleepTimer(time); } } catch (NumberFormatException e) { e.printStackTrace(); - Toast.makeText(getContext(), R.string.time_dialog_invalid_input, Toast.LENGTH_LONG).show(); + Snackbar.make(content, R.string.time_dialog_invalid_input, Snackbar.LENGTH_LONG).show(); } }); - return dialog; - } - - private void savePreferences() { - SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(), - spTimeUnit.getSelectedItemPosition()); - SleepTimerPreferences.setShakeToReset(cbShakeToReset.isChecked()); - SleepTimerPreferences.setVibrate(cbVibrate.isChecked()); - SleepTimerPreferences.setAutoEnable(chAutoEnable.isChecked()); + return builder.create(); } private void updateTime() { diff --git a/app/src/main/res/layout/audioplayer_fragment.xml b/app/src/main/res/layout/audioplayer_fragment.xml index 1935ce36c..37c30b4dd 100644 --- a/app/src/main/res/layout/audioplayer_fragment.xml +++ b/app/src/main/res/layout/audioplayer_fragment.xml @@ -107,10 +107,10 @@ android:id="@+id/butPlay" android:layout_width="@dimen/audioplayer_playercontrols_length_big" android:layout_height="@dimen/audioplayer_playercontrols_length_big" - android:layout_marginLeft="8dp" - android:layout_marginStart="8dp" - android:layout_marginRight="8dp" - android:layout_marginEnd="8dp" + android:layout_marginLeft="@dimen/audioplayer_playercontrols_margin" + android:layout_marginStart="@dimen/audioplayer_playercontrols_margin" + android:layout_marginRight="@dimen/audioplayer_playercontrols_margin" + android:layout_marginEnd="@dimen/audioplayer_playercontrols_margin" android:padding="8dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" @@ -145,8 +145,8 @@ android:layout_height="@dimen/audioplayer_playercontrols_length" android:layout_toLeftOf="@id/butPlay" android:layout_toStartOf="@id/butPlay" - android:layout_marginLeft="8dp" - android:layout_marginStart="8dp" + android:layout_marginLeft="@dimen/audioplayer_playercontrols_margin" + android:layout_marginStart="@dimen/audioplayer_playercontrols_margin" android:layout_centerVertical="true" android:background="?attr/selectableItemBackgroundBorderless" android:contentDescription="@string/rewind_label" @@ -201,8 +201,8 @@ android:layout_height="@dimen/audioplayer_playercontrols_length" android:layout_toRightOf="@id/butPlay" android:layout_toEndOf="@id/butPlay" - android:layout_marginRight="8dp" - android:layout_marginEnd="8dp" + android:layout_marginRight="@dimen/audioplayer_playercontrols_margin" + android:layout_marginEnd="@dimen/audioplayer_playercontrols_margin" android:layout_centerVertical="true" android:background="?attr/selectableItemBackgroundBorderless" android:contentDescription="@string/fast_forward_label" |