mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
feat: added an option to prevent phone from going into sleep mode if in-app
This commit is contained in:
parent
cd44368d66
commit
634de67d74
5 changed files with 35 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
@ -37,6 +38,7 @@ public class BaseActivity extends AppCompatActivity {
|
||||||
initializeDownloader();
|
initializeDownloader();
|
||||||
checkBatteryOptimization();
|
checkBatteryOptimization();
|
||||||
checkPermission();
|
checkPermission();
|
||||||
|
checkAlwaysOnDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -66,6 +68,12 @@ public class BaseActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAlwaysOnDisplay() {
|
||||||
|
if (Preferences.isDisplayAlwaysOn()) {
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean detectBatteryOptimization() {
|
private boolean detectBatteryOptimization() {
|
||||||
String packageName = getPackageName();
|
String packageName = getPackageName();
|
||||||
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import androidx.activity.result.ActivityResultLauncher;
|
import androidx.activity.result.ActivityResultLauncher;
|
||||||
import androidx.activity.result.contract.ActivityResultContracts;
|
import androidx.activity.result.contract.ActivityResultContracts;
|
||||||
|
|
@ -91,6 +92,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
actionSyncStarredTracks();
|
actionSyncStarredTracks();
|
||||||
actionChangeDownloadStorage();
|
actionChangeDownloadStorage();
|
||||||
actionDeleteDownloadStorage();
|
actionDeleteDownloadStorage();
|
||||||
|
actionKeepScreenOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -248,4 +250,17 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void actionKeepScreenOn() {
|
||||||
|
findPreference("always_on_display").setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
|
if (newValue instanceof Boolean) {
|
||||||
|
if ((Boolean) newValue) {
|
||||||
|
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
} else {
|
||||||
|
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ object Preferences {
|
||||||
private const val SKIP_MIN_STAR_RATING = "skip_min_star_rating"
|
private const val SKIP_MIN_STAR_RATING = "skip_min_star_rating"
|
||||||
private const val MIN_STAR_RATING = "min_star_rating"
|
private const val MIN_STAR_RATING = "min_star_rating"
|
||||||
private const val ARTIST_ALBUM_LAYOUT = "artist_album_layout"
|
private const val ARTIST_ALBUM_LAYOUT = "artist_album_layout"
|
||||||
|
private const val ALWAYS_ON_DISPLAY = "always_on_display"
|
||||||
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
@ -357,4 +358,9 @@ object Preferences {
|
||||||
App.getInstance().preferences.edit().putBoolean(ARTIST_ALBUM_LAYOUT, isArtistAlbumLayoutHorizontal)
|
App.getInstance().preferences.edit().putBoolean(ARTIST_ALBUM_LAYOUT, isArtistAlbumLayoutHorizontal)
|
||||||
.apply()
|
.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
fun isDisplayAlwaysOn(): Boolean {
|
||||||
|
return App.getInstance().preferences.getBoolean(ALWAYS_ON_DISPLAY, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -224,6 +224,7 @@
|
||||||
<string name="server_unreachable_dialog_title">Server unreachable</string>
|
<string name="server_unreachable_dialog_title">Server unreachable</string>
|
||||||
<string name="settings_about_summary">Tempo is an open source and lightweight music client for Subsonic, designed and built natively for Android.</string>
|
<string name="settings_about_summary">Tempo is an open source and lightweight music client for Subsonic, designed and built natively for Android.</string>
|
||||||
<string name="settings_about_title">About</string>
|
<string name="settings_about_title">About</string>
|
||||||
|
<string name="settings_always_on_display">Always on display</string>
|
||||||
<string name="settings_audio_transcode_download_format">Transcode format</string>
|
<string name="settings_audio_transcode_download_format">Transcode format</string>
|
||||||
<string name="settings_audio_transcode_download_priority_summary">If enabled, Tempo will not force download the track with the transcode settings below.</string>
|
<string name="settings_audio_transcode_download_priority_summary">If enabled, Tempo will not force download the track with the transcode settings below.</string>
|
||||||
<string name="settings_audio_transcode_download_priority_title">Prioritize server settings used for streaming in downloads</string>
|
<string name="settings_audio_transcode_download_priority_title">Prioritize server settings used for streaming in downloads</string>
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@
|
||||||
app:title="@string/settings_theme"
|
app:title="@string/settings_theme"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
|
||||||
|
<SwitchPreference
|
||||||
|
android:title="@string/settings_always_on_display"
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:key="always_on_display" />
|
||||||
|
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:title="@string/settings_rounded_corner"
|
android:title="@string/settings_rounded_corner"
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue