mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
style: code clean up
This commit is contained in:
parent
a3d8b75d07
commit
dacaa03eb7
5 changed files with 29 additions and 24 deletions
|
|
@ -31,6 +31,7 @@ import com.cappielloantonio.tempo.ui.dialog.DeleteDownloadStorageDialog;
|
|||
import com.cappielloantonio.tempo.ui.dialog.DownloadStorageDialog;
|
||||
import com.cappielloantonio.tempo.ui.dialog.StarredSyncDialog;
|
||||
import com.cappielloantonio.tempo.util.DownloadUtil;
|
||||
import com.cappielloantonio.tempo.util.MusicUtil;
|
||||
import com.cappielloantonio.tempo.util.Preferences;
|
||||
import com.cappielloantonio.tempo.util.UIUtil;
|
||||
import com.cappielloantonio.tempo.viewmodel.SettingViewModel;
|
||||
|
|
@ -85,6 +86,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
checkEqualizer();
|
||||
checkStorage();
|
||||
|
||||
setStreamingCacheSize();
|
||||
setAppLanguage();
|
||||
setVersion();
|
||||
|
||||
|
|
@ -114,22 +116,6 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
ListPreference streamingCachePreference = findPreference("streaming_cache_size");
|
||||
if (streamingCachePreference != null) {
|
||||
streamingCachePreference.setSummaryProvider(new Preference.SummaryProvider<ListPreference>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public CharSequence provideSummary(@NonNull ListPreference preference) {
|
||||
CharSequence entry = preference.getEntry();
|
||||
if (entry == null) {
|
||||
return null;
|
||||
}
|
||||
long currentSizeMb = DownloadUtil.getStreamingCacheSize(requireActivity()) / (1024 * 1024);
|
||||
return entry + "\nCurrently in use: " + + currentSizeMb + " MiB\nRestarting is required if changed.";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void checkEqualizer() {
|
||||
|
|
@ -165,6 +151,26 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
}
|
||||
}
|
||||
|
||||
private void setStreamingCacheSize() {
|
||||
ListPreference streamingCachePreference = findPreference("streaming_cache_size");
|
||||
|
||||
if (streamingCachePreference != null) {
|
||||
streamingCachePreference.setSummaryProvider(new Preference.SummaryProvider<ListPreference>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public CharSequence provideSummary(@NonNull ListPreference preference) {
|
||||
CharSequence entry = preference.getEntry();
|
||||
|
||||
if (entry == null) return null;
|
||||
|
||||
long currentSizeMb = DownloadUtil.getStreamingCacheSize(requireActivity()) / (1024 * 1024);
|
||||
|
||||
return getString(R.string.settings_summary_streaming_cache_size, entry, currentSizeMb);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void setAppLanguage() {
|
||||
ListPreference localePref = (ListPreference) findPreference("language");
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,6 @@ public final class DownloadUtil {
|
|||
DefaultDataSource.Factory upstreamFactory = new DefaultDataSource.Factory(context, getHttpDataSourceFactory());
|
||||
|
||||
if (Preferences.getStreamingCacheSize() > 0) {
|
||||
// Cache enabled
|
||||
CacheDataSource.Factory streamCacheFactory = new CacheDataSource.Factory()
|
||||
.setCache(getStreamingCache(context))
|
||||
.setUpstreamDataSourceFactory(upstreamFactory);
|
||||
|
|
@ -97,7 +96,6 @@ public final class DownloadUtil {
|
|||
|
||||
dataSourceFactory = buildReadOnlyCacheDataSource(resolvingFactory, getDownloadCache(context));
|
||||
} else {
|
||||
// Cache disabled
|
||||
dataSourceFactory = buildReadOnlyCacheDataSource(upstreamFactory, getDownloadCache(context));
|
||||
}
|
||||
}
|
||||
|
|
@ -135,12 +133,14 @@ public final class DownloadUtil {
|
|||
private static synchronized SimpleCache getStreamingCache(Context context) {
|
||||
if (streamingCache == null) {
|
||||
File streamingCacheDirectory = new File(context.getCacheDir(), "streamingCache");
|
||||
|
||||
streamingCache = new SimpleCache(
|
||||
streamingCacheDirectory,
|
||||
new LeastRecentlyUsedCacheEvictor(Preferences.getStreamingCacheSize() * 1024 * 1024),
|
||||
getDatabaseProvider(context)
|
||||
);
|
||||
}
|
||||
|
||||
return streamingCache;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -190,9 +190,6 @@ object Preferences {
|
|||
return App.getInstance().preferences.getString(IMAGE_SIZE, "-1")!!.toInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of streaming cache in MiB.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getStreamingCacheSize(): Long {
|
||||
return App.getInstance().preferences.getString(STREAMING_CACHE_SIZE, "256")!!.toLong()
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ class StreamingCacheDataSource private constructor(
|
|||
override fun open(dataSpec: DataSpec): Long {
|
||||
val ret = cacheDataSource.open(dataSpec)
|
||||
currentDataSpec = dataSpec
|
||||
Log.d(TAG, "Opened $currentDataSpec")
|
||||
return ret
|
||||
}
|
||||
|
||||
|
|
@ -45,11 +44,13 @@ class StreamingCacheDataSource private constructor(
|
|||
|
||||
override fun close() {
|
||||
cacheDataSource.close()
|
||||
Log.d(TAG, "Closed $currentDataSpec")
|
||||
|
||||
val dataSpec = currentDataSpec
|
||||
|
||||
if (dataSpec != null) {
|
||||
val cacheKey = cacheDataSource.cacheKeyFactory.buildCacheKey(dataSpec)
|
||||
val contentLength = ContentMetadata.getContentLength(cacheDataSource.cache.getContentMetadata(cacheKey));
|
||||
|
||||
if (contentLength == C.LENGTH_UNSET.toLong()) {
|
||||
Log.d(TAG, "Removing partial cache for $cacheKey")
|
||||
cacheDataSource.cache.removeResource(cacheKey)
|
||||
|
|
|
|||
|
|
@ -288,11 +288,13 @@
|
|||
<string name="settings_scrobble_title">Enable music scrobbling</string>
|
||||
<string name="settings_share_title">Enable music sharing</string>
|
||||
<string name="settings_sub_summary_scrobble">It\'s important to note that scrobbling also relies on the server being enabled to receive this data.</string>
|
||||
<string name="settings_streaming_cache_size">Size of streaming cache</string>
|
||||
<string name="settings_summary_skip_min_star_rating">When listening to an artist\'s radio, an instant mix or when shuffling all, tracks below a certain user rating will be ignored.</string>
|
||||
<string name="settings_summary_replay_gain">Replay gain is a feature that allows you to adjust the volume level of audio tracks for a consistent listening experience. This setting is only effective if the track contains the necessary metadata.</string>
|
||||
<string name="settings_summary_scrobble">Scrobbling is a feature that allows your device to send information about the songs you listen to the music server. This information helps create personalized recommendations based on your music preferences.</string>
|
||||
<string name="settings_summary_share">Allows the user to share music via a link. The functionality must be supported and enabled server-side and is limited to individual tracks, albums and playlists.</string>
|
||||
<string name="settings_summary_syncing">Returns the state of the play queue for this user. This includes the tracks in the play queue, the currently playing track, and the position within this track. The server must support this feature.</string>
|
||||
<string name="settings_summary_streaming_cache_size">%1$s \nCurrently in use: %2$s MiB</string>
|
||||
<string name="settings_summary_transcoding">Priority given to the transcoding mode. If set to \"Direct play\" the bitrate of the file will not be changed.</string>
|
||||
<string name="settings_summary_transcoding_download">Download transcoded media. If enabled, the download endpoint will not be used, but the following settings. \n\n If \"Transcode format for donwloads\" is set to \"Direct download\" the bitrate of the file will not be changed.</string>
|
||||
<string name="settings_summary_transcoding_estimate_content_length">When the file is transcoded on the fly, the client usually does not show the track length. It is possible to request the servers that support the functionality to estimate the duration of the track being played, but the response times may take longer.</string>
|
||||
|
|
@ -377,5 +379,4 @@
|
|||
<string name="undraw_page">unDraw</string>
|
||||
<string name="undraw_thanks">A special thanks goes to unDraw without whose illustrations we could not have made this application more beautiful.</string>
|
||||
<string name="undraw_url">https://undraw.co/</string>
|
||||
<string name="settings_streaming_cache_size">Size of streaming cache</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue