Git Product home page Git Product logo

myinnos / alphabetindex-fast-scroll-recyclerview Goto Github PK

View Code? Open in Web Editor NEW
599.0 10.0 114.0 1.97 MB

A Powerful AlphabetIndex FastScroller Library for Android's RecyclerView!

Home Page: https://myinnos.github.io/AlphabetIndex-Fast-Scroll-RecyclerView/

License: Apache License 2.0

Java 1.38% Kotlin 98.62%
android recyclerview indexing android-recyclerview alphabetindex-fastscroller kotlin

alphabetindex-fast-scroll-recyclerview's Introduction

AlphabetIndex Fast Scroll RecyclerView

A Powerful AlphabetIndex FastScroller for Android's RecyclerView!

MyInnos website Android Language Badge

AlphabetIndex-Fast-Scroll-RecyclerView - Example1 AlphabetIndex-Fast-Scroll-RecyclerView - Example2 AlphabetIndex-Fast-Scroll-RecyclerView - Example3

Kindly use the following links to use this library:

In build.gradle (Project)

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

And then in the other gradle file(may be your app gradle or your own module library gradle, but never add in both of them to avoid conflict.)

dependencies {
       implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:2.0'

    // AppCompat version
    // implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.92'
    //	or
    // AndroidX version
    // implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.95'

}

How to use

Step 1: add this to your xml:

<in.myinnos.alphabetsindexfastscrollrecycler.IndexFastScrollRecyclerView
    android:id="@+id/fast_scroller_recycler"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Step 2: implement SectionIndexer to RecyclerViewAdapter.

public class RecyclerViewAdapter extends RecyclerView.Adapter<ViewHolder> implements SectionIndexer {

private List<String> mDataArray;
private ArrayList<Integer> mSectionPositions;
    
.....
    
@Override
public int getSectionForPosition(int position) {
    return 0;
}
 
@Override
public Object[] getSections() {
    List<String> sections = new ArrayList<>(26);
    mSectionPositions = new ArrayList<>(26);
    for (int i = 0, size = mDataArray.size(); i < size; i++) {
        String section = String.valueOf(mDataArray.get(i).charAt(0)).toUpperCase();
        if (!sections.contains(section)) {
            sections.add(section);
            mSectionPositions.add(i);
        }
    }
    return sections.toArray(new String[0]);
}
 
@Override
public int getPositionForSection(int sectionIndex) {
    return mSectionPositions.get(sectionIndex);
}
    
}

Note: mDataArray: this is your recycler data array model.

Features

  • Change IndexTextSize:
 mRecyclerView.setIndexTextSize(12);
  • Change IndexBarTextColor:
 mRecyclerView.setIndexBarTextColor("#FFFFFF");

 mRecyclerView.setIndexBarTextColor(R.color.index_bar_text_color);
  • Change IndexBarColor:
 mRecyclerView.setIndexBarColor("#33334c");

 mRecyclerView.setIndexBarColor(R.color.index_bar_color);
  • Change IndexBarCornerRadius:
 mRecyclerView.setIndexBarCornerRadius(3);
  • Change IndexBarTransparentValue:
mRecyclerView.setIndexBarTransparentValue((float) 0.4);
  • Change IndexBarMargin:
 mRecyclerView.setIndexBarMargin(4);
  • Change IndexBarWidth:
 mRecyclerView.setIndexBarWidth(40);
  • Change PreviewPadding:
 mRecyclerView.setPreviewPadding(2);
  • Change PreviewVisibility:
 mRecyclerView.setPreviewVisibility(false);
  • Change Typeface:
 Typeface typeface = Typeface.createFromAsset(context.getAssets(), "Custom-Font.ttf");
 mRecyclerView.setTypeface(typeface);
  • To hide/show Fast Scroll IndexBar:
mRecyclerView.setIndexBarVisibility(true);
  • Change IndexBarHighLateTextColor:
mRecyclerView.setIndexBarHighLightTextColor("#33334c);

mRecyclerView.setIndexBarHighLightTextColor(R.color.index_bar_highlight_text_color);
  • To hide/show IndexBarHighLightText:
mRecyclerView.setIndexBarHighLightTextVisibility(true);
  • To hide/show IndexBarStroke:
mRecyclerView.setIndexBarStrokeVisibility(true);
  • Change IndexBarStrokeWidth:
mRecyclerView.setIndexBarStrokeWidth(1);
  • Change IndexBarStrokeColor:
mRecyclerView.setIndexBarStrokeColor("#000000");

Compatibility

This library works with any layout manager but is optimized for the use with a LinearLayoutManager.

Any Queries? or Feedback, please let me know by opening a new issue!

Contact

Prabhakar Thota

โšก If you appreciate my work, consider buying me a cup of โ˜• to keep me recharged ๐Ÿค˜ by GitHub or PayPal

Contributing

Thanks to all the people who contributed to AlphabetIndex Fast Scroll RecyclerView

License

Copyright 2017 - 2022 MyInnos

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

alphabetindex-fast-scroll-recyclerview's People

Contributors

abandonedcart avatar appspell avatar benniebotha avatar hamza417 avatar imgbotapp avatar ivanabakumov avatar libernys avatar mflisar avatar myinnos avatar raphaelmarion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alphabetindex-fast-scroll-recyclerview's Issues

Conflict with allowBackup and supportsRTL in manifest file.

For some applications that have allowBackup and/or supportsRtl set to false we receive the following error when trying to use your library:

 Manifest merger failed : Attribute application@allowBackup value=(false) from [:corevero] AndroidManifest.xml:12:9-36
  	is also present at [com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.8] AndroidManifest.xml:12:9-35 value=(true).
  	Suggestion: add 'tools:replace="android:allowBackup"' to <application> element at manifestMerger3423917709392243790.xml:7:5-9:19 to override.

Would it be possible to have those two lines* removed from the manifest of the library? This should resolve the issue for those with different settings without causing any new issues afaik.

Thanks

*android:allowBackup=โ€œtrueโ€
android:supportsRtl=โ€œtrueโ€

java.lang.Object[] cannot be cast to java.lang.String[]

java.lang.Object[] cannot be cast to java.lang.String[]

public void setAdapter(RecyclerView.Adapter adapter) {
if (adapter instanceof SectionIndexer) {
adapter.registerAdapterDataObserver(this);
mIndexer = (SectionIndexer) adapter;
mSections = (String[]) mIndexer.getSections(); <--- erro line(ava.lang.Object[] cannot be cast to java.lang.String[])
}
}

Suggestion: enable setting the indexBarText to be centered horizontally

I love this library, it saves my day, especially your callback allows me to handle position pinning by myself, so that I can list out all alphabets can calculate positions correspondingly even there are no such alphabet.

I found that the text in the text bar now aligns to the right; but I think it would be better for us to control this, like if we can center it horizontally in its parent.

Issues: Index Bar overlapping content || Index Bar Height Matches view Parent

  1. The Index Bar overlaps content. If your ViewHolder layout doesn't have a margin, the Index Bar gets in the way of the content. Its even worse if you give the Index Bar a margin. This is true both for Vertical Views and Grid Views. Could you possibly add and attribute like app:indexBarContentMargin so that the users can set the Index Bar margin from viewHolder content.

  2. When you have few items in your RecyclerView, there are of course less sections for the Index Bar to display. Could you add an option/attribute like app:wrapIndexBarSectionText so that the Index Bar can wrap it's height to the amount of section content in it. Possibly even adding the option setIndexBarGravity="TOP", setIndexBarGravity="Center" and setIndexBarGravity="Bottom".
    Currently the Index Bar spans the full height of the view regardless of how many sections there are to show in it. It looks quite bad when you have few items in your RecyclerView.

Thank you.

setIndexbarWidth() is not using a correct density

According to README and the code inside, I think setIndexbarWidth takes dp as input instead of pixel, since I saw you multiplied this input by mDensity.

However, I tested on 2 devices with different density, it is very clear that the index bar has very different size. The size on a higher density device is much smaller.

I therefore think the conversion from dp to pixel is incorrect.

I usually use the below code to convert from dp to pixel:
public static int pixelFromDp (Resources r, int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()); }

Failed to resolve library

As per your description, I am integrating this library but I got following error.

This is my build.gradle(project) file:
allprojects { repositories { ... maven { url "https://jitpack.io" } } }

build.gradel(app) file

implementation 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.94'

ERROR: Failed to resolve: com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.94

Showing or Hiding the fast scroll

Hi, I want to hide the Fast scroll when user filtering the recycle view and I want to make the Fast scroll visible if the search edit text length is zero. Help me on showing and hiding the Fast scroll.

How to scroll at specific section

I want to scroll it to "F" section when it opens, Is it possible?
have tried with
mAdapter?.let { it.getPositionForSection(6) it.notifyDataSetChanged() }

mAdapter?.let { it.getSectionForPosition(6) it.notifyDataSetChanged() }

Suggestions

I would have following suggestions:

  • change your color attributes to be integers instead of strings
  • remove the transparency parameter => just extract the transparency from the color itself

This breaks your current API though but would fit to the way nearly every android library works. I would add this to my pull request if that's ok for you

ๅธ้กถ

็œ‹็€ๆ–‡็ซ ่ฟ‡ๆฅ็š„ๅปบ่ฎฎๅŠ ๅ…ฅๅธ้กถๆ•ˆๆžœ

Crash while scrolling index & filter

I found there is a crash while scrolling using the index letters(at the right side of the view) and filter.
Please take a look when you get a chance.
Added error log

2019-10-31 12:58:49.414 12373-12373/? E/application: Fatal Exception occurred: length=2; index=24
2019-10-31 12:58:49.417 12373-12373/? E/application: Stack Trace: java.lang.ArrayIndexOutOfBoundsException: length=2; index=24
at in.myinnos.alphabetsindexfastscrollrecycler.IndexFastScrollRecyclerSection.draw(IndexFastScrollRecyclerSection.java:94)
at in.myinnos.alphabetsindexfastscrollrecycler.IndexFastScrollRecyclerView.draw(IndexFastScrollRecyclerView.java:105)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.draw(View.java:20373)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.draw(View.java:20373)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.updateDisplayListIfDirty(View.java:19306)
at android.view.View.draw(View.java:20093)
at android.view.ViewGroup.drawChild(ViewGroup.java:4421)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4207)
at android.view.View.draw(View.java:20373)
at com.android.internal.policy.DecorView.draw(DecorView.java:980)
at android.view.View.updateDisplayListIfDirty(View.java:19315)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:686)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:692)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:800)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:3496)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3283)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2818)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1780)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7827)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)

Using cursor instead of Arraylist scroller shows but does nothing when clicked

What method or component handles the responsibility of the onclick for the alphabet scroller. I have the scroller with all the alphatbets due to successful implementation of the getSections method however I am not sure where the onclick of the scroller functionality is designated. Thanks for your assistance.

onBindViewHolder position value not correctly assigning values

I have a function that looks something like the one below

@OverRide
public void onBindViewHolder(@nonnull ProcedureViewHolder holder, int position) {
if(position % 17 == 0){
holder.procedureName.setTextColor(context.getResources().getColor(R.color.com_facebook_blue));
}
}

and when I run it, the rows that change text color are seemingly random. There are several places where 2 or 3 rows in a row have blue text. For sure there are more than every 17th items whos text is blue

getSections() should be called if adapter calls notifyDataSetChanged()

Normally we set adapter in recyclerview first before we downloaded all items from internet, and set the list later on which at the same time calls notifyDataSetChanged().

But I found that the indexBar doesn't update accordingly. In fact since this is the case, the "sectionPositions" arraylist always remains empty.

not working in appCompect

    mRecyclerView.setPreviewColor("#00FF00");
    mRecyclerView.setPreviewTextColor("#FFFFFF");
    mRecyclerView.setPreviewTransparentValue(0.6f);

@Not working in appCompect

setIndexbarMargin doesn't work

Hi,

I am with AlphabetIndex-Fast-Scroll-RecyclerView:1.0.8 and I have a problem when I try to remove the margin of the IndexBar. I have tried to set the parameter in the layout and the class but neither work.

This is how I put in the layout:
Sometimes I could see how the parameter is apply but when I exit and open the layout again, the IndexBar has margin again.

<in.myinnos.alphabetsindexfastscrollrecycler.IndexFastScrollRecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:setIndexbarMargin="0"
app:setIndexbarWidth="0"
/>

This is how I put in the class:

//Setup recyclerViewFastScroll
mBinding.incRecyclerView.recyclerView.setIndexBarTransparentValue((float) 1.0);
mBinding.incRecyclerView.recyclerView.setIndexBarCornerRadius(0);
mBinding.incRecyclerView.recyclerView.setIndexbarMargin(0);
mBinding.incRecyclerView.recyclerView.setPreviewPadding(0);
mBinding.incRecyclerView.recyclerView.setIndexBarColor("#"+Integer.toHexString(ContextCompat.getColor(mActivity, R.color.color_primary_dark)));
mBinding.incRecyclerView.recyclerView.setIndexbarHighLateTextColor("#"+Integer.toHexString(ContextCompat.getColor(mActivity, R.color.color_eab817)));
mBinding.incRecyclerView.recyclerView.setIndexBarHighLateTextVisibility(true);
mBinding.incRecyclerView.recyclerView.setIndexBarVisibility(true);

I execute in Android 4.4.2 and Android 6.0.1.

What's the problem?

stroller of alphabet got compressed

hello, I am facing an issue while using this library that I am using edit text with this recyclerView so when I click on edit text and keyboard opens up the scroller of alphabets got compressed can you please guide me to fix it.
-thanks for making this library as well

Downloading

When I was putting the line
compile 'com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0'
into the gradle, Android Studio was yelling at me
Error:(44, 13) Failed to resolve: com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0

Implementing the library

The following error occurs when trying to implement:
Could not find com.github.myinnos:AlphabetIndex-Fast-Scroll-RecyclerView:1.0.94.
Searched in the following locations:

Sometimes the bar is empty

I have an app that is constantly running and showing/hiding it's view on demand (a sidebar like app).

What I see is that rarely the fast scroller shows up empty after some time (after many days, hardly reproduceable).

Any ideas what could cause this? I have no idea yet, did check the fast scrollers code but did not find anything that could cause this..

Quick question about color change

So currently I'm working on getting themes to change. Wanna throw something out the window.

Is there anyway to change the color of the text on the scroller? Is there also a way to call from colors.xml to change the color?

Can not set index bar fully transparent

Hello,

I've tried many ways but can not set background of index bar transparent.
I've used:
recyclerView.setIndexBarTransparentValue((float) 0);
recyclerView.setIndexBarColor("#00FFFFFF");
and tried to set it using xml too, but no luck.

Can you help me?
Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.