GrantRootFragment view binding
This commit is contained in:
parent
be23fe821d
commit
4d14ddf1c6
|
@ -3,52 +3,47 @@ package com.vanced.manager.ui.fragments
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.core.content.edit
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import androidx.preference.PreferenceManager.*
|
||||
import com.topjohnwu.superuser.Shell
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentGrantRootBinding
|
||||
import com.vanced.manager.ui.MainActivity
|
||||
import com.vanced.manager.ui.core.BindingFragment
|
||||
|
||||
class GrantRootFragment : Fragment(), View.OnClickListener {
|
||||
class GrantRootFragment : BindingFragment<FragmentGrantRootBinding>() {
|
||||
|
||||
private lateinit var binding: FragmentGrantRootBinding
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_grant_root, container, false)
|
||||
return binding.root
|
||||
) = FragmentGrantRootBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun otherSetups() {
|
||||
bindData()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
binding.grantRootFinishFab.setOnClickListener(this)
|
||||
binding.grantRootFab.setOnClickListener(this)
|
||||
}
|
||||
|
||||
override fun onClick(v: View?) {
|
||||
when (v?.id) {
|
||||
R.id.grant_root_fab -> {
|
||||
if (Shell.rootAccess()) {
|
||||
getDefaultSharedPreferences(requireActivity()).edit { putString("vanced_variant", "root") }
|
||||
} else {
|
||||
Toast.makeText(requireActivity(), R.string.root_not_granted, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
R.id.grant_root_finish_fab -> {
|
||||
val intent = Intent(requireActivity(), MainActivity::class.java)
|
||||
intent.putExtra("firstLaunch", true)
|
||||
startActivity(intent)
|
||||
requireActivity().finish()
|
||||
}
|
||||
private fun bindData() {
|
||||
with(binding) {
|
||||
grantRootFinishFab.setOnClickListener { navigateToFirstLaunch() }
|
||||
grantRootFab.setOnClickListener { grantRoot() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun navigateToFirstLaunch() {
|
||||
val intent = Intent(requireActivity(), MainActivity::class.java)
|
||||
intent.putExtra("firstLaunch", true)
|
||||
startActivity(intent)
|
||||
requireActivity().finish()
|
||||
}
|
||||
|
||||
private fun grantRoot() {
|
||||
if (Shell.rootAccess()) {
|
||||
getDefaultSharedPreferences(requireActivity()).edit { putString("vanced_variant", "root") }
|
||||
} else {
|
||||
Toast.makeText(requireActivity(), R.string.root_not_granted, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
<com.vanced.manager.ui.core.SlidingConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?colorSurface">
|
||||
|
||||
<com.vanced.manager.ui.core.SlidingConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?colorSurface">
|
||||
<TextView
|
||||
android:id="@+id/grant_root_header"
|
||||
android:text="@string/are_you_rooted"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
style="@style/WelcomeHeaderTitle"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/grant_root_header"
|
||||
style="@style/WelcomeHeaderTitle"
|
||||
android:text="@string/are_you_rooted"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<TextView
|
||||
android:id="@+id/grant_root_description"
|
||||
android:text="@string/willing_to_use_root"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_header"
|
||||
style="@style/WelcomeHeaderSubtitle"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/grant_root_description"
|
||||
style="@style/WelcomeHeaderSubtitle"
|
||||
android:text="@string/willing_to_use_root"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_header" />
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/grant_root_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="#1F1F1F"
|
||||
android:padding="16dp"
|
||||
android:src="@drawable/ic_magisk"
|
||||
app:borderWidth="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_header"
|
||||
app:maxImageSize="44dp"/>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/grant_root_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="#1F1F1F"
|
||||
android:padding="16dp"
|
||||
android:src="@drawable/ic_magisk"
|
||||
app:borderWidth="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_header"
|
||||
app:maxImageSize="44dp" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/grant_root"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_fab"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/grant_root"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="13sp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/grant_root_fab" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/grant_root_finish_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="45dp"
|
||||
android:layout_marginBottom="45dp"
|
||||
android:backgroundTint="?colorPrimary"
|
||||
android:src="@drawable/ic_baseline_navigate_next_48"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:maxImageSize="48dp" />
|
||||
|
||||
</com.vanced.manager.ui.core.SlidingConstraintLayout>
|
||||
|
||||
</layout>
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/grant_root_finish_fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="45dp"
|
||||
android:layout_marginEnd="45dp"
|
||||
android:backgroundTint="?colorPrimary"
|
||||
android:src="@drawable/ic_baseline_navigate_next_48"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:maxImageSize="48dp"/>
|
||||
</com.vanced.manager.ui.core.SlidingConstraintLayout>
|
Loading…
Reference in New Issue