Skip to content

Commit

Permalink
Add fast scrolling to cards listing
Browse files Browse the repository at this point in the history
If the user wanted to scroll to the end of the card lists in a fast way, she would need to make a lot of flings. Now this is possible with a fast scroller.

Thanks to https://github.com/L4Digital/FastScroll project

Fix #43
  • Loading branch information
franciscojunior committed Jun 30, 2017
1 parent 549179f commit d8ec998
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,6 @@ dependencies {
compile 'com.jsibbold:zoomage:1.0.0'

compile 'net.opacapp:multiline-collapsingtoolbar:1.3.1'

compile 'com.l4digital.fastscroll:fastscroll:1.0.4'
}
11 changes: 10 additions & 1 deletion app/src/main/java/name/vampidroid/CryptCardsListViewAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.l4digital.fastscroll.FastScroller;

/**
* Created by fxjr on 17/03/16.
*/

public class CryptCardsListViewAdapter extends CursorRecyclerAdapter<CryptCardsListViewAdapter.ViewHolder> {
public class CryptCardsListViewAdapter extends CursorRecyclerAdapter<CryptCardsListViewAdapter.ViewHolder>
implements FastScroller.SectionIndexer
{


View.OnClickListener editDeckListener = new View.OnClickListener() {
Expand Down Expand Up @@ -66,6 +70,11 @@ public void onBindViewHolderCursor(ViewHolder viewHolder, Cursor cursor) {
Utils.loadCardImageThumbnail(viewHolder.imageViewCardImage, Utils.getCardFileName(cardName, viewHolder.txtCardAdv.length() > 0), R.drawable.gold_back);
}

@Override
public String getSectionText(int position) {
return getCursor().getString(1).substring(0, 1);
}

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.l4digital.fastscroll.FastScroller;

/**
* Created by fxjr on 17/03/16.
*/
public class LibraryCardsListViewAdapter extends CursorRecyclerAdapter<LibraryCardsListViewAdapter.ViewHolder> {
public class LibraryCardsListViewAdapter extends CursorRecyclerAdapter<LibraryCardsListViewAdapter.ViewHolder>
implements FastScroller.SectionIndexer
{


public LibraryCardsListViewAdapter(Context context, Cursor cursor) {
Expand Down Expand Up @@ -66,6 +70,11 @@ public void onBindViewHolderCursor(ViewHolder viewHolder, Cursor cursor) {

}

@Override
public String getSectionText(int position) {
return getCursor().getString(1).substring(0, 1);
}

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/name/vampidroid/ViewPagerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public boolean isViewFromObject(View view, Object object) {
@Override
public Object instantiateItem(ViewGroup container, int position) {

RecyclerView recyclerView = (RecyclerView) LayoutInflater.from(context).inflate(R.layout.fragment_cards_list, container, false);
View v = LayoutInflater.from(context).inflate(R.layout.fragment_cards_list, container, false);


RecyclerView recyclerView = v.findViewById(R.id.my_recycler_view);


// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
Expand All @@ -56,9 +60,9 @@ public Object instantiateItem(ViewGroup container, int position) {

recyclerView.setAdapter(recyclerViewsAdapters[position]);

container.addView(recyclerView);
container.addView(v);

return recyclerView;
return v;

}

Expand Down
23 changes: 19 additions & 4 deletions app/src/main/res/layout/fragment_cards_list.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:layout_height="match_parent">

<com.l4digital.fastscroll.FastScrollRecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:bubbleColor="@color/colorAccent"
app:bubbleTextColor="#ffffff"
app:handleColor="@color/colorAccent"
app:trackColor="#bbbbbb"
app:hideScrollbar="true"
app:showTrack="true"
android:paddingEnd="10dp"
android:paddingRight="10dp" />

</FrameLayout>

0 comments on commit d8ec998

Please sign in to comment.