Skip to content

Commit

Permalink
Use material-themed unsubscribe button on video-description panel too
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor committed Aug 24, 2024
1 parent e26b75f commit 3b647a3
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void setupDescription() {
DatabaseTasks.getChannelInfo(requireContext(), video.getChannelId(), false)
.subscribe(subscribedChannel -> {
YouTubeChannel youTubeChannel = subscribedChannel.channel();
videoDescriptionBinding.videoDescSubscribeButton.setChannel(youTubeChannel);
videoDescriptionBinding.videoDescSubscribeButton.setChannelInfo(subscribedChannel);

Glide.with(requireContext())
.load(youTubeChannel.getThumbnailUrl())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
/*
* SkyTube
* Copyright (C) 2021 Zsombor Gegesy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation (version 3 of the License).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package free.rm.skytube.businessobjects.db;

import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package free.rm.skytube.gui.businessobjects.views;

import free.rm.skytube.businessobjects.YouTube.POJOs.YouTubeChannel;

public interface ChannelSubscriber {
void setSubscribedState(boolean subscribed);
void setChannel(YouTubeChannel channel);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,27 @@
import android.view.View;
import android.widget.RemoteViews;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatButton;

import com.google.android.material.button.MaterialButton;

import free.rm.skytube.R;
import free.rm.skytube.businessobjects.YouTube.POJOs.YouTubeChannel;
import free.rm.skytube.businessobjects.YouTube.YouTubeTasks;
import free.rm.skytube.businessobjects.YouTube.POJOs.PersistentChannel;
import free.rm.skytube.businessobjects.YouTube.newpipe.ChannelId;
import free.rm.skytube.businessobjects.db.DatabaseTasks;
import io.reactivex.rxjava3.disposables.CompositeDisposable;

/**
* The (channel) subscribe button.
*/
@RemoteViews.RemoteView
public class SubscribeButton extends AppCompatButton implements View.OnClickListener, ChannelSubscriber {
public class SubscribeButton extends MaterialButton implements View.OnClickListener, ChannelSubscriber {

/** Is user subscribed to a channel? */
private boolean isUserSubscribed = false;

private YouTubeChannel channel;
private ChannelId channelId;
private OnClickListener externalClickListener = null;

private final CompositeDisposable compositeDisposable = new CompositeDisposable();
Expand All @@ -58,9 +60,9 @@ public void onClick(View view) {
if(externalClickListener != null) {
externalClickListener.onClick(SubscribeButton.this);
}
if(channel != null) {
if(channelId != null) {
compositeDisposable.add(DatabaseTasks.subscribeToChannel(!isUserSubscribed,
this, getContext(), channel.getChannelId(), true).subscribe());
this, getContext(), channelId, true).subscribe());
}
}

Expand All @@ -74,12 +76,9 @@ public void clearBackgroundTasks() {
compositeDisposable.clear();
}

@Override
public void setChannel(YouTubeChannel channel) {
this.channel = channel;
if (channel != null) {
setSubscribedState(channel.isUserSubscribed());
}
public void setChannelInfo(@NonNull PersistentChannel persistentChannel) {
this.channelId = persistentChannel.getChannelId();
setSubscribedState(persistentChannel.isSubscribed());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ public void setSubscribedState(boolean subscribed) {
}
}

@Override
public void setChannel(YouTubeChannel channel) {
private void setChannel(YouTubeChannel channel) {
this.channel = channel;
if (channel != null) {
this.channelId = channel.getChannelId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
private void getVideoInfoTasks() {
// get Channel info (e.g. avatar...etc) task
compositeDisposable.add(DatabaseTasks.getChannelInfo(requireContext(), youTubeVideo.getChannelId(), false)
.subscribe(youTubeChannel1 -> {
youTubeChannel = youTubeChannel1.channel();
.subscribe(persistentChannel -> {
youTubeChannel = persistentChannel.channel();

videoDescriptionBinding.videoDescSubscribeButton.setChannel(youTubeChannel);
videoDescriptionBinding.videoDescSubscribeButton.setChannelInfo(persistentChannel);
if (youTubeChannel != null) {
Glide.with(requireContext())
.load(youTubeChannel.getThumbnailUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
import free.rm.skytube.businessobjects.Sponsorblock.SBTasks;
import free.rm.skytube.businessobjects.Sponsorblock.SBTimeBarView;
import free.rm.skytube.businessobjects.Sponsorblock.SBVideoInfo;
import free.rm.skytube.businessobjects.YouTube.POJOs.PersistentChannel;
import free.rm.skytube.businessobjects.YouTube.POJOs.YouTubeChannel;
import free.rm.skytube.businessobjects.YouTube.POJOs.YouTubeVideo;
import free.rm.skytube.businessobjects.YouTube.YouTubeTasks;
Expand Down Expand Up @@ -122,7 +123,6 @@ public class YouTubePlayerV2Fragment extends ImmersiveModeFragment implements Yo

private FragmentYoutubePlayerV2Binding fragmentBinding;
private VideoDescriptionBinding videoDescriptionBinding;
private TextView playbackSpeedTextView;

private SimpleExoPlayer player;
private long playerInitialPosition = 0;
Expand Down Expand Up @@ -153,22 +153,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
// inflate the layout for this fragment
fragmentBinding = FragmentYoutubePlayerV2Binding.inflate(inflater, container, false);
videoDescriptionBinding = fragmentBinding.desContent;
playbackSpeedTextView = fragmentBinding.getRoot().findViewById(R.id.playbackSpeed);

// indicate that this fragment has an action bar menu
setHasOptionsMenu(true);

// final View decorView = getActivity().getWindow().getDecorView();
// decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
// @Override
// public void onSystemUiVisibilityChange(int visibility) {
// hideNavigationBar();
// }
// });

///if (savedInstanceState != null)
/// videoCurrentPosition = savedInstanceState.getInt(VIDEO_CURRENT_POSITION, 0);

if (youTubeVideo == null) {
// initialise the views
initViews();
Expand All @@ -192,6 +180,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
return fragmentBinding.getRoot();
}

private TextView getPlaybackSpeedTextView() {
return fragmentBinding.getRoot().findViewById(R.id.playbackSpeed);
}

private void openVideo(ContentId contentId) {
Utils.isTrue(contentId.getType() == StreamingService.LinkType.STREAM, "Content is a video:" + contentId);
compositeDisposable.add(YouTubeTasks.getVideoDetails(requireContext(), contentId)
Expand Down Expand Up @@ -269,7 +261,7 @@ private void initViews() {
}
});
this.playbackSpeedController = new PlaybackSpeedController(getContext(),
playbackSpeedTextView, player);
getPlaybackSpeedTextView(), player);

//set playback speed
float playbackSpeed = SkyTubeApp.getSettings().getDefaultPlaybackSpeed();
Expand Down Expand Up @@ -778,10 +770,10 @@ private void fetchVideoInformations() {
// get Channel info (e.g. avatar...etc) task
compositeDisposable.add(
DatabaseTasks.getChannelInfo(requireContext(), youTubeVideo.getChannelId(), false)
.subscribe(youTubeChannel1 -> {
youTubeChannel = youTubeChannel1.channel();
.subscribe(newPersistentChannel -> {
youTubeChannel = newPersistentChannel.channel();
videoDescriptionBinding.videoDescSubscribeButton.setChannelInfo(newPersistentChannel);

videoDescriptionBinding.videoDescSubscribeButton.setChannel(youTubeChannel);
if (youTubeChannel != null) {
Glide.with(requireContext())
.load(youTubeChannel.getThumbnailUrl())
Expand Down
7 changes: 0 additions & 7 deletions app/src/main/res/drawable/subscribe_button_background.xml

This file was deleted.

8 changes: 6 additions & 2 deletions app/src/main/res/layout/video_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@
<!-- SUB BUTTON -->
<free.rm.skytube.gui.businessobjects.views.SubscribeButton
android:id="@+id/video_desc_subscribe_button"
style="@style/SubscribeButton"
android:layout_below="@id/video_desc_channel"
android:text="Unsubscribe" />
android:text="Unsubscribe"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="3dp"
android:textAppearance="@style/RegularTextStyle"
/>
</LinearLayout>

</RelativeLayout>
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
<drawable name="sub_channel">@android:color/transparent</drawable>
<color name="subs_text">@color/brightText</color>

<drawable name="subscribe_button">@color/skytube_theme_colour</drawable>
<drawable name="subscribe_button_pressed">#ff8e44</drawable>


<!--
Video (Grid) Cells
Expand Down
11 changes: 0 additions & 11 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,6 @@
<item name="android:textColor">@color/subs_text</item>
</style>

<style name="SubscribeButton" parent="AppTheme">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">@color/subs_text</item>
<item name="android:minHeight">0dp</item>
<item name="android:minWidth">0dp</item>
<item name="android:padding">3dp</item>
<item name="android:background">@drawable/subscribe_button_background</item>
<item name="android:text">@string/subscribe</item>
</style>


<!-- *************************************************************************************** -->
<!--
Expand Down

0 comments on commit 3b647a3

Please sign in to comment.