Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 397f5439 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

home: Migrate to viewBinding

- Kotlin Android Extensions is deprecated
- It has important advantages over using findViewById

Ref:
- [1]: https://developer.android.com/topic/libraries/view-binding/migration
- [2]: https://developer.android.com/topic/libraries/view-binding#findviewbyid



Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
parent fa26ef72
Loading
Loading
Loading
Loading
+25 −14
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.ProgressBar
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
@@ -36,10 +35,14 @@ import foundation.e.apps.application.model.Application
import foundation.e.apps.applicationmanager.ApplicationManager
import foundation.e.apps.categories.model.Category
import foundation.e.apps.common.SmallApplicationListAdapter
import foundation.e.apps.databinding.FragmentHomeBinding
import foundation.e.apps.home.viewmodel.HomeViewModel


class HomeFragment : Fragment() {
    private var _binding: FragmentHomeBinding? = null
    private val binding get() = _binding!!

    private lateinit var homeViewModel: HomeViewModel
    private lateinit var imageCarousel: ViewPager
    private lateinit var divider: View
@@ -54,24 +57,27 @@ class HomeFragment : Fragment() {
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        _binding = FragmentHomeBinding.inflate(inflater, container, false)

        if (applicationManager == null) {
            return null

        }

        val view = inflater.inflate(R.layout.fragment_home, container, false)

        homeViewModel = ViewModelProvider(this).get(HomeViewModel::class.java)
        imageCarousel = view.findViewById(R.id.image_carousel)
        divider = view.findViewById(R.id.divider)
        categoryList = view.findViewById(R.id.category_list)
        progressBar = view.findViewById(R.id.progress_bar)
        val errorContainer = view.findViewById<LinearLayout>(R.id.error_container)
        val errorDescription = view.findViewById<TextView>(R.id.error_description)
        //set accent color to Error button (Retry )

        view.findViewById<TextView>(R.id.error_resolve).setTextColor(Color.parseColor("#ffffff"))
        view.findViewById<TextView>(R.id.error_resolve).setBackgroundColor(accentColorOS)
        // Fragment variables
        imageCarousel = binding.imageCarousel
        divider = binding.divider
        categoryList = binding.categoryList
        progressBar = binding.progressBar
        val errorContainer = binding.errorLayout.errorContainer
        val errorDescription = binding.errorLayout.errorDescription
        val errorResolve = binding.errorLayout.errorResolve

        //set accent color to Error button (Retry )
        errorResolve.setTextColor(Color.parseColor("#ffffff"))
        errorResolve.setBackgroundColor(accentColorOS)

        // Initialise UI elements
        homeViewModel.initialise(applicationManager!!)
@@ -81,7 +87,7 @@ class HomeFragment : Fragment() {
        categoryList.visibility = View.GONE
        progressBar.visibility = View.VISIBLE
        errorContainer.visibility = View.GONE
        view.findViewById<TextView>(R.id.error_resolve).setOnClickListener {
        errorResolve.setOnClickListener {
            progressBar.visibility = View.VISIBLE
            homeViewModel.loadCategories(requireContext())
        }
@@ -125,7 +131,7 @@ class HomeFragment : Fragment() {
                homeViewModel.getCategories().value!!.isEmpty()) {
            homeViewModel.loadCategories(requireContext())
        }
        return view
        return binding.root
    }

    private fun setCustomScroller() {
@@ -156,6 +162,11 @@ class HomeFragment : Fragment() {
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null
    }

    fun decrementApplicationUses() {
        if (::homeViewModel.isInitialized) {
            homeViewModel.getCategories().value!!.forEach {
+2 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
            android:orientation="vertical">

            <TextView
                android:id="@+id/tvFeatured"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="@string/featured"
@@ -74,6 +75,7 @@
    </foundation.e.apps.utils.CustomNestedScrollView>

    <include
        android:id="@+id/error_layout"
        layout="@layout/error_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"