Fix some bugs when playing

This commit is contained in:
Thomas 2020-11-28 14:54:47 +01:00
parent 4b25b61680
commit 964b0f2690
5 changed files with 86 additions and 77 deletions

View File

@ -222,7 +222,7 @@
<string name="peertube_video_from_subscription"><![CDATA[<b>%1$s</b> a publié une nouvelle vidéo : <b>%2$s</b>]]></string>
<string name="peertube_video_blacklist"><![CDATA[Votre vidéo <b>%1$s</b> a été blacklisté]]></string>
<string name="peertube_video_unblacklist"><![CDATA[Votre vidéo <b>%1$s</b> nest plus blacklisté]]></string>
<string name="peertube_video_report_success"><![CDATA[Votre rapport d'abus <b>%1$s</b> a été accepté]]></string>
<string name="peertube_video_report_success"><![CDATA[Votre rapport dabus <b>%1$s</b> a été accepté]]></string>
<string name="peertube_video_abuse"><![CDATA[Nouveau signalement pour la vidéo : <b>%1$s</b>]]></string>
<string name="add_public_comment">Ajouter un commentaire public</string>
<string name="send_comment">Envoyer un commentaire</string>

View File

@ -24,7 +24,6 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -195,7 +194,6 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v(Helper.TAG, "onCreate: " + savedInstanceState);
binding = ActivityMainBinding.inflate(getLayoutInflater());
View view = binding.getRoot();
setContentView(view);
@ -240,7 +238,6 @@ public class MainActivity extends AppCompatActivity {
mostLikedFragment.setArguments(bundle);
overviewFragment = new DisplayOverviewFragment();
Log.v(Helper.TAG, "Helper.isLoggedIn(MainActivity.this): " + Helper.isLoggedIn(MainActivity.this));
if (!Helper.isLoggedIn(MainActivity.this)) {
PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
binding.viewpager.setAdapter(mPagerAdapter);
@ -632,7 +629,6 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onNewIntent(Intent intent) {
Log.v(Helper.TAG, "onNewIntent: " + intent);
super.onNewIntent(intent);
if (intent == null)
return;

View File

@ -193,6 +193,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
private String currentResolution;
private String currentCaption;
private boolean isRemote;
private boolean willPlayFromIntent;
public static void hideKeyboard(Activity activity) {
if (activity != null && activity.getWindow() != null) {
@ -301,7 +302,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
peertube = b.getParcelable("video");
}
manageIntentUrl(intent);
willPlayFromIntent = manageIntentUrl(intent);
binding.peertubeDescriptionMore.setOnClickListener(v -> {
if (show_more_content != null && peertube != null) {
@ -411,12 +412,13 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
});
if (peertube != null && sepiaSearch && peertube.getEmbedUrl() != null && Helper.isLoggedIn(PeertubeActivity.this)) {
if (!willPlayFromIntent && peertube != null && sepiaSearch && peertube.getEmbedUrl() != null && Helper.isLoggedIn(PeertubeActivity.this)) {
SearchVM viewModelSearch = new ViewModelProvider(PeertubeActivity.this).get(SearchVM.class);
viewModelSearch.getVideos("0", peertube.getEmbedUrl()).observe(PeertubeActivity.this, this::manageVIewVideos);
viewModelSearch.getVideos("0", peertube.getUuid()).observe(PeertubeActivity.this, this::manageVIewVideos);
} else {
playVideo();
}
registBroadcastReceiver();
if (autoFullscreen && autoPlay) {
openFullscreenDialog();
@ -446,7 +448,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
} else {
binding.videoSensitive.setVisibility(View.INVISIBLE);
}
if (peertube.getUserHistory() != null) {
if (player != null && peertube.getUserHistory() != null) {
player.seekTo(peertube.getUserHistory().getCurrentTime() * 1000);
}
sepiaSearch = false;
@ -529,10 +531,10 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
playVideo();
}
manageIntentUrl(intent);
willPlayFromIntent = manageIntentUrl(intent);
}
private void manageIntentUrl(Intent intent) {
private boolean manageIntentUrl(Intent intent) {
if (intent.getData() != null) { //Comes from a link
String url = intent.getData().toString();
Pattern link = Pattern.compile("(https?://[\\da-z.-]+\\.[a-z.]{2,10})/videos/watch/(\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12})(\\?start=(\\d+[hH])?(\\d+[mM])?(\\d+[sS])?)?$");
@ -572,6 +574,17 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
TimelineVM viewModelTimeline = new ViewModelProvider(PeertubeActivity.this).get(TimelineVM.class);
viewModelTimeline.getVideo(peertubeInstance, peertube.getUuid(), false).observe(PeertubeActivity.this, this::manageVIewVideo);
if (player != null) {
player.release();
}
if (comments != null && comments.size() > 0) {
int number = comments.size();
comments.clear();
commentListAdapter.notifyItemRangeRemoved(0, number);
}
fetchComments();
isRemote = true;
return true;
} else {
Helper.forwardToAnotherApp(PeertubeActivity.this, intent);
finish();
@ -581,6 +594,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
finish();
}
}
return false;
}
private void playVideo() {
@ -735,7 +749,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
@SuppressLint("ClickableViewAccessibility")
public void manageVIewVideo(APIResponse apiResponse) {
if (!isRemote && apiResponse != null && apiResponse.getPeertubes() != null && apiResponse.getPeertubes().get(0).getErrorCode() == 1 && apiResponse.getPeertubes().get(0).getOriginUrl() != null) {
String url = apiResponse.getPeertubes().get(0).getOriginUrl();
@ -758,7 +772,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
totalSeconds += 60 * minInt;
}
if (sec != null) {
secInt = Integer.parseInt(sec.replace("s", ""));
secInt = Integer.parseInt(sec.replace("strue", ""));
totalSeconds += secInt;
}
@ -899,26 +913,7 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
alertDialog.show();
});
if (peertube.isCommentsEnabled()) {
if (Helper.isLoggedIn(PeertubeActivity.this)) {
binding.postCommentButton.setVisibility(View.VISIBLE);
} else {
binding.postCommentButton.setVisibility(View.GONE);
}
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
commentViewModel.getThread(sepiaSearch ? peertubeInstance : null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
binding.writeCommentContainer.setVisibility(View.VISIBLE);
}
binding.peertubeComments.setVisibility(View.VISIBLE);
} else {
binding.postCommentButton.setVisibility(View.GONE);
binding.peertubeComments.setVisibility(View.GONE);
binding.writeCommentContainer.setVisibility(View.GONE);
binding.noActionText.setText(getString(R.string.comment_no_allowed_peertube));
binding.noAction.setVisibility(View.VISIBLE);
binding.writeCommentContainer.setVisibility(View.GONE);
}
fetchComments();
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
setTitle(peertube.getName());
@ -1161,6 +1156,30 @@ public class PeertubeActivity extends AppCompatActivity implements CommentListAd
}
}
private void fetchComments() {
if (peertube.isCommentsEnabled()) {
if (Helper.isLoggedIn(PeertubeActivity.this)) {
binding.postCommentButton.setVisibility(View.VISIBLE);
} else {
binding.postCommentButton.setVisibility(View.GONE);
}
CommentVM commentViewModel = new ViewModelProvider(PeertubeActivity.this).get(CommentVM.class);
commentViewModel.getThread(sepiaSearch ? peertubeInstance : null, videoUuid, max_id).observe(PeertubeActivity.this, this::manageVIewComment);
if (Helper.isLoggedIn(PeertubeActivity.this) && !sepiaSearch) {
binding.writeCommentContainer.setVisibility(View.VISIBLE);
}
binding.peertubeComments.setVisibility(View.VISIBLE);
binding.noAction.setVisibility(View.GONE);
} else {
binding.postCommentButton.setVisibility(View.GONE);
binding.peertubeComments.setVisibility(View.GONE);
binding.writeCommentContainer.setVisibility(View.GONE);
binding.noActionText.setText(getString(R.string.comment_no_allowed_peertube));
binding.noAction.setVisibility(View.VISIBLE);
binding.writeCommentContainer.setVisibility(View.GONE);
}
}
private void startStream(String videoURL, String streamingPlaylistsURLS, boolean autoPlay, long position, Uri subtitles, String lang, boolean promptNSFW) {
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);

View File

@ -932,6 +932,7 @@ public class RetrofitPeertubeAPI {
APIResponse apiResponse = new APIResponse();
try {
Response<VideoData> response = searchVideosCall.execute();
if (response.isSuccessful() && response.body() != null) {
apiResponse.setPeertubes(response.body().data);
} else {

View File

@ -22,17 +22,15 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.jetbrains.annotations.NotNull;
@ -44,6 +42,7 @@ import app.fedilab.fedilabtube.R;
import app.fedilab.fedilabtube.client.data.ChannelData;
import app.fedilab.fedilabtube.client.data.VideoData;
import app.fedilab.fedilabtube.client.entities.SepiaSearch;
import app.fedilab.fedilabtube.databinding.FragmentVideoBinding;
import app.fedilab.fedilabtube.drawer.AccountsHorizontalListAdapter;
import app.fedilab.fedilabtube.drawer.PeertubeAdapter;
import app.fedilab.fedilabtube.helper.Helper;
@ -62,23 +61,24 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
private Context context;
private PeertubeAdapter peertubeAdapater;
private List<VideoData.Video> peertubes;
private RelativeLayout mainLoader, nextElementLoader, textviewNoAction;
private boolean firstLoad;
private SwipeRefreshLayout swipeRefreshLayout;
private SharedPreferences sharedpreferences;
private TextView textviewNoActionText;
private View rootView;
private RecyclerView lv_status;
private SepiaSearchVM viewModelSearch;
private SepiaSearch sepiaSearchVideo;
private FragmentVideoBinding binding;
public DisplaySepiaSearchFragment() {
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_video, container, false);
binding = FragmentVideoBinding.inflate(inflater, container, false);
return binding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
peertubes = new ArrayList<>();
context = getContext();
@ -86,40 +86,35 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
if (bundle != null) {
sepiaSearchVideo = bundle.getParcelable("sepiaSearchVideo");
}
lv_status = rootView.findViewById(R.id.lv_status);
flag_loading = true;
firstLoad = true;
assert context != null;
sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
swipeRefreshLayout = rootView.findViewById(R.id.swipeContainer);
mainLoader = rootView.findViewById(R.id.loader);
nextElementLoader = rootView.findViewById(R.id.loading_next_status);
textviewNoAction = rootView.findViewById(R.id.no_action);
textviewNoActionText = rootView.findViewById(R.id.no_action_text);
mainLoader.setVisibility(View.VISIBLE);
nextElementLoader.setVisibility(View.GONE);
binding.loader.setVisibility(View.VISIBLE);
binding.loadingNextVideos.setVisibility(View.GONE);
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH, true);
lv_status.setAdapter(peertubeAdapater);
binding.lvVideos.setAdapter(peertubeAdapater);
if (!Helper.isTablet(context)) {
mLayoutManager = new LinearLayoutManager(context);
lv_status.setLayoutManager(mLayoutManager);
binding.lvVideos.setLayoutManager(mLayoutManager);
} else {
gLayoutManager = new GridLayoutManager(context, 2);
int spanCount = (int) Helper.convertDpToPixel(2, context);
int spacing = (int) Helper.convertDpToPixel(5, context);
lv_status.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
lv_status.setLayoutManager(gLayoutManager);
binding.lvVideos.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, true));
binding.lvVideos.setLayoutManager(gLayoutManager);
}
viewModelSearch = new ViewModelProvider(DisplaySepiaSearchFragment.this).get(SepiaSearchVM.class);
swipeRefreshLayout.setOnRefreshListener(this::pullToRefresh);
binding.swipeContainer.setOnRefreshListener(this::pullToRefresh);
lv_status.addOnScrollListener(new RecyclerView.OnScrollListener() {
binding.lvVideos.addOnScrollListener(new RecyclerView.OnScrollListener() {
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (mLayoutManager != null) {
int firstVisibleItem = mLayoutManager.findFirstVisibleItemPosition();
@ -130,10 +125,10 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
if (!flag_loading) {
flag_loading = true;
loadTimeline();
nextElementLoader.setVisibility(View.VISIBLE);
binding.loadingNextVideos.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
binding.loadingNextVideos.setVisibility(View.GONE);
}
}
} else if (gLayoutManager != null) {
@ -145,27 +140,26 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
if (!flag_loading) {
flag_loading = true;
loadTimeline();
nextElementLoader.setVisibility(View.VISIBLE);
binding.loadingNextVideos.setVisibility(View.VISIBLE);
}
} else {
nextElementLoader.setVisibility(View.GONE);
binding.loadingNextVideos.setVisibility(View.GONE);
}
}
}
}
});
loadTimeline();
return rootView;
}
@Override
public void onPause() {
super.onPause();
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(false);
swipeRefreshLayout.setRefreshing(false);
swipeRefreshLayout.clearAnimation();
if (binding.swipeContainer != null) {
binding.swipeContainer.setEnabled(false);
binding.swipeContainer.setRefreshing(false);
binding.swipeContainer.clearAnimation();
}
if (getActivity() != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
@ -202,12 +196,12 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
private void manageVIewVideos(VideoData videoData) {
//hide loaders
mainLoader.setVisibility(View.GONE);
nextElementLoader.setVisibility(View.GONE);
binding.loader.setVisibility(View.GONE);
binding.loadingNextVideos.setVisibility(View.GONE);
//handle other API error
if (videoData == null || videoData.data == null) {
Toasty.error(context, context.getString(R.string.toast_error), Toast.LENGTH_LONG).show();
swipeRefreshLayout.setRefreshing(false);
binding.swipeContainer.setRefreshing(false);
flag_loading = false;
return;
}
@ -228,16 +222,16 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
//If no item were inserted previously the adapter is created
if (previousPosition == 0) {
peertubeAdapater = new PeertubeAdapter(this.peertubes, SEPIA_SEARCH, true);
lv_status.setAdapter(peertubeAdapater);
binding.lvVideos.setAdapter(peertubeAdapater);
} else
peertubeAdapater.notifyItemRangeInserted(previousPosition, videoData.data.size());
//remove handlers
swipeRefreshLayout.setRefreshing(false);
textviewNoAction.setVisibility(View.GONE);
binding.swipeContainer.setRefreshing(false);
binding.noAction.setVisibility(View.GONE);
if (firstLoad && (videoData.data == null || videoData.data.size() == 0)) {
textviewNoActionText.setText(R.string.no_video_to_display);
textviewNoAction.setVisibility(View.VISIBLE);
binding.noActionText.setText(R.string.no_video_to_display);
binding.noAction.setVisibility(View.VISIBLE);
}
flag_loading = false;
firstLoad = false;
@ -245,20 +239,19 @@ public class DisplaySepiaSearchFragment extends Fragment implements AccountsHori
@Override
public void onDestroyView() {
if (lv_status != null) {
if (binding.lvVideos != null) {
try {
lv_status.setAdapter(null);
binding.lvVideos.setAdapter(null);
} catch (Exception ignored) {
}
}
super.onDestroyView();
rootView = null;
}
@Override
public void onResume() {
super.onResume();
swipeRefreshLayout.setEnabled(true);
binding.swipeContainer.setEnabled(true);
}