Messaging: Implement option for swipe right to delete.

Squashed commit of the following:

Author: Adnan Begovic <adnan@cyngn.com>
Date:   Thu Jan 14 17:20:43 2016 -0800
Messaging: Implement option for swipe to delete.

  No one wants to swipe to archive, that's stupid.

Change-Id: Ia8f0fc675582ef343311e60b755e284322f25102

Author: chengzhi.hou <chengzhi.hou@ck-telecom.com>
Date:   Wed Feb 24 20:01:17 2016 +0800
Messaging: Swipe right to delete conversation

Change "swipe delete" to "swipe right delete", so SwipeArchive and SwipeDelete
can exist at the same time.

Change-Id: Id66167c2e749f8ab0ee917e0138027c7404b8c90

Author: Michael Bestas <mikeioannina@cyanogenmod.org>
Date:   Tue Mar 1 02:27:16 2016 +0200
Improve swipe to delete strings

Change-Id: I180d09a6680084d9fd87c6dafd56db18ca5a580a

Author: Joey Rizzoli <joey@cyanogenmoditalia.it>
Date:   Mon Oct 17 16:32:25 2016 +0200
Messaging: show snackbar instead of toast when deleting conversation

more consistency with archive action

Change-Id: I06129850860a2a51c10ade65fb87c9f37a0c2bfa
Signed-off-by: Joey Rizzoli <joey@cyanogenmoditalia.it>

Change-Id: Ia8f0fc675582ef343311e60b755e284322f25102
This commit is contained in:
Adnan Begovic
2024-09-09 05:45:11 +03:00
committed by Michael Bestas
parent 950286f001
commit 086bb5c3f5
12 changed files with 152 additions and 9 deletions
@@ -114,7 +114,6 @@ public class BugleActionToasts {
}
public static void onConversationDeleted() {
showToast(R.string.conversation_deleted);
}
private static void showToast(final int messageResId) {
@@ -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 androidx.core.app.NavUtils;
@@ -97,6 +98,8 @@ public class ApplicationSettingsActivity extends BugleActionBarActivity {
private String mSmsEnabledPrefKey;
private Preference mSmsEnabledPreference;
private boolean mIsSmsPreferenceClicked;
private String mSwipeRightToDeleteConversationkey;
private SwitchPreference mSwipeRightToDeleteConversationPreference;
public ApplicationSettingsFragment() {
// Required empty constructor
@@ -121,6 +124,10 @@ public class ApplicationSettingsActivity extends BugleActionBarActivity {
mSmsDisabledPreference = findPreference(mSmsDisabledPrefKey);
mSmsEnabledPrefKey = getString(R.string.sms_enabled_pref_key);
mSmsEnabledPreference = findPreference(mSmsEnabledPrefKey);
mSwipeRightToDeleteConversationkey = getString(
R.string.swipe_right_deletes_conversation_key);
mSwipeRightToDeleteConversationPreference =
(SwitchPreference) findPreference(mSwipeRightToDeleteConversationkey);
mIsSmsPreferenceClicked = false;
final SharedPreferences prefs = getPreferenceScreen().getSharedPreferences();
@@ -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 org.lineageos.messaging.util.PrefsUtils;
import java.util.List;
@@ -75,6 +76,8 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
private static String sPlusOneString;
private static String sPlusNString;
private static final int SWIPE_DIRECTION_RIGHT = 2;
public interface HostInterface {
boolean isConversationSelected(final String conversationId);
void onConversationClicked(final ConversationListItemData conversationListItemData,
@@ -502,6 +505,18 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
final int notificationBellVisiblity = mData.getNotificationEnabled() ? GONE : VISIBLE;
mNotificationBellView.setVisibility(notificationBellVisiblity);
if (PrefsUtils.isSwipeRightToDeleteEnabled()) {
mCrossSwipeArchiveLeftImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.ic_delete_small_dark));
mCrossSwipeArchiveRightImageView.setImageDrawable(getResources()
.getDrawable(R.drawable.ic_archive_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() {
@@ -535,10 +550,16 @@ public class ConversationListItemView extends FrameLayout implements OnClickList
}
}
public void onSwipeComplete() {
public void onSwipeComplete(int swipeDirection) {
final String conversationId = mData.getConversationId();
if (PrefsUtils.isSwipeRightToDeleteEnabled()
&& swipeDirection == ConversationListSwipeHelper.SWIPE_DIRECTION_RIGHT) {
mData.deleteConversation();
UiUtils.showSnackBar(getContext(), getRootView(),
getResources().getString(R.string.conversation_deleted));
return;
}
UpdateConversationArchiveStatusAction.archiveConversation(conversationId);
final Runnable undoRunnable = new Runnable() {
@Override
public void run() {
@@ -44,9 +44,9 @@ public class ConversationListSwipeHelper implements OnItemTouchListener {
private static final float PERCENTAGE_OF_WIDTH_TO_DISMISS = 0.4f;
private static final float FLING_PERCENTAGE_OF_WIDTH_TO_DISMISS = 0.05f;
private static final int SWIPE_DIRECTION_NONE = 0;
private static final int SWIPE_DIRECTION_LEFT = 1;
private static final int SWIPE_DIRECTION_RIGHT = 2;
public static final int SWIPE_DIRECTION_NONE = 0;
public static final int SWIPE_DIRECTION_LEFT = 1;
public static final int SWIPE_DIRECTION_RIGHT = 2;
private final RecyclerView mRecyclerView;
private final long mDefaultRestoreAnimationDuration;
@@ -269,7 +269,7 @@ public class ConversationListSwipeHelper implements OnItemTouchListener {
private void onSwipeGestureEnd(final ConversationListItemView itemView,
final int swipeDirection) {
if (swipeDirection == SWIPE_DIRECTION_RIGHT || swipeDirection == SWIPE_DIRECTION_LEFT) {
itemView.onSwipeComplete();
itemView.onSwipeComplete(swipeDirection);
}
// Balances out onSwipeGestureStart.
@@ -132,6 +132,16 @@ public class UiUtils {
null /* placement */);
}
public static void showSnackBar(final Context context, @NonNull final View parentView,
final String message) {
Assert.notNull(context);
Assert.isTrue(!TextUtils.isEmpty(message));
SnackBarManager.get()
.newBuilder(parentView)
.setText(message)
.show();
}
public static void showSnackBarWithCustomAction(final Context context,
@NonNull final View parentView,
@NonNull final String message,
@@ -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 org.lineageos.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 isSwipeRightToDeleteEnabled() {
final BuglePrefs prefs = BuglePrefs.getApplicationPrefs();
final Context context = Factory.get().getApplicationContext();
final String prefKey = context.getString(R.string.swipe_right_deletes_conversation_key);
final boolean defaultValue = context.getResources().getBoolean(
R.bool.swipe_right_deletes_conversation_default);
return prefs.getBoolean(prefKey, defaultValue);
}
}