Fix issue #31 - Show more content when available (with a toggle button)

This commit is contained in:
Thomas 2020-11-07 10:09:58 +01:00
parent 02cc00780d
commit 8c958a2563
7 changed files with 89 additions and 1 deletions

View File

@ -18,6 +18,8 @@
<string name="set_video_in_list">Vidéos dans une liste</string>
<string name="set_video_in_list_description">Change la mise en page pour afficher les vidéos dans une liste</string>
<string name="show_more">Montrer plus</string>
<string name="show_less">Montrer moins</string>
<string name="set_play_screen_lock">Verrouillage d\'écran</string>
<string name="set_play_screen_lock_description">Continuer à lire des vidéos lorsque l\'écran est verrouillé</string>

View File

@ -17,6 +17,9 @@
<string name="set_video_in_list">Videos in list</string>
<string name="set_video_in_list_description">Change the layout for displaying videos in a list</string>
<string name="show_more">Show more</string>
<string name="show_less">Show less</string>
<string name="set_play_screen_lock">Screen lock</string>
<string name="set_play_screen_lock_description">Keep playing videos when the screen is locked</string>

View File

@ -34,6 +34,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.media.session.MediaSessionCompat;
import android.text.Html;
import android.text.Spanned;
@ -176,6 +177,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
public static List<String> playedVideos = new ArrayList<>();
private VideoData.Video nextVideo;
private TorrentStream torrentStream;
private String show_more_content;
@Override
public void onVideoSizeChanged(int width, int height, int unappliedRotationDegrees, float pixelWidthHeightRatio) {
@ -285,6 +287,17 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
manageIntentUrl(intent);
binding.peertubeDescriptionMore.setOnClickListener(v->{
if( show_more_content != null && peertube != null) {
if( binding.peertubeDescriptionMore.getText().toString().compareTo(getString(R.string.show_more)) == 0) {
binding.peertubeDescriptionMore.setText(getString(R.string.show_less));
binding.peertubeDescription.setText(show_more_content);
}else{
binding.peertubeDescriptionMore.setText(getString(R.string.show_more));
binding.peertubeDescription.setText(peertube.getDescription());
}
}
});
if (!Helper.isLoggedIn(PeertubeActivity.this) || sepiaSearch) {
binding.writeCommentContainerReply.setVisibility(View.GONE);
binding.writeCommentContainer.setVisibility(View.GONE);
@ -539,6 +552,8 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
player.setPlayWhenReady(autoPlay);
captions = null;
}
show_more_content = null;
binding.peertubeDescriptionMore.setVisibility(View.GONE);
if( autoFullscreen && autoPlay) {
fullscreen = FullScreenMediaController.fullscreen.ON;
setFullscreen(FullScreenMediaController.fullscreen.ON);
@ -561,6 +576,31 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
feedsViewModel.getVideo(sepiaSearch ? peertubeInstance : null, videoUuid, isMyVideo).observe(PeertubeActivity.this, this::manageVIewVideo);
CaptionsVM captionsViewModel = new ViewModelProvider(PeertubeActivity.this).get(CaptionsVM.class);
captionsViewModel.getCaptions(sepiaSearch ? peertubeInstance : null, videoUuid).observe(PeertubeActivity.this, this::manageCaptions);
new Thread(() -> {
try {
RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(PeertubeActivity.this);
VideoData.Description description = api.getVideoDescription(videoUuid);
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> {
if( description == null) {
binding.peertubeDescriptionMore.setVisibility(View.GONE);
show_more_content = null;
}else{
if( description.getDescription().compareTo(peertube.getDescription()) > 0) {
binding.peertubeDescriptionMore.setVisibility(View.VISIBLE);
show_more_content = description.getDescription();
}else{
binding.peertubeDescriptionMore.setVisibility(View.GONE);
show_more_content = null;
}
}
};
mainHandler.post(myRunnable);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
public void change() {

View File

@ -202,6 +202,10 @@ public interface PeertubeService {
@GET("videos/{id}")
Call<VideoData.Video> getVideo(@Path("id") String id);
//Get a video description
@GET("videos/{uuid}/description")
Call<VideoData.Description> getVideoDescription(@Path("uuid") String uuid);
@GET("videos/{id}")
Call<VideoData.Video> getMyVideo(@Header("Authorization") String credentials, @Path("id") String id);

View File

@ -1038,6 +1038,25 @@ public class RetrofitPeertubeAPI {
}
/**
* Get video description
*
* @param uuid String (pagination)
* @return APIResponse
*/
public VideoData.Description getVideoDescription(String uuid) {
PeertubeService peertubeService = init();
Call<VideoData.Description> videoDescription = peertubeService.getVideoDescription(uuid);
try {
Response<VideoData.Description> response = videoDescription.execute();
if (response.isSuccessful() && response.body() != null) {
return response.body();
}
} catch (IOException ignored) {}
return null;
}
/**
* Get muted accounts
*

View File

@ -685,4 +685,17 @@ public class VideoData {
}
public static class Description{
@SerializedName("description")
private String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
}

View File

@ -225,7 +225,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
<TextView
android:id="@+id/peertube_description_more"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/show_more"
android:visibility="gone"
android:textColor="?attr/colorAccent"
android:layout_marginTop="2dp" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/write_comment_container"