From a4151fb198e2ff7bffc4286c4277965ee25589df Mon Sep 17 00:00:00 2001 From: Kr328 <39107975+Kr328@users.noreply.github.com> Date: Sat, 21 Dec 2019 11:56:02 +0800 Subject: [PATCH] cleanup code & update version code --- app/build.gradle | 4 +- .../kr328/clash/BootCompleteReceiver.kt | 1 - .../kr328/clash/CreateProfileActivity.kt | 2 +- .../github/kr328/clash/FeedbackActivity.kt | 9 +++- .../github/kr328/clash/ImportUrlActivity.kt | 49 ++++++++++--------- .../com/github/kr328/clash/LogActivity.kt | 20 +++++--- .../com/github/kr328/clash/MainActivity.kt | 13 +++-- .../com/github/kr328/clash/MainApplication.kt | 5 +- .../github/kr328/clash/ProfilesActivity.kt | 25 +++++----- .../com/github/kr328/clash/ProxyActivity.kt | 11 +++-- .../kr328/clash/SettingApplicationActivity.kt | 5 +- .../com/github/kr328/clash/TileService.kt | 13 ++--- .../github/kr328/clash/adapter/FormAdapter.kt | 7 ++- .../github/kr328/clash/adapter/LogAdapter.kt | 12 +++-- .../kr328/clash/adapter/ProfileAdapter.kt | 35 +++++++------ .../kr328/clash/adapter/ProxyAdapter.kt | 10 ++-- .../com/github/kr328/clash/model/ClashRule.kt | 20 ++++++-- .../com/github/kr328/clash/model/ListProxy.kt | 8 ++- .../github/kr328/clash/utils/ServiceUtils.kt | 2 +- .../kr328/clash/view/MarqueeTextView.kt | 2 +- 20 files changed, 153 insertions(+), 100 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index bf8fd5e..11e1a0e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,8 +13,8 @@ android { applicationId "com.github.kr328.clash" minSdkVersion 24 targetSdkVersion 29 - versionCode 10028 - versionName "1.0.28-alpha" + versionCode 10029 + versionName "1.0.29-alpha" } buildTypes { release { diff --git a/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt b/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt index 7c66681..798c66d 100644 --- a/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt +++ b/app/src/main/java/com/github/kr328/clash/BootCompleteReceiver.kt @@ -3,7 +3,6 @@ package com.github.kr328.clash import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import android.os.Build import com.github.kr328.clash.utils.ServiceUtils class BootCompleteReceiver : BroadcastReceiver() { diff --git a/app/src/main/java/com/github/kr328/clash/CreateProfileActivity.kt b/app/src/main/java/com/github/kr328/clash/CreateProfileActivity.kt index 1330088..a29e5a6 100644 --- a/app/src/main/java/com/github/kr328/clash/CreateProfileActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/CreateProfileActivity.kt @@ -54,7 +54,7 @@ class CreateProfileActivity : BaseActivity() { } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - if ( requestCode == IMPORT_REQUEST_CODE && resultCode == Activity.RESULT_OK ) { + if (requestCode == IMPORT_REQUEST_CODE && resultCode == Activity.RESULT_OK) { finish() return } diff --git a/app/src/main/java/com/github/kr328/clash/FeedbackActivity.kt b/app/src/main/java/com/github/kr328/clash/FeedbackActivity.kt index 5f8ab06..4b01192 100644 --- a/app/src/main/java/com/github/kr328/clash/FeedbackActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/FeedbackActivity.kt @@ -25,9 +25,14 @@ class FeedbackActivity : BaseActivity() { onPreferenceClickListener = Preference.OnPreferenceClickListener { p -> val data = ClipData.newPlainText("userIdentifier", summary) - requireContext().getSystemService(ClipboardManager::class.java)?.setPrimaryClip(data) + requireContext().getSystemService(ClipboardManager::class.java) + ?.setPrimaryClip(data) - Toast.makeText(requireContext(), R.string.feedback_feedback_id_copied, Toast.LENGTH_LONG).show() + Toast.makeText( + requireContext(), + R.string.feedback_feedback_id_copied, + Toast.LENGTH_LONG + ).show() true } diff --git a/app/src/main/java/com/github/kr328/clash/ImportUrlActivity.kt b/app/src/main/java/com/github/kr328/clash/ImportUrlActivity.kt index da238ff..517429c 100644 --- a/app/src/main/java/com/github/kr328/clash/ImportUrlActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/ImportUrlActivity.kt @@ -6,18 +6,13 @@ import android.os.Bundle import android.os.ParcelFileDescriptor import android.view.View import androidx.recyclerview.widget.LinearLayoutManager -import com.charleskorn.kaml.Yaml -import com.charleskorn.kaml.YamlConfiguration import com.charleskorn.kaml.YamlException import com.github.kr328.clash.adapter.FormAdapter -import com.github.kr328.clash.model.ClashProfile import com.github.kr328.clash.service.data.ClashProfileEntity import com.github.kr328.clash.utils.FileUtils import com.google.android.material.snackbar.Snackbar import kotlinx.android.synthetic.main.activity_import_url.* import java.io.FileOutputStream -import java.net.InetSocketAddress -import java.net.Proxy import java.net.URL import kotlin.concurrent.thread @@ -54,9 +49,10 @@ class ImportUrlActivity : BaseActivity() { checkAndInsert() } - if ( intent.action == Intent.ACTION_VIEW + if (intent.action == Intent.ACTION_VIEW && intent.data?.scheme == "clash" - && intent.data?.host == "install-config") { + && intent.data?.host == "install-config" + ) { (elements[1] as FormAdapter.TextType).content = intent.data?.getQueryParameter("url") ?: "" } @@ -78,11 +74,11 @@ class ImportUrlActivity : BaseActivity() { val name = elements[0] as FormAdapter.TextType val url = elements[1] as FormAdapter.TextType - if ( name.content.isBlank() ) { + if (name.content.isBlank()) { return } - if ( url.content.isBlank() ) { + if (url.content.isBlank()) { return } @@ -94,7 +90,7 @@ class ImportUrlActivity : BaseActivity() { try { val connection = URL(url.content).openConnection() - val data = with (connection) { + val data = with(connection) { connectTimeout = DEFAULT_TIMEOUT connect() @@ -117,22 +113,29 @@ class ImportUrlActivity : BaseActivity() { pipe[0].close() - if ( error != null ) + if (error != null) throw Exception(error) val cache = - FileUtils.generateRandomFile(filesDir.resolve(Constants.PROFILES_DIR), ".yaml") + FileUtils.generateRandomFile( + filesDir.resolve(Constants.PROFILES_DIR), + ".yaml" + ) FileOutputStream(cache).use { outputStream -> outputStream.write(data.toByteArray()) } runClash { clash -> - clash.profileService.addProfile(ClashProfileEntity(name.content, - ClashProfileEntity.urlToken(url.content), - cache.absolutePath, - false, - System.currentTimeMillis())) + clash.profileService.addProfile( + ClashProfileEntity( + name.content, + ClashProfileEntity.urlToken(url.content), + cache.absolutePath, + false, + System.currentTimeMillis() + ) + ) } runOnUiThread { @@ -140,12 +143,15 @@ class ImportUrlActivity : BaseActivity() { finish() } - } - catch (e: Exception) { + } catch (e: Exception) { runOnUiThread { Snackbar.make( activity_import_url_root, - getString(R.string.clash_profile_invalid, e.message?.replace(YamlException::class.java.name + ":", "") ?: "Unknown"), + getString( + R.string.clash_profile_invalid, + e.message?.replace(YamlException::class.java.name + ":", "") + ?: "Unknown" + ), Snackbar.LENGTH_LONG ).show() @@ -155,8 +161,7 @@ class ImportUrlActivity : BaseActivity() { } } } - } - catch (e: Exception) { + } catch (e: Exception) { } } diff --git a/app/src/main/java/com/github/kr328/clash/LogActivity.kt b/app/src/main/java/com/github/kr328/clash/LogActivity.kt index ff339ee..45036f8 100644 --- a/app/src/main/java/com/github/kr328/clash/LogActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/LogActivity.kt @@ -46,9 +46,11 @@ class LogActivity : BaseActivity() { activity_logs_list.adapter?.notifyDataSetChanged() runClash { - it.eventService.registerEventObserver(LogActivity::class.java.name, + it.eventService.registerEventObserver( + LogActivity::class.java.name, this, - intArrayOf(Event.EVENT_LOG)) + intArrayOf(Event.EVENT_LOG) + ) } } @@ -70,18 +72,20 @@ class LogActivity : BaseActivity() { handler.post { buffer.addFirst(event) - if ( syncLog ) { + if (syncLog) { activity_logs_list.adapter!!.notifyItemInserted(0) - if ( activity_logs_list.computeVerticalScrollOffset() < 30 ) + if (activity_logs_list.computeVerticalScrollOffset() < 30) activity_logs_list.scrollToPosition(0) } - if ( buffer.size() >= MAX_EVENT_COUNT ) { + if (buffer.size() >= MAX_EVENT_COUNT) { buffer.removeFromEnd(buffer.size() - MAX_EVENT_COUNT - 1) - if ( syncLog ) { - activity_logs_list.adapter?.notifyItemRangeRemoved(MAX_EVENT_COUNT - 1, - buffer.size() - MAX_EVENT_COUNT - 1 ) + if (syncLog) { + activity_logs_list.adapter?.notifyItemRangeRemoved( + MAX_EVENT_COUNT - 1, + buffer.size() - MAX_EVENT_COUNT - 1 + ) } } } diff --git a/app/src/main/java/com/github/kr328/clash/MainActivity.kt b/app/src/main/java/com/github/kr328/clash/MainActivity.kt index 1b504ea..28e8cb9 100644 --- a/app/src/main/java/com/github/kr328/clash/MainActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/MainActivity.kt @@ -94,7 +94,10 @@ class MainActivity : BaseActivity() { activity_main_clash_status_icon.setImageResource(R.drawable.ic_clash_started) activity_main_clash_status_title.text = getString(R.string.clash_status_started) activity_main_clash_status_summary.text = - getString(R.string.clash_status_forwarded_traffic, ByteFormatter.byteToString(0)) + getString( + R.string.clash_status_forwarded_traffic, + ByteFormatter.byteToString(0) + ) activity_main_clash_proxies.visibility = View.VISIBLE activity_main_clash_logs.visibility = View.VISIBLE } @@ -116,7 +119,7 @@ class MainActivity : BaseActivity() { val general = it.queryGeneral() runOnUiThread { - when ( general.mode ) { + when (general.mode) { General.Mode.DIRECT -> activity_main_clash_proxies_summary.text = getText(R.string.clash_proxy_manage_summary_direct) @@ -198,9 +201,11 @@ class MainActivity : BaseActivity() { } private fun showAboutDialog() { - val view = LayoutInflater.from(this).inflate(R.layout.dialog_about, window.decorView as ViewGroup?, false) + val view = LayoutInflater.from(this) + .inflate(R.layout.dialog_about, window.decorView as ViewGroup?, false) - view.findViewById(android.R.id.summary).text = packageManager.getPackageInfo(packageName, 0).let(PackageInfo::versionName) + view.findViewById(android.R.id.summary).text = + packageManager.getPackageInfo(packageName, 0).let(PackageInfo::versionName) AlertDialog.Builder(this).setView(view).show() } diff --git a/app/src/main/java/com/github/kr328/clash/MainApplication.kt b/app/src/main/java/com/github/kr328/clash/MainApplication.kt index 6bbb678..0ef3d22 100644 --- a/app/src/main/java/com/github/kr328/clash/MainApplication.kt +++ b/app/src/main/java/com/github/kr328/clash/MainApplication.kt @@ -9,7 +9,6 @@ import com.github.kr328.clash.core.utils.Log import com.google.firebase.FirebaseApp import io.fabric.sdk.android.Fabric import java.security.MessageDigest -import kotlin.experimental.and class MainApplication : Application() { @@ -35,7 +34,7 @@ class MainApplication : Application() { return this.map { Integer.toHexString(it.toInt() and 0xff) }.map { - if ( it.length < 2 ) + if (it.length < 2) "0$it" else it @@ -63,7 +62,7 @@ class MainApplication : Application() { Crashlytics.setBool(CRASHLYTICS_SPLIT_APK_KEY, detectSplitArchive()) Crashlytics.setUserIdentifier(userIdentifier) - Log.handler = object: Log.LogHandler { + Log.handler = object : Log.LogHandler { override fun info(message: String, throwable: Throwable?) { android.util.Log.i(Constants.TAG, message, throwable) } diff --git a/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt b/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt index 91ec84d..224a07b 100644 --- a/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/ProfilesActivity.kt @@ -9,19 +9,14 @@ import android.view.View import android.widget.PopupMenu import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager -import com.charleskorn.kaml.Yaml -import com.charleskorn.kaml.YamlConfiguration import com.github.kr328.clash.adapter.ProfileAdapter import com.github.kr328.clash.core.event.ErrorEvent import com.github.kr328.clash.core.event.ProfileChangedEvent -import com.github.kr328.clash.model.ClashProfile import com.github.kr328.clash.service.data.ClashProfileEntity import com.google.android.material.snackbar.Snackbar import kotlinx.android.synthetic.main.activity_profiles.* import java.io.File import java.io.FileOutputStream -import java.net.InetSocketAddress -import java.net.Proxy import java.net.URL import kotlin.concurrent.thread @@ -35,10 +30,12 @@ class ProfilesActivity : BaseActivity() { setSupportActionBar(activity_profiles_toolbar) activity_profiles_main_list.layoutManager = LinearLayoutManager(this) - activity_profiles_main_list.adapter = ProfileAdapter(this, + activity_profiles_main_list.adapter = ProfileAdapter( + this, this::onProfileClick, this::onOperateClick, - this::onProfileLongClick) { + this::onProfileLongClick + ) { startActivity(Intent(this, CreateProfileActivity::class.java)) } } @@ -114,7 +111,7 @@ class ProfilesActivity : BaseActivity() { .setCancelable(false) .show() - updateProfile(profile) + updateProfile(profile) } ClashProfileEntity.isFileToken(profile.token) -> { Snackbar.make( @@ -150,7 +147,7 @@ class ProfilesActivity : BaseActivity() { try { val connection = URL(url).openConnection() - val data = with (connection) { + val data = with(connection) { connectTimeout = ImportUrlActivity.DEFAULT_TIMEOUT connect() @@ -172,7 +169,7 @@ class ProfilesActivity : BaseActivity() { pipe[0].close() - if ( error != null ) + if (error != null) throw Exception(error) FileOutputStream(profile.file).use { outputStream -> @@ -182,8 +179,7 @@ class ProfilesActivity : BaseActivity() { runClash { clash -> clash.profileService.touchProfile(profile.id) } - } - catch (e: Exception) { + } catch (e: Exception) { runOnUiThread { Snackbar.make( activity_profiles_root, @@ -194,7 +190,7 @@ class ProfilesActivity : BaseActivity() { } runOnUiThread { - if ( dialog?.isShowing == true ) + if (dialog?.isShowing == true) dialog?.dismiss() } } @@ -202,6 +198,7 @@ class ProfilesActivity : BaseActivity() { } override fun onErrorEvent(event: ErrorEvent?) { - Snackbar.make(activity_profiles_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG).show() + Snackbar.make(activity_profiles_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG) + .show() } } \ No newline at end of file diff --git a/app/src/main/java/com/github/kr328/clash/ProxyActivity.kt b/app/src/main/java/com/github/kr328/clash/ProxyActivity.kt index 8446a35..ff9fcab 100644 --- a/app/src/main/java/com/github/kr328/clash/ProxyActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/ProxyActivity.kt @@ -39,18 +39,18 @@ class ProxyActivity : BaseActivity() { val adapter = (activity_proxies_list.adapter as ProxyAdapter) runClash { - val proxies = adapter.elements.subList(position, position+size) + val proxies = adapter.elements.subList(position, position + size) .filterIsInstance() - .mapIndexed { index, proxy -> proxy.name to IndexedValue(index, proxy)} + .mapIndexed { index, proxy -> proxy.name to IndexedValue(index, proxy) } .toMap() for ((_, p) in proxies) { p.value.delay = -1 } - it.startUrlTest(proxies.keys.toTypedArray(), object: IUrlTestCallback.Stub() { + it.startUrlTest(proxies.keys.toTypedArray(), object : IUrlTestCallback.Stub() { override fun onResult(proxy: String?, delay: Long) { - if ( proxy == null ) { + if (proxy == null) { (adapter.elements[position] as ListProxy.ListProxyHeader).urlTest = false runOnUiThread { @@ -177,6 +177,7 @@ class ProxyActivity : BaseActivity() { } override fun onErrorEvent(event: ErrorEvent?) { - Snackbar.make(activity_proxies_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG).show() + Snackbar.make(activity_proxies_root, event?.message ?: "Unknown", Snackbar.LENGTH_LONG) + .show() } } \ No newline at end of file diff --git a/app/src/main/java/com/github/kr328/clash/SettingApplicationActivity.kt b/app/src/main/java/com/github/kr328/clash/SettingApplicationActivity.kt index c127a10..7ca62e0 100644 --- a/app/src/main/java/com/github/kr328/clash/SettingApplicationActivity.kt +++ b/app/src/main/java/com/github/kr328/clash/SettingApplicationActivity.kt @@ -50,7 +50,7 @@ class SettingApplicationActivity : BaseActivity() { } override fun onPreferenceChange(preference: Preference?, newValue: Any?): Boolean { - if ( !isAdded ) + if (!isAdded) return false when (preference?.key) { @@ -60,8 +60,7 @@ class SettingApplicationActivity : BaseActivity() { thread { try { setBootCompleteReceiverEnabled(enabled) - } - catch (e: Exception) { + } catch (e: Exception) { Log.w("Set boot complete failure", e) } } diff --git a/app/src/main/java/com/github/kr328/clash/TileService.kt b/app/src/main/java/com/github/kr328/clash/TileService.kt index 3ec689c..4fb8192 100644 --- a/app/src/main/java/com/github/kr328/clash/TileService.kt +++ b/app/src/main/java/com/github/kr328/clash/TileService.kt @@ -7,10 +7,8 @@ import android.content.IntentFilter import android.service.quicksettings.Tile import android.service.quicksettings.TileService import com.github.kr328.clash.core.event.ProcessEvent -import com.github.kr328.clash.core.event.ProfileReloadEvent import com.github.kr328.clash.service.ClashService import com.github.kr328.clash.service.Constants -import com.github.kr328.clash.service.IClashEventObserver import com.github.kr328.clash.service.IClashService import com.github.kr328.clash.service.data.ClashProfileEntity import com.github.kr328.clash.utils.ServiceUtils @@ -41,7 +39,7 @@ class TileService : TileService() { } private fun refreshStatus() { - if ( qsTile == null ) + if (qsTile == null) return val current = getCurrentStatus() @@ -86,11 +84,14 @@ class TileService : TileService() { private fun getCurrentStatus(): Pair { val service = - IClashService.Stub.asInterface(clashStatusReceiver - .peekService(this, Intent(this, ClashService::class.java))) + IClashService.Stub.asInterface( + clashStatusReceiver + .peekService(this, Intent(this, ClashService::class.java)) + ) return runCatching { - (service?.currentProcessStatus ?: ProcessEvent.STOPPED) to service?.profileService?.queryActiveProfile() + (service?.currentProcessStatus + ?: ProcessEvent.STOPPED) to service?.profileService?.queryActiveProfile() }.getOrNull() ?: ProcessEvent.STOPPED to null } } \ No newline at end of file diff --git a/app/src/main/java/com/github/kr328/clash/adapter/FormAdapter.kt b/app/src/main/java/com/github/kr328/clash/adapter/FormAdapter.kt index f8d9e34..50fc57b 100644 --- a/app/src/main/java/com/github/kr328/clash/adapter/FormAdapter.kt +++ b/app/src/main/java/com/github/kr328/clash/adapter/FormAdapter.kt @@ -127,7 +127,12 @@ class FormAdapter( return elements[position].javaClass.hashCode() } - private fun showTextEditDialog(initial: String, title: String, hint: String, callback: (String) -> Unit) { + private fun showTextEditDialog( + initial: String, + title: String, + hint: String, + callback: (String) -> Unit + ) { MaterialAlertDialogBuilder(activity) .setTitle(title) .setView(R.layout.dialog_text_edit) diff --git a/app/src/main/java/com/github/kr328/clash/adapter/LogAdapter.kt b/app/src/main/java/com/github/kr328/clash/adapter/LogAdapter.kt index d728a19..f5fbd1a 100644 --- a/app/src/main/java/com/github/kr328/clash/adapter/LogAdapter.kt +++ b/app/src/main/java/com/github/kr328/clash/adapter/LogAdapter.kt @@ -12,8 +12,10 @@ import com.github.kr328.clash.core.event.LogEvent import java.text.SimpleDateFormat import java.util.* -class LogAdapter(private val content: Context, - private val buffer: CircularArray) : RecyclerView.Adapter() { +class LogAdapter( + private val content: Context, + private val buffer: CircularArray +) : RecyclerView.Adapter() { private val formatter = SimpleDateFormat("HH:mm:ss", Locale.getDefault()) class Holder(view: View) : RecyclerView.ViewHolder(view) { @@ -23,8 +25,10 @@ class LogAdapter(private val content: Context, } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder { - return Holder(LayoutInflater.from(content) - .inflate(R.layout.adapter_log, parent, false)) + return Holder( + LayoutInflater.from(content) + .inflate(R.layout.adapter_log, parent, false) + ) } override fun getItemCount(): Int { diff --git a/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt b/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt index 62b7426..e4b0fbc 100644 --- a/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt +++ b/app/src/main/java/com/github/kr328/clash/adapter/ProfileAdapter.kt @@ -11,11 +11,13 @@ import com.github.kr328.clash.view.RadioFatItem import java.text.SimpleDateFormat import java.util.* -class ProfileAdapter(private val context: Context, - private val onClick: (ClashProfileEntity) -> Unit, - private val onOperateClick: (ClashProfileEntity) -> Unit, - private val onLongClicked: (View,ClashProfileEntity) -> Unit, - private val onNewProfile: () -> Unit) : +class ProfileAdapter( + private val context: Context, + private val onClick: (ClashProfileEntity) -> Unit, + private val onOperateClick: (ClashProfileEntity) -> Unit, + private val onLongClicked: (View, ClashProfileEntity) -> Unit, + private val onNewProfile: () -> Unit +) : RecyclerView.Adapter() { var profiles: Array = emptyArray() @@ -23,7 +25,7 @@ class ProfileAdapter(private val context: Context, class NewProfileHolder(val view: FatItem) : RecyclerView.ViewHolder(view) override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { - if ( viewType == 0 ) { + if (viewType == 0) { return NewProfileHolder(FatItem(context).apply { layoutParams = ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, @@ -47,7 +49,7 @@ class ProfileAdapter(private val context: Context, } override fun onBindViewHolder(raw: RecyclerView.ViewHolder, position: Int) { - if ( position == profiles.size ) { + if (position == profiles.size) { val holder = raw as NewProfileHolder holder.view.icon = context.getDrawable(R.drawable.ic_new_profile) @@ -80,9 +82,10 @@ class ProfileAdapter(private val context: Context, } val now = Calendar.getInstance() - val formatter = if ( profileUpdateDate.get(Calendar.YEAR) == now.get(Calendar.YEAR) && + val formatter = if (profileUpdateDate.get(Calendar.YEAR) == now.get(Calendar.YEAR) && profileUpdateDate.get(Calendar.MONTH) == now.get(Calendar.MONTH) && - profileUpdateDate.get(Calendar.DAY_OF_MONTH) == now.get(Calendar.DAY_OF_MONTH) ) + profileUpdateDate.get(Calendar.DAY_OF_MONTH) == now.get(Calendar.DAY_OF_MONTH) + ) SimpleDateFormat("HH:mm:ss", Locale.getDefault()) else SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) @@ -90,19 +93,23 @@ class ProfileAdapter(private val context: Context, when { ClashProfileEntity.isFileToken(current.token) -> { holder.view.operation = context.getDrawable(R.drawable.ic_edit) - holder.view.summary = context.getString(R.string.clash_profile_item_summary_file, - formatter.format(profileUpdateDate.time)) + holder.view.summary = context.getString( + R.string.clash_profile_item_summary_file, + formatter.format(profileUpdateDate.time) + ) } ClashProfileEntity.isUrlToken(current.token) -> { holder.view.operation = context.getDrawable(R.drawable.ic_sync) - holder.view.summary = context.getString(R.string.clash_profile_item_summary_url, - formatter.format(profileUpdateDate.time)) + holder.view.summary = context.getString( + R.string.clash_profile_item_summary_url, + formatter.format(profileUpdateDate.time) + ) } } } override fun getItemViewType(position: Int): Int { - return if ( position == profiles.size ) + return if (position == profiles.size) 0 else 1 diff --git a/app/src/main/java/com/github/kr328/clash/adapter/ProxyAdapter.kt b/app/src/main/java/com/github/kr328/clash/adapter/ProxyAdapter.kt index 495a5e5..3bdcd05 100644 --- a/app/src/main/java/com/github/kr328/clash/adapter/ProxyAdapter.kt +++ b/app/src/main/java/com/github/kr328/clash/adapter/ProxyAdapter.kt @@ -13,9 +13,11 @@ import com.github.kr328.clash.core.model.Proxy import com.github.kr328.clash.model.ListProxy import com.google.android.material.card.MaterialCardView -class ProxyAdapter(private val context: Context, - private val onSelect: (String, String) -> Unit, - private val onUrlTest: (Int, Int) -> Unit) : +class ProxyAdapter( + private val context: Context, + private val onSelect: (String, String) -> Unit, + private val onUrlTest: (Int, Int) -> Unit +) : RecyclerView.Adapter() { var elements: List = emptyList() var clickable: Boolean = false @@ -141,7 +143,7 @@ class ProxyAdapter(private val context: Context, holder.test.visibility = if (current.type == Proxy.Type.SELECT) View.VISIBLE else View.GONE holder.test.setOnClickListener { - if ( current.urlTest ) + if (current.urlTest) return@setOnClickListener val indexed = elements.withIndex() diff --git a/app/src/main/java/com/github/kr328/clash/model/ClashRule.kt b/app/src/main/java/com/github/kr328/clash/model/ClashRule.kt index 37ed8a1..3b6665d 100644 --- a/app/src/main/java/com/github/kr328/clash/model/ClashRule.kt +++ b/app/src/main/java/com/github/kr328/clash/model/ClashRule.kt @@ -5,7 +5,12 @@ import kotlinx.serialization.* import kotlinx.serialization.internal.StringDescriptor @Serializable(ClashRule.Serializer::class) -data class ClashRule(val matcher: Matcher, val pattern: String, val target: String, val extras: List) { +data class ClashRule( + val matcher: Matcher, + val pattern: String, + val target: String, + val extras: List +) { enum class Matcher { DOMAIN_SUFFIX, DOMAIN_KEYWORD, @@ -76,7 +81,12 @@ data class ClashRule(val matcher: Matcher, val pattern: String, val target: Stri ClashRule(Matcher.fromString(rule[0]), rule[1], rule[2], emptyList()) } else -> { - ClashRule(Matcher.fromString(rule[0]), rule[1], rule[2], rule.subList(3, rule.size)) + ClashRule( + Matcher.fromString(rule[0]), + rule[1], + rule[2], + rule.subList(3, rule.size) + ) } } } @@ -85,7 +95,11 @@ data class ClashRule(val matcher: Matcher, val pattern: String, val target: Stri if (obj.matcher == Matcher.MATCH) { encoder.encodeString("${obj.matcher},${obj.target}") } else { - encoder.encodeString("${obj.matcher},${obj.pattern},${obj.target},${obj.extras.joinToString(",")}") + encoder.encodeString( + "${obj.matcher},${obj.pattern},${obj.target},${obj.extras.joinToString( + "," + )}" + ) } } } diff --git a/app/src/main/java/com/github/kr328/clash/model/ListProxy.kt b/app/src/main/java/com/github/kr328/clash/model/ListProxy.kt index 5f751ee..116dd5b 100644 --- a/app/src/main/java/com/github/kr328/clash/model/ListProxy.kt +++ b/app/src/main/java/com/github/kr328/clash/model/ListProxy.kt @@ -3,7 +3,13 @@ package com.github.kr328.clash.model import com.github.kr328.clash.core.model.Proxy interface ListProxy { - data class ListProxyHeader(val name: String, val type: Proxy.Type, val now: String, var nowIndex: Int, var urlTest: Boolean = false) : + data class ListProxyHeader( + val name: String, + val type: Proxy.Type, + val now: String, + var nowIndex: Int, + var urlTest: Boolean = false + ) : ListProxy data class ListProxyItem( diff --git a/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt b/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt index 9e68f1a..fdfb403 100644 --- a/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt +++ b/app/src/main/java/com/github/kr328/clash/utils/ServiceUtils.kt @@ -19,7 +19,7 @@ object ServiceUtils { MainApplication.PROXY_MODE_VPN -> { val prepare = VpnService.prepare(context) - if ( prepare != null ) + if (prepare != null) return prepare context.startService(Intent(context, TunService::class.java)) diff --git a/app/src/main/java/com/github/kr328/clash/view/MarqueeTextView.kt b/app/src/main/java/com/github/kr328/clash/view/MarqueeTextView.kt index c4c8282..3a09e2a 100644 --- a/app/src/main/java/com/github/kr328/clash/view/MarqueeTextView.kt +++ b/app/src/main/java/com/github/kr328/clash/view/MarqueeTextView.kt @@ -10,7 +10,7 @@ class MarqueeTextView @JvmOverloads constructor( attributeSet: AttributeSet? = null, defStyleAttr: Int = 0, defStyleRes: Int = 0 -): TextView(context, attributeSet, defStyleAttr, defStyleRes) { +) : TextView(context, attributeSet, defStyleAttr, defStyleRes) { init { ellipsize = TextUtils.TruncateAt.MARQUEE }