Code Monkey home page Code Monkey logo

igrefreshlayout's Introduction

IGRefreshLayout

Android Arsenal

Instagram like refresh layout

It is similar to pull to refresh layout, which has in instagram.

Main idea was taken from https://github.com/Yalantis/Phoenix and behaviour of layout was changed.

Alt Text Alt Text

Usage

Add it in your root build.gradle at the end of repositories

repositories {

        maven { url 'https://jitpack.io' }
    }

For a working implementation check out source from sample directory

dependencies {
	implementation 'com.github.Jamshid-M:IGRefreshLayout:1.0.3'
}

Include IGRefreshLayout in your xml and put inside ListView or Recyclerview

<uz.jamshid.library.IGRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools" 
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/swipe"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:offsetTop="120"
        app:customBar="true"
        tools:context=".MainActivity">

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
    />

</uz.jamshid.library.IGRefreshLayout>

Open activity and specify IGRefreshLayout object and setup InstaRefreshCallback

        var swipe = findViewById<IGRefreshLayout>(R.id.swipe)
        swipe.setRefreshListener {
            Handler().postDelayed({
                swipe.setRefreshing(false)
            }, 3000)
        }

You can use lambda callback or callback through object

Enabling and disabling refreshing state

swipe.setRefreshing(false)

Using custom views

swipe.setCustomBar(CircleProgressBar(this))

or

swipe.setCustomBar(LineProgressBar(this))

You can also change color and width of line

val cp = CircleProgressBar(this)
cp.setColors(Color.RED, Color.BLUE)
cp.setBorderWidth(4)

val lp = LineProgressBar(this)
lp.setColors(Color.RED, Color.BLUE)
lp.setBorderWidth(4)

Use your own view e.g Android components (Button, ImageView, TextView should be View)

Alt Text

Extend it from BaseProgressBar

class Circle @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : BaseProgressBar(context, attrs, defStyleAttr)

Specify view you want in custom view

var bar = ImageView(context)

And call setCustomView method in mParent object

mParent.setCustomView(bar, dp2px(80), dp2px(80))

That's all, after that you can bind your view into percent which cames from IGRefreshLayout

    override fun setPercent(percent: Float) {
        mPercent = percent
        bar.alpha = percent/100
    }

For detailed info go to sample directory and check out Circle.kt class

igrefreshlayout's People

Contributors

jamshid-m avatar panosx2 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

Watchers

 avatar  avatar  avatar

igrefreshlayout's Issues

java.lang.Exception: Custom View has not been initialized

Hello! I can't get this library to work. I'm getting this error:
Process: com.aromaticnectarineapps.instagramsaver, PID: 14351 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:502) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)ย  Caused by: java.lang.Exception: Custom View has not been initialized at uz.jamshid.library.IGRefreshLayout.onMeasure(IGRefreshLayout.kt:105) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760) at com.google.android.material.appbar.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:99) at com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1892) at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:831) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552) at android.widget.LinearLayout.measureVertical(LinearLayout.java:842) at android.widget.LinearLayout.onMeasure(LinearLayout.java:721) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:760) at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:833) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552) at android.widget.LinearLayout.measureVertical(LinearLayout.java:842) at android.widget.LinearLayout.onMeasure(LinearLayout.java:721) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at android.view.View.measure(View.java:24530) at androidx.drawerlayout.widget.DrawerLayout.onMeasure(DrawerLayout.java:1156) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194) at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1552) at android.widget.LinearLayout.measureVertical(LinearLayout.java:842) at android.widget.LinearLayout.onMeasure(LinearLayout.java:721) at android.view.View.measure(View.java:24530) at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6828) at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)

Tested on API 29. Initialisation code in OnCreateView in fragment.

Update Code

I see it old project but its very useful. If you allow me then i will update it latest versions.

Can't show AppBarLayout upon scrolling up

Issue 1.:

This is my layout:

    <LinearLayout>
        <androidx.coordinatorlayout.widget.CoordinatorLayout>




            <com.google.android.material.appbar.AppBarLayout>
                <androidx.constraintlayout.widget.ConstraintLayout>
                                    --- APPBARLAYOUT CONTENT ---
                </androidx.constraintlayout.widget.ConstraintLayout>
            </com.google.android.material.appbar.AppBarLayout>



            <FrameLayout>
                <uz.jamshid.library.IGRefreshLayout>

                    <androidx.recyclerview.widget.RecyclerView
                        android:id="@+id/recycler_list" />

                </uz.jamshid.library.IGRefreshLayout>
            </FrameLayout>




        </androidx.coordinatorlayout.widget.CoordinatorLayout>
    </LinearLayout>

The appbarlayout scrolls with these flags: app:layout_scrollFlags="scroll|snap|exitUntilCollapsed.
The IGRefreshLayout overrides this scroll, and instead triggers the refresh animation, without letting the appbarlayout show itself first. Scrolling a bit down, and then up again fixes this issue.

Issue 2.:
The same layout, but with the IGRefreshLayout as the top element has this same effect + when scrolling up, the views from the recyclerlayout are not recycled, and the IGRefreshLayout animation triggers again.

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.