Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactive Installer Library with Demo #1

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.aab
*.apk
*.iml

.gradle
.idea
.DS_Store

/build
/captures
.externalNativeBuild

local.properties
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
48 changes: 48 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion compile_sdk_version

defaultConfig {
applicationId application_id

minSdkVersion min_sdk_version
targetSdkVersion target_sdk_version

versionCode version_code
versionName version_name
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

dynamicFeatures = [
":feature1",
":feature2"
]
}

dependencies {
implementation project(':reactivesplitinstaller')

// Android Support Libraries
api 'androidx.appcompat:appcompat:1.1.0-alpha03'
api 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
api 'com.google.android.gms:play-services-instantapps:16.0.1'

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// Play Core
api 'com.google.android.play:core:1.4.0'

// RxAndroid & RxJava
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
api 'io.reactivex.rxjava2:rxjava:2.2.7'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
30 changes: 30 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.branhamplayer.android.reactivesplitinstaller.app">

<dist:module
dist:instant="true"
dist:onDemand="false"
dist:title="@string/module_base">
<dist:fusing dist:include="true"/>
</dist:module>

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.branhamplayer.android.reactivesplitinstaller.app

import android.app.Application
import android.content.Context
import com.google.android.play.core.splitcompat.SplitCompat

@Suppress("Unused")
class App : Application() {
override fun attachBaseContext(base: Context?) {
super.attachBaseContext(base)
SplitCompat.install(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
package com.branhamplayer.android.reactivesplitinstaller.app

import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.AppCompatTextView
import com.branhamplayer.android.reactivesplitinstaller.InstallationStatus
import com.branhamplayer.android.reactivesplitinstaller.ReactiveSplitInstaller
import com.google.android.play.core.splitcompat.SplitCompat
import io.reactivex.disposables.CompositeDisposable
import android.text.method.ScrollingMovementMethod
import com.google.android.play.core.splitinstall.SplitInstallHelper


class MainActivity : AppCompatActivity(), View.OnClickListener {

private var button1: AppCompatButton? = null
private var button2: AppCompatButton? = null
private var button3: AppCompatButton? = null
private var logView: AppCompatTextView? = null

private val compositeDisposable = CompositeDisposable()
private lateinit var installer: ReactiveSplitInstaller

override fun attachBaseContext(newBase: Context?) {
super.attachBaseContext(newBase)
SplitCompat.install(this)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

installer = ReactiveSplitInstaller(this)

button1 = findViewById(R.id.feature_one)
button1?.setOnClickListener(this)

button2 = findViewById(R.id.feature_two)
button2?.setOnClickListener(this)

button3 = findViewById(R.id.unavailable_feature)
button3?.setOnClickListener(this)

logView = findViewById(R.id.log)
logView?.movementMethod = ScrollingMovementMethod()

}

override fun onDestroy() {
super.onDestroy()
compositeDisposable.dispose()
}

override fun onClick(view: View?) {

val moduleName = when (view) {
button1 -> getString(R.string.module_feature1)
button2 -> getString(R.string.module_feature2)
else -> "Does not exist"
}

if (view == button1) {
installer.addModule(moduleName)
.install()
.subscribe({ status ->
Log.d("INSTALLER_STATUS", status::class.java.simpleName)
logView?.appendLine(status::class.java.simpleName)

when (status) {
is InstallationStatus.Installed -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SplitInstallHelper.updateAppInfo(this@MainActivity)
}

launchActivity("com.branhamplayer.android.reactivesplitinstaller.feature1.FeatureOneActivity")
}
}
}, { exception ->
Log.e("INSTALLER_STATUS", exception.message)
logView?.appendLine("Error code: ${exception.message}")
}, {
Log.d("INSTALLER_STATUS", "Done")
logView?.appendLine("Done")
}).also {
compositeDisposable.add(it)
}
}

if (view == button2) {
installer.addModule(moduleName)
.install()
.subscribe({ status ->
Log.d("INSTALLER_STATUS", status::class.java.simpleName)
logView?.appendLine(status::class.java.simpleName)

when (status) {
is InstallationStatus.Installed -> {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
SplitInstallHelper.updateAppInfo(this@MainActivity)
}

launchActivity("com.branhamplayer.android.reactivesplitinstaller.feature2.FeatureTwoActivity")
}
}
}, { exception ->
Log.e("INSTALLER_STATUS", "Error code: ${exception.message}")
logView?.appendLine("Error code: ${exception.message}")
}, {
Log.d("INSTALLER_STATUS", "Done")
logView?.appendLine("Done")
}).also {
compositeDisposable.add(it)
}
}

if (view == button3) {
installer.addModule(moduleName)
.install()
.subscribe({ status ->
Log.d("INSTALLER_STATUS", status::class.java.simpleName)
logView?.appendLine(status::class.java.simpleName)
}, { exception ->
Log.e("INSTALLER_STATUS", "Error code: ${exception.message}")
logView?.appendLine("Error code: ${exception.message}")
}).also {
compositeDisposable.add(it)
}
}
}

private fun launchActivity(className: String) {
val intent = Intent()
intent.setClassName(this, className)

startActivity(intent)
}

private fun AppCompatTextView.appendLine(text: String) {
this.append("$text\n")
}
}
53 changes: 53 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.branhamplayer.android.reactivesplitinstaller.app.MainActivity">

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/feature_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Instant Dynamic Feature Module 1"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintBottom_toTopOf="@+id/feature_two"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/feature_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Instant Dynamic Feature Module 2"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@+id/unavailable_feature"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/feature_one"/>

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/unavailable_feature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Load Non-Existing Feature Module"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/feature_two"
app:layout_constraintBottom_toTopOf="@+id/log"/>

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:maxLines="8"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/unavailable_feature"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
Binary file added app/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 app/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 app/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>
<string name="app_name">Reactive Split Installer Demo</string>

<!-- region Modules -->

<string name="module_base">Base Module</string>
<string name="module_feature1">Instant Dynamic Feature Module 1</string>
<string name="module_feature2">Instant Dynamic Feature Module 2</string>

<!-- endregion -->
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
8 changes: 8 additions & 0 deletions assets/credits.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
ic_launcher
https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=clipart&foreground.clipart=assignment_returned&foreground.space.trim=1&foreground.space.pad=0.25&foreColor=rgb(255%2C%20255%2C%20255)&backColor=rgb(0%2C%20150%2C%20136)&crop=0&backgroundShape=square&effects=score&name=ic_launcher

ic_launcher_round
https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html#foreground.type=clipart&foreground.clipart=assignment_returned&foreground.space.trim=1&foreground.space.pad=0.25&foreColor=rgb(255%2C%20255%2C%20255)&backColor=rgb(0%2C%20150%2C%20136)&crop=0&backgroundShape=circle&effects=score&name=ic_launcher_round

feature-graphic
https://www.norio.be/android-feature-graphic-generator/
Binary file added assets/feature-graphic.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 assets/ic_launcher.zip
Binary file not shown.
Binary file added assets/ic_launcher_round.zip
Binary file not shown.
Binary file added assets/screenshots/feature-1.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 assets/screenshots/feature-2.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 assets/screenshots/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 assets/screenshots/unavailable-feature.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading