Skip to content

Commit

Permalink
Pupil-28 Add option to select update channels
Browse files Browse the repository at this point in the history
  • Loading branch information
tom5079 committed Jan 13, 2020
1 parent b323353 commit 48e0ebc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 22 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
buildTypes.each {
it.buildConfigField('boolean', 'PRERELEASE', 'false')
it.buildConfigField('boolean', 'CENSOR', 'false')
}
}
Expand All @@ -39,7 +38,7 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildToolsVersion = '29.0.1'
buildToolsVersion = '29.0.2'
}

dependencies {
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/xyz/quaver/pupil/ui/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ import xyz.quaver.pupil.Pupil
import xyz.quaver.pupil.R
import xyz.quaver.pupil.types.Tags
import xyz.quaver.pupil.ui.dialog.DownloadLocationDialog
import xyz.quaver.pupil.util.Lock
import xyz.quaver.pupil.util.LockManager
import xyz.quaver.pupil.util.byteToString
import xyz.quaver.pupil.util.getDownloadDirectory
import xyz.quaver.pupil.util.*
import java.io.File
import java.nio.charset.Charset
import java.util.*
Expand Down Expand Up @@ -120,7 +117,13 @@ class SettingsActivity : AppCompatActivity() {
val manager = context.packageManager
val info = manager.getPackageInfo(context.packageName, 0)

summary = info.versionName
summary = context.getString(R.string.settings_app_version_description, info.versionName)

setOnPreferenceClickListener {
checkUpdate(activity as SettingsActivity, true)

true
}
}

with(findPreference<Preference>("delete_cache")) {
Expand Down
24 changes: 12 additions & 12 deletions app/src/main/java/xyz/quaver/pupil/util/update.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,17 @@ fun getReleases(url: String) : JsonArray {
}
}

fun checkUpdate(url: String) : JsonObject? {
fun checkUpdate(context: Context, url: String) : JsonObject? {
val releases = getReleases(url)

if (releases.isEmpty())
return null

return releases.firstOrNull {
if (BuildConfig.PRERELEASE) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("beta", false))
true
} else {
else
it.jsonObject["prerelease"]?.boolean == false
}
}?.let {
if (it.jsonObject["tag_name"]?.content == BuildConfig.VERSION_NAME)
null
Expand All @@ -82,13 +81,13 @@ fun getApkUrl(releases: JsonObject) : String? {
}
}

val UPDATE_NOTIFICATION_ID = 384823
fun checkUpdate(context: AppCompatActivity) {
const val UPDATE_NOTIFICATION_ID = 384823
fun checkUpdate(context: AppCompatActivity, force: Boolean = false) {

val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val ignoreUpdateUntil = preferences.getLong("ignore_update_until", 0)

if (ignoreUpdateUntil > System.currentTimeMillis())
if (!force && ignoreUpdateUntil > System.currentTimeMillis())
return

fun extractReleaseNote(update: JsonObject, locale: Locale) : String {
Expand Down Expand Up @@ -135,7 +134,7 @@ fun checkUpdate(context: AppCompatActivity) {

CoroutineScope(Dispatchers.Default).launch {
val update =
checkUpdate(context.getString(R.string.release_url)) ?: return@launch
checkUpdate(context, context.getString(R.string.release_url)) ?: return@launch

val url = getApkUrl(update) ?: return@launch

Expand Down Expand Up @@ -185,10 +184,11 @@ fun checkUpdate(context: AppCompatActivity) {
notificationManager.notify(UPDATE_NOTIFICATION_ID, builder.build())
}
}
setNegativeButton(R.string.ignore_update) { _, _ ->
preferences.edit()
.putLong("ignore_update_until", System.currentTimeMillis() + 604800000)
.apply()
setNegativeButton(if (force) android.R.string.no else R.string.ignore_update) { _, _ ->
if (!force)
preferences.edit()
.putLong("ignore_update_until", System.currentTimeMillis() + 604800000)
.apply()
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<string name="main_drawer_grouop_contact_discord">ディスコード</string>
<string name="settings_app_lock">アプリロック</string>
<string name="settings_app_lock_type">アップロックの種類</string>
<string name="settings_app_version_title">バージョン</string>
<string name="settings_app_version_title">バージョン(アップデート確認)</string>
<string name="settings_lock_biometrics">生体認識</string>
<string name="settings_lock_confirm">ロック確認のためもう一回入力してください。</string>
<string name="settings_lock_enabled">有効</string>
Expand Down Expand Up @@ -116,4 +116,6 @@
<string name="settings_dl_location_available">%s 使用可能</string>
<string name="update_download_completed">ダウンロードが完了しました</string>
<string name="update_download_completed_description">ここをクリックしてアップデートを行えます</string>
<string name="settings_beta">ベータチャンネルでアップデートを受信</string>
<string name="settings_app_version_description">v%s</string>
</resources>
4 changes: 3 additions & 1 deletion app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<string name="main_drawer_grouop_contact_discord">디스코드</string>
<string name="settings_app_lock">앱 잠금</string>
<string name="settings_app_lock_type">앱 잠금 종류</string>
<string name="settings_app_version_title">앱 버전</string>
<string name="settings_app_version_title">앱 버전(업데이트 확인)</string>
<string name="settings_lock_biometrics">생체 인식</string>
<string name="settings_lock_confirm">잠금 확인을 위해 한번 더 입력해주세요</string>
<string name="settings_lock_enabled">사용 중</string>
Expand Down Expand Up @@ -116,4 +116,6 @@
<string name="settings_dl_location_available">%s 사용 가능</string>
<string name="update_download_completed">다운로드가 완료되었습니다</string>
<string name="update_download_completed_description">여기를 클릭해서 업데이트를 진행할 수 있습니다</string>
<string name="settings_beta">베타 채널에서 업데이트</string>
<string name="settings_app_version_description">v%s</string>
</resources>
7 changes: 6 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@

<string name="settings_title">Settings</string>

<string name="settings_app_version_title">App version</string>
<string name="settings_app_version_title">App version(Click to check update)</string>
<string name="settings_app_version_description">v%s</string>
<string name="settings_beta">Update from beta channel</string>

<!-- SEARCH -->

<string name="settings_search_title">Search Settings</string>
<string name="settings_galleries_per_page">Galleries per page</string>
<string name="settings_default_query">Default query</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
app:title="@string/settings_app_version_title"
app:key="app_version"/>

<SwitchPreference
app:title="@string/settings_beta"
app:key="beta"/>

<PreferenceCategory
app:title="@string/settings_search_title">

Expand Down

0 comments on commit 48e0ebc

Please sign in to comment.