Fixed frames dropping when playing videos. Use smaller icons for saving and unsaving comments. Temporarily show precise error message when loading posts failed.

This commit is contained in:
Alex Ning 2019-09-19 17:16:31 +08:00
parent 50da29ad8c
commit 0b2e358584
10 changed files with 53 additions and 28 deletions

View File

@ -159,8 +159,8 @@
<map>
<entry key="assetSourceType" value="FILE" />
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_tack_save_button" />
<entry key="sourceFile" value="$USER_HOME$/Downloads/tack-save-button.svg" />
<entry key="outputName" value="ic_bookmark_border_18dp" />
<entry key="sourceFile" value="$USER_HOME$/Documents/24px.svg" />
</map>
</option>
</PersistentState>

Binary file not shown.

Binary file not shown.

View File

@ -749,9 +749,9 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
});
if(comment.isSaved()) {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_20dp);
} else {
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_20dp);
}
((CommentViewHolder) holder).saveButton.setOnClickListener(view -> {
@ -761,14 +761,14 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
@Override
public void success() {
comment.setSaved(false);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_20dp);
Toast.makeText(mActivity, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@Override
public void failed() {
comment.setSaved(true);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_20dp);
Toast.makeText(mActivity, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
});
@ -778,14 +778,14 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
@Override
public void success() {
comment.setSaved(true);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_20dp);
Toast.makeText(mActivity, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@Override
public void failed() {
comment.setSaved(false);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px);
((CommentViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_20dp);
Toast.makeText(mActivity, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
});

View File

@ -289,9 +289,9 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
});
if(comment.isSaved()) {
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_20dp);
} else {
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_20dp);
}
((DataViewHolder) holder).saveButton.setOnClickListener(view -> {
@ -301,14 +301,14 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
@Override
public void success() {
comment.setSaved(false);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_20dp);
Toast.makeText(mContext, R.string.comment_unsaved_success, Toast.LENGTH_SHORT).show();
}
@Override
public void failed() {
comment.setSaved(true);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_20dp);
Toast.makeText(mContext, R.string.comment_unsaved_failed, Toast.LENGTH_SHORT).show();
}
});
@ -318,14 +318,14 @@ class CommentsListingRecyclerViewAdapter extends PagedListAdapter<CommentData, R
@Override
public void success() {
comment.setSaved(true);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_24px);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_20dp);
Toast.makeText(mContext, R.string.comment_saved_success, Toast.LENGTH_SHORT).show();
}
@Override
public void failed() {
comment.setSaved(false);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_baseline_bookmark_border_24px);
((DataViewHolder) holder).saveButton.setImageResource(R.drawable.ic_bookmark_border_20dp);
Toast.makeText(mContext, R.string.comment_saved_failed, Toast.LENGTH_SHORT).show();
}
});

View File

@ -229,19 +229,21 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
@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<String> 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<String, Post> {
@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<String, Post> {
@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<String> 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()));
}
});
}

View File

@ -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);

View File

@ -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;

View File

@ -0,0 +1,4 @@
<vector android:height="20dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17,3H7c-1.1,0 -2,0.9 -2,2v16l7,-3 7,3V5c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

View File

@ -0,0 +1,4 @@
<vector android:height="20dp" android:viewportHeight="24"
android:viewportWidth="24" android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M17,3L7,3c-1.1,0 -2,0.9 -2,2v16l7,-3 7,3L19,5c0,-1.1 -0.9,-2 -2,-2zM17,18l-5,-2.18L7,18L7,5h10v13z"/>
</vector>