Skip to content

Commit

Permalink
Fix ugly time picker preference
Browse files Browse the repository at this point in the history
  • Loading branch information
niknetniko committed Oct 26, 2023
1 parent d8131bf commit ac2e597
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@

import java.time.LocalTime;

import be.ugent.zeus.hydra.R;
import be.ugent.zeus.hydra.common.utils.ViewUtils;

/**
* Custom dialog to select a time in the preferences.
* <p>
Expand All @@ -48,36 +45,28 @@
* @author Niko Strijbol
* @see <a href="https://github.com/Gericop/Android-Support-Preference-V7-Fix">Based on this library</a>
* @see LocalTime#toString() The exact documentation on how the value is saved.
* @noinspection unused
*/
@SuppressWarnings({"WeakerAccess"})
public class TimePreference extends DialogPreference {

public TimePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TimePreference, defStyleAttr, defStyleRes);

if (ViewUtils.getBoolean(a, R.styleable.TimePreference_useDefaultSummary,
R.styleable.TimePreference_useDefaultSummary, false)) {
setSummaryProvider(new TimeSummaryProvider());
}

a.recycle();
setSummaryProvider(new TimeSummaryProvider());
}

public TimePreference(Context context, AttributeSet attrs, int defStyleAttr) {
this(context, attrs, defStyleAttr, 0);
super(context, attrs, defStyleAttr);
setSummaryProvider(new TimeSummaryProvider());
}

public TimePreference(Context context, AttributeSet attrs) {
this(context, attrs, ViewUtils.getAttr(context,
androidx.preference.R.attr.dialogPreferenceStyle,
android.R.attr.dialogPreferenceStyle));
super(context, attrs);
setSummaryProvider(new TimeSummaryProvider());
}

@SuppressWarnings({"unused", "RedundantSuppression"})
public TimePreference(Context context) {
this(context, null);
super(context);
setSummaryProvider(new TimeSummaryProvider());
}

@Nullable
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
<attr name="messagePaddingTop" format="boolean" />
</declare-styleable>

<declare-styleable name="TimePreference">
<attr name="useDefaultSummary" format="boolean" />
</declare-styleable>

<!--
An attribute that is the primary colour in the light theme,
but the secondary colour in the dark theme.
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/xml/pref_resto.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
app:allowDividerBelow="true"
app:defaultValue="21:00"
app:key="pref_resto_closing_hour"
app:summary="@string/resto_pref_closing_description"
app:title="@string/resto_pref_closing_title"
app:useDefaultSummary="true" />
app:title="@string/resto_pref_closing_title" />

<ListPreference
app:allowDividerAbove="true"
Expand Down

0 comments on commit ac2e597

Please sign in to comment.