diff --git a/app/build.gradle b/app/build.gradle index c4a04917..3d3cf668 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "ml.docilealligator.infinityforreddit" minSdkVersion 21 targetSdkVersion 29 - versionCode 20 - versionName "1.4.1" + versionCode 21 + versionName "1.5.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { @@ -80,4 +80,5 @@ dependencies { implementation 'androidx.work:work-runtime:2.2.0' implementation 'androidx.preference:preference:1.1.0' implementation 'com.nex3z:flow-layout:1.3.0' + implementation 'com.github.thunder413:DateTimeUtils:3.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b166996a..c7883829 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,5 +1,6 @@ @@ -14,11 +15,12 @@ android:name=".Infinity" android:allowBackup="true" android:icon="@mipmap/ic_launcher" - android:label="@string/app_name" + android:label="@string/application_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" - android:usesCleartextTraffic="true"> + android:usesCleartextTraffic="true" + tools:replace="android:label"> 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 6bafbebe..6264b0a1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -160,6 +160,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS private boolean mNeedBlurNsfw; private boolean mNeedBlurSpoiler; private boolean mVoteButtonsOnTheRight; + private boolean mShowElapsedTime; private boolean showToast = false; private boolean isSortingComments = false; private LinearLayoutManager mLinearLayoutManager; @@ -234,6 +235,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mNeedBlurNsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true); mNeedBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_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); mLocale = getResources().getConfiguration().locale; @@ -387,7 +389,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mAdapter = new CommentAndPostRecyclerViewAdapter(ViewPostDetailActivity.this, mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, - mVoteButtonsOnTheRight, + mVoteButtonsOnTheRight, mShowElapsedTime, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { @@ -508,7 +510,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS mRetrofit, mOauthRetrofit, mRedditDataRoomDatabase, mGlide, mAccessToken, mAccountName, mPost, mLocale, mSingleCommentId, isSingleCommentThreadMode, mNeedBlurNsfw, mNeedBlurSpoiler, - mVoteButtonsOnTheRight, + mVoteButtonsOnTheRight, mShowElapsedTime, new CommentAndPostRecyclerViewAdapter.CommentRecyclerViewAdapterCallback() { @Override public void updatePost(Post post) { 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 1e2861f7..2074999e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -35,10 +35,13 @@ 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; @@ -105,6 +108,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter 0) { ((PostDetailViewHolder) holder).mGildedNumberTextView.setVisibility(View.VISIBLE); @@ -602,7 +613,12 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter mCommentViewModel.retryLoadingMore()); + voteButtonsOnTheRight, mShowElapsedTime, () -> mCommentViewModel.retryLoadingMore()); String username = getArguments().getString(EXTRA_USERNAME); 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 public void onAttach(@NonNull Context context) { super.onAttach(context); - this.activity = (Activity) context; + this.mActivity = (Activity) context; } @Override @@ -227,7 +230,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni } private void showErrorView(int stringResId) { - if (activity != null && isAdded()) { + if (mActivity != null && isAdded()) { mProgressBar.setVisibility(View.GONE); mFetchCommentInfoLinearLayout.setVisibility(View.VISIBLE); mFetchCommentInfoTextView.setText(stringResId); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 1a3ea761..24b116fd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -28,7 +28,6 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; import androidx.paging.PagedList; -import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearSmoothScroller; 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.Adapter.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; 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 needBlurSpoiler = mSharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_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; @@ -293,7 +294,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -356,7 +357,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, displaySubredditName, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -402,7 +403,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { @Override public void retryLoadingMore() { mPostViewModel.retryLoadingMore(); @@ -441,7 +442,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase, accessToken, postType, postLayout, true, needBlurNsfw, needBlurSpoiler, - voteButtonsOnTheRight, new PostRecyclerViewAdapter.Callback() { + voteButtonsOnTheRight, showElapsedTime, new PostRecyclerViewAdapter.Callback() { @Override public void 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 public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) { mAdapter.setVoteButtonsPosition(event.voteButtonsOnTheRight); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java index 84343132..815ef8e3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java @@ -154,8 +154,8 @@ public class ParseComment { boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String); return new CommentData(id, fullName, author, authorFlair, linkAuthor, formattedSubmitTime, - commentContent, linkId, subredditName, parentId, score, voteType, isSubmitter, - distinguished, permalink, depth, collapsed, hasReply, scoreHidden, saved); + submitTime, commentContent, linkId, subredditName, parentId, score, voteType, + isSubmitter, distinguished, permalink, depth, collapsed, hasReply, scoreHidden, saved); } @Nullable diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index c4979fde..66133766 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -89,22 +89,22 @@ public class ParsePost { data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0); Post crosspostParent = parseBasicData(data, locale); Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, - author, formattedPostTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, - previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, - stickied, archived, locked, saved, true); + author, formattedPostTime, postTime, title, previewUrl, thumbnailPreviewUrl, + previewWidth, previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler, + nsfw, stickied, archived, locked, saved, true); post.setCrosspostParentId(crosspostParent.getId()); return post; } else { return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed, - author, formattedPostTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, - previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, - stickied, archived, locked, saved, false); + author, formattedPostTime, postTime, title, previewUrl, thumbnailPreviewUrl, + previewWidth, previewHeight, score, voteType, gilded, nComments, flair, hidden, spoiler, + nsfw, stickied, archived, locked, saved, false); } } private static Post parseData(JSONObject data, String permalink, String id, String fullName, 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, int score, int voteType, int gilded, int nComments, String flair, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied, @@ -118,9 +118,9 @@ public class ParsePost { if (url.contains(permalink)) { //Text post int postType = Post.TEXT_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, permalink, score, postType, voteType, gilded, nComments, flair, hidden, - spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis, + title, permalink, score, postType, voteType, gilded, nComments, flair, + hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -139,9 +139,9 @@ public class ParsePost { } else { //No preview link post int postType = Post.NO_PREVIEW_LINK_TYPE; - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType, gilded, - nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis, + title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType, voteType, + gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -160,9 +160,9 @@ public class ParsePost { int postType = Post.VIDEO_TYPE; String videoUrl = Html.fromHtml(redditVideoObject.getString(JSONUtils.HLS_URL_KEY)).toString(); - post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, - title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType, gilded, - nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); + post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, formattedPostTime, postTimeMillis, + title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType, + gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -175,9 +175,9 @@ public class ParsePost { .getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.HLS_URL_KEY)).toString(); post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, previewUrl, thumbnailPreviewUrl, permalink, score, postType, - voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied, - archived, locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, permalink, score, + postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, + stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); post.setVideoUrl(videoUrl); @@ -187,9 +187,9 @@ public class ParsePost { int postType = Post.IMAGE_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, url, thumbnailPreviewUrl, url, permalink, score, - postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, - stickied, archived, locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink, + score, postType, voteType, gilded, nComments, flair, hidden, spoiler, + nsfw, stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -197,9 +197,9 @@ public class ParsePost { //Gif post int postType = Post.GIF_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, - postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, - stickied, archived, locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink, + score, postType, voteType, gilded, nComments, flair, hidden, spoiler, + nsfw, stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -210,9 +210,9 @@ public class ParsePost { int postType = Post.TEXT_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, permalink, score, postType, voteType, - gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, - locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, permalink, score, postType, + voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); @@ -237,9 +237,9 @@ public class ParsePost { int postType = Post.LINK_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, - postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, - stickied, archived, locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink, + score, postType, voteType, gilded, nComments, flair, hidden, spoiler, + nsfw, stickied, archived, locked, saved, isCrosspost); if (data.isNull(JSONUtils.SELFTEXT_KEY)) { post.setSelfText(""); } else { @@ -257,9 +257,9 @@ public class ParsePost { int postType = Post.IMAGE_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, previewUrl, thumbnailPreviewUrl, url, permalink, score, - postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, - stickied, archived, locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, previewUrl, thumbnailPreviewUrl, url, permalink, + score, postType, voteType, gilded, nComments, flair, hidden, spoiler, + nsfw, stickied, archived, locked, saved, isCrosspost); post.setPreviewWidth(previewWidth); post.setPreviewHeight(previewHeight); } else { @@ -267,9 +267,9 @@ public class ParsePost { int postType = Post.NO_PREVIEW_LINK_TYPE; post = new Post(id, fullName, subredditName, subredditNamePrefixed, author, - formattedPostTime, title, url, thumbnailPreviewUrl, url, permalink, score, postType, - voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied, archived, - locked, saved, isCrosspost); + formattedPostTime, postTimeMillis, title, url, thumbnailPreviewUrl, url, permalink, score, + postType, voteType, gilded, nComments, flair, hidden, spoiler, nsfw, stickied, + archived, locked, saved, isCrosspost); } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java index 90cf631d..fba35a7e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post.java @@ -44,6 +44,7 @@ public class Post implements Parcelable { private String videoUrl; private String permalink; private String flair; + private long postTimeMillis; private int score; private int postType; private int voteType; @@ -61,10 +62,12 @@ public class Post implements Parcelable { private boolean isCrosspost; private String crosspostParentId; - public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, - String postTime, String title, String previewUrl, String thumbnailPreviewUrl, String permalink, int score, int postType, + public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, + 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, - 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.fullName = fullName; this.subredditName = subredditName; @@ -72,6 +75,7 @@ public class Post implements Parcelable { this.author = author; this.authorNamePrefixed = "u/" + author; this.postTime = postTime; + this.postTimeMillis = postTimeMillis; this.title = title; this.previewUrl = previewUrl; this.thumbnailPreviewUrl = thumbnailPreviewUrl; @@ -92,8 +96,9 @@ public class Post implements Parcelable { this.isCrosspost = isCrosspost; } - public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, String author, - String postTime, String title, String previewUrl, String thumbnailPreviewUrl, String url, String permalink, int score, + public Post(String id, String fullName, String subredditName, String subredditNamePrefixed, + 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, boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) { @@ -104,6 +109,7 @@ public class Post implements Parcelable { this.author = author; this.authorNamePrefixed = "u/" + author; this.postTime = postTime; + this.postTimeMillis = postTimeMillis; this.title = title; this.previewUrl = previewUrl; this.thumbnailPreviewUrl = thumbnailPreviewUrl; @@ -126,7 +132,7 @@ public class Post implements Parcelable { } 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, boolean archived, boolean locked, boolean saved, boolean isCrosspost) { this.id = id; @@ -136,6 +142,7 @@ public class Post implements Parcelable { this.author = author; this.authorNamePrefixed = "u/" + author; this.postTime = postTime; + this.postTimeMillis = postTimeMillis; this.title = title; this.permalink = RedditUtils.API_BASE_URI + permalink; this.score = score; @@ -164,6 +171,7 @@ public class Post implements Parcelable { authorNamePrefixed = in.readString(); authorIconUrl = in.readString(); postTime = in.readString(); + postTimeMillis = in.readLong(); title = in.readString(); selfText = in.readString(); selfTextPlainTrimmed = in.readString(); @@ -235,6 +243,10 @@ public class Post implements Parcelable { return postTime; } + public long getPostTimeMillis() { + return postTimeMillis; + } + public String getTitle() { return title; } @@ -411,6 +423,7 @@ public class Post implements Parcelable { parcel.writeString(authorNamePrefixed); parcel.writeString(authorIconUrl); parcel.writeString(postTime); + parcel.writeLong(postTimeMillis); parcel.writeString(title); parcel.writeString(selfText); parcel.writeString(selfTextPlainTrimmed); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index dcc1c201..c6f936f4 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -18,6 +18,7 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; +import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent; import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; @@ -49,6 +50,7 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { SwitchPreference amoledDarkSwitch = findPreference(SharedPreferencesUtils.AMOLED_DARK_KEY); SwitchPreference immersiveInterfaceSwitch = findPreference(SharedPreferencesUtils.IMMERSIVE_INTERFACE_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 blurNSFWSwitch = findPreference(SharedPreferencesUtils.BLUR_NSFW_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) { nsfwSwitch.setOnPreferenceChangeListener((preference, newValue) -> { EventBus.getDefault().post(new ChangeNSFWEvent((Boolean) newValue)); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java index 309db29a..510cb357 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SharedPreferencesUtils.java @@ -56,4 +56,5 @@ public class SharedPreferencesUtils { public static final int POST_LAYOUT_CARD = 0; 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"; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dd113044..db0ed690 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,5 @@ - Infinity + Infinity Login Search Send Comment @@ -289,6 +289,7 @@ Amoled Dark Immersive Interface Vote Buttons on the Right + Show Elpased Time in Posts and Comments Lazy Mode Interval Font Size Title Font Size diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml index 575dfd38..548bf949 100644 --- a/app/src/main/res/xml/main_preferences.xml +++ b/app/src/main/res/xml/main_preferences.xml @@ -29,8 +29,12 @@ + app:title="@string/settings_vote_buttons_on_the_right_title"/> + +