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

Commit f22fdb1

Browse files
committed
Rewritten to java; added RestVersionFetcher
1 parent 2c3258e commit f22fdb1

21 files changed

Lines changed: 369 additions & 171 deletions

.idea/misc.xml

Lines changed: 97 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

firebase-fetcher/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'com.android.library'
2-
//apply plugin: 'kotlin-android'
32

43
android {
54
compileSdkVersion 25
@@ -16,13 +15,10 @@ android {
1615
}
1716
buildTypes {
1817
release {
19-
minifyEnabled true
18+
minifyEnabled false
2019
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2120
}
2221
}
23-
sourceSets {
24-
main.java.srcDirs += 'src/main/kotlin'
25-
}
2622
}
2723

2824
dependencies {

firebase-fetcher/src/main/AndroidManifest.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.ackee.versionupdatehandler">
1+
<manifest package="com.ackee.versionupdatehandler"
2+
xmlns:android="http://schemas.android.com/apk/res/android">
33

4-
<application android:allowBackup="true" android:label="@string/app_name"
5-
android:supportsRtl="true">
4+
<application android:allowBackup="false">
65

76
</application>
87

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package com.ackee.versionupdatehandler;
2+
3+
import android.support.annotation.NonNull;
4+
import android.util.Log;
5+
6+
import com.ackee.versioupdatehandler.VersionFetcher;
7+
import com.ackee.versioupdatehandler.model.BasicVersionsConfiguration;
8+
import com.ackee.versioupdatehandler.model.VersionFetchError;
9+
import com.ackee.versioupdatehandler.model.VersionsConfiguration;
10+
import com.google.android.gms.tasks.OnCompleteListener;
11+
import com.google.android.gms.tasks.Task;
12+
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
13+
14+
import rx.Single;
15+
import rx.SingleSubscriber;
16+
17+
/**
18+
* Class that fetches version configuration from Firebase Remote.
19+
*
20+
* @author Georgiy Shur ([email protected])
21+
* @since 2/5/2017
22+
*/
23+
public class FirebaseVersionFetcher implements VersionFetcher {
24+
public static final String TAG = FirebaseVersionFetcher.class.getName();
25+
26+
public static final String MINIMAL_VERSION = "minimal_version_android";
27+
public static final String CURRENT_VERSION = "current_version_android";
28+
29+
private int cacheExpiration;
30+
31+
public FirebaseVersionFetcher() {
32+
this(3600);
33+
}
34+
35+
public FirebaseVersionFetcher(int cacheExpiration) {
36+
this.cacheExpiration = cacheExpiration;
37+
}
38+
39+
@Override
40+
public Single<VersionsConfiguration> fetch() {
41+
return Single.create(new Single.OnSubscribe<VersionsConfiguration>() {
42+
@Override
43+
public void call(final SingleSubscriber<? super VersionsConfiguration> singleSubscriber) {
44+
boolean isDevMode = FirebaseRemoteConfig.getInstance().getInfo().getConfigSettings().isDeveloperModeEnabled();
45+
46+
FirebaseRemoteConfig.getInstance().fetch(isDevMode ? 0 : cacheExpiration).addOnCompleteListener(new OnCompleteListener<Void>() {
47+
@Override
48+
public void onComplete(@NonNull Task<Void> task) {
49+
if (task.isSuccessful()) {
50+
Log.d("FirebaseVersionFetcher", "onComplete: success");
51+
FirebaseRemoteConfig.getInstance().activateFetched();
52+
} else {
53+
Log.d("FirebaseVersionFetcher", "onComplete: failed");
54+
singleSubscriber.onError(new VersionFetchError());
55+
}
56+
long minimalVersion = FirebaseRemoteConfig.getInstance().getLong(MINIMAL_VERSION);
57+
long currentVersion = FirebaseRemoteConfig.getInstance().getLong(CURRENT_VERSION);
58+
59+
singleSubscriber.onSuccess(new BasicVersionsConfiguration(minimalVersion, currentVersion));
60+
}
61+
});
62+
}
63+
});
64+
}
65+
}

firebase-fetcher/src/main/java/com/ackee/versionupdatehandler/FirebaseVersionFetcher.kt

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

library/build.gradle

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'com.android.library'
2-
apply plugin: 'kotlin-android'
32

43
android {
54
compileSdkVersion 25
@@ -16,36 +15,14 @@ android {
1615
}
1716
buildTypes {
1817
release {
19-
minifyEnabled true
18+
minifyEnabled false
2019
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2120
}
2221
}
23-
sourceSets {
24-
main.java.srcDirs += 'src/main/kotlin'
25-
}
2622
}
2723

2824
dependencies {
29-
compile fileTree(dir: 'libs', include: ['*.jar'])
30-
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
31-
exclude group: 'com.android.support', module: 'support-annotations'
32-
})
33-
compile 'com.android.support:appcompat-v7:25.1.0'
3425
testCompile 'junit:junit:4.12'
35-
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
36-
compile 'io.reactivex:rxkotlin:0.60.0'
26+
compile 'io.reactivex:rxjava:1.2.5'
3727
compile 'io.reactivex:rxandroid:0.24.0'
3828
}
39-
40-
buildscript {
41-
ext.kotlin_version = '1.0.6'
42-
43-
repositories {
44-
jcenter()
45-
mavenCentral()
46-
}
47-
dependencies {
48-
classpath 'com.android.tools.build:gradle:2.2.3'
49-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
50-
}
51-
}

library/src/main/AndroidManifest.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.ackee.versioupdatehandler">
1+
<manifest package="com.ackee.versioupdatehandler"
2+
xmlns:android="http://schemas.android.com/apk/res/android">
33

4-
<application android:allowBackup="true" android:label="@string/app_name"
5-
android:supportsRtl="true">
4+
<application android:allowBackup="false">
65

76
</application>
87

library/src/main/java/com/ackee/versioupdatehandler/VersionFetcher.kt renamed to library/src/main/java/com/ackee/versioupdatehandler/VersionFetcher.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
package com.ackee.versioupdatehandler
1+
package com.ackee.versioupdatehandler;
22

3-
import com.ackee.versioupdatehandler.model.VersionsConfiguration
4-
import rx.Single
3+
import com.ackee.versioupdatehandler.model.VersionsConfiguration;
4+
5+
import rx.Single;
56

67
/**
78
* Base interface for classes that will handle version fetching.
89
*
910
* @author Georgiy Shur ([email protected])
1011
* @since 2/5/2017
1112
*/
12-
interface VersionFetcher {
13-
fun fetch(): Single<VersionsConfiguration>
14-
}
13+
public interface VersionFetcher {
14+
public static final String TAG = VersionFetcher.class.getName();
15+
16+
Single<VersionsConfiguration> fetch();
17+
18+
}

0 commit comments

Comments
 (0)