Skip to content

Commit

Permalink
Merge pull request #1 from timonknispel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
timonknispel authored Jan 24, 2020
2 parents ed665c3 + 925a444 commit 1488ccc
Show file tree
Hide file tree
Showing 51 changed files with 1,679 additions and 1 deletion.
16 changes: 16 additions & 0 deletions .idea/checkstyle-idea.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 111 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,112 @@
# KTLoadingButton
Simple loading button for kotlin andorid apps

Simple loading button for kotlin andorid apps.
This button can show results in a nicely designed way to not block the ui while the user is waiting.

|SUCCESS| ERROR |
|--|--|
| ![](success.gif) | ![](fail.gif) |


## Installation
1. Add the JitPack repository to your build file

```css
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

2. Add the dependency

```css
dependencies {
implementation 'com.github.User:Repo:Tag'
}
```

## Usage
### Example needed? Look inside the app folder

1. Add the KTLoadingButton to your layout

```xml
<de.timonknispel.ktloadingbutton.KTLoadingButton
android:id="@+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonName="Test"
/>
```
2. DONE
Now all you have to do is to start the button. This can be done in several ways.

#### Option 1: INTERMEDIATE (DEFAULT)
Simply call :
```kotlin
test_button.startLoading()
````

This will start the loading animation of the button. By default it should now intermediate.

When loading is done simply call:
```kotlin
test_button.doResult(success: Boolean)
```
This will stop the loading animation an start the result animation according to the given success.
Optional you can add a callback if you want to know when the animation is done:
```kotlin
test_button.doResult(success: Boolean) {
// do stuff here
}
```

#### Option 2: PROGRESS
Add the progressStyle option to your xml layout:
```xml
<de.timonknispel.ktloadingbutton.KTLoadingButton
android:id="@+id/test_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:buttonName="Test"
app:progressStyle="PROGRESS"
/>
```
All you have to do now is to call:
```kotlin
test_button.setProgress(progress: Float)
```
to show the progress.

## Good to know

- You can add a callback to the button if you need the click event even if the button is in loading state:
```kotlin
test_button.touchListener = {
// do some stuff
}
```
This can be handy if for example want the user to cancel the loading process.

- You can reset the button by calling:
```kotlin
test_button.reset()
```

## Customization

### In XML
|Attribute| Value/s | Description| Required | Default |
|--|--| -- | -- | -- |
| buttonName | String | Sets the text for the button |[x]| |
| buttonTextSize | Dimension (SP) | Sets the text size for the button |[]| 16sp |
| allCaps | Boolean | If set to true all button text will be in caps |[]| true |
| buttonColor | Color | Sets the color for the button text and progress |[]| #373737|
| loadingBackgroundColor | Color | Sets the background color for a failed result |[]| buttonColor with transparency of 31% |
| succeedColor | Color | Sets the background color for a success result |[]|#4CAF50 |
| failedColor | Color | Sets the background color for a failed result |[]|#F44336 |
| autoResetButtonAfterResult | Boolean | Decides if the button should reset itself after the result was displayed (after 1,5 seconds) |[]| true |
| progressStyle | [INTERMEDIATE or PROGRESS] | Decides if the button should intermediate or display a progress |[]| INTERMEDIATE |
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

apply from: "../ktlint.gradle"

android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "de.timonknispel.ktloadingbutton"
minSdkVersion 22
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation project(path: ':ktloadingbutton')
implementation "org.jetbrains.kotlin:kotlin-reflect:1.3.61"
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package de.timonknispel.ktloadingbutton

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("de.timonknispel.ktloadingbutton", appContext.packageName)
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.timonknispel.ktloadingbutton">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading

0 comments on commit 1488ccc

Please sign in to comment.