summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2023-02-28 16:10:24 +0100
committerThomas <tschneider.ac@gmail.com>2023-02-28 16:10:24 +0100
commita655cab7aefb281e710ba6363729a9705805817b (patch)
tree63fb925d17a35999558f97f1a6d7329d5a3f8d5f
parent7195f03501bbe7c2da405a9ecb2ac6bafbdc59a2 (diff)
Request remove battery optimization
-rw-r--r--app/src/main/AndroidManifest.xml1
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/jobs/FetchHomeWorker.java17
-rw-r--r--app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentNotificationsSettings.java26
-rw-r--r--app/src/main/res/values/strings.xml3
-rw-r--r--app/src/main/res/xml/pref_notifications.xml5
-rw-r--r--src/fdroid/fastlane/metadata/android/en/changelogs/482.txt3
6 files changed, 53 insertions, 2 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 399f8770b..4b06ef7cc 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
+ <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
diff --git a/app/src/main/java/app/fedilab/android/mastodon/jobs/FetchHomeWorker.java b/app/src/main/java/app/fedilab/android/mastodon/jobs/FetchHomeWorker.java
index 5b2e899a6..422f1e99e 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/jobs/FetchHomeWorker.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/jobs/FetchHomeWorker.java
@@ -169,6 +169,8 @@ public class FetchHomeWorker extends Worker {
int call = 0;
String max_id = null;
MastodonTimelinesService mastodonTimelinesService = init(account.instance);
+ int insertValue = 0;
+ StatusCache lastStatusCache = null;
while (canContinue && call < max_calls) {
Call<List<Status>> homeCall = mastodonTimelinesService.getHome(account.token, max_id, null, null, status_per_page, null);
if (homeCall != null) {
@@ -184,12 +186,14 @@ public class FetchHomeWorker extends Worker {
statusCache.status = status;
statusCache.type = Timeline.TimeLineEnum.HOME;
statusCache.status_id = status.id;
+ lastStatusCache = statusCache;
try {
- statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
+ insertValue = statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
} catch (DBException e) {
e.printStackTrace();
}
}
+
Pagination pagination = MastodonHelper.getPagination(homeResponse.headers());
if (pagination.max_id != null) {
max_id = pagination.max_id;
@@ -211,6 +215,17 @@ public class FetchHomeWorker extends Worker {
}
call++;
}
+ //insertValue is for last status and equals zero if updated or 1 if inserted
+ if (lastStatusCache != null && insertValue == 1) { //Last inserted message was not in cache.
+ StatusCache statusCacheDAO = new StatusCache(getApplicationContext());
+ lastStatusCache.status.isFetchMore = true;
+ lastStatusCache.status.positionFetchMore = Status.PositionFetchMore.TOP;
+ try {
+ statusCacheDAO.updateIfExists(lastStatusCache);
+ } catch (DBException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
}
diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentNotificationsSettings.java b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentNotificationsSettings.java
index be4b82288..a665adc93 100644
--- a/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentNotificationsSettings.java
+++ b/app/src/main/java/app/fedilab/android/mastodon/ui/fragment/settings/FragmentNotificationsSettings.java
@@ -14,12 +14,16 @@ package app.fedilab.android.mastodon.ui.fragment.settings;
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
* see <http://www.gnu.org/licenses>. */
+import static android.content.Context.POWER_SERVICE;
+
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.os.PowerManager;
import android.provider.Settings;
import androidx.annotation.NonNull;
@@ -121,6 +125,28 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl
}
}
+ Preference SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS = findPreference(getString(R.string.SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS));
+ if (SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS != null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ PowerManager pm = (PowerManager) requireActivity().getSystemService(POWER_SERVICE);
+ String packageName = requireActivity().getPackageName();
+ if (!pm.isIgnoringBatteryOptimizations(packageName)) {
+ SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS.setOnPreferenceClickListener(preference -> {
+ Intent intent = new Intent();
+ String packageName1 = requireActivity().getPackageName();
+ intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
+ intent.setData(Uri.parse("package:" + packageName1));
+ startActivity(intent);
+ return false;
+ });
+ } else {
+ preferenceScreen.removePreferenceRecursively(getString(R.string.SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS));
+ }
+ } else {
+ preferenceScreen.removePreferenceRecursively(getString(R.string.SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS));
+ }
+ }
+
Preference button_mention = findPreference("button_mention");
assert button_mention != null;
button_mention.setOnPreferenceClickListener(preference -> {
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 33c2dfcea..a7955120e 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -840,6 +840,8 @@
<string name="SET_NOTIFICATION_TYPE" translatable="false">SET_NOTIFICATION_TYPE</string>
<string name="SET_LOAD_MEDIA_TYPE" translatable="false">SET_LOAD_MEDIA_TYPE</string>
<string name="SET_NOTIFICATION_DELAY_VALUE" translatable="false">SET_NOTIFICATION_DELAY_VALUE</string>
+ <string name="SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS" translatable="false">SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS</string>
+
<string name="SET_PUSH_DISTRIBUTOR" translatable="false">SET_PUSH_DISTRIBUTOR</string>
<string-array name="SET_NOTIFICATION_TYPE_VALUE" translatable="false">
<item>PUSH_NOTIFICATIONS</item>
@@ -1923,4 +1925,5 @@
<string name="set_alt_text_mandatory_warn">Warn only</string>
<string name="set_alt_text_mandatory_description_warn">If there are missing media a dialog will be displayed with the ability to send the message without media description</string>
<string name="send_anyway">Send anyway</string>
+ <string name="set_remove_battery">Ignore battery optimizations</string>
</resources> \ No newline at end of file
diff --git a/app/src/main/res/xml/pref_notifications.xml b/app/src/main/res/xml/pref_notifications.xml
index 3dea8a05b..7ae5fcfc5 100644
--- a/app/src/main/res/xml/pref_notifications.xml
+++ b/app/src/main/res/xml/pref_notifications.xml
@@ -33,6 +33,11 @@
app:key="@string/SET_PUSH_DISTRIBUTOR"
app:title="@string/push_distributors"
app:useSimpleSummaryProvider="true" />
+
+ <Preference
+ app:iconSpaceReserved="false"
+ app:key="@string/SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS"
+ app:title="@string/set_remove_battery" />
</PreferenceCategory>
diff --git a/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt b/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt
index 020553135..755e5e4ec 100644
--- a/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt
+++ b/src/fdroid/fastlane/metadata/android/en/changelogs/482.txt
@@ -1,10 +1,11 @@
Added:
- Settings compose: display a dialog to warn if there are missing media description (default disabled)
-
+- Settings > Notification: disable battery optimization
Changed:
-
Fixed:
+- Fix an issue with cache and fetch more
- Cache view with large fonts
- Bad behaviors with truncated messages \ No newline at end of file