forked from mirrors/Fedilab
Add settings
This commit is contained in:
parent
e8950f03ae
commit
b19cd7c0c9
5 changed files with 53 additions and 52 deletions
|
@ -90,17 +90,13 @@ public class FetchHomeWorker extends Worker {
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<ForegroundInfo> getForegroundInfoAsync() {
|
public ListenableFuture<ForegroundInfo> getForegroundInfoAsync() {
|
||||||
if (Build.VERSION.SDK_INT >= 26) {
|
if (Build.VERSION.SDK_INT >= 26) {
|
||||||
String channelName = "Notifications";
|
String channelName = "Fetch Home";
|
||||||
String channelDescription = "Fetched notifications";
|
String channelDescription = "Fetch home messages";
|
||||||
NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
|
NotificationChannel fetchHomeChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
|
||||||
notifChannel.setDescription(channelDescription);
|
fetchHomeChannel.setDescription(channelDescription);
|
||||||
notifChannel.setSound(null, null);
|
fetchHomeChannel.setSound(null, null);
|
||||||
notifChannel.setShowBadge(false);
|
fetchHomeChannel.setShowBadge(false);
|
||||||
notificationManager.createNotificationChannel(notifChannel);
|
notificationManager.createNotificationChannel(fetchHomeChannel);
|
||||||
if (notificationManager.getNotificationChannel("notifications") != null) {
|
|
||||||
notificationManager.deleteNotificationChannel("notifications");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
|
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
|
||||||
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
|
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
|
||||||
|
@ -115,20 +111,20 @@ public class FetchHomeWorker extends Worker {
|
||||||
@NonNull
|
@NonNull
|
||||||
private ForegroundInfo createForegroundInfo() {
|
private ForegroundInfo createForegroundInfo() {
|
||||||
if (Build.VERSION.SDK_INT >= 26) {
|
if (Build.VERSION.SDK_INT >= 26) {
|
||||||
String channelName = "Notifications";
|
String channelName = "Fetch Home";
|
||||||
String channelDescription = "Fetched notifications";
|
String channelDescription = "Fetch home messages";
|
||||||
NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
|
NotificationChannel fetchHomeChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
|
||||||
notifChannel.setSound(null, null);
|
fetchHomeChannel.setSound(null, null);
|
||||||
notifChannel.setShowBadge(false);
|
fetchHomeChannel.setShowBadge(false);
|
||||||
notifChannel.setDescription(channelDescription);
|
fetchHomeChannel.setDescription(channelDescription);
|
||||||
notificationManager.createNotificationChannel(notifChannel);
|
notificationManager.createNotificationChannel(fetchHomeChannel);
|
||||||
|
|
||||||
}
|
}
|
||||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
|
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
|
||||||
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
|
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher_foreground))
|
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher_foreground))
|
||||||
.setContentTitle(getApplicationContext().getString(R.string.notifications))
|
.setContentTitle(getApplicationContext().getString(R.string.fetch_home_messages))
|
||||||
.setContentText(getApplicationContext().getString(R.string.fetch_notifications))
|
.setContentText(getApplicationContext().getString(R.string.set_fetch_home))
|
||||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||||
.setSilent(true)
|
.setSilent(true)
|
||||||
.setPriority(Notification.PRIORITY_LOW);
|
.setPriority(Notification.PRIORITY_LOW);
|
||||||
|
@ -183,12 +179,7 @@ public class FetchHomeWorker extends Worker {
|
||||||
statusCache.type = Timeline.TimeLineEnum.HOME;
|
statusCache.type = Timeline.TimeLineEnum.HOME;
|
||||||
statusCache.status_id = status.id;
|
statusCache.status_id = status.id;
|
||||||
try {
|
try {
|
||||||
int inserted = statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
|
statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
|
||||||
//We reached already cached messages
|
|
||||||
if (inserted == 0) {
|
|
||||||
canContinue = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -206,6 +197,12 @@ public class FetchHomeWorker extends Worker {
|
||||||
canContinue = false;
|
canContinue = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Pause between calls (1 second)
|
||||||
|
try {
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
call++;
|
call++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
|
||||||
import androidx.work.WorkManager;
|
import androidx.work.WorkManager;
|
||||||
|
|
||||||
import app.fedilab.android.R;
|
import app.fedilab.android.R;
|
||||||
|
@ -53,7 +52,7 @@ public class FragmentHomeCacheSettings extends PreferenceFragmentCompat implemen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
SwitchPreferenceCompat SET_FETCH_HOME = findPreference(getString(R.string.SET_FETCH_HOME));
|
SwitchPreference SET_FETCH_HOME = findPreference(getString(R.string.SET_FETCH_HOME));
|
||||||
if (SET_FETCH_HOME != null) {
|
if (SET_FETCH_HOME != null) {
|
||||||
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, false);
|
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, false);
|
||||||
SET_FETCH_HOME.setChecked(checked);
|
SET_FETCH_HOME.setChecked(checked);
|
||||||
|
@ -69,27 +68,29 @@ public class FragmentHomeCacheSettings extends PreferenceFragmentCompat implemen
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
if (getActivity() != null) {
|
||||||
if (key.compareToIgnoreCase(getString(R.string.SET_FETCH_HOME)) == 0) {
|
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
if (key.compareToIgnoreCase(getString(R.string.SET_FETCH_HOME)) == 0) {
|
||||||
SwitchPreference SET_FETCH_HOME = findPreference(getString(R.string.SET_FETCH_HOME));
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
if (SET_FETCH_HOME != null) {
|
SwitchPreference SET_FETCH_HOME = findPreference(getString(R.string.SET_FETCH_HOME));
|
||||||
editor.putBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, SET_FETCH_HOME.isChecked());
|
if (SET_FETCH_HOME != null) {
|
||||||
editor.commit();
|
editor.putBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, SET_FETCH_HOME.isChecked());
|
||||||
if (SET_FETCH_HOME.isChecked()) {
|
editor.commit();
|
||||||
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
|
if (SET_FETCH_HOME.isChecked()) {
|
||||||
} else {
|
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
|
||||||
WorkManager.getInstance(requireActivity()).cancelAllWorkByTag(Helper.WORKER_REFRESH_HOME + MainActivity.currentUserID + MainActivity.currentInstance);
|
} else {
|
||||||
|
WorkManager.getInstance(requireActivity()).cancelAllWorkByTag(Helper.WORKER_REFRESH_HOME + MainActivity.currentUserID + MainActivity.currentInstance);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (key.compareToIgnoreCase(getString(R.string.SET_FETCH_HOME_DELAY_VALUE)) == 0) {
|
||||||
if (key.compareToIgnoreCase(getString(R.string.SET_FETCH_HOME_DELAY_VALUE)) == 0) {
|
ListPreference SET_FETCH_HOME_DELAY_VALUE = findPreference(getString(R.string.SET_FETCH_HOME_DELAY_VALUE));
|
||||||
ListPreference SET_FETCH_HOME_DELAY_VALUE = findPreference(getString(R.string.SET_FETCH_HOME_DELAY_VALUE));
|
if (SET_FETCH_HOME_DELAY_VALUE != null) {
|
||||||
if (SET_FETCH_HOME_DELAY_VALUE != null) {
|
SharedPreferences.Editor editor = sharedpreferences.edit();
|
||||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
editor.putString(getString(R.string.SET_FETCH_HOME_DELAY_VALUE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_FETCH_HOME_DELAY_VALUE.getValue());
|
||||||
editor.putString(getString(R.string.SET_FETCH_HOME_DELAY_VALUE) + MainActivity.currentUserID + MainActivity.currentInstance, SET_FETCH_HOME_DELAY_VALUE.getValue());
|
editor.commit();
|
||||||
editor.commit();
|
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
|
||||||
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<string name="fetch_home_every">Fetch Home every</string>
|
|
||||||
<string name="type_of_home_delay_title">Home fetch time</string>
|
|
||||||
<string name="set_fetch_home">Automatically fetch home messages</string>
|
|
||||||
<string name="home_cache">Home cache</string>
|
|
||||||
</resources>
|
</resources>
|
|
@ -2236,4 +2236,10 @@
|
||||||
<string name="compose_shortcut_short_label1">Compose</string>
|
<string name="compose_shortcut_short_label1">Compose</string>
|
||||||
<string name="toast_error_peertube_not_supported">Your Peertube is too old and cannot be supported by the app.</string>
|
<string name="toast_error_peertube_not_supported">Your Peertube is too old and cannot be supported by the app.</string>
|
||||||
<string name="otp_message">Two factor authentication token</string>
|
<string name="otp_message">Two factor authentication token</string>
|
||||||
|
|
||||||
|
<string name="fetch_home_every">Fetch Home every</string>
|
||||||
|
<string name="type_of_home_delay_title">Home fetch time</string>
|
||||||
|
<string name="set_fetch_home">Automatically fetch home messages</string>
|
||||||
|
<string name="home_cache">Home cache</string>
|
||||||
|
<string name="fetch_home_messages">Fetch home messages</string>
|
||||||
</resources>
|
</resources>
|
|
@ -4,7 +4,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreference
|
||||||
app:defaultValue="false"
|
app:defaultValue="false"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:key="@string/SET_FETCH_HOME"
|
app:key="@string/SET_FETCH_HOME"
|
||||||
|
|
Loading…
Reference in a new issue