Merged master into release-2.6

This commit is contained in:
Moez Bhatti
2016-05-26 01:26:11 -04:00
10 changed files with 129 additions and 51 deletions
+4 -2
View File
@@ -81,6 +81,8 @@ buildscript {
} }
} }
String leakCanaryVersion = '1.4-beta2'
dependencies { dependencies {
// Open source libraries // Open source libraries
compile 'com.mcxiaoke.volley:library:1.0.19' compile 'com.mcxiaoke.volley:library:1.0.19'
@@ -91,8 +93,8 @@ dependencies {
compile 'com.googlecode.libphonenumber:libphonenumber:6.2' compile 'com.googlecode.libphonenumber:libphonenumber:6.2'
compile 'com.nispok:snackbar:2.10.6' compile 'com.nispok:snackbar:2.10.6'
compile 'com.github.lzyzsd:circleprogress:1.1.0' compile 'com.github.lzyzsd:circleprogress:1.1.0'
debugCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' debugCompile "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
compile 'com.vdurmont:emoji-java:1.1.1' compile 'com.vdurmont:emoji-java:1.1.1'
compile 'me.leolin:ShortcutBadger:1.1.1' compile 'me.leolin:ShortcutBadger:1.1.1'
compile 'com.googlecode.ez-vcard:ez-vcard:0.9.6' compile 'com.googlecode.ez-vcard:ez-vcard:0.9.6'
@@ -42,6 +42,13 @@ public class DonationManager {
return sInstance; return sInstance;
} }
public static void clearInstance() {
if (null != sInstance) {
sInstance.destroy();
}
sInstance = null;
}
private DonationManager(QKActivity context) { private DonationManager(QKActivity context) {
mContext = context; mContext = context;
mRes = mContext.getResources(); mRes = mContext.getResources();
@@ -77,6 +84,10 @@ public class DonationManager {
if (mHelper != null) { if (mHelper != null) {
mHelper.dispose(); mHelper.dispose();
} }
mHelper = null;
mContext = null;
mRes = null;
mBillingServiceReady = false;
} }
// Callback for when a purchase is finished // Callback for when a purchase is finished
@@ -15,13 +15,19 @@ public class LifecycleHandler implements Application.ActivityLifecycleCallbacks
private static int sPaused; private static int sPaused;
private static int sStarted; private static int sStarted;
private static int sStopped; private static int sStopped;
private static int sActivityCounter;
@Override @Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) { public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
sActivityCounter++;
} }
@Override @Override
public void onActivityDestroyed(Activity activity) { public void onActivityDestroyed(Activity activity) {
sActivityCounter--;
if (isNoActivitiesAlive()) {
DonationManager.clearInstance();
}
} }
@Override @Override
@@ -57,4 +63,8 @@ public class LifecycleHandler implements Application.ActivityLifecycleCallbacks
public static boolean isApplicationInForeground() { public static boolean isApplicationInForeground() {
return sResumed > sPaused; return sResumed > sPaused;
} }
public static boolean isNoActivitiesAlive() {
return sActivityCounter <= 0;
}
} }
@@ -26,6 +26,7 @@ import com.moez.QKSMS.common.BlockedConversationHelper;
import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.DialogHelper;
import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.LiveViewManager;
import com.moez.QKSMS.common.utils.ColorUtils; import com.moez.QKSMS.common.utils.ColorUtils;
import com.moez.QKSMS.data.Contact;
import com.moez.QKSMS.data.Conversation; import com.moez.QKSMS.data.Conversation;
import com.moez.QKSMS.data.ConversationLegacy; import com.moez.QKSMS.data.ConversationLegacy;
import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.enums.QKPreference;
@@ -271,6 +272,21 @@ public class ConversationListFragment extends QKFragment implements LoaderManage
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().deleteObserver(this); BlockedConversationHelper.FutureBlockedConversationObservable.getInstance().deleteObserver(this);
if (null == mRecyclerView) {
return;
}
try {
for (int i = 0; i < mRecyclerView.getChildCount(); i++) {
View child = mRecyclerView.getChildAt(i);
RecyclerView.ViewHolder holder = mRecyclerView.getChildViewHolder(child);
if (holder instanceof ConversationListViewHolder) {
Contact.removeListener((ConversationListViewHolder) holder);
}
}
} catch (Exception ignored) {
//
}
} }
public Loader<Cursor> onCreateLoader(int id, Bundle args) { public Loader<Cursor> onCreateLoader(int id, Bundle args) {
@@ -85,13 +85,10 @@ public class ConversationListViewHolder extends ClickyViewHolder<Conversation> i
final ConversationLegacy conversationLegacy = new ConversationLegacy(mContext, mData.getThreadId()); final ConversationLegacy conversationLegacy = new ConversationLegacy(mContext, mData.getThreadId());
if (shouldUpdate) { if (shouldUpdate) {
((MainActivity) mContext).runOnUiThread(new Runnable() { mContext.runOnUiThread(() -> {
@Override mAvatarView.setImageDrawable(drawable);
public void run() { mAvatarView.setContactName(name);
mAvatarView.setImageDrawable(drawable); fromView.setText(formatMessage(mData, conversationLegacy));
mAvatarView.setContactName(name);
fromView.setText(formatMessage(mData, conversationLegacy));
}
}); });
} }
} }
@@ -21,6 +21,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import com.android.mms.transaction.Transaction; import com.android.mms.transaction.Transaction;
import com.android.mms.transaction.TransactionBundle; import com.android.mms.transaction.TransactionBundle;
import com.android.mms.transaction.TransactionService; 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.mms.MmsThumbnailPresenter;
import com.moez.QKSMS.ui.settings.SettingsFragment; import com.moez.QKSMS.ui.settings.SettingsFragment;
import com.moez.QKSMS.ui.view.AvatarView; import com.moez.QKSMS.ui.view.AvatarView;
import ezvcard.Ezvcard;
import ezvcard.VCard;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import ezvcard.Ezvcard;
import ezvcard.VCard;
public class MessageListAdapter extends RecyclerCursorAdapter<MessageListViewHolder, MessageItem> { public class MessageListAdapter extends RecyclerCursorAdapter<MessageListViewHolder, MessageItem> {
private final String TAG = "MessageListAdapter"; private final String TAG = "MessageListAdapter";
@@ -273,55 +275,72 @@ public class MessageListAdapter extends RecyclerCursorAdapter<MessageListViewHol
holder.mDownloadButton.setVisibility(View.GONE); holder.mDownloadButton.setVisibility(View.GONE);
} }
private void bindGrouping(MessageListViewHolder holder, MessageItem messageItem) { private boolean shouldShowTimestamp(MessageItem messageItem, int position) {
boolean showAvatar;
boolean showTimestamp;
int position = mCursor.getPosition();
if (position == mCursor.getCount() - 1) { if (position == mCursor.getCount() - 1) {
showTimestamp = true; return 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;
}
} }
if (position == 0) { MessageItem messageItem2 = getItem(position + 1);
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;
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, // 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 // we need to show the avatar/timestamp. This is used for group chats, which is why we want
// both to be incoming messages // both to be incoming messages
if (messageItem.mAddress != null && messageItem2.mAddress != null && return true;
!messageItem.mAddress.equals(messageItem2.mAddress) && } else {
!messageItem.isOutgoingMessage() && !messageItem2.isOutgoingMessage()) { int MAX_DURATION = 60 * 60 * 1000;
showAvatar = true; 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.mDateView.setVisibility(showTimestamp ? View.VISIBLE : View.GONE);
holder.mSpace.setVisibility(showAvatar ? View.VISIBLE : View.GONE); holder.mSpace.setVisibility(showAvatar ? View.VISIBLE : View.GONE);
holder.mBodyTextView.setBackgroundResource(showAvatar ? (messageItem.isMe() ? ThemeManager.getSentBubbleRes() : holder.mBodyTextView.setBackgroundResource(getBubbleBackgroundResource(showAvatar, messageItem.isMe()));
ThemeManager.getReceivedBubbleRes()) : (messageItem.isMe() ?
ThemeManager.getSentBubbleAltRes() : ThemeManager.getReceivedBubbleAltRes()));
holder.setLiveViewCallback(key -> { holder.setLiveViewCallback(key -> {
if (messageItem.isMe()) { if (messageItem.isMe()) {
@@ -94,6 +94,8 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
public static final String AUTO_EMOJI = "pref_key_auto_emoji"; public static final String AUTO_EMOJI = "pref_key_auto_emoji";
public static final String MARKDOWN_ENABLED = "pref_key_markdown_enabled"; public static final String MARKDOWN_ENABLED = "pref_key_markdown_enabled";
public static final String ENTER_BUTTON = "pref_key_enter_button"; 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 COMPOSE_FAVORITES = "pref_key_compose_favorites";
public static final String FONT_FAMILY = "pref_key_font_family"; public static final String FONT_FAMILY = "pref_key_font_family";
public static final String FONT_SIZE = "pref_key_font_size"; public static final String FONT_SIZE = "pref_key_font_size";
+4
View File
@@ -155,6 +155,10 @@
<string name="pref_sent_timestamps">Sent timestamps</string> <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_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_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_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> <string name="pref_prox_sensor_call">Proximity sensor</string>
@@ -137,6 +137,22 @@
android:summary="@string/pref_sent_timestamps_summary" android:summary="@string/pref_sent_timestamps_summary"
android:title="@string/pref_sent_timestamps" android:title="@string/pref_sent_timestamps"
android:widgetLayout="@layout/view_switch" /> 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 <CheckBoxPreference
android:defaultValue="true" android:defaultValue="true"
android:key="pref_key_compose_favorites" android:key="pref_key_compose_favorites"
+3 -2
View File
@@ -1,10 +1,11 @@
# QKSMS # QKSMS
QKSMS is an open source replacement to the [stock messaging app](https://github.com/android/platform_packages_apps_mms) on Android. It is currently available on the Google Play Store. [![Join the chat at https://gitter.im/qklabs/qksms](https://badges.gitter.im/qklabs/qksms.svg)](https://gitter.im/qklabs/qksms?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![ZenHub] (https://raw.githubusercontent.com/ZenHubIO/support/master/zenhub-badge.png)] (https://zenhub.io) [![ZenHub] (https://raw.githubusercontent.com/ZenHubIO/support/master/zenhub-badge.png)] (https://zenhub.io)
[![Build Status](https://travis-ci.org/qklabs/qksms.svg?branch=master)](https://travis-ci.org/qklabs/qksms) [![Build Status](https://travis-ci.org/qklabs/qksms.svg?branch=master)](https://travis-ci.org/qklabs/qksms)
QKSMS is an open source replacement to the [stock messaging app](https://github.com/android/platform_packages_apps_mms) on Android. It is currently available on the Google Play Store.
[![Download on Google Play](http://i.imgur.com/rHhHvZw.png)](https://play.google.com/store/apps/details?id=com.moez.QKSMS) [![Download on Google Play](http://i.imgur.com/rHhHvZw.png)](https://play.google.com/store/apps/details?id=com.moez.QKSMS)
[![Download on F-Droid](https://f-droid.org/wiki/images/0/06/F-Droid-button_get-it-on.png)](https://f-droid.org/repository/browse/?fdid=com.moez.QKSMS) [![Download on F-Droid](https://f-droid.org/wiki/images/0/06/F-Droid-button_get-it-on.png)](https://f-droid.org/repository/browse/?fdid=com.moez.QKSMS)