Some improvements

This commit is contained in:
Thomas 2020-11-19 18:08:28 +01:00
parent 8ff3b81112
commit 50a9f8a1b0
11 changed files with 333 additions and 6 deletions

View File

@ -20,6 +20,7 @@
<string name="export_list">Exporter</string> <string name="export_list">Exporter</string>
<string name="import_list">Importer</string> <string name="import_list">Importer</string>
<string name="originally_published">Date de publication</string>
<string name="delete_history">Supprimer l\'historique de vidéos</string> <string name="delete_history">Supprimer l\'historique de vidéos</string>
<string name="delete_history_confirm">Êtes vous sur de vouloir supprimer toutes les vidéos de votre historique ?</string> <string name="delete_history_confirm">Êtes vous sur de vouloir supprimer toutes les vidéos de votre historique ?</string>

View File

@ -35,6 +35,7 @@
<string name="set_autoplay_next_video_description">When a video ends, follow up with the next suggested video.</string> <string name="set_autoplay_next_video_description">When a video ends, follow up with the next suggested video.</string>
<string name="add_public_reply">Add a public reply</string> <string name="add_public_reply">Add a public reply</string>
<string name="originally_published">Originally published</string>
<string name="activity">Activity</string> <string name="activity">Activity</string>
<string name="app">App</string> <string name="app">App</string>
<string name="notif_new_video">New video from your subscriptions</string> <string name="notif_new_video">New video from your subscriptions</string>

View File

@ -37,7 +37,11 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.MediaSessionCompat;
import android.text.Html; import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -99,8 +103,10 @@ import com.google.android.exoplayer2.video.VideoListener;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.text.DateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; 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.CommentData.Comment;
import app.fedilab.fedilabtube.client.data.PlaylistData; import app.fedilab.fedilabtube.client.data.PlaylistData;
import app.fedilab.fedilabtube.client.data.VideoData; 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.File;
import app.fedilab.fedilabtube.client.entities.MenuItemView; import app.fedilab.fedilabtube.client.entities.MenuItemView;
import app.fedilab.fedilabtube.client.entities.PlaylistExist; import app.fedilab.fedilabtube.client.entities.PlaylistExist;
import app.fedilab.fedilabtube.client.entities.Report; import app.fedilab.fedilabtube.client.entities.Report;
import app.fedilab.fedilabtube.client.entities.UserSettings;
import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding; import app.fedilab.fedilabtube.databinding.ActivityPeertubeBinding;
import app.fedilab.fedilabtube.drawer.CommentListAdapter; import app.fedilab.fedilabtube.drawer.CommentListAdapter;
import app.fedilab.fedilabtube.drawer.MenuAdapter; import app.fedilab.fedilabtube.drawer.MenuAdapter;
@ -139,6 +147,7 @@ import app.fedilab.fedilabtube.webview.MastalabWebChromeClient;
import app.fedilab.fedilabtube.webview.MastalabWebViewClient; import app.fedilab.fedilabtube.webview.MastalabWebViewClient;
import es.dmoral.toasty.Toasty; 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.ADD_COMMENT;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.RATEVIDEO;
import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY; import static app.fedilab.fedilabtube.client.RetrofitPeertubeAPI.ActionType.REPLY;
@ -606,7 +615,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
show_more_content = null; show_more_content = null;
} else { } else {
if (!PeertubeActivity.this.isFinishing()) { 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); binding.peertubeDescriptionMore.setVisibility(View.VISIBLE);
show_more_content = description.getDescription(); show_more_content = description.getDescription();
} else { } else {
@ -706,8 +715,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
i++; i++;
} }
nextVideo = apiResponse.getPeertubes().get(i); nextVideo = apiResponse.getPeertubes().get(i);
MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(nextVideo.getFileUrl(null, PeertubeActivity.this))).build(); if (!playedVideos.contains(nextVideo.getId())) {
player.addMediaItem(mediaItem); MediaItem mediaItem = new MediaItem.Builder().setUri(Uri.parse(nextVideo.getFileUrl(null, PeertubeActivity.this))).build();
player.addMediaItem(mediaItem);
}
} }
@SuppressLint("ClickableViewAccessibility") @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); 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<Integer, String> privaciesInit = new LinkedHashMap<>(peertubeInformation.getPrivacies());
info_privacy.setText(privaciesInit.get(peertube.getPrivacy().getId()));
LinkedHashMap<Integer, String> licenseInit = new LinkedHashMap<>(peertubeInformation.getLicences());
info_license.setText(licenseInit.get(peertube.getLicence().getId()));
LinkedHashMap<String, String> languageStr = new LinkedHashMap<>(peertubeInformation.getLanguages());
info_language.setText(languageStr.get(peertube.getLanguage().getId()));
LinkedHashMap<Integer, String> 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<String> 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 (peertube.isCommentsEnabled()) {
if (Helper.isLoggedIn(PeertubeActivity.this)) { if (Helper.isLoggedIn(PeertubeActivity.this)) {
binding.postCommentButton.setVisibility(View.VISIBLE); binding.postCommentButton.setVisibility(View.VISIBLE);
@ -1266,6 +1346,12 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
menuItemVideos.add(captionItem); 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); MenuAdapter menuAdapter = new MenuAdapter(menuItemVideos);
binding.mainOptionsVideo.setAdapter(menuAdapter); binding.mainOptionsVideo.setAdapter(menuAdapter);
menuAdapter.itemClicked = this; 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)); items.add(new MenuItemView(i, caption.getLanguage().getId(), caption.getLanguage().getLabel(), currentCaption.compareTo(caption.getLanguage().getId()) == 0));
} }
break; 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); MenuItemAdapter menuItemAdapter = new MenuItemAdapter(action, items);
binding.subMenuRecycler.setAdapter(menuItemAdapter); binding.subMenuRecycler.setAdapter(menuItemAdapter);
@ -1410,6 +1503,24 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
item.getStrId() item.getStrId()
); );
break; 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(); closeSubMenuMenuOptions();
} }

View File

@ -131,6 +131,11 @@ public class VideosTimelineActivity extends AppCompatActivity {
} }
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {

View File

@ -47,6 +47,7 @@ public class MenuItemVideo {
public enum actionType { public enum actionType {
RESOLUTION, RESOLUTION,
SPEED, SPEED,
CAPTION CAPTION,
AUTONEXT
} }
} }

View File

@ -218,6 +218,20 @@
android:visibility="gone" android:visibility="gone"
app:drawableTopCompat="@drawable/ic_baseline_list_24" /> app:drawableTopCompat="@drawable/ic_baseline_list_24" />
<TextView
android:id="@+id/video_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="10dp"
android:layout_marginLeft="10dp"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:drawablePadding="5dp"
android:gravity="center_horizontal"
android:text=""
app:drawableTopCompat="@drawable/ic_baseline_info_24" />
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -27,6 +27,8 @@
android:gravity="start|center_vertical" android:gravity="start|center_vertical"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:ellipsize="end"
android:singleLine="true"
app:layout_constraintStart_toEndOf="@+id/menu_icon" app:layout_constraintStart_toEndOf="@+id/menu_icon"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -24,6 +24,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:gravity="start|center_vertical" android:gravity="start|center_vertical"
android:ellipsize="end"
android:singleLine="true"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/radio" app:layout_constraintStart_toEndOf="@+id/radio"

View File

@ -1,4 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
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; either version 3 of the
License, or (at your option) any later version.
TubeLab 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 TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -1,4 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
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; either version 3 of the
License, or (at your option) any later version.
TubeLab 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 TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="utf-8"?><!--
Copyright 2020 Thomas Schneider
This file is a part of TubeLab
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; either version 3 of the
License, or (at your option) any later version.
TubeLab 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 TubeLab; if not,
see <http://www.gnu.org/licenses>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/popup_padding">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/action_privacy" />
<TextView
android:id="@+id/info_privacy"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/originally_published" />
<TextView
android:id="@+id/info_published_at"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/category" />
<TextView
android:id="@+id/info_category"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/license" />
<TextView
android:id="@+id/info_license"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/language" />
<TextView
android:id="@+id/info_language"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/tags" />
<TextView
android:id="@+id/info_tags"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<TextView
android:layout_width="170dp"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/sepia_element_duration" />
<TextView
android:id="@+id/info_duration"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true" />
</LinearLayout>
</LinearLayout>