From 5f2f24116d645c5c50e0ebf142398f1f048e17ec Mon Sep 17 00:00:00 2001 From: "daniel.boehrs" Date: Wed, 10 Oct 2018 14:40:44 +0200 Subject: [PATCH 1/6] ask before deleting contacts #82 --- res/values/strings.xml | 2 + .../ContactSelectionListFragment.java | 41 +++++++++++-------- .../thoughtcrime/securesms/util/Dialogs.java | 11 +++++ 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 6bfc91b1a..3f539664c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -750,6 +750,8 @@ Delta Chat requires the Contacts permission in order to display your contacts, but it has been permanently denied. Please continue to the app settings menu, select \"Permissions\", and enable \"Contacts\". Error retrieving contacts, check your network connection Error deleting contacts, some contacts couldn\'t get deleted. Please delete existing conversations before. + Delete contacts? + This will permanently delete the selected contacts. Only contacts without ongoing conversations will be deleted. If the contact permission is granted, local phone contacts will be automatically added again on reopening. No blocked contacts diff --git a/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java b/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java index baf87813d..beef4a047 100644 --- a/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java +++ b/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java @@ -53,6 +53,7 @@ import org.thoughtcrime.securesms.contacts.ContactSelectionListAdapter; import org.thoughtcrime.securesms.contacts.ContactSelectionListItem; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.permissions.Permissions; +import org.thoughtcrime.securesms.util.Dialogs; import org.thoughtcrime.securesms.util.StickyHeaderDecoration; import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.ViewUtil; @@ -161,6 +162,10 @@ public class ContactSelectionListFragment extends Fragment public void onDestroyActionMode(ActionMode actionMode) { ContactSelectionListFragment.this.actionMode = null; getContactSelectionListAdapter().resetActionModeSelection(); + ContactSelectionActivity activity = (ContactSelectionActivity) getActivity(); + if (activity != null) { + activity.getToolbar().setBackgroundColor(getResources().getColor(R.color.textsecure_primary)); + } } }; @@ -176,23 +181,25 @@ public class ContactSelectionListFragment extends Fragment } private void handleDeleteSelected() { - ContactSelectionListAdapter adapter = getContactSelectionListAdapter(); - final SparseIntArray actionModeSelection = adapter.getActionModeSelection().clone(); - new Thread(() -> { - boolean failed = false; - for (int index = 0; index < actionModeSelection.size(); index++) { - int contactId = actionModeSelection.valueAt(index); - boolean currentFailed = !dcContext.deleteContact(contactId); - failed = currentFailed || failed; - } - if (failed) { - Util.runOnMain(()-> { - Toast.makeText(getActivity(), R.string.ContactSelectionListFragment_error_deleting_contacts_check_existing_conversations, Toast.LENGTH_LONG).show(); - }); - } - }).start(); - adapter.resetActionModeSelection(); - actionMode.finish(); + Dialogs.showResponseDialog(getActivity(), getString(R.string.ContactSelectionListFragment_contact_delete_confirmation_title), getString(R.string.ContactSelectionListFragment_contact_delete_confirmation_message), (dialogInterface, i) -> { + ContactSelectionListAdapter adapter = getContactSelectionListAdapter(); + final SparseIntArray actionModeSelection = adapter.getActionModeSelection().clone(); + new Thread(() -> { + boolean failed = false; + for (int index = 0; index < actionModeSelection.size(); index++) { + int contactId = actionModeSelection.valueAt(index); + boolean currentFailed = !dcContext.deleteContact(contactId); + failed = currentFailed || failed; + } + if (failed) { + Util.runOnMain(()-> { + Toast.makeText(getActivity(), R.string.ContactSelectionListFragment_error_deleting_contacts_check_existing_conversations, Toast.LENGTH_LONG).show(); + }); + } + }).start(); + adapter.resetActionModeSelection(); + actionMode.finish(); + }); } private ContactSelectionListAdapter getContactSelectionListAdapter() { diff --git a/src/org/thoughtcrime/securesms/util/Dialogs.java b/src/org/thoughtcrime/securesms/util/Dialogs.java index 0f2937457..16d4ea766 100644 --- a/src/org/thoughtcrime/securesms/util/Dialogs.java +++ b/src/org/thoughtcrime/securesms/util/Dialogs.java @@ -17,11 +17,22 @@ package org.thoughtcrime.securesms.util; import android.content.Context; +import android.content.DialogInterface; import android.support.v7.app.AlertDialog; import org.thoughtcrime.securesms.R; public class Dialogs { + public static void showResponseDialog(Context context, String title, String message, DialogInterface.OnClickListener listener) { + AlertDialog.Builder dialog = new AlertDialog.Builder(context); + dialog.setTitle(title); + dialog.setMessage(message); + dialog.setIconAttribute(R.attr.dialog_alert_icon); + dialog.setPositiveButton(android.R.string.ok, listener); + dialog.setNegativeButton(android.R.string.cancel, null); + dialog.show(); + } + public static void showAlertDialog(Context context, String title, String message) { AlertDialog.Builder dialog = new AlertDialog.Builder(context); dialog.setTitle(title); From 749ccb12282b8873d80cb0f6a34b54d8b2f93206 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 10 Oct 2018 15:23:27 +0200 Subject: [PATCH 2/6] adapt to new api --- jni/dc_wrapper.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/jni/dc_wrapper.c b/jni/dc_wrapper.c index 73abeb0f9..e7333bd87 100644 --- a/jni/dc_wrapper.c +++ b/jni/dc_wrapper.c @@ -590,15 +590,13 @@ JNIEXPORT void Java_com_b44t_messenger_DcContext_setConfig(JNIEnv *env, jobject JNIEXPORT jstring Java_com_b44t_messenger_DcContext_getConfig(JNIEnv *env, jobject obj, jstring key, jstring def/*may be NULL*/) { CHAR_REF(key); - CHAR_REF(def); - char* temp = dc_get_config(get_dc_context(env, obj), keyPtr, defPtr /*is NULL if value is NULL, CHAR_REF() handles this*/); + char* temp = dc_get_config(get_dc_context(env, obj), keyPtr); jstring ret = NULL; if (temp) { ret = JSTRING_NEW(temp); } free(temp); CHAR_UNREF(key); - CHAR_UNREF(def); return ret; /* returns NULL only if key is unset and "def" is NULL */ } From eaabc755011b5eeb65894e85c0c7ceeb406fcf8d Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 10 Oct 2018 15:23:45 +0200 Subject: [PATCH 3/6] Update messenger-backend submodule. --- jni/messenger-backend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jni/messenger-backend b/jni/messenger-backend index 987dc8003..d7055d088 160000 --- a/jni/messenger-backend +++ b/jni/messenger-backend @@ -1 +1 @@ -Subproject commit 987dc8003327593a3f77a7ae39889a83cdda8652 +Subproject commit d7055d088a99b9ef76c295221b33fe52f18e03ae From 62e03e7ce4894ddcc072d52c65102743ca986ef2 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 10 Oct 2018 15:53:02 +0200 Subject: [PATCH 4/6] tweak contact deletion, closes #83 --- res/values/strings.xml | 2 +- .../securesms/ContactSelectionListFragment.java | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 3f539664c..65aad25d8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -751,7 +751,7 @@ Error retrieving contacts, check your network connection Error deleting contacts, some contacts couldn\'t get deleted. Please delete existing conversations before. Delete contacts? - This will permanently delete the selected contacts. Only contacts without ongoing conversations will be deleted. If the contact permission is granted, local phone contacts will be automatically added again on reopening. + This will permanently delete the selected contacts.\n\nContacts with ongoing chats and contacts from the system\'s address book cannot be deleted permanently. No blocked contacts diff --git a/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java b/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java index beef4a047..33cfe57fa 100644 --- a/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java +++ b/src/org/thoughtcrime/securesms/ContactSelectionListFragment.java @@ -19,6 +19,8 @@ package org.thoughtcrime.securesms; import android.Manifest; import android.annotation.SuppressLint; +import android.content.res.TypedArray; +import android.graphics.Color; import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; @@ -27,10 +29,11 @@ import android.support.v4.app.Fragment; import android.support.v4.app.LoaderManager; import android.support.v4.content.Loader; import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.support.v7.view.ActionMode; import android.util.SparseIntArray; -import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -162,9 +165,11 @@ public class ContactSelectionListFragment extends Fragment public void onDestroyActionMode(ActionMode actionMode) { ContactSelectionListFragment.this.actionMode = null; getContactSelectionListAdapter().resetActionModeSelection(); - ContactSelectionActivity activity = (ContactSelectionActivity) getActivity(); - if (activity != null) { - activity.getToolbar().setBackgroundColor(getResources().getColor(R.color.textsecure_primary)); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + TypedArray color = getActivity().getTheme().obtainStyledAttributes(new int[] {android.R.attr.statusBarColor}); + getActivity().getWindow().setStatusBarColor(color.getColor(0, Color.BLACK)); + color.recycle(); } } }; @@ -362,7 +367,7 @@ public class ContactSelectionListFragment extends Fragment @Override public void onItemLongClick(ContactSelectionListItem view) { if (actionMode == null) { - actionMode = Objects.requireNonNull(getActivity()).startActionMode(actionModeCallback); + actionMode = ((AppCompatActivity)getActivity()).startSupportActionMode(actionModeCallback); } else { finishActionModeIfSelectionIsEmpty(); } From 02ea677a3c9d8e02ad269a4a1c695309b4a5aebe Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 10 Oct 2018 23:13:02 +0200 Subject: [PATCH 5/6] speed up encryption by disable debug, tackles https://github.com/deltachat/deltachat-core/issues/376 --- jni/Android.mk | 2 +- jni/Application.mk | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/jni/Android.mk b/jni/Android.mk index bb0712b83..6041a9d1c 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -871,7 +871,7 @@ LOCAL_STATIC_LIBRARIES := etpan sasl2 sqlite crypto libiconv # "breakpad" was placed after "crypto", NativeLoader.cpp after dc_wrapper.c LOCAL_CFLAGS := -w -Os -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno +LOCAL_CFLAGS += -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -fno-math-errno -std=c99 LOCAL_CFLAGS += -DANDROID_NDK -DDISABLE_IMPORTGL -fno-strict-aliasing -fprefetch-loop-arrays -DAVOID_TABLES -DANDROID_TILE_BASED_DECODE -DANDROID_ARMV6_IDCT -ffast-math -D__STDC_CONSTANT_MACROS LOCAL_SRC_FILES := \ diff --git a/jni/Application.mk b/jni/Application.mk index 1381bda63..605abf3db 100644 --- a/jni/Application.mk +++ b/jni/Application.mk @@ -1,5 +1,5 @@ +APP_PLATFORM := android-14 APP_ABI := armeabi armeabi-v7a x86 -APP_PLATFORM := android-9 -APP_STL := stlport_static -APP_CPPFLAGS += -fexceptions -APP_OPTIM := debug \ No newline at end of file +NDK_TOOLCHAIN_VERSION := 4.9 +APP_STL := gnustl_static + From b4c1f214a03585ce2abdab7c96a81aa059f35e23 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Thu, 11 Oct 2018 18:38:55 +0200 Subject: [PATCH 6/6] show compound messages --- src/org/thoughtcrime/securesms/ConversationItem.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ConversationItem.java b/src/org/thoughtcrime/securesms/ConversationItem.java index 12a34bb5c..80f36c623 100644 --- a/src/org/thoughtcrime/securesms/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/ConversationItem.java @@ -376,14 +376,20 @@ public class ConversationItem extends LinearLayout bodyText.setFocusable(false); bodyText.setTextSize(TypedValue.COMPLEX_UNIT_SP, TextSecurePreferences.getMessageBodyTextSize(context)); + String text = messageRecord.getText(); + if (messageRecord.isSetupMessage()) { - bodyText.setText(context.getString(R.string.autocrypt__asm_tap_body)); + bodyText.setText(context.getString(R.string.autocrypt__asm_tap_body)); + bodyText.setVisibility(View.VISIBLE); + } + else if (text.isEmpty()) { + bodyText.setVisibility(View.GONE); } else { - bodyText.setText(linkifyMessageBody(new SpannableString(messageRecord.getText()), batchSelected.isEmpty())); + bodyText.setText(linkifyMessageBody(new SpannableString(text), batchSelected.isEmpty())); + bodyText.setVisibility(View.VISIBLE); } - bodyText.setVisibility(View.VISIBLE); } private void setMediaAttributes(@NonNull DcMsg messageRecord,