GithubHelp home page GithubHelp logo

ackeecz / version-update-handler Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 0.0 271 KB

This library will compare current application version number to the versions that are stored in remote locations and show dialog to user with prompt to update their app.

License: Apache License 2.0

Kotlin 100.00%
android version-update firebase-remote-config

version-update-handler's Introduction

Maven Central

Android Version Status Resolver and Fetcher

Purpose of library

Many applications have need to tell their users to update current application because they have outdated version. Google Play doesn't support any API for that so we need to use custom solution. This library will compare current application version number to the versions that are stored in remote locations (Api request/Firebase Remote Config, ...) and show the dialog to the user with prompt to update their app.

This library is based on Kotlin Coroutines

Usage

The simplest way for use this library is

 val versionFetcher = ...
 val versionResolver = VersionStatusResolver(versionFetcher)
 versionResolver.checkVersionStatusAndOpenDialog(BuildConfig.VERSION_CODE, getSupportFragmentManager())

this will check versions and show update dialog with default texts. If you want to modify strings in dialog and maybe package name, you can via DialogSettings.Builder() class.

 val versionFetcher = ...
 val versionResolver = VersionStatusResolver(versionFetcher)
 versionResolver.checkVersionStatusAndOpenDialog(BuildConfig.VERSION_CODE, getSupportFragmentManager(),
                            DialogSettings.Builder()
                            .title("My custom title")
                            .messageRes(R.string.update_dialog_message)
                            .positiveButton("Yaay")
                            .negativeButton("Never")
                            .build())

If you want to show UI that built-in dialog cannot handle, you can use different method and based on result show corresponding UI:

suspend fun checkVersionStatus() {
    val versionFetcher = ...
    val versionResolver = VersionStatusResolver(versionFetcher)
    
    val status = versionResolver.checkVersionStatus(BuildConfig.VERSION_CODE)
    when(status) {
        UP_TO_DATE -> // app is up to date
        UPDATE_AVAILABLE -> // update is available but is not mandatory
        UPDATE_REQUIRED -> // update is mandatory, user should not be able to run app
    }}
}

VersionStatusResolver class takes responsibility for deciding status of update based on fetched version info and current application version.

Interface VersionFetcher should be used for actual fetching of version configurations.

Two basic implementation are provided in separate modules - Firebase Remote Config fetcher and Rest Api Fetcher

Firebase Remote Config

Class FirebaseVersionFetcher takes optional argument for cache expiration of fetched data from Firebase Remote Config. Default names of attributes are minimal_version_android and current_version_android but you can modify that with constructor attributes.

implementation "io.github.ackeecz:updatechecker-firebase-fetcher:x.x.x"

Besides that, you need to add a dependency to the Firebase Remote Config since it is not transitive.

implementation "com.google.firebase:firebase-config:x.x.x"
implementation "com.google.firebase:firebase-config-ktx:x.x.x"

Rest Api

Class RestVersionFetcher accepts as argument base url of server. On url GET ${baseUrl}/app-version is expected response with attributes minimal_version_android and current_version_android (names can be also modified)

compile "io.github.ackeecz:updatechecker-rest-fetcher:x.x.x"

Dependencies

For current version check lib.properties file

compile "io.github.ackeecz:updatechecker-status-resolver:x.x.x"

Sample

In the app module is sample that demonstrates basic usage of library with mocked fetcher.

License

Copyright 2018 Ackee s.r.o.

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.

version-update-handler's People

Contributors

gorbuvla avatar mottljan1 avatar pavelskala avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

version-update-handler's Issues

Check version status with Long

As of API 28, PackageInfo.versionCode is deprecated and replaced with longVersionCode which is a long. We should update VersionStatusResolver.checkVersionStatus() to use long instead of int

See more info about versionCode here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.