Merge pull request #250 from HaliksaR/improvements/viewbinding
improvements view binding
This commit is contained in:
commit
50a59a4eb8
|
@ -53,6 +53,7 @@ android {
|
|||
|
||||
buildFeatures {
|
||||
dataBinding true
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
// To inline the bytecode built with JVM target 1.8 into
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.vanced.manager.ui.core
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
abstract class BindingFragment<VB : ViewBinding> : Fragment() {
|
||||
|
||||
private var _binding: VB? = null
|
||||
protected val binding: VB get() = requireNotNull(_binding)
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = binding(inflater, container, savedInstanceState)
|
||||
otherSetups()
|
||||
return binding.root
|
||||
}
|
||||
|
||||
protected abstract fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): VB
|
||||
|
||||
protected open fun otherSetups() = Unit
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
|
@ -9,37 +9,33 @@ import android.view.ViewGroup
|
|||
import android.widget.Toast
|
||||
import androidx.core.content.edit
|
||||
import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.vanced.manager.R
|
||||
import com.vanced.manager.databinding.FragmentAboutBinding
|
||||
import com.vanced.manager.ui.core.BindingFragment
|
||||
import com.vanced.manager.ui.viewmodels.AboutViewModel
|
||||
|
||||
class AboutFragment : Fragment() {
|
||||
class AboutFragment : BindingFragment<FragmentAboutBinding>() {
|
||||
|
||||
private lateinit var binding: FragmentAboutBinding
|
||||
private val viewModel: AboutViewModel by viewModels()
|
||||
private var count = 0
|
||||
private var startMillSec: Long = 0
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
override fun binding(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
requireActivity().title = getString(R.string.title_about)
|
||||
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_about, container, false)
|
||||
binding.viewModel = viewModel
|
||||
return binding.root
|
||||
) = FragmentAboutBinding.inflate(inflater, container, false)
|
||||
|
||||
override fun otherSetups() {
|
||||
dataBind()
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
view.setOnTouchListener { _, event: MotionEvent ->
|
||||
|
||||
private fun dataBind() {
|
||||
requireActivity().title = getString(R.string.title_about)
|
||||
binding.root.setOnTouchListener { _, event: MotionEvent ->
|
||||
val eventAction = event.action
|
||||
if (eventAction == MotionEvent.ACTION_UP) {
|
||||
val time = System.currentTimeMillis()
|
||||
|
@ -64,5 +60,7 @@ class AboutFragment : Fragment() {
|
|||
}
|
||||
false
|
||||
}
|
||||
binding.aboutSources.aboutGithubButton.setOnClickListener { viewModel.openUrl("https://github.com/YTVanced/VancedInstaller") }
|
||||
binding.aboutSources.aboutLicenseButton.setOnClickListener { viewModel.openUrl("https://raw.githubusercontent.com/YTVanced/VancedInstaller/dev/LICENSE") }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:bind="http://schemas.android.com/tools">
|
||||
<androidx.core.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:scrollbars="none">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.vanced.manager.ui.viewmodels.AboutViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fillViewport="true"
|
||||
android:scrollbars="none">
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="@dimen/twelvedp"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<include
|
||||
layout="@layout/include_about_header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="@dimen/twelvedp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<include
|
||||
layout="@layout/include_about_header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<include
|
||||
layout="@layout/include_about_vanced_devs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/stdp" />
|
||||
|
||||
<include
|
||||
layout="@layout/include_about_app_devs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/stdp" />
|
||||
|
||||
<include
|
||||
layout="@layout/include_about_sources"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/stdp"
|
||||
bind:viewModel="@{viewModel}" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</layout>
|
||||
<include
|
||||
layout="@layout/include_about_vanced_devs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/stdp"/>
|
||||
|
||||
<include
|
||||
layout="@layout/include_about_app_devs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/stdp"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/about_sources"
|
||||
layout="@layout/include_about_sources"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/stdp"/>
|
||||
</LinearLayout>
|
||||
</androidx.core.widget.NestedScrollView>
|
|
@ -1,73 +1,55 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
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="wrap_content"
|
||||
app:cardBackgroundColor="?colorLinkBG"
|
||||
app:cardElevation="0dp"
|
||||
app:contentPaddingBottom="8dp"
|
||||
app:contentPaddingTop="2dp">
|
||||
|
||||
<data>
|
||||
|
||||
<variable
|
||||
name="viewModel"
|
||||
type="com.vanced.manager.ui.viewmodels.AboutViewModel" />
|
||||
|
||||
</data>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView 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"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardBackgroundColor="?colorLinkBG"
|
||||
app:cardElevation="0dp"
|
||||
app:contentPaddingBottom="8dp"
|
||||
app:contentPaddingTop="2dp">
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
<TextView
|
||||
android:id="@+id/about_card_vancedTeam"
|
||||
style="@style/CardTextHeader"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/sources"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
android:layout_height="wrap_content"
|
||||
app:alignItems="center"
|
||||
app:flexDirection="row"
|
||||
app:justifyContent="space_evenly">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_card_vancedTeam"
|
||||
style="@style/CardTextHeader"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/sources"
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/about_github_button"
|
||||
style="@style/SocialButtonStyle"
|
||||
app:icon="@drawable/ic_github"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/about_license_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:alignItems="center"
|
||||
app:flexDirection="row"
|
||||
app:justifyContent="space_evenly">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/about_github_button"
|
||||
style="@style/SocialButtonStyle"
|
||||
android:onClick='@{()-> viewModel.openUrl("https://github.com/YTVanced/VancedInstaller")}'
|
||||
app:icon="@drawable/ic_github"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/about_license_button"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/about_license_button"
|
||||
style="@style/SocialButtonStyle"
|
||||
android:fontFamily="@font/exo_semibold"
|
||||
android:onClick='@{()-> viewModel.openUrl("https://raw.githubusercontent.com/YTVanced/VancedInstaller/dev/LICENSE")}'
|
||||
android:text="GPL"
|
||||
android:textSize="21sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/about_github_button"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:ignore="HardcodedText" />
|
||||
|
||||
</com.google.android.flexbox.FlexboxLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
</layout>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/about_license_button"
|
||||
style="@style/SocialButtonStyle"
|
||||
android:fontFamily="@font/exo_semibold"
|
||||
android:text="GPL"
|
||||
android:textSize="21sp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/about_github_button"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:ignore="HardcodedText" />
|
||||
</com.google.android.flexbox.FlexboxLayout>
|
||||
</LinearLayout>
|
||||
</com.google.android.material.card.MaterialCardView>
|
Loading…
Reference in New Issue