Skip to content

Commit

Permalink
Merge pull request #7 from SanojPunchihewa/dev
Browse files Browse the repository at this point in the history
Add method to get Available version code
  • Loading branch information
SanojPunchihewa authored Jul 27, 2019
2 parents 275da5c + dfb1d1d commit 9117f68
Show file tree
Hide file tree
Showing 13 changed files with 228 additions and 51 deletions.
8 changes: 8 additions & 0 deletions .idea/markdown-exported-files.xml

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

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: android
sudo: required
jdk: oraclejdk8
dist: trusty

env:
global:
Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog
All notable changes to InAppUpdater will be documented in this file.

## [Unreleased]
### Added
- Method to get the Version code of the Available Update

### Changed
- Pass the Activity to the `Builder()` instead of `start()`
```java
mUpdateManager = UpdateManager.Builder(this);
```
- No need to pass Activity to `continueUpdate()`
## [1.0.3-alpha.1] - 2019-07-25
### Added
- Debug Logs to the UpdateManager

## [1.0.2] - 2019-07-16

## [1.0.1] - 2019-07-16
### Changed
- Package name

## [v1.0] - 2019-07-16
:tada: Initial Release
33 changes: 22 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,48 @@ allprojects {
### Step 2: Add the dependency
```Gradle
dependencies {
implementation 'com.github.SanojPunchihewa:InAppUpdater:1.0.2'
implementation 'com.github.SanojPunchihewa:InAppUpdater:1.0.3'
}
```

### Step 3: Initialize the UpdateManager
Initialize the UpdateManager in your `onCreate` method of the Activity
```java
UpdateManager.Builder().mode(UpdateManagerConstant.IMMEDIATE).start(this);
UpdateManager.Builder(this).mode(UpdateManagerConstant.FLEXIBLE).start();
```

#### Update Mode
**Update Mode**

There are two modes
* Flexible *(default)* - User can use the app during update download, installation and restart needs to be triggered by user
* Flexible(`UpdateManagerConstant.FLEXIBLE`) *(default)* - User can use the app during update download, installation and restart needs to be triggered by user

* Immediate - User will be blocked until download and installation is finished, restart is triggered automatically
* Immediate(`UpdateManagerConstant.IMMEDIATE`) - User will be blocked until download and installation is finished, restart is triggered automatically


#### Set the update mode
```java
UpdateManager.Builder().mode(UpdateManagerConstant.IMMEDIATE)
```

### Step 4: Resume the updates
Call `continueUpdate` method in your `onResume` method to install waiting updates
```java
@Override
protected void onResume() {
super.onResume();
UpdateManager.continueUpdate(this);
UpdateManager.continueUpdate();
}
```
**Additionally** you can get the Available Version Code of the update. You can find these codes in the [demo app](/app/src/main/java/com/zanojmobiapps/inappupdatedemoapp/MainActivity.java)

```java
mUpdateManager.getAvailableVersionCode(new onVersionCheckListener() {
@Override
public void onReceiveVersionCode(final int code) {
// Do something here
}
});
```
## :movie_camera: Demo
Flexible Update | Immediate Update
:-------------------------:|:-------------------------:
![](/images/gif/flexible_update.gif) | ![](/images/gif/immediate_update.gif)

## :exclamation: Troubleshoot
- In-app updates works only with devices running **Android 5.0 (API level 21) or higher**
- In-app updates are available only to user accounts that own the app. So, **make sure the account you’re using has downloaded your app from Google Play at least once before using the account to test in-app updates.**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,55 @@
package com.zanojmobiapps.inappupdatedemoapp;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import com.sanojpunchihewa.updatemanager.UpdateManager;
import com.sanojpunchihewa.updatemanager.UpdateManager.onVersionCheckListener;
import com.sanojpunchihewa.updatemanager.UpdateManagerConstant;

public class MainActivity extends AppCompatActivity {

// Declare the UpdateManager
UpdateManager mUpdateManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

UpdateManager.Builder().mode(UpdateManagerConstant.IMMEDIATE).start(this);
TextView txtCurrentVersion = findViewById(R.id.txt_current_version);
TextView txtAvailableVersion = findViewById(R.id.txt_available_version);

txtCurrentVersion.setText(String.valueOf(BuildConfig.VERSION_CODE));

// Initialize the Update Manager with the Activity and the Update Mode
mUpdateManager = UpdateManager.Builder(this);

// Callback from Available version code
mUpdateManager.getAvailableVersionCode(new onVersionCheckListener() {
@Override
public void onReceiveVersionCode(final int code) {
txtAvailableVersion.setText(String.valueOf(code));
}
});

}

@Override
protected void onResume() {
super.onResume();
UpdateManager.continueUpdate(this);
// Continue updates when resumed
mUpdateManager.continueUpdate();
}

public void callFlexibleUpdate(View view) {
// Start a Flexible Update
mUpdateManager.mode(UpdateManagerConstant.FLEXIBLE).start();
}

public void callImmediateUpdate(View view) {
// Start a Immediate Update
mUpdateManager.mode(UpdateManagerConstant.IMMEDIATE).start();
}
}
91 changes: 82 additions & 9 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/layout_main">
tools:context=".MainActivity">

<LinearLayout
android:layout_centerInParent="true"
android:id="@+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="120dp"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/linearLayout2"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/txt_available_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
tools:text="25" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Available Version"
android:textSize="15sp" />
</LinearLayout>

<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="120dp"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="@+id/linearLayout"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TextView
android:id="@+id/textView"
android:id="@+id/txt_current_version"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In App Update Demo App"
android:textSize="25sp" />
android:textSize="40sp"
tools:text="2" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current Version"
android:textSize="15sp" />
</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="100dp"
android:gravity="center_horizontal"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout">

<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:textColor="@color/colorAccent"
app:strokeColor="@color/colorAccent"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Flexible Update"
android:layout_margin="10dp"
android:onClick="callFlexibleUpdate" />

<com.google.android.material.button.MaterialButton
android:backgroundTint="@color/colorAccent"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="Immediate Update"
android:layout_margin="10dp"
android:onClick="callImmediateUpdate" />

</LinearLayout>

</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<style name="AppTheme" parent="Theme.MaterialComponents.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down
Binary file added images/gif/flexible_update.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gif/immediate_update.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/update_flexible.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/update_immediate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9117f68

Please sign in to comment.