Browse Source

add refresh label

pull/61/merge
Thodoris1999 6 years ago
parent
commit
9bed06fb7c
  1. 50
      app/src/main/java/gr/thmmy/mthmmy/activities/main/shoutbox/ShoutboxFragment.java
  2. 16
      app/src/main/res/drawable/refresh_label_background.xml
  3. 30
      app/src/main/res/layout/fragment_shoutbox.xml
  4. 1
      app/src/main/res/values/dimens.xml
  5. 1
      app/src/main/res/values/strings.xml

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

@ -1,5 +1,6 @@
package gr.thmmy.mthmmy.activities.main.shoutbox;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
@ -7,11 +8,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.base.BaseFragment;
import gr.thmmy.mthmmy.editorview.EditorView;
@ -29,11 +33,13 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
private static final String TAG = "ShoutboxFragment";
private MaterialProgressBar progressBar;
private TextView refreshLabel;
private ShoutboxTask shoutboxTask;
private ShoutAdapter shoutAdapter;
private EmojiKeyboard emojiKeyboard;
private EditorView editorView;
private Shoutbox shoutbox;
private ValueAnimator animator;
public static ShoutboxFragment newInstance(int sectionNumber) {
ShoutboxFragment fragment = new ShoutboxFragment();
@ -46,6 +52,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
private void onShoutboxTaskSarted() {
Timber.i("Starting shoutbox task...");
hideRefreshLabel();
progressBar.setVisibility(View.VISIBLE);
}
@ -58,6 +65,7 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
editorView.setAlpha(1f);
editorView.setEnabled(true);
progressBar.setVisibility(View.INVISIBLE);
showRefreshLabel();
if (resultCode == NetworkResultCodes.SUCCESSFUL) {
Timber.i("Shout was sent successfully");
editorView.getEditText().getText().clear();
@ -90,6 +98,12 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_shoutbox, container, false);
refreshLabel = rootView.findViewById(R.id.refresh_label);
refreshLabel.setOnClickListener(v -> {
shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
});
progressBar = rootView.findViewById(R.id.progressBar);
CustomRecyclerView recyclerView = rootView.findViewById(R.id.shoutbox_recyclerview);
shoutAdapter = new ShoutAdapter(getContext(), new Shout[0]);
@ -103,6 +117,16 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
imm.hideSoftInputFromWindow(editorView.getWindowToken(), 0);
return false;
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
showRefreshLabel();
} else {
hideRefreshLabel();
}
}
});
shoutboxTask = new ShoutboxTask(this::onShoutboxTaskSarted, this::onShoutboxTaskFinished);
shoutboxTask.execute(SessionManager.shoutboxUrl.toString());
@ -136,6 +160,32 @@ public class ShoutboxFragment extends BaseFragment implements EmojiKeyboard.Emoj
return rootView;
}
private void hideRefreshLabel() {
if (refreshLabel.getVisibility() == View.GONE) return;
if (animator != null) animator.cancel();
animator = getRefreshLabelAnimation();
animator.start();
}
private void showRefreshLabel() {
if (refreshLabel.getVisibility() == View.VISIBLE) return;
if (animator != null) animator.cancel();
animator = getRefreshLabelAnimation();
animator.reverse();
}
private ValueAnimator getRefreshLabelAnimation() {
ValueAnimator animator = ValueAnimator.ofFloat(-200, 0);
animator.addUpdateListener(valueAnimator -> {
if (((Float) valueAnimator.getAnimatedValue()).intValue() == 1) refreshLabel.setVisibility(View.VISIBLE);
if (((Float) valueAnimator.getAnimatedValue()).intValue() == -199) refreshLabel.setVisibility(View.GONE);
refreshLabel.setTranslationY((float) valueAnimator.getAnimatedValue());
});
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.setDuration(200);
return animator;
}
@Override
public void setEmojiKeyboardVisible(boolean visible) {
emojiKeyboard.setVisibility(visible ? View.VISIBLE : View.GONE);

16
app/src/main/res/drawable/refresh_label_background.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke
android:width="1dp"
android:color="@color/accent" />
<solid android:color="@color/accent" />
<padding
android:left="1dp"
android:right="1dp"
android:bottom="1dp"
android:top="1dp" />
<corners android:radius="@dimen/refresh_label_border_radius" />
</shape>

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

@ -17,23 +17,41 @@
app:mpb_indeterminateTint="@color/accent"
app:mpb_progressStyle="horizontal" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<gr.thmmy.mthmmy.utils.CustomRecyclerView
android:id="@+id/shoutbox_recyclerview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
tools:listitem="@layout/fragment_shoutbox_shout_row" />
<TextView
android:id="@+id/refresh_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="top"
android:layout_marginTop="4dp"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:background="@drawable/refresh_label_background"
android:text="@string/refresh_button"
android:textColor="@color/primary_text" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<gr.thmmy.mthmmy.editorview.EditorView
android:id="@+id/edior_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:paddingTop="8dp"
app:layout_anchor="@id/shoutbox_recyclerview"
app:layout_anchorGravity="bottom"
app:layout_behavior="gr.thmmy.mthmmy.utils.ScrollAwareLinearBehavior" />
android:paddingTop="8dp" />
<gr.thmmy.mthmmy.editorview.EmojiKeyboard
android:id="@+id/emoji_keyboard"

1
app/src/main/res/values/dimens.xml

@ -11,4 +11,5 @@
<dimen name="big_text">24sp</dimen>
<dimen name="editor_format_button_size">24dp</dimen>
<dimen name="editor_format_button_margin_between">6dp</dimen>
<dimen name="refresh_label_border_radius">12dp</dimen>
</resources>

1
app/src/main/res/values/strings.xml

@ -20,6 +20,7 @@
<string name="forum">Forum</string>
<string name="unread">Unread</string>
<string name="shoutbox">Shoutbox</string>
<string name="refresh_button">REFRESH</string>
<!--Login Activity-->
<string name="thmmy_img_description">thmmy.gr</string>

Loading…
Cancel
Save