Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/src/main/java/com/best/deskclock/data/DataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public final class DataModel {
*/
private RingtoneModel mRingtoneModel;

/**
* The preferences for the application.
*/
private SharedPreferences mPrefs;

private DataModel() {
}

Expand All @@ -107,6 +112,7 @@ public static DataModel getDataModel() {
public void init(Context context, SharedPreferences prefs) {
if (mContext != context) {
mContext = context.getApplicationContext();
mPrefs = prefs;

final String themeValue = prefs.getString(KEY_THEME, SYSTEM_THEME);
switch (themeValue) {
Expand All @@ -128,6 +134,21 @@ public void init(Context context, SharedPreferences prefs) {
}
}

/**
* @return the holiday data url.
*/
public String getHolidayDataUrl() {
return SettingsDAO.getHolidayDataUrl(mPrefs);
}

/**
* @param url the holiday data url
*/
public void setHolidayDataUrl(String url) {
enforceMainLooper();
SettingsDAO.setHolidayDataUrl(mPrefs, url);
}

/**
* Convenience for {@code run(runnable, 0)}, i.e. waits indefinitely.
*/
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/best/deskclock/data/SettingsDAO.java
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,21 @@ public static int getRingtoneTitleColor(SharedPreferences prefs) {
return prefs.getInt(KEY_RINGTONE_TITLE_COLOR, DEFAULT_RINGTONE_TITLE_COLOR);
}

/**
* @return the holiday data url.
*/
public static String getHolidayDataUrl(SharedPreferences prefs) {
// Default value must match the one in res/values/strings.xml
return prefs.getString(KEY_HOLIDAY_DATA_URL, DEFAULT_HOLIDAY_DATA_URL);
}

/**
* @param url the holiday data url
*/
public static void setHolidayDataUrl(SharedPreferences prefs, String url) {
prefs.edit().putString(KEY_HOLIDAY_DATA_URL, url).apply();
}

private static ClockStyle getClockStyle(SharedPreferences prefs, String key) {
final String clockStyle = prefs.getString(key, DEFAULT_CLOCK_STYLE);
// Use hardcoded locale to perform toUpperCase, because in some languages toUpperCase adds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import android.app.Application;

import com.best.deskclock.data.DataModel;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

Expand All @@ -40,10 +42,10 @@ public HolidayRepository(Application application) {
mExecutorService = Executors.newSingleThreadExecutor();
}

public void downloadHolidays() {
public void updateWorkdayData() {
mExecutorService.execute(() -> {
try {
URL url = new URL("https://raw.githubusercontent.com/lanceliao/china-holiday-calender/master/holidayAPI.json");
URL url = new URL(DataModel.getDataModel().getHolidayDataUrl());
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
Type listType = new TypeToken<List<Holiday>>() {}.getType();
List<Holiday> holidays = new Gson().fromJson(in, listType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static com.best.deskclock.settings.PreferencesKeys.KEY_ENABLE_PER_ALARM_VOLUME;
import static com.best.deskclock.settings.PreferencesKeys.KEY_ENABLE_SNOOZED_OR_DISMISSED_ALARM_VIBRATIONS;
import static com.best.deskclock.settings.PreferencesKeys.KEY_FLIP_ACTION;
import static com.best.deskclock.settings.PreferencesKeys.KEY_HOLIDAY_DATA_URL;
import static com.best.deskclock.settings.PreferencesKeys.KEY_MATERIAL_DATE_PICKER_STYLE;
import static com.best.deskclock.settings.PreferencesKeys.KEY_MATERIAL_TIME_PICKER_STYLE;
import static com.best.deskclock.settings.PreferencesKeys.KEY_POWER_BUTTON;
Expand All @@ -23,9 +24,11 @@
import static com.best.deskclock.settings.PreferencesKeys.KEY_SHAKE_INTENSITY;
import static com.best.deskclock.settings.PreferencesKeys.KEY_SYSTEM_MEDIA_VOLUME;
import static com.best.deskclock.settings.PreferencesKeys.KEY_TURN_ON_BACK_FLASH_FOR_TRIGGERED_ALARM;
import static com.best.deskclock.settings.PreferencesKeys.KEY_UPDATE_HOLIDAY_DATA;
import static com.best.deskclock.settings.PreferencesKeys.KEY_VOLUME_BUTTONS;
import static com.best.deskclock.settings.PreferencesKeys.KEY_WEEK_START;

import android.app.Application;
import android.content.ContentResolver;
import android.content.Context;
import android.hardware.Sensor;
Expand All @@ -50,6 +53,7 @@
import com.best.deskclock.data.DataModel;
import com.best.deskclock.data.SettingsDAO;
import com.best.deskclock.data.Weekdays;
import com.best.deskclock.holiday.HolidayRepository;
import com.best.deskclock.provider.Alarm;
import com.best.deskclock.ringtone.RingtonePickerActivity;
import com.best.deskclock.utils.AlarmUtils;
Expand Down Expand Up @@ -85,6 +89,9 @@ public class AlarmSettingsFragment extends ScreenFragment
ListPreference mMaterialTimePickerStylePref;
ListPreference mMaterialDatePickerStylePref;
Preference mAlarmDisplayCustomizationPref;
Preference mUpdateHolidayDataPref;
Preference mHolidayDataUrlPref;
private HolidayRepository mHolidayRepository;

@Override
protected String getFragmentTitle() {
Expand All @@ -97,6 +104,9 @@ public void onCreate(Bundle savedInstanceState) {

addPreferencesFromResource(R.xml.settings_alarm);

final Application application = requireActivity().getApplication();
mHolidayRepository = new HolidayRepository(application);

mAlarmRingtonePref = findPreference(KEY_DEFAULT_ALARM_RINGTONE);
mEnablePerAlarmVolumePref = findPreference(KEY_ENABLE_PER_ALARM_VOLUME);
mAlarmVolumePref = findPreference(KEY_ALARM_VOLUME_SETTING);
Expand All @@ -118,6 +128,8 @@ public void onCreate(Bundle savedInstanceState) {
mMaterialTimePickerStylePref = findPreference(KEY_MATERIAL_TIME_PICKER_STYLE);
mMaterialDatePickerStylePref = findPreference(KEY_MATERIAL_DATE_PICKER_STYLE);
mAlarmDisplayCustomizationPref = findPreference(KEY_ALARM_DISPLAY_CUSTOMIZATION);
mUpdateHolidayDataPref = findPreference(KEY_UPDATE_HOLIDAY_DATA);
mHolidayDataUrlPref = findPreference(KEY_HOLIDAY_DATA_URL);

setupPreferences();
}
Expand Down Expand Up @@ -229,6 +241,12 @@ public boolean onPreferenceChange(Preference pref, Object newValue) {
// Set result so DeskClock knows to refresh itself
requireActivity().setResult(REQUEST_CHANGE_SETTINGS);
}

case KEY_HOLIDAY_DATA_URL -> {
final String url = (String) newValue;
DataModel.getDataModel().setHolidayDataUrl(url);
pref.setSummary(url);
}
}

return true;
Expand All @@ -246,6 +264,8 @@ public boolean onPreferenceClick(@NonNull Preference pref) {
startActivity(RingtonePickerActivity.createAlarmRingtonePickerIntentForSettings(context));

case KEY_ALARM_DISPLAY_CUSTOMIZATION -> animateAndShowFragment(new AlarmDisplayCustomizationFragment());

case KEY_UPDATE_HOLIDAY_DATA -> mHolidayRepository.updateWorkdayData();
}

return true;
Expand Down Expand Up @@ -400,6 +420,11 @@ private void setupPreferences() {
mMaterialDatePickerStylePref.setSummary(mMaterialDatePickerStylePref.getEntry());

mAlarmDisplayCustomizationPref.setOnPreferenceClickListener(this);

mUpdateHolidayDataPref.setOnPreferenceClickListener(this);

mHolidayDataUrlPref.setOnPreferenceChangeListener(this);
mHolidayDataUrlPref.setSummary(DataModel.getDataModel().getHolidayDataUrl());
}

private void initAudioDeviceCallback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public class PreferencesDefaultValues {
public static final String SPINNER_TIME_PICKER_STYLE = "spinner";
public static final String DEFAULT_DATE_PICKER_STYLE = "calendar";
public static final String SPINNER_DATE_PICKER_STYLE = "spinner";
public static final String DEFAULT_HOLIDAY_DATA_URL = "https://raw.githubusercontent.com/lanceliao/china-holiday-calender/master/holidayAPI.json";


// Alarm Display Customization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ public class PreferencesKeys {
public static final String KEY_MATERIAL_TIME_PICKER_STYLE = "key_material_time_picker_style";
public static final String KEY_MATERIAL_DATE_PICKER_STYLE = "key_material_date_picker_style";
public static final String KEY_ALARM_DISPLAY_CUSTOMIZATION = "key_alarm_display_customization";
public static final String KEY_UPDATE_HOLIDAY_DATA = "key_update_holiday_data";
public static final String KEY_HOLIDAY_DATA_URL = "key_holiday_data_url";

// Alarm Display Customization
public static final String KEY_ALARM_CLOCK_STYLE = "key_alarm_clock_style";
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -646,4 +646,16 @@
<string name="disconnect_bluetooth_device_title">请断开蓝牙设备的连接以访问此设置</string>
<string name="system_media_volume_summary">仅在连接蓝牙设备时有效</string>
<string name="widget_apply_horizontal_padding_title">将边距应用于微件两侧</string>
<!-- Category title for holiday alarm settings -->
<string name="holiday_alarm_category_title">节假日闹钟</string>
<!-- Title for the preference to update holiday data -->
<string name="update_holiday_data_title">更新节假日数据</string>
<!-- Summary for the preference to update holiday data -->
<string name="update_holiday_data_summary">手动更新节假日和工作日数据</string>
<!-- Title for the preference to set the holiday data URL -->
<string name="holiday_data_url_title">节假日数据 URL</string>
<!-- Summary for the preference to set the holiday data URL -->
<string name="holiday_data_url_summary">设置节假日和工作日数据的 URL</string>
<!-- Dialog message for the preference to set the holiday data URL -->
<string name="holiday_data_url_dialog_message">输入节假日和工作日数据的 URL</string>
</resources>
12 changes: 12 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -637,4 +637,16 @@
<string name="bluetooth_volume_title">藍牙裝置鬧鐘音量</string>
<string name="connect_bluetooth_device_title">請連接藍牙裝置以變更這項設定</string>
<string name="disconnect_bluetooth_device_title">請中斷連接藍牙裝置以存取這項設定</string>
<!-- Category title for holiday alarm settings -->
<string name="holiday_alarm_category_title">節假日鬧鐘</string>
<!-- Title for the preference to update holiday data -->
<string name="update_holiday_data_title">更新節假日資料</string>
<!-- Summary for the preference to update holiday data -->
<string name="update_holiday_data_summary">手動更新節假日和工作日資料</string>
<!-- Title for the preference to set the holiday data URL -->
<string name="holiday_data_url_title">節假日資料 URL</string>
<!-- Summary for the preference to set the holiday data URL -->
<string name="holiday_data_url_summary">設定節假日和工作日資料的 URL</string>
<!-- Dialog message for the preference to set the holiday data URL -->
<string name="holiday_data_url_dialog_message">輸入節假日和工作日資料的 URL</string>
</resources>
13 changes: 13 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,19 @@
<string name="first_launch_important_info_message_for_SDK34">• &lt;b&gt;FULL SCREEN NOTIFICATIONS;&lt;/b&gt; &lt;br&gt; &lt;br&gt;</string>
<string name="first_launch_dialog_title">Quit</string>
<string name="first_launch_dialog_message">Are you sure you want to leave the application?</string>
<!-- Category title for holiday alarm settings -->
<string name="holiday_alarm_category_title">Holiday alarm</string>
<!-- Title for the preference to update holiday data -->
<string name="update_holiday_data_title">Update holiday data</string>
<!-- Summary for the preference to update holiday data -->
<string name="update_holiday_data_summary">Manually update holiday and work schedule data</string>
<!-- Title for the preference to set the holiday data URL -->
<string name="holiday_data_url_title">Holiday data URL</string>
<!-- Summary for the preference to set the holiday data URL -->
<string name="holiday_data_url_summary">Set the URL for holiday and work schedule data</string>
<!-- Dialog message for the preference to set the holiday data URL -->
<string name="holiday_data_url_dialog_message">Enter the URL for the holiday and work schedule data</string>

<!--
Widgets
-->
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/xml/settings_alarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,29 @@

</PreferenceCategory>

<PreferenceCategory
android:title="@string/holiday_alarm_category_title"
app:allowDividerAbove="false"
app:iconSpaceReserved="false"
tools:layout="@layout/settings_preference_category_layout">

<Preference
android:key="key_update_holiday_data"
android:title="@string/update_holiday_data_title"
android:summary="@string/update_holiday_data_summary"
app:iconSpaceReserved="false"
app:singleLineTitle="false"
tools:layout="@layout/settings_preference_layout" />

<EditTextPreference
android:key="key_holiday_data_url"
android:title="@string/holiday_data_url_title"
android:summary="@string/holiday_data_url_summary"
android:dialogMessage="@string/holiday_data_url_dialog_message"
app:iconSpaceReserved="false"
app:singleLineTitle="false"
tools:layout="@layout/settings_preference_layout" />

</PreferenceCategory>

</PreferenceScreen>