2020-10-31 19:45:39 +00:00
|
|
|
package com.vanced.manager.ui.fragments
|
|
|
|
|
|
|
|
import android.content.Intent
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.Toast
|
2020-11-05 16:35:49 +00:00
|
|
|
import androidx.core.content.edit
|
2020-11-15 17:04:23 +00:00
|
|
|
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
2020-10-31 19:45:39 +00:00
|
|
|
import com.topjohnwu.superuser.Shell
|
|
|
|
import com.vanced.manager.R
|
2020-11-26 15:37:03 +00:00
|
|
|
import com.vanced.manager.core.ui.base.BindingFragment
|
2020-10-31 19:45:39 +00:00
|
|
|
import com.vanced.manager.databinding.FragmentGrantRootBinding
|
|
|
|
import com.vanced.manager.ui.MainActivity
|
|
|
|
|
2020-11-14 21:43:20 +00:00
|
|
|
class GrantRootFragment : BindingFragment<FragmentGrantRootBinding>() {
|
2020-10-31 19:45:39 +00:00
|
|
|
|
2020-11-14 21:43:20 +00:00
|
|
|
override fun binding(
|
|
|
|
inflater: LayoutInflater,
|
|
|
|
container: ViewGroup?,
|
2020-10-31 19:45:39 +00:00
|
|
|
savedInstanceState: Bundle?
|
2020-11-14 21:43:20 +00:00
|
|
|
) = FragmentGrantRootBinding.inflate(inflater, container, false)
|
2020-10-31 19:45:39 +00:00
|
|
|
|
2020-11-14 21:43:20 +00:00
|
|
|
override fun otherSetups() {
|
|
|
|
bindData()
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 21:43:20 +00:00
|
|
|
private fun bindData() {
|
|
|
|
with(binding) {
|
|
|
|
grantRootFinishFab.setOnClickListener { navigateToFirstLaunch() }
|
|
|
|
grantRootFab.setOnClickListener { grantRoot() }
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-14 21:43:20 +00:00
|
|
|
private fun navigateToFirstLaunch() {
|
|
|
|
val intent = Intent(requireActivity(), MainActivity::class.java)
|
|
|
|
intent.putExtra("firstLaunch", true)
|
|
|
|
startActivity(intent)
|
|
|
|
requireActivity().finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun grantRoot() {
|
|
|
|
if (Shell.rootAccess()) {
|
2021-04-19 15:57:14 +00:00
|
|
|
getDefaultSharedPreferences(requireActivity()).edit {
|
|
|
|
putString(
|
|
|
|
"vanced_variant",
|
|
|
|
"root"
|
|
|
|
)
|
|
|
|
}
|
2020-11-16 11:52:23 +00:00
|
|
|
navigateToFirstLaunch()
|
2020-11-14 21:43:20 +00:00
|
|
|
} else {
|
|
|
|
Toast.makeText(requireActivity(), R.string.root_not_granted, Toast.LENGTH_SHORT).show()
|
|
|
|
}
|
|
|
|
}
|
2020-10-31 19:45:39 +00:00
|
|
|
}
|