Skip to content

Commit

Permalink
alert android 10+ users to use github release version
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhoavn committed Jun 1, 2021
1 parent e05c3e0 commit 1e3c395
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
java-version: '12.x'
- name: "Build"
run: |
USE_SPLITBUILD=1 ./gradlew assembleRelease
USE_SPLITBUILD=1 CI_BUILD=1 ./gradlew assembleRelease
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down
12 changes: 8 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
ndkVersion '21.3.6528147'

dexOptions {
Expand All @@ -14,9 +13,13 @@ android {
defaultConfig {
applicationId "vn.vhn.vsc"
minSdkVersion 24
targetSdkVersion 28 // Do not update to 29 - /data/data no longer executable
versionCode 19
versionName "1.2.1"
if (System.env['CI_BUILD'] == '1') {
targetSdkVersion 28 // Do not update to 29 - /data/data no longer executable
} else {
targetSdkVersion 29 // google play require minimum version to be 29
}
versionCode 20
versionName "1.2.2"

externalNativeBuild {
ndkBuild {
Expand Down Expand Up @@ -93,6 +96,7 @@ dependencies {
implementation 'org.apache.commons:commons-compress:1.20'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.0.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true">
<activity
android:name=".GithubReleaseInstallActivity"
android:launchMode="singleInstance"></activity>

<service
android:name="vn.vhn.vhscode.CodeServerService"
android:name=".CodeServerService"
android:enabled="true"
android:exported="true"></service>
android:exported="true" />

<activity android:name=".VSCodeActivity">
<intent-filter>
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/vn/vhn/vhscode/GithubReleaseInstallActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package vn.vhn.vhscode

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.method.LinkMovementMethod
import kotlinx.android.synthetic.main.activity_github_release_install.*

class GithubReleaseInstallActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_github_release_install)

txtReleaseLink.movementMethod = LinkMovementMethod.getInstance()
}
}
66 changes: 63 additions & 3 deletions app/src/main/java/vn/vhn/vhscode/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import android.content.SharedPreferences
import android.content.pm.PackageManager
import android.os.Bundle
import android.text.Editable
import android.text.Html
import android.text.TextWatcher
import android.text.method.LinkMovementMethod
import android.view.View
import android.view.Window
import android.view.WindowManager
Expand All @@ -27,9 +29,9 @@ import com.termux.app.TermuxInstaller
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.io.File
import java.io.FileInputStream
import java.io.IOException
import java.io.*
import java.net.URL
import java.util.*


class MainActivity : AppCompatActivity() {
Expand All @@ -46,6 +48,7 @@ class MainActivity : AppCompatActivity() {
var startServerObserver: Observer<Int>? = null
var serverLogObserver: Observer<String>? = null
var requestedPermission: Boolean = false
var latestRemoteVersion: String? = null

override fun onResume() {
super.onResume()
Expand Down Expand Up @@ -179,10 +182,62 @@ class MainActivity : AppCompatActivity() {
sharedPreferences().edit().putString(kPrefRemoteServer, s.toString()).apply()
}
})

creditLine.movementMethod = LinkMovementMethod.getInstance()
txtAppVersion.movementMethod = LinkMovementMethod.getInstance()

checkLatestVersion()
}

private fun checkLatestVersion() {
CoroutineScope(Dispatchers.IO).launch {
val yahoo = URL("https://github.com/vhqtvn/VHEditor-Android/releases/latest")
val br = BufferedReader(
InputStreamReader(
yahoo.openStream()
)
)

var inputLine: String?
var version = ""

val versionExtractor = Regex("\"/vhqtvn/VHEditor-Android/releases/tag/v([\\d\\.]+)\"")

while (br.readLine().also { inputLine = it } != null) {
if (inputLine != null) {
val matches = versionExtractor.find(inputLine!!)
if (matches != null) {
version = matches!!.groupValues[1]
}
}
}

br.close()

if (version != "" && version != latestRemoteVersion) {
latestRemoteVersion = version
updateUI()
}
}
}

fun updateUI() {
if (wrongTargetSDK()) {
val intent = Intent(this, GithubReleaseInstallActivity::class.java)
startActivity(intent)
finish()
}
CoroutineScope(Dispatchers.Main).launch {
var txtVersion = "App version: ${BuildConfig.VERSION_NAME}"
if (latestRemoteVersion != null) {
if (latestRemoteVersion == BuildConfig.VERSION_NAME) {
txtVersion += ", already latest version."
} else {
txtVersion += ", latest version: <a href=\"https://github.com/vhqtvn/VHEditor-Android/releases/latest\">${latestRemoteVersion}</a>"
}
}
txtAppVersion.text = Html.fromHtml(txtVersion, 0)

sharedPreferences().apply {
chkHardKeyboard.isChecked = getBoolean(kPrefHardKeyboard, false)
chkKeepScreenAlive.isChecked = getBoolean(kPrefKeepScreenAlive, false)
Expand Down Expand Up @@ -215,6 +270,11 @@ class MainActivity : AppCompatActivity() {
}
}

private fun wrongTargetSDK(): Boolean {
val targetSdkVersion = applicationContext.applicationInfo.targetSdkVersion
return android.os.Build.VERSION.SDK_INT >= 29 && targetSdkVersion != 28
}

private fun performRequestPermissions() {
CoroutineScope(Dispatchers.Main).launch {
if (requestedPermission) return@launch
Expand Down
34 changes: 34 additions & 0 deletions app/src/main/res/layout/activity_github_release_install.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
tools:context=".GithubReleaseInstallActivity">

<TextView
android:id="@+id/txtVersionNotSupported"
android:text="@string/wrong_target_sdk"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="12dp"
android:textColor="@color/white"
android:gravity="center_vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/txtReleaseLink"
/>

<TextView
android:id="@+id/txtReleaseLink"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/link_release"
android:layout_marginBottom="12dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
21 changes: 18 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,39 @@
android:gravity="center"
android:text="@string/credit"
android:textColor="@color/credit"
app:layout_constraintBottom_toTopOf="@+id/txtInstalledServerVersion"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toTopOf="@+id/txtAppVersion"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txtAppName" />

<TextView
android:id="@+id/txtInstalledServerVersion"
android:id="@+id/txtAppVersion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="18dp"
android:gravity="center"
android:text="@string/loading"
android:textColor="@color/white"
app:layout_constraintBottom_toTopOf="@+id/btnInstallServer"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toTopOf="@+id/txtInstalledServerVersion"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/creditLine" />

<TextView
android:id="@+id/txtInstalledServerVersion"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/loading"
android:textColor="@color/white"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toTopOf="@+id/btnInstallServer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/txtAppVersion" />

<Button
android:id="@+id/btnInstallServer"
style="?android:attr/borderlessButtonStyle"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
<string name="reset_root_fs_finished">Reset rootfs finished</string>
<string name="server_listen_on_all_interfaces">Server listen on all interfaces</string>
<string name="use_https">Use https</string>
<string name="link_release"><a href="https://github.com/vhqtvn/VHEditor-Android/releases/latest">github.com/vhqtvn/VHEditor-Android</a></string>
<string name="wrong_target_sdk"><h1>I\'m sorry!</h1>\nAndroid api version <b>28</b> is required to make termux embedding works.\nBut now Google Play <b>disabled</b> uploading applications with targetSdk 28, devices with <b>Android 10 and later can\'t use VHEditor version installed from Google Play</b>.\nPlease tap the <b>following link</b> to download latest release from VHEditor\'s github repository.</string>
</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 1e3c395

Please sign in to comment.