forked from upstream-mirrors/quik
Separate calls for read and unread messages
This commit is contained in:
@@ -44,42 +44,29 @@ public class DeleteOldMessagesService extends IntentService {
|
|||||||
private void deleteOldUnreadMessages(Context context) {
|
private void deleteOldUnreadMessages(Context context) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD)));
|
calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD)));
|
||||||
|
int count = deleteOldMessages(context, SmsHelper.UNREAD_SELECTION, calendar.getTimeInMillis());
|
||||||
Cursor cursor = null;
|
Log.i(TAG, "Deleted unread messages: " + count);
|
||||||
String selection = SmsHelper.COLUMN_DATE + "<=?";
|
|
||||||
|
|
||||||
try {
|
|
||||||
cursor = context.getContentResolver().query(
|
|
||||||
SmsHelper.SMS_CONTENT_PROVIDER,
|
|
||||||
new String[]{SmsHelper.COLUMN_ID, SmsHelper.COLUMN_DATE},
|
|
||||||
selection,
|
|
||||||
new String[]{String.valueOf(calendar.getTimeInMillis())},
|
|
||||||
null);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
if (cursor != null) {
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void deleteOldReadMessages(Context context) {
|
private void deleteOldReadMessages(Context context) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_READ)));
|
calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_READ)));
|
||||||
|
int count = deleteOldMessages(context, SmsHelper.READ_SELECTION + "=" + SmsHelper.READ, calendar.getTimeInMillis());
|
||||||
|
Log.i(TAG, "Deleted read messages: " + count);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int deleteOldMessages(Context context, String selection, long before) {
|
||||||
Cursor cursor = null;
|
Cursor cursor = null;
|
||||||
String selection = SmsHelper.COLUMN_DATE + "<=?";
|
selection += " AND " + SmsHelper.COLUMN_DATE + "<=?";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cursor = context.getContentResolver().query(
|
cursor = context.getContentResolver().query(
|
||||||
SmsHelper.SMS_CONTENT_PROVIDER,
|
SmsHelper.SMS_CONTENT_PROVIDER,
|
||||||
new String[]{SmsHelper.COLUMN_ID, SmsHelper.COLUMN_DATE},
|
new String[]{SmsHelper.COLUMN_ID, SmsHelper.COLUMN_DATE},
|
||||||
selection,
|
selection,
|
||||||
new String[]{String.valueOf(calendar.getTimeInMillis())},
|
new String[]{String.valueOf(before)},
|
||||||
null);
|
null);
|
||||||
|
return cursor.getCount();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
} finally {
|
||||||
@@ -87,6 +74,8 @@ public class DeleteOldMessagesService extends IntentService {
|
|||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setupAutoDeleteAlarm(Context context) {
|
public static void setupAutoDeleteAlarm(Context context) {
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ public class SmsHelper {
|
|||||||
public static final String COLUMN_BODY = "body";
|
public static final String COLUMN_BODY = "body";
|
||||||
public static final String COLUMN_SEEN = "seen";
|
public static final String COLUMN_SEEN = "seen";
|
||||||
|
|
||||||
|
public static final String READ_SELECTION = COLUMN_READ + " = " + READ;
|
||||||
public static final String UNREAD_SELECTION = COLUMN_READ + " = " + UNREAD;
|
public static final String UNREAD_SELECTION = COLUMN_READ + " = " + UNREAD;
|
||||||
public static final String UNSEEN_SELECTION = COLUMN_SEEN + " = " + UNREAD;
|
public static final String UNSEEN_SELECTION = COLUMN_SEEN + " = " + UNREAD;
|
||||||
public static final String FAILED_SELECTION = COLUMN_TYPE + " = " + Message.FAILED;
|
public static final String FAILED_SELECTION = COLUMN_TYPE + " = " + Message.FAILED;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import com.moez.QKSMS.common.utils.KeyboardUtils;
|
|||||||
import com.moez.QKSMS.common.utils.PackageUtils;
|
import com.moez.QKSMS.common.utils.PackageUtils;
|
||||||
import com.moez.QKSMS.enums.QKPreference;
|
import com.moez.QKSMS.enums.QKPreference;
|
||||||
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
|
import com.moez.QKSMS.receiver.NightModeAutoReceiver;
|
||||||
|
import com.moez.QKSMS.service.DeleteOldMessagesService;
|
||||||
import com.moez.QKSMS.transaction.EndlessJabber;
|
import com.moez.QKSMS.transaction.EndlessJabber;
|
||||||
import com.moez.QKSMS.transaction.NotificationManager;
|
import com.moez.QKSMS.transaction.NotificationManager;
|
||||||
import com.moez.QKSMS.transaction.SmsHelper;
|
import com.moez.QKSMS.transaction.SmsHelper;
|
||||||
@@ -106,6 +107,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
public static final String DELIVERY_REPORTS = "pref_key_delivery";
|
public static final String DELIVERY_REPORTS = "pref_key_delivery";
|
||||||
public static final String DELIVERY_TOAST = "pref_key_delivery_toast";
|
public static final String DELIVERY_TOAST = "pref_key_delivery_toast";
|
||||||
public static final String DELIVERY_VIBRATE = "pref_key_delivery_vibrate";
|
public static final String DELIVERY_VIBRATE = "pref_key_delivery_vibrate";
|
||||||
|
public static final String DELETE_OLD_MESSAGES = "pref_key_delete_old_messages";
|
||||||
public static final String DELETE_UNREAD_MESSAGES = "pref_key_delete_old_unread_messages";
|
public static final String DELETE_UNREAD_MESSAGES = "pref_key_delete_old_unread_messages";
|
||||||
public static final String DELETE_READ_MESSAGES = "pref_key_delete_old_read_messages";
|
public static final String DELETE_READ_MESSAGES = "pref_key_delete_old_read_messages";
|
||||||
public static final String YAPPY = "pref_key_endlessjabber";
|
public static final String YAPPY = "pref_key_endlessjabber";
|
||||||
@@ -453,12 +455,22 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
case NIGHT_START:
|
case NIGHT_START:
|
||||||
updateAlarmManager(mContext, true);
|
updateAlarmManager(mContext, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case DELETE_OLD_MESSAGES:
|
||||||
|
DeleteOldMessagesService.setupAutoDeleteAlarm(mContext);
|
||||||
|
if ((Boolean) newValue) {
|
||||||
|
mContext.makeToast(R.string.toast_deleting_old_messages);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case DELETE_UNREAD_MESSAGES:
|
case DELETE_UNREAD_MESSAGES:
|
||||||
preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, newValue));
|
preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, newValue));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETE_READ_MESSAGES:
|
case DELETE_READ_MESSAGES:
|
||||||
preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, newValue));
|
preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, newValue));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case YAPPY:
|
case YAPPY:
|
||||||
if ((Boolean) newValue) {
|
if ((Boolean) newValue) {
|
||||||
try {
|
try {
|
||||||
@@ -566,7 +578,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O
|
|||||||
case SHOULD_I_ANSWER:
|
case SHOULD_I_ANSWER:
|
||||||
final String packageName = "org.mistergroup.muzutozvednout";
|
final String packageName = "org.mistergroup.muzutozvednout";
|
||||||
if (!PackageUtils.isAppInstalled(mContext, packageName)) {
|
if (!PackageUtils.isAppInstalled(mContext, packageName)) {
|
||||||
String referrer="referrer=utm_source%3Dqksms%26utm_medium%3Dapp%26utm_campaign%3Dqksmssettings";
|
String referrer = "referrer=utm_source%3Dqksms%26utm_medium%3Dapp%26utm_campaign%3Dqksmssettings";
|
||||||
new QKDialog()
|
new QKDialog()
|
||||||
.setContext(mContext)
|
.setContext(mContext)
|
||||||
.setTitle(R.string.dialog_should_i_answer_title)
|
.setTitle(R.string.dialog_should_i_answer_title)
|
||||||
|
|||||||
@@ -641,6 +641,7 @@
|
|||||||
<string name="toast_endlessjabber_not_installed">EndlessJabber is not installed, opening Google Play</string>
|
<string name="toast_endlessjabber_not_installed">EndlessJabber is not installed, opening Google Play</string>
|
||||||
<string name="toast_changelog_error">Couldn\'t load the changelog. Please try again later</string>
|
<string name="toast_changelog_error">Couldn\'t load the changelog. Please try again later</string>
|
||||||
<string name="toast_conversation_error">Couldn\'t open conversation</string>
|
<string name="toast_conversation_error">Couldn\'t open conversation</string>
|
||||||
|
<string name="toast_deleting_old_messages">Your old messages will be deleted shortly</string>
|
||||||
|
|
||||||
<!--Toast shown to thank user for donating-->
|
<!--Toast shown to thank user for donating-->
|
||||||
<string name="thanks_1">Thank you for donating! You\'re my new best friend.</string>
|
<string name="thanks_1">Thank you for donating! You\'re my new best friend.</string>
|
||||||
|
|||||||
@@ -59,7 +59,6 @@
|
|||||||
android:widgetLayout="@layout/view_switch" />
|
android:widgetLayout="@layout/view_switch" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="7"
|
android:defaultValue="7"
|
||||||
android:dependency="pref_key_delete_old_messages"
|
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="pref_key_delete_old_unread_messages"
|
android:key="pref_key_delete_old_unread_messages"
|
||||||
android:layout="@layout/list_item_preference"
|
android:layout="@layout/list_item_preference"
|
||||||
@@ -67,7 +66,6 @@
|
|||||||
android:title="@string/pref_delete_old_messages_unread" />
|
android:title="@string/pref_delete_old_messages_unread" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="7"
|
android:defaultValue="7"
|
||||||
android:dependency="pref_key_delete_old_messages"
|
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="pref_key_delete_old_read_messages"
|
android:key="pref_key_delete_old_read_messages"
|
||||||
android:layout="@layout/list_item_preference"
|
android:layout="@layout/list_item_preference"
|
||||||
|
|||||||
Reference in New Issue
Block a user