From 6939efed0d1c9d0fc90489a58339685922cc8ec6 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sun, 29 Jul 2018 00:39:45 +0800 Subject: [PATCH] Refine styling --- detekt.yml | 109 +++++++++++++++++- .../vpnhotspot/LocalOnlyHotspotService.kt | 2 +- .../java/be/mygod/vpnhotspot/MainActivity.kt | 14 +-- .../be/mygod/vpnhotspot/RepeaterService.kt | 2 +- .../vpnhotspot/client/ClientsFragment.kt | 12 +- .../vpnhotspot/manage/InterfaceManager.kt | 2 +- .../manage/LocalOnlyHotspotManager.kt | 2 +- .../be/mygod/vpnhotspot/manage/ManageBar.kt | 2 +- .../be/mygod/vpnhotspot/manage/Manager.kt | 6 +- .../vpnhotspot/manage/TetheringFragment.kt | 12 +- .../mygod/vpnhotspot/net/TetheringManager.kt | 2 +- .../net/wifi/P2pSupplicantConfiguration.kt | 3 +- ...eEditTextPreferenceDialogFragmentCompat.kt | 4 +- .../util/ServiceForegroundConnector.kt | 8 +- .../widget/AlwaysAutoCompleteEditText.kt | 2 +- 15 files changed, 140 insertions(+), 42 deletions(-) diff --git a/detekt.yml b/detekt.yml index 2ff0fc29..a977acaa 100644 --- a/detekt.yml +++ b/detekt.yml @@ -1,4 +1,5 @@ -# https://github.com/arturbosch/detekt/blob/RC6-4/detekt-cli/src/main/resources/default-detekt-config.yml +# https://github.com/arturbosch/detekt/blob/RC8/detekt-cli/src/main/resources/default-detekt-config.yml +autoCorrect: true comments: active: false @@ -46,12 +47,14 @@ complexity: thresholdInInterfaces: 11 thresholdInObjects: 11 thresholdInEnums: 11 + ignoreDeprecated: true + ignorePrivate: false empty-blocks: active: true EmptyCatchBlock: active: true - allowedExceptionNameRegex: "^(_|ignore|expected).*" + allowedExceptionNameRegex: "^(_|(ignore|expected).*)" EmptyClassBlock: active: true EmptyDefaultConstructor: @@ -125,6 +128,90 @@ exceptions: - Throwable - RuntimeException +formatting: + active: true + android: true + autoCorrect: true + ChainWrapping: + active: true + autoCorrect: true + CommentSpacing: + active: false + Filename: + active: true + FinalNewline: + active: true + autoCorrect: true + ImportOrdering: + active: true + autoCorrect: false + Indentation: + active: true + autoCorrect: true + indentSize: 4 + continuationIndentSize: 4 + MaximumLineLength: + active: false + ModifierOrdering: + active: true + autoCorrect: true + NoBlankLineBeforeRbrace: + active: true + autoCorrect: true + NoConsecutiveBlankLines: + active: true + autoCorrect: true + NoEmptyClassBody: + active: true + autoCorrect: true + NoItParamInMultilineLambda: + active: true + NoLineBreakAfterElse: + active: true + autoCorrect: true + NoLineBreakBeforeAssignment: + active: true + autoCorrect: true + NoMultipleSpaces: + active: false + NoSemicolons: + active: true + autoCorrect: true + NoTrailingSpaces: + active: true + autoCorrect: true + NoUnitReturn: + active: true + autoCorrect: true + NoUnusedImports: + active: true + autoCorrect: true + NoWildcardImports: + active: false + ParameterListWrapping: + active: false + SpacingAroundColon: + active: true + autoCorrect: true + SpacingAroundComma: + active: true + autoCorrect: true + SpacingAroundCurly: + active: true + autoCorrect: true + SpacingAroundKeyword: + active: true + autoCorrect: true + SpacingAroundOperators: + active: true + autoCorrect: true + SpacingAroundRangeOperator: + active: true + autoCorrect: true + StringTemplate: + active: true + autoCorrect: true + naming: active: true ClassNaming: @@ -153,14 +240,15 @@ naming: ObjectPropertyNaming: active: true propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + constantPattern: '[A-Za-z][_A-Za-z0-9]*' PackageNaming: active: true packagePattern: '^[a-z]+(\.[a-z][a-z0-9]*)*$' TopLevelPropertyNaming: active: true constantPattern: '[A-Z][_A-Z0-9]*' - propertyPattern: '[a-z][A-Za-z\d]*' - privatePropertyPattern: '(_)?[a-z][A-Za-z0-9]*' + propertyPattern: '[A-Za-z][_A-Za-z0-9]*' + privatePropertyPattern: '(_)?[A-Za-z][A-Za-z0-9]*' VariableMaxLength: active: true maximumVariableNameLength: 64 @@ -223,6 +311,7 @@ style: active: true ExpressionBodySyntax: active: true + includeLineWrapping: false ForbiddenComment: active: true values: 'TODO:,FIXME:,STOPSHIP:' @@ -238,11 +327,14 @@ style: maxJumpCount: 1 MagicNumber: active: false + MandatoryBracesIfStatements: + active: false MaxLineLength: active: true maxLineLength: 120 - excludePackageStatements: false - excludeImportStatements: false + excludePackageStatements: true + excludeImportStatements: true + excludeCommentStatements: true MayBeConst: active: true ModifierOrder: @@ -259,6 +351,8 @@ style: active: true OptionalWhenBraces: active: true + PreferToOverPairSyntax: + active: false ProtectedMemberInFinalClass: active: true RedundantVisibilityModifierRule: @@ -288,9 +382,12 @@ style: active: true UnusedPrivateMember: active: true + allowedNames: "(_|ignored|expected|serialVersionUID)" UseDataClass: active: false UtilityClassWithPublicConstructor: active: true + VarCouldBeVal: + active: false WildcardImport: active: false diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt index 21d01120..0c956105 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/LocalOnlyHotspotService.kt @@ -3,8 +3,8 @@ package be.mygod.vpnhotspot import android.content.Intent import android.content.IntentFilter import android.net.wifi.WifiManager -import androidx.annotation.RequiresApi import android.widget.Toast +import androidx.annotation.RequiresApi import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.manage.LocalOnlyHotspotManager import be.mygod.vpnhotspot.net.IpNeighbourMonitor diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt b/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt index 398af633..c663953c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/MainActivity.kt @@ -3,24 +3,24 @@ package be.mygod.vpnhotspot import android.content.ComponentName import android.content.Intent import android.content.ServiceConnection -import androidx.databinding.DataBindingUtil import android.net.Uri import android.os.Bundle import android.os.IBinder -import androidx.browser.customtabs.CustomTabsIntent -import com.google.android.material.bottomnavigation.BottomNavigationView -import com.google.android.material.snackbar.Snackbar -import androidx.fragment.app.Fragment -import androidx.core.content.ContextCompat -import androidx.appcompat.app.AppCompatActivity import android.view.Gravity import android.view.MenuItem +import androidx.appcompat.app.AppCompatActivity +import androidx.browser.customtabs.CustomTabsIntent +import androidx.core.content.ContextCompat +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment import be.mygod.vpnhotspot.client.ClientMonitorService import be.mygod.vpnhotspot.client.ClientsFragment import be.mygod.vpnhotspot.databinding.ActivityMainBinding import be.mygod.vpnhotspot.manage.TetheringFragment import be.mygod.vpnhotspot.util.ServiceForegroundConnector import com.google.android.material.bottomnavigation.BottomNavigationMenuView +import com.google.android.material.bottomnavigation.BottomNavigationView +import com.google.android.material.snackbar.Snackbar import q.rorbin.badgeview.QBadgeView class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener, ServiceConnection { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt index ce3fa9b6..e8419bc9 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/RepeaterService.kt @@ -10,9 +10,9 @@ import android.net.wifi.p2p.WifiP2pGroup import android.net.wifi.p2p.WifiP2pInfo import android.net.wifi.p2p.WifiP2pManager import android.os.Looper -import androidx.annotation.StringRes import android.util.Log import android.widget.Toast +import androidx.annotation.StringRes import androidx.core.content.getSystemService import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt index b5356a77..1b4745cb 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/client/ClientsFragment.kt @@ -2,17 +2,17 @@ package be.mygod.vpnhotspot.client import android.content.ComponentName import android.content.ServiceConnection -import androidx.databinding.DataBindingUtil import android.os.Bundle import android.os.IBinder -import androidx.fragment.app.Fragment -import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.DefaultItemAnimator -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.DefaultItemAnimator +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.databinding.FragmentRepeaterBinding import be.mygod.vpnhotspot.databinding.ListitemClientBinding diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/InterfaceManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/InterfaceManager.kt index c1ed6142..fc41c644 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/InterfaceManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/InterfaceManager.kt @@ -1,9 +1,9 @@ package be.mygod.vpnhotspot.manage import android.content.Intent +import android.view.View import androidx.core.content.ContextCompat import androidx.recyclerview.widget.RecyclerView -import android.view.View import be.mygod.vpnhotspot.TetheringService import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding import be.mygod.vpnhotspot.net.TetherType diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt index fd9d4ab0..c2ec0b68 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/LocalOnlyHotspotManager.kt @@ -11,10 +11,10 @@ import android.location.LocationManager import android.os.Build import android.os.IBinder import android.provider.Settings -import androidx.recyclerview.widget.RecyclerView import android.view.View import android.widget.Toast import androidx.core.content.getSystemService +import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.LocalOnlyHotspotService import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt index 8bee37ef..03bd9d02 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt @@ -3,8 +3,8 @@ package be.mygod.vpnhotspot.manage import android.content.ActivityNotFoundException import android.content.Context import android.content.Intent -import androidx.recyclerview.widget.RecyclerView import android.view.View +import androidx.recyclerview.widget.RecyclerView import com.crashlytics.android.Crashlytics object ManageBar : Manager() { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt index 8b2681d6..843300ca 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/Manager.kt @@ -1,10 +1,10 @@ package be.mygod.vpnhotspot.manage import android.annotation.TargetApi -import androidx.recyclerview.widget.DiffUtil -import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding import be.mygod.vpnhotspot.databinding.ListitemRepeaterBinding @@ -23,7 +23,7 @@ abstract class Manager { override fun areItemsTheSame(oldItem: Manager, newItem: Manager) = oldItem.isSameItemAs(newItem) override fun areContentsTheSame(oldItem: Manager, newItem: Manager) = oldItem == newItem - fun createViewHolder(inflater: LayoutInflater, parent: ViewGroup, type: Int): RecyclerView.ViewHolder = when (type) { + fun createViewHolder(inflater: LayoutInflater, parent: ViewGroup, type: Int) = when (type) { VIEW_TYPE_INTERFACE -> InterfaceManager.ViewHolder(ListitemInterfaceBinding.inflate(inflater, parent, false)) VIEW_TYPE_MANAGE -> ManageBar.ViewHolder(inflater.inflate(R.layout.listitem_manage, parent, false)) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt index 16be63c6..b8cbb115 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/manage/TetheringFragment.kt @@ -6,18 +6,18 @@ import android.content.Intent import android.content.IntentFilter import android.content.ServiceConnection import android.content.pm.PackageManager -import androidx.databinding.DataBindingUtil import android.os.Build import android.os.Bundle import android.os.IBinder -import androidx.fragment.app.Fragment -import androidx.recyclerview.widget.ListAdapter -import androidx.recyclerview.widget.DefaultItemAnimator -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.databinding.DataBindingUtil +import androidx.fragment.app.Fragment +import androidx.recyclerview.widget.DefaultItemAnimator +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.ListAdapter +import androidx.recyclerview.widget.RecyclerView import be.mygod.vpnhotspot.LocalOnlyHotspotService import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.TetheringService diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt index 961c9af6..0662bf84 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/TetheringManager.kt @@ -5,8 +5,8 @@ import android.net.ConnectivityManager import android.os.Build import android.os.Bundle import android.os.Handler -import androidx.annotation.RequiresApi import android.util.Log +import androidx.annotation.RequiresApi import be.mygod.vpnhotspot.App.Companion.app import com.android.dx.stock.ProxyBuilder import com.crashlytics.android.Crashlytics diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt index 2dff0201..ef1a4b84 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/P2pSupplicantConfiguration.kt @@ -44,7 +44,8 @@ class P2pSupplicantConfiguration(private val initContent: String? = null) : Parc return try { val match = pskParser.findAll(content ?: return null).single() if (match.groups[2] == null && match.groups[3] == null) "" else { - val result = match.groupValues[2] + match.groupValues[3] // only one will match and hold non-empty value + // only one will match and hold non-empty value + val result = match.groupValues[2] + match.groupValues[3] check(result.length in 8..63) result } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/preference/AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/preference/AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat.kt index 09c1fc3a..da1554cb 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/preference/AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/preference/AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat.kt @@ -1,11 +1,11 @@ package be.mygod.vpnhotspot.preference -import androidx.preference.PreferenceDialogFragmentCompat -import androidx.appcompat.widget.AppCompatAutoCompleteTextView import android.view.View import android.view.ViewGroup import android.widget.ArrayAdapter import android.widget.EditText +import androidx.appcompat.widget.AppCompatAutoCompleteTextView +import androidx.preference.PreferenceDialogFragmentCompat open class AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat : PreferenceDialogFragmentCompat() { companion object { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt index f9a74032..adaba02d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/ServiceForegroundConnector.kt @@ -1,14 +1,14 @@ package be.mygod.vpnhotspot.util import android.app.Service -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.LifecycleObserver -import androidx.lifecycle.LifecycleOwner -import androidx.lifecycle.OnLifecycleEvent import android.content.Context import android.content.Intent import android.content.ServiceConnection import androidx.fragment.app.Fragment +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.LifecycleOwner +import androidx.lifecycle.OnLifecycleEvent import kotlin.reflect.KClass /** diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/widget/AlwaysAutoCompleteEditText.kt b/mobile/src/main/java/be/mygod/vpnhotspot/widget/AlwaysAutoCompleteEditText.kt index 366bdbaf..1a189581 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/widget/AlwaysAutoCompleteEditText.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/widget/AlwaysAutoCompleteEditText.kt @@ -2,9 +2,9 @@ package be.mygod.vpnhotspot.widget import android.content.Context import android.graphics.Rect -import androidx.appcompat.widget.AppCompatAutoCompleteTextView import android.util.AttributeSet import android.view.View +import androidx.appcompat.widget.AppCompatAutoCompleteTextView import be.mygod.vpnhotspot.R /**