aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-11-15 16:20:09 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-11-15 16:20:09 +0000
commitee60cbf640df8386bd7ffab0508edff9c283fdbd (patch)
treeae95ba175ad79d5f3349ea247ff078fc90083133 /app/src/main
parente0a9a02157153cbfd27ad6dacbfbabba158a278d (diff)
downloadinfinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.tar
infinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.tar.gz
infinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.tar.bz2
infinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.tar.lz
infinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.tar.xz
infinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.tar.zst
infinity-for-reddit-ee60cbf640df8386bd7ffab0508edff9c283fdbd.zip
Swipe right to go back from ViewPostDetailActivity. Fix inconsistency in elapsed time.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java40
-rw-r--r--app/src/main/res/values/strings.xml13
-rw-r--r--app/src/main/res/xml/main_preferences.xml5
8 files changed, 76 insertions, 37 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index 4b38e45b..66457f9a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -4,7 +4,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
-import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.Menu;
@@ -34,9 +33,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar;
import com.livefront.bridge.Bridge;
import com.r0adkll.slidr.Slidr;
-import com.r0adkll.slidr.model.SlidrConfig;
-import com.r0adkll.slidr.model.SlidrListener;
-import com.r0adkll.slidr.model.SlidrPosition;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -186,16 +182,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
EventBus.getDefault().register(this);
- SlidrConfig config = new SlidrConfig.Builder()
- .sensitivity(1f)
- .scrimColor(Color.BLACK)
- .scrimStartAlpha(0.8f)
- .scrimEndAlpha(0f)
- .velocityThreshold(2400)
- .distanceThreshold(0.25f)
- .build();
-
- Slidr.attach(this);
+ if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL, true)) {
+ Slidr.attach(this);
+ }
Resources resources = getResources();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index 3a21d872..da09328f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -35,13 +35,10 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
-import com.github.thunder413.datetimeutils.DateTimeStyle;
-import com.github.thunder413.datetimeutils.DateTimeUtils;
import com.libRG.CustomTextView;
import com.santalu.aspectratioimageview.AspectRatioImageView;
import java.util.ArrayList;
-import java.util.Date;
import java.util.Locale;
import butterknife.BindView;
@@ -73,8 +70,9 @@ import ml.docilealligator.infinityforreddit.Post;
import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import ml.docilealligator.infinityforreddit.SaveThing;
+import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import ml.docilealligator.infinityforreddit.VoteThing;
import retrofit2.Retrofit;
@@ -367,7 +365,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (mShowElapsedTime) {
((PostDetailViewHolder) holder).mPostTimeTextView.setText(
- DateTimeUtils.getTimeAgo(mActivity, new Date(mPost.getPostTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
+ Utils.getElapsedTime(mActivity, mPost.getPostTimeMillis()));
} else {
((PostDetailViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime());
}
@@ -615,7 +613,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if (mShowElapsedTime) {
((CommentViewHolder) holder).commentTimeTextView.setText(
- DateTimeUtils.getTimeAgo(mActivity, new Date(comment.getCommentTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
+ Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
} else {
((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
index 1f629072..ed76dcba 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentsListingRecyclerViewAdapter.java
@@ -24,11 +24,6 @@ import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
-import com.github.thunder413.datetimeutils.DateTimeStyle;
-import com.github.thunder413.datetimeutils.DateTimeUtils;
-
-import java.util.Date;
-
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
@@ -44,8 +39,9 @@ import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.Fragment.ModifyCommentBottomSheetFragment;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
-import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import ml.docilealligator.infinityforreddit.SaveThing;
+import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import ml.docilealligator.infinityforreddit.VoteThing;
import retrofit2.Retrofit;
@@ -148,7 +144,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
if (mShowElapsedTime) {
((DataViewHolder) holder).commentTimeTextView.setText(
- DateTimeUtils.getTimeAgo(mContext, new Date(comment.getCommentTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
+ Utils.getElapsedTime(mContext, comment.getCommentTimeMillis()));
} else {
((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index 8c7c443d..96f1ce3f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -33,15 +33,11 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
-import com.github.thunder413.datetimeutils.DateTimeStyle;
-import com.github.thunder413.datetimeutils.DateTimeUtils;
import com.google.android.material.card.MaterialCardView;
import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
-import java.util.Date;
-
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.BlurTransformation;
@@ -63,10 +59,11 @@ import ml.docilealligator.infinityforreddit.Post;
import ml.docilealligator.infinityforreddit.PostDataSource;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
import ml.docilealligator.infinityforreddit.SaveThing;
-import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.User.UserDao;
+import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+import ml.docilealligator.infinityforreddit.Utils.Utils;
import ml.docilealligator.infinityforreddit.VoteThing;
import retrofit2.Retrofit;
@@ -340,8 +337,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
if (mShowElapsedTime) {
- ((PostViewHolder) holder).postTimeTextView.setText(DateTimeUtils
- .getTimeAgo(mContext, new Date(post.getPostTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
+ ((PostViewHolder) holder).postTimeTextView.setText(
+ Utils.getElapsedTime(mContext, post.getPostTimeMillis()));
} else {
((PostViewHolder) holder).postTimeTextView.setText(postTime);
}
@@ -890,8 +887,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
if (mShowElapsedTime) {
- ((PostCompactViewHolder) holder).postTimeTextView.setText(DateTimeUtils
- .getTimeAgo(mContext, new Date(post.getPostTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
+ ((PostCompactViewHolder) holder).postTimeTextView.setText(
+ Utils.getElapsedTime(mContext, post.getPostTimeMillis()));
} else {
((PostCompactViewHolder) holder).postTimeTextView.setText(postTime);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
index 4379beaf..aa612bed 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -57,4 +57,5 @@ public class SharedPreferencesUtils {
public static final int POST_LAYOUT_COMPACT = 1;
public static final String PULL_NOTIFICATION_TIME = "pull_notification_time";
public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time";
+ public static final String SWIPE_RIGHT_TO_GO_BACK_FROM_POST_DETAIL = "swipe_to_go_back_from_post_detail";
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
index c5c299be..4363fde3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/Utils.java
@@ -1,6 +1,17 @@
package ml.docilealligator.infinityforreddit.Utils;
+import android.content.Context;
+
+import ml.docilealligator.infinityforreddit.R;
+
public class Utils {
+ private static final long SECOND_MILLIS = 1000;
+ private static final long MINUTE_MILLIS = 60 * SECOND_MILLIS;
+ private static final long HOUR_MILLIS = 60 * MINUTE_MILLIS;
+ private static final long DAY_MILLIS = 24 * HOUR_MILLIS;
+ private static final long MONTH_MILLIS = 30 * DAY_MILLIS;
+ private static final long YEAR_MILLIS = 12 * MONTH_MILLIS;
+
public static String addSubredditAndUserLink(String markdown) {
return markdown.replaceAll("((?<=[\\s])|^)/{0,1}[rRuU]/\\w+/{0,1}", "[$0]($0)");
}
@@ -19,4 +30,33 @@ public class Utils {
return source.subSequence(0, i+1);
}
+
+ public static String getElapsedTime(Context context, long time) {
+ long now = System.currentTimeMillis();
+ long diff = now - time;
+
+ if (diff < MINUTE_MILLIS) {
+ return context.getString(R.string.elapsed_time_just_now);
+ } else if (diff < 2 * MINUTE_MILLIS) {
+ return context.getString(R.string.elapsed_time_a_minute_ago);
+ } else if (diff < 50 * MINUTE_MILLIS) {
+ return context.getString(R.string.elapsed_time_minutes_ago, diff / MINUTE_MILLIS);
+ } else if (diff < 90 * MINUTE_MILLIS) {
+ return context.getString(R.string.elapsed_time_an_hour_ago);
+ } else if (diff < 24 * HOUR_MILLIS) {
+ return context.getString(R.string.elapsed_time_hours_ago, diff / HOUR_MILLIS);
+ } else if (diff < 48 * HOUR_MILLIS) {
+ return context.getString(R.string.elapsed_time_yesterday);
+ } else if (diff < MONTH_MILLIS) {
+ return context.getString(R.string.elapsed_time_days_ago, diff / DAY_MILLIS);
+ } else if (diff < 2 * MONTH_MILLIS) {
+ return context.getString(R.string.elapsed_time_a_month_ago);
+ } else if (diff < YEAR_MILLIS) {
+ return context.getString(R.string.elapsed_time_months_ago, diff / MONTH_MILLIS);
+ } else if (diff < 2 * YEAR_MILLIS) {
+ return context.getString(R.string.elapsed_time_a_year_ago);
+ } else {
+ return context.getString(R.string.elapsed_time_years_ago, diff / YEAR_MILLIS);
+ }
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index db0ed690..88228a44 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -290,6 +290,7 @@
<string name="settings_immersive_interface_title">Immersive Interface</string>
<string name="settings_vote_buttons_on_the_right_title">Vote Buttons on the Right</string>
<string name="settings_show_elapsed_time">Show Elpased Time in Posts and Comments</string>
+ <string name="swipe_to_go_back_from_post_detail">Swipe Right to Go Back From Comments</string>
<string name="settings_lazy_mode_interval_title">Lazy Mode Interval</string>
<string name="settings_font_size_title">Font Size</string>
<string name="settings_title_font_size_title">Title Font Size</string>
@@ -353,4 +354,16 @@
<string name="post_layout_card">Card Layout</string>
<string name="post_layout_compact">Compact Layout</string>
+
+ <string name="elapsed_time_just_now">Just Now</string>
+ <string name="elapsed_time_a_minute_ago">1 Minute</string>
+ <string name="elapsed_time_minutes_ago">%1$d Minutes</string>
+ <string name="elapsed_time_an_hour_ago">1 Hour</string>
+ <string name="elapsed_time_hours_ago">%1$d Hours</string>
+ <string name="elapsed_time_yesterday">Yesterday</string>
+ <string name="elapsed_time_days_ago">%1$d Days</string>
+ <string name="elapsed_time_a_month_ago">1 Month</string>
+ <string name="elapsed_time_months_ago">%1$d Months</string>
+ <string name="elapsed_time_a_year_ago">1 Year</string>
+ <string name="elapsed_time_years_ago">%1$d Years</string>
</resources>
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index 548bf949..db4b75a1 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -36,6 +36,11 @@
app:key="show_elapsed_time"
app:title="@string/settings_show_elapsed_time"/>
+ <SwitchPreference
+ app:defaultValue="true"
+ app:key="swipe_to_go_back_from_post_detail"
+ app:title="@string/swipe_to_go_back_from_post_detail"/>
+
<Preference
app:title="@string/settings_font_size_title"
app:icon="@drawable/ic_font_size_24dp"