mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
added a function that generates pseudo-random numbers that change every x hours
This commit is contained in:
parent
a7fd7688ab
commit
40e9a6f778
4 changed files with 40 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package com.cappielloantonio.play.ui.fragment;
|
package com.cappielloantonio.play.ui.fragment;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
@ -24,6 +25,7 @@ import com.cappielloantonio.play.adapter.YearAdapter;
|
||||||
import com.cappielloantonio.play.databinding.FragmentHomeBinding;
|
import com.cappielloantonio.play.databinding.FragmentHomeBinding;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.ui.activities.MainActivity;
|
import com.cappielloantonio.play.ui.activities.MainActivity;
|
||||||
|
import com.cappielloantonio.play.util.MusicUtil;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
import com.cappielloantonio.play.viewmodel.HomeViewModel;
|
import com.cappielloantonio.play.viewmodel.HomeViewModel;
|
||||||
|
|
||||||
|
|
@ -113,6 +115,8 @@ public class HomeFragment extends Fragment {
|
||||||
bind.discoverSongViewPager.setAdapter(discoverSongAdapter);
|
bind.discoverSongViewPager.setAdapter(discoverSongAdapter);
|
||||||
bind.discoverSongViewPager.setOffscreenPageLimit(3);
|
bind.discoverSongViewPager.setOffscreenPageLimit(3);
|
||||||
setDiscoverSongSlideViewOffset(20, 16);
|
setDiscoverSongSlideViewOffset(20, 16);
|
||||||
|
|
||||||
|
Log.i(TAG, "initDiscoverSongSlideView: " + MusicUtil.getRandomSongNumber(requireContext(), 10, 3));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMostPlayedSongView() {
|
private void initMostPlayedSongView() {
|
||||||
|
|
|
||||||
|
|
@ -204,6 +204,7 @@ public class SyncFragment extends Fragment {
|
||||||
songRepository.deleteAllSongGenreCross();
|
songRepository.deleteAllSongGenreCross();
|
||||||
songRepository.insertAll((ArrayList<Song>) media);
|
songRepository.insertAll((ArrayList<Song>) media);
|
||||||
syncSongArtistCross((ArrayList<Song>) media);
|
syncSongArtistCross((ArrayList<Song>) media);
|
||||||
|
PreferenceUtil.getInstance(requireContext()).setSongNumber(media.size());
|
||||||
animateProgressBar(true);
|
animateProgressBar(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.cappielloantonio.play.util;
|
package com.cappielloantonio.play.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
|
@ -10,7 +11,10 @@ import com.cappielloantonio.play.model.Song;
|
||||||
|
|
||||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class MusicUtil {
|
public class MusicUtil {
|
||||||
public static String getSongFileUri(Song song) {
|
public static String getSongFileUri(Song song) {
|
||||||
|
|
@ -86,4 +90,23 @@ public class MusicUtil {
|
||||||
return R.drawable.default_album_art;
|
return R.drawable.default_album_art;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Integer> getRandomSongNumber(Context context, int numberOfNumbers, int refreshAfterXHours) {
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < numberOfNumbers; i++)
|
||||||
|
{
|
||||||
|
list.add(getRandomNumber(0, PreferenceUtil.getInstance(context).getSongNumber(), getMidnightTimestamp(System.currentTimeMillis() / 1000, refreshAfterXHours) + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long getMidnightTimestamp(long timestamp, int hours) {
|
||||||
|
return timestamp - timestamp % (hours * 60 * 60); // 24 * 60 * 60 sec in one day
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getRandomNumber(int min, int max, long seed) {
|
||||||
|
return new Random(seed).nextInt((max - min) + 1) + min;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ public class PreferenceUtil {
|
||||||
public static final String MAXIMUM_BITRATE = "maximum_bitrate";
|
public static final String MAXIMUM_BITRATE = "maximum_bitrate";
|
||||||
public static final String AUDIO_DUCKING = "audio_ducking";
|
public static final String AUDIO_DUCKING = "audio_ducking";
|
||||||
|
|
||||||
|
public static final String SONG_NUMBER = "SONG_NUMBER";
|
||||||
|
|
||||||
private static PreferenceUtil sInstance;
|
private static PreferenceUtil sInstance;
|
||||||
private final SharedPreferences mPreferences;
|
private final SharedPreferences mPreferences;
|
||||||
|
|
||||||
|
|
@ -175,4 +177,14 @@ public class PreferenceUtil {
|
||||||
public final boolean getAudioDucking() {
|
public final boolean getAudioDucking() {
|
||||||
return mPreferences.getBoolean(AUDIO_DUCKING, true);
|
return mPreferences.getBoolean(AUDIO_DUCKING, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getSongNumber() {
|
||||||
|
return mPreferences.getInt(SONG_NUMBER, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSongNumber(int number) {
|
||||||
|
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||||
|
editor.putInt(SONG_NUMBER, number);
|
||||||
|
editor.apply();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue