2019-05-06 07:10:13 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-01-05 17:32:53 +00:00
|
|
|
Copyright 2018-2020 by Marcel Bokhorst (M66B)
|
2019-05-06 07:10:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
import android.app.Dialog;
|
|
|
|
import android.app.TimePickerDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.text.format.DateFormat;
|
|
|
|
import android.view.LayoutInflater;
|
2019-05-06 12:41:03 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
2019-12-23 10:21:27 +00:00
|
|
|
import android.widget.CheckBox;
|
2019-05-06 07:10:13 +00:00
|
|
|
import android.widget.CompoundButton;
|
|
|
|
import android.widget.Spinner;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.TimePicker;
|
2019-07-14 10:32:32 +00:00
|
|
|
import android.widget.Toast;
|
2019-05-06 07:10:13 +00:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.appcompat.widget.SwitchCompat;
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
2019-09-10 06:53:07 +00:00
|
|
|
import androidx.lifecycle.Lifecycle;
|
2019-05-06 07:10:13 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
|
2019-12-23 10:21:27 +00:00
|
|
|
import java.text.DateFormatSymbols;
|
2019-05-06 07:10:13 +00:00
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
2019-05-06 13:03:35 +00:00
|
|
|
public class FragmentOptionsSynchronize extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
2019-05-06 07:10:13 +00:00
|
|
|
private SwitchCompat swEnabled;
|
|
|
|
private Spinner spPollInterval;
|
|
|
|
private SwitchCompat swSchedule;
|
2019-12-23 10:21:27 +00:00
|
|
|
private TextView tvSchedulePro;
|
2019-05-06 07:10:13 +00:00
|
|
|
private TextView tvScheduleStart;
|
|
|
|
private TextView tvScheduleEnd;
|
2019-12-23 10:21:27 +00:00
|
|
|
private CheckBox[] cbDay;
|
2019-05-06 13:25:11 +00:00
|
|
|
private SwitchCompat swUnseen;
|
|
|
|
private SwitchCompat swFlagged;
|
2019-07-06 16:13:38 +00:00
|
|
|
private SwitchCompat swDeleteUnseen;
|
2019-06-02 06:26:12 +00:00
|
|
|
private SwitchCompat swSyncKept;
|
2019-06-08 14:33:25 +00:00
|
|
|
private SwitchCompat swSyncFolders;
|
2019-08-17 07:26:45 +00:00
|
|
|
private SwitchCompat swSubscriptions;
|
|
|
|
private TextView tvSubscriptionPro;
|
|
|
|
private SwitchCompat swSubscribedOnly;
|
2019-07-16 12:44:21 +00:00
|
|
|
private SwitchCompat swCheckMx;
|
2019-05-06 07:10:13 +00:00
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
private final static String[] RESET_OPTIONS = new String[]{
|
2019-07-06 16:13:38 +00:00
|
|
|
"enabled", "poll_interval", "schedule", "schedule_start", "schedule_end",
|
2019-08-17 07:26:45 +00:00
|
|
|
"sync_unseen", "sync_flagged", "delete_unseen", "sync_kept", "sync_folders", "subscriptions", "subscribed_only", "check_mx"
|
2019-05-06 12:41:03 +00:00
|
|
|
};
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
@Override
|
|
|
|
@Nullable
|
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
2019-06-12 14:15:46 +00:00
|
|
|
setSubtitle(R.string.title_setup);
|
2019-05-06 12:41:03 +00:00
|
|
|
setHasOptionsMenu(true);
|
2019-05-06 07:10:13 +00:00
|
|
|
|
2019-05-06 13:03:35 +00:00
|
|
|
View view = inflater.inflate(R.layout.fragment_options_synchronize, container, false);
|
2019-05-06 07:10:13 +00:00
|
|
|
|
|
|
|
// Get controls
|
|
|
|
|
|
|
|
swEnabled = view.findViewById(R.id.swEnabled);
|
|
|
|
spPollInterval = view.findViewById(R.id.spPollInterval);
|
|
|
|
swSchedule = view.findViewById(R.id.swSchedule);
|
2019-12-23 10:21:27 +00:00
|
|
|
tvSchedulePro = view.findViewById(R.id.tvSchedulePro);
|
2019-05-06 07:10:13 +00:00
|
|
|
tvScheduleStart = view.findViewById(R.id.tvScheduleStart);
|
|
|
|
tvScheduleEnd = view.findViewById(R.id.tvScheduleEnd);
|
2019-12-23 10:21:27 +00:00
|
|
|
cbDay = new CheckBox[]{
|
|
|
|
view.findViewById(R.id.cbDay0),
|
|
|
|
view.findViewById(R.id.cbDay1),
|
|
|
|
view.findViewById(R.id.cbDay2),
|
|
|
|
view.findViewById(R.id.cbDay3),
|
|
|
|
view.findViewById(R.id.cbDay4),
|
|
|
|
view.findViewById(R.id.cbDay5),
|
|
|
|
view.findViewById(R.id.cbDay6)
|
|
|
|
};
|
2019-05-06 13:25:11 +00:00
|
|
|
swUnseen = view.findViewById(R.id.swUnseen);
|
|
|
|
swFlagged = view.findViewById(R.id.swFlagged);
|
2019-07-06 16:13:38 +00:00
|
|
|
swDeleteUnseen = view.findViewById(R.id.swDeleteUnseen);
|
2019-06-02 06:26:12 +00:00
|
|
|
swSyncKept = view.findViewById(R.id.swSyncKept);
|
2019-06-08 14:33:25 +00:00
|
|
|
swSyncFolders = view.findViewById(R.id.swSyncFolders);
|
2019-08-17 07:26:45 +00:00
|
|
|
swSubscriptions = view.findViewById(R.id.swSubscriptions);
|
|
|
|
tvSubscriptionPro = view.findViewById(R.id.tvSubscriptionPro);
|
|
|
|
swSubscribedOnly = view.findViewById(R.id.swSubscribedOnly);
|
2019-07-16 12:44:21 +00:00
|
|
|
swCheckMx = view.findViewById(R.id.swCheckMx);
|
2019-05-06 07:10:13 +00:00
|
|
|
|
2019-05-06 13:30:30 +00:00
|
|
|
setOptions();
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
// Wire controls
|
|
|
|
|
|
|
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
|
|
|
|
swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("enabled", checked).apply();
|
2019-12-09 18:44:27 +00:00
|
|
|
ServiceSynchronize.eval(getContext(), "enabled=" + checked);
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
spPollInterval.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
|
|
|
|
Object tag = adapterView.getTag();
|
|
|
|
int current = (tag == null ? 0 : (Integer) tag);
|
|
|
|
int[] values = getResources().getIntArray(R.array.pollIntervalValues);
|
|
|
|
int value = values[position];
|
|
|
|
if (value != current) {
|
|
|
|
adapterView.setTag(value);
|
|
|
|
prefs.edit().putInt("poll_interval", value).apply();
|
2019-12-29 11:26:51 +00:00
|
|
|
ServiceSynchronize.reschedule(getContext());
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-12-07 14:14:35 +00:00
|
|
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
|
|
|
adapterView.setTag(null);
|
2019-05-06 07:10:13 +00:00
|
|
|
prefs.edit().remove("poll_interval").apply();
|
2019-12-29 11:26:51 +00:00
|
|
|
ServiceSynchronize.reschedule(getContext());
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swSchedule.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
2019-06-28 11:08:04 +00:00
|
|
|
prefs.edit().putBoolean("schedule", checked).apply();
|
2020-01-10 10:23:42 +00:00
|
|
|
ServiceSynchronize.reschedule(getContext());
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-23 10:21:27 +00:00
|
|
|
Helper.linkPro(tvSchedulePro);
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
tvScheduleStart.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("start", true);
|
|
|
|
DialogFragment timePicker = new TimePickerFragment();
|
|
|
|
timePicker.setArguments(args);
|
2019-10-12 15:16:53 +00:00
|
|
|
timePicker.show(getParentFragmentManager(), "timePicker");
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tvScheduleEnd.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean("start", false);
|
|
|
|
DialogFragment timePicker = new TimePickerFragment();
|
|
|
|
timePicker.setArguments(args);
|
2019-10-12 15:16:53 +00:00
|
|
|
timePicker.show(getParentFragmentManager(), "timePicker");
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-12-23 10:21:27 +00:00
|
|
|
String[] daynames = new DateFormatSymbols().getWeekdays();
|
|
|
|
for (int i = 0; i < 7; i++) {
|
|
|
|
final int day = i;
|
|
|
|
cbDay[i].setText(daynames[i + 1]);
|
|
|
|
cbDay[i].setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
|
|
prefs.edit().putBoolean("schedule_day" + day, isChecked).apply();
|
|
|
|
ServiceSynchronize.reschedule(getContext());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-06-28 19:22:20 +00:00
|
|
|
|
2019-05-06 13:25:11 +00:00
|
|
|
swUnseen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("sync_unseen", checked).apply();
|
2019-12-09 21:26:29 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), null, "sync_unseen=" + checked);
|
2019-05-06 13:25:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
swFlagged.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("sync_flagged", checked).apply();
|
2019-12-09 21:26:29 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), null, "sync_flagged=" + checked);
|
2019-05-06 13:25:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-06 16:13:38 +00:00
|
|
|
swDeleteUnseen.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("delete_unseen", checked).apply();
|
2019-12-09 21:26:29 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), null, "delete_unseen=" + checked);
|
2019-07-06 16:13:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-02 06:26:12 +00:00
|
|
|
swSyncKept.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("sync_kept", checked).apply();
|
2019-12-09 21:26:29 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), null, "sync_kept=" + checked);
|
2019-06-02 06:26:12 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-06-08 14:33:25 +00:00
|
|
|
swSyncFolders.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("sync_folders", checked).apply();
|
2019-12-09 21:26:29 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), null, "sync_folders=" + checked);
|
2019-06-08 14:33:25 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-08-17 07:26:45 +00:00
|
|
|
swSubscriptions.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("subscriptions", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Helper.linkPro(tvSubscriptionPro);
|
|
|
|
|
|
|
|
swSubscribedOnly.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("subscribed_only", checked).apply();
|
2019-12-09 21:26:29 +00:00
|
|
|
ServiceSynchronize.reload(getContext(), null, "subscribed_only");
|
2019-08-17 07:26:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-07-16 12:44:21 +00:00
|
|
|
swCheckMx.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
|
|
|
@Override
|
|
|
|
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
|
|
|
prefs.edit().putBoolean("check_mx", checked).apply();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
2019-05-06 12:41:03 +00:00
|
|
|
@Override
|
|
|
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
2019-09-10 06:53:07 +00:00
|
|
|
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
|
|
|
|
setOptions();
|
2019-05-06 12:41:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
|
|
inflater.inflate(R.menu.menu_options, menu);
|
|
|
|
super.onCreateOptionsMenu(menu, inflater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.menu_default:
|
|
|
|
onMenuDefault();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onMenuDefault() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
for (String option : RESET_OPTIONS)
|
|
|
|
editor.remove(option);
|
|
|
|
editor.apply();
|
2019-07-14 10:32:32 +00:00
|
|
|
ToastEx.makeText(getContext(), R.string.title_setup_done, Toast.LENGTH_LONG).show();
|
2019-05-06 12:41:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-06 07:10:13 +00:00
|
|
|
private void setOptions() {
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
2019-08-17 07:26:45 +00:00
|
|
|
boolean pro = ActivityBilling.isPro(getContext());
|
2019-05-06 07:10:13 +00:00
|
|
|
|
|
|
|
swEnabled.setChecked(prefs.getBoolean("enabled", true));
|
|
|
|
|
|
|
|
int pollInterval = prefs.getInt("poll_interval", 0);
|
|
|
|
int[] pollIntervalValues = getResources().getIntArray(R.array.pollIntervalValues);
|
|
|
|
for (int pos = 0; pos < pollIntervalValues.length; pos++)
|
|
|
|
if (pollIntervalValues[pos] == pollInterval) {
|
|
|
|
spPollInterval.setTag(pollInterval);
|
|
|
|
spPollInterval.setSelection(pos);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-06-28 11:08:04 +00:00
|
|
|
swSchedule.setChecked(prefs.getBoolean("schedule", false) && pro);
|
|
|
|
swSchedule.setEnabled(pro);
|
2019-05-06 07:10:13 +00:00
|
|
|
tvScheduleStart.setText(formatHour(getContext(), prefs.getInt("schedule_start", 0)));
|
|
|
|
tvScheduleEnd.setText(formatHour(getContext(), prefs.getInt("schedule_end", 0)));
|
2019-12-23 10:21:27 +00:00
|
|
|
for (int i = 0; i < 7; i++)
|
|
|
|
cbDay[i].setChecked(prefs.getBoolean("schedule_day" + i, true));
|
2019-05-06 13:25:11 +00:00
|
|
|
|
|
|
|
swUnseen.setChecked(prefs.getBoolean("sync_unseen", false));
|
2019-07-24 14:33:00 +00:00
|
|
|
swFlagged.setChecked(prefs.getBoolean("sync_flagged", false));
|
2019-07-06 16:13:38 +00:00
|
|
|
swDeleteUnseen.setChecked(prefs.getBoolean("delete_unseen", false));
|
2019-06-15 11:14:41 +00:00
|
|
|
swSyncKept.setChecked(prefs.getBoolean("sync_kept", true));
|
2019-06-08 14:33:25 +00:00
|
|
|
swSyncFolders.setChecked(prefs.getBoolean("sync_folders", true));
|
2019-08-17 07:26:45 +00:00
|
|
|
swSubscriptions.setChecked(prefs.getBoolean("subscriptions", false) && pro);
|
|
|
|
swSubscriptions.setEnabled(pro);
|
|
|
|
swSubscribedOnly.setChecked(prefs.getBoolean("subscribed_only", false));
|
2019-07-16 12:44:21 +00:00
|
|
|
swCheckMx.setChecked(prefs.getBoolean("check_mx", false));
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private String formatHour(Context context, int minutes) {
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
cal.set(Calendar.HOUR_OF_DAY, minutes / 60);
|
|
|
|
cal.set(Calendar.MINUTE, minutes % 60);
|
|
|
|
cal.set(Calendar.SECOND, 0);
|
|
|
|
cal.set(Calendar.MILLISECOND, 0);
|
|
|
|
return Helper.getTimeInstance(context, SimpleDateFormat.SHORT).format(cal.getTime());
|
|
|
|
}
|
|
|
|
|
2019-09-11 19:43:27 +00:00
|
|
|
public static class TimePickerFragment extends FragmentDialogBase implements TimePickerDialog.OnTimeSetListener {
|
2019-05-06 07:10:13 +00:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
|
Bundle args = getArguments();
|
|
|
|
boolean start = args.getBoolean("start");
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
int minutes = prefs.getInt("schedule_" + (start ? "start" : "end"), 0);
|
|
|
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
cal.set(Calendar.HOUR_OF_DAY, minutes / 60);
|
|
|
|
cal.set(Calendar.MINUTE, minutes % 60);
|
|
|
|
cal.set(Calendar.SECOND, 0);
|
|
|
|
cal.set(Calendar.MILLISECOND, 0);
|
|
|
|
|
2019-07-05 18:54:07 +00:00
|
|
|
return new TimePickerDialog(getContext(), this,
|
2019-05-06 07:10:13 +00:00
|
|
|
cal.get(Calendar.HOUR_OF_DAY),
|
|
|
|
cal.get(Calendar.MINUTE),
|
2019-07-05 18:54:07 +00:00
|
|
|
DateFormat.is24HourFormat(getContext()));
|
2019-05-06 07:10:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onTimeSet(TimePicker view, int hour, int minute) {
|
|
|
|
Bundle args = getArguments();
|
|
|
|
boolean start = args.getBoolean("start");
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
editor.putInt("schedule_" + (start ? "start" : "end"), hour * 60 + minute);
|
|
|
|
editor.putBoolean("schedule", true);
|
|
|
|
editor.apply();
|
|
|
|
|
|
|
|
ServiceSynchronize.reschedule(getContext());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|