Merge pull request #478 from InfinityDeltaX/master

Made timestamps more configurable.
This commit is contained in:
Moez Bhatti
2016-05-01 00:54:26 -04:00
4 changed files with 81 additions and 40 deletions
@@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import com.android.mms.transaction.Transaction;
import com.android.mms.transaction.TransactionBundle;
import com.android.mms.transaction.TransactionService;
@@ -44,13 +45,14 @@ import com.moez.QKSMS.ui.base.RecyclerCursorAdapter;
import com.moez.QKSMS.ui.mms.MmsThumbnailPresenter;
import com.moez.QKSMS.ui.settings.SettingsFragment;
import com.moez.QKSMS.ui.view.AvatarView;
import ezvcard.Ezvcard;
import ezvcard.VCard;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import ezvcard.Ezvcard;
import ezvcard.VCard;
public class MessageListAdapter extends RecyclerCursorAdapter<MessageListViewHolder, MessageItem> {
private final String TAG = "MessageListAdapter";
@@ -273,55 +275,72 @@ public class MessageListAdapter extends RecyclerCursorAdapter<MessageListViewHol
holder.mDownloadButton.setVisibility(View.GONE);
}
private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) {
boolean showAvatar;
boolean showTimestamp;
int position = mCursor.getPosition();
private boolean shouldShowTimestamp(MessageItem messageItem, int position) {
if (position == mCursor.getCount() - 1) {
showTimestamp = true;
} else if (messageItem.mDeliveryStatus != MessageItem.DeliveryStatus.NONE) {
showTimestamp = true;
} else if (messageItem.isFailedMessage()) {
showTimestamp = true;
} else if (messageItem.isSending()) {
showTimestamp = true;
} else {
int MAX_DURATION = 60 * 60 * 1000;
MessageItem messageItem2 = getItem(position + 1);
showTimestamp = messageItem2.mDate - messageItem.mDate >= MAX_DURATION;
if (messageItem.mAddress != null && messageItem2.mAddress != null &&
!messageItem.mAddress.equals(messageItem2.mAddress) &&
!messageItem.isOutgoingMessage() && !messageItem2.isOutgoingMessage()) {
showTimestamp = true;
}
return true;
}
if (position == 0) {
showAvatar = true;
} else {
int MAX_DURATION = 60 * 60 * 1000;
MessageItem messageItem2 = getItem(position - 1);
showAvatar = messageItem.getBoxId() != messageItem2.getBoxId() || messageItem.mDate - messageItem2.mDate >= MAX_DURATION;
MessageItem messageItem2 = getItem(position + 1);
if(mPrefs.getBoolean(SettingsFragment.FORCE_TIMESTAMPS, false)) {
return true;
} else if (messageItem.mDeliveryStatus != MessageItem.DeliveryStatus.NONE) {
return true;
} else if (messageItem.isFailedMessage()) {
return true;
} else if (messageItem.isSending()) {
return true;
} else if (messagesFromDifferentPeople(messageItem, messageItem2)) {
return true;
} else {
int MAX_DURATION = Integer.parseInt(mPrefs.getString(SettingsFragment.SHOW_NEW_TIMESTAMP_DELAY, "5")) * 60 * 1000;
return (messageItem2.mDate - messageItem.mDate >= MAX_DURATION);
}
}
private boolean shouldShowAvatar(MessageItem messageItem, int position) {
if (position == 0) {
return true;
}
MessageItem messageItem2 = getItem(position - 1);
if (messagesFromDifferentPeople(messageItem, messageItem2)) {
// If the messages are from different people, then we don't care about any of the other checks,
// we need to show the avatar/timestamp. This is used for group chats, which is why we want
// both to be incoming messages
if (messageItem.mAddress != null && messageItem2.mAddress != null &&
!messageItem.mAddress.equals(messageItem2.mAddress) &&
!messageItem.isOutgoingMessage() && !messageItem2.isOutgoingMessage()) {
showAvatar = true;
}
return true;
} else {
int MAX_DURATION = 60 * 60 * 1000;
return (messageItem.getBoxId() != messageItem2.getBoxId() || messageItem.mDate - messageItem2.mDate >= MAX_DURATION);
}
}
private boolean messagesFromDifferentPeople(MessageItem a, MessageItem b) {
return (a.mAddress != null && b.mAddress != null &&
!a.mAddress.equals(b.mAddress) &&
!a.isOutgoingMessage(
) && !b.isOutgoingMessage());
}
private int getBubbleBackgroundResource(boolean showAvatar, boolean isMine) {
if (showAvatar && isMine) return ThemeManager.getSentBubbleRes();
else if (showAvatar && !isMine) return ThemeManager.getReceivedBubbleRes();
else if (!showAvatar && isMine) return ThemeManager.getSentBubbleAltRes();
else if (!showAvatar && !isMine) return ThemeManager.getReceivedBubbleAltRes();
else return -1;
}
private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) {
int position = mCursor.getPosition();
boolean showAvatar = shouldShowAvatar(messageItem, position);
boolean showTimestamp = shouldShowTimestamp(messageItem, position);
holder.mDateView.setVisibility(showTimestamp ? View.VISIBLE : View.GONE);
holder.mSpace.setVisibility(showAvatar ? View.VISIBLE : View.GONE);
holder.mBodyTextView.setBackgroundResource(showAvatar ? (messageItem.isMe() ? ThemeManager.getSentBubbleRes() :
ThemeManager.getReceivedBubbleRes()) : (messageItem.isMe() ?
ThemeManager.getSentBubbleAltRes() : ThemeManager.getReceivedBubbleAltRes()));
holder.mBodyTextView.setBackgroundResource(getBubbleBackgroundResource(showAvatar, messageItem.isMe()));
holder.setLiveViewCallback(key -> {
if (messageItem.isMe()) {
@@ -95,6 +95,8 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
public static final String AUTO_EMOJI = "pref_key_auto_emoji";
public static final String MARKDOWN_ENABLED = "pref_key_markdown_enabled";
public static final String ENTER_BUTTON = "pref_key_enter_button";
public static final String FORCE_TIMESTAMPS = "pref_key_force_timestamps";
public static final String SHOW_NEW_TIMESTAMP_DELAY = "pref_key_timestamp_delay";
public static final String COMPOSE_FAVORITES = "pref_key_compose_favorites";
public static final String FONT_FAMILY = "pref_key_font_family";
public static final String FONT_SIZE = "pref_key_font_size";
+4
View File
@@ -157,6 +157,10 @@
<string name="pref_sent_timestamps">Sent timestamps</string>
<string name="pref_sent_timestamps_summary">Show the timestamp for when a message was sent, not received</string>
<string name="pref_force_timestamps">Force timestamps</string>
<string name="pref_force_timestamps_summary">Enable timestamps for all messages</string>
<string name="pref_key_timestamp_delay">New timestamp delay</string>
<string name="pref_key_timestamp_delay_summary">The number of minutes which must elapse between two messages in order for a new timestamp to be shown.</string>
<string name="pref_compose_favorites">Starred contacts</string>
<string name="pref_compose_summary_favorites">Show your starred contacts in the QK Compose window, making them only a tap away</string>
<string name="pref_prox_sensor_call">Proximity sensor</string>
@@ -137,6 +137,22 @@
android:summary="@string/pref_sent_timestamps_summary"
android:title="@string/pref_sent_timestamps"
android:widgetLayout="@layout/view_switch" />
<EditTextPreference
android:defaultValue="60"
android:dependency="pref_key_force_timestamps"
android:inputType="number"
android:key="pref_key_timestamp_delay"
android:layout="@layout/list_item_preference"
android:summary="@string/pref_key_timestamp_delay_summary"
android:title="@string/pref_key_timestamp_delay" />
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_key_force_timestamps"
android:layout="@layout/list_item_preference"
android:summary="@string/pref_force_timestamps_summary"
android:title="@string/pref_force_timestamps"
android:widgetLayout="@layout/view_switch"
android:disableDependentsState="true"/>
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_key_compose_favorites"