Add an option to change time format. Properly show message time in ViewPrivateMessagesActivity.

This commit is contained in:
Alex Ning 2020-07-02 18:59:53 +08:00
parent 3a72c5a1f8
commit 9a4edde8fb
20 changed files with 242 additions and 126 deletions

View File

@ -158,7 +158,8 @@ public class ViewPrivateMessagesActivity extends BaseActivity implements Activit
}
private void bindView() {
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, privateMessage, mAccountName, mCustomThemeWrapper);
mAdapter = new PrivateMessagesDetailRecyclerViewAdapter(this, mSharedPreferences,
getResources().getConfiguration().locale, privateMessage, mAccountName, mCustomThemeWrapper);
mLinearLayoutManager = new LinearLayoutManager(this);
mLinearLayoutManager.setStackFromEnd(true);
mRecyclerView.setLayoutManager(mLinearLayoutManager);

View File

@ -36,7 +36,6 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
@ -147,6 +146,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
private boolean mNeedBlurSpoiler;
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private String mTimeFormatPattern;
private boolean mExpandChildren;
private boolean mCommentToolbarHidden;
private boolean mCommentToolbarHideOnClick;
@ -215,7 +215,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
RedditDataRoomDatabase redditDataRoomDatabase, RequestManager glide,
String accessToken, String accountName, Post post, Locale locale,
String singleCommentId, boolean isSingleCommentThreadMode,
SharedPreferences mSharedPreferences, ExoCreator exoCreator,
SharedPreferences sharedPreferences, ExoCreator exoCreator,
CommentRecyclerViewAdapterCallback commentRecyclerViewAdapterCallback) {
mActivity = activity;
mRetrofit = retrofit;
@ -302,25 +302,26 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mSingleCommentId = singleCommentId;
mIsSingleCommentThreadMode = isSingleCommentThreadMode;
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);
mExpandChildren = !mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mCommentToolbarHidden = mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false);
mCommentToolbarHideOnClick = mSharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
mSwapTapAndLong = mSharedPreferences.getBoolean(SharedPreferencesUtils.SWAP_TAP_AND_LONG_COMMENTS, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
mNeedBlurNsfw = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_NSFW_KEY, true);
mNeedBlurSpoiler = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
mExpandChildren = !sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_TOP_LEVEL_COMMENTS_FIRST, false);
mCommentToolbarHidden = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDDEN, false);
mCommentToolbarHideOnClick = sharedPreferences.getBoolean(SharedPreferencesUtils.COMMENT_TOOLBAR_HIDE_ON_CLICK, true);
mSwapTapAndLong = sharedPreferences.getBoolean(SharedPreferencesUtils.SWAP_TAP_AND_LONG_COMMENTS, false);
mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
String autoplayString = mSharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ALWAYS_ON)) {
mAutoplay = true;
} else if (autoplayString.equals(SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_ON_WIFI)) {
mAutoplay = Utils.isConnectedToWifi(activity);
}
mAutoplayNsfwVideos = mSharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
mMuteAutoplayingVideos = mSharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
mAutoplayNsfwVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.AUTOPLAY_NSFW_VIDEOS, true);
mMuteAutoplayingVideos = sharedPreferences.getBoolean(SharedPreferencesUtils.MUTE_AUTOPLAYING_VIDEOS, true);
mCommentRecyclerViewAdapterCallback = commentRecyclerViewAdapterCallback;
isInitiallyLoading = true;
@ -610,7 +611,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(
Utils.getElapsedTime(mActivity, mPost.getPostTimeMillis()));
} else {
((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(mPost.getPostTime());
((PostDetailBaseViewHolder) holder).mPostTimeTextView.setText(Utils.getFormattedTime(mLocale, mPost.getPostTimeMillis(), mTimeFormatPattern));
}
if (mPost.isArchived()) {
@ -771,7 +772,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((CommentViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mActivity, comment.getCommentTimeMillis()));
} else {
((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
if (mCommentToolbarHidden) {

View File

@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit.Adapter;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.net.Uri;
import android.os.Bundle;
@ -25,6 +26,8 @@ import androidx.paging.PagedListAdapter;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
@ -37,13 +40,14 @@ import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.CommentMoreBottomSheetFragment;
import ml.docilealligator.infinityforreddit.CommentData;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.BottomSheetFragment.CommentMoreBottomSheetFragment;
import ml.docilealligator.infinityforreddit.NetworkState;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import ml.docilealligator.infinityforreddit.VoteThing;
import retrofit2.Retrofit;
@ -65,6 +69,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
};
private Context mContext;
private Retrofit mOauthRetrofit;
private Locale mLocale;
private Markwon mMarkwon;
private String mAccessToken;
private String mAccountName;
@ -83,17 +88,16 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
private int mCommentIconAndInfoColor;
private boolean mVoteButtonsOnTheRight;
private boolean mShowElapsedTime;
private String mTimeFormatPattern;
private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
private NetworkState networkState;
private RetryLoadingMoreCallback mRetryLoadingMoreCallback;
public CommentsListingRecyclerViewAdapter(Context context, Retrofit oauthRetrofit,
CustomThemeWrapper customThemeWrapper, String accessToken,
String accountName, boolean voteButtonsOnTheRight,
boolean showElapsedTime, boolean showCommentDivider,
boolean showAbsoluteNumberOfVotes,
RetryLoadingMoreCallback retryLoadingMoreCallback) {
CustomThemeWrapper customThemeWrapper, Locale locale,
SharedPreferences sharedPreferences, String accessToken,
String accountName, RetryLoadingMoreCallback retryLoadingMoreCallback) {
super(DIFF_CALLBACK);
mContext = context;
mOauthRetrofit = oauthRetrofit;
@ -122,12 +126,14 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
)
)
.build();
mLocale = locale;
mAccessToken = accessToken;
mAccountName = accountName;
mVoteButtonsOnTheRight = voteButtonsOnTheRight;
mShowElapsedTime = showElapsedTime;
mShowCommentDivider = showCommentDivider;
mShowAbsoluteNumberOfVotes = showAbsoluteNumberOfVotes;
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
mRetryLoadingMoreCallback = retryLoadingMoreCallback;
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
@ -191,7 +197,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment
((CommentViewHolder) holder).commentTimeTextView.setText(
Utils.getElapsedTime(mContext, comment.getCommentTimeMillis()));
} else {
((CommentViewHolder) holder).commentTimeTextView.setText(comment.getCommentTime());
((CommentViewHolder) holder).commentTimeTextView.setText(Utils.getFormattedTime(mLocale, comment.getCommentTimeMillis(), mTimeFormatPattern));
}
if (comment.getAwards() != null && !comment.getAwards().equals("")) {

View File

@ -34,7 +34,6 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
@ -51,6 +50,7 @@ import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
@ -121,6 +121,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private String mAccessToken;
private RequestManager mGlide;
private RedditDataRoomDatabase mRedditDataRoomDatabase;
private Locale mLocale;
private UserDao mUserDao;
private boolean canStartActivity = true;
private int mPostType;
@ -161,6 +162,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mNeedBlurNSFW;
private boolean mNeedBlurSpoiler;
private boolean mShowElapsedTime;
private String mTimeFormatPattern;
private boolean mShowDividerInCompactLayout;
private boolean mShowAbsoluteNumberOfVotes;
private boolean mAutoplay = false;
@ -175,7 +177,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
public PostRecyclerViewAdapter(AppCompatActivity activity, Retrofit oauthRetrofit, Retrofit retrofit,
RedditDataRoomDatabase redditDataRoomDatabase,
CustomThemeWrapper customThemeWrapper, String accessToken,
CustomThemeWrapper customThemeWrapper, Locale locale, String accessToken,
int postType, int postLayout, boolean displaySubredditName,
SharedPreferences sharedPreferences, ExoCreator exoCreator,
Callback callback) {
@ -191,6 +193,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mNeedBlurSpoiler = sharedPreferences.getBoolean(SharedPreferencesUtils.BLUR_SPOILER_KEY, false);
mVoteButtonsOnTheRight = sharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
mShowDividerInCompactLayout = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT, true);
mShowAbsoluteNumberOfVotes = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
String autoplayString = sharedPreferences.getString(SharedPreferencesUtils.VIDEO_AUTOPLAY, SharedPreferencesUtils.VIDEO_AUTOPLAY_VALUE_NEVER);
@ -243,6 +246,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mScale = activity.getResources().getDisplayMetrics().density;
mGlide = Glide.with(mActivity);
mRedditDataRoomDatabase = redditDataRoomDatabase;
mLocale = locale;
mUserDao = redditDataRoomDatabase.userDao();
mExoCreator = exoCreator;
mCallback = callback;
@ -445,7 +449,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostBaseViewHolder) holder).postTimeTextView.setText(
Utils.getElapsedTime(mActivity, post.getPostTimeMillis()));
} else {
((PostBaseViewHolder) holder).postTimeTextView.setText(post.getPostTime());
((PostBaseViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern));
}
((PostBaseViewHolder) holder).titleTextView.setText(post.getTitle());
@ -577,7 +581,6 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
final String subredditNamePrefixed = post.getSubredditNamePrefixed();
String subredditName = subredditNamePrefixed.substring(2);
String authorPrefixed = "u/" + post.getAuthor();
final String postTime = post.getPostTime();
final String title = post.getTitle();
int voteType = post.getVoteType();
boolean nsfw = post.isNSFW();
@ -741,7 +744,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostCompactViewHolder) holder).postTimeTextView.setText(
Utils.getElapsedTime(mActivity, post.getPostTimeMillis()));
} else {
((PostCompactViewHolder) holder).postTimeTextView.setText(postTime);
((PostCompactViewHolder) holder).postTimeTextView.setText(Utils.getFormattedTime(mLocale, post.getPostTimeMillis(), mTimeFormatPattern));
}
if (mShowDividerInCompactLayout) {
@ -1281,6 +1284,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
mShowElapsedTime = showElapsedTime;
}
public void setTimeFormat(String timeFormat) {
mTimeFormatPattern = timeFormat;
}
public void setShowDividerInCompactLayout(boolean showDividerInCompactLayout) {
mShowDividerInCompactLayout = showDividerInCompactLayout;
}

View File

@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit.Adapter;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.text.style.SuperscriptSpan;
@ -18,6 +19,8 @@ import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
import java.util.Locale;
import butterknife.BindView;
import butterknife.ButterKnife;
import io.noties.markwon.AbstractMarkwonPlugin;
@ -33,6 +36,7 @@ import ml.docilealligator.infinityforreddit.Activity.ViewUserDetailActivity;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Message;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@ -41,17 +45,23 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
private Message mMessage;
private ViewPrivateMessagesActivity mViewPrivateMessagesActivity;
private RequestManager mGlide;
private Locale mLocale;
private String mAccountName;
private Markwon mMarkwon;
private boolean mShowElapsedTime;
private String mTimeFormatPattern;
private int mMessageBackgroundColor;
private int mSecondaryTextColor;
private int mUnreadMessageBackgroundColor;
public PrivateMessagesDetailRecyclerViewAdapter(ViewPrivateMessagesActivity viewPrivateMessagesActivity, Message message, String accountName,
public PrivateMessagesDetailRecyclerViewAdapter(ViewPrivateMessagesActivity viewPrivateMessagesActivity,
SharedPreferences sharedPreferences, Locale locale,
Message message, String accountName,
CustomThemeWrapper customThemeWrapper) {
mMessage = message;
mViewPrivateMessagesActivity = viewPrivateMessagesActivity;
mGlide = Glide.with(viewPrivateMessagesActivity);
mLocale = locale;
mAccountName = accountName;
mMarkwon = Markwon.builder(viewPrivateMessagesActivity)
.usePlugin(new AbstractMarkwonPlugin() {
@ -78,6 +88,8 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
)
)
.build();
mShowElapsedTime = sharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mTimeFormatPattern = sharedPreferences.getString(SharedPreferencesUtils.TIME_FORMAT_KEY, SharedPreferencesUtils.TIME_FORMAT_DEFAULT_VALUE);
mMessageBackgroundColor = customThemeWrapper.getCardViewBackgroundColor();
mSecondaryTextColor = customThemeWrapper.getSecondaryTextColor();
mUnreadMessageBackgroundColor = customThemeWrapper.getUnreadMessageBackgroundColor();
@ -115,6 +127,11 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
mMarkwon.setMarkdown(((MessageViewHolder) holder).messageTextView, message.getBody());
((MessageViewHolder) holder).messageTextView.setOnClickListener(view -> ((MessageViewHolder) holder).itemView.performClick());
if (mShowElapsedTime) {
((MessageViewHolder) holder).timeTextView.setText(Utils.getElapsedTime(mViewPrivateMessagesActivity, message.getTimeUTC()));
} else {
((MessageViewHolder) holder).timeTextView.setText(Utils.getFormattedTime(mLocale, message.getTimeUTC(), mTimeFormatPattern));
}
((MessageViewHolder) holder).messageTextView.setOnClickListener(view -> {
if (((MessageViewHolder) holder).timeTextView.getVisibility() != View.VISIBLE) {
@ -125,8 +142,6 @@ public class PrivateMessagesDetailRecyclerViewAdapter extends RecyclerView.Adapt
mViewPrivateMessagesActivity.delayTransition();
}
});
((MessageViewHolder) holder).timeTextView.setText(Utils.getElapsedTime(mViewPrivateMessagesActivity, message.getTimeUTC()));
}
if (holder instanceof SentMessageViewHolder) {

View File

@ -28,7 +28,6 @@ public class CommentData implements Parcelable {
private String authorFlair;
private String authorFlairHTML;
private String linkAuthor;
private String commentTime;
private long commentTimeMillis;
private String commentMarkdown;
private String commentRawText;
@ -55,7 +54,7 @@ public class CommentData implements Parcelable {
private boolean loadMoreChildrenFailed;
public CommentData(String id, String fullName, String author, String authorFlair,
String authorFlairHTML, String linkAuthor, String commentTime,
String authorFlairHTML, String linkAuthor,
long commentTimeMillis, String commentMarkdown, String commentRawText,
String linkId, String subredditName, String parentId, int score,
int voteType, boolean isSubmitter, String distinguished, String permalink,
@ -67,7 +66,6 @@ public class CommentData implements Parcelable {
this.authorFlair = authorFlair;
this.authorFlairHTML = authorFlairHTML;
this.linkAuthor = linkAuthor;
this.commentTime = commentTime;
this.commentTimeMillis = commentTimeMillis;
this.commentMarkdown = commentMarkdown;
this.commentRawText = commentRawText;
@ -105,7 +103,6 @@ public class CommentData implements Parcelable {
authorFlair = in.readString();
authorFlairHTML = in.readString();
linkAuthor = in.readString();
commentTime = in.readString();
commentTimeMillis = in.readLong();
commentMarkdown = in.readString();
commentRawText = in.readString();
@ -159,10 +156,6 @@ public class CommentData implements Parcelable {
return linkAuthor;
}
public String getCommentTime() {
return commentTime;
}
public long getCommentTimeMillis() {
return commentTimeMillis;
}
@ -355,7 +348,6 @@ public class CommentData implements Parcelable {
parcel.writeString(authorFlair);
parcel.writeString(authorFlairHTML);
parcel.writeString(linkAuthor);
parcel.writeString(commentTime);
parcel.writeLong(commentTimeMillis);
parcel.writeString(commentMarkdown);
parcel.writeString(commentRawText);

View File

@ -0,0 +1,9 @@
package ml.docilealligator.infinityforreddit.Event;
public class ChangeTimeFormatEvent {
public String timeFormat;
public ChangeTimeFormatEvent(String timeFormat) {
this.timeFormat = timeFormat;
}
}

View File

@ -7,7 +7,6 @@ import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -98,9 +97,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private LinearLayoutManager mLinearLayoutManager;
private CommentsListingRecyclerViewAdapter mAdapter;
private SortType sortType;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
private boolean mShowAbsoluteNumberOfVotes;
public CommentsListingFragment() {
// Required empty public constructor
@ -132,10 +128,6 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
}
mShowElapsedTime = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY, false);
mShowCommentDivider = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_COMMENT_DIVIDER, false);
mShowAbsoluteNumberOfVotes = mSharedPreferences.getBoolean(SharedPreferencesUtils.SHOW_ABSOLUTE_NUMBER_OF_VOTES, true);
if (savedInstanceState == null) {
getCurrentAccountAndBindView(resources);
} else {
@ -167,10 +159,9 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mLinearLayoutManager = new LinearLayoutManager(mActivity);
mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
getResources().getConfiguration().locale, mSharedPreferences,
getArguments().getString(EXTRA_ACCESS_TOKEN), getArguments().getString(EXTRA_ACCOUNT_NAME),
voteButtonsOnTheRight, mShowElapsedTime, mShowCommentDivider, mShowAbsoluteNumberOfVotes,
() -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME);
@ -197,9 +188,9 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class);
mCommentViewModel.getComments().observe(this, comments -> mAdapter.submitList(comments));
mCommentViewModel.getComments().observe(getViewLifecycleOwner(), comments -> mAdapter.submitList(comments));
mCommentViewModel.hasComment().observe(this, hasComment -> {
mCommentViewModel.hasComment().observe(getViewLifecycleOwner(), hasComment -> {
mSwipeRefreshLayout.setRefreshing(false);
if (hasComment) {
mFetchCommentInfoLinearLayout.setVisibility(View.GONE);
@ -211,7 +202,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
});
mCommentViewModel.getInitialLoadingState().observe(this, networkState -> {
mCommentViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
@ -223,7 +214,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
});
mCommentViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
mCommentViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> mAdapter.setNetworkState(networkState));
mSwipeRefreshLayout.setOnRefreshListener(() -> mCommentViewModel.refresh());
}

View File

@ -41,6 +41,8 @@ import com.bumptech.glide.RequestManager;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
@ -65,6 +67,7 @@ import ml.docilealligator.infinityforreddit.Event.ChangePostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeSpoilerBlurEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVideoAutoplayEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeWifiStatusEvent;
@ -344,6 +347,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
boolean nsfw = mSharedPreferences.getBoolean(SharedPreferencesUtils.NSFW_KEY, false);
int defaultPostLayout = Integer.parseInt(mSharedPreferences.getString(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY, "0"));
Locale locale = getResources().getConfiguration().locale;
if (postType == PostDataSource.TYPE_SEARCH) {
String subredditName = getArguments().getString(EXTRA_NAME);
@ -355,7 +359,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
customThemeWrapper, locale, accessToken, postType, postLayout, true,
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
@ -417,7 +421,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, displaySubredditName,
customThemeWrapper, locale, accessToken, postType, postLayout, displaySubredditName,
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
@ -464,7 +468,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
customThemeWrapper, locale, accessToken, postType, postLayout, true,
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
@ -509,7 +513,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
customThemeWrapper, locale, accessToken, postType, postLayout, true,
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
@ -547,7 +551,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
customThemeWrapper, locale, accessToken, postType, postLayout, true,
mSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
@ -579,9 +583,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return new PlaybackInfo(INDEX_UNSET, TIME_UNSET, volumeInfo);
});
mPostViewModel.getPosts().observe(this, posts -> mAdapter.submitList(posts));
mPostViewModel.getPosts().observe(getViewLifecycleOwner(), posts -> mAdapter.submitList(posts));
mPostViewModel.hasPost().observe(this, hasPost -> {
mPostViewModel.hasPost().observe(getViewLifecycleOwner(), hasPost -> {
this.hasPost = hasPost;
mSwipeRefreshLayout.setRefreshing(false);
if (hasPost) {
@ -597,7 +601,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
mPostViewModel.getInitialLoadingState().observe(this, networkState -> {
mPostViewModel.getInitialLoadingState().observe(getViewLifecycleOwner(), networkState -> {
if (networkState.getStatus().equals(NetworkState.Status.SUCCESS)) {
mSwipeRefreshLayout.setRefreshing(false);
} else if (networkState.getStatus().equals(NetworkState.Status.FAILED)) {
@ -609,7 +613,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
});
mPostViewModel.getPaginationNetworkState().observe(this, networkState -> mAdapter.setNetworkState(networkState));
mPostViewModel.getPaginationNetworkState().observe(getViewLifecycleOwner(), networkState -> mAdapter.setNetworkState(networkState));
return rootView;
}
@ -788,13 +792,21 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
@Subscribe
public void onChangeShowElapsedTime(ChangeShowElapsedTimeEvent event) {
public void onChangeShowElapsedTimeEvent(ChangeShowElapsedTimeEvent event) {
if (mAdapter != null) {
mAdapter.setShowElapsedTime(event.showElapsedTime);
refreshAdapter();
}
}
@Subscribe
public void onChangeTimeFormatEvent(ChangeTimeFormatEvent changeTimeFormatEvent) {
if (mAdapter != null) {
mAdapter.setTimeFormat(changeTimeFormatEvent.timeFormat);
refreshAdapter();
}
}
@Subscribe
public void onChangeVoteButtonsPositionEvent(ChangeVoteButtonsPositionEvent event) {
if (mAdapter != null) {

View File

@ -9,9 +9,7 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
@ -171,11 +169,6 @@ public class ParseComment {
boolean scoreHidden = singleCommentData.getBoolean(JSONUtils.SCORE_HIDDEN_KEY);
boolean saved = singleCommentData.getBoolean(JSONUtils.SAVED_KEY);
Calendar submitTimeCalendar = Calendar.getInstance();
submitTimeCalendar.setTimeInMillis(submitTime);
String formattedSubmitTime = new SimpleDateFormat("MMM d, yyyy, HH:mm",
locale).format(submitTimeCalendar.getTime());
if (singleCommentData.has(JSONUtils.DEPTH_KEY)) {
depth = singleCommentData.getInt(JSONUtils.DEPTH_KEY);
}
@ -184,7 +177,7 @@ public class ParseComment {
boolean hasReply = !(singleCommentData.get(JSONUtils.REPLIES_KEY) instanceof String);
return new CommentData(id, fullName, author, authorFlair, authorFlairHTMLBuilder.toString(),
linkAuthor, formattedSubmitTime, submitTime, commentMarkdown, commentRawText,
linkAuthor, submitTime, commentMarkdown, commentRawText,
linkId, subredditName, parentId, score, voteType, isSubmitter, distinguished,
permalink, awardingsBuilder.toString(),depth, collapsed, hasReply, scoreHidden, saved);
}

View File

@ -8,8 +8,6 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.LinkedHashSet;
import java.util.Locale;
@ -107,10 +105,6 @@ public class ParsePost {
score -= voteType;
}
Calendar postTimeCalendar = Calendar.getInstance();
postTimeCalendar.setTimeInMillis(postTime);
String formattedPostTime = new SimpleDateFormat("MMM d, yyyy, HH:mm",
locale).format(postTimeCalendar.getTime());
String permalink = Html.fromHtml(data.getString(JSONUtils.PERMALINK_KEY)).toString();
String previewUrl = "";
@ -137,7 +131,7 @@ 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, authorFlair, authorFlairHTMLBuilder.toString(), formattedPostTime,
author, authorFlair, authorFlairHTMLBuilder.toString(),
postTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, previewHeight,
score, voteType, nComments, flair, awardingsBuilder.toString(), nAwards, hidden,
spoiler, nsfw, stickied, archived, locked, saved, true);
@ -145,7 +139,7 @@ public class ParsePost {
return post;
} else {
return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, authorFlair, authorFlairHTMLBuilder.toString(), formattedPostTime,
author, authorFlair, authorFlairHTMLBuilder.toString(),
postTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, previewHeight,
score, voteType, nComments, flair, awardingsBuilder.toString(), nAwards, hidden,
spoiler, nsfw, stickied, archived, locked, saved, false);
@ -154,7 +148,7 @@ public class ParsePost {
private static Post parseData(JSONObject data, String permalink, String id, String fullName,
String subredditName, String subredditNamePrefixed, String author,
String authorFlair, String authorFlairHTML, String formattedPostTime,
String authorFlair, String authorFlairHTML,
long postTimeMillis, String title, String previewUrl,
String thumbnailPreviewUrl, int previewWidth, int previewHeight,
int score, int voteType, int nComments, String flair,
@ -171,7 +165,7 @@ public class ParsePost {
//Text post
int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
authorFlair, authorFlairHTML, postTimeMillis,
title, permalink, score, postType, voteType, nComments, flair, awards, nAwards,
hidden, spoiler, nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
@ -196,7 +190,7 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
url, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
@ -207,7 +201,7 @@ public class ParsePost {
//No preview link post
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
authorFlair, authorFlairHTML, postTimeMillis,
title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
@ -232,7 +226,7 @@ public class ParsePost {
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked,
saved, isCrosspost);
@ -251,7 +245,7 @@ public class ParsePost {
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.FALLBACK_URL_KEY);
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
@ -265,7 +259,7 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
authorFlair, authorFlairHTML, postTimeMillis,
title, url, thumbnailPreviewUrl, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw,
stickied, archived, locked, saved, isCrosspost);
@ -276,7 +270,7 @@ public class ParsePost {
//Gif post
int postType = Post.GIF_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
authorFlair, authorFlairHTML, postTimeMillis,
title, previewUrl, thumbnailPreviewUrl, url, permalink, score,
postType, voteType, nComments, flair, awards, nAwards, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
@ -289,7 +283,7 @@ public class ParsePost {
int postType = Post.VIDEO_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
@ -303,7 +297,7 @@ public class ParsePost {
int postType = Post.TEXT_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
authorFlair, authorFlairHTML, postTimeMillis,
title, permalink, score, postType, voteType, nComments, flair,
awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked,
saved, isCrosspost);
@ -332,7 +326,7 @@ public class ParsePost {
int postType = Post.LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis,
authorFlair, authorFlairHTML, postTimeMillis,
title, previewUrl, thumbnailPreviewUrl, url, permalink, score,
postType, voteType, nComments, flair, awards, nAwards, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
@ -353,7 +347,7 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
@ -364,7 +358,7 @@ public class ParsePost {
int postType = Post.VIDEO_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
@ -377,7 +371,7 @@ public class ParsePost {
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, formattedPostTime, postTimeMillis, title,
authorFlair, authorFlairHTML, postTimeMillis, title,
url, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);

View File

@ -40,7 +40,6 @@ public class Post implements Parcelable {
private String authorIconUrl;
private String authorFlair;
private String authorFlairHTML;
private String postTime;
private String title;
private String selfText;
private String selfTextPlain;
@ -72,7 +71,7 @@ public class Post implements Parcelable {
private String crosspostParentId;
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String author, String authorFlair, String authorFlairHTML, String postTime,
String author, String authorFlair, String authorFlairHTML,
long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl,
String permalink, int score, int postType, int voteType, int nComments, String flair,
String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied,
@ -85,7 +84,6 @@ public class Post implements Parcelable {
this.authorNamePrefixed = "u/" + author;
this.authorFlair = authorFlair;
this.authorFlairHTML = authorFlairHTML;
this.postTime = postTime;
this.postTimeMillis = postTimeMillis;
this.title = title;
this.previewUrl = previewUrl;
@ -109,7 +107,7 @@ public class Post implements Parcelable {
}
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String author, String authorFlair, String authorFlairHTML, String postTime,
String author, String authorFlair, String authorFlairHTML,
long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl,
String url, String permalink, int score, int postType, int voteType, int nComments,
String flair, String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw,
@ -122,7 +120,6 @@ public class Post implements Parcelable {
this.authorNamePrefixed = "u/" + author;
this.authorFlair = authorFlair;
this.authorFlairHTML = authorFlairHTML;
this.postTime = postTime;
this.postTimeMillis = postTimeMillis;
this.title = title;
this.previewUrl = previewUrl;
@ -147,7 +144,7 @@ public class Post implements Parcelable {
}
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String author, String authorFlair, String authorFlairHTML, String postTime,
String author, String authorFlair, String authorFlairHTML,
long postTimeMillis, String title, String permalink, int score, int postType,
int voteType, int nComments, String flair, String awards, int nAwards, boolean hidden,
boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked,
@ -160,7 +157,6 @@ public class Post implements Parcelable {
this.authorNamePrefixed = "u/" + author;
this.authorFlair = authorFlair;
this.authorFlairHTML = authorFlairHTML;
this.postTime = postTime;
this.postTimeMillis = postTimeMillis;
this.title = title;
this.permalink = APIUtils.API_BASE_URI + permalink;
@ -192,7 +188,6 @@ public class Post implements Parcelable {
authorFlair = in.readString();
authorFlairHTML = in.readString();
authorIconUrl = in.readString();
postTime = in.readString();
postTimeMillis = in.readLong();
title = in.readString();
selfText = in.readString();
@ -277,10 +272,6 @@ public class Post implements Parcelable {
this.authorIconUrl = authorIconUrl;
}
public String getPostTime() {
return postTime;
}
public long getPostTimeMillis() {
return postTimeMillis;
}
@ -494,7 +485,6 @@ public class Post implements Parcelable {
parcel.writeString(authorFlair);
parcel.writeString(authorFlairHTML);
parcel.writeString(authorIconUrl);
parcel.writeString(postTime);
parcel.writeLong(postTimeMillis);
parcel.writeString(title);
parcel.writeString(selfText);

View File

@ -11,7 +11,6 @@ import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangeDefaultPostLayoutEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowAbsoluteNumberOfVotesEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeVoteButtonsPositionEvent;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.Event.ShowDividerInCompactLayoutPreferenceEvent;
@ -27,7 +26,6 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
SwitchPreference bottomAppBarSwitch = findPreference(SharedPreferencesUtils.BOTTOM_APP_BAR_KEY);
SwitchPreference voteButtonsOnTheRightSwitch = findPreference(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY);
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
ListPreference defaultPostLayoutSwitch = findPreference(SharedPreferencesUtils.DEFAULT_POST_LAYOUT_KEY);
SwitchPreference showDividerInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_DIVIDER_IN_COMPACT_LAYOUT);
SwitchPreference showThumbnailOnTheRightInCompactLayout = findPreference(SharedPreferencesUtils.SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT);
@ -47,13 +45,6 @@ public class InterfacePreferenceFragment extends PreferenceFragmentCompat {
});
}
if (showElapsedTimeSwitch != null) {
showElapsedTimeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeShowElapsedTimeEvent((Boolean) newValue));
return true;
});
}
if (defaultPostLayoutSwitch != null) {
defaultPostLayoutSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeDefaultPostLayoutEvent(Integer.parseInt((String) newValue)));

View File

@ -0,0 +1,38 @@
package ml.docilealligator.infinityforreddit.Settings;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.SwitchPreference;
import org.greenrobot.eventbus.EventBus;
import ml.docilealligator.infinityforreddit.Event.ChangeShowElapsedTimeEvent;
import ml.docilealligator.infinityforreddit.Event.ChangeTimeFormatEvent;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class TimeFormatPreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.time_format_preferences, rootKey);
SwitchPreference showElapsedTimeSwitch = findPreference(SharedPreferencesUtils.SHOW_ELAPSED_TIME_KEY);
ListPreference timeFormatList = findPreference(SharedPreferencesUtils.TIME_FORMAT_KEY);
if (showElapsedTimeSwitch != null) {
showElapsedTimeSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeShowElapsedTimeEvent((Boolean) newValue));
return true;
});
}
if (timeFormatList != null) {
timeFormatList.setOnPreferenceChangeListener((preference, newValue) -> {
EventBus.getDefault().post(new ChangeTimeFormatEvent((String) newValue));
return true;
});
}
}
}

View File

@ -74,6 +74,8 @@ public class SharedPreferencesUtils {
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 TIME_FORMAT_KEY = "time_format";
public static final String TIME_FORMAT_DEFAULT_VALUE = "MMM d, yyyy, HH:mm";
public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout";
public static final String SHOW_DIVIDER_IN_COMPACT_LAYOUT = "show_divider_in_compact_layout";
public static final String SHOW_THUMBNAIL_ON_THE_RIGHT_IN_COMPACT_LAYOUT = "show_thumbnail_on_the_right_in_compact_layout";

View File

@ -13,6 +13,8 @@ import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import ml.docilealligator.infinityforreddit.R;
@ -46,6 +48,12 @@ public class Utils {
return source.subSequence(0, i+1);
}
public static String getFormattedTime(Locale locale, long time, String pattern) {
Calendar postTimeCalendar = Calendar.getInstance();
postTimeCalendar.setTimeInMillis(time);
return new SimpleDateFormat(pattern, locale).format(postTimeCalendar.getTime());
}
public static String getElapsedTime(Context context, long time) {
long now = System.currentTimeMillis();
long diff = now - time;

View File

@ -168,4 +168,54 @@
<item>4</item>
<item>5</item>
</string-array>
<string-array name="settings_time_format">
<item>Jan 2, 2020, 01:00</item>
<item>Jan 2, 2020, 01:00 PM</item>
<item>2 Jan, 2020, 01:00</item>
<item>2 Jan, 2020, 01:00 PM</item>
<item>1/2/2020 01:00 (Month first)</item>
<item>1/2/2020 01:00 PM (Month first)</item>
<item>2/1/2020 01:00 (Day first)</item>
<item>2/1/2020 01:00 PM (Day first)</item>
<item>2020/1/2 01:00 (Month first)</item>
<item>2020/1/2 01:00 PM (Month first)</item>
<item>1-2-2020 01:00 (Month first)</item>
<item>1-2-2020 01:00 PM (Month first)</item>
<item>2-1-2020 01:00 (Day first)</item>
<item>2-1-2020 01:00 PM (Day first)</item>
<item>2020-1-2 01:00 (Month first)</item>
<item>2020-1-2 01:00 PM (Month first)</item>
<item>1.2.2020 01:00 (Month first)</item>
<item>1.2.2020 01:00 PM (Month first)</item>
<item>2.1.2020 01:00 (Day first)</item>
<item>2.1.2020 01:00 PM (Day first)</item>
<item>2020.1.2 01:00 (Month first)</item>
<item>2020.1.2 01:00 PM (Month first)</item>
</string-array>
<string-array name="settings_time_format_values">
<item>MMM d, yyyy, HH:mm</item>
<item>MMM d, yyyy, hh:mm a</item>
<item>d MMM yyyy, HH:mm</item>
<item>d MMM yyyy, hh:mm a</item>
<item>M/d/yyyy HH:mm</item>
<item>M/d/yyyy hh:mm a</item>
<item>d/M/yyyy HH:mm</item>
<item>d/M/yyyy hh:mm a</item>
<item>yyyy/M/d HH:mm</item>
<item>yyyy/M/d hh:mm a</item>
<item>M-d-yyyy HH:mm</item>
<item>M-d-yyyy hh:mm a</item>
<item>d-M-yyyy HH:mm</item>
<item>d-M-yyyy hh:mm a</item>
<item>yyyy-M-d HH:mm</item>
<item>yyyy-M-d hh:mm a</item>
<item>M.d.yyyy HH:mm</item>
<item>M.d.yyyy hh:mm a</item>
<item>d.M.yyyy HH:mm</item>
<item>d.M.yyyy hh:mm a</item>
<item>yyyy.M.d HH:mm</item>
<item>yyyy.M.d hh:mm a</item>
</string-array>
</resources>

View File

@ -355,6 +355,7 @@
<string name="settings_comment_toolbar_hidden">Comment Toolbar Hidden by Default</string>
<string name="settings_show_absolute_number_of_votes_title">Show Absolute Number of Votes</string>
<string name="settings_show_elapsed_time">Show Elapsed Time in Posts and Comments</string>
<string name="settings_time_format_title">Time Format</string>
<string name="settings_default_post_layout">Default Post Layout</string>
<string name="settings_show_divider_in_compact_layout">Show Divider in Compact Layout</string>
<string name="settings_show_thumbnail_on_the_right_in_compact_layout">Show Thumbnail on the Right in Compact Layout</string>

View File

@ -27,10 +27,9 @@
app:key="vote_buttons_on_the_right"
app:title="@string/settings_vote_buttons_on_the_right_title" />
<SwitchPreference
app:defaultValue="false"
app:key="show_elapsed_time"
app:title="@string/settings_show_elapsed_time" />
<Preference
app:title="@string/settings_time_format_title"
app:fragment="ml.docilealligator.infinityforreddit.Settings.TimeFormatPreferenceFragment" />
<ListPreference
app:defaultValue="0"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<SwitchPreference
app:defaultValue="false"
app:key="show_elapsed_time"
app:title="@string/settings_show_elapsed_time" />
<ListPreference
app:defaultValue="MMM d, yyyy, HH:mm"
app:entries="@array/settings_time_format"
app:entryValues="@array/settings_time_format_values"
app:key="time_format"
app:title="@string/settings_time_format_title"
app:useSimpleSummaryProvider="true" />
</PreferenceScreen>