diff --git a/app/src/acad/res/values/strings.xml b/app/src/acad/res/values/strings.xml index 4f85e2c..60aeb55 100644 --- a/app/src/acad/res/values/strings.xml +++ b/app/src/acad/res/values/strings.xml @@ -20,6 +20,7 @@ Exporter Importer + Date de publication Supprimer l\'historique de vidéos Êtes vous sur de vouloir supprimer toutes les vidéos de votre historique ? diff --git a/app/src/full/res/values/strings.xml b/app/src/full/res/values/strings.xml index 7cd6645..324d66c 100644 --- a/app/src/full/res/values/strings.xml +++ b/app/src/full/res/values/strings.xml @@ -35,6 +35,7 @@ When a video ends, follow up with the next suggested video. Add a public reply + Originally published Activity App New video from your subscriptions diff --git a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java index 41ccb8d..5505f69 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/PeertubeActivity.java @@ -37,7 +37,11 @@ import android.os.Handler; import android.os.Looper; import android.support.v4.media.session.MediaSessionCompat; import android.text.Html; +import android.text.SpannableString; import android.text.Spanned; +import android.text.TextPaint; +import android.text.method.LinkMovementMethod; +import android.text.style.ClickableSpan; import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.MenuItem; @@ -99,8 +103,10 @@ import com.google.android.exoplayer2.video.VideoListener; import org.jetbrains.annotations.NotNull; +import java.text.DateFormat; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -116,10 +122,12 @@ import app.fedilab.fedilabtube.client.data.CommentData; import app.fedilab.fedilabtube.client.data.CommentData.Comment; import app.fedilab.fedilabtube.client.data.PlaylistData; import app.fedilab.fedilabtube.client.data.VideoData; +import app.fedilab.fedilabtube.client.entities.Error; import app.fedilab.fedilabtube.client.entities.File; import app.fedilab.fedilabtube.client.entities.MenuItemView; import app.fedilab.fedilabtube.client.entities.PlaylistExist; import app.fedilab.fedilabtube.client.entities.Report; +import app.fedilab.fedilabtube.client.entities.UserSettings; import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding; import app.fedilab.fedilabtube.drawer.CommentListAdapter; import app.fedilab.fedilabtube.drawer.MenuAdapter; @@ -139,6 +147,7 @@ import app.fedilab.fedilabtube.webview.MastalabWebChromeClient; import app.fedilab.fedilabtube.webview.MastalabWebViewClient; import es.dmoral.toasty.Toasty; +import static app.fedilab.fedilabtube.MainActivity.peertubeInformation; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.ADD_COMMENT; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY; @@ -606,7 +615,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd show_more_content = null; } else { if (!PeertubeActivity.this.isFinishing()) { - if ((peertube.getDescription() == null && description.getDescription() != null) || (peertube.getDescription() != null && description.getDescription() != null && description.getDescription().compareTo(peertube.getDescription()) > 0)) { + if ((peertube.getDescription() == null && description.getDescription() != null && description.getDescription().trim().length() > 0) || (peertube.getDescription() != null && description.getDescription() != null && description.getDescription().compareTo(peertube.getDescription()) > 0)) { binding.peertubeDescriptionMore.setVisibility(View.VISIBLE); show_more_content = description.getDescription(); } else { @@ -706,8 +715,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd i++; } nextVideo = apiResponse.getPeertubes().get(i); - MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(nextVideo.getFileUrl(null, PeertubeActivity.this))).build(); - player.addMediaItem(mediaItem); + if (!playedVideos.contains(nextVideo.getId())) { + MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(nextVideo.getFileUrl(null, PeertubeActivity.this))).build(); + player.addMediaItem(mediaItem); + } } @SuppressLint("ClickableViewAccessibility") @@ -749,6 +760,75 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd viewModelOwnerPlaylist.manage(PlaylistsVM.action.GET_PLAYLISTS, null, null).observe(PeertubeActivity.this, this::manageVIewPlaylists); }); + binding.videoInformation.setOnClickListener(v -> { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(PeertubeActivity.this); + LayoutInflater inflater = getLayoutInflater(); + View dialogView = inflater.inflate(R.layout.popup_video_info, new LinearLayout(PeertubeActivity.this), false); + TextView info_privacy = dialogView.findViewById(R.id.info_privacy); + TextView info_published_at = dialogView.findViewById(R.id.info_published_at); + TextView info_category = dialogView.findViewById(R.id.info_category); + TextView info_license = dialogView.findViewById(R.id.info_license); + TextView info_language = dialogView.findViewById(R.id.info_language); + TextView info_duration = dialogView.findViewById(R.id.info_duration); + TextView info_tags = dialogView.findViewById(R.id.info_tags); + + LinkedHashMap privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies()); + info_privacy.setText(privaciesInit.get(peertube.getPrivacy().getId())); + LinkedHashMap licenseInit = new LinkedHashMap<>(peertubeInformation.getLicences()); + info_license.setText(licenseInit.get(peertube.getLicence().getId())); + LinkedHashMap languageStr = new LinkedHashMap<>(peertubeInformation.getLanguages()); + info_language.setText(languageStr.get(peertube.getLanguage().getId())); + LinkedHashMap categoryInit = new LinkedHashMap<>(peertubeInformation.getCategories()); + info_category.setText(categoryInit.get(peertube.getCategory().getId())); + + info_duration.setText(Helper.secondsToString(peertube.getDuration())); + String format = DateFormat.getDateInstance(DateFormat.LONG).format(peertube.getPublishedAt()); + info_published_at.setText(format); + List tags = peertube.getTags(); + StringBuilder sb = new StringBuilder(); + for (String tag : tags) { + sb.append("#").append(tag).append(" "); + } + + SpannableString spannableString = new SpannableString(sb.toString()); + for (String tag : tags) { + String target = "#" + tag; + if (spannableString != null && spannableString.toString().contains(target)) { + for (int startPosition = -1; (startPosition = spannableString.toString().indexOf(target, startPosition + 1)) != -1; startPosition++) { + final int endPosition = startPosition + target.length(); + if (endPosition <= spannableString.toString().length() && endPosition >= startPosition) { + spannableString.setSpan(new ClickableSpan() { + @Override + public void onClick(@NonNull View textView) { + Intent intent = new Intent(PeertubeActivity.this, SearchActivity.class); + Bundle b = new Bundle(); + String search = tag.trim(); + b.putString("search", search); + intent.putExtras(b); + startActivity(intent); + } + + @Override + public void updateDrawState(@NonNull TextPaint ds) { + super.updateDrawState(ds); + ds.setUnderlineText(false); + ds.setColor(getResources().getColor(R.color.colorAccent)); + } + }, + startPosition, endPosition, + Spanned.SPAN_INCLUSIVE_EXCLUSIVE); + } + } + } + } + info_tags.setText(spannableString, TextView.BufferType.SPANNABLE); + info_tags.setMovementMethod(LinkMovementMethod.getInstance()); + dialogBuilder.setView(dialogView); + dialogBuilder.setNeutralButton(R.string.close, (dialog, id) -> dialog.dismiss()); + AlertDialog alertDialog = dialogBuilder.create(); + alertDialog.show(); + }); + if (peertube.isCommentsEnabled()) { if (Helper.isLoggedIn(PeertubeActivity.this)) { binding.postCommentButton.setVisibility(View.VISIBLE); @@ -1266,6 +1346,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd menuItemVideos.add(captionItem); } + MenuItemVideo autoNextItem = new MenuItemVideo(); + autoNextItem.setIcon(R.drawable.ic_baseline_play_arrow_24); + autoNextItem.setTitle(getString(R.string.set_autoplay)); + autoNextItem.setAction(MenuItemVideo.actionType.AUTONEXT); + menuItemVideos.add(autoNextItem); + MenuAdapter menuAdapter = new MenuAdapter(menuItemVideos); binding.mainOptionsVideo.setAdapter(menuAdapter); menuAdapter.itemClicked = this; @@ -1324,6 +1410,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd items.add(new MenuItemView(i, caption.getLanguage().getId(), caption.getLanguage().getLabel(), currentCaption.compareTo(caption.getLanguage().getId()) == 0)); } break; + case AUTONEXT: + binding.subMenuTitle.setText(R.string.set_autoplay); + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE); + boolean autoplayNextVideo = sharedpreferences.getBoolean(getString(R.string.set_autoplay_next_video_choice), true); + items.add(new MenuItemView(0, getString(R.string.no), !autoplayNextVideo)); + items.add(new MenuItemView(1, getString(R.string.yes), autoplayNextVideo)); + break; } MenuItemAdapter menuItemAdapter = new MenuItemAdapter(action, items); binding.subMenuRecycler.setAdapter(menuItemAdapter); @@ -1410,6 +1503,24 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd item.getStrId() ); break; + case AUTONEXT: + SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putBoolean(getString(R.string.set_autoplay_next_video_choice), item.getId() == 1); + editor.apply(); + if (Helper.isLoggedIn(PeertubeActivity.this)) { + new Thread(() -> { + UserSettings userSettings = new UserSettings(); + userSettings.setAutoPlayNextVideo(item.getId() == 1); + try { + RetrofitPeertubeAPI api = new RetrofitPeertubeAPI(PeertubeActivity.this); + api.updateUser(userSettings); + } catch (Exception | Error e) { + e.printStackTrace(); + } + }).start(); + } + break; } closeSubMenuMenuOptions(); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/VideosTimelineActivity.java b/app/src/main/java/app/fedilab/fedilabtube/VideosTimelineActivity.java index 211b336..56064f2 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/VideosTimelineActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/VideosTimelineActivity.java @@ -131,6 +131,11 @@ public class VideosTimelineActivity extends AppCompatActivity { } + @Override + public void onBackPressed() { + super.onBackPressed(); + finish(); + } @Override public boolean onOptionsItemSelected(MenuItem item) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/MenuItemVideo.java b/app/src/main/java/app/fedilab/fedilabtube/client/MenuItemVideo.java index 590ec1d..1c5465b 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/MenuItemVideo.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/MenuItemVideo.java @@ -47,6 +47,7 @@ public class MenuItemVideo { public enum actionType { RESOLUTION, SPEED, - CAPTION + CAPTION, + AUTONEXT } } diff --git a/app/src/main/res/layout/activity_peertube.xml b/app/src/main/res/layout/activity_peertube.xml index cf924e6..45c96a6 100644 --- a/app/src/main/res/layout/activity_peertube.xml +++ b/app/src/main/res/layout/activity_peertube.xml @@ -218,6 +218,20 @@ android:visibility="gone" app:drawableTopCompat="@drawable/ic_baseline_list_24" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/drawer_menu_item.xml b/app/src/main/res/layout/drawer_menu_item.xml index 7086d59..d9647de 100644 --- a/app/src/main/res/layout/drawer_menu_item.xml +++ b/app/src/main/res/layout/drawer_menu_item.xml @@ -24,6 +24,8 @@ android:layout_height="wrap_content" android:layout_marginStart="10dp" android:gravity="start|center_vertical" + android:ellipsize="end" + android:singleLine="true" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@+id/radio" diff --git a/app/src/main/res/layout/popup_report.xml b/app/src/main/res/layout/popup_report.xml index f48d9ae..0bcaff6 100644 --- a/app/src/main/res/layout/popup_report.xml +++ b/app/src/main/res/layout/popup_report.xml @@ -1,4 +1,19 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file