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

Commit f8d29aa4 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Apps: Switch to require API instead of get API



AndroidX added new "require____()" versions of common "get___()" APIs, such as getContext/getActivity/getArguments/etc.
Rather than wrap these in something like requireNotNull(), using these APIs will allow the underlying component to try
to tell you _why_ it was null, and thus yield a better error message.

Signed-off-by: Aayush Gupta's avatarAayush Gupta <theimpulson@e.email>
parent aa98cc89
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -43,13 +43,13 @@ class ApplicationsFragment() : Fragment() {

        val view = inflater.inflate(R.layout.fragment_application_categories, container, false)
        view.categories_list.layoutManager = LinearLayoutManager(context)
        color = arguments!!.getInt("color",0)
        color = requireArguments().getInt("color",0)
        view.categories_list.visibility = View.GONE
        view.progress_bar.visibility = View.VISIBLE
        view.error_container.visibility = View.GONE
        view.findViewById<TextView>(R.id.error_resolve).setOnClickListener {
            view.progress_bar.visibility = View.VISIBLE
            categoriesViewModel.loadCategories(context!!)
            categoriesViewModel.loadCategories(requireContext())
        }

        view.error_resolve.setTextColor(Color.parseColor("#ffffff"))
@@ -72,7 +72,7 @@ class ApplicationsFragment() : Fragment() {
        // Bind to the screen error
        categoriesViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
            if (it != null) {
                view.error_description.text = activity!!.getString(it.description)
                view.error_description.text = requireActivity().getString(it.description)
                view.error_container.visibility = View.VISIBLE
                view.progress_bar.visibility = View.GONE
            } else {
@@ -81,7 +81,7 @@ class ApplicationsFragment() : Fragment() {
        })

        if (categoriesViewModel.getApplicationsCategories().value!!.isEmpty()) {
            categoriesViewModel.loadCategories(context!!)
            categoriesViewModel.loadCategories(requireContext())
        }
        return view
    }
+2 −2
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ class CategoriesFragment : Fragment() {
        val view = inflater.inflate(R.layout.fragment_categories, container, false)
        val tabLayout = view.findViewById<TabLayout>(R.id.tab_layout)
        val viewPager = view.findViewById<ViewPager>(R.id.view_pager)
        var color = getAccentColor(activity!!);
        viewPager.adapter = CategoriesViewPagerAdapter(activity!!.supportFragmentManager, tabLayout.tabCount, color)
        var color = getAccentColor(requireActivity());
        viewPager.adapter = CategoriesViewPagerAdapter(requireActivity().supportFragmentManager, tabLayout.tabCount, color)
        viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout))

        if (color != null) {
+4 −4
Original line number Diff line number Diff line
@@ -42,13 +42,13 @@ class GamesFragment() : Fragment() {

        val view = inflater.inflate(R.layout.fragment_games_categories, container, false)
        view.categories_list.layoutManager = LinearLayoutManager(context)
        color = arguments!!.getInt("color",0)
        color = requireArguments().getInt("color",0)
        view.categories_list.visibility = View.GONE
        view.progress_bar.visibility = View.VISIBLE
        view.error_container.visibility = View.GONE
        view.findViewById<TextView>(R.id.error_resolve).setOnClickListener {
            view.progress_bar.visibility = View.VISIBLE
            categoriesViewModel.loadCategories(context!!)
            categoriesViewModel.loadCategories(requireContext())
        }
        view.error_resolve.setTextColor(Color.parseColor("#ffffff"))
        if (color != null) {
@@ -68,7 +68,7 @@ class GamesFragment() : Fragment() {
        // Bind to the screen error
        categoriesViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
            if (it != null) {
                view.error_description.text = activity!!.getString(it.description)
                view.error_description.text = requireActivity().getString(it.description)
                view.error_container.visibility = View.VISIBLE
                view.progress_bar.visibility = View.GONE
            } else {
@@ -77,7 +77,7 @@ class GamesFragment() : Fragment() {
        })

        if (categoriesViewModel.getGamesCategories().value!!.isEmpty()) {
            categoriesViewModel.loadCategories(context!!)
            categoriesViewModel.loadCategories(requireContext())
        }
        return view
    }
+3 −3
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ class PwasFragment : Fragment() {
        view.error_container.visibility = View.GONE
        view.findViewById<TextView>(R.id.error_resolve).setOnClickListener {
            view.progress_bar.visibility = View.VISIBLE
            categoriesViewModel.loadCategories(context!!)
            categoriesViewModel.loadCategories(requireContext())
        }

        // Bind to the list of pwas categories
@@ -60,7 +60,7 @@ class PwasFragment : Fragment() {
        // Bind to the screen error
        categoriesViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
            if (it != null) {
                view.error_description.text = activity!!.getString(it.description)
                view.error_description.text = requireActivity().getString(it.description)
                view.error_container.visibility = View.VISIBLE
                view.progress_bar.visibility = View.GONE
            } else {
@@ -69,7 +69,7 @@ class PwasFragment : Fragment() {
        })

        if (categoriesViewModel.getPwasCategories().value!!.isEmpty()) {
            categoriesViewModel.loadCategories(context!!)
            categoriesViewModel.loadCategories(requireContext())
        }
        return view
    }
+8 −8
Original line number Diff line number Diff line
@@ -89,13 +89,13 @@ class HomeFragment : Fragment() {
        errorContainer.visibility = View.GONE
        view.findViewById<TextView>(R.id.error_resolve).setOnClickListener {
            progressBar.visibility = View.VISIBLE
            homeViewModel.loadCategories(context!!)
            homeViewModel.loadCategories(requireContext())
        }

        // Bind image carousel adapter to banner images in view model
        homeViewModel.getBannerApplications().observe(viewLifecycleOwner, Observer {
            if (homeViewModel.getBannerApplications().value!!.isNotEmpty()) {
                imageCarousel.adapter = ImageCarouselAdapter(activity!!, homeViewModel.getBannerApplications().value!!)
                imageCarousel.adapter = ImageCarouselAdapter(requireActivity(), homeViewModel.getBannerApplications().value!!)
                imageCarousel.clipToPadding = false;
                imageCarousel.setPadding(170, 10, 170, 10);
                imageCarousel.pageMargin =50
@@ -119,7 +119,7 @@ class HomeFragment : Fragment() {
        // Bind to the screen error
        homeViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
            if (it != null) {
                errorDescription.text = activity!!.getString(it.description)
                errorDescription.text = requireActivity().getString(it.description)
                errorContainer.visibility = View.VISIBLE
                progressBar.visibility = View.GONE
            } else {
@@ -129,7 +129,7 @@ class HomeFragment : Fragment() {

        if (homeViewModel.getBannerApplications().value!!.isEmpty() ||
                homeViewModel.getCategories().value!!.isEmpty()) {
            homeViewModel.loadCategories(context!!)
            homeViewModel.loadCategories(requireContext())
        }
        return view
    }
@@ -137,16 +137,16 @@ class HomeFragment : Fragment() {
    private fun setCustomScroller() {
        val scroller = ViewPager::class.java.getDeclaredField("mScroller")
        scroller.isAccessible = true
        scroller.set(imageCarousel, ImageCarouselScroller(context!!))
        scroller.set(imageCarousel, ImageCarouselScroller(requireContext()))
    }

    private fun showCategories(categories: LinkedHashMap<Category, ArrayList<Application>>) {
        categoryList.removeAllViews()
        categories.forEach {
            val homeCategory = HomeCategory(context!!, it.key)
            val homeCategory = HomeCategory(requireContext(), it.key)
            val applicationList = homeCategory.findViewById<RecyclerView>(R.id.application_list)
            applicationList.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
            applicationList.adapter = SmallApplicationListAdapter(activity!!, it.value)
            applicationList.adapter = SmallApplicationListAdapter(requireActivity(), it.value)
            categoryList.addView(homeCategory)
        }
    }
@@ -156,7 +156,7 @@ class HomeFragment : Fragment() {
        if (::homeViewModel.isInitialized) {
            homeViewModel.getCategories().value!!.values.forEach {
                it.forEach { application ->
                    application.checkForStateUpdate(context!!)
                    application.checkForStateUpdate(requireContext())
                }
            }
        }
Loading