Skip to content

Commit

Permalink
Renamed package and main class to Updatotron (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssawchenko authored Oct 7, 2021
1 parent 6ceded4 commit cef0c04
Show file tree
Hide file tree
Showing 37 changed files with 224 additions and 266 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ Example basic usage:

```
class App: Application() {
override fun onCreate() {
super.onCreate()
setupVersionCheck()
setupUpdatotron()
}
private fun setupVersionCheck() {
val versionChecker = VersionCheck(
VersionCheckConfig(
packageDetails = DefaultPackageDetails(
private fun setupUpdatotron() {
val updatotron = Updatotron(
Config(
packageDetails = DefaultPackageDetails(
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE,
packageManager,
packageName),
url = "https://myservice.com/api/version" // <-- Change this URL
)
packageName
),
url = "https://myservice.com/api/version" // <-- Change this URL
)
)
// Add the following line if you want the version check to be automatically
// run whenever the app is "Started"
ProcessLifecycleOwner.get().lifecycle.addObserver(versionChecker)
ProcessLifecycleOwner.get().lifecycle.addObserver(updatotron)
// Add the following lines if you want a default alert dialog to handle the displayStates
// and allow the user to jump out to the Play Store to get updates.
val upgradeDialog = DefaultUpgradeDialog(versionChecker.displayStateFlow, packageName)
val upgradeDialog = DefaultUpgradeDialog(updatotron.displayStateFlow, packageName)
registerActivityLifecycleCallbacks(upgradeDialog)
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.steamclock.versioncheckkotlin"
applicationId "com.steamclock.updatotron"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
Expand All @@ -33,7 +33,7 @@ android {
}

dependencies {
implementation project(':versioncheckkotlin')
implementation project(':updatotron')

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "com.google.android.material:material:$material"
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.steamclock.versioncheckkotlinsample">
package="com.steamclock.updatotronsample">

<application
android:name=".App"
Expand All @@ -9,8 +9,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.VersionCheckKotlin">
<activity android:name="com.steamclock.versioncheckkotlinsample.MainActivity">
android:theme="@style/Theme.Updatotron">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
63 changes: 63 additions & 0 deletions app/src/main/java/com/steamclock/updatotronsample/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.steamclock.updatotronsample

import android.app.Application
import androidx.lifecycle.ProcessLifecycleOwner
import com.steamclock.updatotron.DefaultUpgradeDialog
import com.steamclock.updatotron.Updatotron
import com.steamclock.updatotron.Config
import com.steamclock.updatotron.interfaces.DefaultPackageDetails
import com.steamclock.updatotron.interfaces.URLFetcher
import java.net.URL

class App : Application() {

override fun onCreate() {
super.onCreate()
setupUpdatotron()
}

private fun setupUpdatotron() {
val updatotron = Updatotron(
Config(
packageDetails = DefaultPackageDetails(
BuildConfig.VERSION_NAME,
BuildConfig.VERSION_CODE,
packageManager,
packageName
),
url = "https://doesn't_matter",
urlFetcher = MockURLFetcher
)
)

// Add the following line if you want the version check to be automatically
// run whenever the app is "Started"
ProcessLifecycleOwner.get().lifecycle.addObserver(updatotron)

// Add the following lines if you want a default alert dialog to handle the displayStates
// and allow the user to jump out to the Play Store to get updates.
val upgradeDialog = DefaultUpgradeDialog(updatotron.displayStateFlow, packageName)
registerActivityLifecycleCallbacks(upgradeDialog)
}
}

object MockURLFetcher : URLFetcher {
override fun getData(url: URL): String? {
return """
{
"ios" : {
"minimumVersion": "1.1",
"blockedVersions": ["1.2.0", "1.2.1", "@301"],
"latestTestVersion": "1.4.2@400"
},
"android" : {
"minimumVersion": "1.1",
"blockedVersions": ["1.2.0", "1.2.1", "@301"],
"latestTestVersion": "1.4.2@400"
},
"serverForceVersionFailure": false,
"serverMaintenance": false
}
"""
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.steamclock.versioncheckkotlinsample
package com.steamclock.updatotronsample

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
Expand Down
62 changes: 0 additions & 62 deletions app/src/main/java/com/steamclock/versioncheckkotlinsample/App.kt

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.VersionCheckKotlin" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Updatotron" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">Version Check Kotlin</string>
<string name="app_name">Updatotron Example</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.VersionCheckKotlin" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Updatotron" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down

This file was deleted.

4 changes: 2 additions & 2 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include ':versioncheckkotlin'
include ':updatotron'
include ':app'
rootProject.name = "Version Check Kotlin"
rootProject.name = "Updatotron"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.steamclock.versioncheckkotlin">
package="com.steamclock.updatotron">

</manifest>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.steamclock.versioncheckkotlin
package com.steamclock.updatotron

import com.steamclock.versioncheckkotlin.interfaces.*
import com.steamclock.updatotron.interfaces.*

data class VersionCheckConfig(
data class Config(
val packageDetails: PackageDetails,
val url: String,
val urlFetcher: URLFetcher = NetworkURLFetcher,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.steamclock.versioncheckkotlin
package com.steamclock.updatotron

import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import com.steamclock.versioncheckkotlin.models.DisplayState
import com.steamclock.versioncheckkotlin.models.Status
import com.steamclock.versioncheckkotlin.models.Version
import com.steamclock.versioncheckkotlin.models.VersionData
import com.steamclock.updatotron.models.DisplayState
import com.steamclock.updatotron.models.Status
import com.steamclock.updatotron.models.Version
import com.steamclock.updatotron.models.VersionData
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -15,7 +15,7 @@ import kotlinx.coroutines.launch
import java.lang.Exception
import java.net.URL

class VersionCheck(private val config: VersionCheckConfig):
class Updatotron(private val config: Config):
LifecycleObserver {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.steamclock.updatotron

import java.lang.Exception

sealed class UpdatotronException(message: String? = null, cause: Throwable? = null): Exception(message, cause) {
class InvalidVersionString(cause: Exception? = null): UpdatotronException("Invalid version string", cause)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.steamclock.versioncheckkotlin
package com.steamclock.updatotron

import android.app.Activity
import android.app.AlertDialog
Expand All @@ -7,7 +7,7 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import com.steamclock.versioncheckkotlin.models.DisplayState
import com.steamclock.updatotron.models.DisplayState
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collect
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.steamclock.versioncheckkotlin.interfaces
package com.steamclock.updatotron.interfaces

import android.content.pm.PackageManager
import android.os.Build
import com.steamclock.versioncheckkotlin.models.Version
import com.steamclock.updatotron.models.Version

interface PackageDetails {
fun getAppVersion(): Version
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.steamclock.versioncheckkotlin.interfaces
package com.steamclock.updatotron.interfaces

import java.net.URL

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.steamclock.versioncheckkotlin.interfaces
package com.steamclock.updatotron.interfaces

import com.steamclock.versioncheckkotlin.models.Version
import com.steamclock.versioncheckkotlin.models.PlatformVersionData
import com.steamclock.versioncheckkotlin.models.VersionData
import com.steamclock.updatotron.models.Version
import com.steamclock.updatotron.models.PlatformVersionData
import com.steamclock.updatotron.models.VersionData
import org.json.JSONArray
import org.json.JSONObject

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.steamclock.versioncheckkotlin.models
package com.steamclock.updatotron.models

sealed class DisplayState {
object Clear: DisplayState()
Expand Down
Loading

0 comments on commit cef0c04

Please sign in to comment.