Loading QKSMS/src/main/java/com/moez/QKSMS/service/DeleteOldMessagesService.java +11 −22 Original line number Diff line number Diff line Loading @@ -44,42 +44,29 @@ public class DeleteOldMessagesService extends IntentService { private void deleteOldUnreadMessages(Context context) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD))); Cursor cursor = null; 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(); } } int count = deleteOldMessages(context, SmsHelper.UNREAD_SELECTION, calendar.getTimeInMillis()); Log.i(TAG, "Deleted unread messages: " + count); } private void deleteOldReadMessages(Context context) { Calendar calendar = Calendar.getInstance(); 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; String selection = SmsHelper.COLUMN_DATE + "<=?"; selection += " AND " + 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())}, new String[]{String.valueOf(before)}, null); return cursor.getCount(); } catch (Exception e) { e.printStackTrace(); } finally { Loading @@ -87,6 +74,8 @@ public class DeleteOldMessagesService extends IntentService { cursor.close(); } } return 0; } public static void setupAutoDeleteAlarm(Context context) { Loading QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java +1 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ public class SmsHelper { public static final String COLUMN_BODY = "body"; 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 UNSEEN_SELECTION = COLUMN_SEEN + " = " + UNREAD; public static final String FAILED_SELECTION = COLUMN_TYPE + " = " + Message.FAILED; Loading QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +13 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.PackageUtils; import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.receiver.NightModeAutoReceiver; import com.moez.QKSMS.service.DeleteOldMessagesService; import com.moez.QKSMS.transaction.EndlessJabber; import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; Loading Loading @@ -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_TOAST = "pref_key_delivery_toast"; 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_READ_MESSAGES = "pref_key_delete_old_read_messages"; public static final String YAPPY = "pref_key_endlessjabber"; Loading Loading @@ -453,12 +455,22 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O case NIGHT_START: updateAlarmManager(mContext, true); break; case DELETE_OLD_MESSAGES: DeleteOldMessagesService.setupAutoDeleteAlarm(mContext); if ((Boolean) newValue) { mContext.makeToast(R.string.toast_deleting_old_messages); } break; case DELETE_UNREAD_MESSAGES: preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, newValue)); break; case DELETE_READ_MESSAGES: preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, newValue)); break; case YAPPY: if ((Boolean) newValue) { try { Loading QKSMS/src/main/res/values/strings.xml +1 −0 Original line number Diff line number Diff line Loading @@ -641,6 +641,7 @@ <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_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--> <string name="thanks_1">Thank you for donating! You\'re my new best friend.</string> Loading QKSMS/src/main/res/xml/settings_general.xml +0 −2 Original line number Diff line number Diff line Loading @@ -59,7 +59,6 @@ android:widgetLayout="@layout/view_switch" /> <EditTextPreference android:defaultValue="7" android:dependency="pref_key_delete_old_messages" android:inputType="number" android:key="pref_key_delete_old_unread_messages" android:layout="@layout/list_item_preference" Loading @@ -67,7 +66,6 @@ android:title="@string/pref_delete_old_messages_unread" /> <EditTextPreference android:defaultValue="7" android:dependency="pref_key_delete_old_messages" android:inputType="number" android:key="pref_key_delete_old_read_messages" android:layout="@layout/list_item_preference" Loading Loading
QKSMS/src/main/java/com/moez/QKSMS/service/DeleteOldMessagesService.java +11 −22 Original line number Diff line number Diff line Loading @@ -44,42 +44,29 @@ public class DeleteOldMessagesService extends IntentService { private void deleteOldUnreadMessages(Context context) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_YEAR, -Integer.parseInt(QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD))); Cursor cursor = null; 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(); } } int count = deleteOldMessages(context, SmsHelper.UNREAD_SELECTION, calendar.getTimeInMillis()); Log.i(TAG, "Deleted unread messages: " + count); } private void deleteOldReadMessages(Context context) { Calendar calendar = Calendar.getInstance(); 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; String selection = SmsHelper.COLUMN_DATE + "<=?"; selection += " AND " + 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())}, new String[]{String.valueOf(before)}, null); return cursor.getCount(); } catch (Exception e) { e.printStackTrace(); } finally { Loading @@ -87,6 +74,8 @@ public class DeleteOldMessagesService extends IntentService { cursor.close(); } } return 0; } public static void setupAutoDeleteAlarm(Context context) { Loading
QKSMS/src/main/java/com/moez/QKSMS/transaction/SmsHelper.java +1 −0 Original line number Diff line number Diff line Loading @@ -86,6 +86,7 @@ public class SmsHelper { public static final String COLUMN_BODY = "body"; 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 UNSEEN_SELECTION = COLUMN_SEEN + " = " + UNREAD; public static final String FAILED_SELECTION = COLUMN_TYPE + " = " + Message.FAILED; Loading
QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +13 −1 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.PackageUtils; import com.moez.QKSMS.enums.QKPreference; import com.moez.QKSMS.receiver.NightModeAutoReceiver; import com.moez.QKSMS.service.DeleteOldMessagesService; import com.moez.QKSMS.transaction.EndlessJabber; import com.moez.QKSMS.transaction.NotificationManager; import com.moez.QKSMS.transaction.SmsHelper; Loading Loading @@ -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_TOAST = "pref_key_delivery_toast"; 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_READ_MESSAGES = "pref_key_delete_old_read_messages"; public static final String YAPPY = "pref_key_endlessjabber"; Loading Loading @@ -453,12 +455,22 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O case NIGHT_START: updateAlarmManager(mContext, true); break; case DELETE_OLD_MESSAGES: DeleteOldMessagesService.setupAutoDeleteAlarm(mContext); if ((Boolean) newValue) { mContext.makeToast(R.string.toast_deleting_old_messages); } break; case DELETE_UNREAD_MESSAGES: preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, newValue)); break; case DELETE_READ_MESSAGES: preference.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, newValue)); break; case YAPPY: if ((Boolean) newValue) { try { Loading
QKSMS/src/main/res/values/strings.xml +1 −0 Original line number Diff line number Diff line Loading @@ -641,6 +641,7 @@ <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_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--> <string name="thanks_1">Thank you for donating! You\'re my new best friend.</string> Loading
QKSMS/src/main/res/xml/settings_general.xml +0 −2 Original line number Diff line number Diff line Loading @@ -59,7 +59,6 @@ android:widgetLayout="@layout/view_switch" /> <EditTextPreference android:defaultValue="7" android:dependency="pref_key_delete_old_messages" android:inputType="number" android:key="pref_key_delete_old_unread_messages" android:layout="@layout/list_item_preference" Loading @@ -67,7 +66,6 @@ android:title="@string/pref_delete_old_messages_unread" /> <EditTextPreference android:defaultValue="7" android:dependency="pref_key_delete_old_messages" android:inputType="number" android:key="pref_key_delete_old_read_messages" android:layout="@layout/list_item_preference" Loading