-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #248 from GuoXiCheng/dev
add ApkVersionButton
- Loading branch information
Showing
10 changed files
with
125 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/com/android/skip/data/version/ApkVersionRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.android.skip.data.version | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.android.skip.R | ||
import com.android.skip.data.network.MyApiNetwork | ||
import com.android.skip.dataclass.VersionPostSchema | ||
import com.android.skip.dataclass.VersionState | ||
import com.blankj.utilcode.util.AppUtils | ||
import com.blankj.utilcode.util.StringUtils.getString | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class ApkVersionRepository @Inject constructor( | ||
private val myApiNetwork: MyApiNetwork | ||
) { | ||
private val _versionPostState = MutableLiveData<VersionPostSchema>() | ||
val versionPostState: LiveData<VersionPostSchema> = _versionPostState | ||
|
||
private suspend fun changeVersionState(versionPostState: VersionPostSchema) = | ||
withContext(Dispatchers.IO) { | ||
_versionPostState.postValue(versionPostState) | ||
val version = myApiNetwork.fetchLatestVersion() | ||
if (version == AppUtils.getAppVersionName()) { | ||
_versionPostState.postValue(VersionPostSchema(VersionState.CURRENT_LATEST, version)) | ||
} else { | ||
_versionPostState.postValue( | ||
VersionPostSchema( | ||
VersionState.DISCOVER_LATEST, | ||
getString(R.string.about_discover_latest) | ||
) | ||
) | ||
} | ||
} | ||
|
||
suspend fun checkVersion() { | ||
changeVersionState( | ||
VersionPostSchema(VersionState.PENDING, getString(R.string.checking)) | ||
) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/android/skip/data/version/ApkVersionViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.android.skip.data.version | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ApkVersionViewModel @Inject constructor( | ||
private val apkVersionRepository: ApkVersionRepository | ||
) : ViewModel() { | ||
val versionPostState = apkVersionRepository.versionPostState | ||
|
||
fun checkVersion() { | ||
viewModelScope.launch { | ||
apkVersionRepository.checkVersion() | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/android/skip/dataclass/VersionPostSchema.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.android.skip.dataclass | ||
|
||
enum class VersionState { | ||
PENDING, CURRENT_LATEST, DISCOVER_LATEST | ||
} | ||
|
||
data class VersionPostSchema( | ||
val status: VersionState, | ||
val value: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/android/skip/ui/about/version/ApkVersionButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.android.skip.ui.about.version | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.livedata.observeAsState | ||
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 | ||
|
||
@Composable | ||
fun ApkVersionButton(apkVersionViewModel: ApkVersionViewModel) { | ||
val versionPostState = apkVersionViewModel.versionPostState.observeAsState() | ||
|
||
FlatButton(content = { | ||
RowContent( | ||
title = R.string.about_app_version, | ||
subTitle = versionPostState.value?.value | ||
) | ||
}, { | ||
apkVersionViewModel.checkVersion() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters