SelectAppsFragment view binding
This commit is contained in:
parent
cdd5228447
commit
60b297adc1
|
@ -2,53 +2,56 @@ package com.vanced.manager.ui.fragments
|
|||
|
||||
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.navigation.fragment.findNavController
|
||||
import androidx.preference.PreferenceManager.getDefaultSharedPreferences
|
||||
import androidx.preference.PreferenceManager.*
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.adapter.SelectAppsAdapter
|
||||
import com.vanced.manager.databinding.FragmentSelectAppsBinding
|
||||
import com.vanced.manager.ui.core.BindingFragment
|
||||
|
||||
class SelectAppsFragment : Fragment() {
|
||||
class SelectAppsFragment : BindingFragment<FragmentSelectAppsBinding>() {
|
||||
|
||||
private lateinit var binding: FragmentSelectAppsBinding
|
||||
private lateinit var selectAdapter: SelectAppsAdapter
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_select_apps, container, false)
|
||||
return binding.root
|
||||
) = FragmentSelectAppsBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun otherSetups() {
|
||||
bindData()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val selectAdapter = SelectAppsAdapter(requireActivity())
|
||||
val prefs = getDefaultSharedPreferences(requireActivity())
|
||||
binding.selectAppsRecycler.apply {
|
||||
private fun bindData() {
|
||||
with(binding) {
|
||||
initRecycler()
|
||||
selectAppsFab.setOnClickListener { actionOnClickAppsFab() }
|
||||
}
|
||||
}
|
||||
|
||||
private fun FragmentSelectAppsBinding.initRecycler() {
|
||||
selectAdapter = SelectAppsAdapter(requireActivity())
|
||||
selectAppsRecycler.apply {
|
||||
layoutManager = LinearLayoutManager(requireActivity())
|
||||
setHasFixedSize(true)
|
||||
adapter = selectAdapter
|
||||
}
|
||||
|
||||
binding.selectAppsFab.setOnClickListener {
|
||||
if (selectAdapter.apps.all { app -> !app.isChecked }) {
|
||||
Toast.makeText(requireActivity(), R.string.select_at_least_one_app, Toast.LENGTH_SHORT).show()
|
||||
return@setOnClickListener
|
||||
}
|
||||
|
||||
selectAdapter.apps.forEach { app ->
|
||||
prefs.edit { putBoolean("enable_${app.tag}", app.isChecked) }
|
||||
}
|
||||
|
||||
findNavController().navigate(SelectAppsFragmentDirections.selectAppsToGrantRoot())
|
||||
}
|
||||
}
|
||||
|
||||
private fun actionOnClickAppsFab() {
|
||||
if (selectAdapter.apps.all { app -> !app.isChecked }) {
|
||||
Toast.makeText(requireActivity(), R.string.select_at_least_one_app, Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
val prefs = getDefaultSharedPreferences(requireActivity())
|
||||
selectAdapter.apps.forEach { app ->
|
||||
prefs.edit { putBoolean("enable_${app.tag}", app.isChecked) }
|
||||
}
|
||||
findNavController().navigate(SelectAppsFragmentDirections.selectAppsToGrantRoot())
|
||||
}
|
||||
}
|
|
@ -1,43 +1,41 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<com.vanced.manager.ui.core.SlidingConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
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"
|
||||
<TextView
|
||||
android:id="@+id/select_apps_header"
|
||||
android:text="@string/select_apps"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
style="@style/WelcomeHeaderTitle"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/select_apps_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?colorSurface">
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:itemCount="2"
|
||||
tools:listitem="@layout/view_app_checkbox"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/select_apps_header"
|
||||
style="@style/WelcomeHeaderTitle"
|
||||
android:text="@string/select_apps"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/select_apps_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"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/select_apps_recycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="24dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:itemCount="2"
|
||||
tools:listitem="@layout/view_app_checkbox" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/select_apps_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.vanced.manager.ui.core.SlidingConstraintLayout>
|
||||
|
|
Loading…
Reference in New Issue