fixed some regressions introduced in toolbar migration

This commit is contained in:
Daniel Gultsch 2018-03-18 09:31:37 +01:00
parent f2885575ba
commit 82ba4ce4fc
2 changed files with 55 additions and 33 deletions

View file

@ -83,6 +83,7 @@ import eu.siacs.conversations.ui.adapter.ListItemAdapter;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected; import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.ui.service.EmojiService; import eu.siacs.conversations.ui.service.EmojiService;
import eu.siacs.conversations.ui.util.DelayedHintHelper; import eu.siacs.conversations.ui.util.DelayedHintHelper;
import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import eu.siacs.conversations.xmpp.XmppConnection; import eu.siacs.conversations.xmpp.XmppConnection;
@ -110,8 +111,13 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
public boolean onMenuItemActionExpand(MenuItem item) { public boolean onMenuItemActionExpand(MenuItem item) {
mSearchEditText.post(() -> { mSearchEditText.post(() -> {
mSearchEditText.requestFocus(); mSearchEditText.requestFocus();
if (oneShotKeyboardSuppress.compareAndSet(true,false)) {
return;
}
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT); if (imm != null) {
imm.showSoftInput(mSearchEditText, InputMethodManager.SHOW_IMPLICIT);
}
}); });
return true; return true;
@ -133,8 +139,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, public void beforeTextChanged(CharSequence s, int start, int count, int after) {
int after) {
} }
@Override @Override
@ -173,7 +178,8 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
} }
} }
}; };
private String mInitialJid; private final PendingItem<String> mInitialSearchValue = new PendingItem<>();
private final AtomicBoolean oneShotKeyboardSuppress = new AtomicBoolean();
private Pair<Integer, Intent> mPostponedActivityResult; private Pair<Integer, Intent> mPostponedActivityResult;
private Toast mToast; private Toast mToast;
private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() { private UiCallback<Conversation> mAdhocConferenceCallback = new UiCallback<Conversation>() {
@ -511,14 +517,24 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
switchToConversation(conversation, body, false); switchToConversation(conversation, body, false);
} }
@Override
public void invalidateOptionsMenu() {
boolean isExpanded = mMenuSearchView != null && mMenuSearchView.isActionViewExpanded();
String text = mSearchEditText != null ? mSearchEditText.getText().toString() : "";
if (isExpanded) {
mInitialSearchValue.push(text);
oneShotKeyboardSuppress.set(true);
}
super.invalidateOptionsMenu();
}
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.start_conversation, menu); getMenuInflater().inflate(R.menu.start_conversation, menu);
MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline); MenuItem menuHideOffline = menu.findItem(R.id.action_hide_offline);
MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference); MenuItem joinGroupChat = menu.findItem(R.id.action_join_conference);
MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code); MenuItem qrCodeScanMenuItem = menu.findItem(R.id.action_scan_qr_code);
ActionBar bar = getSupportActionBar(); joinGroupChat.setVisible(binding.startConversationViewPager.getCurrentItem() == 1);
joinGroupChat.setVisible(bar != null && binding.startConversationViewPager.getCurrentItem() == 1);
qrCodeScanMenuItem.setVisible(isCameraFeatureAvailable()); qrCodeScanMenuItem.setVisible(isCameraFeatureAvailable());
menuHideOffline.setChecked(this.mHideOfflineContacts); menuHideOffline.setChecked(this.mHideOfflineContacts);
mMenuSearchView = menu.findItem(R.id.action_search); mMenuSearchView = menu.findItem(R.id.action_search);
@ -527,10 +543,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
mSearchEditText = mSearchView.findViewById(R.id.search_field); mSearchEditText = mSearchView.findViewById(R.id.search_field);
mSearchEditText.addTextChangedListener(mSearchTextWatcher); mSearchEditText.addTextChangedListener(mSearchTextWatcher);
mSearchEditText.setOnEditorActionListener(mSearchDone); mSearchEditText.setOnEditorActionListener(mSearchDone);
if (mInitialJid != null) { String initialSearchValue = mInitialSearchValue.pop();
if (initialSearchValue != null) {
mMenuSearchView.expandActionView(); mMenuSearchView.expandActionView();
mSearchEditText.append(mInitialJid); mSearchEditText.append(initialSearchValue);
filter(mInitialJid); filter(initialSearchValue);
} }
return super.onCreateOptionsMenu(menu); return super.onCreateOptionsMenu(menu);
} }
@ -775,7 +792,7 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
mSearchEditText.append(invite.getJid().toString()); mSearchEditText.append(invite.getJid().toString());
filter(invite.getJid().toString()); filter(invite.getJid().toString());
} else { } else {
mInitialJid = invite.getJid().toString(); mInitialSearchValue.push(invite.getJid().toString());
} }
return true; return true;
} }

View file

@ -1,35 +1,40 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/color_background_secondary" android:background="?attr/color_background_secondary"
tools:context="eu.siacs.conversations.ui.AboutActivity" android:orientation="vertical"
android:orientation="vertical"> tools:context="eu.siacs.conversations.ui.AboutActivity">
<include layout="@layout/toolbar" /> <include layout="@layout/toolbar"/>
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<android.support.v7.widget.CardView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin">
<TextView <android.support.v7.widget.CardView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:autoLink="web" android:layout_marginBottom="@dimen/activity_vertical_margin"
android:fontFamily="monospace" android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:linksClickable="true" android:layout_marginRight="@dimen/activity_horizontal_margin"
android:padding="@dimen/card_padding_regular" android:layout_marginTop="@dimen/activity_vertical_margin">
android:text="@string/pref_about_message"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" <TextView
android:typeface="monospace"/> android:layout_width="wrap_content"
</android.support.v7.widget.CardView> android:layout_height="wrap_content"
android:autoLink="web"
android:fontFamily="monospace"
android:linksClickable="true"
android:padding="@dimen/card_padding_regular"
android:text="@string/pref_about_message"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:typeface="monospace"/>
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>