Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zh-rCN (Chinese Simplified) #29

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/src/main/java/io/nekohasekai/sfa/constant/EnabledType.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package io.nekohasekai.sfa.constant

enum class EnabledType(val boolValue: Boolean) {
Enabled(true), Disabled(false);
import android.content.Context
import androidx.annotation.StringRes
import io.nekohasekai.sfa.R

enum class EnabledType(val boolValue: Boolean, @StringRes var stringId: Int) {
Enabled(true, R.string.enabled),
Disabled(false, R.string.disabled);

companion object {
fun from(value: Boolean): EnabledType {
return if (value) Enabled else Disabled
}

fun valueOf(value: String, context: Context): EnabledType = when (value) {
context.getString(Enabled.stringId) -> Enabled
context.getString(Disabled.stringId) -> Disabled
else -> throw IllegalArgumentException()
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package io.nekohasekai.sfa.constant

import android.content.Context
import androidx.annotation.StringRes
import io.nekohasekai.sfa.R
import io.nekohasekai.sfa.database.Settings

enum class PerAppProxyUpdateType {
Disabled, Select, Deselect;
enum class PerAppProxyUpdateType(@StringRes var stringId: Int) {
Disabled(R.string.disabled),
Select(R.string.action_select),
Deselect(R.string.action_deselect);

fun value() = when (this) {
Disabled -> Settings.PER_APP_PROXY_DISABLED
Expand All @@ -12,11 +17,18 @@ enum class PerAppProxyUpdateType {
}

companion object {
fun valueOf(value: Int): PerAppProxyUpdateType = when (value) {
fun from(value: Int): PerAppProxyUpdateType = when (value) {
Settings.PER_APP_PROXY_DISABLED -> Disabled
Settings.PER_APP_PROXY_INCLUDE -> Select
Settings.PER_APP_PROXY_EXCLUDE -> Deselect
else -> throw IllegalArgumentException()
}

fun valueOf(value: String, context: Context): PerAppProxyUpdateType = when (value) {
context.getString(Disabled.stringId) -> Disabled
context.getString(Select.stringId) -> Select
context.getString(Deselect.stringId) -> Deselect
else -> throw IllegalArgumentException()
}
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/io/nekohasekai/sfa/database/TypedProfile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package io.nekohasekai.sfa.database

import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.StringRes
import androidx.room.TypeConverter
import io.nekohasekai.sfa.R
import io.nekohasekai.sfa.ktx.marshall
import io.nekohasekai.sfa.ktx.unmarshall
import java.util.Date

class TypedProfile() : Parcelable {

enum class Type {
Local, Remote;
enum class Type(@StringRes var stringId: Int) {
Local(R.string.profile_type_local),
Remote(R.string.profile_type_remote);

companion object {
fun valueOf(value: Int): Type {
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/io/nekohasekai/sfa/ui/main/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class SettingsFragment : Fragment() {
}
binding.checkUpdateEnabled.addTextChangedListener {
lifecycleScope.launch(Dispatchers.IO) {
val newValue = EnabledType.valueOf(it).boolValue
val newValue = EnabledType.valueOf(it, requireContext()).boolValue
Settings.checkUpdateEnabled = newValue
}
}
Expand All @@ -82,13 +82,13 @@ class SettingsFragment : Fragment() {
}
binding.disableMemoryLimit.addTextChangedListener {
lifecycleScope.launch(Dispatchers.IO) {
val newValue = EnabledType.valueOf(it).boolValue
val newValue = EnabledType.valueOf(it, requireContext()).boolValue
Settings.disableMemoryLimit = !newValue
}
}
binding.dynamicNotificationEnabled.addTextChangedListener {
lifecycleScope.launch(Dispatchers.IO) {
val newValue = EnabledType.valueOf(it).boolValue
val newValue = EnabledType.valueOf(it, requireContext()).boolValue
Settings.dynamicNotification = newValue
}
}
Expand Down Expand Up @@ -137,12 +137,15 @@ class SettingsFragment : Fragment() {
val dynamicNotification = Settings.dynamicNotification
withContext(Dispatchers.Main) {
binding.dataSizeText.text = dataSize
binding.checkUpdateEnabled.text = EnabledType.from(checkUpdateEnabled).name
binding.checkUpdateEnabled.text =
getString(EnabledType.from(checkUpdateEnabled).stringId)
binding.checkUpdateEnabled.setSimpleItems(R.array.enabled)
binding.disableMemoryLimit.text = EnabledType.from(!Settings.disableMemoryLimit).name
binding.disableMemoryLimit.text =
getString(EnabledType.from(!Settings.disableMemoryLimit).stringId)
binding.disableMemoryLimit.setSimpleItems(R.array.enabled)
binding.backgroundPermissionCard.isGone = removeBackgroundPermissionPage
binding.dynamicNotificationEnabled.text = EnabledType.from(dynamicNotification).name
binding.dynamicNotificationEnabled.text =
getString(EnabledType.from(dynamicNotification).stringId)
binding.dynamicNotificationEnabled.setSimpleItems(R.array.enabled)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
}
}
}
binding.type.text = profile.typed.type.name
binding.type.text = getString(profile.typed.type.stringId)
binding.editButton.setOnClickListener {
startActivity(
Intent(
Expand All @@ -88,7 +88,8 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
binding.remoteURL.text = profile.typed.remoteURL
binding.lastUpdated.text =
DateFormat.getDateTimeInstance().format(profile.typed.lastUpdated)
binding.autoUpdate.text = EnabledType.from(profile.typed.autoUpdate).name
binding.autoUpdate.text =
getString(EnabledType.from(profile.typed.autoUpdate).stringId)
binding.autoUpdate.setSimpleItems(R.array.enabled)
binding.autoUpdateInterval.isVisible = profile.typed.autoUpdate
binding.autoUpdateInterval.text = profile.typed.autoUpdateInterval.toString()
Expand All @@ -110,7 +111,7 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
}

private fun updateAutoUpdate(newValue: String) {
val boolValue = EnabledType.valueOf(newValue).boolValue
val boolValue = EnabledType.valueOf(newValue, this).boolValue
if (profile.typed.autoUpdate == boolValue) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import io.nekohasekai.libbox.Libbox
Expand All @@ -29,9 +30,9 @@ import java.io.InputStream
import java.util.Date

class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
enum class FileSource(val formatted: String) {
CreateNew("Create New"),
Import("Import");
enum class FileSource(@StringRes var stringId: Int) {
CreateNew(R.string.profile_source_create_new),
Import(R.string.profile_source_import);
}

private val importFile =
Expand All @@ -49,7 +50,7 @@ class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
intent.getStringExtra("importName")?.also { importName ->
intent.getStringExtra("importURL")?.also { importURL ->
binding.name.editText?.setText(importName)
binding.type.text = TypedProfile.Type.Remote.name
binding.type.text = getString(TypedProfile.Type.Remote.stringId)
binding.remoteURL.editText?.setText(importURL)
binding.localFields.isVisible = false
binding.remoteFields.isVisible = true
Expand All @@ -60,12 +61,12 @@ class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
binding.name.removeErrorIfNotEmpty()
binding.type.addTextChangedListener {
when (it) {
TypedProfile.Type.Local.name -> {
getString(TypedProfile.Type.Local.stringId) -> {
binding.localFields.isVisible = true
binding.remoteFields.isVisible = false
}

TypedProfile.Type.Remote.name -> {
getString(TypedProfile.Type.Remote.stringId) -> {
binding.localFields.isVisible = false
binding.remoteFields.isVisible = true
if (binding.autoUpdateInterval.text.toIntOrNull() == null) {
Expand All @@ -76,12 +77,12 @@ class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
}
binding.fileSourceMenu.addTextChangedListener {
when (it) {
FileSource.CreateNew.formatted -> {
getString(FileSource.CreateNew.stringId) -> {
binding.importFileButton.isVisible = false
binding.sourceURL.isVisible = false
}

FileSource.Import.formatted -> {
getString(FileSource.Import.stringId) -> {
binding.importFileButton.isVisible = true
binding.sourceURL.isVisible = true
}
Expand All @@ -99,17 +100,17 @@ class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
return
}
when (binding.type.text) {
TypedProfile.Type.Local.name -> {
getString(TypedProfile.Type.Local.stringId) -> {
when (binding.fileSourceMenu.text) {
FileSource.Import.formatted -> {
getString(FileSource.Import.stringId) -> {
if (binding.sourceURL.showErrorIfEmpty()) {
return
}
}
}
}

TypedProfile.Type.Remote.name -> {
getString(TypedProfile.Type.Remote.stringId) -> {
if (binding.remoteURL.showErrorIfEmpty()) {
return
}
Expand Down Expand Up @@ -138,15 +139,15 @@ class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
typedProfile.path = configFile.path

when (binding.type.text) {
TypedProfile.Type.Local.name -> {
getString(TypedProfile.Type.Local.stringId) -> {
typedProfile.type = TypedProfile.Type.Local

when (binding.fileSourceMenu.text) {
FileSource.CreateNew.formatted -> {
getString(FileSource.CreateNew.stringId) -> {
configFile.writeText("{}")
}

FileSource.Import.formatted -> {
getString(FileSource.Import.stringId) -> {
val sourceURL = binding.sourceURL.text
val content = if (sourceURL.startsWith("content://")) {
val inputStream =
Expand All @@ -165,15 +166,16 @@ class NewProfileActivity : AbstractActivity<ActivityAddProfileBinding>() {
}
}

TypedProfile.Type.Remote.name -> {
getString(TypedProfile.Type.Remote.stringId) -> {
typedProfile.type = TypedProfile.Type.Remote
val remoteURL = binding.remoteURL.text
val content = HTTPClient().use { it.getString(remoteURL) }
Libbox.checkConfig(content)
configFile.writeText(content)
typedProfile.remoteURL = remoteURL
typedProfile.lastUpdated = Date()
typedProfile.autoUpdate = EnabledType.valueOf(binding.autoUpdate.text).boolValue
typedProfile.autoUpdate =
EnabledType.valueOf(binding.autoUpdate.text, this).boolValue
binding.autoUpdateInterval.text.toIntOrNull()?.also {
typedProfile.autoUpdateInterval = it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class QRScanActivity : AbstractActivity<ActivityQrScanBinding>() {
} else {
setResult(RESULT_CANCELED)
finish()
}
}
}

private lateinit var imageAnalysis: ImageAnalysis
private lateinit var imageAnalyzer: ImageAnalysis.Analyzer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ProfileOverrideActivity :

binding.perAppProxyUpdateOnChange.addTextChangedListener {
lifecycleScope.launch(Dispatchers.IO) {
Settings.perAppProxyUpdateOnChange = PerAppProxyUpdateType.valueOf(it).value()
Settings.perAppProxyUpdateOnChange =
PerAppProxyUpdateType.valueOf(it, this@ProfileOverrideActivity).value()
}
}

Expand All @@ -49,7 +50,7 @@ class ProfileOverrideActivity :
val perAppUpdateOnChange = Settings.perAppProxyUpdateOnChange
withContext(Dispatchers.Main) {
binding.perAppProxyUpdateOnChange.text =
PerAppProxyUpdateType.valueOf(perAppUpdateOnChange).name
getString(PerAppProxyUpdateType.from(perAppUpdateOnChange).stringId)
binding.perAppProxyUpdateOnChange.setSimpleItems(R.array.per_app_proxy_update_on_change_value)
}
}
Expand Down
Loading