mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
fix: fixed directory navigation
This commit is contained in:
parent
803b61430f
commit
a9b264004c
6 changed files with 26 additions and 91 deletions
|
|
@ -76,7 +76,7 @@ public class MusicDirectoryAdapter extends RecyclerView.Adapter<MusicDirectoryAd
|
|||
Bundle bundle = new Bundle();
|
||||
|
||||
if (children.get(getBindingAdapterPosition()).isDir()) {
|
||||
bundle.putParcelable(Constants.MUSIC_DIRECTORY_OBJECT, children.get(getBindingAdapterPosition()));
|
||||
bundle.putString(Constants.MUSIC_DIRECTORY_ID, children.get(getBindingAdapterPosition()).getId());
|
||||
click.onMusicDirectoryClick(bundle);
|
||||
} else {
|
||||
bundle.putParcelableArrayList(Constants.TRACKS_OBJECT, new ArrayList<>(children));
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class MusicIndexAdapter extends RecyclerView.Adapter<MusicIndexAdapter.Vi
|
|||
|
||||
public void onClick() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(Constants.MUSIC_INDEX_OBJECT, artists.get(getBindingAdapterPosition()));
|
||||
bundle.putString(Constants.MUSIC_DIRECTORY_ID, artists.get(getBindingAdapterPosition()).getId());
|
||||
click.onMusicIndexClick(bundle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
import androidx.media3.common.util.UnstableApi;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
import androidx.media3.session.SessionToken;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.cappielloantonio.tempo.R;
|
||||
|
|
@ -20,17 +21,12 @@ import com.cappielloantonio.tempo.databinding.FragmentDirectoryBinding;
|
|||
import com.cappielloantonio.tempo.interfaces.ClickCallback;
|
||||
import com.cappielloantonio.tempo.service.MediaManager;
|
||||
import com.cappielloantonio.tempo.service.MediaService;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Artist;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Child;
|
||||
import com.cappielloantonio.tempo.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.tempo.ui.adapter.MusicDirectoryAdapter;
|
||||
import com.cappielloantonio.tempo.util.Constants;
|
||||
import com.cappielloantonio.tempo.viewmodel.DirectoryViewModel;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
@UnstableApi
|
||||
public class DirectoryFragment extends Fragment implements ClickCallback {
|
||||
private static final String TAG = "DirectoryFragment";
|
||||
|
|
@ -52,9 +48,7 @@ public class DirectoryFragment extends Fragment implements ClickCallback {
|
|||
directoryViewModel = new ViewModelProvider(requireActivity()).get(DirectoryViewModel.class);
|
||||
|
||||
initAppBar();
|
||||
initButtons();
|
||||
initDirectoryListView();
|
||||
init();
|
||||
|
||||
return view;
|
||||
}
|
||||
|
|
@ -77,17 +71,6 @@ public class DirectoryFragment extends Fragment implements ClickCallback {
|
|||
bind = null;
|
||||
}
|
||||
|
||||
private void init() {
|
||||
Artist artist = getArguments().getParcelable(Constants.MUSIC_INDEX_OBJECT);
|
||||
|
||||
if (artist != null) {
|
||||
directoryViewModel.setMusicDirectoryId(artist.getId());
|
||||
directoryViewModel.setMusicDirectoryName(artist.getName());
|
||||
}
|
||||
|
||||
directoryViewModel.loadMusicDirectory(getViewLifecycleOwner());
|
||||
}
|
||||
|
||||
private void initAppBar() {
|
||||
activity.setSupportActionBar(bind.toolbar);
|
||||
|
||||
|
|
@ -96,39 +79,10 @@ public class DirectoryFragment extends Fragment implements ClickCallback {
|
|||
activity.getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
if (bind != null)
|
||||
if (bind != null) {
|
||||
bind.toolbar.setNavigationOnClickListener(v -> activity.navController.navigateUp());
|
||||
|
||||
if (bind != null)
|
||||
bind.appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
|
||||
if ((bind.directoryInfoSector.getHeight() + verticalOffset) < (2 * ViewCompat.getMinimumHeight(bind.toolbar))) {
|
||||
directoryViewModel.getDirectory().observe(getViewLifecycleOwner(), directory -> {
|
||||
if (directory != null) {
|
||||
bind.toolbar.setTitle(directory.getName());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
bind.toolbar.setTitle(R.string.empty_string);
|
||||
}
|
||||
});
|
||||
|
||||
directoryViewModel.getDirectory().observe(getViewLifecycleOwner(), directory -> {
|
||||
if (directory != null) {
|
||||
bind.directoryTitleLabel.setText(directory.getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
directoryViewModel.getDirectory().observe(getViewLifecycleOwner(), directory -> {
|
||||
if (directory != null && directory.getParentId() != null && !Objects.equals(directory.getParentId(), "-1")) {
|
||||
bind.directoryBackImageView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
bind.directoryBackImageView.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
bind.directoryBackImageView.setOnClickListener(v -> directoryViewModel.goBack());
|
||||
bind.directoryBackImageView.setOnClickListener(v -> activity.navController.navigateUp());
|
||||
}
|
||||
}
|
||||
|
||||
private void initDirectoryListView() {
|
||||
|
|
@ -137,13 +91,18 @@ public class DirectoryFragment extends Fragment implements ClickCallback {
|
|||
|
||||
musicDirectoryAdapter = new MusicDirectoryAdapter(this);
|
||||
bind.directoryRecyclerView.setAdapter(musicDirectoryAdapter);
|
||||
directoryViewModel.loadMusicDirectory(getArguments().getString(Constants.MUSIC_DIRECTORY_ID)).observe(getViewLifecycleOwner(), directory -> {
|
||||
bind.appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
|
||||
if ((bind.directoryInfoSector.getHeight() + verticalOffset) < (2 * ViewCompat.getMinimumHeight(bind.toolbar))) {
|
||||
bind.toolbar.setTitle(directory.getName());
|
||||
} else {
|
||||
bind.toolbar.setTitle(R.string.empty_string);
|
||||
}
|
||||
});
|
||||
|
||||
directoryViewModel.getDirectory().observe(getViewLifecycleOwner(), directory -> {
|
||||
if (directory != null) {
|
||||
musicDirectoryAdapter.setItems(directory.getChildren());
|
||||
} else {
|
||||
musicDirectoryAdapter.setItems(Collections.emptyList());
|
||||
}
|
||||
bind.directoryTitleLabel.setText(directory.getName());
|
||||
|
||||
musicDirectoryAdapter.setItems(directory.getChildren());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -162,11 +121,6 @@ public class DirectoryFragment extends Fragment implements ClickCallback {
|
|||
|
||||
@Override
|
||||
public void onMusicDirectoryClick(Bundle bundle) {
|
||||
Child child = bundle.getParcelable(Constants.MUSIC_DIRECTORY_OBJECT);
|
||||
|
||||
if (child != null) {
|
||||
directoryViewModel.setMusicDirectoryId(child.getId());
|
||||
directoryViewModel.setMusicDirectoryName(child.getTitle());
|
||||
}
|
||||
Navigation.findNavController(requireView()).navigate(R.id.directoryFragment, bundle);
|
||||
}
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ object Constants {
|
|||
const val MUSIC_FOLDER_OBJECT = "MUSIC_FOLDER_OBJECT"
|
||||
const val MUSIC_DIRECTORY_OBJECT = "MUSIC_DIRECTORY_OBJECT"
|
||||
const val MUSIC_INDEX_OBJECT = "MUSIC_DIRECTORY_OBJECT"
|
||||
const val MUSIC_DIRECTORY_ID = "MUSIC_DIRECTORY_ID"
|
||||
|
||||
const val ALBUM_RECENTLY_PLAYED = "ALBUM_RECENTLY_PLAYED"
|
||||
const val ALBUM_MOST_PLAYED = "ALBUM_MOST_PLAYED"
|
||||
|
|
|
|||
|
|
@ -4,9 +4,7 @@ import android.app.Application;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import com.cappielloantonio.tempo.repository.DirectoryRepository;
|
||||
import com.cappielloantonio.tempo.subsonic.models.Directory;
|
||||
|
|
@ -14,34 +12,13 @@ import com.cappielloantonio.tempo.subsonic.models.Directory;
|
|||
public class DirectoryViewModel extends AndroidViewModel {
|
||||
private final DirectoryRepository directoryRepository;
|
||||
|
||||
private MutableLiveData<String> id = new MutableLiveData<>(null);
|
||||
private MutableLiveData<String> name = new MutableLiveData<>(null);
|
||||
|
||||
private MutableLiveData<Directory> directory = new MutableLiveData<>(null);
|
||||
|
||||
public DirectoryViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
|
||||
directoryRepository = new DirectoryRepository();
|
||||
}
|
||||
|
||||
public LiveData<Directory> getDirectory() {
|
||||
return directory;
|
||||
}
|
||||
|
||||
public void setMusicDirectoryId(String id) {
|
||||
this.id.setValue(id);
|
||||
}
|
||||
|
||||
public void setMusicDirectoryName(String name) {
|
||||
this.name.setValue(name);
|
||||
}
|
||||
|
||||
public void loadMusicDirectory(LifecycleOwner owner) {
|
||||
this.id.observe(owner, id -> directoryRepository.getMusicDirectory(id).observe(owner, directory -> this.directory.setValue(directory)));
|
||||
}
|
||||
|
||||
public void goBack() {
|
||||
this.id.setValue(this.directory.getValue().getParentId());
|
||||
public LiveData<Directory> loadMusicDirectory(String id) {
|
||||
return directoryRepository.getMusicDirectory(id);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,13 +286,16 @@
|
|||
android:id="@+id/directoryFragment"
|
||||
android:name="com.cappielloantonio.tempo.ui.fragment.DirectoryFragment"
|
||||
android:label="DirectoryFragment"
|
||||
tools:layout="@layout/fragment_directory" />
|
||||
tools:layout="@layout/fragment_directory">
|
||||
<action
|
||||
android:id="@+id/action_directoryFragment_to_directoryFragment"
|
||||
app:destination="@id/directoryFragment" />
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/indexFragment"
|
||||
android:name="com.cappielloantonio.tempo.ui.fragment.IndexFragment"
|
||||
android:label="IndexFragment"
|
||||
tools:layout="@layout/fragment_index">
|
||||
|
||||
<action
|
||||
android:id="@+id/action_indexFragment_to_directoryFragment"
|
||||
app:destination="@id/directoryFragment" />
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue