From 76fd9c14f87c1e95bec36a4dc414b08f1e734c77 Mon Sep 17 00:00:00 2001 From: Adnan Begovic Date: Thu, 14 Jan 2016 17:20:43 -0800 Subject: Messaging: Implement option for swipe to delete. No one wants to swipe to archive, that's stupid. Change-Id: Ia8f0fc675582ef343311e60b755e284322f25102 --- res/layout/conversation_list_item_view.xml | 2 -- res/values/cm_constants.xml | 25 +++++++++++++ res/values/cm_strings.xml | 19 ++++++++++ res/xml-v21/preferences_application.xml | 6 ++++ res/xml-v23/preferences_application.xml | 6 ++++ res/xml/preferences_application.xml | 6 ++++ .../appsettings/ApplicationSettingsActivity.java | 6 ++++ .../conversationlist/ConversationListItemView.java | 19 +++++++++- src/com/cyanogenmod/messaging/util/PrefsUtils.java | 42 ++++++++++++++++++++++ 9 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 res/values/cm_constants.xml create mode 100644 res/values/cm_strings.xml create mode 100644 src/com/cyanogenmod/messaging/util/PrefsUtils.java diff --git a/res/layout/conversation_list_item_view.xml b/res/layout/conversation_list_item_view.xml index da1ca4e..10848ae 100644 --- a/res/layout/conversation_list_item_view.xml +++ b/res/layout/conversation_list_item_view.xml @@ -37,7 +37,6 @@ android:layout_height="wrap_content" android:gravity="center_vertical|left" android:visibility="gone" - android:src="@drawable/ic_archive_small_dark" android:importantForAccessibility="no" android:contentDescription="@null"/> diff --git a/res/values/cm_constants.xml b/res/values/cm_constants.xml new file mode 100644 index 0000000..b664dd0 --- /dev/null +++ b/res/values/cm_constants.xml @@ -0,0 +1,25 @@ + + + + + + + swipe_deletes_conversation + + + false + diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml new file mode 100644 index 0000000..7759e77 --- /dev/null +++ b/res/values/cm_strings.xml @@ -0,0 +1,19 @@ + + + + Swipe deletes conversation + diff --git a/res/xml-v21/preferences_application.xml b/res/xml-v21/preferences_application.xml index 5d8ee4c..374b1d2 100644 --- a/res/xml-v21/preferences_application.xml +++ b/res/xml-v21/preferences_application.xml @@ -66,6 +66,12 @@ android:persistent="true" android:dependency="@string/notifications_enabled_pref_key" /> + + diff --git a/res/xml-v23/preferences_application.xml b/res/xml-v23/preferences_application.xml index 8fbadc4..c6b934a 100644 --- a/res/xml-v23/preferences_application.xml +++ b/res/xml-v23/preferences_application.xml @@ -67,6 +67,12 @@ android:persistent="true" android:dependency="@string/notifications_enabled_pref_key" /> + + diff --git a/res/xml/preferences_application.xml b/res/xml/preferences_application.xml index 7a18d09..f9895d0 100644 --- a/res/xml/preferences_application.xml +++ b/res/xml/preferences_application.xml @@ -66,6 +66,12 @@ android:persistent="true" android:dependency="@string/notifications_enabled_pref_key" /> + + diff --git a/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java b/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java index 906009f..d41c0b4 100644 --- a/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java +++ b/src/com/android/messaging/ui/appsettings/ApplicationSettingsActivity.java @@ -28,6 +28,7 @@ import android.preference.Preference; import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import android.preference.RingtonePreference; +import android.preference.SwitchPreference; import android.preference.TwoStatePreference; import android.provider.Settings; import android.support.v4.app.NavUtils; @@ -97,6 +98,8 @@ public class ApplicationSettingsActivity extends BugleActionBarActivity { private String mSmsEnabledPrefKey; private Preference mSmsEnabledPreference; private boolean mIsSmsPreferenceClicked; + private String mSwipeToDeleteConversationkey; + private SwitchPreference mSwipeToDeleteConversationPreference; public ApplicationSettingsFragment() { // Required empty constructor @@ -121,6 +124,9 @@ public class ApplicationSettingsActivity extends BugleActionBarActivity { mSmsDisabledPreference = findPreference(mSmsDisabledPrefKey); mSmsEnabledPrefKey = getString(R.string.sms_enabled_pref_key); mSmsEnabledPreference = findPreference(mSmsEnabledPrefKey); + mSwipeToDeleteConversationkey = getString(R.string.swipe_deletes_conversation_key); + mSwipeToDeleteConversationPreference = + (SwitchPreference) findPreference(mSwipeToDeleteConversationkey); mIsSmsPreferenceClicked = false; final SharedPreferences prefs = getPreferenceScreen().getSharedPreferences(); diff --git a/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java b/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java index 9b8c5ff..9ce9e87 100644 --- a/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java +++ b/src/com/android/messaging/ui/conversationlist/ConversationListItemView.java @@ -58,6 +58,7 @@ import com.android.messaging.util.PhoneUtils; import com.android.messaging.util.Typefaces; import com.android.messaging.util.UiUtils; import com.android.messaging.util.UriUtil; +import com.cyanogenmod.messaging.util.PrefsUtils; import java.util.List; @@ -495,6 +496,18 @@ public class ConversationListItemView extends FrameLayout implements OnClickList final int notificationBellVisiblity = mData.getNotificationEnabled() ? GONE : VISIBLE; mNotificationBellView.setVisibility(notificationBellVisiblity); + + if (PrefsUtils.isSwipeToDeleteEnabled()) { + mCrossSwipeArchiveLeftImageView.setImageDrawable(getResources() + .getDrawable(R.drawable.ic_delete_small_dark)); + mCrossSwipeArchiveRightImageView.setImageDrawable(getResources() + .getDrawable(R.drawable.ic_delete_small_dark)); + } else { + mCrossSwipeArchiveLeftImageView.setImageDrawable(getResources() + .getDrawable(R.drawable.ic_archive_small_dark)); + mCrossSwipeArchiveRightImageView.setImageDrawable(getResources() + .getDrawable(R.drawable.ic_archive_small_dark)); + } } public boolean isSwipeAnimatable() { @@ -530,8 +543,12 @@ public class ConversationListItemView extends FrameLayout implements OnClickList public void onSwipeComplete() { final String conversationId = mData.getConversationId(); + if (PrefsUtils.isSwipeToDeleteEnabled()) { + mData.deleteConversation(); + UiUtils.showToastAtBottom(R.string.conversation_deleted); + return; + } UpdateConversationArchiveStatusAction.archiveConversation(conversationId); - final Runnable undoRunnable = new Runnable() { @Override public void run() { diff --git a/src/com/cyanogenmod/messaging/util/PrefsUtils.java b/src/com/cyanogenmod/messaging/util/PrefsUtils.java new file mode 100644 index 0000000..9df56b0 --- /dev/null +++ b/src/com/cyanogenmod/messaging/util/PrefsUtils.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016 The CyanogenMod Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.cyanogenmod.messaging.util; + +import android.content.Context; +import com.android.messaging.Factory; +import com.android.messaging.R; +import com.android.messaging.util.BuglePrefs; + +public class PrefsUtils { + private PrefsUtils() { + //Don't instantiate + } + + /** + * Returns whether or not swipe to dismiss in the ConversationListFragment deletes + * the conversation rather than archiving it. + * @return hopefully true + */ + public static boolean isSwipeToDeleteEnabled() { + final BuglePrefs prefs = BuglePrefs.getApplicationPrefs(); + final Context context = Factory.get().getApplicationContext(); + final String prefKey = context.getString(R.string.swipe_deletes_conversation_key); + final boolean defaultValue = context.getResources().getBoolean( + R.bool.swipe_deletes_conversation_default); + return prefs.getBoolean(prefKey, defaultValue); + } +} -- cgit v1.2.3