aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-01-22 14:28:05 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-01-22 14:28:05 +0000
commit86570d495996141d3c74eecf7fc1735f9168ae50 (patch)
treebd6635bc63b42abfedbc03d86dba2c823cf78d4d /app
parentd733be6e55eccc6fef34b0065f6044e8402aa3ad (diff)
downloadinfinity-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')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java82
-rw-r--r--app/src/main/res/layout/activity_view_post_detail.xml52
-rw-r--r--app/src/main/res/layout/item_post.xml3
5 files changed, 108 insertions, 59 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
diff --git a/app/src/main/res/layout/activity_view_post_detail.xml b/app/src/main/res/layout/activity_view_post_detail.xml
index bb2bd0e2..103edf40 100644
--- a/app/src/main/res/layout/activity_view_post_detail.xml
+++ b/app/src/main/res/layout/activity_view_post_detail.xml
@@ -26,38 +26,47 @@
android:layout_height="match_parent"
android:orientation="vertical">
- <RelativeLayout
+ <android.support.constraint.ConstraintLayout
android:id="@+id/relative_layout_view_post_detail"
android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_margin="16dp">
-
- <de.hdodenhof.circleimageview.CircleImageView
- android:id="@+id/subreddit_icon_circle_image_view_view_post_detail"
- android:layout_width="24dp"
- android:layout_height="24dp"
- android:layout_alignParentStart="true"
- android:layout_centerVertical="true" />
+ android:layout_height="wrap_content">
- <TextView
- android:id="@+id/subreddit_text_view_view_post_detail"
+ <LinearLayout
+ android:id="@+id/subreddit_icon_name_linear_layout_view_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_marginStart="16dp"
- android:layout_marginEnd="16dp"
- android:layout_toEndOf="@id/subreddit_icon_circle_image_view_view_post_detail"
- android:layout_toStartOf="@id/post_time_text_view_view_post_detail"
- android:textColor="#E91E63" />
+ android:padding="16dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
+
+ <CustomView.AspectRatioGifImageView
+ android:id="@+id/subreddit_icon_circle_image_view_view_post_detail"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center"/>
+
+ <TextView
+ android:id="@+id/subreddit_text_view_view_post_detail"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="16dp"
+ android:layout_gravity="center"
+ android:textColor="#E91E63" />
+
+ </LinearLayout>
<TextView
android:id="@+id/post_time_text_view_view_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_centerVertical="true" />
+ android:layout_gravity="center"
+ android:layout_marginEnd="16dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent"/>
- </RelativeLayout>
+ </android.support.constraint.ConstraintLayout>
<TextView
android:id="@+id/title_text_view_view_post_detail"
@@ -93,6 +102,7 @@
android:layout_marginEnd="8dp"
android:textSize="12sp"
android:textColor="@android:color/white"
+ android:layout_centerVertical="true"
app:chipBackgroundColor="@color/colorPrimaryDark"/>
<ImageView
diff --git a/app/src/main/res/layout/item_post.xml b/app/src/main/res/layout/item_post.xml
index 585c8931..b3d32486 100644
--- a/app/src/main/res/layout/item_post.xml
+++ b/app/src/main/res/layout/item_post.xml
@@ -37,7 +37,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
- android:layout_marginEnd="8dp"
android:layout_gravity="center"
android:textColor="#E91E63" />
@@ -72,9 +71,7 @@
android:id="@+id/title_text_view_best_post_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
- android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:textSize="18sp"
android:textColor="#000000"/>