|
| 1 | +# DirectAppUpdate 📲 |
| 2 | + |
| 3 | +DirectAppUpdate is an open-source in-app update library using Jetpack Compose to update your Android app without relying on the Play Store or any other app store. Instead, updates are managed via a private server using a configurable JSON URL. |
| 4 | + |
| 5 | +<p align="center"> |
| 6 | + <img src="https://user-images.githubusercontent.com/12345678/DirectAppUpdate-1.gif" alt="DirectAppUpdate Demo 1" width="45%" /> |
| 7 | + <img src="https://user-images.githubusercontent.com/12345678/DirectAppUpdate-2.gif" alt="DirectAppUpdate Demo 2" width="45%" /> |
| 8 | +</p> |
| 9 | + |
| 10 | +## Getting Started 🚀 |
| 11 | + |
| 12 | +### Library Setup |
| 13 | + |
| 14 | +#### In your `settings.gradle` |
| 15 | +```gradle |
| 16 | +dependencyResolutionManagement { |
| 17 | + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) |
| 18 | + repositories { |
| 19 | + mavenCentral() |
| 20 | + maven { url 'https://jitpack.io' } |
| 21 | + } |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +#### In your project `build.gradle` |
| 26 | +[](https://jitpack.io/#Micoder-dev/DirectAppUpdate) |
| 27 | +```gradle |
| 28 | +dependencies { |
| 29 | + implementation 'com.github.Micoder-dev:DirectAppUpdate:Tag' |
| 30 | +} |
| 31 | +``` |
| 32 | + |
| 33 | +### JSON Config Setup |
| 34 | + |
| 35 | +Create a configuration file for your app updates: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "apkFileName": "new_release.apk", |
| 40 | + "appName": "CTN-IPTV", |
| 41 | + "downloadUrl": "https://example/new_release.apk", |
| 42 | + "immediateUpdate": false, |
| 43 | + "releaseNotes": "- Exciting Update\n - Bug Fixes", |
| 44 | + "versionCode": 2, |
| 45 | + "versionName": "2.0.0" |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +## Implementation Methods 🔧 |
| 50 | + |
| 51 | +### 1st Way: Simple Implementation using Jetpack Compose |
| 52 | + |
| 53 | +```kotlin |
| 54 | +val configUrl = "https://cloud-multiapp-default-rtdb.firebaseio.com/ctn-iptv.json" |
| 55 | +DirectAppUpdate(activity = this@MainActivity, configUrl = configUrl, appIcon = R.mipmap.ic_launcher) |
| 56 | +``` |
| 57 | + |
| 58 | +The `DirectAppUpdate` is a composable function that can be used within your main activity's composable theme or any other composable function where you can check for update status. |
| 59 | + |
| 60 | +### 2nd Way: Custom Implementation |
| 61 | + |
| 62 | +```kotlin |
| 63 | +@Composable |
| 64 | +fun DirectAppUpdate(activity: Activity, configUrl: String, notificationViewModel: NotificationViewModel = hiltViewModel(), appIcon: Int) { |
| 65 | + |
| 66 | + val updateDialogState = remember { mutableStateOf(UpdateDialogState()) } |
| 67 | + |
| 68 | + val directAppUpdateManager = remember { DirectAppUpdateManager.Builder(activity) } |
| 69 | + |
| 70 | + LaunchedEffect(key1 = true) { |
| 71 | + directAppUpdateManager.fetchUpdateConfig( |
| 72 | + configUrl = configUrl, |
| 73 | + onSuccess = { builder -> |
| 74 | + builder.setDirectUpdateListener(object : DirectUpdateListener { |
| 75 | + override fun onImmediateUpdateAvailable() { |
| 76 | + updateDialogState.value = updateDialogState.value.copy( |
| 77 | + visible = true, |
| 78 | + updateType = UpdateType.Immediate, |
| 79 | + status = "Immediate Update Available", |
| 80 | + showUpdateButton = true |
| 81 | + ) |
| 82 | + } |
| 83 | + |
| 84 | + override fun onFlexibleUpdateAvailable() { |
| 85 | + updateDialogState.value = updateDialogState.value.copy( |
| 86 | + visible = true, |
| 87 | + updateType = UpdateType.Flexible, |
| 88 | + status = "Flexible Update Available", |
| 89 | + showUpdateButton = true |
| 90 | + ) |
| 91 | + } |
| 92 | + |
| 93 | + override fun onAlreadyUpToDate() { |
| 94 | + updateDialogState.value = updateDialogState.value.copy( |
| 95 | + status = "Already up to date", |
| 96 | + showUpdateButton = false |
| 97 | + ) |
| 98 | + } |
| 99 | + |
| 100 | + override fun onDownloadStart() { |
| 101 | + updateDialogState.value = updateDialogState.value.copy( |
| 102 | + status = "Download started", |
| 103 | + showUpdateButton = false |
| 104 | + ) |
| 105 | + } |
| 106 | + |
| 107 | + override fun onProgress(progress: Float) { |
| 108 | + notificationViewModel.showProgress(progress = progress.toInt(), icon = appIcon) |
| 109 | + updateDialogState.value = updateDialogState.value.copy( |
| 110 | + status = "Downloading: $progress%", |
| 111 | + progress = progress |
| 112 | + ) |
| 113 | + } |
| 114 | + |
| 115 | + override fun onDownloadComplete() { |
| 116 | + updateDialogState.value = updateDialogState.value.copy( |
| 117 | + status = "Download complete", |
| 118 | + showUpdateButton = false |
| 119 | + ) |
| 120 | + } |
| 121 | + |
| 122 | + override fun onDownloadFailed(error: String) { |
| 123 | + updateDialogState.value = updateDialogState.value.copy( |
| 124 | + status = "Download failed: $error", |
| 125 | + showUpdateButton = false |
| 126 | + ) |
| 127 | + } |
| 128 | + }).build().checkForUpdate() |
| 129 | + }, |
| 130 | + onError = { error -> |
| 131 | + Toast.makeText(activity, error, Toast.LENGTH_SHORT).show() |
| 132 | + } |
| 133 | + ) |
| 134 | + } |
| 135 | + |
| 136 | + UpdateDialog( |
| 137 | + dialogState = updateDialogState.value, |
| 138 | + onUpdateClick = { directAppUpdateManager.build().startUpdate() }, |
| 139 | + onCancelClick = { |
| 140 | + if (updateDialogState.value.updateType == UpdateType.Flexible) { |
| 141 | + updateDialogState.value = updateDialogState.value.copy(visible = false) |
| 142 | + } |
| 143 | + } |
| 144 | + ) |
| 145 | + |
| 146 | +} |
| 147 | +``` |
| 148 | + |
| 149 | +This method provides more customization options. Users can create custom dialogs or use `DirectUpdateListener` overrides as per their needs. |
| 150 | + |
| 151 | +## Contributions 🙌 |
| 152 | + |
| 153 | +We welcome contributions! Please fork the repository, create a new branch, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change. |
| 154 | + |
| 155 | +Don't forget to give this repo a ⭐ if you found it useful! |
| 156 | + |
| 157 | +## License 📄 |
| 158 | + |
| 159 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
| 160 | + |
| 161 | +Happy Coding! 💻 |
0 commit comments