Skip to content

Commit

Permalink
Open keyboard when we open contact selection from blocked preference.
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-signal committed Nov 12, 2020
1 parent 2dace38 commit 06aada2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ protected void onCreate(Bundle savedInstanceState, boolean ready) {
//noinspection CodeBlock2Expr
getSupportFragmentManager().addOnBackStackChangedListener(() -> {
viewSwitcher.setDisplayedChild(getSupportFragmentManager().getBackStackEntryCount());

if (getSupportFragmentManager().getBackStackEntryCount() == 1) {
contactFilterToolbar.focusAndShowKeyboard();
}
});

getSupportFragmentManager().beginTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.ServiceUtil;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.views.DarkOverflowToolbar;

public final class ContactFilterToolbar extends DarkOverflowToolbar {
Expand Down Expand Up @@ -125,6 +126,10 @@ private void applyAttributes(@NonNull EditText searchText,
attributes.recycle();
}

public void focusAndShowKeyboard() {
ViewUtil.focusAndShowKeyboard(searchText);
}

public void clear() {
searchText.setText("");
notifyListener();
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.ViewTreeObserver;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.inputmethod.InputMethodManager;
Expand All @@ -51,6 +52,32 @@ public final class ViewUtil {
private ViewUtil() {
}

public static void focusAndShowKeyboard(@NonNull View view) {
view.requestFocus();
if (view.hasWindowFocus()) {
showTheKeyboardNow(view);
} else {
view.getViewTreeObserver().addOnWindowFocusChangeListener(new ViewTreeObserver.OnWindowFocusChangeListener() {
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
showTheKeyboardNow(view);
view.getViewTreeObserver().removeOnWindowFocusChangeListener(this);
}
}
});
}
}

private static void showTheKeyboardNow(@NonNull View view) {
if (view.isFocused()) {
view.post(() -> {
InputMethodManager inputMethodManager = ServiceUtil.getInputMethodManager(view.getContext());
inputMethodManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
});
}
}

public static void setBackground(final @NonNull View v, final @Nullable Drawable drawable) {
v.setBackground(drawable);
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/blocked_users_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
android:layout_marginTop="29dp"
android:layout_marginEnd="16dp"
android:text="@string/BlockedUsersActivity__blocked_users"
android:textAppearance="@style/TextAppearance.Signal.Subtitle"
android:textAppearance="@style/TextAppearance.Signal.Body2.Bold"
android:textColor="?colorAccent"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit 06aada2

Please sign in to comment.