From 6284ee12afe51197ae9a1b67caa3fa4d7b56b97f Mon Sep 17 00:00:00 2001 From: kosyak Date: Wed, 27 Dec 2023 01:10:23 +0100 Subject: [PATCH] new ui category in expert settings --- .../conversations/ui/ConversationFragment.java | 9 +++++++-- .../conversations/ui/EditAccountActivity.java | 7 ++++++- .../ui/adapter/ConversationAdapter.java | 9 ++++++++- .../conversations/ui/adapter/MessageAdapter.java | 15 ++++++++++----- .../eu/siacs/conversations/utils/UIHelper.java | 16 ++++++++-------- src/main/res/values-qwerty/defaults.xml | 1 + src/main/res/values/defaults.xml | 2 ++ src/main/res/values/strings.xml | 4 ++++ src/main/res/xml/preferences.xml | 12 ++++++++++++ 9 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 2bfe26e2c..34ea0dc9d 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -1175,7 +1175,7 @@ public class ConversationFragment extends XmppFragment case ATTACHMENT_CHOICE_CHOOSE_IMAGE: final List imageUris = Attachment.extractAttachments(getActivity(), data, Attachment.Type.IMAGE); - if (imageUris.size() == 1) { + if (imageUris.size() == 1 && !skipImageEditor()) { editImage(imageUris.get(0).getUri()); } else { mediaPreviewAdapter.addMediaPreviews(imageUris); @@ -1184,7 +1184,7 @@ public class ConversationFragment extends XmppFragment break; case ATTACHMENT_CHOICE_TAKE_PHOTO: final Uri takePhotoUri = pendingTakePhotoUri.pop(); - if (takePhotoUri != null) { + if (takePhotoUri != null && !skipImageEditor()) { editImage(takePhotoUri); } else { Log.d(Config.LOGTAG, "lost take photo uri. unable to to attach"); @@ -3943,6 +3943,11 @@ public class ConversationFragment extends XmppFragment return p.getBoolean("enter_is_send", getResources().getBoolean(R.bool.enter_is_send)); } + private boolean skipImageEditor() { + final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(getActivity()); + return p.getBoolean("skip_image_editor_screen", getResources().getBoolean(R.bool.skip_image_editor_screen)); + } + public boolean onArrowUpCtrlPressed() { final Message lastEditableMessage = conversation == null ? null : conversation.getLastEditableMessage(); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 741cbcce5..792df76a7 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -1070,7 +1070,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat boolean showDataSaverWarning = isAffectedByDataSaver(); showOsOptimizationWarning(showBatteryWarning, showDataSaverWarning); this.binding.sessionEst.setText(UIHelper.readableTimeDifferenceFull(this, this.mAccount.getXmppConnection() - .getLastSessionEstablished())); + .getLastSessionEstablished(), allowRelativeTimestamps())); if (features.rosterVersioning()) { this.binding.serverInfoRosterVersion.setText(R.string.server_info_available); } else { @@ -1401,4 +1401,9 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat public void OnUpdateBlocklist(Status status) { refreshUi(); } + + private boolean allowRelativeTimestamps() { + final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); + return !p.getBoolean("always_full_timestamps", getResources().getBoolean(R.bool.always_full_timestamps)); + } } diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index 139ca48c2..2c4e868aa 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -1,6 +1,8 @@ package eu.siacs.conversations.ui.adapter; +import android.content.SharedPreferences; import android.graphics.Typeface; +import android.preference.PreferenceManager; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -37,9 +39,14 @@ public class ConversationAdapter private final List conversations; private OnConversationClickListener listener; + private boolean allowRelativeTimestamps = true; + public ConversationAdapter(XmppActivity activity, List conversations) { this.activity = activity; this.conversations = conversations; + + final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); + allowRelativeTimestamps = !p.getBoolean("always_full_timestamps", activity.getResources().getBoolean(R.bool.always_full_timestamps)); } @NonNull @@ -280,7 +287,7 @@ public class ConversationAdapter ? View.VISIBLE : View.GONE); viewHolder.binding.conversationLastupdate.setText( - UIHelper.readableTimeDifference(activity, timestamp)); + UIHelper.readableTimeDifference(activity, timestamp, allowRelativeTimestamps)); AvatarWorkerTask.loadAvatar( conversation, viewHolder.binding.conversationImage, diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 9f11258e3..282066e13 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -117,6 +117,8 @@ public class MessageAdapter extends ArrayAdapter { @ColorInt private int primaryColor = -1; + private boolean allowRelativeTimestamps = true; + public MessageAdapter(final XmppActivity activity, final List messages, final boolean forceNames) { super(activity, 0, messages); this.audioPlayer = new AudioPlayer(this); @@ -126,6 +128,9 @@ public class MessageAdapter extends ArrayAdapter { this.mForceNames = forceNames; allowedSwipeActions = new HashSet<>(); allowedSwipeActions.add(SwipeDetector.Action.RL); + + final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(activity); + allowRelativeTimestamps = !p.getBoolean("always_full_timestamps", activity.getResources().getBoolean(R.bool.always_full_timestamps)); } public MessageAdapter(final XmppActivity activity, final List messages) { @@ -352,7 +357,7 @@ public class MessageAdapter extends ArrayAdapter { viewHolder.indicator.setVisibility(View.VISIBLE); } - final String formattedTime = UIHelper.readableTimeDifferenceFull(getContext(), message.getMergedTimeSent()); + final String formattedTime = UIHelper.readableTimeDifferenceFull(getContext(), message.getMergedTimeSent(), allowRelativeTimestamps); final String bodyLanguage = message.getBodyLanguage(); final String bodyLanguageInfo = bodyLanguage == null ? "" : String.format(" \u00B7 %s", bodyLanguage.toUpperCase(Locale.US)); if (message.getStatus() <= Message.STATUS_RECEIVED) { @@ -847,17 +852,17 @@ public class MessageAdapter extends ArrayAdapter { final long duration = rtpSessionStatus.duration; if (received) { if (duration > 0) { - viewHolder.status_message.setText(activity.getString(R.string.incoming_call_duration_timestamp, TimeFrameUtils.resolve(activity, duration), UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent()))); + viewHolder.status_message.setText(activity.getString(R.string.incoming_call_duration_timestamp, TimeFrameUtils.resolve(activity, duration), UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent(), allowRelativeTimestamps))); } else if (rtpSessionStatus.successful) { viewHolder.status_message.setText(R.string.incoming_call); } else { - viewHolder.status_message.setText(activity.getString(R.string.missed_call_timestamp, UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent()))); + viewHolder.status_message.setText(activity.getString(R.string.missed_call_timestamp, UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent(), allowRelativeTimestamps))); } } else { if (duration > 0) { - viewHolder.status_message.setText(activity.getString(R.string.outgoing_call_duration_timestamp, TimeFrameUtils.resolve(activity, duration), UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent()))); + viewHolder.status_message.setText(activity.getString(R.string.outgoing_call_duration_timestamp, TimeFrameUtils.resolve(activity, duration), UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent(), allowRelativeTimestamps))); } else { - viewHolder.status_message.setText(activity.getString(R.string.outgoing_call_timestamp, UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent()))); + viewHolder.status_message.setText(activity.getString(R.string.outgoing_call_timestamp, UIHelper.readableTimeDifferenceFull(activity, message.getTimeSent(), allowRelativeTimestamps))); } } viewHolder.indicatorReceived.setImageResource(RtpSessionStatus.getDrawable(received, rtpSessionStatus.successful, isDarkTheme)); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 173454f59..e22f55446 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -136,26 +136,26 @@ public class UIHelper { private static final int FULL_DATE_FLAGS = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL | DateUtils.FORMAT_SHOW_DATE; - public static String readableTimeDifference(Context context, long time) { - return readableTimeDifference(context, time, false); + public static String readableTimeDifference(Context context, long time, boolean allowRelative) { + return readableTimeDifference(context, time, false, allowRelative); } - public static String readableTimeDifferenceFull(Context context, long time) { - return readableTimeDifference(context, time, true); + public static String readableTimeDifferenceFull(Context context, long time, boolean allowRelative) { + return readableTimeDifference(context, time, true, allowRelative); } private static String readableTimeDifference(Context context, long time, - boolean fullDate) { + boolean fullDate, boolean allowRelative) { if (time == 0) { return context.getString(R.string.just_now); } Date date = new Date(time); long difference = (System.currentTimeMillis() - time) / 1000; - if (difference < 60) { + if (difference < 60 && allowRelative) { return context.getString(R.string.just_now); - } else if (difference < 60 * 2) { + } else if (difference < 60 * 2 && allowRelative) { return context.getString(R.string.minute_ago); - } else if (difference < 60 * 15) { + } else if (difference < 60 * 15 && allowRelative) { return context.getString(R.string.minutes_ago, Math.round(difference / 60.0)); } else if (today(date)) { java.text.DateFormat df = DateFormat.getTimeFormat(context); diff --git a/src/main/res/values-qwerty/defaults.xml b/src/main/res/values-qwerty/defaults.xml index 17e88c0bb..4d0dc5b78 100644 --- a/src/main/res/values-qwerty/defaults.xml +++ b/src/main/res/values-qwerty/defaults.xml @@ -1,4 +1,5 @@ true + true \ No newline at end of file diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 316f414dc..0047d32e7 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -48,4 +48,6 @@ false up.conversations.im none + false + false diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 5fdb2eb7f..49d6e56d4 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -592,6 +592,10 @@ Dark Green Background Use green background for received messages + Show full timestamps + Always show full messages timestamps without "now", "1 min ago", etc + Skip image editor + Don’t open image editor screen automatically for single image attachments Could not connect to OpenKeychain This device is no longer in use Computer diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index c6a5c4a1b..795636027 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -380,6 +380,18 @@ android:summary="@string/pref_channel_discovery_summary" android:title="@string/pref_channel_discovery" /> + + + +