From 1b0e9f2f0d4ea74c1b79be9ee728fbf94d860f60 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 23 Jun 2018 09:29:29 +0200 Subject: [PATCH] open/close soft keyboard in quick edit --- .../ui/ConferenceDetailsActivity.java | 48 ++++++++++++++---- .../conversations/ui/ShareWithActivity.java | 2 +- .../ui/StartConversationActivity.java | 2 +- .../siacs/conversations/ui/XmppActivity.java | 20 +++++--- .../ui/adapter/ConversationAdapter.java | 12 ++--- .../ui/util/SoftKeyboardUtils.java | 11 +++- .../drawable-hdpi/ic_cancel_black_24dp.png | Bin 0 -> 397 bytes .../drawable-mdpi/ic_cancel_black_24dp.png | Bin 0 -> 291 bytes .../drawable-xhdpi/ic_cancel_black_24dp.png | Bin 0 -> 517 bytes .../drawable-xxhdpi/ic_cancel_black_24dp.png | Bin 0 -> 721 bytes .../drawable-xxxhdpi/ic_cancel_black_24dp.png | Bin 0 -> 963 bytes src/main/res/layout/activity_edit_account.xml | 2 +- src/main/res/values/defaults.xml | 1 - src/main/res/values/strings.xml | 2 - src/main/res/values/themes.xml | 2 +- src/main/res/xml/preferences.xml | 5 -- 16 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 src/main/res/drawable-hdpi/ic_cancel_black_24dp.png create mode 100644 src/main/res/drawable-mdpi/ic_cancel_black_24dp.png create mode 100644 src/main/res/drawable-xhdpi/ic_cancel_black_24dp.png create mode 100644 src/main/res/drawable-xxhdpi/ic_cancel_black_24dp.png create mode 100644 src/main/res/drawable-xxxhdpi/ic_cancel_black_24dp.png diff --git a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java index b650e46a0..29b5cd529 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ConferenceDetailsActivity.java @@ -13,7 +13,9 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.v7.app.AlertDialog; import android.support.v7.widget.Toolbar; +import android.text.Editable; import android.text.SpannableStringBuilder; +import android.text.TextWatcher; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -48,13 +50,14 @@ import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdat import eu.siacs.conversations.services.XmppConnectionService.OnMucRosterUpdate; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MyLinkify; +import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.utils.XmppUri; import rocks.xmpp.addr.Jid; import static eu.siacs.conversations.entities.Bookmark.printableValue; -public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed { +public class ConferenceDetailsActivity extends XmppActivity implements OnConversationUpdate, OnMucRosterUpdate, XmppConnectionService.OnAffiliationChanged, XmppConnectionService.OnRoleChanged, XmppConnectionService.OnConfigurationPushed, TextWatcher { public static final String ACTION_VIEW_MUC = "view_muc"; private static final float INACTIVE_ALPHA = 0.4684f; //compromise between dark and light theme @@ -260,6 +263,8 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers startActivity(intent); }); this.binding.editMucNameButton.setOnClickListener(this::onMucEditButtonClicked); + this.binding.mucEditTitle.addTextChangedListener(this); + this.binding.mucEditSubject.addTextChangedListener(this); } @Override @@ -310,7 +315,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers final MucOptions mucOptions = mConversation.getMucOptions(); this.binding.mucEditor.setVisibility(View.VISIBLE); this.binding.mucDisplay.setVisibility(View.GONE); - this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_save, R.drawable.ic_save_black_24dp)); + this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_cancel, R.drawable.ic_cancel_black_24dp)); final String name = mucOptions.getName(); this.binding.mucEditTitle.setText(""); final boolean owner = mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER); @@ -332,11 +337,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers if (!owner) { this.binding.mucEditSubject.requestFocus(); } - this.binding.yourPhoto.setVisibility(View.GONE); } else { String subject = this.binding.mucEditSubject.isEnabled() ? this.binding.mucEditSubject.getEditableText().toString().trim() : null; String name = this.binding.mucEditTitle.isEnabled() ? this.binding.mucEditTitle.getEditableText().toString().trim() : null; onMucInfoUpdated(subject, name); + SoftKeyboardUtils.hideSoftKeyboard(this); hideEditor(); } } @@ -345,21 +350,18 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers this.binding.mucEditor.setVisibility(View.GONE); this.binding.mucDisplay.setVisibility(View.VISIBLE); this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_edit_body, R.drawable.ic_edit_black_24dp)); - this.binding.yourPhoto.setVisibility(View.VISIBLE); } private void onMucInfoUpdated(String subject, String name) { final MucOptions mucOptions = mConversation.getMucOptions(); - if (mucOptions.canChangeSubject() && !blankOnNull(mucOptions.getSubject()).equals(subject)) { - Log.d(Config.LOGTAG,"subject changed"); + if (mucOptions.canChangeSubject() && changed(mucOptions.getSubject(), subject)) { xmppConnectionService.pushSubjectToConference(mConversation, subject); } - if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && !blankOnNull(mucOptions.getName()).equals(name)) { - Log.d(Config.LOGTAG,"name changed"); + if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && changed(mucOptions.getName(), name)) { Bundle options = new Bundle(); options.putString("muc#roomconfig_persistentroom", "1"); options.putString("muc#roomconfig_roomname", name); - xmppConnectionService.pushConferenceConfiguration(mConversation, options, null); + xmppConnectionService.pushConferenceConfiguration(mConversation, options, this); } } @@ -367,6 +369,10 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers return input == null ? "" : input; } + private static boolean changed(String one, String two) { + return !blankOnNull(one).equals(blankOnNull(two)); + } + @Override protected String getShareableUri(boolean http) { if (mConversation != null) { @@ -793,6 +799,30 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers } } + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + final MucOptions mucOptions = mConversation.getMucOptions(); + if (this.binding.mucEditor.getVisibility() == View.VISIBLE) { + boolean subjectChanged = changed(binding.mucEditSubject.getEditableText().toString(), mucOptions.getSubject()); + boolean nameChanged = changed(binding.mucEditTitle.getEditableText().toString(), mucOptions.getName()); + if (subjectChanged || nameChanged) { + this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_save, R.drawable.ic_save_black_24dp)); + } else { + this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_cancel, R.drawable.ic_cancel_black_24dp)); + } + } + } + static class AsyncDrawable extends BitmapDrawable { private final WeakReference bitmapWorkerTaskReference; diff --git a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java index abe490dae..fc23aad5f 100644 --- a/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ShareWithActivity.java @@ -199,7 +199,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer if (intent == null) { return; } - this.mReturnToPrevious = getPreferences().getBoolean("return_to_previous", getResources().getBoolean(R.bool.return_to_previous)); + this.mReturnToPrevious = getBooleanPreference("return_to_previous", R.bool.return_to_previous); final String type = intent.getType(); final String action = intent.getAction(); Log.d(Config.LOGTAG, "action: "+action+ ", type:"+type); diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index f42ea06b4..efd5259ec 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -984,7 +984,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne jid.setError(getString(R.string.bookmark_already_exists)); } else { final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); - bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))); + bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin)); String nick = conferenceJid.getResource(); if (nick != null && !nick.isEmpty()) { bookmark.setNick(nick); diff --git a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java index 65fcceee7..a9b066216 100644 --- a/src/main/java/eu/siacs/conversations/ui/XmppActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/XmppActivity.java @@ -72,6 +72,7 @@ import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.PresenceSelector; +import eu.siacs.conversations.ui.util.SoftKeyboardUtils; import eu.siacs.conversations.utils.ExceptionHelper; import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; @@ -95,7 +96,6 @@ public abstract class XmppActivity extends ActionBarActivity { private boolean isCameraFeatureAvailable = false; - protected boolean mUseSubject = true; protected int mTheme; protected boolean mUsingEnterKey = false; protected Toast mToast; @@ -402,7 +402,6 @@ public abstract class XmppActivity extends ActionBarActivity { setTheme(this.mTheme); this.mUsingEnterKey = usingEnterKey(); - mUseSubject = getBooleanPreference("use_subject", R.bool.use_subject); } protected boolean isCameraFeatureAvailable() { @@ -445,7 +444,7 @@ public abstract class XmppActivity extends ActionBarActivity { } protected boolean usingEnterKey() { - return getPreferences().getBoolean("display_enter_key", getResources().getBoolean(R.bool.display_enter_key)); + return getBooleanPreference("display_enter_key", R.bool.display_enter_key); } protected SharedPreferences getPreferences() { @@ -456,10 +455,6 @@ public abstract class XmppActivity extends ActionBarActivity { return getPreferences().getBoolean(name, getResources().getBoolean(res)); } - public boolean useSubjectToIdentifyConference() { - return mUseSubject; - } - public void switchToConversation(Conversation conversation) { switchToConversation(conversation, null, false); } @@ -723,6 +718,7 @@ public abstract class XmppActivity extends ActionBarActivity { builder.setView(binding.getRoot()); builder.setNegativeButton(R.string.cancel, null); final AlertDialog dialog = builder.create(); + dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(binding.inputEditText)); dialog.show(); View.OnClickListener clickListener = v -> { String value = binding.inputEditText.getText().toString(); @@ -733,9 +729,17 @@ public abstract class XmppActivity extends ActionBarActivity { return; } } + SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText); dialog.dismiss(); }; dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener); + dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener((v -> { + SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText); + dialog.dismiss(); + })); + dialog.setOnDismissListener(dialog1 -> { + SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText); + }); } protected boolean hasStoragePermission(int requestCode) { @@ -790,7 +794,7 @@ public abstract class XmppActivity extends ActionBarActivity { } protected boolean manuallyChangePresence() { - return getPreferences().getBoolean(SettingsActivity.MANUALLY_CHANGE_PRESENCE, getResources().getBoolean(R.bool.manually_change_presence)); + return getBooleanPreference(SettingsActivity.MANUALLY_CHANGE_PRESENCE, R.bool.manually_change_presence); } protected String getShareableUri() { diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java index 8721ed36d..1700e5fcf 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ConversationAdapter.java @@ -84,15 +84,11 @@ public class ConversationAdapter extends RecyclerView.Adapterg6K^oQ4gStOx?8jW0;tMcIA7! zATP=1H_AN{kuYOR&iP`_hA9aVUNjkV#9(`1L`+2<*<)~zjg#Am%@EEQcS8QjBW>dsJH?N#^I*PpmE)?Sq^WW+&_$aO~IH95FBAqpe8&(d*d zYrM*}0TwZt_s__V1~#M^Pun<{du3)gsq;}e^F|%YQj1ENsUst#WTlZEZ7LEobo|@q r3~1m*NQ((;GENsW)=X#-a({dSZUbA_Y}NV500000NkvXXu0mjf?tG(j literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-mdpi/ic_cancel_black_24dp.png b/src/main/res/drawable-mdpi/ic_cancel_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..f19848466978650969d74f5c68b55dc680bd56f6 GIT binary patch literal 291 zcmV+;0o?wHP)esOvhhW%7f}0O8dAi$Idp6Zk3bGc95* zB>)|%=r6!TyCveFVWI;(ebHY@+U*dLtRy_(k*=H&H!=!69;7Q=s|V^1ojt%-QuofB z91(k?C-nK+Z4oOCL(%p51nm|G$E6IvnGAm1Z+S;rK+MSxGG)MKRR6%xjGVmFP-Vv1 p$dM@{v@F?i;(E`KEel$n%s=$T3_n~l>pK7d002ovPDHLkV1kVceYF4p literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xhdpi/ic_cancel_black_24dp.png b/src/main/res/drawable-xhdpi/ic_cancel_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6253c0d47e050f8e2b95dfbc42e6d8a401e145ee GIT binary patch literal 517 zcmV+g0{Z=lP)*zT$p0@;*+&k^zhirq9$yLEza zx@#6+E^~74q6q%J-OTX&!sXl?o&_&t>~O?@F%?s$RE!yL$Tk_tY;ej?ERcIXvQ9Ls zTrkBNQd6=*1U-IZ&QugE#4EmH3#O!vlMXjnM22*Hzh3qJiZ+dW!4gu^Ko3jIdkC}2 zpX7oEmI-nppFh#%drwl7*tAIY&Bjk=2!VZQxD?~5ZLO8#=S%DtGK0w!YBE#hwAm}?a8}i=CY11oFbr~Rdi+HJhDcBa^aP^Cwk+I zAS+Z@Vt%m%VT$B}T^cBp^q*;@%`jU3gB%APhLQT$IB8Qx98S(c6g=RcoLwSV=A61w z{>T|iMDvyt?t=1Lj#(p_j4cl6Gh#wb&4dws_SvMxGvI~4d!jIk5EVl`00000NkvXX Hu0mjfY7OmW literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxhdpi/ic_cancel_black_24dp.png b/src/main/res/drawable-xxhdpi/ic_cancel_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..98c59c176f6cc8c6eb7f70520cd4be1d704a7e08 GIT binary patch literal 721 zcmV;?0xtcDP)Dtva{DoUR3-+mMMr~UjKy)ZNHG_oXd`+Xr$`|LWnf0IQ{xl|)EGi4=Ws4S z>_wPhv-ehbPi?VYSKjOuQsnvf@`JsyKV;ajVFTL)B@Q{E%_GmGq&)LTn_~`GWr997 z#~w{mL|MumyW|L7kveaP=iazviC}%9jTqLVNaoFRhSIYKg8 zm53gjp@C$$Yo@SAp8t@H_nREXW^5b}(v|~Mv7DtNB;cyu|Ij7yD)`4dFTp__ z3V3&h^kF~zpIM^pf=yz?V=){2LX<7zRa@mmz&f!9rvyY?Azl1huWTc8OpqGjo5>upST^=nutnT zQ%Dw$&_L-EDPkbmIYPoX&PoVkCaD}{D>yquOr#RAnIr7u>;zG!os^Q9Bh=J;w3TG$ z2rZmFB1V#(BRt^j88MRV9N`IPDPknqIYKgUpnYH9uS@NUa<*DPatyJ0r(Vx4?y}2IX`R!+t76~&*|3Ob zr$`_69q$Tsf^+_m$3H5;L0fcLH7MtAx-Q~680Q~GFf`4-K{)qJVk{Scbk8jInC2$q zi#17)MN~69$|Gb_g-!q~z|S7<%6T$xnWhQTV3A;b=7Lvm$}8tA5WE~aG)PoR z!Y$j((#OVGVV@c;9(W=l;fV)Y)YxZ*F$T0@!-oA2HKlI81oMTp00000NkvXXu0mjf DJqt_W literal 0 HcmV?d00001 diff --git a/src/main/res/drawable-xxxhdpi/ic_cancel_black_24dp.png b/src/main/res/drawable-xxxhdpi/ic_cancel_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..36116eda0b9e56e979d18bfb83b0f4b8e7e68fa0 GIT binary patch literal 963 zcmV;!13dhRP)D0%lrqq`B~L?-(HYd^qDODKg>dJ#xrU!atdZYkU6D6X-V4N9T(dKc;2 zT}+|3LOLWhxRyzD)5H`nl>e^1DCeJZ{^tcb&+l4z9yqT#Vn|F(OiWD7EM@9E<_#VC z9COMk$Mos&nsw@wnIV#7xxpG;M6oRzTqi?BNKocEpOG;);u%*+5Gr|U^bil*<}Nux zA;YiyhZt<1`=kk&DjyNU?NA{w7I=l&k0$d3z>f?OpLR$UUrF%?;`7!>`gfChhXk-T z1?*vo9um;He1kFH@edN!VLNs}I0MRl*)w#-gUvKa<>cp|4N4gC4%3r`2~(aM0H#d?10E zvO;48K$qa453qtbu7sNBs@IOZED@r8tzxxVlo1+xfZoS@WKY+8Q_wM($m7cS#S-Q9!P7ZWV?g?l*i z7%@!9nd%D-9C?G7CRpkVFL9)Ucu2_ksxNHfNFT9JFwz%xapV}WPcYIKMmTbc*e4k2 z3n%A3;2a!65kHB;zl`SnzKp)M*EdXffg|gt`jg~M6CUD7-BiC#+ccquBV|*4ckj-g zewmmt*0)WVM!}Y`zFoq5R5Z->RWF{3JwU~EdwrvXtEk8@ve!3A7?MKCGgJMuf8{>m z32LrrE@%pUeL_k9bFzj6+lv3~xv0?BC0tT`YU(lpdhQ~c1P6V^;iuFWZZj4+_Vo#_ zKQZa``(zlC`-m#R>qowUt7jkuX?7y>nYBj>7gUgl>?SU0MneBjTrfOP~s^^W2+B&!VgRk5z<^^mA_Q#9UgF%6p^IBW$w}7C7bLr;)D}M?6S!V l9#W&kG-kxa#KgqJ{15U!$utaUbZ7to002ovPDHLkV1lsW!mR)R literal 0 HcmV?d00001 diff --git a/src/main/res/layout/activity_edit_account.xml b/src/main/res/layout/activity_edit_account.xml index 3eb5bfc1e..2467705a3 100644 --- a/src/main/res/layout/activity_edit_account.xml +++ b/src/main/res/layout/activity_edit_account.xml @@ -43,7 +43,7 @@ android:layout_width="72dp" android:layout_height="72dp" android:layout_alignParentTop="true" - android:layout_marginRight="16dp" + android:layout_marginRight="@dimen/avatar_item_distance" android:contentDescription="@string/account_image_description" app:riv_corner_radius="2dp"/> diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index 7c5823e6a..68db7d6fa 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -19,7 +19,6 @@ 524288 auto light - true true false recent diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 635466ef5..4d1a29bc5 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -277,8 +277,6 @@ Received messages will be marked with a green tick if supported Colorize send button to indicate contact status Other - Group chat name - Use subject instead of JID to identify group chats Automatically join group chats Respect the autojoin flag in group chat bookmarks OMEMO fingerprint copied to clipboard! diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index a779c20d4..477ee2330 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -62,7 +62,7 @@ @drawable/ic_group_add_white_24dp @drawable/ic_person_add_white_24dp - @drawable/ic_cancel_white_24dp + @drawable/ic_cancel_black_24dp @drawable/ic_content_copy_black_24dp @drawable/ic_delete_white_24dp @drawable/ic_file_download_white_24dp diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 8fd69e557..e5668bdb9 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -169,11 +169,6 @@ android:key="font_size" android:summary="@string/pref_font_size_summary" android:title="@string/pref_font_size"/> -