From 0b2e358584add4c70550dea654acfc79994c3490 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 19 Sep 2019 17:16:31 +0800 Subject: Fixed frames dropping when playing videos. Use smaller icons for saving and unsaving comments. Temporarily show precise error message when loading posts failed. --- .../CommentAndPostRecyclerViewAdapter.java | 12 ++++++------ .../CommentsListingRecyclerViewAdapter.java | 12 ++++++------ .../infinityforreddit/PostDataSource.java | 18 +++++++++++------- .../infinityforreddit/PostFragment.java | 12 +++++++++++- .../infinityforreddit/ViewVideoActivity.java | 15 +++++++++------ 5 files changed, 43 insertions(+), 26 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index b3c501c0..ac80f670 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -749,9 +749,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -761,14 +761,14 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { @@ -301,14 +301,14 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter { @Override public void onParsePostsListingFail() { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data")); + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts")); } }); } } else { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, response.message())); + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, + "code: " + response.code() + " message: " + response.message())); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { String errorMessage = t.getMessage(); - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, errorMessage)); + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, + errorMessage + " " + call.request().url().toString())); } }); } @@ -270,7 +272,7 @@ class PostDataSource extends PageKeyedDataSource { @Override public void onParsePostsListingFail() { - paginationNetworkStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data")); + paginationNetworkStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing more posts")); } }); } else { @@ -342,19 +344,21 @@ class PostDataSource extends PageKeyedDataSource { @Override public void onParsePostsListingFail() { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing data")); + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, "Error parsing posts")); } }); } } else { - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, response.message())); + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, + "code: " + response + " message: " + response.message())); } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { String errorMessage = t.getMessage(); - initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, errorMessage)); + initialLoadStateLiveData.postValue(new NetworkState(NetworkState.Status.FAILED, + errorMessage + " " + call.request().url().toString())); } }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index 67a0b247..23cb85bc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -411,7 +411,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } else if(networkState.getStatus().equals(NetworkState.Status.FAILED)) { mProgressBar.setVisibility(View.GONE); mFetchPostInfoLinearLayout.setOnClickListener(view -> refresh()); - showErrorView(R.string.load_posts_error); + //showErrorView(R.string.load_posts_error); + showErrorView(networkState.getMsg()); } else { mProgressBar.setVisibility(View.VISIBLE); } @@ -466,6 +467,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator { } } + private void showErrorView(String message) { + if(activity != null && isAdded()) { + mProgressBar.setVisibility(View.GONE); + mFetchPostInfoLinearLayout.setVisibility(View.VISIBLE); + mFetchPostInfoTextView.setText(message); + mGlide.load(R.drawable.error_image).into(mFetchPostInfoImageView); + } + } + @Override public void changeNSFW(boolean nsfw) { mPostViewModel.changeNSFW(nsfw); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java index 640db3d7..ec336d65 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewVideoActivity.java @@ -38,8 +38,6 @@ import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; import com.google.android.exoplayer2.source.ExtractorMediaSource; -import com.google.android.exoplayer2.source.dash.DashChunkSource; -import com.google.android.exoplayer2.source.dash.DefaultDashChunkSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; @@ -49,6 +47,7 @@ import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; +import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory; import com.google.android.exoplayer2.util.Util; import java.io.File; @@ -291,17 +290,21 @@ public class ViewVideoActivity extends AppCompatActivity { TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoPlayerView.setPlayer(player); - // Produces DataSource instances through which media data is loaded. - DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, - Util.getUserAgent(this, "Infinity"), bandwidthMeter); + DataSource.Factory dataSourceFactory; // Prepare the player with the source. if(mIsHLSVideo) { - DashChunkSource.Factory dashChunkSourceFactory = new DefaultDashChunkSource.Factory(dataSourceFactory); + // Produces DataSource instances through which media data is loaded. + dataSourceFactory = new DefaultHttpDataSourceFactory( + Util.getUserAgent(this, "Infinity")); player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); } else { + // Produces DataSource instances through which media data is loaded. + dataSourceFactory = new DefaultDataSourceFactory(this, + Util.getUserAgent(this, "Infinity"), bandwidthMeter); player.prepare(new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); } + player.setRepeatMode(Player.REPEAT_MODE_ALL); player.setPlayWhenReady(true); wasPlaying = true; -- cgit v1.2.3