diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-01-22 14:28:05 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-01-22 14:28:05 +0000 |
commit | 86570d495996141d3c74eecf7fc1735f9168ae50 (patch) | |
tree | bd6635bc63b42abfedbc03d86dba2c823cf78d4d /app/src/main/java/ml | |
parent | d733be6e55eccc6fef34b0065f6044e8402aa3ad (diff) | |
download | infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.tar infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.tar.gz infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.tar.bz2 infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.tar.lz infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.tar.xz infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.tar.zst infinity-for-reddit-86570d495996141d3c74eecf7fc1735f9168ae50.zip |
Enlarge the area which contains subreddit or user name and icon for easier touching in ViewPostDetailActivity. Fixed subreddit icon cannot be loaded in ViewPostDetailActivity. Smoothly play gif subreddit icon in ViewPostDetailActivity.
Diffstat (limited to 'app/src/main/java/ml')
3 files changed, 77 insertions, 35 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 4e97a934..4e4a30d2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -56,16 +56,11 @@ public class MainActivity extends AppCompatActivity { private static final String FETCH_USER_INFO_STATE = "FUIS"; private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS"; - @BindView(R.id.subscribed_subreddit_recycler_view_main_activity) - RecyclerView subscribedSubredditRecyclerView; - @BindView(R.id.subscriptions_label_main_activity) - TextView subscriptionsLabelTextView; - @BindView(R.id.subscribed_user_recycler_view_main_activity) - RecyclerView subscribedUserRecyclerView; - @BindView(R.id.following_label_main_activity) - TextView followingLabelTextView; - @BindView(R.id.profile_linear_layout_main_activity) - LinearLayout profileLinearLayout; + @BindView(R.id.subscribed_subreddit_recycler_view_main_activity) RecyclerView subscribedSubredditRecyclerView; + @BindView(R.id.subscriptions_label_main_activity) TextView subscriptionsLabelTextView; + @BindView(R.id.subscribed_user_recycler_view_main_activity) RecyclerView subscribedUserRecyclerView; + @BindView(R.id.following_label_main_activity) TextView followingLabelTextView; + @BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout; private TextView mNameTextView; private TextView mKarmaTextView; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 7028c81b..291d8e26 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -219,10 +219,17 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo ((DataViewHolder) holder).subredditIconNameLinearLayout.setOnClickListener(view -> { if(canStartActivity) { canStartActivity = false; - Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, - post.getSubredditNamePrefixed().substring(2)); - mContext.startActivity(intent); + if(post.getSubredditNamePrefixed().startsWith("u/")) { + Intent intent = new Intent(mContext, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, + post.getSubredditNamePrefixed().substring(2)); + mContext.startActivity(intent); + } else { + Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, + post.getSubredditNamePrefixed().substring(2)); + mContext.startActivity(intent); + } } }); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index 6b0c9e49..34601c3d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.graphics.ColorFilter; import android.graphics.PorterDuff; +import android.graphics.drawable.Animatable; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -28,6 +29,7 @@ import android.widget.Toast; import com.bumptech.glide.Glide; import com.bumptech.glide.RequestBuilder; +import com.bumptech.glide.RequestManager; import com.bumptech.glide.load.DataSource; import com.bumptech.glide.load.engine.GlideException; import com.bumptech.glide.request.RequestListener; @@ -43,11 +45,12 @@ import java.util.List; import javax.inject.Inject; import javax.inject.Named; +import CustomView.AspectRatioGifImageView; import SubredditDatabase.SubredditRoomDatabase; import butterknife.BindView; import butterknife.ButterKnife; -import de.hdodenhof.circleimageview.CircleImageView; import jp.wasabeef.glide.transformations.BlurTransformation; +import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import retrofit2.Retrofit; import ru.noties.markwon.SpannableConfiguration; import ru.noties.markwon.view.MarkwonView; @@ -57,6 +60,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { static final String EXTRA_TITLE = "ET"; static final String EXTRA_POST_DATA = "EPD"; + private RequestManager glide; + private int orientation; private String orientationState = "OS"; @@ -64,9 +69,10 @@ public class ViewPostDetailActivity extends AppCompatActivity { private Post mPost; @BindView(R.id.coordinator_layout_view_post_detail) CoordinatorLayout mCoordinatorLayout; - @BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) CircleImageView mSubredditIconCircleImageView; - @BindView(R.id.post_time_text_view_view_post_detail) TextView mPostTimeTextView; + @BindView(R.id.subreddit_icon_name_linear_layout_view_post_detail) LinearLayout mSubredditIconNameLinearLayout; + @BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) AspectRatioGifImageView mSubredditIconGifImageView; @BindView(R.id.subreddit_text_view_view_post_detail) TextView mSubredditTextView; + @BindView(R.id.post_time_text_view_view_post_detail) TextView mPostTimeTextView; @BindView(R.id.content_markdown_view_view_post_detail) MarkwonView mContentMarkdownView; @BindView(R.id.type_text_view_view_post_detail) Chip mTypeChip; @BindView(R.id.gilded_image_view_view_post_detail) ImageView mGildedImageView; @@ -121,34 +127,68 @@ public class ViewPostDetailActivity extends AppCompatActivity { TextView titleTextView = findViewById(R.id.title_text_view_view_post_detail); titleTextView.setText(mPost.getTitle()); + glide = Glide.with(this); if(mPost.getSubredditIconUrl() == null) { mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask( - SubredditRoomDatabase.getDatabase(this).subredditDao(), mPost.getSubredditNamePrefixed(), + SubredditRoomDatabase.getDatabase(this).subredditDao(), mPost.getSubredditNamePrefixed().substring(2), iconImageUrl -> { if(!iconImageUrl.equals("")) { - Glide.with(ViewPostDetailActivity.this).load(iconImageUrl) - .into(mSubredditIconCircleImageView); + glide.load(iconImageUrl) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon)) + .listener(new RequestListener<Drawable>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + if(resource instanceof Animatable) { + //This is a gif + //((Animatable) resource).start(); + mSubredditIconGifImageView.startAnimation(); + } + return false; + } + }) + .into(mSubredditIconGifImageView); } else { - Glide.with(ViewPostDetailActivity.this).load(R.drawable.subreddit_default_icon) - .into(mSubredditIconCircleImageView); + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(mSubredditIconGifImageView); } mPost.setSubredditIconUrl(iconImageUrl); }); mLoadSubredditIconAsyncTask.execute(); } else if(!mPost.getSubredditIconUrl().equals("")) { - Glide.with(this).load(mPost.getSubredditIconUrl()).into(mSubredditIconCircleImageView); + glide.load(mPost.getSubredditIconUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(glide.load(R.drawable.subreddit_default_icon)) + .listener(new RequestListener<Drawable>() { + @Override + public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) { + return false; + } + + @Override + public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) { + if(resource instanceof Animatable) { + //This is a gif + //((Animatable) resource).start(); + mSubredditIconGifImageView.startAnimation(); + } + return false; + } + }) + .into(mSubredditIconGifImageView); } else { - Glide.with(this).load(R.drawable.subreddit_default_icon).into(mSubredditIconCircleImageView); + glide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .into(mSubredditIconGifImageView); } - mSubredditIconCircleImageView.setOnClickListener(view -> { - Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, - mPost.getSubredditNamePrefixed().substring(2)); - startActivity(intent); - }); - switch (mPost.getVoteType()) { case 1: //Upvote @@ -176,7 +216,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { mRecyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); mSubredditTextView.setText(mPost.getSubredditNamePrefixed()); - mSubredditTextView.setOnClickListener(view -> { + mSubredditIconNameLinearLayout.setOnClickListener(view -> { Intent intent = new Intent(ViewPostDetailActivity.this, ViewSubredditDetailActivity.class); intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, mPost.getSubredditNamePrefixed().substring(2)); @@ -187,7 +227,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { if(mPost.getGilded() > 0) { mGildedImageView.setVisibility(View.VISIBLE); - Glide.with(this).load(R.drawable.gold).into(mGildedImageView); + glide.load(R.drawable.gold).into(mGildedImageView); mGildedNumberTextView.setVisibility(View.VISIBLE); String gildedNumber = getResources().getString(R.string.gilded, mPost.getGilded()); mGildedNumberTextView.setText(gildedNumber); @@ -432,7 +472,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { mCommentCardView.setVisibility(View.VISIBLE); } else { mNoCommentWrapperLinearLayout.setVisibility(View.VISIBLE); - Glide.with(ViewPostDetailActivity.this).load(R.drawable.no_comment_indicator).into(mNoCommentImageView); + glide.load(R.drawable.no_comment_indicator).into(mNoCommentImageView); } } @@ -453,7 +493,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { } private void loadImage() { - RequestBuilder imageRequestBuilder = Glide.with(this).load(mPost.getPreviewUrl()) + RequestBuilder imageRequestBuilder = glide.load(mPost.getPreviewUrl()) .apply(new RequestOptions().override(mPost.getPreviewWidth(), mPost.getPreviewHeight())) .listener(new RequestListener<Drawable>() { @Override |