Refine code style

This commit is contained in:
Mygod
2019-03-20 12:21:22 +08:00
parent ef32866c66
commit 673ff9800a
3 changed files with 32 additions and 21 deletions

View File

@@ -363,7 +363,7 @@ style:
OptionalUnit:
active: true
OptionalWhenBraces:
active: true
active: false
PreferToOverPairSyntax:
active: false
ProtectedMemberInFinalClass:

View File

@@ -22,10 +22,7 @@ import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.netId
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.requestPersistentGroupInfo
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.setWifiP2pChannels
import be.mygod.vpnhotspot.net.wifi.WifiP2pManagerHelper.startWps
import be.mygod.vpnhotspot.util.StickyEvent0
import be.mygod.vpnhotspot.util.StickyEvent1
import be.mygod.vpnhotspot.util.broadcastReceiver
import be.mygod.vpnhotspot.util.intentFilter
import be.mygod.vpnhotspot.util.*
import be.mygod.vpnhotspot.widget.SmartSnackbar
import timber.log.Timber
import java.lang.reflect.InvocationTargetException
@@ -233,6 +230,7 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
registerReceiver(receiver, intentFilter(WifiP2pManager.WIFI_P2P_STATE_CHANGED_ACTION,
WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION))
receiverRegistered = true
try {
p2pManager.requestGroupInfo(channel) {
when {
it == null -> doStart()
@@ -247,15 +245,26 @@ class RepeaterService : Service(), WifiP2pManager.ChannelListener, SharedPrefere
}
}
}
} catch (e: SecurityException) {
Timber.w(e)
startFailure(e.readableMessage)
}
return START_NOT_STICKY
}
/**
* startService Step 2 (if a group isn't already available)
*/
private fun doStart() = p2pManager.createGroup(channel, object : WifiP2pManager.ActionListener {
override fun onFailure(reason: Int) = startFailure(formatReason(R.string.repeater_create_group_failure, reason))
private fun doStart() = try {
p2pManager.createGroup(channel, object : WifiP2pManager.ActionListener {
override fun onFailure(reason: Int) {
startFailure(formatReason(R.string.repeater_create_group_failure, reason))
}
override fun onSuccess() { } // wait for WIFI_P2P_CONNECTION_CHANGED_ACTION to fire to go to step 3
})
} catch (e: SecurityException) {
Timber.w(e)
startFailure(e.readableMessage)
}
/**
* Used during step 2, also called when connection changed
*/

View File

@@ -1,5 +1,6 @@
package be.mygod.vpnhotspot.manage
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.view.LayoutInflater
import android.view.ViewGroup
@@ -21,7 +22,8 @@ abstract class Manager {
const val VIEW_TYPE_REPEATER = 7
override fun areItemsTheSame(oldItem: Manager, newItem: Manager) = oldItem.isSameItemAs(newItem)
override fun areContentsTheSame(oldItem: Manager, newItem: Manager) = oldItem == newItem
@SuppressLint("DiffUtilEquals")
override fun areContentsTheSame(oldItem: Manager, newItem: Manager) = oldItem === newItem
fun createViewHolder(inflater: LayoutInflater, parent: ViewGroup, type: Int) = when (type) {
VIEW_TYPE_INTERFACE ->