A version checker for Android
A small, fast, efficient and flexible open source library that checks for your app updates from REST APIs.
Will be added as soon as possible!
Building with gradle is fairly straight forward:
git clone https://github.com/mafixmafix/VersionCheckerSample.git
cd VersionCheckerSample
./gradlew build
You will need to include the version-checker-0.x.aar
in your application’s runtime.
<dependency>
<groupId>tk.pallas.versionchecker</groupId>
<artifactId>version-checker</artifactId>
<version>0.1.0</version>
<type>pom</type>
</dependency>
// Add VersionChecker dependencies
dependencies {
implementation 'tk.pallas.versionchecker:version-checker:0.1.0'
}
<dependency org='tk.pallas.versionchecker' name='version-checker' rev='0.1.0'></dependency>
Note: library is available ONLY on JCenter.
JSON response:
{
"data": {
"id": 2,
"first_name": "Janet",
"last_name": "Weaver",
"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
}
}
POJO class:
public class ResultModel {
Data data;
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
@NonNull
@Override
public String toString() {
return data.toString();
}
public static class Data {
Integer id;
String first_name;
String last_name;
String avatar;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirst_name() {
return first_name;
}
public void setFirst_name(String first_name) {
this.first_name = first_name;
}
public String getLast_name() {
return last_name;
}
public void setLast_name(String last_name) {
this.last_name = last_name;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
}
}
Note:
VersionChecker
instance in AppModule.
@Module
public abstract class AppModule {
@Provides
static VersionChecker provideVersionChecker(VersionCheckerClient versionCheckerClient) {
return VersionChecker.Builder.getInstance()
.versionCheckerClient(versionCheckerClient)
.build();
}
@Provides
static VersionCheckerClient provideVersionCheckerClient(Context context, Condition<ResultModel> condition) {
return VersionCheckerClient
.Builder
.getInstance()
.appContext(context)
.condition(condition)
.result(ResultModel.class)
.url("https://reqres.in/api/users/2") // Fake REST_API :)
.build();
}
@Provides
static Condition<ResultModel> provideCondition() {
return new Condition<ResultModel>() {
@Override
public void whatHappen(IVersion<ResultModel> version) {
if (version.getNetworkInfo().isConnected() && version.getTag().equals(MainActivity.TAG)) {
if (version.getResult() != null) {
Log.d("VersionChecker", version.getResult().toString());
((MainActivity) version.getActivity()).openDialogFragment();
}
}
}
};
}
@Singleton
@Binds
abstract Context bindContext(App app);
}
Note:
VersionChecker
instance MUST be created in application scope.start
method in onResume
method of your activity.
@Override
protected void onResume() {
super.onResume();
versionChecker.start(this, TAG);
}
Note:
start
method in any other activity callbacks.(e.g.,onCreate
)start
method in multiple activities!Note:
Note: All dependencies will be removed in 1.x version.
Will be added as soon as possible!
Of course, Pull Requests are welcome.
Here are the few rules we’d like you to respect if you do so:
Copyright 2019 Pallas
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.