Files
vpnhotspotmod/mobile/src/main/java/be/mygod/vpnhotspot/manage/ManageBar.kt
2018-07-15 14:28:42 +08:00

47 lines
1.5 KiB
Kotlin

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 com.crashlytics.android.Crashlytics
object ManageBar : Manager() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
init {
view.setOnClickListener(this)
}
override fun onClick(v: View?) = start(itemView.context)
}
override val type: Int get() = VIEW_TYPE_MANAGE
fun start(context: Context) {
try {
context.startActivity(Intent()
.setClassName("com.android.settings", "com.android.settings.Settings\$TetherSettingsActivity"))
} catch (e: ActivityNotFoundException) {
startAlternative(context, e)
} catch (e: SecurityException) {
startAlternative(context, e)
}
}
private fun startAlternative(context: Context, e: Exception) {
try {
context.startActivity(Intent()
.setClassName("com.android.settings", "com.android.settings.TetherSettings"))
e.printStackTrace()
Crashlytics.logException(e)
} catch (e: ActivityNotFoundException) {
e.printStackTrace()
Crashlytics.logException(e)
} catch (e: SecurityException) {
e.printStackTrace()
Crashlytics.logException(e)
}
}
}