mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Added automation support
This commit is contained in:
parent
572607a76b
commit
582ce275db
6 changed files with 115 additions and 19 deletions
23
FAQ.md
23
FAQ.md
|
@ -136,7 +136,8 @@ FairEmail follows all the best practices for an email client as decribed in [thi
|
|||
* [(74) Why do I see duplicate messages?](#user-content-faq74)
|
||||
* [(75) Can you make an iOS, Windows, etc version?](#user-content-faq75)
|
||||
* [(76) What does 'Clear local messages' ?](#user-content-faq76)
|
||||
* [(77) Why are messages sometimes shown with a small delay?](#user-content-faq76)
|
||||
* [(77) Why are messages sometimes shown with a small delay?](#user-content-faq77)
|
||||
* [(78) How do I use schedules?](#user-content-faq78)
|
||||
|
||||
[I have another question.](#support)
|
||||
|
||||
|
@ -1241,6 +1242,26 @@ so there is little room for performance improvements.
|
|||
|
||||
<br />
|
||||
|
||||
<a name="faq78"></a>
|
||||
**(78) How do I use schedules?**
|
||||
|
||||
In the advanced options you can enable scheduling and set the time to turn synchronizing automatically on and off.
|
||||
|
||||
An end time equal to or earlier than the start time is considered to be 24 hours later.
|
||||
|
||||
You can also automate turning synchronization on and off by sending these commands to FairEmail:
|
||||
|
||||
```
|
||||
(adb shell) am startservice -a eu.faircode.email.ENABLE
|
||||
(adb shell) am startservice -a eu.faircode.email.DISABLE
|
||||
```
|
||||
|
||||
Sending these commands will automatically turn scheduling off.
|
||||
|
||||
Scheduling is a pro feature.
|
||||
|
||||
<br />
|
||||
|
||||
## Support
|
||||
|
||||
If you have another question, want to request a feature or report a bug, you can use [this forum](https://forum.xda-developers.com/android/apps-games/source-email-t3824168).
|
||||
|
|
|
@ -163,6 +163,13 @@
|
|||
|
||||
<service android:name=".ServiceSynchronize" />
|
||||
|
||||
<service android:name=".ServiceExternal">
|
||||
<intent-filter>
|
||||
<action android:name="eu.faircode.email.ENABLE" />
|
||||
<action android:name="eu.faircode.email.DISABLE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<service
|
||||
android:name=".JobDaily"
|
||||
android:exported="true"
|
||||
|
|
|
@ -63,6 +63,7 @@ import static android.app.Activity.RESULT_OK;
|
|||
|
||||
public class FragmentOptions extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private SwitchCompat swEnabled;
|
||||
private SwitchCompat swSchedule;
|
||||
private TextView tvScheduleStart;
|
||||
private TextView tvScheduleEnd;
|
||||
|
||||
|
@ -131,6 +132,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
|
||||
// Get controls
|
||||
swEnabled = view.findViewById(R.id.swEnabled);
|
||||
swSchedule = view.findViewById(R.id.swSchedule);
|
||||
tvScheduleStart = view.findViewById(R.id.tvScheduleStart);
|
||||
tvScheduleEnd = view.findViewById(R.id.tvScheduleEnd);
|
||||
|
||||
|
@ -185,6 +187,19 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
}
|
||||
});
|
||||
|
||||
swSchedule.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("schedule", checked).apply();
|
||||
if (checked)
|
||||
ServiceSynchronize.schedule(getContext());
|
||||
else {
|
||||
prefs.edit().putBoolean("enabled", true).apply();
|
||||
ServiceSynchronize.reload(getContext(), "schedule=" + checked);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tvScheduleStart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -513,6 +528,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
|
||||
swEnabled.setChecked(prefs.getBoolean("enabled", true));
|
||||
swSchedule.setChecked(prefs.getBoolean("schedule", false));
|
||||
|
||||
tvScheduleStart.setText(formatHour(prefs.getInt("schedule_start", 0)));
|
||||
tvScheduleEnd.setText(formatHour(prefs.getInt("schedule_end", 0)));
|
||||
|
@ -601,7 +617,10 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
boolean start = args.getBoolean("start");
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
prefs.edit().putInt("schedule_" + (start ? "start" : "end"), hour * 60 + minute).apply();
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putInt("schedule_" + (start ? "start" : "end"), hour * 60 + minute);
|
||||
editor.putBoolean("schedule", true);
|
||||
editor.apply();
|
||||
|
||||
ServiceSynchronize.schedule(getContext());
|
||||
}
|
||||
|
@ -624,7 +643,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
}
|
||||
};
|
||||
|
||||
public void showConnectionType() {
|
||||
private void showConnectionType() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity == null)
|
||||
return;
|
||||
|
@ -665,6 +684,8 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if ("enabled".equals(key))
|
||||
swEnabled.setChecked(prefs.getBoolean(key, true));
|
||||
else if ("schedule".equals(key))
|
||||
swSchedule.setChecked(prefs.getBoolean(key, false));
|
||||
else if ("schedule_start".equals(key))
|
||||
tvScheduleStart.setText(formatHour(prefs.getInt(key, 0)));
|
||||
else if ("schedule_end".equals(key))
|
||||
|
|
46
app/src/main/java/eu/faircode/email/ServiceExternal.java
Normal file
46
app/src/main/java/eu/faircode/email/ServiceExternal.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package eu.faircode.email;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ServiceExternal extends IntentService {
|
||||
private final static String ACTION_ENABLE = "eu.faircode.email.ENABLE";
|
||||
private final static String ACTION_DISABLE = "eu.faircode.email.DISABLE";
|
||||
|
||||
// adb shell am startservice -a eu.faircode.email.ENABLE
|
||||
// adb shell am startservice -a eu.faircode.email.DISABLE
|
||||
|
||||
public ServiceExternal() {
|
||||
super(ServiceExternal.class.getName());
|
||||
}
|
||||
|
||||
public ServiceExternal(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(@Nullable Intent intent) {
|
||||
if (intent == null)
|
||||
return;
|
||||
|
||||
Boolean enabled = null;
|
||||
if (ACTION_ENABLE.equals(intent.getAction()))
|
||||
enabled = true;
|
||||
else if (ACTION_DISABLE.equals(intent.getAction()))
|
||||
enabled = false;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean previous = prefs.getBoolean("enabled", true);
|
||||
if (enabled != null) {
|
||||
prefs.edit().putBoolean("schedule", false).apply();
|
||||
if (!enabled.equals(previous)) {
|
||||
prefs.edit().putBoolean("enabled", enabled).apply();
|
||||
ServiceSynchronize.reload(this, "external");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3239,6 +3239,9 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
am.cancel(piSchedule);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);
|
||||
if (!prefs.getBoolean("schedule", false))
|
||||
return;
|
||||
|
||||
int minuteStart = prefs.getInt("schedule_start", 0);
|
||||
int minuteEnd = prefs.getInt("schedule_end", 0);
|
||||
|
||||
|
|
|
@ -57,41 +57,39 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swEnabled" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSchedule"
|
||||
android:layout_width="wrap_content"
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swSchedule"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:text="@string/title_advanced_schedule"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvScheduleStart"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvScheduleStart" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvEnabledHint"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvScheduleStart"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:padding="12dp"
|
||||
android:text="00:00"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvScheduleSeparator"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvEnabledHint" />
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swSchedule" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvScheduleSeparator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="—"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvScheduleStart"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvScheduleEnd"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvScheduleStart" />
|
||||
app:layout_constraintStart_toEndOf="@id/tvScheduleStart"
|
||||
app:layout_constraintTop_toTopOf="@id/tvScheduleStart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvScheduleEnd"
|
||||
|
@ -101,8 +99,8 @@
|
|||
android:text="00:00"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvEnabledHint" />
|
||||
app:layout_constraintStart_toEndOf="@id/tvScheduleSeparator"
|
||||
app:layout_constraintTop_toTopOf="@id/tvScheduleStart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvScheduleHint"
|
||||
|
@ -115,7 +113,7 @@
|
|||
android:textStyle="italic"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvScheduleEnd" />
|
||||
app:layout_constraintTop_toBottomOf="@id/tvScheduleStart" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvSectionConnection"
|
||||
|
|
Loading…
Add table
Reference in a new issue