summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas <tschneider.ac@gmail.com>2022-06-28 16:28:11 +0200
committerThomas <tschneider.ac@gmail.com>2022-06-28 16:28:11 +0200
commita48f997ae3e8f9ea74c54e7b682a4065297c0233 (patch)
tree222abc62292ddbe2149b3f9ab990a81d796427f8
parentfc4cbc533427a4ed7e351c78c6810af150547f94 (diff)
Manage Peertube videos
-rw-r--r--app/src/main/java/app/fedilab/android/activities/MediaActivity.java2
-rw-r--r--app/src/main/java/app/fedilab/android/activities/SearchResultTabActivity.java1
-rw-r--r--app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java4
-rw-r--r--app/src/main/java/app/fedilab/android/client/entities/api/Attachment.java2
-rw-r--r--app/src/main/java/app/fedilab/android/client/entities/peertube/PeertubeVideo.java28
-rw-r--r--app/src/main/java/app/fedilab/android/helper/Helper.java1
-rw-r--r--app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java18
-rw-r--r--app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java65
-rw-r--r--app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java29
9 files changed, 123 insertions, 27 deletions
diff --git a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java
index 4af12d8db..baeb5a82a 100644
--- a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java
@@ -125,7 +125,7 @@ public class MediaActivity extends BaseActivity implements OnDownloadInterface {
ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(MediaActivity.this);
binding.mediaViewpager.setAdapter(mPagerAdapter);
-
+ binding.mediaViewpager.setSaveEnabled(false);
binding.mediaViewpager.setCurrentItem(mediaPosition - 1);
binding.haulerView.setOnDragDismissedListener(dragDirection -> ActivityCompat.finishAfterTransition(MediaActivity.this));
registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
diff --git a/app/src/main/java/app/fedilab/android/activities/SearchResultTabActivity.java b/app/src/main/java/app/fedilab/android/activities/SearchResultTabActivity.java
index b7814e67a..04195b35b 100644
--- a/app/src/main/java/app/fedilab/android/activities/SearchResultTabActivity.java
+++ b/app/src/main/java/app/fedilab/android/activities/SearchResultTabActivity.java
@@ -83,6 +83,7 @@ public class SearchResultTabActivity extends BaseActivity {
binding.searchTabLayout.setTabIconTint(ThemeHelper.getColorStateList(SearchResultTabActivity.this));
ScreenSlidePagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(SearchResultTabActivity.this);
binding.searchViewpager.setAdapter(mPagerAdapter);
+ binding.searchViewpager.setSaveEnabled(false);
binding.searchViewpager.setOffscreenPageLimit(3);
new TabLayoutMediator(binding.searchTabLayout, binding.searchViewpager,
(tab, position) -> {
diff --git a/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java b/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java
index 69850f5bf..5602c02a6 100644
--- a/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java
+++ b/app/src/main/java/app/fedilab/android/client/endpoints/MastodonTimelinesService.java
@@ -224,4 +224,8 @@ public interface MastodonTimelinesService {
@Query("count") int count
);
+ @GET("api/v1/videos/{id}")
+ Call<PeertubeVideo.Video> getPeertubeVideo(
+ @Path("id") String id
+ );
}
diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Attachment.java b/app/src/main/java/app/fedilab/android/client/entities/api/Attachment.java
index 5f11e2e1f..2d06c3143 100644
--- a/app/src/main/java/app/fedilab/android/client/entities/api/Attachment.java
+++ b/app/src/main/java/app/fedilab/android/client/entities/api/Attachment.java
@@ -44,4 +44,6 @@ public class Attachment implements Serializable {
@SerializedName("local_path")
public String local_path;
+ public String peertubeHost = null;
+ public String peertubeId = null;
}
diff --git a/app/src/main/java/app/fedilab/android/client/entities/peertube/PeertubeVideo.java b/app/src/main/java/app/fedilab/android/client/entities/peertube/PeertubeVideo.java
index 90f323813..7f48a99a3 100644
--- a/app/src/main/java/app/fedilab/android/client/entities/peertube/PeertubeVideo.java
+++ b/app/src/main/java/app/fedilab/android/client/entities/peertube/PeertubeVideo.java
@@ -56,9 +56,11 @@ public class PeertubeVideo implements Serializable {
status.account = account;
List<Attachment> attachmentList = new ArrayList<>();
Attachment attachment = new Attachment();
- attachment.type = "video/mp4";
+ attachment.type = "video";
attachment.url = "https://" + peertubeVideo.account.host + peertubeVideo.embedPath;
attachment.preview_url = "https://" + peertubeVideo.account.host + peertubeVideo.thumbnailPath;
+ attachment.peertubeId = peertubeVideo.uuid;
+ attachment.peertubeHost = peertubeVideo.account.host;
attachmentList.add(attachment);
status.media_attachments = attachmentList;
return status;
@@ -111,11 +113,33 @@ public class PeertubeVideo implements Serializable {
public Date updatedAt;
@SerializedName("uuid")
public String uuid;
-
+ @SerializedName("files")
+ public List<File> files;
@SerializedName("views")
public int views;
}
+ public class File implements Serializable {
+ @SerializedName("fileDownloadUrl")
+ public String fileDownloadUrl;
+ @SerializedName("fileUrl")
+ public String fileUrl;
+ @SerializedName("fps")
+ public int fps;
+ @SerializedName("magnetUri")
+ public String magnetUri;
+ @SerializedName("metadataUrl")
+ public String metadataUrl;
+ @SerializedName("resolution")
+ public Item resolutions;
+ @SerializedName("size")
+ public long size;
+ @SerializedName("torrentDownloadUrl")
+ public String torrentDownloadUrl;
+ @SerializedName("torrentUrl")
+ public String torrentUrl;
+ }
+
public static class PeertubeAccount implements Serializable {
@SerializedName("avatar")
public Avatar avatar;
diff --git a/app/src/main/java/app/fedilab/android/helper/Helper.java b/app/src/main/java/app/fedilab/android/helper/Helper.java
index 284e1ae3f..361ef13e6 100644
--- a/app/src/main/java/app/fedilab/android/helper/Helper.java
+++ b/app/src/main/java/app/fedilab/android/helper/Helper.java
@@ -280,6 +280,7 @@ public class Helper {
public static final Pattern libredditPattern = Pattern.compile("(www\\.|m\\.)?(reddit\\.com|preview\\.redd\\.it|i\\.redd\\.it|redd\\.it)/(((?!([\"'<])).)*)");
public static final Pattern ouichesPattern = Pattern.compile("https?://ouich\\.es/tag/(\\w+)");
public static final Pattern xmppPattern = Pattern.compile("xmpp:[-a-zA-Z0-9+$&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
+ public static final Pattern peertubePattern = Pattern.compile("(https?://([\\da-z.-]+\\.[a-z.]{2,10}))/videos/watch/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})$");
public static final Pattern mediumPattern = Pattern.compile("([\\w@-]*)?\\.?medium.com/@?([/\\w-]+)");
public static final Pattern wikipediaPattern = Pattern.compile("([\\w_-]+)\\.wikipedia.org/(((?!([\"'<])).)*)");
public static final Pattern codePattern = Pattern.compile("code=([\\w-]+)");
diff --git a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java
index 798049339..a8e0c6505 100644
--- a/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java
+++ b/app/src/main/java/app/fedilab/android/ui/drawer/StatusAdapter.java
@@ -433,6 +433,24 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.statusContent.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
holder.binding.spoiler.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
}
+
+ //If the message contain a link to peertube and no media was added, we add it
+ if (statusToDeal.card != null && statusToDeal.card.url != null && (statusToDeal.media_attachments == null || statusToDeal.media_attachments.size() == 0)) {
+ Matcher matcherLink = Helper.peertubePattern.matcher(statusToDeal.card.url);
+ if (matcherLink.find()) { //Peertubee video
+ List<Attachment> attachmentList = new ArrayList<>();
+ Attachment attachment = new Attachment();
+ attachment.type = "video";
+ attachment.url = matcherLink.group(0);
+ attachment.preview_url = statusToDeal.card.image;
+ attachment.peertubeHost = matcherLink.group(2);
+ attachment.peertubeId = matcherLink.group(3);
+ attachmentList.add(attachment);
+ statusToDeal.media_attachments = attachmentList;
+ adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
+ }
+ }
+
if (status.card != null && (display_card || status.isFocused)) {
if (status.card.width > status.card.height) {
holder.binding.cardImageHorizontal.setVisibility(View.VISIBLE);
diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java
index 3ef9f5575..08fee2707 100644
--- a/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java
+++ b/app/src/main/java/app/fedilab/android/ui/fragment/media/FragmentMedia.java
@@ -31,6 +31,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;
+import androidx.lifecycle.ViewModelProvider;
import androidx.preference.PreferenceManager;
import com.bumptech.glide.Glide;
@@ -51,6 +52,7 @@ import app.fedilab.android.client.entities.api.Attachment;
import app.fedilab.android.databinding.FragmentSlideMediaBinding;
import app.fedilab.android.helper.CacheDataSourceFactory;
import app.fedilab.android.helper.Helper;
+import app.fedilab.android.viewmodel.mastodon.TimelinesVM;
import app.fedilab.android.webview.CustomWebview;
import app.fedilab.android.webview.FedilabWebChromeClient;
import app.fedilab.android.webview.FedilabWebViewClient;
@@ -198,32 +200,18 @@ public class FragmentMedia extends Fragment {
case "video":
case "audio":
case "gifv":
- binding.pbarInf.setIndeterminate(false);
- binding.pbarInf.setScaleY(3f);
- binding.mediaVideo.setVisibility(View.VISIBLE);
- Uri uri = Uri.parse(url);
-
- String userAgent = sharedpreferences.getString(getString(R.string.SET_CUSTOM_USER_AGENT), Helper.USER_AGENT);
- int video_cache = sharedpreferences.getInt(getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB);
- ProgressiveMediaSource videoSource;
- if (video_cache == 0) {
- DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(requireActivity(),
- Util.getUserAgent(requireActivity(), userAgent), null);
- videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
- .createMediaSource(uri);
+ if (attachment.peertubeId != null) {
+ //It's a peertube video, we are fetching data
+ TimelinesVM timelinesVM = new ViewModelProvider(requireActivity()).get(TimelinesVM.class);
+ String finalType = type;
+ timelinesVM.getPeertubeVideo(attachment.peertubeHost, attachment.peertubeId).observe(requireActivity(), video -> {
+ if (video != null && video.files != null && video.files.size() > 0) {
+ loadVideo(video.files.get(0).fileUrl, finalType);
+ }
+ });
} else {
- CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(requireActivity());
- videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
- .createMediaSource(uri);
+ loadVideo(url, type);
}
- player = new SimpleExoPlayer.Builder(requireActivity()).build();
- if (type.equalsIgnoreCase("gifv"))
- player.setRepeatMode(Player.REPEAT_MODE_ONE);
- binding.mediaVideo.setPlayer(player);
- binding.loader.setVisibility(View.GONE);
- binding.mediaPicture.setVisibility(View.GONE);
- player.prepare(videoSource);
- player.setPlayWhenReady(true);
break;
case "web":
binding.loader.setVisibility(View.GONE);
@@ -261,6 +249,35 @@ public class FragmentMedia extends Fragment {
}
}
+ private void loadVideo(String url, String type) {
+ binding.pbarInf.setIndeterminate(false);
+ binding.pbarInf.setScaleY(3f);
+ binding.mediaVideo.setVisibility(View.VISIBLE);
+ Uri uri = Uri.parse(url);
+ SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(requireActivity());
+ String userAgent = sharedpreferences.getString(getString(R.string.SET_CUSTOM_USER_AGENT), Helper.USER_AGENT);
+ int video_cache = sharedpreferences.getInt(getString(R.string.SET_VIDEO_CACHE), Helper.DEFAULT_VIDEO_CACHE_MB);
+ ProgressiveMediaSource videoSource;
+ if (video_cache == 0) {
+ DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(requireActivity(),
+ Util.getUserAgent(requireActivity(), userAgent), null);
+ videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
+ .createMediaSource(uri);
+ } else {
+ CacheDataSourceFactory cacheDataSourceFactory = new CacheDataSourceFactory(requireActivity());
+ videoSource = new ProgressiveMediaSource.Factory(cacheDataSourceFactory)
+ .createMediaSource(uri);
+ }
+ player = new SimpleExoPlayer.Builder(requireActivity()).build();
+ if (type.equalsIgnoreCase("gifv"))
+ player.setRepeatMode(Player.REPEAT_MODE_ONE);
+ binding.mediaVideo.setPlayer(player);
+ binding.loader.setVisibility(View.GONE);
+ binding.mediaPicture.setVisibility(View.GONE);
+ player.prepare(videoSource);
+ player.setPlayWhenReady(true);
+ }
+
@Override
public void onCreate(Bundle saveInstance) {
super.onCreate(saveInstance);
diff --git a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java
index f0243dffc..368467da7 100644
--- a/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java
+++ b/app/src/main/java/app/fedilab/android/viewmodel/mastodon/TimelinesVM.java
@@ -71,6 +71,7 @@ public class TimelinesVM extends AndroidViewModel {
private MutableLiveData<List<StatusDraft>> statusDraftListMutableLiveData;
private MutableLiveData<Status> statusMutableLiveData;
private MutableLiveData<Statuses> statusesMutableLiveData;
+ private MutableLiveData<PeertubeVideo.Video> peertubeVideoMutableLiveData;
private MutableLiveData<Conversations> conversationListMutableLiveData;
private MutableLiveData<MastodonList> mastodonListMutableLiveData;
private MutableLiveData<List<MastodonList>> mastodonListListMutableLiveData;
@@ -247,6 +248,34 @@ public class TimelinesVM extends AndroidViewModel {
/**
+ * Returns details for a peertube video
+ *
+ * @return {@link LiveData} containing a {@link PeertubeVideo.Video}
+ */
+ public LiveData<PeertubeVideo.Video> getPeertubeVideo(@NonNull String instance, String id) {
+ MastodonTimelinesService mastodonTimelinesService = initInstanceOnly(instance);
+ peertubeVideoMutableLiveData = new MutableLiveData<>();
+ new Thread(() -> {
+ Call<PeertubeVideo.Video> publicTlCall = mastodonTimelinesService.getPeertubeVideo(id);
+ PeertubeVideo.Video peertubeVideo = null;
+ try {
+ Response<PeertubeVideo.Video> videoResponse = publicTlCall.execute();
+ if (videoResponse.isSuccessful()) {
+ peertubeVideo = videoResponse.body();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ Handler mainHandler = new Handler(Looper.getMainLooper());
+ PeertubeVideo.Video finalPeertubeVideo = peertubeVideo;
+ Runnable myRunnable = () -> peertubeVideoMutableLiveData.setValue(finalPeertubeVideo);
+ mainHandler.post(myRunnable);
+ }).start();
+ return peertubeVideoMutableLiveData;
+ }
+
+
+ /**
* View public statuses containing the given hashtag.
*
* @param hashtag Content of a #hashtag, not including # symbol.