Request remove battery optimization
This commit is contained in:
parent
7195f03501
commit
a655cab7ae
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
|
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||||
<uses-permission
|
<uses-permission
|
||||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||||
tools:ignore="ScopedStorage" />
|
tools:ignore="ScopedStorage" />
|
||||||
|
|
|
@ -169,6 +169,8 @@ public class FetchHomeWorker extends Worker {
|
||||||
int call = 0;
|
int call = 0;
|
||||||
String max_id = null;
|
String max_id = null;
|
||||||
MastodonTimelinesService mastodonTimelinesService = init(account.instance);
|
MastodonTimelinesService mastodonTimelinesService = init(account.instance);
|
||||||
|
int insertValue = 0;
|
||||||
|
StatusCache lastStatusCache = null;
|
||||||
while (canContinue && call < max_calls) {
|
while (canContinue && call < max_calls) {
|
||||||
Call<List<Status>> homeCall = mastodonTimelinesService.getHome(account.token, max_id, null, null, status_per_page, null);
|
Call<List<Status>> homeCall = mastodonTimelinesService.getHome(account.token, max_id, null, null, status_per_page, null);
|
||||||
if (homeCall != null) {
|
if (homeCall != null) {
|
||||||
|
@ -184,12 +186,14 @@ public class FetchHomeWorker extends Worker {
|
||||||
statusCache.status = status;
|
statusCache.status = status;
|
||||||
statusCache.type = Timeline.TimeLineEnum.HOME;
|
statusCache.type = Timeline.TimeLineEnum.HOME;
|
||||||
statusCache.status_id = status.id;
|
statusCache.status_id = status.id;
|
||||||
|
lastStatusCache = statusCache;
|
||||||
try {
|
try {
|
||||||
statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
|
insertValue = statusCacheDAO.insertOrUpdate(statusCache, Timeline.TimeLineEnum.HOME.getValue());
|
||||||
} catch (DBException e) {
|
} catch (DBException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Pagination pagination = MastodonHelper.getPagination(homeResponse.headers());
|
Pagination pagination = MastodonHelper.getPagination(homeResponse.headers());
|
||||||
if (pagination.max_id != null) {
|
if (pagination.max_id != null) {
|
||||||
max_id = pagination.max_id;
|
max_id = pagination.max_id;
|
||||||
|
@ -211,6 +215,17 @@ public class FetchHomeWorker extends Worker {
|
||||||
}
|
}
|
||||||
call++;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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,
|
* You should have received a copy of the GNU General Public License along with Fedilab; if not,
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
import static android.content.Context.POWER_SERVICE;
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
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");
|
Preference button_mention = findPreference("button_mention");
|
||||||
assert button_mention != null;
|
assert button_mention != null;
|
||||||
button_mention.setOnPreferenceClickListener(preference -> {
|
button_mention.setOnPreferenceClickListener(preference -> {
|
||||||
|
|
|
@ -840,6 +840,8 @@
|
||||||
<string name="SET_NOTIFICATION_TYPE" translatable="false">SET_NOTIFICATION_TYPE</string>
|
<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_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_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 name="SET_PUSH_DISTRIBUTOR" translatable="false">SET_PUSH_DISTRIBUTOR</string>
|
||||||
<string-array name="SET_NOTIFICATION_TYPE_VALUE" translatable="false">
|
<string-array name="SET_NOTIFICATION_TYPE_VALUE" translatable="false">
|
||||||
<item>PUSH_NOTIFICATIONS</item>
|
<item>PUSH_NOTIFICATIONS</item>
|
||||||
|
@ -1923,4 +1925,5 @@
|
||||||
<string name="set_alt_text_mandatory_warn">Warn only</string>
|
<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="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="send_anyway">Send anyway</string>
|
||||||
|
<string name="set_remove_battery">Ignore battery optimizations</string>
|
||||||
</resources>
|
</resources>
|
|
@ -33,6 +33,11 @@
|
||||||
app:key="@string/SET_PUSH_DISTRIBUTOR"
|
app:key="@string/SET_PUSH_DISTRIBUTOR"
|
||||||
app:title="@string/push_distributors"
|
app:title="@string/push_distributors"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
app:key="@string/SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS"
|
||||||
|
app:title="@string/set_remove_battery" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
Added:
|
Added:
|
||||||
- Settings compose: display a dialog to warn if there are missing media description (default disabled)
|
- Settings compose: display a dialog to warn if there are missing media description (default disabled)
|
||||||
|
- Settings > Notification: disable battery optimization
|
||||||
|
|
||||||
Changed:
|
Changed:
|
||||||
-
|
-
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
|
- Fix an issue with cache and fetch more
|
||||||
- Cache view with large fonts
|
- Cache view with large fonts
|
||||||
- Bad behaviors with truncated messages
|
- Bad behaviors with truncated messages
|
Loading…
Reference in New Issue