Skip to content

Commit

Permalink
Make linter happy
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Mar 16, 2024
1 parent 78dd252 commit 75a35d3
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 34 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/io/nekohasekai/sfa/Application.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Application : Application() {

Seq.setContext(this)

@Suppress("OPT_IN_USAGE")
GlobalScope.launch(Dispatchers.IO) {
UpdateProfileWork.reconfigureUpdater()
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/nekohasekai/sfa/bg/AppChangeReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class AppChangeReceiver : BroadcastReceiver() {

override fun onReceive(context: Context, intent: Intent) {
Log.d(TAG, "onReceive: ${intent.action}")
checkUpdate(context, intent)
checkUpdate(intent)
}

private fun checkUpdate(context: Context, intent: Intent) {
private fun checkUpdate(intent: Intent) {
if (!Settings.perAppProxyEnabled) {
Log.d(TAG, "per app proxy disabled")
return
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/nekohasekai/sfa/bg/BootReceiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import io.nekohasekai.sfa.database.Settings
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class BootReceiver : BroadcastReceiver() {

@OptIn(DelicateCoroutinesApi::class)
override fun onReceive(context: Context, intent: Intent) {
when (intent.action) {
Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED -> {
Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/io/nekohasekai/sfa/bg/BoxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.database.ProfileManager
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.ktx.hasPermission
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -243,6 +244,7 @@ class BoxService(
}
}

@OptIn(DelicateCoroutinesApi::class)
private fun stopService() {
if (status.value != Status.Started) return
status.value = Status.Stopping
Expand Down Expand Up @@ -298,7 +300,9 @@ class BoxService(
}
}

fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@OptIn(DelicateCoroutinesApi::class)
@Suppress("SameReturnValue")
internal fun onStartCommand(): Int {
if (status.value != Status.Stopped) return Service.START_NOT_STICKY
status.value = Status.Starting

Expand Down Expand Up @@ -327,19 +331,19 @@ class BoxService(
return Service.START_NOT_STICKY
}

fun onBind(intent: Intent): IBinder {
internal fun onBind(): IBinder {
return binder
}

fun onDestroy() {
internal fun onDestroy() {
binder.close()
}

fun onRevoke() {
internal fun onRevoke() {
stopService()
}

fun writeLog(message: String) {
internal fun writeLog(message: String) {
binder.broadcast {
it.onServiceWriteLog(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ import android.os.Handler
import android.os.Looper
import io.nekohasekai.sfa.Application
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.ObsoleteCoroutinesApi
import kotlinx.coroutines.channels.actor
import kotlinx.coroutines.runBlocking

Expand All @@ -49,6 +51,7 @@ object DefaultNetworkListener {
class Lost(val network: Network) : NetworkMessage()
}

@OptIn(DelicateCoroutinesApi::class, ObsoleteCoroutinesApi::class)
private val networkActor = GlobalScope.actor<NetworkMessage>(Dispatchers.Unconfined) {
val listeners = mutableMapOf<Any, (Network?) -> Unit>()
var network: Network? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ interface PlatformInterfaceWrapper : PlatformInterface {
}

override fun readWIFIState(): WIFIState? {
@Suppress("DEPRECATION")
val wifiInfo = Application.wifiManager.connectionInfo ?: return null
var ssid = wifiInfo.ssid
if (ssid.startsWith("\"") && ssid.endsWith("\"")) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/nekohasekai/sfa/bg/ProxyService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class ProxyService : Service(), PlatformInterfaceWrapper {
private val service = BoxService(this, this)

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
service.onStartCommand(intent, flags, startId)
service.onStartCommand()

override fun onBind(intent: Intent) = service.onBind(intent)
override fun onBind(intent: Intent) = service.onBind()
override fun onDestroy() = service.onDestroy()

override fun writeLog(message: String) = service.writeLog(message)
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/nekohasekai/sfa/bg/ServiceBinder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
import io.nekohasekai.sfa.aidl.IService
import io.nekohasekai.sfa.aidl.IServiceCallback
import io.nekohasekai.sfa.constant.Status
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand All @@ -23,6 +24,7 @@ class ServiceBinder(private val status: MutableLiveData<Status>) : IService.Stub
}
}

@OptIn(DelicateCoroutinesApi::class)
fun broadcast(work: (IServiceCallback) -> Unit) {
GlobalScope.launch(Dispatchers.Main) {
broadcastLock.withLock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import io.nekohasekai.sfa.constant.Status
import io.nekohasekai.sfa.database.Settings
import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.utils.CommandClient
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.withContext
Expand All @@ -43,6 +44,7 @@ class ServiceNotification(
}
}

@OptIn(DelicateCoroutinesApi::class)
private val commandClient =
CommandClient(GlobalScope, CommandClient.ConnectionType.Status, this)
private var receiverRegistered = false
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/io/nekohasekai/sfa/bg/VPNService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class VPNService : VpnService(), PlatformInterfaceWrapper {
private val service = BoxService(this, this)

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int) =
service.onStartCommand(intent, flags, startId)
service.onStartCommand()

override fun onBind(intent: Intent): IBinder {
val binder = super.onBind(intent)
if (binder != null) {
return binder
}
return service.onBind(intent)
return service.onBind()
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.nekohasekai.sfa.database
import androidx.room.Room
import io.nekohasekai.sfa.Application
import io.nekohasekai.sfa.constant.Path
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

Expand All @@ -19,6 +20,7 @@ object ProfileManager {
callbacks.remove(callback)
}

@OptIn(DelicateCoroutinesApi::class)
private val instance by lazy {
Application.application.getDatabasePath(Path.PROFILES_DATABASE_PATH).parentFile?.mkdirs()
Room
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/io/nekohasekai/sfa/database/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import io.nekohasekai.sfa.ktx.int
import io.nekohasekai.sfa.ktx.long
import io.nekohasekai.sfa.ktx.string
import io.nekohasekai.sfa.ktx.stringSet
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.io.File

object Settings {

@OptIn(DelicateCoroutinesApi::class)
private val instance by lazy {
Application.application.getDatabasePath(Path.SETTINGS_DATABASE_PATH).parentFile?.mkdirs()
Room.databaseBuilder(
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/nekohasekai/sfa/ktx/Shares.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ suspend fun Context.shareProfile(profile: Profile) {
}
}

suspend fun FragmentActivity.shareProfileURL(profile: Profile) {
fun FragmentActivity.shareProfileURL(profile: Profile) {
val link = Libbox.generateRemoteProfileImportLink(
profile.name,
profile.typed.remoteURL
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/io/nekohasekai/sfa/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ class MainActivity : AbstractActivity<ActivityMainBinding>(),
return navController.navigateUp(appBarConfiguration)
}

@Suppress("UNUSED_PARAMETER")
private fun onDestinationChanged(
navController: NavController,
navDestination: NavDestination,
bundle: Bundle?
) {
val binding = binding ?: return
val destinationId = navDestination.id
binding.dashboardTabContainer.isVisible = destinationId == R.id.navigation_dashboard
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import io.nekohasekai.sfa.ktx.errorDialogBuilder
import io.nekohasekai.sfa.ktx.text
import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.utils.CommandClient
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -152,6 +153,7 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
private lateinit var adapter: ItemAdapter
private lateinit var textWatcher: TextWatcher

@OptIn(DelicateCoroutinesApi::class)
@SuppressLint("NotifyDataSetChanged")
fun bind(group: OutboundGroup) {
this.group = group
Expand Down Expand Up @@ -185,6 +187,7 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
updateExpand()
}

@OptIn(DelicateCoroutinesApi::class)
private fun updateExpand(isExpand: Boolean? = null) {
val newExpandStatus = isExpand ?: group.isExpand
if (isExpand != null) {
Expand Down Expand Up @@ -280,6 +283,7 @@ class GroupsFragment : Fragment(), CommandClient.Handler {
private class ItemGroupView(val binding: ViewDashboardGroupItemBinding) :
RecyclerView.ViewHolder(binding.root) {

@OptIn(DelicateCoroutinesApi::class)
fun bind(groupView: GroupView, group: OutboundGroup, item: OutboundGroupItem) {
if (group.selectable) {
binding.itemCard.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import io.nekohasekai.sfa.ktx.getAttrColor
import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.utils.CommandClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
Expand Down Expand Up @@ -224,6 +225,7 @@ class OverviewFragment : Fragment() {
private inner class ClashModeItemView(val binding: ViewClashModeButtonBinding) :
RecyclerView.ViewHolder(binding.root) {

@OptIn(DelicateCoroutinesApi::class)
fun bind(item: String, selected: String) {
binding.clashModeButtonText.text = item
if (item != selected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class VPNScanActivity : AbstractActivity<ActivityVpnScanBinding>() {

private suspend fun scanVPN() {
val adapter = adapter ?: return
val binding = binding ?: return
val flag =
PackageManager.GET_SERVICES or if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
PackageManager.MATCH_UNINSTALLED_PACKAGES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
Expand All @@ -29,10 +28,12 @@ import io.nekohasekai.sfa.ui.MainActivity
import io.nekohasekai.sfa.ui.profile.EditProfileActivity
import io.nekohasekai.sfa.ui.profile.NewProfileActivity
import io.nekohasekai.sfa.ui.profile.QRScanActivity
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.text.DateFormat
import java.util.Collections

class ConfigurationFragment : Fragment() {
Expand Down Expand Up @@ -126,7 +127,7 @@ class ConfigurationFragment : Fragment() {

internal var items: MutableList<Profile> = mutableListOf()
internal val scope = lifecycleScope
internal val fragmentActivity = requireActivity() as FragmentActivity
internal val fragmentActivity = requireActivity()

@SuppressLint("NotifyDataSetChanged")
internal fun reload() {
Expand Down Expand Up @@ -160,6 +161,7 @@ class ConfigurationFragment : Fragment() {
return true
}

@OptIn(DelicateCoroutinesApi::class)
internal fun updateUserOrder() {
items.forEachIndexed { index, profile ->
profile.userOrder = index.toLong()
Expand Down Expand Up @@ -199,7 +201,7 @@ class ConfigurationFragment : Fragment() {
binding.profileLastUpdated.isVisible = true
binding.profileLastUpdated.text = binding.root.context.getString(
R.string.profile_item_last_updated,
profile.typed.lastUpdated.toLocaleString()
DateFormat.getDateTimeInstance().format(profile.typed.lastUpdated)
)
} else {
binding.profileLastUpdated.isVisible = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {
private fun enablePager() {
val activity = activity ?: return
val binding = binding ?: return
activity.binding?.dashboardTabLayout?.isVisible = true
activity.binding.dashboardTabLayout.isVisible = true
binding.dashboardPager.isUserInputEnabled = true
}

private fun disablePager() {
val activity = activity ?: return
val binding = binding ?: return
activity.binding?.dashboardTabLayout?.isVisible = false
activity.binding.dashboardTabLayout.isVisible = false
binding.dashboardPager.isUserInputEnabled = false
binding.dashboardPager.setCurrentItem(0, false)
}
Expand All @@ -119,11 +119,11 @@ class DashboardFragment : Fragment(R.layout.fragment_dashboard) {

class Adapter(parent: Fragment) : FragmentStateAdapter(parent) {
override fun getItemCount(): Int {
return Page.values().size
return Page.entries.size
}

override fun createFragment(position: Int): Fragment {
return Page.values()[position].fragmentClass.newInstance()
return Page.entries[position].fragmentClass.getConstructor().newInstance()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
}

private fun updateAutoUpdate(newValue: String) {
val binding = binding ?: return
val boolValue = EnabledType.valueOf(newValue).boolValue
if (profile.typed.autoUpdate == boolValue) {
return
Expand All @@ -126,7 +125,6 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
}

private fun updateAutoUpdateInterval(newValue: String) {
val binding = binding ?: return
if (newValue.isBlank()) {
binding.autoUpdateInterval.error = getString(R.string.profile_input_required)
return
Expand All @@ -148,7 +146,6 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
}

private fun updateProfile() {
val binding = binding ?: return
binding.progressView.isVisible = true
lifecycleScope.launch(Dispatchers.IO) {
delay(200L)
Expand All @@ -165,8 +162,8 @@ class EditProfileActivity : AbstractActivity<ActivityEditProfileBinding>() {
}
}

@Suppress("UNUSED_PARAMETER")
private fun updateProfile(view: View) {
val binding = binding ?: return
binding.progressView.isVisible = true
lifecycleScope.launch(Dispatchers.IO) {
try {
Expand Down
Loading

0 comments on commit 75a35d3

Please sign in to comment.