...
 
Commits (6)
......@@ -23,6 +23,8 @@
<receiver android:name=".receivers.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.TIME_SET" />
<action android:name="android.intent.action.TIMEZONE_CHANGED" />
</intent-filter>
</receiver>
......
......@@ -66,7 +66,9 @@ import com.tmendes.birthdaydroid.helpers.AlarmHelper;
import com.tmendes.birthdaydroid.helpers.PermissionHelper;
import com.tmendes.birthdaydroid.providers.BirthdayDataProvider;
import java.util.Calendar;
import java.util.Objects;
import java.util.TimeZone;
import static androidx.appcompat.app.AppCompatDelegate.setDefaultNightMode;
......@@ -113,6 +115,7 @@ public class MainActivity extends AppCompatActivity
permissionHelper = new PermissionHelper(this);
showBreakingChangeDialogAndMigradeIfNeeded();
checkIsEnableBatteryOptimizations();
requestForPermissions();
......@@ -180,6 +183,34 @@ public class MainActivity extends AppCompatActivity
}
}
private void showBreakingChangeDialogAndMigradeIfNeeded() {
if (!prefs.contains("breaking_change_v46")) {
long scanDailyInterval = prefs.getLong("scan_daily_interval", 0);
if (scanDailyInterval != 0) {
// Migrade
Calendar oldCalendar = Calendar.getInstance();
oldCalendar.setTimeInMillis(scanDailyInterval);
Calendar newCalendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
newCalendar.set(Calendar.HOUR_OF_DAY, oldCalendar.get(Calendar.HOUR_OF_DAY));
newCalendar.set(Calendar.MINUTE, oldCalendar.get(Calendar.MINUTE));
long scanDailyIntervalNew = newCalendar.getTimeInMillis();
prefs.edit().putLong("scan_daily_interval", scanDailyIntervalNew).apply();
AlarmHelper alarmHelper = new AlarmHelper();
alarmHelper.cancelAlarm(this);
alarmHelper.setAlarm(this, scanDailyIntervalNew);
// Show message because migration is not save.
new AlertDialog.Builder(this)
.setTitle(R.string.breaking_change_dialog_title)
.setMessage(R.string.breaking_change_dialog_message_v46)
.show();
}
prefs.edit().putBoolean("breaking_change_v46", true).apply();
}
}
@Override
public void onBackPressed() {
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
......
......@@ -32,6 +32,7 @@ import com.tmendes.birthdaydroid.receivers.NotifierReceiver;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
import static android.app.AlarmManager.INTERVAL_DAY;
......@@ -45,13 +46,22 @@ public class AlarmHelper {
Calendar defaultToRingAt = Calendar.getInstance();
if (toGoesOffAt == 0) {
defaultToRingAt.set(Calendar.HOUR, MainActivity.DEFAULT_ALARM_TIME);
defaultToRingAt.set(Calendar.HOUR_OF_DAY, MainActivity.DEFAULT_ALARM_TIME);
defaultToRingAt.set(Calendar.MINUTE, 0);
defaultToRingAt.set(Calendar.SECOND, 0);
} else {
Calendar configuredTime = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
configuredTime.setTimeInMillis(toGoesOffAt);
defaultToRingAt.set(Calendar.HOUR_OF_DAY, configuredTime.get(Calendar.HOUR_OF_DAY));
defaultToRingAt.set(Calendar.MINUTE, configuredTime.get(Calendar.MINUTE));
defaultToRingAt.set(Calendar.SECOND, configuredTime.get(Calendar.SECOND));
Calendar now = Calendar.getInstance();
defaultToRingAt.setTimeInMillis(toGoesOffAt);
defaultToRingAt.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
if(defaultToRingAt.getTimeInMillis() < now.getTimeInMillis()){
defaultToRingAt.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH) + 1);
}
}
@SuppressLint("SimpleDateFormat")
......
......@@ -30,6 +30,7 @@ import com.tmendes.birthdaydroid.R;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
public class TimeDialogPreference extends DialogPreference {
private final Calendar calendar;
......@@ -49,8 +50,8 @@ public class TimeDialogPreference extends DialogPreference {
setPositiveButtonText(ctxt.getResources().getString(R.string.settings_time_set));
setNegativeButtonText(ctxt.getResources().getString(R.string.settings_time_cancel));
calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR, MainActivity.DEFAULT_ALARM_TIME);
calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.set(Calendar.HOUR_OF_DAY, MainActivity.DEFAULT_ALARM_TIME);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
}
......@@ -116,6 +117,9 @@ public class TimeDialogPreference extends DialogPreference {
if (calendar == null) {
return null;
}
return DateFormat.getTimeFormat(getContext()).format(new Date(calendar.getTimeInMillis()));
java.text.DateFormat timeFormat = DateFormat.getTimeFormat(getContext());
timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return timeFormat.format(new Date(calendar.getTimeInMillis()));
}
}
\ No newline at end of file
......@@ -33,7 +33,11 @@ public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Objects.requireNonNull(intent.getAction()).equals("android.intent.action.BOOT_COMPLETED")) {
String action = Objects.requireNonNull(intent.getAction());
if (action.equals(Intent.ACTION_BOOT_COMPLETED)
|| action.equals(Intent.ACTION_TIME_CHANGED)
|| action.equals(Intent.ACTION_TIMEZONE_CHANGED)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
long toRingAt = prefs.getLong("scan_daily_interval", 0);
alarm.cancelAlarm(context);
......
......@@ -149,5 +149,8 @@
<string name="accounts_enabled_title">Select Accounts</string>
<string name="accounts_enabled_sum">Enable the use of specific accounts</string>
<string name="accounts_title">Accounts</string>
<string name="breaking_change_dialog_title">Important Update Notice</string>
<string name="breaking_change_dialog_message_v46">The mechanism how times are saved has changed. Please check the notification time and correct it if needed.</string>
</resources>