Skip to content

Commit

Permalink
Merge pull request #251 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
update
  • Loading branch information
GuoXiCheng authored Sep 24, 2024
2 parents bf1887c + 87fedad commit 7a6c083
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />


<application
android:name=".MyApp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.android.skip.data.version

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.android.skip.R
import com.android.skip.util.DataStoreUtils
import com.blankj.utilcode.util.StringUtils.getString
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
Expand Down
34 changes: 32 additions & 2 deletions app/src/main/java/com/android/skip/ui/about/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.core.content.FileProvider
import com.android.skip.MyApp
import com.android.skip.R
import com.android.skip.data.config.ConfigViewModel
import com.android.skip.data.download.ApkDownloadViewModel
import com.android.skip.data.version.ApkVersionViewModel
import com.android.skip.dataclass.VersionState
import com.android.skip.ui.about.config.ConfigVersionButton
import com.android.skip.ui.about.download.ApkDownloadDialog
import com.android.skip.data.download.ApkDownloadViewModel
import com.android.skip.ui.about.version.ApkVersionButton
import com.android.skip.ui.components.FlatButton
import com.android.skip.ui.components.ResourceIcon
Expand All @@ -25,7 +26,9 @@ import com.android.skip.ui.components.ScaffoldPage
import com.android.skip.ui.settings.theme.SwitchThemeViewModel
import com.android.skip.ui.theme.AppTheme
import com.android.skip.ui.webview.WebViewActivity
import com.android.skip.util.DataStoreUtils
import dagger.hilt.android.AndroidEntryPoint
import java.io.File

@AndroidEntryPoint
class AboutActivity : AppCompatActivity() {
Expand Down Expand Up @@ -72,9 +75,36 @@ class AboutActivity : AppCompatActivity() {
}
}

var latestVersion = ""
apkVersionViewModel.versionPostState.observe(this) {
if (it.status == VersionState.DISCOVER_LATEST) {
apkDownloadViewModel.changeDialogState(true)
val isNotUpdate =
DataStoreUtils.getSyncData(getString(R.string.store_not_update), false)
if (!isNotUpdate) {
apkDownloadViewModel.changeDialogState(true)
latestVersion = it.latestVersion
}
}
}

apkDownloadViewModel.apkDownloadProcess.observe(this) {
if (it == 100) {
apkDownloadViewModel.changeDialogState(false)

val filename = "SKIP-v$latestVersion.apk"
val path = "${MyApp.context.filesDir}/apk"
val apkFile = File(path, filename)
val apkUri = FileProvider.getUriForFile(
this,
"${packageName}.fileprovider",
apkFile
)

val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
intent.flags =
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
startActivity(intent)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.res.stringResource
import com.android.skip.R
import com.android.skip.data.download.ApkDownloadViewModel
import com.android.skip.data.version.ApkVersionViewModel
import com.android.skip.util.DataStoreUtils
import com.blankj.utilcode.util.AppUtils
import com.blankj.utilcode.util.StringUtils.getString

Expand Down Expand Up @@ -57,9 +58,7 @@ fun ApkDownloadDialog(
}

},
onDismissRequest = {
apkDownloadViewModel.changeDialogState(false)
},
onDismissRequest = {},
confirmButton = {
Button(onClick = {
versionPostState.value?.latestVersion?.let {
Expand All @@ -74,6 +73,7 @@ fun ApkDownloadDialog(
dismissButton = {
TextButton(onClick = { apkDownloadViewModel.changeDialogState(false) }) {
Text(text = stringResource(id = R.string.dialog_not_update))
DataStoreUtils.putSyncData(getString(R.string.store_not_update), true)
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import com.android.skip.R
import com.android.skip.data.version.ApkVersionViewModel
import com.android.skip.ui.components.FlatButton
import com.android.skip.ui.components.RowContent
import com.android.skip.util.DataStoreUtils
import com.blankj.utilcode.util.StringUtils.getString

@Composable
fun ApkVersionButton(apkVersionViewModel: ApkVersionViewModel) {
Expand All @@ -17,6 +19,7 @@ fun ApkVersionButton(apkVersionViewModel: ApkVersionViewModel) {
subTitle = versionPostState.value?.value
)
}, {
DataStoreUtils.removeSync(getString(R.string.store_not_update))
apkVersionViewModel.checkVersion()
})
}
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<string name="dialog_update_now">立即更新</string>
<string name="dialog_not_update">暂不更新</string>
<string name="dialog_new_version_released">新版本已发布</string>
<string name="dialog_update_version">更新版本: v%1$s 至 v%2$s</string>
<string name="dialog_update_version">更新应用: v%1$s 至 v%2$s</string>
<string name="dialog_downloading">下载中: %1$s%%</string>

<string name="store_custom_config">CUSTOM_CONFIG</string>
Expand All @@ -103,6 +103,7 @@
<string name="store_exclude_from_recent">EXCLUDE_FROM_RECENT</string>
<string name="store_auto_update">AUTO_UPDATE</string>
<string name="store_current_theme">CURRENT_THEME</string>
<string name="store_not_update">NOT_UPDATE</string>

<string name="notification_accessibility_service_running">无障碍服务运行中</string>
</resources>

0 comments on commit 7a6c083

Please sign in to comment.