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 { public class ShoutboxActivity extends BaseActivity {
private ShoutboxFragment shoutboxFragment;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -25,8 +27,9 @@ public class ShoutboxActivity extends BaseActivity {
drawer.setSelection(SHOUTBOX_ID); drawer.setSelection(SHOUTBOX_ID);
if (savedInstanceState == null) { if (savedInstanceState == null) {
shoutboxFragment = ShoutboxFragment.newInstance();
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.replace(R.id.container, ShoutboxFragment.newInstance()) .replace(R.id.container, shoutboxFragment)
.commitNow(); .commitNow();
} }
} }
@ -36,4 +39,16 @@ public class ShoutboxActivity extends BaseActivity {
drawer.setSelection(SHOUTBOX_ID); drawer.setSelection(SHOUTBOX_ID);
super.onResume(); 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()); shoutboxViewModel.sendShout(editorView.getText().toString());
}); });
editorView.hideMarkdown(); editorView.hideMarkdown();
editorView.setOnTouchListener((view, motionEvent) -> {
editorView.showMarkdown();
return false;
});
editorView.setMarkdownVisible(false);
editorView.showMarkdownOnfocus(); editorView.showMarkdownOnfocus();
return rootView; 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(); 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 { 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 SparseArray<String> colors = new SparseArray<>();
private TextInputLayout edittextWrapper; private TextInputLayout edittextWrapper;
@ -308,24 +308,32 @@ public class EditorView extends LinearLayout implements EmojiInputField {
this.emojiKeyboard = emojiKeyboard; this.emojiKeyboard = emojiKeyboard;
} }
public void setMarkdownVisible(boolean visible) {
formatButtonsRecyclerview.setVisibility(visible ? VISIBLE : GONE);
}
public void showMarkdownOnfocus() { public void showMarkdownOnfocus() {
edittextWrapper.setOnClickListener(view -> { edittextWrapper.setOnClickListener(view -> {
showMarkdown(); showMarkdown();
}); });
editText.setOnClickListener(view -> { 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(); showMarkdown();
}); });
edittextWrapper.setOnFocusChangeListener((view, b) -> { edittextWrapper.setOnFocusChangeListener((view, b) -> {
if (b) showMarkdown(); if (b) {
else hideMarkdown(); emojiKeyboard.onEmojiInputFieldFocused(EditorView.this);
showMarkdown();
} else hideMarkdown();
}); });
editText.setOnFocusChangeListener((view, b) -> { editText.setOnFocusChangeListener((view, b) -> {
if (b) showMarkdown(); if (b) {
else hideMarkdown(); emojiKeyboard.onEmojiInputFieldFocused(EditorView.this);
showMarkdown();
} else hideMarkdown();
}); });
} }

Loading…
Cancel
Save