mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-22 17:10:56 +00:00
Add animation to recyclerview
This commit is contained in:
parent
4f0fea8a88
commit
1071192156
4 changed files with 58 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
||||||
package me.impy.aegis.ui.views;
|
package me.impy.aegis.ui.views;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
@ -9,6 +10,8 @@ import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
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.animation.AnimationUtils;
|
||||||
|
import android.view.animation.LayoutAnimationController;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -23,6 +26,7 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
private Listener _listener;
|
private Listener _listener;
|
||||||
private SimpleItemTouchHelperCallback _touchCallback;
|
private SimpleItemTouchHelperCallback _touchCallback;
|
||||||
|
|
||||||
|
private RecyclerView _rvKeyProfiles;
|
||||||
private PeriodProgressBar _progressBar;
|
private PeriodProgressBar _progressBar;
|
||||||
private boolean _showProgress;
|
private boolean _showProgress;
|
||||||
|
|
||||||
|
@ -44,13 +48,17 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
_progressBar.getProgressDrawable().setColorFilter(primaryColorId, PorterDuff.Mode.SRC_IN);
|
_progressBar.getProgressDrawable().setColorFilter(primaryColorId, PorterDuff.Mode.SRC_IN);
|
||||||
|
|
||||||
// set up the recycler view
|
// set up the recycler view
|
||||||
RecyclerView rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles);
|
_rvKeyProfiles = view.findViewById(R.id.rvKeyProfiles);
|
||||||
LinearLayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
|
LinearLayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
|
||||||
rvKeyProfiles.setLayoutManager(mLayoutManager);
|
_rvKeyProfiles.setLayoutManager(mLayoutManager);
|
||||||
_touchCallback = new SimpleItemTouchHelperCallback(_adapter);
|
_touchCallback = new SimpleItemTouchHelperCallback(_adapter);
|
||||||
ItemTouchHelper touchHelper = new ItemTouchHelper(_touchCallback);
|
ItemTouchHelper touchHelper = new ItemTouchHelper(_touchCallback);
|
||||||
touchHelper.attachToRecyclerView(rvKeyProfiles);
|
touchHelper.attachToRecyclerView(_rvKeyProfiles);
|
||||||
rvKeyProfiles.setAdapter(_adapter);
|
_rvKeyProfiles.setAdapter(_adapter);
|
||||||
|
|
||||||
|
int resId = R.anim.layout_animation_fall_down;
|
||||||
|
LayoutAnimationController animation = AnimationUtils.loadLayoutAnimation(getContext(), resId);
|
||||||
|
_rvKeyProfiles.setLayoutAnimation(animation);
|
||||||
|
|
||||||
_refresher = new UiRefresher(new UiRefresher.Listener() {
|
_refresher = new UiRefresher(new UiRefresher.Listener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -71,6 +79,8 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
_adapter.setGroupFilter(group);
|
_adapter.setGroupFilter(group);
|
||||||
_touchCallback.setIsLongPressDragEnabled(group == null);
|
_touchCallback.setIsLongPressDragEnabled(group == null);
|
||||||
checkPeriodUniformity();
|
checkPeriodUniformity();
|
||||||
|
|
||||||
|
runLayoutAnimation(_rvKeyProfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh(boolean hard) {
|
public void refresh(boolean hard) {
|
||||||
|
@ -165,6 +175,16 @@ public class EntryListView extends Fragment implements EntryAdapter.Listener {
|
||||||
checkPeriodUniformity();
|
checkPeriodUniformity();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void runLayoutAnimation(final RecyclerView recyclerView) {
|
||||||
|
final Context context = recyclerView.getContext();
|
||||||
|
final LayoutAnimationController controller =
|
||||||
|
AnimationUtils.loadLayoutAnimation(context, R.anim.layout_animation_fall_down);
|
||||||
|
|
||||||
|
recyclerView.setLayoutAnimation(controller);
|
||||||
|
recyclerView.getAdapter().notifyDataSetChanged();
|
||||||
|
recyclerView.scheduleLayoutAnimation();
|
||||||
|
}
|
||||||
|
|
||||||
public interface Listener {
|
public interface Listener {
|
||||||
void onEntryClick(DatabaseEntry entry);
|
void onEntryClick(DatabaseEntry entry);
|
||||||
void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2);
|
void onEntryMove(DatabaseEntry entry1, DatabaseEntry entry2);
|
||||||
|
|
26
app/src/main/res/anim/item_animation_fall_down.xml
Normal file
26
app/src/main/res/anim/item_animation_fall_down.xml
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<set xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:duration="400">
|
||||||
|
|
||||||
|
<translate
|
||||||
|
android:fromYDelta="-20%"
|
||||||
|
android:toYDelta="0"
|
||||||
|
android:interpolator="@android:anim/decelerate_interpolator"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<alpha
|
||||||
|
android:fromAlpha="0"
|
||||||
|
android:toAlpha="1"
|
||||||
|
android:interpolator="@android:anim/decelerate_interpolator"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<scale
|
||||||
|
android:fromXScale="105%"
|
||||||
|
android:fromYScale="105%"
|
||||||
|
android:toXScale="100%"
|
||||||
|
android:toYScale="100%"
|
||||||
|
android:pivotX="50%"
|
||||||
|
android:pivotY="50%"
|
||||||
|
android:interpolator="@android:anim/decelerate_interpolator"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</set>
|
7
app/src/main/res/anim/layout_animation_fall_down.xml
Normal file
7
app/src/main/res/anim/layout_animation_fall_down.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layoutAnimation
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:animation="@anim/item_animation_fall_down"
|
||||||
|
android:delay="15%"
|
||||||
|
android:animationOrder="normal"
|
||||||
|
/>
|
|
@ -19,5 +19,6 @@
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:scrollbars="vertical"
|
android:scrollbars="vertical"
|
||||||
android:id="@+id/rvKeyProfiles"
|
android:id="@+id/rvKeyProfiles"
|
||||||
|
android:layoutAnimation="@anim/layout_animation_fall_down"
|
||||||
android:layout_weight="1"/>
|
android:layout_weight="1"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue