Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Commit 207022e

Browse files
authored
Merge pull request #3 from AckeeCZ/feature/java-to-kt
Rewritten to Kotlin. Replaced Rx with Coroutines. Added tests for Rest
2 parents cb8af8d + 942f0b8 commit 207022e

38 files changed

Lines changed: 673 additions & 922 deletions

.gitignore

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,43 @@
1+
# built application files
2+
*.apk
3+
*.ap_
4+
5+
# files for the dex VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# generated files
12+
bin/
13+
gen/
14+
out/
15+
.out/
16+
out/
17+
build/
18+
.idea/*
19+
!.idea/localizerSettings.xml
20+
!.idea/mvpAddSettings.xml
21+
.gradle/
22+
captures/
23+
24+
25+
#iml files
126
*.iml
2-
.gradle
3-
/local.properties
4-
/.idea
27+
28+
# Local configuration file (sdk path, etc)
29+
local.properties
30+
31+
# linux files
32+
.directory
33+
*.*~
34+
35+
# mac files
536
.DS_Store
6-
/build
7-
/captures
8-
.externalNativeBuild
9-
/projectFilesBackup*
37+
38+
Thumbs.db
39+
thumbs.db
40+
41+
outputs/mapping.txt
42+
43+
artwork

.idea/encodings.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/gradle.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.idea/misc.xml

Lines changed: 0 additions & 98 deletions
This file was deleted.

.idea/runConfigurations.xml

Lines changed: 0 additions & 12 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/build.gradle

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
22
apply plugin: 'kotlin-android'
33

44
android {
5-
compileSdkVersion 29
5+
compileSdkVersion Config.compileSdk
66

77
defaultConfig {
88
applicationId "com.ackee.versionupdatehandler"
9-
minSdkVersion 15
10-
targetSdkVersion 29
9+
minSdkVersion Config.minSdk
10+
targetSdkVersion Config.targetSdk
1111
versionCode 1
1212
versionName "1.0"
1313
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -29,24 +29,18 @@ android {
2929
}
3030
}
3131

32-
ext {
33-
ankoVersion = "0.10.8"
34-
}
35-
3632
dependencies {
3733
implementation fileTree(dir: 'libs', include: ['*.jar'])
34+
implementation project(':status-resolver')
35+
36+
implementation Dependencies.androidXAppCompat
37+
implementation Dependencies.kotlinStdLib
38+
implementation Dependencies.ankoSdk15
39+
implementation Dependencies.ankoSdk21Coroutines
40+
implementation Dependencies.ankoAppcompat
41+
42+
testImplementation Dependencies.jUnit
3843
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
3944
exclude group: 'com.android.support', module: 'support-annotations'
4045
})
41-
implementation 'androidx.appcompat:appcompat:1.1.0'
42-
testImplementation 'junit:junit:4.12'
43-
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
44-
45-
// Anko
46-
implementation "org.jetbrains.anko:anko-sdk15:$ankoVersion" // So here it's 15 too
47-
48-
// Anko libs matching support libs
49-
implementation "org.jetbrains.anko:anko-appcompat-v7:${ankoVersion}"
50-
51-
implementation project(':status-resolver')
5246
}
Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
package com.ackee.versionupdatehandler.setup
22

3+
import android.annotation.SuppressLint
34
import android.os.Bundle
45
import androidx.appcompat.app.AppCompatActivity
56
import com.ackee.versionupdatehandler.R
7+
import com.ackee.versioupdatehandler.VersionFetcher
68
import com.ackee.versioupdatehandler.VersionStatusResolver
79
import com.ackee.versioupdatehandler.model.BasicVersionsConfiguration
810
import com.ackee.versioupdatehandler.model.DialogSettings
911
import com.ackee.versioupdatehandler.model.VersionStatus
10-
import io.reactivex.Single
12+
import com.ackee.versioupdatehandler.model.VersionsConfiguration
1113
import org.jetbrains.anko.*
14+
import org.jetbrains.anko.sdk21.coroutines.onClick
1215
import java.util.Random
1316

1417
/**
1518
* Activity with samples
1619
*/
1720
class MainActivity : AppCompatActivity() {
1821

22+
@SuppressLint("SetTextI18n")
1923
override fun onCreate(savedInstanceState: Bundle?) {
2024
super.onCreate(savedInstanceState)
2125
scrollView {
2226
verticalLayout {
2327
padding = dip(16)
2428
button {
2529
text = "Not mandatory update"
26-
setOnClickListener {
30+
onClick {
2731
checkWithVersion(13)
2832
}
2933
}.lparams(width = matchParent) {
@@ -32,7 +36,7 @@ class MainActivity : AppCompatActivity() {
3236

3337
button {
3438
text = "Mandatory update"
35-
setOnClickListener {
39+
onClick {
3640
checkWithVersion(8)
3741
}
3842
}.lparams(width = matchParent) {
@@ -41,33 +45,26 @@ class MainActivity : AppCompatActivity() {
4145

4246
button {
4347
text = "Customized dialog"
44-
setOnClickListener {
45-
VersionStatusResolver({
46-
Single.just(BasicVersionsConfiguration(10, 15))
47-
}).checkVersionStatusAndOpenDefault(8, supportFragmentManager, DialogSettings.Builder()
48-
.title("My custom title")
49-
.messageRes(R.string.update_dialog_message)
50-
.positiveButton("Yaay")
51-
.negativeButton("Never")
52-
.build()
53-
)
48+
onClick {
49+
getDefaultStatusResolver().checkVersionStatusAndOpenDialog(8, supportFragmentManager, DialogSettings(
50+
title = "My custom title",
51+
messageRes = R.string.update_dialog_message,
52+
positiveButton = "Yaay",
53+
negativeButton = "Never"
54+
))
5455
}
5556
}.lparams(width = matchParent) {
5657
bottomMargin = dip(16)
5758
}
5859

5960
button {
6061
text = "Custom UI"
61-
setOnClickListener {
62-
VersionStatusResolver({
63-
Single.just(BasicVersionsConfiguration(10, 15))
64-
}).checkVersionStatus(if (Random().nextInt() % 2 == 0) 8 else 12)
65-
.subscribe({
66-
when (it) {
67-
VersionStatus.UPDATE_AVAILABLE -> toast("Update is available")
68-
VersionStatus.UPDATE_REQUIRED -> toast("Mandatory update is available")
69-
}
70-
}, Throwable::printStackTrace)
62+
onClick {
63+
when (getDefaultStatusResolver().checkVersionStatus(if (Random().nextInt() % 2 == 0) 8 else 12)) {
64+
VersionStatus.UPDATE_AVAILABLE -> toast("Update is available")
65+
VersionStatus.UPDATE_REQUIRED -> toast("Mandatory update is available")
66+
VersionStatus.UP_TO_DATE -> toast("Up to date")
67+
}
7168
}
7269
}.lparams(width = matchParent) {
7370
bottomMargin = dip(16)
@@ -76,10 +73,16 @@ class MainActivity : AppCompatActivity() {
7673
}
7774
}
7875

79-
private fun checkWithVersion(version: Int) {
76+
private suspend fun checkWithVersion(version: Int) {
8077
// replace fetcher with some real one
81-
VersionStatusResolver({
82-
Single.just(BasicVersionsConfiguration(10, 15))
83-
}).checkVersionStatusAndOpenDefault(version, supportFragmentManager)
78+
getDefaultStatusResolver().checkVersionStatusAndOpenDialog(version, supportFragmentManager)
79+
}
80+
81+
private fun getDefaultStatusResolver(minimalVersion: Long = 10, currentVersion: Long = 15): VersionStatusResolver {
82+
return VersionStatusResolver(object : VersionFetcher {
83+
override suspend fun fetch(): VersionsConfiguration {
84+
return BasicVersionsConfiguration(minimalVersion, currentVersion)
85+
}
86+
})
8487
}
8588
}

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.50'
4+
ext.kotlin_version = Config.kotlinVersion
55

66
repositories {
77
jcenter()
88
google()
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.5.1'
11+
classpath 'com.android.tools.build:gradle:4.0.0'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
1414
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
@@ -19,6 +19,7 @@ allprojects {
1919
repositories {
2020
jcenter()
2121
google()
22+
mavenCentral()
2223
}
2324
}
2425

0 commit comments

Comments
 (0)