in-app updater changes

This commit is contained in:
C10udburst 2022-08-15 15:27:25 +02:00
parent d987492d01
commit 6233edefd4
9 changed files with 61 additions and 30 deletions

View file

@ -31,14 +31,6 @@ jobs:
distribution: 'adopt'
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Set checks for prerelease updates to true by default
run: |
sed -i "s/R\.string\.prerelease_update_key), false))/R\.string\.prerelease_update_key), true))/" app/src/main/java/com/lagradost/cloudstream3/utils/InAppUpdater.kt
- name: Update prerelease_commit_hash
run: |
COMMIT_HASH="$(git log -1 --format='%H')"
sed -i "s/<string name=\"prerelease_commit_hash\" translatable=\"false\">unknown_prerelease<\/string>/<string name=\"prerelease_commit_hash\">$COMMIT_HASH<\/string>/g" app/src/main/res/values/strings.xml
- name: Fetch keystore
id: fetch_keystore
run: |

View file

@ -1,5 +1,6 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
],
"java.configuration.updateBuildConfiguration": "interactive"
}

View file

@ -13,7 +13,6 @@ if (allFilesFromDir != null) {
prerelaseStoreFile = allFilesFromDir.first()
}
android {
testOptions {
unitTests.returnDefaultValues = true
@ -42,6 +41,9 @@ android {
resValue "string", "app_version",
"${defaultConfig.versionName}${versionNameSuffix ?: ""}"
resValue "string", "commit_hash",
("git rev-parse --short HEAD".execute().text.trim() ?: "")
buildConfigField("String", "BUILDDATE", "new java.text.SimpleDateFormat(\"yyyy-MM-dd HH:mm\").format(new java.util.Date(" + System.currentTimeMillis() + "L));")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@ -57,6 +59,7 @@ android {
// minifyEnabled false
// shrinkResources false
// proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// resValue "bool", "is_prerelease", "false"
// }
prerelease {
applicationIdSuffix ".prerelease"
@ -67,11 +70,13 @@ android {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "bool", "is_prerelease", "true"
}
debug {
debuggable true
applicationIdSuffix ".debug"
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
resValue "bool", "is_prerelease", "true"
}
}
compileOptions {

View file

@ -40,6 +40,8 @@
android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
android:value="com.lagradost.cloudstream3.utils.CastOptionsProvider" />
<profileable android:shell="true" tools:targetApi="q" />
<activity
android:name=".ui.player.DownloadedPlayerActivity"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|keyboard|keyboardHidden|navigation"

View file

@ -8,16 +8,13 @@ import android.content.Intent
import android.content.IntentFilter
import android.net.Uri
import android.os.Environment
import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.core.content.FileProvider
import androidx.core.content.getSystemService
import androidx.preference.PreferenceManager
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.json.JsonMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import com.fasterxml.jackson.module.kotlin.readValue
import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.CommonActivity.showToast
import com.lagradost.cloudstream3.R
@ -34,6 +31,8 @@ class InAppUpdater {
const val GITHUB_USER_NAME = "recloudstream"
const val GITHUB_REPO = "cloudstream"
const val LOG_TAG = "InAppUpdater"
// === IN APP UPDATER ===
data class GithubAsset(
@JsonProperty("name") val name: String,
@ -72,13 +71,13 @@ class InAppUpdater {
private fun Activity.getAppUpdate(): Update {
return try {
val settingsManager = PreferenceManager.getDefaultSharedPreferences(this)
if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), false)) {
if (settingsManager.getBoolean(getString(R.string.prerelease_update_key), resources.getBoolean(R.bool.is_prerelease))) {
getPreReleaseUpdate()
} else {
getReleaseUpdate()
}
} catch (e: Exception) {
println(e)
Log.e(LOG_TAG, Log.getStackTraceString(e))
Update(false, null, null, null, null)
}
}
@ -159,15 +158,19 @@ class InAppUpdater {
val found =
response.lastOrNull { rel ->
rel.prerelease
rel.prerelease || rel.tag_name == "pre-release"
}
val foundAsset = found?.assets?.getOrNull(0)
val foundAsset = found?.assets?.filter { it ->
it.content_type == "application/vnd.android.package-archive"
}?.getOrNull(0)
val tagResponse =
parseJson<GithubTag>(app.get(tagUrl, headers = headers).text)
Log.d(LOG_TAG, "Fetched GitHub tag: ${tagResponse.github_object.sha.take(8)}")
val shouldUpdate =
(getString(R.string.prerelease_commit_hash) != tagResponse.github_object.sha)
(getString(R.string.commit_hash) != tagResponse.github_object.sha.take(8))
return@runBlocking if (foundAsset != null) {
Update(
@ -183,6 +186,8 @@ class InAppUpdater {
}
private fun Activity.downloadUpdate(url: String): Boolean {
Log.d(LOG_TAG, "Downloading update: ${url}")
val downloadManager = getSystemService<DownloadManager>()!!
val request = DownloadManager.Request(Uri.parse(url))

View file

@ -104,14 +104,39 @@
android:nextFocusUp="@id/settings_updates"
android:text="@string/extensions" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:padding="10dp"
android:text="@string/app_version"
android:textColor="?attr/textColor" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="@string/app_version"
android:textColor="?attr/textColor" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="•"
android:textColor="?attr/textColor" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="@string/commit_hash"
android:textColor="?attr/textColor" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>

View file

@ -429,4 +429,6 @@
<string name="sync_score_format">%d na 10</string>
<string name="others">Inne</string>
<string name="other_singular">Wideo</string>
<string name="view_public_repositories_button">Zobacz repozytoria społeczności</string>
<string name="view_public_repositories_button_short">Publiczna lista</string>
</resources>

View file

@ -20,7 +20,6 @@
<string name="video_buffer_length_key" translatable="false">video_buffer_length_key</string>
<string name="video_buffer_clear_key" translatable="false">video_buffer_clear_key</string>
<string name="video_buffer_disk_key" translatable="false">video_buffer_disk_key</string>
<string name="prerelease_commit_hash" translatable="false">unknown_prerelease</string>
<string name="use_system_brightness_key" translatable="false">use_system_brightness_key</string>
<string name="swipe_enabled_key" translatable="false">swipe_enabled_key</string>
<string name="playback_speed_enabled_key" translatable="false">playback_speed_enabled_key</string>
@ -600,6 +599,6 @@
<string name="plugins_disabled" formatted="true">Disabled: %d</string>
<string name="plugins_not_downloaded" formatted="true">Not downloaded: %d</string>
<string name="blank_repo_message">Add a repository to install site extensions</string>
<string name="view_public_repositories_button">View public repositories</string>
<string name="view_public_repositories_button">View community repositories</string>
<string name="view_public_repositories_button_short">Public list</string>
</resources>

View file

@ -43,7 +43,7 @@
android:icon="@drawable/ic_baseline_developer_mode_24"
android:summary="@string/uprereleases_settings_des"
android:title="@string/uprereleases_settings"
app:defaultValue="false"
app:defaultValue="@bool/is_prerelease"
app:key="@string/prerelease_update_key" />
<Preference
android:icon="@drawable/ic_baseline_construction_24"