Browse Source

focus aware editor view

pull/61/merge
Thodoris1999 6 years ago
parent
commit
9a7f99be37
  1. 27
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java
  2. 24
      app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java
  3. 24
      app/src/main/res/layout/fragment_shoutbox.xml

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

@ -1,16 +1,17 @@
package gr.thmmy.mthmmy.activities.main.shoutbox; package gr.thmmy.mthmmy.activities.main.shoutbox;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseFragment; import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.editorview.EditorView; import gr.thmmy.mthmmy.editorview.EditorView;
@ -29,7 +30,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
private MaterialProgressBar progressBar; private MaterialProgressBar progressBar;
private ShoutboxTask shoutboxTask; private ShoutboxTask shoutboxTask;
private ShoutAdapter shoutAdapter; private ShoutAdapter shoutAdapter;
private SwipeRefreshLayout swipeRefreshLayout;
private EmojiKeyboard emojiKeyboard; private EmojiKeyboard emojiKeyboard;
private EditorView editorView; private EditorView editorView;
private Shoutbox shoutbox; private Shoutbox shoutbox;
@ -66,7 +66,6 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) { private void onShoutboxTaskFinished(int resultCode, Shoutbox shoutbox) {
progressBar.setVisibility(View.INVISIBLE); progressBar.setVisibility(View.INVISIBLE);
swipeRefreshLayout.setRefreshing(false);
if (resultCode == NetworkResultCodes.SUCCESSFUL) { if (resultCode == NetworkResultCodes.SUCCESSFUL) {
shoutAdapter.setShouts(shoutbox.getShouts()); shoutAdapter.setShouts(shoutbox.getShouts());
shoutAdapter.notifyDataSetChanged(); shoutAdapter.notifyDataSetChanged();
@ -90,17 +89,16 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
layoutManager.setReverseLayout(true); layoutManager.setReverseLayout(true);
recyclerView.setLayoutManager(layoutManager); 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 = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString()); 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); emojiKeyboard = rootView.findViewById(R.id.emoji_keyboard);
editorView = rootView.findViewById(R.id.edior_view); editorView = rootView.findViewById(R.id.edior_view);
editorView.setEmojiKeyboardOwner(this); editorView.setEmojiKeyboardOwner(this);
@ -119,6 +117,13 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
.execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(), .execute(shoutbox.getSendShoutUrl(), editorView.getText().toString(), shoutbox.getSc(),
shoutbox.getShoutName(), shoutbox.getShoutSend(), shoutbox.getShoutUrl()); 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; return rootView;
} }

24
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.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.Drawable; 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.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -26,8 +20,15 @@ import android.widget.PopupWindow;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import java.util.Objects; 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; import gr.thmmy.mthmmy.R;
public class EditorView extends LinearLayout { public class EditorView extends LinearLayout {
@ -275,6 +276,17 @@ public class EditorView extends LinearLayout {
submitButton = findViewById(R.id.submit_button); 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() { public TextInputEditText getEditText() {
return editText; return editText;
} }

24
app/src/main/res/layout/fragment_shoutbox.xml

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -16,19 +17,12 @@
app:mpb_indeterminateTint="@color/accent" app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal" /> app:mpb_progressStyle="horizontal" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <gr.thmmy.mthmmy.utils.CustomRecyclerView
android:id="@+id/swiperefresh" android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1"> android:layout_weight="1"
tools:listitem="@layout/fragment_shoutbox_shout_row" />
<gr.thmmy.mthmmy.utils.CustomRecyclerView
android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:listitem="@layout/fragment_shoutbox_shout_row" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<gr.thmmy.mthmmy.editorview.EditorView <gr.thmmy.mthmmy.editorview.EditorView
android:id="@+id/edior_view" android:id="@+id/edior_view"
@ -36,12 +30,14 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:paddingTop="8dp" /> android:paddingTop="8dp"
app:layout_anchor="@id/shoutbox_recyclerview"
app:layout_anchorGravity="bottom"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareLinearBehavior" />
<gr.thmmy.mthmmy.editorview.EmojiKeyboard <gr.thmmy.mthmmy.editorview.EmojiKeyboard
android:id="@+id/emoji_keyboard" android:id="@+id/emoji_keyboard"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="180dp" android:layout_height="180dp"
android:visibility="gone" /> android:visibility="gone" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save