open/close soft keyboard in quick edit

This commit is contained in:
Daniel Gultsch 2018-06-23 09:29:29 +02:00
parent 64aa238d57
commit 1b0e9f2f0d
16 changed files with 69 additions and 38 deletions

View file

@ -13,7 +13,9 @@ import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.LayoutInflater; 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.services.XmppConnectionService.OnMucRosterUpdate;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.MyLinkify; 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.UIHelper;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
import static eu.siacs.conversations.entities.Bookmark.printableValue; 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"; public static final String ACTION_VIEW_MUC = "view_muc";
private static final float INACTIVE_ALPHA = 0.4684f; //compromise between dark and light theme 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); startActivity(intent);
}); });
this.binding.editMucNameButton.setOnClickListener(this::onMucEditButtonClicked); this.binding.editMucNameButton.setOnClickListener(this::onMucEditButtonClicked);
this.binding.mucEditTitle.addTextChangedListener(this);
this.binding.mucEditSubject.addTextChangedListener(this);
} }
@Override @Override
@ -310,7 +315,7 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
final MucOptions mucOptions = mConversation.getMucOptions(); final MucOptions mucOptions = mConversation.getMucOptions();
this.binding.mucEditor.setVisibility(View.VISIBLE); this.binding.mucEditor.setVisibility(View.VISIBLE);
this.binding.mucDisplay.setVisibility(View.GONE); 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(); final String name = mucOptions.getName();
this.binding.mucEditTitle.setText(""); this.binding.mucEditTitle.setText("");
final boolean owner = mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER); final boolean owner = mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER);
@ -332,11 +337,11 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
if (!owner) { if (!owner) {
this.binding.mucEditSubject.requestFocus(); this.binding.mucEditSubject.requestFocus();
} }
this.binding.yourPhoto.setVisibility(View.GONE);
} else { } else {
String subject = this.binding.mucEditSubject.isEnabled() ? this.binding.mucEditSubject.getEditableText().toString().trim() : null; 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; String name = this.binding.mucEditTitle.isEnabled() ? this.binding.mucEditTitle.getEditableText().toString().trim() : null;
onMucInfoUpdated(subject, name); onMucInfoUpdated(subject, name);
SoftKeyboardUtils.hideSoftKeyboard(this);
hideEditor(); hideEditor();
} }
} }
@ -345,21 +350,18 @@ public class ConferenceDetailsActivity extends XmppActivity implements OnConvers
this.binding.mucEditor.setVisibility(View.GONE); this.binding.mucEditor.setVisibility(View.GONE);
this.binding.mucDisplay.setVisibility(View.VISIBLE); this.binding.mucDisplay.setVisibility(View.VISIBLE);
this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_edit_body, R.drawable.ic_edit_black_24dp)); 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) { private void onMucInfoUpdated(String subject, String name) {
final MucOptions mucOptions = mConversation.getMucOptions(); final MucOptions mucOptions = mConversation.getMucOptions();
if (mucOptions.canChangeSubject() && !blankOnNull(mucOptions.getSubject()).equals(subject)) { if (mucOptions.canChangeSubject() && changed(mucOptions.getSubject(), subject)) {
Log.d(Config.LOGTAG,"subject changed");
xmppConnectionService.pushSubjectToConference(mConversation, subject); xmppConnectionService.pushSubjectToConference(mConversation, subject);
} }
if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && !blankOnNull(mucOptions.getName()).equals(name)) { if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && changed(mucOptions.getName(), name)) {
Log.d(Config.LOGTAG,"name changed");
Bundle options = new Bundle(); Bundle options = new Bundle();
options.putString("muc#roomconfig_persistentroom", "1"); options.putString("muc#roomconfig_persistentroom", "1");
options.putString("muc#roomconfig_roomname", name); 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; return input == null ? "" : input;
} }
private static boolean changed(String one, String two) {
return !blankOnNull(one).equals(blankOnNull(two));
}
@Override @Override
protected String getShareableUri(boolean http) { protected String getShareableUri(boolean http) {
if (mConversation != null) { 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 { static class AsyncDrawable extends BitmapDrawable {
private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference; private final WeakReference<BitmapWorkerTask> bitmapWorkerTaskReference;

View file

@ -199,7 +199,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer
if (intent == null) { if (intent == null) {
return; 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 type = intent.getType();
final String action = intent.getAction(); final String action = intent.getAction();
Log.d(Config.LOGTAG, "action: "+action+ ", type:"+type); Log.d(Config.LOGTAG, "action: "+action+ ", type:"+type);

View file

@ -984,7 +984,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne
jid.setError(getString(R.string.bookmark_already_exists)); jid.setError(getString(R.string.bookmark_already_exists));
} else { } else {
final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); 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(); String nick = conferenceJid.getResource();
if (nick != null && !nick.isEmpty()) { if (nick != null && !nick.isEmpty()) {
bookmark.setNick(nick); bookmark.setNick(nick);

View file

@ -72,6 +72,7 @@ import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder; import eu.siacs.conversations.services.XmppConnectionService.XmppConnectionBinder;
import eu.siacs.conversations.ui.util.MenuDoubleTabUtil; import eu.siacs.conversations.ui.util.MenuDoubleTabUtil;
import eu.siacs.conversations.ui.util.PresenceSelector; 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.ExceptionHelper;
import eu.siacs.conversations.utils.ThemeHelper; import eu.siacs.conversations.utils.ThemeHelper;
import eu.siacs.conversations.xmpp.OnKeyStatusUpdated; import eu.siacs.conversations.xmpp.OnKeyStatusUpdated;
@ -95,7 +96,6 @@ public abstract class XmppActivity extends ActionBarActivity {
private boolean isCameraFeatureAvailable = false; private boolean isCameraFeatureAvailable = false;
protected boolean mUseSubject = true;
protected int mTheme; protected int mTheme;
protected boolean mUsingEnterKey = false; protected boolean mUsingEnterKey = false;
protected Toast mToast; protected Toast mToast;
@ -402,7 +402,6 @@ public abstract class XmppActivity extends ActionBarActivity {
setTheme(this.mTheme); setTheme(this.mTheme);
this.mUsingEnterKey = usingEnterKey(); this.mUsingEnterKey = usingEnterKey();
mUseSubject = getBooleanPreference("use_subject", R.bool.use_subject);
} }
protected boolean isCameraFeatureAvailable() { protected boolean isCameraFeatureAvailable() {
@ -445,7 +444,7 @@ public abstract class XmppActivity extends ActionBarActivity {
} }
protected boolean usingEnterKey() { 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() { protected SharedPreferences getPreferences() {
@ -456,10 +455,6 @@ public abstract class XmppActivity extends ActionBarActivity {
return getPreferences().getBoolean(name, getResources().getBoolean(res)); return getPreferences().getBoolean(name, getResources().getBoolean(res));
} }
public boolean useSubjectToIdentifyConference() {
return mUseSubject;
}
public void switchToConversation(Conversation conversation) { public void switchToConversation(Conversation conversation) {
switchToConversation(conversation, null, false); switchToConversation(conversation, null, false);
} }
@ -723,6 +718,7 @@ public abstract class XmppActivity extends ActionBarActivity {
builder.setView(binding.getRoot()); builder.setView(binding.getRoot());
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
final AlertDialog dialog = builder.create(); final AlertDialog dialog = builder.create();
dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(binding.inputEditText));
dialog.show(); dialog.show();
View.OnClickListener clickListener = v -> { View.OnClickListener clickListener = v -> {
String value = binding.inputEditText.getText().toString(); String value = binding.inputEditText.getText().toString();
@ -733,9 +729,17 @@ public abstract class XmppActivity extends ActionBarActivity {
return; return;
} }
} }
SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
dialog.dismiss(); dialog.dismiss();
}; };
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener); 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) { protected boolean hasStoragePermission(int requestCode) {
@ -790,7 +794,7 @@ public abstract class XmppActivity extends ActionBarActivity {
} }
protected boolean manuallyChangePresence() { 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() { protected String getShareableUri() {

View file

@ -84,16 +84,12 @@ public class ConversationAdapter extends RecyclerView.Adapter<ConversationAdapte
if (conversation == null) { if (conversation == null) {
return; return;
} }
if (conversation.getMode() == Conversation.MODE_SINGLE || activity.useSubjectToIdentifyConference()) {
CharSequence name = conversation.getName(); CharSequence name = conversation.getName();
if (name instanceof Jid) { if (name instanceof Jid) {
viewHolder.name.setText(IrregularUnicodeDetector.style(activity, (Jid) name)); viewHolder.name.setText(IrregularUnicodeDetector.style(activity, (Jid) name));
} else { } else {
viewHolder.name.setText(EmojiWrapper.transform(name)); viewHolder.name.setText(EmojiWrapper.transform(name));
} }
} else {
viewHolder.name.setText(conversation.getJid().asBareJid().toString());
}
viewHolder.frame.setBackgroundColor(Color.get(activity, conversation == ConversationFragment.getConversation(activity) ? R.attr.color_background_secondary : R.attr.color_background_primary)); viewHolder.frame.setBackgroundColor(Color.get(activity, conversation == ConversationFragment.getConversation(activity) ? R.attr.color_background_secondary : R.attr.color_background_primary));

View file

@ -31,6 +31,7 @@ package eu.siacs.conversations.ui.util;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View; import android.view.View;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.EditText; import android.widget.EditText;
@ -48,7 +49,15 @@ public class SoftKeyboardUtils {
if (view == null) { if (view == null) {
view = new View(activity); view = new View(activity);
} }
imm.hideSoftInputFromWindow(view.getWindowToken(), 0); imm.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
public static void hideSoftKeyboard(@NonNull final EditText editText) {
InputMethodManager imm = (InputMethodManager) editText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm == null) {
return;
}
imm.hideSoftInputFromWindow(editText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
} }
public static void showKeyboard(EditText editText) { public static void showKeyboard(EditText editText) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 397 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 517 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 721 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 963 B

View file

@ -43,7 +43,7 @@
android:layout_width="72dp" android:layout_width="72dp"
android:layout_height="72dp" android:layout_height="72dp"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_marginRight="16dp" android:layout_marginRight="@dimen/avatar_item_distance"
android:contentDescription="@string/account_image_description" android:contentDescription="@string/account_image_description"
app:riv_corner_radius="2dp"/> app:riv_corner_radius="2dp"/>

View file

@ -19,7 +19,6 @@
<integer name="auto_accept_filesize">524288</integer> <integer name="auto_accept_filesize">524288</integer>
<string name="picture_compression">auto</string> <string name="picture_compression">auto</string>
<string name="theme">light</string> <string name="theme">light</string>
<bool name="use_subject">true</bool>
<bool name="use_green_background">true</bool> <bool name="use_green_background">true</bool>
<bool name="send_button_status">false</bool> <bool name="send_button_status">false</bool>
<string name="quick_action">recent</string> <string name="quick_action">recent</string>

View file

@ -277,8 +277,6 @@
<string name="pref_use_indicate_received_summary">Received messages will be marked with a green tick if supported</string> <string name="pref_use_indicate_received_summary">Received messages will be marked with a green tick if supported</string>
<string name="pref_use_send_button_to_indicate_status_summary">Colorize send button to indicate contact status</string> <string name="pref_use_send_button_to_indicate_status_summary">Colorize send button to indicate contact status</string>
<string name="pref_expert_options_other">Other</string> <string name="pref_expert_options_other">Other</string>
<string name="pref_conference_name">Group chat name</string>
<string name="pref_conference_name_summary">Use subject instead of JID to identify group chats</string>
<string name="pref_autojoin">Automatically join group chats</string> <string name="pref_autojoin">Automatically join group chats</string>
<string name="pref_autojoin_summary">Respect the autojoin flag in group chat bookmarks</string> <string name="pref_autojoin_summary">Respect the autojoin flag in group chat bookmarks</string>
<string name="toast_message_omemo_fingerprint">OMEMO fingerprint copied to clipboard!</string> <string name="toast_message_omemo_fingerprint">OMEMO fingerprint copied to clipboard!</string>

View file

@ -62,7 +62,7 @@
<item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item> <item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item>
<item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item> <item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item>
<item type="reference" name="icon_cancel">@drawable/ic_cancel_white_24dp</item> <item type="reference" name="icon_cancel">@drawable/ic_cancel_black_24dp</item>
<item type="reference" name="icon_copy">@drawable/ic_content_copy_black_24dp</item> <item type="reference" name="icon_copy">@drawable/ic_content_copy_black_24dp</item>
<item type="reference" name="icon_discard">@drawable/ic_delete_white_24dp</item> <item type="reference" name="icon_discard">@drawable/ic_delete_white_24dp</item>
<item type="reference" name="icon_download">@drawable/ic_file_download_white_24dp</item> <item type="reference" name="icon_download">@drawable/ic_file_download_white_24dp</item>

View file

@ -169,11 +169,6 @@
android:key="font_size" android:key="font_size"
android:summary="@string/pref_font_size_summary" android:summary="@string/pref_font_size_summary"
android:title="@string/pref_font_size"/> android:title="@string/pref_font_size"/>
<CheckBoxPreference
android:defaultValue="@bool/use_subject"
android:key="use_subject"
android:summary="@string/pref_conference_name_summary"
android:title="@string/pref_conference_name"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/send_button_status" android:defaultValue="@bool/send_button_status"
android:key="send_button_status" android:key="send_button_status"