Skip to content

Commit

Permalink
Refine code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Aug 28, 2024
1 parent c2ff4a2 commit 7e7116b
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 32 deletions.
2 changes: 0 additions & 2 deletions buildSrc/src/main/kotlin/Helpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import com.android.build.api.dsl.CommonExtension
import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.ExtensionAware
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByName
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.kotlinExtension
import java.util.Locale

const val lifecycleVersion = "2.8.4"
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class VpnService : BaseVpnService(), BaseService.Interface {

override val isVpnService get() = true

private suspend fun startVpn(): FileDescriptor {
private fun startVpn(): FileDescriptor {
val profile = data.proxy!!.profile
val builder = Builder()
.setConfigureIntent(Core.configureIntent(this))
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/com/github/shadowsocks/database/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ data class Profile(
remoteDns = json["remote_dns"].optString ?: remoteDns
ipv6 = json["ipv6"].optBoolean ?: ipv6
metered = json["metered"].optBoolean ?: metered
(json["proxy_apps"] as? JsonObject)?.also {
proxyApps = it["enabled"].optBoolean ?: proxyApps
bypass = it["bypass"].optBoolean ?: bypass
individual = (it["android_list"] as? JsonArray)?.asIterable()?.mapNotNull { it.optString }
(json["proxy_apps"] as? JsonObject)?.also { obj ->
proxyApps = obj["enabled"].optBoolean ?: proxyApps
bypass = obj["bypass"].optBoolean ?: bypass
individual = (obj["android_list"] as? JsonArray)?.asIterable()?.mapNotNull { it.optString }
?.joinToString("\n") ?: individual
}
udpdns = json["udpdns"].optBoolean ?: udpdns
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ object DefaultNetworkListener {
}

suspend fun start(key: Any, listener: (Network?) -> Unit) = networkActor.send(NetworkMessage.Start(key, listener))
suspend fun get() = if (fallback) @TargetApi(23) {
suspend fun get() = if (fallback) {
Core.connectivity.activeNetwork ?: throw UnknownHostException() // failed to listen, return current if available
} else NetworkMessage.Get().run {
networkActor.send(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ sealed class DnsResolverCompat {
abstract suspend fun resolveRaw(network: Network, query: ByteArray): ByteArray
abstract suspend fun resolveRawOnActiveNetwork(query: ByteArray): ByteArray

private object DnsResolverCompat23 : DnsResolverCompat() {
private data object DnsResolverCompat23 : DnsResolverCompat() {
/**
* This dispatcher is used for noncancellable possibly-forever-blocking operations in network IO.
*
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/github/shadowsocks/net/HttpsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class HttpsTest : ViewModel() {
protected abstract val status: CharSequence
open fun retrieve(setStatus: (CharSequence) -> Unit, errorCallback: (String) -> Unit) = setStatus(status)

object Idle : Status() {
data object Idle : Status() {
override val status get() = app.getText(R.string.vpn_connected)
}
object Testing : Status() {
data object Testing : Status() {
override val status get() = app.getText(R.string.connection_test_testing)
}
class Success(private val elapsed: Long) : Status() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ object PluginManager {
}
val provider = providers.single().providerInfo
val options = configuration.getOptions { provider.loadString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) }
val isV2 = provider.applicationInfo.metaData?.getString(PluginContract.METADATA_KEY_VERSION)
?.substringBefore('.')?.toIntOrNull() ?: 0 >= 2
val isV2 = (provider.applicationInfo.metaData?.getString(PluginContract.METADATA_KEY_VERSION)
?.substringBefore('.')?.toIntOrNull() ?: 0) >= 2
var failure: Throwable? = null
try {
initNativeFaster(provider)?.also { return InitResult(it, options, isV2) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ object Commandline {
* An empty or null toProcess parameter results in a zero sized array.
*/
fun translateCommandline(toProcess: String?): Array<String> {
if (toProcess == null || toProcess.isEmpty()) {
if (toProcess.isNullOrEmpty()) {
//no command? no string
return arrayOf()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener,
private val domainPattern =
"(?<=^(?:\\(\\^\\|\\\\\\.\\)|\\^\\(\\.\\*\\\\\\.\\)\\?|\\(\\?:\\^\\|\\\\\\.\\))).*(?=\\\$\$)".toRegex()

@Suppress("FunctionName")
private fun AclItem(item: Any) = when (item) {
is String -> AclItem(item, false)
is Subnet -> AclItem(item.toString(), false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ import androidx.appcompat.widget.TooltipCompat
import androidx.dynamicanimation.animation.DynamicAnimation
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.withStarted
import androidx.vectordrawable.graphics.drawable.Animatable2Compat
import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat
import com.github.shadowsocks.R
import com.github.shadowsocks.bg.BaseService
import com.google.android.material.floatingactionbutton.FloatingActionButton
import com.google.android.material.progressindicator.BaseProgressIndicator
import com.google.android.material.progressindicator.DeterminateDrawable
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import java.util.*
import kotlinx.coroutines.launch
import java.util.ArrayDeque

class ServiceButton @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) :
FloatingActionButton(context, attrs, defStyleAttr), DynamicAnimation.OnAnimationEndListener {
Expand Down Expand Up @@ -74,10 +75,12 @@ class ServiceButton @JvmOverloads constructor(context: Context, attrs: Attribute
private val iconConnecting by lazy {
AnimatedState(R.drawable.ic_service_connecting) {
hideProgress()
delayedAnimation = (context as LifecycleOwner).lifecycleScope.launchWhenStarted {
delayedAnimation = (context as LifecycleOwner).lifecycleScope.launch {
delay(context.resources.getInteger(android.R.integer.config_mediumAnimTime) + 1000L)
isIndeterminate = true
show()
context.lifecycle.withStarted {
isIndeterminate = true
show()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
limitations under the License.
-->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<selector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:override="true">
<item android:alpha="1.00" android:color="@color/color_primary_text" android:state_checkable="true" android:state_checked="true" android:state_enabled="true"/>
<item android:alpha="0.60" android:color="?attr/colorOnSurface" android:state_checkable="true" android:state_checked="false" android:state_enabled="true"/>
<item android:alpha="1.00" android:color="@color/color_primary_text" android:state_enabled="true"/>
Expand Down
20 changes: 10 additions & 10 deletions release.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

release=$1
cp mobile/build/outputs/apk/release/mobile-armeabi-v7a-release.apk shadowsocks-armeabi-v7a-${release}.apk
cp mobile/build/outputs/apk/release/mobile-arm64-v8a-release.apk shadowsocks-arm64-v8a-${release}.apk
cp mobile/build/outputs/apk/release/mobile-x86-release.apk shadowsocks-x86-${release}.apk
cp mobile/build/outputs/apk/release/mobile-x86_64-release.apk shadowsocks-x86_64-${release}.apk
cp mobile/build/outputs/apk/release/mobile-universal-release.apk shadowsocks--universal-${release}.apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-armeabi-v7a-release.apk shadowsocks-tv-armeabi-v7a-${release}.apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-arm64-v8a-release.apk shadowsocks-tv-arm64-v8a-${release}.apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-x86-release.apk shadowsocks-tv-x86-${release}.apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-x86_64-release.apk shadowsocks-tv-x86_64-${release}.apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-universal-release.apk shadowsocks-tv-universal-${release}.apk
cp mobile/build/outputs/apk/release/mobile-armeabi-v7a-release.apk shadowsocks-armeabi-v7a-"${release}".apk
cp mobile/build/outputs/apk/release/mobile-arm64-v8a-release.apk shadowsocks-arm64-v8a-"${release}".apk
cp mobile/build/outputs/apk/release/mobile-x86-release.apk shadowsocks-x86-"${release}".apk
cp mobile/build/outputs/apk/release/mobile-x86_64-release.apk shadowsocks-x86_64-"${release}".apk
cp mobile/build/outputs/apk/release/mobile-universal-release.apk shadowsocks--universal-"${release}".apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-armeabi-v7a-release.apk shadowsocks-tv-armeabi-v7a-"${release}".apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-arm64-v8a-release.apk shadowsocks-tv-arm64-v8a-"${release}".apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-x86-release.apk shadowsocks-tv-x86-"${release}".apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-x86_64-release.apk shadowsocks-tv-x86_64-"${release}".apk
cp tv/build/outputs/apk/freedom/release/tv-freedom-universal-release.apk shadowsocks-tv-universal-"${release}".apk
2 changes: 1 addition & 1 deletion tv/src/main/java/com/github/shadowsocks/tv/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class MainFragment : LeanbackSettingsFragmentCompat() {
}
return true
}
if (pref is ListPreference && pref !is MultiSelectListPreference) {
if (pref is ListPreference) {
startPreferenceFragment(LeanbackSingleListPreferenceDialogFragment().apply {
arguments = bundleOf(Pair(LeanbackPreferenceDialogFragmentCompat.ARG_KEY, pref.key))
setTargetFragment(caller, 0)
Expand Down

0 comments on commit 7e7116b

Please sign in to comment.