diff --git a/QKSMS/src/main/AndroidManifest.xml b/QKSMS/src/main/AndroidManifest.xml index ea9b0041..c1349f5e 100644 --- a/QKSMS/src/main/AndroidManifest.xml +++ b/QKSMS/src/main/AndroidManifest.xml @@ -486,6 +486,7 @@ + { - mStatusTintEnabled = getBoolean(QKPreference.TINTED_STATUS) && + mStatusTintEnabled = QKPreferences.getBoolean(QKPreference.TINTED_STATUS) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; }); LiveViewManager.registerView(QKPreference.TINTED_NAV, this, key -> { - mNavigationTintEnabled = getBoolean(QKPreference.TINTED_NAV) && + mNavigationTintEnabled = QKPreferences.getBoolean(QKPreference.TINTED_NAV) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; }); } @@ -296,28 +296,4 @@ public abstract class QKActivity extends AppCompatActivity { public RequestQueue getRequestQueue() { return ((QKSMSApp) getApplication()).getRequestQueue(); } - - public boolean getBoolean(QKPreference preference) { - return getPrefs().getBoolean(preference.getKey(), (boolean) preference.getDefaultValue()); - } - - public void setBoolean(QKPreference preference, boolean newValue) { - getPrefs().edit().putBoolean(preference.getKey(), newValue).apply(); - } - - public int getInt(QKPreference preference) { - return getPrefs().getInt(preference.getKey(), (int) preference.getDefaultValue()); - } - - public void setInt(QKPreference preference, int newValue) { - getPrefs().edit().putInt(preference.getKey(), newValue).apply(); - } - - public String getString(QKPreference preference) { - return getPrefs().getString(preference.getKey(), (String) preference.getDefaultValue()); - } - - public void setString(QKPreference preference, String newValue) { - getPrefs().edit().putString(preference.getKey(), newValue).apply(); - } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java index 5875b102..9f5897a1 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/conversationlist/ConversationListAdapter.java @@ -8,6 +8,7 @@ import com.moez.QKSMS.R; import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.FontManager; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.QKPreferences; import com.moez.QKSMS.common.emoji.EmojiRegistry; import com.moez.QKSMS.common.utils.DateFormatter; import com.moez.QKSMS.data.Contact; @@ -106,7 +107,7 @@ public class ConversationListAdapter extends RecyclerCursorAdapter { - holder.mAvatarView.setVisibility(mContext.getBoolean(QKPreference.HIDE_AVATAR_CONVERSATIONS) ? View.GONE : View.VISIBLE); + holder.mAvatarView.setVisibility(QKPreferences.getBoolean(QKPreference.HIDE_AVATAR_CONVERSATIONS) ? View.GONE : View.VISIBLE); }); // Date diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java index e01db50c..4a0cfdf3 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/messagelist/MessageListFragment.java @@ -46,6 +46,7 @@ import com.moez.QKSMS.common.CIELChEvaluator; import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.QKPreferences; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; import com.moez.QKSMS.common.vcard.ContactOperations; @@ -188,7 +189,7 @@ public class MessageListFragment extends QKFragment implements ActivityLauncher, mSensorManager = (SensorManager) mContext.getSystemService(Context.SENSOR_SERVICE); mProxSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY); - if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { + if (QKPreferences.getBoolean(QKPreference.PROXIMITY_SENSOR)) { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } @@ -247,7 +248,7 @@ public class MessageListFragment extends QKFragment implements ActivityLauncher, public void onResume() { super.onResume(); - if (mContext.getBoolean(QKPreference.PROXIMITY_SENSOR)) { + if (QKPreferences.getBoolean(QKPreference.PROXIMITY_SENSOR)) { mSensorManager.registerListener(this, mProxSensor, SensorManager.SENSOR_DELAY_NORMAL); } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java index 44190fa3..06238cfd 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/settings/SettingsFragment.java @@ -35,11 +35,13 @@ import com.moez.QKSMS.common.DialogHelper; import com.moez.QKSMS.common.DonationManager; import com.moez.QKSMS.common.ListviewHelper; import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.common.QKPreferences; import com.moez.QKSMS.common.utils.DateFormatter; 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; @@ -105,6 +107,9 @@ 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"; public static final String BLOCKED_ENABLED = "pref_key_blocked_enabled"; public static final String BLOCKED_SENDERS = "pref_key_blocked_senders"; @@ -283,6 +288,16 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O font_weight.setSummary(mFontWeights[i == 2 ? 0 : 1]); } + EditTextPreference deleteUnread = (EditTextPreference) findPreference(DELETE_UNREAD_MESSAGES); + if (deleteUnread != null) { + deleteUnread.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD))); + } + + EditTextPreference deleteRead = (EditTextPreference) findPreference(DELETE_READ_MESSAGES); + if (deleteRead != null) { + deleteRead.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_READ))); + } + Preference day_start = findPreference(DAY_START); if (day_start != null) { day_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(DAY_START, "6:00"))); @@ -442,6 +457,33 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O case NIGHT_START: updateAlarmManager(mContext, true); break; + + case DELETE_OLD_MESSAGES: + if ((Boolean) newValue) { + new QKDialog() + .setContext(mContext) + .setTitle(R.string.pref_delete_old_messages) + .setMessage(R.string.dialog_delete_old_messages) + .setPositiveButton(R.string.yes, v -> { + QKPreferences.setBoolean(QKPreference.AUTO_DELETE, true); + ((CheckBoxPreference) preference).setChecked(true); + DeleteOldMessagesService.setupAutoDeleteAlarm(mContext); + mContext.makeToast(R.string.toast_deleting_old_messages); + }) + .setNegativeButton(R.string.cancel, null) + .show(); + return false; + } + 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 { @@ -546,7 +588,7 @@ public class SettingsFragment extends PreferenceFragment implements Preference.O case SHOULD_I_ANSWER: final String packageName = "org.mistergroup.muzutozvednout"; 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() .setContext(mContext) .setTitle(R.string.dialog_should_i_answer_title) diff --git a/QKSMS/src/main/res/values/strings.xml b/QKSMS/src/main/res/values/strings.xml index 599cd394..38f7eb15 100644 --- a/QKSMS/src/main/res/values/strings.xml +++ b/QKSMS/src/main/res/values/strings.xml @@ -170,6 +170,12 @@ Show a short toast to indicate a message being delivered Vibrate Vibrate on message delivery + Delete old messages + Automatically delete messages once they\'re old enough + Unread messages + Automatically delete unread messages after %s days + Read messages + Automatically delete read messages after %s days Yappy integration Enable full support for Yappy Blocked conversations @@ -591,6 +597,7 @@ Recipients (%s) Should I Answer? not installed Would you like to download the app from Google Play now? + Are you sure you want to automatically delete old messages? Choose audio @@ -636,6 +643,7 @@ EndlessJabber is not installed, opening Google Play Couldn\'t load the changelog. Please try again later Couldn\'t open conversation + Your old messages will be deleted shortly Thank you for donating! You\'re my new best friend. diff --git a/QKSMS/src/main/res/xml/settings.xml b/QKSMS/src/main/res/xml/settings.xml index 8f1c50b0..1ab095da 100644 --- a/QKSMS/src/main/res/xml/settings.xml +++ b/QKSMS/src/main/res/xml/settings.xml @@ -73,6 +73,15 @@ + + + diff --git a/QKSMS/src/main/res/xml/settings_general.xml b/QKSMS/src/main/res/xml/settings_general.xml index c968353f..e470f93b 100644 --- a/QKSMS/src/main/res/xml/settings_general.xml +++ b/QKSMS/src/main/res/xml/settings_general.xml @@ -47,6 +47,31 @@ android:title="@string/pref_delivery_vibrate" android:widgetLayout="@layout/view_switch" /> + + + + + @@ -147,12 +172,12 @@ android:title="@string/pref_key_timestamp_delay" /> + android:widgetLayout="@layout/view_switch" />