diff --git a/QKSMS/build.gradle b/QKSMS/build.gradle index 8e7b8df4..9863ba37 100644 --- a/QKSMS/build.gradle +++ b/QKSMS/build.gradle @@ -2,6 +2,7 @@ apply plugin: 'com.android.application' repositories { mavenCentral() + jcenter() } android { @@ -74,6 +75,7 @@ dependencies { compile 'com.googlecode.ez-vcard:ez-vcard:0.9.6' compile 'com.google.code.gson:gson:2.3' compile 'com.koushikdutta.ion:ion:1.1.7' + compile 'org.ligi:snackengage:0.4' // Google libraries compile 'com.android.support:appcompat-v7:22.2.1' diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/QKRateSnack.java b/QKSMS/src/main/java/com/moez/QKSMS/common/QKRateSnack.java new file mode 100644 index 00000000..714e42f1 --- /dev/null +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/QKRateSnack.java @@ -0,0 +1,24 @@ +package com.moez.QKSMS.common; + +import com.moez.QKSMS.R; + +import org.ligi.snackengage.conditions.AfterNumberOfOpportunities; +import org.ligi.snackengage.conditions.NeverAgainWhenClickedOnce; +import org.ligi.snackengage.snacks.RateSnack; + +/* https://github.com/ligi/SnackEngage +* "This shows a snackbar after MainActivity was created *10* times and never again when once clicked on Rate" */ + +public class QKRateSnack extends RateSnack { + public QKRateSnack() { + withConditions(new NeverAgainWhenClickedOnce(), new AfterNumberOfOpportunities(10)); + } + + @Override public String getText(){ + return getString(R.string.rate_title); + } + + @Override public String getActionText(){ + return getString(R.string.rate_action); + } +} \ No newline at end of file diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/EmojiRegistry.java b/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/EmojiRegistry.java index d214e654..3189590a 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/EmojiRegistry.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/EmojiRegistry.java @@ -38,28 +38,29 @@ public class EmojiRegistry { public static String parseEmojis(String body) { if (TextUtils.isEmpty(body)) { return body; - } else { - // whitespace and punctuation characters - String ACCEPTED_CHARS = "[\\s.,?:;'\"!]"; - - // explanation: we want to match: - // 1) either an accepted char or the beginning of the text (i.e. ^) - // 2) the actual emoji code (to be inserted in the loop) - // 3) either an accepted char or the end of the text (i.e. $) - String REGEX_TEMPLATE = String.format("(^|%s)%s(%s|$)", ACCEPTED_CHARS, "%s", ACCEPTED_CHARS); - - // iterate over all the entries - for (Map.Entry entry : EmojiRegistry.EMOJIS_MAP.entrySet()) { - // quote the emoji code because some characters like ) are protected in regex land - String quoted = Pattern.quote(entry.getKey()); - String regex = String.format(REGEX_TEMPLATE, quoted); - - // the $1 and $2 represent the character* that came before the emoji and the - // character* that came after the emoji - // * - or beginning / end of text - body = body.replaceAll(regex, "$1:" + entry.getValue() + ":$2"); - } - return EmojiParser.parseToUnicode(body); } + + // whitespace and punctuation characters + String ACCEPTED_CHARS = "[\\s.,?:;'\"!]"; + + // explanation: we want to match: + // 1) either an accepted char or the beginning of the text (i.e. ^) + // 2) the actual emoji code (to be inserted in the loop) + // 3) either an accepted char or the end of the text (i.e. $) + String REGEX_TEMPLATE = String.format("(^|%s)%s(%s|$)", ACCEPTED_CHARS, "%s", ACCEPTED_CHARS); + + // iterate over all the entries + for (Map.Entry entry : EmojiRegistry.EMOJIS_MAP.entrySet()) { + // quote the emoji code because some characters like ) are protected in regex land + String quoted = Pattern.quote(entry.getKey()); + String regex = String.format(REGEX_TEMPLATE, quoted); + + // the $1 and $2 represent the character* that came before the emoji and the + // character* that came after the emoji + // * - or beginning / end of text + body = body.replaceAll(regex, "$1:" + entry.getValue() + ":$2"); + } + + return EmojiParser.parseToUnicode(body); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/Emojis.java b/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/Emojis.java index a6680036..3e6cade1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/Emojis.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/emoji/Emojis.java @@ -1,5 +1,8 @@ package com.moez.QKSMS.common.emoji; +/** + * Defines all supported emojis + */ public class Emojis { public static final String SMILE = "smile"; public static final String SMILEY = "smiley"; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/Contact.java b/QKSMS/src/main/java/com/moez/QKSMS/data/Contact.java index 53454894..23f4ecbb 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/Contact.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/Contact.java @@ -122,6 +122,7 @@ public class Contact { mIsStale = true; mSendToVoicemail = false; } + @Override public String toString() { return String.format("{ number=%s, name=%s, nameAndNumber=%s, label=%s, person_id=%d, hash=%d method_id=%d }", diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java index f9e711e4..38b101cb 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/ContactHelper.java @@ -188,10 +188,9 @@ public class ContactHelper { } catch (IOException e) { e.printStackTrace(); } - return bitmap; } - + public static Bitmap blankContact(Context context, String name) { String text = name == null || PhoneNumberUtils.isWellFormedSmsAddress(PhoneNumberUtils.stripSeparators(name)) || name.length() == 0 ? "#" : "" + name.toUpperCase().charAt(0); diff --git a/QKSMS/src/main/java/com/moez/QKSMS/data/Message.java b/QKSMS/src/main/java/com/moez/QKSMS/data/Message.java index c057dd97..73dbc955 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/data/Message.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/data/Message.java @@ -82,12 +82,12 @@ public class Message { } public boolean isMms() { - boolean bool = false; + boolean isMms = false; Cursor cursor = null; try { cursor = context.getContentResolver().query(MMS_SMS_CONTENT_PROVIDER, new String[]{SmsHelper.COLUMN_MMS}, "_id=" + id, null, null); cursor.moveToFirst(); - bool = "application/vnd.wap.multipart.related".equals(cursor.getString(cursor.getColumnIndex(SmsHelper.COLUMN_MMS))); + isMms = "application/vnd.wap.multipart.related".equals(cursor.getString(cursor.getColumnIndex(SmsHelper.COLUMN_MMS))); } catch (Exception e) { e.printStackTrace(); } finally { @@ -95,7 +95,7 @@ public class Message { cursor.close(); } } - return bool; + return isMms; } public String getAddress() { diff --git a/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java b/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java index a599e8dd..60113467 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java @@ -95,8 +95,6 @@ public class SmsHelper { private static final String TAG = "SMSHelper"; private static SmsManager sms; - private static Cursor cursor; - private static Settings sendSettings; public SmsHelper() { @@ -157,11 +155,6 @@ public class SmsHelper { private static String[] sNoSubjectStrings; - public static long getLastThreadId(Context context) { - Cursor cursor = context.getContentResolver().query(SmsHelper.RECEIVED_MESSAGE_CONTENT_PROVIDER, new String[]{COLUMN_ID}, null, null, "date DESC"); - return (cursor != null && cursor.moveToFirst()) ? cursor.getLong(0) : 0; - } - public static void markSmsSeen(Context context) { Cursor cursor = context.getContentResolver().query(RECEIVED_MESSAGE_CONTENT_PROVIDER, new String[]{SmsHelper.COLUMN_ID}, SmsHelper.UNSEEN_SELECTION + " AND " + SmsHelper.UNREAD_SELECTION, null, null); @@ -290,7 +283,7 @@ public class SmsHelper { } public static int getUnseenSMSCount(Context context, long threadId) { - + Cursor cursor = null; int count = 0; String selection = UNSEEN_SELECTION + " AND " + UNREAD_SELECTION + (threadId == 0 ? "" : " AND " + COLUMN_THREAD_ID + " = " + threadId); @@ -301,7 +294,9 @@ public class SmsHelper { } catch (Exception e) { e.printStackTrace(); } finally { - cursor.close(); + if (cursor != null) { + cursor.close(); + } } return count; @@ -314,6 +309,7 @@ public class SmsHelper { */ public static String getHistoryForWearable(Context context, String name, long threadId) { final String me = context.getString(R.string.me); + Cursor cursor = null; StringBuilder builder = new StringBuilder(); MessageColumns.ColumnsMap map = new MessageColumns.ColumnsMap(); @@ -432,6 +428,7 @@ public class SmsHelper { } public static long getThreadId(Context context, String address) { + Cursor cursor = null; long threadId = 0; try { @@ -440,67 +437,13 @@ public class SmsHelper { threadId = cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_THREAD_ID)); } catch (Exception e) { e.printStackTrace(); - } - - return threadId; - } - - public static long getLastSentThreadId(Context context) { - long threadId = 0; - - try { - cursor = context.getContentResolver().query(SENT_MESSAGE_CONTENT_PROVIDER, new String[]{COLUMN_THREAD_ID}, null, null, sortDateDesc); - cursor.moveToFirst(); - threadId = cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_THREAD_ID)); - } catch (Exception e) { - e.printStackTrace(); - } - - return threadId; - } - - public static List getUnseenMessageNames(Context context) { - List messages = getUnseenMessages(context); - List names = new ArrayList<>(); - - for (int i = 0; i < messages.size(); i++) { - if (!names.contains(messages.get(i).getName())) - names.add(messages.get(i).getName()); - } - - return names; - } - - public static String getUnseenMessageText(Context context, boolean names) { - List messages = getUnseenMessages(context); - String s = ""; - - for (Message message : messages) { - if (names) s += message.getName() + ": "; - s += message.getBody() + "\n"; - } - - return s.substring(0, s.length() - 1); - } - - public static List getUnseenMessages(Context context) { - - List messages = new ArrayList<>(); - - try { - cursor = context.getContentResolver().query(RECEIVED_MESSAGE_CONTENT_PROVIDER, new String[]{COLUMN_ID}, UNSEEN_SELECTION + " AND " + UNREAD_SELECTION, null, sortDateDesc); - cursor.moveToFirst(); - for (int i = 0; i < cursor.getCount(); i++) { - messages.add(new Message(context, cursor.getLong(cursor.getColumnIndexOrThrow(COLUMN_ID)))); - cursor.moveToNext(); - } - } catch (Exception e) { - e.printStackTrace(); } finally { - cursor.close(); + if (cursor != null) { + cursor.close(); + } } - return messages; + return threadId; } public static int getUnreadMessageCount(Context context) { @@ -519,11 +462,13 @@ public class SmsHelper { } while (conversationCursor.moveToNext()); } + conversationCursor.close(); + return result; } public static List getFailedMessages(Context context) { - + Cursor cursor = null; List messages = new ArrayList<>(); try { @@ -536,16 +481,17 @@ public class SmsHelper { } catch (Exception e) { e.printStackTrace(); } finally { - cursor.close(); + if (cursor != null) { + cursor.close(); + } } return messages; } public static List deleteFailedMessages(Context context, long threadId) { - Log.d(TAG, "Deleting failed messages"); - + Cursor cursor = null; List messages = new ArrayList<>(); try { @@ -558,12 +504,13 @@ public class SmsHelper { } catch (Exception e) { e.printStackTrace(); } finally { - cursor.close(); + if (cursor != null) { + cursor.close(); + } } - for (Message m : messages) - { - if(m.getThreadId() == threadId) { + for (Message m : messages) { + if (m.getThreadId() == threadId) { Log.d(TAG, "Deleting failed message to " + m.getName() + "\n Body: " + m.getBody()); m.delete(); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 4840422f..578f50a8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -24,10 +24,12 @@ import android.view.MenuItem; import android.view.View; import android.widget.CheckBox; import android.widget.ImageView; + import com.google.android.mms.pdu_alt.PduHeaders; import com.moez.QKSMS.R; import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.DonationManager; +import com.moez.QKSMS.common.QKRateSnack; import com.moez.QKSMS.common.google.DraftCache; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; @@ -52,6 +54,9 @@ import com.moez.QKSMS.ui.welcome.WelcomeActivity; import com.nispok.snackbar.Snackbar; import com.nispok.snackbar.listeners.ActionClickListener; +import org.ligi.snackengage.SnackEngage; +import org.ligi.snackengage.snacks.BaseSnack; + import java.net.URLDecoder; import java.util.Collection; @@ -112,6 +117,10 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen onNewIntent(getIntent()); showDialogIfNeeded(savedInstanceState); + + //Adds a small/non intrusive snackbar that asks the user to rate the app + SnackEngage.from(this).withSnack(new QKRateSnack().withDuration(BaseSnack.DURATION_LONG)) + .build().engageWhenAppropriate(); } /** diff --git a/QKSMS/src/main/res/values-de/strings.xml b/QKSMS/src/main/res/values-de/strings.xml index e071e360..d9dd1ca9 100755 --- a/QKSMS/src/main/res/values-de/strings.xml +++ b/QKSMS/src/main/res/values-de/strings.xml @@ -49,6 +49,8 @@ Inhalt Gesendet Empfangen + Gefällt dir QKSMS? + Bewerten Erscheinungsbild Themen, Schriften, Farben, Avatare und mehr Allgemein diff --git a/QKSMS/src/main/res/values/donottranslate.xml b/QKSMS/src/main/res/values/donottranslate.xml index 31a40183..5af07d85 100644 --- a/QKSMS/src/main/res/values/donottranslate.xml +++ b/QKSMS/src/main/res/values/donottranslate.xml @@ -30,6 +30,7 @@ Jacob Klinker Jeff Gilfelt Melnykov Oleksandr + ligi @@ -39,6 +40,7 @@ github.com/klinker41 github.com/jgilfelt github.com/makovkastar + github.com/ligi @@ -48,6 +50,7 @@ android-smsmms\nandroid-chips SystemBarTint FloatingActionButton + SnackEngage diff --git a/QKSMS/src/main/res/values/strings.xml b/QKSMS/src/main/res/values/strings.xml index 927af657..00aaa045 100644 --- a/QKSMS/src/main/res/values/strings.xml +++ b/QKSMS/src/main/res/values/strings.xml @@ -101,6 +101,10 @@ Date sent Date received + + Like QKSMS? + + Rate Appearance Themes, fonts, colors, avatars, and more diff --git a/README.md b/README.md index fb8f515f..bc3d22d3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Any new code written should follow these guidelines # Bug Reports / Feature Requests -We track issues and pull requests using GitHub issues. You can view existing issues and create your own here: https://github.com/qklabs/qksms/issues +We track issues and feature requests using GitHub issues. You can view existing issues and create your own here: https://github.com/qklabs/qksms/issues ### How to help @@ -90,12 +90,12 @@ The conversation isn't marked as read. #### Helping reproduce bugs Reproducing a bug is important, since if we can't reproduce an issue then it's hard to figure out what's going wrong, and we can't know that we've fixed it. -To see bugs that need "repro steps", go to the Issues section and search for `is:open label:needs-repro`. If you see any bugs that you know how to reproduce (see above for example repro steps), then make a comment with the steps and we'll track the bug down! +You can see bugs which need "repro steps" [here](https://github.com/qklabs/qksms/issues?q=is%3Aopen+is%3Aissue+label%3Aneeds-repro). If you see any bugs that you know how to reproduce (see above for example repro steps), then make a comment with the steps and we'll track the bug down! #### Making enhancement requests There are no rules for enhancement requests. Your ideas are all awesome. Although we may not implement every suggestion, we love brainstorming with you and hearing your feedback. -To make an enhancement request, add an "issue" with the "enhancement" label. +To make an enhancement request, add an "issue". # Contact