Skip to content

Commit 1488ccc

Browse files
authored
Merge pull request #1 from timonknispel/develop
Develop
2 parents ed665c3 + 925a444 commit 1488ccc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1679
-1
lines changed

.idea/checkstyle-idea.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

Lines changed: 125 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,112 @@
11
# KTLoadingButton
2-
Simple loading button for kotlin andorid apps
2+
3+
Simple loading button for kotlin andorid apps.
4+
This button can show results in a nicely designed way to not block the ui while the user is waiting.
5+
6+
|SUCCESS| ERROR |
7+
|--|--|
8+
| ![](success.gif) | ![](fail.gif) |
9+
10+
11+
## Installation
12+
1. Add the JitPack repository to your build file
13+
14+
```css
15+
allprojects {
16+
repositories {
17+
...
18+
maven { url 'https://jitpack.io' }
19+
}
20+
}
21+
```
22+
23+
2. Add the dependency
24+
25+
```css
26+
dependencies {
27+
implementation 'com.github.User:Repo:Tag'
28+
}
29+
```
30+
31+
## Usage
32+
### Example needed? Look inside the app folder
33+
34+
1. Add the KTLoadingButton to your layout
35+
36+
```xml
37+
<de.timonknispel.ktloadingbutton.KTLoadingButton
38+
android:id="@+id/test_button"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
app:buttonName="Test"
42+
/>
43+
```
44+
2. DONE
45+
Now all you have to do is to start the button. This can be done in several ways.
46+
47+
#### Option 1: INTERMEDIATE (DEFAULT)
48+
Simply call :
49+
```kotlin
50+
test_button.startLoading()
51+
````
52+
53+
This will start the loading animation of the button. By default it should now intermediate.
54+
55+
When loading is done simply call:
56+
```kotlin
57+
test_button.doResult(success: Boolean)
58+
```
59+
This will stop the loading animation an start the result animation according to the given success.
60+
Optional you can add a callback if you want to know when the animation is done:
61+
```kotlin
62+
test_button.doResult(success: Boolean) {
63+
// do stuff here
64+
}
65+
```
66+
67+
#### Option 2: PROGRESS
68+
Add the progressStyle option to your xml layout:
69+
```xml
70+
<de.timonknispel.ktloadingbutton.KTLoadingButton
71+
android:id="@+id/test_button"
72+
android:layout_width="wrap_content"
73+
android:layout_height="wrap_content"
74+
app:buttonName="Test"
75+
app:progressStyle="PROGRESS"
76+
/>
77+
```
78+
All you have to do now is to call:
79+
```kotlin
80+
test_button.setProgress(progress: Float)
81+
```
82+
to show the progress.
83+
84+
## Good to know
85+
86+
- You can add a callback to the button if you need the click event even if the button is in loading state:
87+
```kotlin
88+
test_button.touchListener = {
89+
// do some stuff
90+
}
91+
```
92+
This can be handy if for example want the user to cancel the loading process.
93+
94+
- You can reset the button by calling:
95+
```kotlin
96+
test_button.reset()
97+
```
98+
99+
## Customization
100+
101+
### In XML
102+
|Attribute| Value/s | Description| Required | Default |
103+
|--|--| -- | -- | -- |
104+
| buttonName | String | Sets the text for the button |[x]| |
105+
| buttonTextSize | Dimension (SP) | Sets the text size for the button |[]| 16sp |
106+
| allCaps | Boolean | If set to true all button text will be in caps |[]| true |
107+
| buttonColor | Color | Sets the color for the button text and progress |[]| #373737|
108+
| loadingBackgroundColor | Color | Sets the background color for a failed result |[]| buttonColor with transparency of 31% |
109+
| succeedColor | Color | Sets the background color for a success result |[]|#4CAF50 |
110+
| failedColor | Color | Sets the background color for a failed result |[]|#F44336 |
111+
| autoResetButtonAfterResult | Boolean | Decides if the button should reset itself after the result was displayed (after 1,5 seconds) |[]| true |
112+
| progressStyle | [INTERMEDIATE or PROGRESS] | Decides if the button should intermediate or display a progress |[]| INTERMEDIATE |

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apply plugin: 'com.android.application'
2+
3+
apply plugin: 'kotlin-android'
4+
5+
apply plugin: 'kotlin-android-extensions'
6+
7+
apply from: "../ktlint.gradle"
8+
9+
android {
10+
compileSdkVersion 29
11+
buildToolsVersion "29.0.2"
12+
defaultConfig {
13+
applicationId "de.timonknispel.ktloadingbutton"
14+
minSdkVersion 22
15+
targetSdkVersion 29
16+
versionCode 1
17+
versionName "1.0"
18+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
}
27+
28+
dependencies {
29+
implementation fileTree(dir: 'libs', include: ['*.jar'])
30+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
31+
implementation 'androidx.appcompat:appcompat:1.1.0'
32+
implementation 'androidx.core:core-ktx:1.1.0'
33+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
34+
testImplementation 'junit:junit:4.12'
35+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
36+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
37+
implementation project(path: ':ktloadingbutton')
38+
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
39+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package de.timonknispel.ktloadingbutton
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import org.junit.Assert.assertEquals
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
/**
10+
* Instrumented test, which will execute on an Android device.
11+
*
12+
* See [testing documentation](http://d.android.com/tools/testing).
13+
*/
14+
@RunWith(AndroidJUnit4::class)
15+
class ExampleInstrumentedTest {
16+
@Test
17+
fun useAppContext() {
18+
// Context of the app under test.
19+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20+
assertEquals("de.timonknispel.ktloadingbutton", appContext.packageName)
21+
}
22+
}

app/src/main/AndroidManifest.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="de.timonknispel.ktloadingbutton">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>

0 commit comments

Comments
 (0)