From 9a7f99be3765cb9bb39890a9ebc7042eb87488ee Mon Sep 17 00:00:00 2001 From: Thodoris1999 Date: Wed, 10 Oct 2018 23:52:22 +0300 Subject: [PATCH] focus aware editor view --- .../main/shoutbox/ShoutboxFragment.java | 27 +++++++++++-------- .../thmmy/mthmmy/editorview/EditorView.java | 24 ++++++++++++----- app/src/main/res/layout/fragment_shoutbox.xml | 24 +++++++---------- 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java index d883ff56..30f61dfc 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java @@ -1,16 +1,17 @@ package gr.thmmy.mthmmy.activities.main.shoutbox; +import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.InputConnection; +import android.view.inputmethod.InputMethodManager; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.editorview.EditorView; @@ -29,7 +30,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private MaterialProgressBar progressBar; private ShoutboxTask shoutboxTask; private ShoutAdapter shoutAdapter; - private SwipeRefreshLayout swipeRefreshLayout; private EmojiKeyboard emojiKeyboard; private EditorView editorView; private Shoutbox shoutbox; @@ -66,7 +66,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { progressBar.setVisibility(View.INVISIBLE); - swipeRefreshLayout.setRefreshing(false); if (resultCode == NetworkResultCodes.SUCCESSFUL) { shoutAdapter.setShouts(shoutbox.getShouts()); shoutAdapter.notifyDataSetChanged(); @@ -90,17 +89,16 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setReverseLayout(true); recyclerView.setLayoutManager(layoutManager); + recyclerView.setOnTouchListener((view, motionEvent) -> { + editorView.setMarkdownVisible(false); + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0); + return false; + }); + shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished); shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); - swipeRefreshLayout = rootView.findViewById(R.id.swiperefresh); - swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.primary); - swipeRefreshLayout.setColorSchemeResources(R.color.accent); - swipeRefreshLayout.setOnRefreshListener(() -> { - shoutboxTask = new ShoutboxTask(ShoutboxFragment.this::onShoutboxTaskSarted, ShoutboxFragment.this::onShoutboxTaskFinished); - shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); - }); - emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard); editorView = rootView.findViewById(R.id.edior_view); editorView.setEmojiKeyboardOwner(this); @@ -119,6 +117,13 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj .execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(), shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); }); + editorView.setMarkdownVisible(false); + editorView.setOnTouchListener((view, motionEvent) -> { + editorView.setMarkdownVisible(true); + return false; + }); + editorView.setMarkdownVisible(false); + editorView.showMarkdownOnfocus(); return rootView; } diff --git a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java index 1710ba90..a7da9420 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java +++ b/app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java @@ -6,12 +6,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.res.TypedArray; import android.graphics.drawable.Drawable; -import androidx.annotation.Nullable; -import com.google.android.material.textfield.TextInputEditText; -import com.google.android.material.textfield.TextInputLayout; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.recyclerview.widget.GridLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import android.text.Editable; import android.text.TextUtils; import android.util.AttributeSet; @@ -26,8 +20,15 @@ import android.widget.PopupWindow; import android.widget.ScrollView; import android.widget.TextView; +import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textfield.TextInputLayout; + import java.util.Objects; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageButton; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import gr.thmmy.mthmmy.R; public class EditorView extends LinearLayout { @@ -275,6 +276,17 @@ public class EditorView extends LinearLayout { submitButton = findViewById(R.id.submit_button); } + public void setMarkdownVisible(boolean visible) { + findViewById(R.id.buttons_recyclerview).setVisibility(visible ? VISIBLE : GONE); + } + + public void showMarkdownOnfocus() { + edittextWrapper.setOnClickListener(view -> setMarkdownVisible(true)); + editText.setOnClickListener(view -> setMarkdownVisible(true)); + edittextWrapper.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); + editText.setOnFocusChangeListener((view, b) -> setMarkdownVisible(b)); + } + public TextInputEditText getEditText() { return editText; } diff --git a/app/src/main/res/layout/fragment_shoutbox.xml b/app/src/main/res/layout/fragment_shoutbox.xml index c7f8485c..625c2b88 100644 --- a/app/src/main/res/layout/fragment_shoutbox.xml +++ b/app/src/main/res/layout/fragment_shoutbox.xml @@ -1,5 +1,6 @@ - - - - - - + android:layout_weight="1" + tools:listitem="@layout/fragment_shoutbox_shout_row" /> + android:paddingTop="8dp" + app:layout_anchor="@id/shoutbox_recyclerview" + app:layout_anchorGravity="bottom" + app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareLinearBehavior" /> - \ No newline at end of file