mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 02:13:33 +00:00
Multi server/user implementation
This commit is contained in:
parent
4e269a7446
commit
78a4006ed6
30 changed files with 959 additions and 192 deletions
|
|
@ -275,17 +275,19 @@ public class AlbumRepository {
|
|||
|
||||
getFirstAlbum(first -> {
|
||||
getLastAlbum(last -> {
|
||||
List<Integer> decadeList = new ArrayList();
|
||||
if(first != -1 && last != -1) {
|
||||
List<Integer> decadeList = new ArrayList();
|
||||
|
||||
int startDecade = first - (first % 10);
|
||||
int lastDecade = last - (last % 10);
|
||||
int startDecade = first - (first % 10);
|
||||
int lastDecade = last - (last % 10);
|
||||
|
||||
while (startDecade <= lastDecade) {
|
||||
decadeList.add(startDecade);
|
||||
startDecade = startDecade + 10;
|
||||
while (startDecade <= lastDecade) {
|
||||
decadeList.add(startDecade);
|
||||
startDecade = startDecade + 10;
|
||||
}
|
||||
|
||||
decades.setValue(decadeList);
|
||||
}
|
||||
|
||||
decades.setValue(decadeList);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -295,7 +297,7 @@ public class AlbumRepository {
|
|||
private void getFirstAlbum(DecadesCallback callback) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getAlbumList2("byYear", 1, 0, 0, Calendar.getInstance().get(Calendar.YEAR))
|
||||
.getAlbumList2("byYear", 1, 0, 1900, Calendar.getInstance().get(Calendar.YEAR))
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
|
|
@ -308,7 +310,7 @@ public class AlbumRepository {
|
|||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
callback.onLoadYear(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -316,20 +318,23 @@ public class AlbumRepository {
|
|||
private void getLastAlbum(DecadesCallback callback) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getAlbumList2("byYear", 1, 0, Calendar.getInstance().get(Calendar.YEAR), 0)
|
||||
.getAlbumList2("byYear", 1, 0, Calendar.getInstance().get(Calendar.YEAR), 1900)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
if(response.body().getAlbumList2().getAlbums().get(0) != null){
|
||||
if(response.body().getAlbumList2().getAlbums().size() > 0 && response.body().getAlbumList2().getAlbums().get(0) != null){
|
||||
callback.onLoadYear(response.body().getAlbumList2().getAlbums().get(0).getYear());
|
||||
}
|
||||
else {
|
||||
callback.onLoadYear(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
callback.onLoadYear(-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ import android.app.Application;
|
|||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.DownloadDao;
|
||||
import com.cappielloantonio.play.model.Download;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
|
@ -60,7 +62,7 @@ public class DownloadRepository {
|
|||
}
|
||||
|
||||
public LiveData<List<Download>> getLiveDownloadSample(int size) {
|
||||
listLiveDownloadSample = downloadDao.getSample(size);
|
||||
listLiveDownloadSample = downloadDao.getSample(size, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
return listLiveDownloadSample;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +123,7 @@ public class DownloadRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
downloadDao.deleteAll();
|
||||
downloadDao.deleteAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ import android.app.Application;
|
|||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.QueueDao;
|
||||
import com.cappielloantonio.play.model.Queue;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||
import com.cappielloantonio.play.util.QueueUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -26,7 +28,7 @@ public class QueueRepository {
|
|||
}
|
||||
|
||||
public LiveData<List<Queue>> getLiveQueue() {
|
||||
listLiveQueue = queueDao.getAll();
|
||||
listLiveQueue = queueDao.getAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
return listLiveQueue;
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +96,7 @@ public class QueueRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
songs = MappingUtil.mapQueue(queueDao.getAllSimple());
|
||||
songs = MappingUtil.mapQueue(queueDao.getAllSimple(PreferenceUtil.getInstance(App.getInstance()).getServerId()));
|
||||
}
|
||||
|
||||
public List<Song> getSongs() {
|
||||
|
|
@ -113,7 +115,7 @@ public class QueueRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs));
|
||||
queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs, PreferenceUtil.getInstance(App.getInstance()).getServerId()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +130,7 @@ public class QueueRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
queueDao.deleteByPosition(position);
|
||||
queueDao.deleteByPosition(position, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +143,7 @@ public class QueueRepository {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
queueDao.deleteAll();
|
||||
queueDao.deleteAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,70 @@
|
|||
package com.cappielloantonio.play.repository;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import com.cappielloantonio.play.database.AppDatabase;
|
||||
import com.cappielloantonio.play.database.dao.ServerDao;
|
||||
import com.cappielloantonio.play.model.Server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ServerRepository {
|
||||
private static final String TAG = "QueueRepository";
|
||||
|
||||
private ServerDao serverDao;
|
||||
private LiveData<List<Server>> listLiveServer;
|
||||
|
||||
public ServerRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
serverDao = database.serverDao();
|
||||
}
|
||||
|
||||
public LiveData<List<Server>> getLiveServer() {
|
||||
listLiveServer = serverDao.getAll();
|
||||
return listLiveServer;
|
||||
}
|
||||
|
||||
public void insert(Server server) {
|
||||
InsertThreadSafe insert = new InsertThreadSafe(serverDao, server);
|
||||
Thread thread = new Thread(insert);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public void delete(Server server) {
|
||||
DeleteThreadSafe delete = new DeleteThreadSafe(serverDao, server);
|
||||
Thread thread = new Thread(delete);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private static class InsertThreadSafe implements Runnable {
|
||||
private ServerDao serverDao;
|
||||
private Server server;
|
||||
|
||||
public InsertThreadSafe(ServerDao serverDao, Server server) {
|
||||
this.serverDao = serverDao;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
serverDao.insert(server);
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeleteThreadSafe implements Runnable {
|
||||
private ServerDao serverDao;
|
||||
private Server server;
|
||||
|
||||
public DeleteThreadSafe(ServerDao serverDao, Server server) {
|
||||
this.serverDao = serverDao;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
serverDao.delete(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue