mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Delete queue on logout
This commit is contained in:
parent
78a4006ed6
commit
af60a4a3eb
12 changed files with 60 additions and 43 deletions
1
.idea/misc.xml
generated
1
.idea/misc.xml
generated
|
|
@ -19,6 +19,7 @@
|
||||||
<entry key="app/src/main/res/layout/fragment_album_catalogue.xml" value="0.3229166666666667" />
|
<entry key="app/src/main/res/layout/fragment_album_catalogue.xml" value="0.3229166666666667" />
|
||||||
<entry key="app/src/main/res/layout/fragment_album_page.xml" value="0.1" />
|
<entry key="app/src/main/res/layout/fragment_album_page.xml" value="0.1" />
|
||||||
<entry key="app/src/main/res/layout/fragment_artist_page.xml" value="0.1" />
|
<entry key="app/src/main/res/layout/fragment_artist_page.xml" value="0.1" />
|
||||||
|
<entry key="app/src/main/res/layout/fragment_home.xml" value="0.2212962962962963" />
|
||||||
<entry key="app/src/main/res/layout/fragment_login.xml" value="0.3166496424923391" />
|
<entry key="app/src/main/res/layout/fragment_login.xml" value="0.3166496424923391" />
|
||||||
<entry key="app/src/main/res/layout/item_horizontal_album.xml" value="0.3166496424923391" />
|
<entry key="app/src/main/res/layout/item_horizontal_album.xml" value="0.3166496424923391" />
|
||||||
<entry key="app/src/main/res/layout/item_horizontal_track.xml" value="0.1" />
|
<entry key="app/src/main/res/layout/item_horizontal_track.xml" value="0.1" />
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
Server server = servers.get(getBindingAdapterPosition());
|
Server server = servers.get(getBindingAdapterPosition());
|
||||||
saveServerPreference(server.getAddress(), server.getUsername(), server.getToken(), server.getSalt());
|
saveServerPreference(server.getAddress(), server.getUsername(), server.getToken(), server.getSalt());
|
||||||
|
refreshSubsonicClientInstance();
|
||||||
|
|
||||||
SystemRepository systemRepository = new SystemRepository(App.getInstance());
|
SystemRepository systemRepository = new SystemRepository(App.getInstance());
|
||||||
systemRepository.checkUserCredential(new SystemCallback() {
|
systemRepository.checkUserCredential(new SystemCallback() {
|
||||||
|
|
@ -116,11 +117,11 @@ public class ServerAdapter extends RecyclerView.Adapter<ServerAdapter.ViewHolder
|
||||||
if (token != null && salt != null) {
|
if (token != null && salt != null) {
|
||||||
PreferenceUtil.getInstance(context).setToken(token);
|
PreferenceUtil.getInstance(context).setToken(token);
|
||||||
PreferenceUtil.getInstance(context).setSalt(salt);
|
PreferenceUtil.getInstance(context).setSalt(salt);
|
||||||
PreferenceUtil.getInstance(context).setServerId(servers.get(getBindingAdapterPosition()).getServerId());
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshSubsonicClientInstance() {
|
||||||
|
PreferenceUtil.getInstance(context).setServerId(servers.get(getBindingAdapterPosition()).getServerId());
|
||||||
App.getSubsonicClientInstance(context, true);
|
App.getSubsonicClientInstance(context, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import com.cappielloantonio.play.model.Queue;
|
||||||
import com.cappielloantonio.play.model.RecentSearch;
|
import com.cappielloantonio.play.model.RecentSearch;
|
||||||
import com.cappielloantonio.play.model.Server;
|
import com.cappielloantonio.play.model.Server;
|
||||||
|
|
||||||
@Database(entities = {Queue.class, Server.class, RecentSearch.class, Download.class}, version = 9, exportSchema = false)
|
@Database(entities = {Queue.class, Server.class, RecentSearch.class, Download.class}, version = 12, exportSchema = false)
|
||||||
public abstract class AppDatabase extends RoomDatabase {
|
public abstract class AppDatabase extends RoomDatabase {
|
||||||
private static final String TAG = "AppDatabase";
|
private static final String TAG = "AppDatabase";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,21 +12,21 @@ import java.util.List;
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
public interface QueueDao {
|
public interface QueueDao {
|
||||||
@Query("SELECT * FROM queue WHERE server = :server")
|
@Query("SELECT * FROM queue")
|
||||||
LiveData<List<Queue>> getAll(String server);
|
LiveData<List<Queue>> getAll();
|
||||||
|
|
||||||
@Query("SELECT * FROM queue WHERE server = :server")
|
@Query("SELECT * FROM queue")
|
||||||
List<Queue> getAllSimple(String server);
|
List<Queue> getAllSimple();
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
void insertAll(List<Queue> songQueueObject);
|
void insertAll(List<Queue> songQueueObject);
|
||||||
|
|
||||||
@Query("DELETE FROM queue WHERE queue.track_order = :position AND server = :server")
|
@Query("DELETE FROM queue WHERE queue.track_order = :position")
|
||||||
void deleteByPosition(int position, String server);
|
void deleteByPosition(int position);
|
||||||
|
|
||||||
@Query("DELETE FROM queue WHERE server = :server")
|
@Query("DELETE FROM queue")
|
||||||
void deleteAll(String server);
|
void deleteAll();
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM queue;")
|
@Query("SELECT COUNT(*) FROM queue")
|
||||||
int count();
|
int count();
|
||||||
}
|
}
|
||||||
|
|
@ -36,10 +36,7 @@ public class Queue {
|
||||||
@ColumnInfo(name = "duration")
|
@ColumnInfo(name = "duration")
|
||||||
private long duration;
|
private long duration;
|
||||||
|
|
||||||
@ColumnInfo(name = "server")
|
public Queue(int trackOrder, String songID, String title, String albumId, String albumName, String artistId, String artistName, String primary, long duration) {
|
||||||
private String server;
|
|
||||||
|
|
||||||
public Queue(int trackOrder, String songID, String title, String albumId, String albumName, String artistId, String artistName, String primary, long duration, String server) {
|
|
||||||
this.trackOrder = trackOrder;
|
this.trackOrder = trackOrder;
|
||||||
this.songID = songID;
|
this.songID = songID;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
|
@ -49,7 +46,6 @@ public class Queue {
|
||||||
this.artistName = artistName;
|
this.artistName = artistName;
|
||||||
this.primary = primary;
|
this.primary = primary;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.server = server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTrackOrder() {
|
public int getTrackOrder() {
|
||||||
|
|
@ -123,12 +119,4 @@ public class Queue {
|
||||||
public void setDuration(long duration) {
|
public void setDuration(long duration) {
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServer() {
|
|
||||||
return server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setServer(String server) {
|
|
||||||
this.server = server;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -293,7 +293,9 @@ public class ArtistRepository {
|
||||||
.enqueue(new Callback<SubsonicResponse>() {
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
topSongs.setValue(MappingUtil.mapSong(response.body().getTopSongs().getSongs()));
|
if (response.body().getTopSongs() != null) {
|
||||||
|
topSongs.setValue(MappingUtil.mapSong(response.body().getTopSongs().getSongs()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.cappielloantonio.play.repository;
|
package com.cappielloantonio.play.repository;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ public class QueueRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Queue>> getLiveQueue() {
|
public LiveData<List<Queue>> getLiveQueue() {
|
||||||
listLiveQueue = queueDao.getAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
listLiveQueue = queueDao.getAll();
|
||||||
return listLiveQueue;
|
return listLiveQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,6 +70,12 @@ public class QueueRepository {
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
DeleteAllThreadSafe deleteAll = new DeleteAllThreadSafe(queueDao);
|
||||||
|
Thread thread = new Thread(deleteAll);
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
public int count() {
|
public int count() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
|
|
@ -96,7 +103,7 @@ public class QueueRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
songs = MappingUtil.mapQueue(queueDao.getAllSimple(PreferenceUtil.getInstance(App.getInstance()).getServerId()));
|
songs = MappingUtil.mapQueue(queueDao.getAllSimple());
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Song> getSongs() {
|
public List<Song> getSongs() {
|
||||||
|
|
@ -115,7 +122,7 @@ public class QueueRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs, PreferenceUtil.getInstance(App.getInstance()).getServerId()));
|
queueDao.insertAll(QueueUtil.getQueueElementsFromSongs(songs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +137,7 @@ public class QueueRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
queueDao.deleteByPosition(position, PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
queueDao.deleteByPosition(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -143,7 +150,7 @@ public class QueueRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
queueDao.deleteAll(PreferenceUtil.getInstance(App.getInstance()).getServerId());
|
queueDao.deleteAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,12 @@ import androidx.navigation.NavController;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.navigation.ui.NavigationUI;
|
import androidx.navigation.ui.NavigationUI;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.broadcast.receiver.ConnectivityStatusBroadcastReceiver;
|
import com.cappielloantonio.play.broadcast.receiver.ConnectivityStatusBroadcastReceiver;
|
||||||
import com.cappielloantonio.play.databinding.ActivityMainBinding;
|
import com.cappielloantonio.play.databinding.ActivityMainBinding;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
|
import com.cappielloantonio.play.repository.QueueRepository;
|
||||||
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
import com.cappielloantonio.play.service.MusicPlayerRemote;
|
||||||
import com.cappielloantonio.play.ui.activity.base.BaseActivity;
|
import com.cappielloantonio.play.ui.activity.base.BaseActivity;
|
||||||
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
||||||
|
|
@ -179,6 +181,9 @@ public class MainActivity extends BaseActivity {
|
||||||
|
|
||||||
// NAVIGATION
|
// NAVIGATION
|
||||||
public void goToLogin() {
|
public void goToLogin() {
|
||||||
|
setBottomNavigationBarVisibility(false);
|
||||||
|
setBottomSheetVisibility(false);
|
||||||
|
|
||||||
if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.landingFragment) {
|
if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.landingFragment) {
|
||||||
navController.navigate(R.id.action_landingFragment_to_loginFragment);
|
navController.navigate(R.id.action_landingFragment_to_loginFragment);
|
||||||
} else if(Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.settingsFragment) {
|
} else if(Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.settingsFragment) {
|
||||||
|
|
@ -197,9 +202,23 @@ public class MainActivity extends BaseActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void goFromLogin() {
|
public void goFromLogin() {
|
||||||
|
isBottomSheetInPeek(mainViewModel.isQueueLoaded());
|
||||||
goToHome();
|
goToHome();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clearViewModel() {
|
||||||
|
this.getViewModelStore().clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void quit() {
|
||||||
|
QueueRepository queueRepository = new QueueRepository(App.getInstance());
|
||||||
|
queueRepository.deleteAll();
|
||||||
|
|
||||||
|
MusicPlayerRemote.quitPlaying();
|
||||||
|
clearViewModel();
|
||||||
|
goToLogin();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
|
if (bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED)
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,10 @@ import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
import com.cappielloantonio.play.helper.ThemeHelper;
|
import com.cappielloantonio.play.helper.ThemeHelper;
|
||||||
|
import com.cappielloantonio.play.repository.QueueRepository;
|
||||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||||
import com.cappielloantonio.play.util.PreferenceUtil;
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
|
|
||||||
|
|
@ -50,7 +52,7 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
PreferenceUtil.getInstance(requireContext()).setSalt(null);
|
PreferenceUtil.getInstance(requireContext()).setSalt(null);
|
||||||
PreferenceUtil.getInstance(requireContext()).setServerId(null);
|
PreferenceUtil.getInstance(requireContext()).setServerId(null);
|
||||||
|
|
||||||
activity.goToLogin();
|
activity.quit();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -91,7 +91,7 @@ public class PreferenceUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerId() {
|
public String getServerId() {
|
||||||
return mPreferences.getString(SERVER_ID, null);
|
return mPreferences.getString(SERVER_ID, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServerId(String serverId) {
|
public void setServerId(String serverId) {
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ import java.util.List;
|
||||||
public class QueueUtil {
|
public class QueueUtil {
|
||||||
private static final String TAG = "QueueUtil";
|
private static final String TAG = "QueueUtil";
|
||||||
|
|
||||||
public static List<Queue> getQueueElementsFromSongs(List<Song> songs, String serverID) {
|
public static List<Queue> getQueueElementsFromSongs(List<Song> songs) {
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
List<Queue> queue = new ArrayList<>();
|
List<Queue> queue = new ArrayList<>();
|
||||||
|
|
||||||
for (Song song : songs) {
|
for (Song song : songs) {
|
||||||
queue.add(new Queue(counter, song.getId(), song.getTitle(), song.getAlbumId(), song.getAlbumName(), song.getArtistId(), song.getArtistName(), song.getPrimary(), song.getDuration(), serverID));
|
queue.add(new Queue(counter, song.getId(), song.getTitle(), song.getAlbumId(), song.getAlbumName(), song.getArtistId(), song.getArtistName(), song.getPrimary(), song.getDuration()));
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,18 +10,15 @@ import com.cappielloantonio.play.repository.QueueRepository;
|
||||||
public class MainViewModel extends AndroidViewModel {
|
public class MainViewModel extends AndroidViewModel {
|
||||||
private static final String TAG = "SearchViewModel";
|
private static final String TAG = "SearchViewModel";
|
||||||
|
|
||||||
private QueueRepository queueRepository;
|
private Application application;
|
||||||
|
|
||||||
public MainViewModel(@NonNull Application application) {
|
public MainViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
this.application = application;
|
||||||
queueRepository = new QueueRepository(application);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isQueueLoaded() {
|
public boolean isQueueLoaded() {
|
||||||
if (queueRepository.count() == 0)
|
QueueRepository queueRepository = new QueueRepository(application);
|
||||||
return false;
|
return queueRepository.count() != 0;
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue