Showing elapsed time in posts and comments is available.

This commit is contained in:
Alex Ning 2019-11-12 19:31:28 +08:00
parent 0aaa63b6f6
commit a0aae589d7
18 changed files with 187 additions and 77 deletions

View File

@ -6,8 +6,8 @@ android {
applicationId "ml.docilealligator.infinityforreddit" applicationId "ml.docilealligator.infinityforreddit"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 20 versionCode 21
versionName "1.4.1" versionName "1.5.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
@ -80,4 +80,5 @@ dependencies {
implementation 'androidx.work:work-runtime:2.2.0' implementation 'androidx.work:work-runtime:2.2.0'
implementation 'androidx.preference:preference:1.1.0' implementation 'androidx.preference:preference:1.1.0'
implementation 'com.nex3z:flow-layout:1.3.0' implementation 'com.nex3z:flow-layout:1.3.0'
implementation 'com.github.thunder413:DateTimeUtils:3.0'
} }

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="ml.docilealligator.infinityforreddit"> package="ml.docilealligator.infinityforreddit">
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
@ -14,11 +15,12 @@
android:name=".Infinity" android:name=".Infinity"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/application_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"> android:usesCleartextTraffic="true"
tools:replace="android:label">
<activity <activity
android:name=".Activity.ViewGIFActivity" android:name=".Activity.ViewGIFActivity"
android:parentActivityName=".Activity.MainActivity" android:parentActivityName=".Activity.MainActivity"
@ -212,7 +214,7 @@
android:theme="@style/AppTheme.NoActionBar" /> android:theme="@style/AppTheme.NoActionBar" />
<activity <activity
android:name=".Activity.MainActivity" android:name=".Activity.MainActivity"
android:label="@string/app_name" android:label="@string/application_name"
android:theme="@style/AppTheme.Launcher"> android:theme="@style/AppTheme.Launcher">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@ -160,6 +160,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
private boolean mNeedBlurNsfw; private boolean mNeedBlurNsfw;
private boolean mNeedBlurSpoiler; private boolean mNeedBlurSpoiler;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private boolean showToast = false; private boolean showToast = false;
private boolean isSortingComments = false; private boolean isSortingComments = false;
private LinearLayoutManager mLinearLayoutManager; private LinearLayoutManager mLinearLayoutManager;
@ -234,6 +235,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mNeedBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); mNeedBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true);
mNeedBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); mNeedBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false);
mVoteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); mVoteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mGlide = Glide.with(this); mGlide = Glide.with(this);
mLocale = getResources().getConfiguration().locale; mLocale = getResources().getConfiguration().locale;
@ -387,7 +389,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit,
mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost,
mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mVoteButtonsOnTheRight, mShowElapsedTime,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {
@ -508,7 +510,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide,
mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId,
isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler,
mVoteButtonsOnTheRight, mVoteButtonsOnTheRight, mShowElapsedTime,
new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() {
@Override @Override
public void updatePost(Post post) { public void updatePost(Post post) {

View File

@ -35,10 +35,13 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target; 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.libRG.CustomTextView;
import com.santalu.aspectratioimageview.AspectRatioImageView; import com.santalu.aspectratioimageview.AspectRatioImageView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Locale; import java.util.Locale;
import butterknife.BindView; import butterknife.BindView;
@ -105,6 +108,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mNeedBlurNSFW; private boolean mNeedBlurNSFW;
private boolean mNeedBlurSpoiler; private boolean mNeedBlurSpoiler;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback; private CommentRecyclerViewAdapterCallback mCommentRecyclerViewAdapterCallback;
private boolean isInitiallyLoading; private boolean isInitiallyLoading;
private boolean isInitiallyLoadingFailed; private boolean isInitiallyLoadingFailed;
@ -117,6 +121,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
String accessToken, String accountName, Post post, Locale locale, String accessToken, String accountName, Post post, Locale locale,
String singleCommentId, boolean isSingleCommentThreadMode, String singleCommentId, boolean isSingleCommentThreadMode,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight, boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
boolean showElapsedTime,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) { CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity; mActivity = activity;
mRetrofit = retrofit; mRetrofit = retrofit;
@ -153,6 +158,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mNeedBlurNSFW = needBlurNSFW; mNeedBlurNSFW = needBlurNSFW;
mNeedBlurSpoiler = needBlurSpoiler; mNeedBlurSpoiler = needBlurSpoiler;
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback; mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true; isInitiallyLoading = true;
isInitiallyLoadingFailed = false; isInitiallyLoadingFailed = false;
@ -359,7 +365,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed()); ((PostDetailViewHolder) holder).mSubredditTextView.setText(mPost.getSubredditNamePrefixed());
((PostDetailViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed()); ((PostDetailViewHolder) holder).mUserTextView.setText(mPost.getAuthorNamePrefixed());
((PostDetailViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime()); if (mShowElapsedTime) {
((PostDetailViewHolder) holder).mPostTimeTextView.setText(
DateTimeUtils.getTimeAgo(mActivity, new Date(mPost.getPostTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
} else {
((PostDetailViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime());
}
if (mPost.getGilded() > 0) { if (mPost.getGilded() > 0) {
((PostDetailViewHolder) holder).mGildedNumberTextView.setVisibility(View.VISIBLE); ((PostDetailViewHolder) holder).mGildedNumberTextView.setVisibility(View.VISIBLE);
@ -602,7 +613,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).authorTypeImageView.setImageResource(R.drawable.ic_verified_user_14dp); ((CommentViewHolder) holder).authorTypeImageView.setImageResource(R.drawable.ic_verified_user_14dp);
} }
((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime()); if (mShowElapsedTime) {
((CommentViewHolder) holder).commentTimeTextView.setText(
DateTimeUtils.getTimeAgo(mActivity, new Date(comment.getCommentTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
} else {
((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
}
mMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentContent()); mMarkwon.setMarkdown(((CommentViewHolder) holder).commentMarkdownView, comment.getCommentContent());
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType())); ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(comment.getScore() + comment.getVoteType()));

View File

@ -24,6 +24,11 @@ import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView; 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.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.AbstractMarkwonPlugin;
@ -67,13 +72,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private int mTextColorPrimaryDark; private int mTextColorPrimaryDark;
private int mColorAccent; private int mColorAccent;
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private NetworkState networkState; private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback; private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit, public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
String accessToken, String accountName, String accessToken, String accountName,
boolean voteButtonsOnTheRight, boolean voteButtonsOnTheRight,
RetryLoadingMoreCallback retryLoadingMoreCallback) { boolean showElapsedTime, RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK); super(DIFF_CALLBACK);
mContext = context; mContext = context;
mOauthRetrofit = oauthRetrofit; mOauthRetrofit = oauthRetrofit;
@ -99,6 +105,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
mAccessToken = accessToken; mAccessToken = accessToken;
mAccountName = accountName; mAccountName = accountName;
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mRetryLoadingMoreCallback = retryLoadingMoreCallback; mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme); mTextColorPrimaryDark = mContext.getResources().getColor(R.color.colorPrimaryDarkDayNightTheme);
mColorAccent = mContext.getResources().getColor(R.color.colorAccent); mColorAccent = mContext.getResources().getColor(R.color.colorAccent);
@ -139,7 +146,12 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
}); });
} }
((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime()); if (mShowElapsedTime) {
((DataViewHolder) holder).commentTimeTextView.setText(
DateTimeUtils.getTimeAgo(mContext, new Date(comment.getCommentTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
} else {
((DataViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
}
mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentContent()); mMarkwon.setMarkdown(((DataViewHolder) holder).commentMarkdownView, comment.getCommentContent());

View File

@ -33,11 +33,15 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener; import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions; import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target; 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.google.android.material.card.MaterialCardView;
import com.libRG.CustomTextView; import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import java.util.Date;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
@ -99,6 +103,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mVoteButtonsOnTheRight; private boolean mVoteButtonsOnTheRight;
private boolean mNeedBlurNSFW; private boolean mNeedBlurNSFW;
private boolean mNeedBlurSpoiler; private boolean mNeedBlurSpoiler;
private boolean mShowElapsedTime;
private NetworkState networkState; private NetworkState networkState;
private Callback mCallback; private Callback mCallback;
@ -106,7 +111,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
RedditDataRoomDatabase redditDataRoomDatabase, String accessToken, RedditDataRoomDatabase redditDataRoomDatabase, String accessToken,
int postType, int postLayout, boolean displaySubredditName, int postType, int postLayout, boolean displaySubredditName,
boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight, boolean needBlurNSFW, boolean needBlurSpoiler, boolean voteButtonsOnTheRight,
Callback callback) { boolean showElapsedTime, Callback callback) {
super(DIFF_CALLBACK); super(DIFF_CALLBACK);
if (context != null) { if (context != null) {
mContext = context; mContext = context;
@ -118,6 +123,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mNeedBlurNSFW = needBlurNSFW; mNeedBlurNSFW = needBlurNSFW;
mNeedBlurSpoiler = needBlurSpoiler; mNeedBlurSpoiler = needBlurSpoiler;
mVoteButtonsOnTheRight = voteButtonsOnTheRight; mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mPostLayout = postLayout; mPostLayout = postLayout;
mGlide = Glide.with(mContext.getApplicationContext()); mGlide = Glide.with(mContext.getApplicationContext());
mRedditDataRoomDatabase = redditDataRoomDatabase; mRedditDataRoomDatabase = redditDataRoomDatabase;
@ -333,7 +339,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostViewHolder) holder).userTextView.performClick()); ((PostViewHolder) holder).userTextView.performClick());
} }
((PostViewHolder) holder).postTimeTextView.setText(postTime); if (mShowElapsedTime) {
((PostViewHolder) holder).postTimeTextView.setText(DateTimeUtils
.getTimeAgo(mContext, new Date(post.getPostTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
} else {
((PostViewHolder) holder).postTimeTextView.setText(postTime);
}
((PostViewHolder) holder).titleTextView.setText(title); ((PostViewHolder) holder).titleTextView.setText(title);
((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
@ -877,7 +889,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).nameTextView.performClick()); ((PostCompactViewHolder) holder).nameTextView.performClick());
} }
((PostCompactViewHolder) holder).postTimeTextView.setText(postTime); if (mShowElapsedTime) {
((PostCompactViewHolder) holder).postTimeTextView.setText(DateTimeUtils
.getTimeAgo(mContext, new Date(post.getPostTimeMillis()), DateTimeStyle.AGO_SHORT_STRING));
} else {
((PostCompactViewHolder) holder).postTimeTextView.setText(postTime);
}
((PostCompactViewHolder) holder).titleTextView.setText(title); ((PostCompactViewHolder) holder).titleTextView.setText(title);
((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType())); ((PostCompactViewHolder) holder).scoreTextView.setText(Integer.toString(post.getScore() + post.getVoteType()));
@ -1342,6 +1360,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mNeedBlurSpoiler = needBlurSpoiler; mNeedBlurSpoiler = needBlurSpoiler;
} }
public void setShowElapsedTime(boolean showElapsedTime) {
mShowElapsedTime = showElapsedTime;
}
private boolean hasExtraRow() { private boolean hasExtraRow() {
return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS; return networkState != null && networkState.getStatus() != NetworkState.Status.SUCCESS;
} }

View File

@ -26,6 +26,7 @@ public class CommentData implements Parcelable {
private String authorFlair; private String authorFlair;
private String linkAuthor; private String linkAuthor;
private String commentTime; private String commentTime;
private long commentTimeMillis;
private String commentContent; private String commentContent;
private String linkId; private String linkId;
private String subredditName; private String subredditName;
@ -49,7 +50,7 @@ public class CommentData implements Parcelable {
private boolean loadMoreChildrenFailed; private boolean loadMoreChildrenFailed;
public CommentData(String id, String fullName, String author, String authorFlair, String linkAuthor, String commentTime, public CommentData(String id, String fullName, String author, String authorFlair, String linkAuthor, String commentTime,
String commentContent, String linkId, String subredditName, String parentId, int score, long commentTimeMillis, String commentContent, String linkId, String subredditName, String parentId, int score,
int voteType, boolean isSubmitter, String distinguished, String permalink, int voteType, boolean isSubmitter, String distinguished, String permalink,
int depth, boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) { int depth, boolean collapsed, boolean hasReply, boolean scoreHidden, boolean saved) {
this.id = id; this.id = id;
@ -58,6 +59,7 @@ public class CommentData implements Parcelable {
this.authorFlair = authorFlair; this.authorFlair = authorFlair;
this.linkAuthor = linkAuthor; this.linkAuthor = linkAuthor;
this.commentTime = commentTime; this.commentTime = commentTime;
this.commentTimeMillis = commentTimeMillis;
this.commentContent = commentContent; this.commentContent = commentContent;
this.linkId = linkId; this.linkId = linkId;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -92,6 +94,7 @@ public class CommentData implements Parcelable {
authorFlair = in.readString(); authorFlair = in.readString();
linkAuthor = in.readString(); linkAuthor = in.readString();
commentTime = in.readString(); commentTime = in.readString();
commentTimeMillis = in.readLong();
commentContent = in.readString(); commentContent = in.readString();
linkId = in.readString(); linkId = in.readString();
subredditName = in.readString(); subredditName = in.readString();
@ -142,6 +145,10 @@ public class CommentData implements Parcelable {
return commentTime; return commentTime;
} }
public long getCommentTimeMillis() {
return commentTimeMillis;
}
public String getCommentContent() { public String getCommentContent() {
return commentContent; return commentContent;
} }
@ -318,6 +325,7 @@ public class CommentData implements Parcelable {
parcel.writeString(authorFlair); parcel.writeString(authorFlair);
parcel.writeString(linkAuthor); parcel.writeString(linkAuthor);
parcel.writeString(commentTime); parcel.writeString(commentTime);
parcel.writeLong(commentTimeMillis);
parcel.writeString(commentContent); parcel.writeString(commentContent);
parcel.writeString(linkId); parcel.writeString(linkId);
parcel.writeString(subredditName); parcel.writeString(subredditName);

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.Event;
public class ChangeShowElapsedTimeEvent {
public boolean showElapsedTime;
public ChangeShowElapsedTimeEvent(boolean showElapsedTime) {
this.showElapsedTime = showElapsedTime;
}
}

View File

@ -83,8 +83,9 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private boolean mNullAccessToken = false; private boolean mNullAccessToken = false;
private String mAccessToken; private String mAccessToken;
private RequestManager mGlide; private RequestManager mGlide;
private Activity activity; private Activity mActivity;
private CommentsListingRecyclerViewAdapter mAdapter; private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime;
public CommentsListingFragment() { public CommentsListingFragment() {
// Required empty public constructor // Required empty public constructor
@ -96,11 +97,11 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
Bundle savedInstanceState) { Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_comments_listing, container, false); View rootView = inflater.inflate(R.layout.fragment_comments_listing, container, false);
((Infinity) activity.getApplication()).getAppComponent().inject(this); ((Infinity) mActivity.getApplication()).getAppComponent().inject(this);
ButterKnife.bind(this, rootView); ButterKnife.bind(this, rootView);
mGlide = Glide.with(activity); mGlide = Glide.with(mActivity);
Resources resources = getResources(); Resources resources = getResources();
@ -113,6 +114,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
} }
} }
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getCurrentAccountAndBindView(resources); getCurrentAccountAndBindView(resources);
} else { } else {
@ -141,12 +144,12 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
} }
private void bindView(Resources resources) { private void bindView(Resources resources) {
mCommentRecyclerView.setLayoutManager(new LinearLayoutManager(activity)); mCommentRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(activity, mOauthRetrofit, mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit,
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME), getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
voteButtonsOnTheRight, () -> mCommentViewModel.retryLoadingMore()); voteButtonsOnTheRight, mShowElapsedTime, () -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME); String username = getArguments().getString(EXTRA_USERNAME);
String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value); String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);
@ -209,7 +212,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Override @Override
public void onAttach(@NonNull Context context) { public void onAttach(@NonNull Context context) {
super.onAttach(context); super.onAttach(context);
this.activity = (Activity) context; this.mActivity = (Activity) context;
} }
@Override @Override
@ -227,7 +230,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
} }
private void showErrorView(int stringResId) { private void showErrorView(int stringResId) {
if (activity != null && isAdded()) { if (mActivity != null && isAdded()) {
mProgressBar.setVisibility(View.GONE); mProgressBar.setVisibility(View.GONE);
mFetchCommentInfoLinearLayout.setVisibility(View.VISIBLE); mFetchCommentInfoLinearLayout.setVisibility(View.VISIBLE);
mFetchCommentInfoTextView.setText(stringResId); mFetchCommentInfoTextView.setText(stringResId);

View File

@ -28,7 +28,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.paging.PagedList; import androidx.paging.PagedList;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.LinearSmoothScroller;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -51,6 +50,7 @@ import ml.docilealligator.infinityforreddit.Activity.MainActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity; import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.PostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList; import ml.docilealligator.infinityforreddit.Event.PostUpdateEventToPostList;
@ -279,6 +279,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
boolean needBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); boolean needBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true);
boolean needBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false); boolean needBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false);
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
boolean showElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
PostViewModel.Factory factory; PostViewModel.Factory factory;
@ -293,7 +294,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -356,7 +357,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -402,7 +403,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -441,7 +442,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler,
voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() {
@Override @Override
public void retryLoadingMore() { public void retryLoadingMore() {
mPostViewModel.retryLoadingMore(); mPostViewModel.retryLoadingMore();
@ -643,6 +644,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
} }
} }
@Subscribe
public void onChangeShowElapsedTime(ChangeShowElapsedTimeEvent event) {
mAdapter.setShowElapsedTime(event.showElapsedTime);
refreshAdapter();
}
@Subscribe @Subscribe
public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) { public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) {
mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight); mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight);

View File

@ -154,8 +154,8 @@ public class ParseComment {
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String); boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
return new CommentData(id, fullName, author, authorFlair, linkAuthor, formattedSubmitTime, return new CommentData(id, fullName, author, authorFlair, linkAuthor, formattedSubmitTime,
commentContent, linkId, subredditName, parentId, score, voteType, isSubmitter, submitTime, commentContent, linkId, subredditName, parentId, score, voteType,
distinguished, permalink, depth, collapsed, hasReply, scoreHidden, saved); isSubmitter, distinguished, permalink, depth, collapsed, hasReply, scoreHidden, saved);
} }
@Nullable @Nullable

View File

@ -89,22 +89,22 @@ public class ParsePost {
data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0);
Post crosspostParent = parseBasicData(data, locale); Post crosspostParent = parseBasicData(data, locale);
Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, formattedPostTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, author, formattedPostTime, postTime, title, previewUrl, thumbnailPreviewUrl,
previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, previewWidth, previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler,
stickied, archived, locked, saved, true); nsfw, stickied, archived, locked, saved, true);
post.setCrosspostParentId(crosspostParent.getId()); post.setCrosspostParentId(crosspostParent.getId());
return post; return post;
} else { } else {
return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, formattedPostTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, author, formattedPostTime, postTime, title, previewUrl, thumbnailPreviewUrl,
previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, previewWidth, previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler,
stickied, archived, locked, saved, false); nsfw, stickied, archived, locked, saved, false);
} }
} }
private static Post parseData(JSONObject data, String permalink, String id, String fullName, private static Post parseData(JSONObject data, String permalink, String id, String fullName,
String subredditName, String subredditNamePrefixed, String author, String subredditName, String subredditNamePrefixed, String author,
String formattedPostTime, String title, String previewUrl, String formattedPostTime, long postTimeMillis, String title, String previewUrl,
String thumbnailPreviewUrl, int previewWidth, int previewHeight, String thumbnailPreviewUrl, int previewWidth, int previewHeight,
int score, int voteType, int gilded, int nComments, String flair, int score, int voteType, int gilded, int nComments, String flair,
boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied,
@ -118,9 +118,9 @@ public class ParsePost {
if (url.contains(permalink)) { if (url.contains(permalink)) {
//Text post //Text post
int postType = Post.TEXT_TYPE; int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis,
title, permalink, score, postType, voteType, gilded, nComments, flair, hidden, title, permalink, score, postType, voteType, gilded, nComments, flair,
spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -139,9 +139,9 @@ public class ParsePost {
} else { } else {
//No preview link post //No preview link post
int postType = Post.NO_PREVIEW_LINK_TYPE; int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis,
title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType, gilded, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -160,9 +160,9 @@ public class ParsePost {
int postType = Post.VIDEO_TYPE; int postType = Post.VIDEO_TYPE;
String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString(); String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString();
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis,
title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType, gilded, title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType,
nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -175,9 +175,9 @@ public class ParsePost {
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString(); .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString();
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, permalink, score,
voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied, postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw,
archived, locked, saved, isCrosspost); stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
post.setVideoUrl(videoUrl); post.setVideoUrl(videoUrl);
@ -187,9 +187,9 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE; int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, url, thumbnailPreviewUrl, url, permalink, score, formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink,
postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, score, postType, voteType, gilded, nComments, flair, hidden, spoiler,
stickied, archived, locked, saved, isCrosspost); nsfw, stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -197,9 +197,9 @@ public class ParsePost {
//Gif post //Gif post
int postType = Post.GIF_TYPE; int postType = Post.GIF_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink,
postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, score, postType, voteType, gilded, nComments, flair, hidden, spoiler,
stickied, archived, locked, saved, isCrosspost); nsfw, stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -210,9 +210,9 @@ public class ParsePost {
int postType = Post.TEXT_TYPE; int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, permalink, score, postType, voteType, formattedPostTime, postTimeMillis, title, permalink, score, postType,
gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied,
locked, saved, isCrosspost); archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
@ -237,9 +237,9 @@ public class ParsePost {
int postType = Post.LINK_TYPE; int postType = Post.LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink,
postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, score, postType, voteType, gilded, nComments, flair, hidden, spoiler,
stickied, archived, locked, saved, isCrosspost); nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) { if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText(""); post.setSelfText("");
} else { } else {
@ -257,9 +257,9 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE; int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink,
postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, score, postType, voteType, gilded, nComments, flair, hidden, spoiler,
stickied, archived, locked, saved, isCrosspost); nsfw, stickied, archived, locked, saved, isCrosspost);
post.setPreviewWidth(previewWidth); post.setPreviewWidth(previewWidth);
post.setPreviewHeight(previewHeight); post.setPreviewHeight(previewHeight);
} else { } else {
@ -267,9 +267,9 @@ public class ParsePost {
int postType = Post.NO_PREVIEW_LINK_TYPE; int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
formattedPostTime, title, url, thumbnailPreviewUrl, url, permalink, score, postType, formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink, score,
voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied,
locked, saved, isCrosspost); archived, locked, saved, isCrosspost);
} }
} }
} }

View File

@ -44,6 +44,7 @@ public class Post implements Parcelable {
private String videoUrl; private String videoUrl;
private String permalink; private String permalink;
private String flair; private String flair;
private long postTimeMillis;
private int score; private int score;
private int postType; private int postType;
private int voteType; private int voteType;
@ -61,10 +62,12 @@ public class Post implements Parcelable {
private boolean isCrosspost; private boolean isCrosspost;
private String crosspostParentId; private String crosspostParentId;
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String postTime, String title, String previewUrl, String thumbnailPreviewUrl, String permalink, int score, int postType, String author, String postTime, long postTimeMillis, String title, String previewUrl,
String thumbnailPreviewUrl, String permalink, int score, int postType,
int voteType, int gilded, int nComments, String flair, boolean hidden, boolean spoiler, int voteType, int gilded, int nComments, String flair, boolean hidden, boolean spoiler,
boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) { boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved,
boolean isCrosspost) {
this.id = id; this.id = id;
this.fullName = fullName; this.fullName = fullName;
this.subredditName = subredditName; this.subredditName = subredditName;
@ -72,6 +75,7 @@ public class Post implements Parcelable {
this.author = author; this.author = author;
this.authorNamePrefixed = "u/" + author; this.authorNamePrefixed = "u/" + author;
this.postTime = postTime; this.postTime = postTime;
this.postTimeMillis = postTimeMillis;
this.title = title; this.title = title;
this.previewUrl = previewUrl; this.previewUrl = previewUrl;
this.thumbnailPreviewUrl = thumbnailPreviewUrl; this.thumbnailPreviewUrl = thumbnailPreviewUrl;
@ -92,8 +96,9 @@ public class Post implements Parcelable {
this.isCrosspost = isCrosspost; this.isCrosspost = isCrosspost;
} }
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String postTime, String title, String previewUrl, String thumbnailPreviewUrl, String url, String permalink, int score, String author, String postTime, long postTimeMillis, String title, String previewUrl,
String thumbnailPreviewUrl, String url, String permalink, int score,
int postType, int voteType, int gilded, int nComments, String flair, boolean hidden, int postType, int voteType, int gilded, int nComments, String flair, boolean hidden,
boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked,
boolean saved, boolean isCrosspost) { boolean saved, boolean isCrosspost) {
@ -104,6 +109,7 @@ public class Post implements Parcelable {
this.author = author; this.author = author;
this.authorNamePrefixed = "u/" + author; this.authorNamePrefixed = "u/" + author;
this.postTime = postTime; this.postTime = postTime;
this.postTimeMillis = postTimeMillis;
this.title = title; this.title = title;
this.previewUrl = previewUrl; this.previewUrl = previewUrl;
this.thumbnailPreviewUrl = thumbnailPreviewUrl; this.thumbnailPreviewUrl = thumbnailPreviewUrl;
@ -126,7 +132,7 @@ public class Post implements Parcelable {
} }
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author,
String postTime, String title, String permalink, int score, int postType, int voteType, int gilded, String postTime, long postTimeMillis, String title, String permalink, int score, int postType, int voteType, int gilded,
int nComments, String flair, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, int nComments, String flair, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied,
boolean archived, boolean locked, boolean saved, boolean isCrosspost) { boolean archived, boolean locked, boolean saved, boolean isCrosspost) {
this.id = id; this.id = id;
@ -136,6 +142,7 @@ public class Post implements Parcelable {
this.author = author; this.author = author;
this.authorNamePrefixed = "u/" + author; this.authorNamePrefixed = "u/" + author;
this.postTime = postTime; this.postTime = postTime;
this.postTimeMillis = postTimeMillis;
this.title = title; this.title = title;
this.permalink = RedditUtils.API_BASE_URI + permalink; this.permalink = RedditUtils.API_BASE_URI + permalink;
this.score = score; this.score = score;
@ -164,6 +171,7 @@ public class Post implements Parcelable {
authorNamePrefixed = in.readString(); authorNamePrefixed = in.readString();
authorIconUrl = in.readString(); authorIconUrl = in.readString();
postTime = in.readString(); postTime = in.readString();
postTimeMillis = in.readLong();
title = in.readString(); title = in.readString();
selfText = in.readString(); selfText = in.readString();
selfTextPlainTrimmed = in.readString(); selfTextPlainTrimmed = in.readString();
@ -235,6 +243,10 @@ public class Post implements Parcelable {
return postTime; return postTime;
} }
public long getPostTimeMillis() {
return postTimeMillis;
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
@ -411,6 +423,7 @@ public class Post implements Parcelable {
parcel.writeString(authorNamePrefixed); parcel.writeString(authorNamePrefixed);
parcel.writeString(authorIconUrl); parcel.writeString(authorIconUrl);
parcel.writeString(postTime); parcel.writeString(postTime);
parcel.writeLong(postTimeMillis);
parcel.writeString(title); parcel.writeString(title);
parcel.writeString(selfText); parcel.writeString(selfText);
parcel.writeString(selfTextPlainTrimmed); parcel.writeString(selfTextPlainTrimmed);

View File

@ -18,6 +18,7 @@ import javax.inject.Inject;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
@ -49,6 +50,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY);
SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY); SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_KEY);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY); SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY); SwitchPreference nsfwSwitch = findPreference(SharedPreferencesUtils.NSFW_KEY);
SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY); SwitchPreference blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_KEY);
SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY); SwitchPreference blurSpoilerSwitch = findPreference(SharedPreferencesUtils.BLUR_SPOILER_KEY);
@ -83,6 +85,13 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat {
}); });
} }
if (showElapsedTimeSwitch != null) {
showElapsedTimeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeShowElapsedTimeEvent((Boolean) newValue));
return true;
});
}
if (nsfwSwitch != null) { if (nsfwSwitch != null) {
nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue));

View File

@ -56,4 +56,5 @@ public class SharedPreferencesUtils {
public static final int POST_LAYOUT_CARD = 0; public static final int POST_LAYOUT_CARD = 0;
public static final int POST_LAYOUT_COMPACT = 1; public static final int POST_LAYOUT_COMPACT = 1;
public static final String PULL_NOTIFICATION_TIME = "pull_notification_time"; public static final String PULL_NOTIFICATION_TIME = "pull_notification_time";
public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time";
} }

View File

@ -1,5 +1,5 @@
<resources> <resources>
<string name="app_name">Infinity</string> <string name="application_name">Infinity</string>
<string name="login_activity_label">Login</string> <string name="login_activity_label">Login</string>
<string name="search_activity_label">Search</string> <string name="search_activity_label">Search</string>
<string name="comment_activity_label">Send Comment</string> <string name="comment_activity_label">Send Comment</string>
@ -289,6 +289,7 @@
<string name="settings_amoled_dark_title">Amoled Dark</string> <string name="settings_amoled_dark_title">Amoled Dark</string>
<string name="settings_immersive_interface_title">Immersive Interface</string> <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_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="settings_lazy_mode_interval_title">Lazy Mode Interval</string> <string name="settings_lazy_mode_interval_title">Lazy Mode Interval</string>
<string name="settings_font_size_title">Font Size</string> <string name="settings_font_size_title">Font Size</string>
<string name="settings_title_font_size_title">Title Font Size</string> <string name="settings_title_font_size_title">Title Font Size</string>

View File

@ -29,8 +29,12 @@
<SwitchPreference <SwitchPreference
app:defaultValue="false" app:defaultValue="false"
app:key="vote_buttons_on_the_right" app:key="vote_buttons_on_the_right"
app:title="@string/settings_vote_buttons_on_the_right_title" app:title="@string/settings_vote_buttons_on_the_right_title"/>
app:isPreferenceVisible="true" />
<SwitchPreference
app:defaultValue="false"
app:key="show_elapsed_time"
app:title="@string/settings_show_elapsed_time"/>
<Preference <Preference
app:title="@string/settings_font_size_title" app:title="@string/settings_font_size_title"

View File

@ -32,5 +32,5 @@ task clean(type: Delete) {
ext { ext {
roomVersion = '2.2.1' roomVersion = '2.2.1'
archLifecycleVersion = '2.2.0-rc01' archLifecycleVersion = '2.2.0-rc02'
} }