mirror of
https://codeberg.org/tom79/Fedilab.git
synced 2025-01-03 06:30:07 +02:00
Add ignore battery optimizations in cache settings
This commit is contained in:
parent
8548e6f098
commit
2687f85935
2 changed files with 37 additions and 0 deletions
|
@ -15,9 +15,15 @@ package app.fedilab.android.mastodon.ui.fragment.settings;
|
||||||
* see <http://www.gnu.org/licenses>. */
|
* see <http://www.gnu.org/licenses>. */
|
||||||
|
|
||||||
|
|
||||||
|
import static android.content.Context.POWER_SERVICE;
|
||||||
|
|
||||||
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.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PowerManager;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
@ -77,6 +83,30 @@ public class FragmentHomeCacheSettings extends PreferenceFragmentCompat implemen
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,4 +30,11 @@
|
||||||
app:icon="@drawable/baseline_show_chart_24"
|
app:icon="@drawable/baseline_show_chart_24"
|
||||||
app:iconSpaceReserved="false"
|
app:iconSpaceReserved="false"
|
||||||
app:key="@string/pref_category_show_data" />
|
app:key="@string/pref_category_show_data" />
|
||||||
|
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
app:iconSpaceReserved="false"
|
||||||
|
app:key="@string/SET_KEY_IGNORE_BATTERY_OPTIMIZATIONS"
|
||||||
|
app:title="@string/set_remove_battery" />
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in a new issue