mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
First implementation of the podcastBottomSheetDialog
This commit is contained in:
parent
0c6bab8fd6
commit
1a736d3744
4 changed files with 326 additions and 0 deletions
|
|
@ -0,0 +1,153 @@
|
||||||
|
package com.cappielloantonio.play.ui.fragment.bottomsheetdialog;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import android.widget.ToggleButton;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
import androidx.media3.session.MediaBrowser;
|
||||||
|
import androidx.media3.session.SessionToken;
|
||||||
|
|
||||||
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||||
|
import com.cappielloantonio.play.R;
|
||||||
|
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||||
|
import com.cappielloantonio.play.model.Media;
|
||||||
|
import com.cappielloantonio.play.service.MediaManager;
|
||||||
|
import com.cappielloantonio.play.service.MediaService;
|
||||||
|
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||||
|
import com.cappielloantonio.play.util.DownloadUtil;
|
||||||
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
import com.cappielloantonio.play.util.MusicUtil;
|
||||||
|
import com.cappielloantonio.play.viewmodel.PodcastBottomSheetViewModel;
|
||||||
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
public class PodcastBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener {
|
||||||
|
private static final String TAG = "PodcastBottomSheetDialog";
|
||||||
|
|
||||||
|
private PodcastBottomSheetViewModel podcastBottomSheetViewModel;
|
||||||
|
private Media podcast;
|
||||||
|
|
||||||
|
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||||
|
View view = inflater.inflate(R.layout.bottom_sheet_podcast_dialog, container, false);
|
||||||
|
|
||||||
|
podcast = requireArguments().getParcelable("podcast_object");
|
||||||
|
|
||||||
|
podcastBottomSheetViewModel = new ViewModelProvider(requireActivity()).get(PodcastBottomSheetViewModel.class);
|
||||||
|
podcastBottomSheetViewModel.setPodcast(podcast);
|
||||||
|
|
||||||
|
init(view);
|
||||||
|
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
|
||||||
|
initializeMediaBrowser();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
releaseMediaBrowser();
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(View view) {
|
||||||
|
ImageView coverPodcast = view.findViewById(R.id.podcast_cover_image_view);
|
||||||
|
CustomGlideRequest.Builder
|
||||||
|
.from(requireContext(), podcastBottomSheetViewModel.getPodcast().getCoverArtId(), CustomGlideRequest.SONG_PIC, null)
|
||||||
|
.build()
|
||||||
|
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||||
|
.into(coverPodcast);
|
||||||
|
|
||||||
|
TextView titlePodcast = view.findViewById(R.id.podcast_title_text_view);
|
||||||
|
titlePodcast.setText(MusicUtil.getReadableString(podcastBottomSheetViewModel.getPodcast().getTitle()));
|
||||||
|
|
||||||
|
titlePodcast.setSelected(true);
|
||||||
|
|
||||||
|
TextView channel = view.findViewById(R.id.podcast_artist_text_view);
|
||||||
|
channel.setText(MusicUtil.getReadableString(podcastBottomSheetViewModel.getPodcast().getArtistName()));
|
||||||
|
|
||||||
|
TextView playNext = view.findViewById(R.id.play_next_text_view);
|
||||||
|
playNext.setOnClickListener(v -> {
|
||||||
|
MediaManager.enqueue(mediaBrowserListenableFuture, requireContext(), podcast, true);
|
||||||
|
((MainActivity) requireActivity()).setBottomSheetInPeek(true);
|
||||||
|
dismissBottomSheet();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView addToQueue = view.findViewById(R.id.add_to_queue_text_view);
|
||||||
|
addToQueue.setOnClickListener(v -> {
|
||||||
|
MediaManager.enqueue(mediaBrowserListenableFuture, requireContext(), podcast, false);
|
||||||
|
((MainActivity) requireActivity()).setBottomSheetInPeek(true);
|
||||||
|
dismissBottomSheet();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView download = view.findViewById(R.id.download_text_view);
|
||||||
|
download.setOnClickListener(v -> {
|
||||||
|
DownloadUtil.getDownloadTracker(requireContext()).download(
|
||||||
|
MappingUtil.mapMediaItem(requireContext(), podcast, false),
|
||||||
|
MappingUtil.mapDownload(podcast, null, null)
|
||||||
|
);
|
||||||
|
dismissBottomSheet();
|
||||||
|
});
|
||||||
|
|
||||||
|
TextView remove = view.findViewById(R.id.remove_text_view);
|
||||||
|
remove.setOnClickListener(v -> {
|
||||||
|
DownloadUtil.getDownloadTracker(requireContext()).remove(
|
||||||
|
MappingUtil.mapMediaItem(requireContext(), podcast, false),
|
||||||
|
MappingUtil.mapDownload(podcast, null, null)
|
||||||
|
);
|
||||||
|
dismissBottomSheet();
|
||||||
|
});
|
||||||
|
|
||||||
|
initDownloadUI(download, remove);
|
||||||
|
|
||||||
|
TextView goToChannel = view.findViewById(R.id.go_to_channel_text_view);
|
||||||
|
goToChannel.setOnClickListener(v -> {
|
||||||
|
Toast.makeText(requireContext(), "Open the channel", Toast.LENGTH_SHORT).show();
|
||||||
|
dismissBottomSheet();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
dismissBottomSheet();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dismissBottomSheet() {
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDownloadUI(TextView download, TextView remove) {
|
||||||
|
if (DownloadUtil.getDownloadTracker(requireContext()).isDownloaded(MappingUtil.mapMediaItem(requireContext(), podcast, false))) {
|
||||||
|
download.setVisibility(View.GONE);
|
||||||
|
remove.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
download.setVisibility(View.VISIBLE);
|
||||||
|
remove.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("UnsafeOptInUsageError")
|
||||||
|
private void initializeMediaBrowser() {
|
||||||
|
mediaBrowserListenableFuture = new MediaBrowser.Builder(requireContext(), new SessionToken(requireContext(), new ComponentName(requireContext(), MediaService.class))).buildAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void releaseMediaBrowser() {
|
||||||
|
MediaBrowser.releaseFuture(mediaBrowserListenableFuture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.cappielloantonio.play.viewmodel;
|
||||||
|
|
||||||
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.model.Media;
|
||||||
|
import com.cappielloantonio.play.repository.PodcastRepository;
|
||||||
|
import com.cappielloantonio.play.util.DownloadUtil;
|
||||||
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
||||||
|
|
||||||
|
public class PodcastBottomSheetViewModel extends AndroidViewModel {
|
||||||
|
private final PodcastRepository podcastRepository;
|
||||||
|
|
||||||
|
private Media podcast;
|
||||||
|
|
||||||
|
public PodcastBottomSheetViewModel(@NonNull Application application) {
|
||||||
|
super(application);
|
||||||
|
|
||||||
|
podcastRepository = new PodcastRepository(application);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Media getPodcast() {
|
||||||
|
return podcast;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPodcast(Media podcast) {
|
||||||
|
this.podcast = podcast;
|
||||||
|
}
|
||||||
|
}
|
||||||
135
app/src/main/res/layout/bottom_sheet_podcast_dialog.xml
Normal file
135
app/src/main/res/layout/bottom_sheet_podcast_dialog.xml
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:layout_marginEnd="12dp"
|
||||||
|
android:clipChildren="false">
|
||||||
|
|
||||||
|
<!-- Header -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/podcast_cover_image_view"
|
||||||
|
android:layout_width="54dp"
|
||||||
|
android:layout_height="54dp"
|
||||||
|
android:layout_margin="2dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/podcast_title_text_view"
|
||||||
|
style="@style/LabelMedium"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:scrollHorizontally="true"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="@string/label_placeholder"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/podcast_cover_image_view"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/podcast_artist_text_view"
|
||||||
|
style="@style/LabelSmall"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingStart="12dp"
|
||||||
|
android:paddingEnd="12dp"
|
||||||
|
android:text="@string/label_placeholder"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/podcast_cover_image_view"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/podcast_title_text_view" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/option_linear_layout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingTop="8dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/play_next_text_view"
|
||||||
|
style="@style/LabelMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/podcast_bottom_sheet_play_next" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/add_to_queue_text_view"
|
||||||
|
style="@style/LabelMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/podcast_bottom_sheet_add_to_queue" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/download_text_view"
|
||||||
|
style="@style/LabelMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/podcast_bottom_sheet_download" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/remove_text_view"
|
||||||
|
style="@style/LabelMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/podcast_bottom_sheet_remove" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/go_to_channel_text_view"
|
||||||
|
style="@style/LabelMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/selectableItemBackground"
|
||||||
|
android:clickable="true"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:text="@string/podcast_bottom_sheet_go_to_channel" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
@ -212,4 +212,9 @@
|
||||||
<string name="home_title_new_releases">New releases</string>
|
<string name="home_title_new_releases">New releases</string>
|
||||||
<string name="home_title_newest_podcasts">Newest podcasts</string>
|
<string name="home_title_newest_podcasts">Newest podcasts</string>
|
||||||
<string name="artist_adapter_radio_station_starting">Searching...</string>
|
<string name="artist_adapter_radio_station_starting">Searching...</string>
|
||||||
|
<string name="podcast_bottom_sheet_go_to_channel">Go to channel</string>
|
||||||
|
<string name="podcast_bottom_sheet_remove">Remove</string>
|
||||||
|
<string name="podcast_bottom_sheet_download">Download</string>
|
||||||
|
<string name="podcast_bottom_sheet_add_to_queue">Add to queue</string>
|
||||||
|
<string name="podcast_bottom_sheet_play_next">Play next</string>
|
||||||
</resources>
|
</resources>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue