Browse Source

fix shoutbox keyboard issues

pull/61/merge
oogee 6 years ago
parent
commit
ea8649515c
  1. 17
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java
  2. 16
      app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java
  3. 26
      app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

17
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxActivity.java

@ -7,6 +7,8 @@ import gr.thmmy.mthmmy.base.BaseActivity;
public class ShoutboxActivity extends BaseActivity {
private ShoutboxFragment shoutboxFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -25,8 +27,9 @@ public class ShoutboxActivity extends BaseActivity {
drawer.setSelection(SHOUTBOX_ID);
if (savedInstanceState == null) {
shoutboxFragment = ShoutboxFragment.newInstance();
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, ShoutboxFragment.newInstance())
.replace(R.id.container, shoutboxFragment)
.commitNow();
}
}
@ -36,4 +39,16 @@ public class ShoutboxActivity extends BaseActivity {
drawer.setSelection(SHOUTBOX_ID);
super.onResume();
}
@Override
public void onBackPressed() {
int count = getSupportFragmentManager().getBackStackEntryCount();
if (count == 0) {
if (!shoutboxFragment.onBackPressed())
super.onBackPressed();
} else {
getSupportFragmentManager().popBackStack();
}
}
}

16
app/src/main/java/gr/thmmy/mthmmy/activities/shoutbox/ShoutboxFragment.java

@ -76,11 +76,6 @@ public class ShoutboxFragment extends Fragment {
shoutboxViewModel.sendShout(editorView.getText().toString());
});
editorView.hideMarkdown();
editorView.setOnTouchListener((view, motionEvent) -> {
editorView.showMarkdown();
return false;
});
editorView.setMarkdownVisible(false);
editorView.showMarkdownOnfocus();
return rootView;
@ -162,4 +157,15 @@ public class ShoutboxFragment extends Fragment {
Toast.makeText(getContext(), "Failed to retrieve shoutbox, please contact mthmmy developer team", Toast.LENGTH_LONG).show();
}
}
/**
* @return whether or not {@link ShoutboxFragment#onBackPressed()} consumed the event or not
*/
public boolean onBackPressed() {
if (emojiKeyboard.isVisible()) {
emojiKeyboard.setVisibility(View.GONE);
return true;
}
return false;
}
}

26
app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

@ -38,7 +38,7 @@ import gr.thmmy.mthmmy.R;
public class EditorView extends LinearLayout implements EmojiInputField {
private static final int ANIMATION_DURATION = 100;
private static final int ANIMATION_DURATION = 200;
private SparseArray<String> colors = new SparseArray<>();
private TextInputLayout edittextWrapper;
@ -308,24 +308,32 @@ public class EditorView extends LinearLayout implements EmojiInputField {
this.emojiKeyboard = emojiKeyboard;
}
public void setMarkdownVisible(boolean visible) {
formatButtonsRecyclerview.setVisibility(visible ? VISIBLE : GONE);
}
public void showMarkdownOnfocus() {
edittextWrapper.setOnClickListener(view -> {
showMarkdown();
});
editText.setOnClickListener(view -> {
if (!emojiKeyboard.isVisible()) {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
} else {
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), 0);
requestEditTextFocus();
}
showMarkdown();
});
edittextWrapper.setOnFocusChangeListener((view, b) -> {
if (b) showMarkdown();
else hideMarkdown();
if (b) {
emojiKeyboard.onEmojiInputFieldFocused(EditorView.this);
showMarkdown();
} else hideMarkdown();
});
editText.setOnFocusChangeListener((view, b) -> {
if (b) showMarkdown();
else hideMarkdown();
if (b) {
emojiKeyboard.onEmojiInputFieldFocused(EditorView.this);
showMarkdown();
} else hideMarkdown();
});
}

Loading…
Cancel
Save