Add settings

media_preview
Thomas 2 years ago
parent e8950f03ae
commit b19cd7c0c9

@ -90,17 +90,13 @@ public class FetchHomeWorker extends Worker {
@Override
public ListenableFuture<ForegroundInfo> getForegroundInfoAsync() {
if (Build.VERSION.SDK_INT >= 26) {
String channelName = "Notifications";
String channelDescription = "Fetched notifications";
NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
notifChannel.setDescription(channelDescription);
notifChannel.setSound(null, null);
notifChannel.setShowBadge(false);
notificationManager.createNotificationChannel(notifChannel);
if (notificationManager.getNotificationChannel("notifications") != null) {
notificationManager.deleteNotificationChannel("notifications");
}
String channelName = "Fetch Home";
String channelDescription = "Fetch home messages";
NotificationChannel fetchHomeChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
fetchHomeChannel.setDescription(channelDescription);
fetchHomeChannel.setSound(null, null);
fetchHomeChannel.setShowBadge(false);
notificationManager.createNotificationChannel(fetchHomeChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
@ -115,20 +111,20 @@ public class FetchHomeWorker extends Worker {
@NonNull
private ForegroundInfo createForegroundInfo() {
if (Build.VERSION.SDK_INT >= 26) {
String channelName = "Notifications";
String channelDescription = "Fetched notifications";
NotificationChannel notifChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
notifChannel.setSound(null, null);
notifChannel.setShowBadge(false);
notifChannel.setDescription(channelDescription);
notificationManager.createNotificationChannel(notifChannel);
String channelName = "Fetch Home";
String channelDescription = "Fetch home messages";
NotificationChannel fetchHomeChannel = new NotificationChannel(CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_LOW);
fetchHomeChannel.setSound(null, null);
fetchHomeChannel.setShowBadge(false);
fetchHomeChannel.setDescription(channelDescription);
notificationManager.createNotificationChannel(fetchHomeChannel);
}
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getApplicationContext(), CHANNEL_ID);
notificationBuilder.setSmallIcon(R.drawable.ic_notification)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher_foreground))
.setContentTitle(getApplicationContext().getString(R.string.notifications))
.setContentText(getApplicationContext().getString(R.string.fetch_notifications))
.setContentTitle(getApplicationContext().getString(R.string.fetch_home_messages))
.setContentText(getApplicationContext().getString(R.string.set_fetch_home))
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setSilent(true)
.setPriority(Notification.PRIORITY_LOW);
@ -183,12 +179,7 @@ public class FetchHomeWorker extends Worker {
statusCache.type = Timeline.TimeLineEnum.HOME;
statusCache.status_id = status.id;
try {
int inserted = statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
//We reached already cached messages
if (inserted == 0) {
canContinue = false;
break;
}
statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
} catch (DBException e) {
e.printStackTrace();
}
@ -206,6 +197,12 @@ public class FetchHomeWorker extends Worker {
canContinue = false;
}
}
//Pause between calls (1 second)
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
call++;
}

@ -23,7 +23,6 @@ import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import androidx.preference.SwitchPreferenceCompat;
import androidx.work.WorkManager;
import app.fedilab.android.R;
@ -53,7 +52,7 @@ public class FragmentHomeCacheSettings extends PreferenceFragmentCompat implemen
return;
}
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) {
boolean checked = sharedpreferences.getBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, false);
SET_FETCH_HOME.setChecked(checked);
@ -69,27 +68,29 @@ public class FragmentHomeCacheSettings extends PreferenceFragmentCompat implemen
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.compareToIgnoreCase(getString(R.string.SET_FETCH_HOME)) == 0) {
SharedPreferences.Editor editor = sharedPreferences.edit();
SwitchPreference SET_FETCH_HOME = findPreference(getString(R.string.SET_FETCH_HOME));
if (SET_FETCH_HOME != null) {
editor.putBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, SET_FETCH_HOME.isChecked());
editor.commit();
if (SET_FETCH_HOME.isChecked()) {
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
} else {
WorkManager.getInstance(requireActivity()).cancelAllWorkByTag(Helper.WORKER_REFRESH_HOME + MainActivity.currentUserID + MainActivity.currentInstance);
if (getActivity() != null) {
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
if (key.compareToIgnoreCase(getString(R.string.SET_FETCH_HOME)) == 0) {
SharedPreferences.Editor editor = sharedpreferences.edit();
SwitchPreference SET_FETCH_HOME = findPreference(getString(R.string.SET_FETCH_HOME));
if (SET_FETCH_HOME != null) {
editor.putBoolean(getString(R.string.SET_FETCH_HOME) + MainActivity.currentUserID + MainActivity.currentInstance, SET_FETCH_HOME.isChecked());
editor.commit();
if (SET_FETCH_HOME.isChecked()) {
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
} 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) {
ListPreference SET_FETCH_HOME_DELAY_VALUE = findPreference(getString(R.string.SET_FETCH_HOME_DELAY_VALUE));
if (SET_FETCH_HOME_DELAY_VALUE != null) {
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.commit();
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
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));
if (SET_FETCH_HOME_DELAY_VALUE != null) {
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.commit();
FetchHomeWorker.setRepeatHome(requireActivity(), MainActivity.currentAccount);
}
}
}
}

@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<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>

@ -2236,4 +2236,10 @@
<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="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>

@ -4,7 +4,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<SwitchPreferenceCompat
<SwitchPreference
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_FETCH_HOME"

Loading…
Cancel
Save