├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── build.gradle ├── gif ├── cbp.gif ├── custom.gif └── lbp.gif ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── uz │ │ └── jamshid │ │ └── library │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── uz │ │ │ └── jamshid │ │ │ └── library │ │ │ ├── IGRefreshLayout.kt │ │ │ └── progress_bar │ │ │ ├── BaseProgressBar.kt │ │ │ ├── CircleProgressBar.kt │ │ │ └── LineProgressBar.kt │ └── res │ │ ├── drawable │ │ └── ic_smile.xml │ │ └── values │ │ ├── attrs.xml │ │ └── strings.xml │ └── test │ └── java │ └── uz │ └── jamshid │ └── library │ └── ExampleUnitTest.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── uz │ │ └── jamshid │ │ └── igrefreshlayout │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── uz │ │ │ └── jamshid │ │ │ └── igrefreshlayout │ │ │ ├── Circle.kt │ │ │ ├── MainActivity.kt │ │ │ └── RVAdapter.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ └── item_view.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── uz │ └── jamshid │ └── igrefreshlayout │ └── ExampleUnitTest.kt └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 13 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # IGRefreshLayout 2 | 3 | [![](https://jitpack.io/v/Jamshid-M/IGRefreshLayout.svg)](https://jitpack.io/#Jamshid-M/IGRefreshLayout) 4 | 5 | [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-IGRefreshLayout-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7859) 6 | 7 | 8 | ## Instagram like refresh layout 9 | 10 | #### It is similar to pull to refresh layout, which has in instagram.
11 | #### Main idea was taken from https://github.com/Yalantis/Phoenix and behaviour of layout was changed. 12 | 13 | 14 | ![Alt Text](https://github.com/Jamshid-M/IGRefreshLayout/blob/master/gif/cbp.gif) 15 | ![Alt Text](https://github.com/Jamshid-M/IGRefreshLayout/blob/master/gif/lbp.gif) 16 | 17 | ## Usage 18 | 19 | Add it in your root build.gradle at the end of repositories 20 | ``` 21 | repositories { 22 | 23 | maven { url 'https://jitpack.io' } 24 | } 25 | ``` 26 | 27 | For a working implementation check out source from sample directory 28 | ``` 29 | dependencies { 30 | implementation 'com.github.Jamshid-M:IGRefreshLayout:1.0.3' 31 | } 32 | ``` 33 | 34 | Include IGRefreshLayout in your xml and put inside ListView or Recyclerview 35 | 36 | ``` 37 | 47 | 48 | 53 | 54 | 55 | ``` 56 | 57 | Open activity and specify IGRefreshLayout object and setup InstaRefreshCallback 58 | 59 | ``` 60 | var swipe = findViewById(R.id.swipe) 61 | swipe.setRefreshListener { 62 | Handler().postDelayed({ 63 | swipe.setRefreshing(false) 64 | }, 3000) 65 | } 66 | ``` 67 | 68 | You can use lambda callback or callback through object 69 | 70 | Enabling and disabling refreshing state 71 | ``` 72 | swipe.setRefreshing(false) 73 | ``` 74 | 75 | Using custom views 76 | ``` 77 | swipe.setCustomBar(CircleProgressBar(this)) 78 | ``` 79 | or 80 | ``` 81 | swipe.setCustomBar(LineProgressBar(this)) 82 | ``` 83 | 84 | You can also change color and width of line 85 | ``` 86 | val cp = CircleProgressBar(this) 87 | cp.setColors(Color.RED, Color.BLUE) 88 | cp.setBorderWidth(4) 89 | 90 | val lp = LineProgressBar(this) 91 | lp.setColors(Color.RED, Color.BLUE) 92 | lp.setBorderWidth(4) 93 | ``` 94 | 95 | Use your own view e.g Android components (Button, ImageView, TextView should be View) 96 | 97 | ![Alt Text](https://github.com/Jamshid-M/IGRefreshLayout/blob/master/gif/custom.gif) 98 | 99 | Extend it from BaseProgressBar 100 | ``` 101 | class Circle @JvmOverloads constructor( 102 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 103 | ) : BaseProgressBar(context, attrs, defStyleAttr) 104 | ``` 105 | 106 | Specify view you want in custom view 107 | ``` 108 | var bar = ImageView(context) 109 | ``` 110 | 111 | And call setCustomView method in mParent object 112 | ``` 113 | mParent.setCustomView(bar, dp2px(80), dp2px(80)) 114 | ``` 115 | 116 | That's all, after that you can bind your view into percent which cames from IGRefreshLayout 117 | ``` 118 | override fun setPercent(percent: Float) { 119 | mPercent = percent 120 | bar.alpha = percent/100 121 | } 122 | ``` 123 | For detailed info go to sample directory and check out Circle.kt class 124 | 125 | 126 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.41' 5 | ext.kotlin_version = '1.3.40' 6 | repositories { 7 | google() 8 | jcenter() 9 | 10 | } 11 | dependencies { 12 | classpath 'com.android.tools.build:gradle:3.4.2' 13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 14 | // NOTE: Do not place your application dependencies here; they belong 15 | // in the individual module build.gradle files 16 | } 17 | } 18 | 19 | allprojects { 20 | repositories { 21 | google() 22 | jcenter() 23 | maven { url 'https://jitpack.io' } 24 | } 25 | } 26 | 27 | task clean(type: Delete) { 28 | delete rootProject.buildDir 29 | } 30 | -------------------------------------------------------------------------------- /gif/cbp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/gif/cbp.gif -------------------------------------------------------------------------------- /gif/custom.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/gif/custom.gif -------------------------------------------------------------------------------- /gif/lbp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/gif/lbp.gif -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Aug 16 11:58:59 UZT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android-extensions' 3 | apply plugin: 'kotlin-android' 4 | 5 | android { 6 | compileSdkVersion 28 7 | buildToolsVersion "29.0.2" 8 | 9 | 10 | defaultConfig { 11 | minSdkVersion 21 12 | targetSdkVersion 28 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | 32 | implementation 'androidx.appcompat:appcompat:1.0.2' 33 | implementation "androidx.core:core-ktx:1.0.2" 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test:runner:1.2.0' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 38 | } 39 | repositories { 40 | mavenCentral() 41 | } 42 | -------------------------------------------------------------------------------- /library/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /library/src/androidTest/java/uz/jamshid/library/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package uz.jamshid.library; 2 | 3 | import android.content.Context; 4 | import androidx.test.InstrumentationRegistry; 5 | import androidx.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("uz.jamshid.library.test", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | -------------------------------------------------------------------------------- /library/src/main/java/uz/jamshid/library/IGRefreshLayout.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.library 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.util.AttributeSet 6 | import android.view.MotionEvent 7 | import android.view.View 8 | import android.view.ViewConfiguration 9 | import android.view.ViewGroup 10 | import android.view.animation.* 11 | import androidx.core.content.ContextCompat 12 | import androidx.core.view.ViewCompat 13 | import androidx.customview.widget.ViewDragHelper.INVALID_POINTER 14 | import uz.jamshid.library.progress_bar.BaseProgressBar 15 | import uz.jamshid.library.progress_bar.CircleProgressBar 16 | import java.lang.Exception 17 | import kotlin.math.* 18 | 19 | 20 | class IGRefreshLayout @JvmOverloads constructor( 21 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 22 | ) : ViewGroup(context, attrs, defStyleAttr) { 23 | 24 | private val DRAG_RATE = .5f 25 | var DRAG_MAX_DISTANCE = 120 26 | private val MAX_OFFSET_ANIMATION_DURATION = 700 27 | private val DECELERATE_INTERPOLATION_FACTOR = 2f 28 | 29 | var mDecelerateInterpolator: Interpolator?=null 30 | private var mTarget: View? = null 31 | private var mTargetPaddingTop: Int = 0 32 | private var mTargetPaddingBottom: Int = 0 33 | private var mTargetPaddingRight: Int = 0 34 | private var mTargetPaddingLeft: Int = 0 35 | private var mRefreshing = false 36 | private var mNotify = false 37 | private var mCurrentOffsetTop = 0 38 | private var mActivePointerId = 0 39 | private var mIsBeingDragged = false 40 | private var mTouchSlop = 0 41 | private var mCurrentDragPercent = 0f 42 | private var mTotalDragDistance = 0 43 | private var mInitialMotionY = 0 44 | private var mFrom: Int = 0 45 | private var mFromDragPercent = 0f 46 | 47 | private var mBar: BaseProgressBar = CircleProgressBar(context) 48 | private var callback: InstaRefreshCallback?=null 49 | private var customViewSet = false 50 | private var customView: View?=null 51 | private var customViewHeight: Int = 0 52 | private var customViewWidth: Int = 0 53 | 54 | init { 55 | mDecelerateInterpolator = DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR) 56 | mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop 57 | 58 | setRefreshing(false) 59 | setupAttributes(attrs) 60 | mTotalDragDistance = dp2px(DRAG_MAX_DISTANCE) 61 | setBackgroundColor(Color.WHITE) 62 | 63 | setWillNotDraw(false) 64 | ViewCompat.setChildrenDrawingOrderEnabled(this, true) 65 | } 66 | 67 | private fun setupAttributes(attrs: AttributeSet?){ 68 | val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.IGRefreshLayout, 69 | 0, 0) 70 | 71 | DRAG_MAX_DISTANCE = typedArray.getInt(R.styleable.IGRefreshLayout_offsetTop, 120) 72 | 73 | if(!typedArray.getBoolean(R.styleable.IGRefreshLayout_customBar, false)){ 74 | setDefaultBar() 75 | customViewSet = true 76 | } 77 | } 78 | 79 | private fun setDefaultBar(){ 80 | mBar.setParent(this) 81 | addView(mBar) 82 | } 83 | 84 | fun setCustomBar(bar: BaseProgressBar){ 85 | if(customViewSet) 86 | throw Exception("ViewGroup can contain only one customBar") 87 | customViewSet = true 88 | mBar = bar 89 | mBar.setParent(this) 90 | addView(mBar, 0) 91 | } 92 | 93 | fun setCustomView(view: View, height: Int, width: Int){ 94 | customView = view 95 | customViewHeight = height 96 | customViewWidth = width 97 | addView(view, 0) 98 | } 99 | 100 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { 101 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) 102 | 103 | ensureTarget() 104 | if(!customViewSet) 105 | throw Exception("Custom View has not been initialized") 106 | if (mTarget == null) 107 | return 108 | 109 | val width = MeasureSpec.makeMeasureSpec(measuredWidth - paddingRight - paddingLeft, MeasureSpec.EXACTLY) 110 | val height = MeasureSpec.makeMeasureSpec(measuredHeight - paddingTop - paddingBottom, MeasureSpec.EXACTLY) 111 | 112 | mTarget?.measure(width, height) 113 | mBar.measure(width, height) 114 | if(customView!=null) 115 | customView?.measure(width, height) 116 | } 117 | 118 | private fun ensureTarget(){ 119 | if (mTarget != null) 120 | return 121 | 122 | if (childCount > 0){ 123 | for(i in 0 until childCount){ 124 | val child = getChildAt(i) 125 | if(child != mBar) { 126 | mTarget = child 127 | if(mTarget?.background == null) 128 | mTarget?.setBackgroundColor(ContextCompat.getColor(context, android.R.color.white)) 129 | mTargetPaddingTop = mTarget?.paddingTop!! 130 | mTargetPaddingBottom = mTarget?.paddingBottom!! 131 | mTargetPaddingRight = mTarget?.paddingRight!! 132 | mTargetPaddingLeft = mTarget?.paddingLeft!! 133 | } 134 | } 135 | } 136 | } 137 | 138 | override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean { 139 | 140 | if(!isEnabled||canChildScrollUp()||mRefreshing){ 141 | return false 142 | } 143 | 144 | when(ev?.actionMasked){ 145 | MotionEvent.ACTION_DOWN -> { 146 | setTargetOffsetTop(0) 147 | mActivePointerId = ev.getPointerId(0) 148 | mIsBeingDragged = false 149 | val initialMotionY = getMotionEventY(ev, mActivePointerId) 150 | if (initialMotionY == -1) { 151 | return false 152 | } 153 | mInitialMotionY = initialMotionY 154 | } 155 | MotionEvent.ACTION_MOVE -> { 156 | if (mActivePointerId == INVALID_POINTER) { 157 | return false 158 | } 159 | 160 | val y = getMotionEventY(ev, mActivePointerId) 161 | if (y == -1) { 162 | return false 163 | } 164 | 165 | val yDiff = y - mInitialMotionY; 166 | if (yDiff > mTouchSlop && !mIsBeingDragged) { 167 | mIsBeingDragged = true 168 | } 169 | } 170 | MotionEvent.ACTION_CANCEL -> { 171 | mIsBeingDragged = false 172 | mActivePointerId = INVALID_POINTER 173 | } 174 | MotionEvent.ACTION_POINTER_UP -> { 175 | onSecondaryPointerUp(ev) 176 | } 177 | } 178 | return mIsBeingDragged 179 | } 180 | 181 | override fun onTouchEvent(ev: MotionEvent?): Boolean { 182 | 183 | if (!mIsBeingDragged) { 184 | return super.onTouchEvent(ev) 185 | } 186 | 187 | when(ev?.actionMasked){ 188 | MotionEvent.ACTION_MOVE -> { 189 | val pointerIndex = ev.findPointerIndex(mActivePointerId) 190 | if(pointerIndex < 0){ 191 | return false 192 | } 193 | val y = ev.getY(pointerIndex) 194 | val yDiff = y - mInitialMotionY 195 | val scrollTop = yDiff * DRAG_RATE 196 | mCurrentDragPercent = scrollTop / mTotalDragDistance 197 | if (mCurrentDragPercent < 0) { 198 | return false 199 | } 200 | val boundedDragPercent = min(1f, abs(mCurrentDragPercent)) 201 | val extraOS = abs(scrollTop) - mTotalDragDistance 202 | val slingshotDist = mTotalDragDistance.toFloat() 203 | val tensionSlingshotPercent = max(0f, min(extraOS, slingshotDist * 2) / slingshotDist) 204 | val tensionPercent = ((tensionSlingshotPercent / 4) - (tensionSlingshotPercent / 4).pow(2))*2f 205 | val extraMove = slingshotDist * tensionPercent / 2 206 | val targetY = (slingshotDist * boundedDragPercent + extraMove).toInt() 207 | 208 | val offsetScrollTop = scrollTop - (mTotalDragDistance/2) 209 | if(offsetScrollTop>0) { 210 | mBar.setPercent(200 * offsetScrollTop/mTotalDragDistance) 211 | mCurrentDragPercent = offsetScrollTop/mTotalDragDistance * 2 212 | } 213 | setTargetOffsetTop(targetY - mCurrentOffsetTop) 214 | } 215 | MotionEvent.ACTION_POINTER_DOWN -> { 216 | val index = ev.actionIndex 217 | mActivePointerId = ev.getPointerId(index) 218 | } 219 | MotionEvent.ACTION_POINTER_UP -> { 220 | onSecondaryPointerUp(ev) 221 | } 222 | MotionEvent.ACTION_UP -> { 223 | if (mActivePointerId == INVALID_POINTER) { 224 | return false 225 | } 226 | val pointerIndex = ev.findPointerIndex(mActivePointerId) 227 | val y = ev.getY(pointerIndex) 228 | val overScrollTop = (y - mInitialMotionY) * DRAG_RATE 229 | mIsBeingDragged = false 230 | if (overScrollTop > mTotalDragDistance) { 231 | setRefreshing(true, true) 232 | }else { 233 | mRefreshing = false 234 | animateOffsetToStartPosition() 235 | } 236 | mActivePointerId = INVALID_POINTER 237 | return false 238 | } 239 | 240 | } 241 | 242 | return true 243 | } 244 | 245 | private fun canChildScrollUp(): Boolean{ 246 | return ViewCompat.canScrollVertically(mTarget, -1) 247 | } 248 | 249 | private fun setTargetOffsetTop(offset: Int){ 250 | mTarget?.offsetTopAndBottom(offset) 251 | mCurrentOffsetTop = mTarget?.top!! 252 | } 253 | 254 | private fun getMotionEventY(ev: MotionEvent, activePointerId: Int): Int{ 255 | val index = ev.findPointerIndex(activePointerId) 256 | if(index < 0) 257 | return -1 258 | 259 | return ev.getY(index).toInt() 260 | } 261 | 262 | private fun onSecondaryPointerUp(ev: MotionEvent){ 263 | val pointerIndex = ev.actionIndex 264 | val pointerId = ev.getPointerId(pointerIndex) 265 | if (pointerId == mActivePointerId) { 266 | val newPointerIndex = if (pointerIndex == 0) 1 else 0 267 | mActivePointerId = ev.getPointerId(newPointerIndex) 268 | } 269 | } 270 | 271 | fun dp2px(dp: Int): Int{ 272 | val density = context.resources.displayMetrics.density 273 | return (dp.toFloat() * density).roundToInt() 274 | } 275 | 276 | 277 | private fun moveToStart(interpolatedTime: Float) { 278 | val targetTop = mFrom - (mFrom * interpolatedTime).toInt() 279 | val targetPercent = mFromDragPercent * (1.0f - interpolatedTime) 280 | val offset = targetTop - mTarget?.top!! 281 | mCurrentDragPercent = targetPercent 282 | mBar.setPercent(100*mCurrentDragPercent) 283 | mTarget?.setPadding(mTargetPaddingLeft, mTargetPaddingTop, mTargetPaddingRight, mTargetPaddingBottom + targetTop) 284 | setTargetOffsetTop(offset) 285 | } 286 | 287 | fun setRefreshing(refreshing: Boolean) { 288 | if (mRefreshing != refreshing) { 289 | setRefreshing(refreshing, false /* notify */) 290 | } 291 | } 292 | 293 | private fun setRefreshing(refreshing: Boolean, notify: Boolean) { 294 | if (mRefreshing != refreshing) { 295 | mNotify = notify 296 | ensureTarget() 297 | mRefreshing = refreshing 298 | if (mRefreshing) { 299 | mBar.setPercent(1f) 300 | animateOffsetToCorrectPosition() 301 | } else { 302 | animateOffsetToStartPosition() 303 | } 304 | } 305 | } 306 | 307 | private fun animateOffsetToStartPosition() { 308 | mFrom = mCurrentOffsetTop 309 | mFromDragPercent = mCurrentDragPercent 310 | val animationDuration = abs((MAX_OFFSET_ANIMATION_DURATION * mFromDragPercent).toLong()) 311 | 312 | mAnimateToStartPosition.reset() 313 | mAnimateToStartPosition.duration = animationDuration 314 | mAnimateToStartPosition.interpolator = mDecelerateInterpolator 315 | mAnimateToStartPosition.setAnimationListener(mToStartListener) 316 | mBar.stop() 317 | mBar.clearAnimation() 318 | mBar.startAnimation(mAnimateToStartPosition) 319 | } 320 | 321 | private fun animateOffsetToCorrectPosition() { 322 | mFrom = mCurrentOffsetTop 323 | mFromDragPercent = mCurrentDragPercent 324 | 325 | mAnimateToCorrectPosition.reset() 326 | mAnimateToCorrectPosition.duration = MAX_OFFSET_ANIMATION_DURATION.toLong() 327 | mAnimateToCorrectPosition.interpolator = mDecelerateInterpolator 328 | 329 | mBar.clearAnimation() 330 | mBar.startAnimation(mAnimateToCorrectPosition) 331 | if (mRefreshing) { 332 | mBar.start() 333 | if (mNotify) { 334 | callback?.onRefresh() 335 | } 336 | } else { 337 | mBar.stop() 338 | animateOffsetToStartPosition() 339 | } 340 | mCurrentOffsetTop = mTarget?.top!! 341 | mTarget?.setPadding(mTargetPaddingLeft, mTargetPaddingTop, mTargetPaddingRight, mTotalDragDistance) 342 | } 343 | 344 | private val mAnimateToStartPosition = object : Animation() { 345 | public override fun applyTransformation(interpolatedTime: Float, t: Transformation) { 346 | moveToStart(interpolatedTime) 347 | } 348 | } 349 | 350 | private val mAnimateToCorrectPosition = object : Animation() { 351 | override fun applyTransformation(interpolatedTime: Float, t: Transformation) { 352 | val targetTop: Int 353 | val endTarget = mTotalDragDistance 354 | targetTop = mFrom + ((endTarget - mFrom) * interpolatedTime).toInt() 355 | val offset = targetTop - mTarget?.top!! 356 | 357 | mCurrentDragPercent = mFromDragPercent - (mFromDragPercent - 1.0f) * interpolatedTime 358 | mBar.setPercent(100*mCurrentDragPercent) 359 | 360 | setTargetOffsetTop(offset) 361 | } 362 | } 363 | 364 | private val mToStartListener = object : Animation.AnimationListener { 365 | override fun onAnimationStart(animation: Animation) {} 366 | 367 | override fun onAnimationRepeat(animation: Animation) {} 368 | 369 | override fun onAnimationEnd(animation: Animation) { 370 | mBar.stop() 371 | mCurrentOffsetTop = mTarget?.top!! 372 | } 373 | } 374 | 375 | fun getTotalDragDistance(): Int { 376 | return mTotalDragDistance 377 | } 378 | 379 | 380 | override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) { 381 | 382 | ensureTarget() 383 | if (mTarget == null) 384 | return 385 | 386 | val height = measuredHeight 387 | val width = measuredWidth 388 | val left = paddingLeft 389 | val top = paddingTop 390 | val right = paddingRight 391 | val bottom = paddingBottom 392 | 393 | mTarget?.layout(left, top + mCurrentOffsetTop, left + width - right, top + height - bottom + mCurrentOffsetTop) 394 | mBar.layout(left, top, left+width-right, top+height-bottom) 395 | if(customView!=null) { 396 | if(DRAG_MAX_DISTANCE - customViewHeight <= 0) 397 | customView?.layout(left, top+dp2px(30), left + width - right, customViewHeight+dp2px(30)) 398 | else { 399 | val diff = DRAG_MAX_DISTANCE - customViewHeight 400 | val center = (width - customViewWidth)/2 401 | customView?.layout(center, diff/2, customViewWidth+center, DRAG_MAX_DISTANCE - diff/2) 402 | } 403 | } 404 | } 405 | 406 | fun setRefreshListener(action:()->Unit){ 407 | this.callback = object : InstaRefreshCallback{ 408 | override fun onRefresh() = action() 409 | } 410 | } 411 | 412 | fun setRefreshListener(callback: InstaRefreshCallback){ 413 | this.callback = callback 414 | } 415 | 416 | interface InstaRefreshCallback{ 417 | fun onRefresh() 418 | } 419 | } -------------------------------------------------------------------------------- /library/src/main/java/uz/jamshid/library/progress_bar/BaseProgressBar.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.library.progress_bar 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import android.view.View 6 | import uz.jamshid.library.IGRefreshLayout 7 | 8 | abstract class BaseProgressBar @JvmOverloads constructor( 9 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 10 | ) : View(context, attrs, defStyleAttr) { 11 | 12 | lateinit var mParent: IGRefreshLayout 13 | var mPercent = 0f 14 | var isLoading = false 15 | 16 | abstract fun setPercent(percent: Float) 17 | abstract fun setParent(parent: IGRefreshLayout) 18 | abstract fun start() 19 | abstract fun stop() 20 | 21 | fun dp2px(dp: Int): Int{ 22 | return dp*context.resources.displayMetrics.density.toInt() 23 | } 24 | } -------------------------------------------------------------------------------- /library/src/main/java/uz/jamshid/library/progress_bar/CircleProgressBar.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.library.progress_bar 2 | 3 | import android.animation.Animator 4 | import android.animation.ValueAnimator 5 | import android.content.Context 6 | import android.graphics.Canvas 7 | import android.graphics.Color 8 | import android.graphics.Paint 9 | import android.graphics.RectF 10 | import android.util.AttributeSet 11 | import android.view.animation.Animation 12 | import android.view.animation.LinearInterpolator 13 | import android.view.animation.ScaleAnimation 14 | import uz.jamshid.library.IGRefreshLayout 15 | 16 | 17 | class CircleProgressBar @JvmOverloads constructor( 18 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 19 | ) : BaseProgressBar(context, attrs, defStyleAttr){ 20 | 21 | private val paint = Paint(Paint.ANTI_ALIAS_FLAG) 22 | 23 | private var backColor = Color.LTGRAY 24 | private var frontColor = Color.GRAY 25 | private val backPaint = Paint(Paint.ANTI_ALIAS_FLAG) 26 | 27 | private var borderWidth = dp2px(4).toFloat() 28 | 29 | private var size = dp2px(80) 30 | private var mIndeterminateSweep: Float = 0f 31 | private var mStartAngle: Float = 0f 32 | 33 | private var mRect: RectF? = null 34 | private var progressAnimator: ValueAnimator? = null 35 | 36 | init { 37 | paint.color = frontColor 38 | paint.style = Paint.Style.STROKE 39 | paint.strokeWidth = borderWidth 40 | backPaint.color = backColor 41 | backPaint.style = Paint.Style.STROKE 42 | backPaint.strokeWidth = borderWidth 43 | 44 | mRect = RectF() 45 | mIndeterminateSweep = 85f 46 | 47 | } 48 | 49 | fun setBorderWidth(width: Int){ 50 | paint.strokeWidth = dp2px(width).toFloat() 51 | backPaint.strokeWidth = dp2px(width).toFloat() 52 | } 53 | 54 | fun setColors(backColor: Int, frontColor: Int){ 55 | paint.color = frontColor 56 | backPaint.color = backColor 57 | } 58 | 59 | fun setSize(px: Int){ 60 | size = (px * context.resources.displayMetrics.density).toInt() 61 | } 62 | 63 | override fun onDraw(canvas: Canvas?) { 64 | super.onDraw(canvas) 65 | mRect?.apply { 66 | left = ((width - size/2)/2).toFloat() 67 | top = mParent.DRAG_MAX_DISTANCE / 3f 68 | right = mRect?.left!! + size/2 69 | bottom = mRect?.top!! + size/2 70 | } 71 | 72 | canvas?.drawArc(mRect!!, 270f, 360f, false, backPaint) 73 | 74 | if(isLoading) 75 | canvas?.drawArc(mRect!!, mStartAngle, mIndeterminateSweep, false, paint) 76 | else 77 | drawProgress(canvas!!) 78 | } 79 | 80 | 81 | private fun drawProgress(canvas: Canvas){ 82 | canvas.drawArc(mRect!!, 270f, mPercent*3.6f, false, paint) 83 | } 84 | 85 | override fun setParent(parent: IGRefreshLayout) { 86 | mParent = parent 87 | } 88 | 89 | override fun setPercent(percent: Float) { 90 | mPercent = if (percent >= 100f) 100f else percent 91 | invalidate() 92 | } 93 | 94 | override fun start() { 95 | isLoading = true 96 | resetAnimation() 97 | } 98 | 99 | override fun stop() { 100 | stopAnimation() 101 | } 102 | 103 | private fun resetAnimation(){ 104 | if(progressAnimator != null && progressAnimator!!.isRunning) 105 | progressAnimator?.cancel() 106 | 107 | progressAnimator = ValueAnimator.ofFloat(0f, 360f) 108 | progressAnimator?.duration = 500 109 | progressAnimator?.interpolator = LinearInterpolator() 110 | progressAnimator?.addUpdateListener { 111 | mStartAngle = it.animatedValue as Float 112 | invalidate() 113 | } 114 | progressAnimator?.start() 115 | progressAnimator?.addListener(object : Animator.AnimatorListener{ 116 | override fun onAnimationRepeat(p0: Animator?) { 117 | 118 | } 119 | 120 | override fun onAnimationEnd(p0: Animator?) { 121 | resetAnimation() 122 | } 123 | 124 | override fun onAnimationCancel(p0: Animator?) { 125 | 126 | } 127 | 128 | override fun onAnimationStart(p0: Animator?) { 129 | 130 | } 131 | 132 | }) 133 | } 134 | 135 | private fun stopAnimation(){ 136 | isLoading = false 137 | 138 | if(progressAnimator != null) { 139 | progressAnimator?.cancel() 140 | progressAnimator?.removeAllListeners() 141 | progressAnimator = null 142 | } 143 | } 144 | } -------------------------------------------------------------------------------- /library/src/main/java/uz/jamshid/library/progress_bar/LineProgressBar.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.library.progress_bar 2 | 3 | import android.animation.Animator 4 | import android.animation.ValueAnimator 5 | import android.content.Context 6 | import android.graphics.Canvas 7 | import android.graphics.Color 8 | import android.graphics.Paint 9 | import android.util.AttributeSet 10 | import android.view.animation.LinearInterpolator 11 | import uz.jamshid.library.IGRefreshLayout 12 | 13 | class LineProgressBar @JvmOverloads constructor( 14 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 15 | ) : BaseProgressBar(context, attrs, defStyleAttr) { 16 | 17 | private val paint = Paint(Paint.ANTI_ALIAS_FLAG) 18 | 19 | private var backColor = Color.LTGRAY 20 | private var frontColor = Color.GRAY 21 | private val backPaint = Paint(Paint.ANTI_ALIAS_FLAG) 22 | private var borderWidth = dp2px(4).toFloat() 23 | private var left = dp2px(10).toFloat() 24 | private var top = dp2px(60).toFloat() 25 | private var isLoaded = false 26 | 27 | private var progressAnimator: ValueAnimator? = null 28 | 29 | private var loadingPercent = 0f 30 | 31 | init { 32 | paint.color = frontColor 33 | paint.style = Paint.Style.STROKE 34 | paint.strokeWidth = borderWidth 35 | backPaint.color = backColor 36 | backPaint.style = Paint.Style.STROKE 37 | backPaint.strokeWidth = borderWidth 38 | } 39 | 40 | fun setLeftAndTop(left: Int, top: Int){ 41 | this.left = dp2px(left).toFloat() 42 | this.top = dp2px(top).toFloat() 43 | } 44 | 45 | fun setBorderWidth(width: Int){ 46 | paint.strokeWidth = dp2px(width).toFloat() 47 | backPaint.strokeWidth = dp2px(width).toFloat() 48 | } 49 | 50 | fun setColors(backColor: Int, frontColor: Int){ 51 | paint.color = frontColor 52 | backPaint.color = backColor 53 | } 54 | 55 | override fun onDraw(canvas: Canvas?) { 56 | super.onDraw(canvas) 57 | 58 | top = (mParent.DRAG_MAX_DISTANCE/2).toFloat() 59 | var currentPercent = (width - left)*(mPercent/100) 60 | val lineWidth = width - left 61 | if(currentPercent<=left) 62 | currentPercent = left 63 | 64 | canvas?.drawLine(left, top, lineWidth, top, backPaint) 65 | 66 | if(isLoading){ 67 | if(isLoaded) 68 | canvas?.drawLine(left, top, loadingPercent, top, paint) 69 | else 70 | canvas?.drawLine(loadingPercent, top, lineWidth, top, paint) 71 | }else{ 72 | canvas?.drawLine(left, top, currentPercent, top, paint) 73 | } 74 | } 75 | 76 | override fun setPercent(percent: Float) { 77 | mPercent = if (percent >= 100f) 100f else percent 78 | invalidate() 79 | } 80 | 81 | override fun setParent(parent: IGRefreshLayout) { 82 | mParent = parent 83 | } 84 | 85 | override fun start() { 86 | isLoading = true 87 | mPercent = 0f 88 | resetAnimation() 89 | } 90 | 91 | override fun stop() { 92 | mPercent = 0f 93 | stopAnimation() 94 | } 95 | 96 | 97 | private fun resetAnimation(){ 98 | if(progressAnimator != null && progressAnimator!!.isRunning) 99 | progressAnimator?.cancel() 100 | 101 | progressAnimator = ValueAnimator.ofFloat(left, width.toFloat()) 102 | progressAnimator?.duration = 500 103 | progressAnimator?.interpolator = LinearInterpolator() 104 | progressAnimator?.addUpdateListener { 105 | loadingPercent = it.animatedValue as Float 106 | invalidate() 107 | } 108 | progressAnimator?.start() 109 | progressAnimator?.addListener(object : Animator.AnimatorListener{ 110 | override fun onAnimationRepeat(p0: Animator?) { 111 | 112 | } 113 | 114 | override fun onAnimationEnd(p0: Animator?) { 115 | isLoaded = !isLoaded 116 | resetAnimation() 117 | } 118 | 119 | override fun onAnimationCancel(p0: Animator?) { 120 | 121 | } 122 | 123 | override fun onAnimationStart(p0: Animator?) { 124 | 125 | } 126 | 127 | }) 128 | } 129 | 130 | private fun stopAnimation(){ 131 | isLoading = false 132 | isLoaded = false 133 | if(progressAnimator != null) { 134 | progressAnimator?.cancel() 135 | progressAnimator?.removeAllListeners() 136 | progressAnimator = null 137 | } 138 | } 139 | 140 | } -------------------------------------------------------------------------------- /library/src/main/res/drawable/ic_smile.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /library/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Library 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/uz/jamshid/library/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package uz.jamshid.library; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | buildToolsVersion "29.0.2" 10 | defaultConfig { 11 | applicationId "uz.jamshid.igrefreshlayout" 12 | minSdkVersion 26 13 | targetSdkVersion 28 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 29 | implementation 'androidx.appcompat:appcompat:1.0.2' 30 | implementation 'androidx.core:core-ktx:1.0.2' 31 | implementation 'androidx.recyclerview:recyclerview:1.0.0' 32 | implementation project(':library') 33 | 34 | testImplementation 'junit:junit:4.12' 35 | androidTestImplementation 'androidx.test:runner:1.2.0' 36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 37 | } 38 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/uz/jamshid/igrefreshlayout/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.igrefreshlayout 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.runner.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getTargetContext() 22 | assertEquals("uz.jamshid.igrefreshlayout", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/java/uz/jamshid/igrefreshlayout/Circle.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.igrefreshlayout 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import android.view.animation.Animation 6 | import android.view.animation.RotateAnimation 7 | import android.widget.ImageView 8 | import uz.jamshid.library.IGRefreshLayout 9 | import uz.jamshid.library.progress_bar.BaseProgressBar 10 | 11 | 12 | class Circle @JvmOverloads constructor( 13 | context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 14 | ) : BaseProgressBar(context, attrs, defStyleAttr) { 15 | 16 | var bar = ImageView(context) 17 | init { 18 | bar.setImageResource(R.drawable.ic_smile) 19 | bar.alpha = 0f 20 | } 21 | 22 | override fun setParent(parent: IGRefreshLayout) { 23 | mParent = parent 24 | setUpView() 25 | } 26 | 27 | override fun setPercent(percent: Float) { 28 | mPercent = percent 29 | bar.alpha = percent/100 30 | } 31 | 32 | private fun setUpView(){ 33 | mParent.setCustomView(bar, dp2px(80), dp2px(80)) 34 | } 35 | 36 | override fun start() { 37 | val animation1 = RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f) 38 | animation1.duration = 500 39 | animation1.repeatCount = Animation.INFINITE 40 | bar.startAnimation(animation1) 41 | } 42 | 43 | override fun stop() { 44 | bar.alpha = 0f 45 | bar.clearAnimation() 46 | } 47 | } -------------------------------------------------------------------------------- /sample/src/main/java/uz/jamshid/igrefreshlayout/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.igrefreshlayout 2 | 3 | import android.os.Bundle 4 | import android.os.Handler 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.recyclerview.widget.LinearLayoutManager 7 | import kotlinx.android.synthetic.main.activity_main.* 8 | import uz.jamshid.library.progress_bar.CircleProgressBar 9 | import uz.jamshid.library.progress_bar.LineProgressBar 10 | 11 | class MainActivity : AppCompatActivity() { 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_main) 16 | 17 | rv.layoutManager = LinearLayoutManager(this) 18 | rv.adapter = RVAdapter(listOf("asd","sad","asd")){ 19 | swipe.setRefreshing(false) 20 | } 21 | 22 | swipe.setRefreshListener { 23 | Handler().postDelayed({ 24 | swipe.setRefreshing(false) 25 | }, 3000) 26 | } 27 | 28 | 29 | val cc = CircleProgressBar(this) 30 | cc.setSize(90) 31 | val l = LineProgressBar(this) 32 | // l.setColors(Color.parseColor("#84ff9d"), Color.parseColor("#004500")) 33 | swipe.setCustomBar(Circle(this)) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sample/src/main/java/uz/jamshid/igrefreshlayout/RVAdapter.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.igrefreshlayout 2 | 3 | import android.view.LayoutInflater 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import androidx.recyclerview.widget.RecyclerView 7 | 8 | class RVAdapter(val items: List, val action:()->Unit): RecyclerView.Adapter() { 9 | 10 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { 11 | return ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_view, parent, false)) 12 | } 13 | 14 | override fun getItemCount(): Int { 15 | return 20 16 | } 17 | 18 | override fun onBindViewHolder(holder: ViewHolder, position: Int) { 19 | holder.itemView.setOnClickListener { action() } 20 | // holder.onBind(items[position]) 21 | } 22 | 23 | inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) { 24 | fun onBind(str: String){ 25 | 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 17 | 18 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/item_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jamshid-M/IGRefreshLayout/3f173c9e0b9ea33d6b7b54a3074fcd62474fcf40/sample/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #008577 4 | #00574B 5 | #D81B60 6 | 7 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | IGRefreshLayout 3 | 4 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /sample/src/test/java/uz/jamshid/igrefreshlayout/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package uz.jamshid.igrefreshlayout 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':sample', ':library' 2 | --------------------------------------------------------------------------------