forked from upstream-mirrors/quik
Merge branch 'master' into mainactivity-cleanup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<String, String> 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<String, String> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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 }",
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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<String> getUnseenMessageNames(Context context) {
|
||||
List<Message> messages = getUnseenMessages(context);
|
||||
List<String> 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<Message> 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<Message> getUnseenMessages(Context context) {
|
||||
|
||||
List<Message> 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<Message> getFailedMessages(Context context) {
|
||||
|
||||
Cursor cursor = null;
|
||||
List<Message> 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<Message> deleteFailedMessages(Context context, long threadId) {
|
||||
|
||||
Log.d(TAG, "Deleting failed messages");
|
||||
|
||||
Cursor cursor = null;
|
||||
List<Message> 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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user