Commit 6374a3af authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch 'aayush_viewBinding_migration' into 'master'

Partial ViewBinding Migration

See merge request e/apps/apps!63
parents 5bbb02d8 5341a197
Pipeline #113725 canceled with stage
in 6 seconds
......@@ -14,7 +14,7 @@ android {
minSdkVersion 25
targetSdkVersion 29
versionCode 10
versionName "1.1.6"
versionName "1.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
......@@ -41,6 +41,9 @@ android {
signingConfig signingConfigs.config
}
}
buildFeatures {
viewBinding true
}
lintOptions {
lintConfig file("lint.xml")
disable 'MissingTranslation'
......
......@@ -23,7 +23,6 @@ import android.annotation.SuppressLint
import android.content.*
import android.content.pm.PackageManager
import android.content.res.ColorStateList
import android.database.Cursor
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
......@@ -44,6 +43,7 @@ import foundation.e.apps.applicationmanager.ApplicationManager
import foundation.e.apps.applicationmanager.ApplicationManagerServiceConnection
import foundation.e.apps.applicationmanager.ApplicationManagerServiceConnectionCallback
import foundation.e.apps.categories.CategoriesFragment
import foundation.e.apps.databinding.ActivityMainBinding
import foundation.e.apps.home.HomeFragment
import foundation.e.apps.search.SearchFragment
import foundation.e.apps.settings.SettingsFragment
......@@ -52,13 +52,11 @@ import foundation.e.apps.updates.UpdatesManager
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Constants.CURRENTLY_SELECTED_FRAGMENT_KEY
import foundation.e.apps.utils.Constants.MICROG_SHARED_PREF
import foundation.e.apps.utils.PreferenceStorage
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemSelectedListener,
ApplicationManagerServiceConnectionCallback {
private lateinit var binding: ActivityMainBinding
private var currentFragmentId = 0
private val homeFragment = HomeFragment()
......@@ -94,13 +92,15 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
override fun onCreate(savedInstanceState: Bundle?) {
binding = ActivityMainBinding.inflate(layoutInflater)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setContentView(binding.root)
mActivity = this
disableCategoryIfOpenSource()
bottom_navigation_view.setOnNavigationItemSelectedListener{
binding.bottomNavigationView.setOnNavigationItemSelectedListener{
if (selectFragment(it.itemId,it)) {
disableCategoryIfOpenSource()
currentFragmentId = it.itemId
......@@ -163,8 +163,8 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
))
bottom_navigation_view.setItemIconTintList(iconsColorStates)
bottom_navigation_view.setItemTextColor(textColorStates)
binding.bottomNavigationView.setItemIconTintList(iconsColorStates)
binding.bottomNavigationView.setItemTextColor(textColorStates)
}
......@@ -266,7 +266,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
private fun showFragment(fragment: Fragment) {
bottom_navigation_view.menu.findItem(currentFragmentId).isChecked = true
binding.bottomNavigationView.menu.findItem(currentFragmentId).isChecked = true
supportFragmentManager
.beginTransaction()
.replace(R.id.frame_layout, fragment)
......@@ -275,7 +275,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
@SuppressLint("RestrictedApi")
private fun disableShiftingOfNabBarItems() {
val menuView = bottom_navigation_view.getChildAt(0) as BottomNavigationMenuView
val menuView = binding.bottomNavigationView.getChildAt(0) as BottomNavigationMenuView
try {
val mShiftingMode = menuView.javaClass.getDeclaredField("mShiftingMode")
mShiftingMode.isAccessible = true
......@@ -295,7 +295,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
private fun disableCategoryIfOpenSource(){
if(showApplicationTypePreference()=="open") {
bottom_navigation_view.menu.removeItem(R.id.menu_categories)
binding.bottomNavigationView.menu.removeItem(R.id.menu_categories)
}
}
......@@ -304,7 +304,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == Constants.STORAGE_PERMISSION_REQUEST_CODE &&
grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_DENIED) {
Snackbar.make(container, R.string.error_storage_permission_denied,
Snackbar.make(binding.container, R.string.error_storage_permission_denied,
Snackbar.LENGTH_LONG).show()
}
}
......
......@@ -22,38 +22,46 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import foundation.e.apps.R
import foundation.e.apps.categories.model.Category
import foundation.e.apps.categories.viewmodel.CategoriesViewModel
import kotlinx.android.synthetic.main.error_layout.view.*
import kotlinx.android.synthetic.main.fragment_application_categories.view.*
import foundation.e.apps.databinding.FragmentApplicationCategoriesBinding
class ApplicationsFragment() : Fragment() {
private var _binding: FragmentApplicationCategoriesBinding? = null
private val binding get() = _binding!!
private lateinit var categoriesViewModel: CategoriesViewModel
var color:Int = 0;
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentApplicationCategoriesBinding.inflate(inflater, container, false)
categoriesViewModel = ViewModelProvider(this).get(CategoriesViewModel::class.java)
val view = inflater.inflate(R.layout.fragment_application_categories, container, false)
view.categories_list.layoutManager = LinearLayoutManager(context)
// Fragment variables
val categoriesList = binding.categoriesList
val progressBar = binding.progressBar
val errorContainer = binding.errorLayout.errorContainer
val errorResolve = binding.errorLayout.errorResolve
val errorDescription = binding.errorLayout.errorDescription
categoriesList.layoutManager = LinearLayoutManager(context)
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
categoriesList.visibility = View.GONE
progressBar.visibility = View.VISIBLE
errorContainer.visibility = View.GONE
errorResolve.setOnClickListener {
progressBar.visibility = View.VISIBLE
categoriesViewModel.loadCategories(requireContext())
}
view.error_resolve.setTextColor(Color.parseColor("#ffffff"))
view.error_resolve.setBackgroundColor(color)
errorResolve.setTextColor(Color.parseColor("#ffffff"))
errorResolve.setBackgroundColor(color)
// Bind to the list of applications categories
categoriesViewModel.getApplicationsCategories().observe(viewLifecycleOwner, Observer {
......@@ -61,28 +69,34 @@ class ApplicationsFragment() : Fragment() {
//Add New Category
if (!it.any { Category -> Category.id == "system_apps" })
it.add(Category("system_apps"))
view.categories_list.adapter = context?.let { context -> CategoriesListAdapter(context, it, color) }
view.categories_list.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
categoriesList.adapter = context?.let { context -> CategoriesListAdapter(context, it, color) }
categoriesList.visibility = View.VISIBLE
progressBar.visibility = View.GONE
}
})
// Bind to the screen error
categoriesViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
if (it != null) {
view.error_description.text = requireActivity().getString(it.description)
view.error_container.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
errorDescription.text = requireActivity().getString(it.description)
errorContainer.visibility = View.VISIBLE
progressBar.visibility = View.GONE
} else {
view.error_container.visibility = View.GONE
errorContainer.visibility = View.GONE
}
})
if (categoriesViewModel.getApplicationsCategories().value!!.isEmpty()) {
categoriesViewModel.loadCategories(requireContext())
}
return view
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
companion object{
fun newInstance(color:Int?) : ApplicationsFragment{
val applicationsFragment = ApplicationsFragment()
......
......@@ -24,18 +24,21 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.google.android.material.tabs.TabLayout
import foundation.e.apps.R
import foundation.e.apps.databinding.FragmentCategoriesBinding
class CategoriesFragment : Fragment() {
private var _binding: FragmentCategoriesBinding? = null
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentCategoriesBinding.inflate(inflater, container, false)
// Fragment variables
val tabLayout = binding.tabLayout
val viewPager = binding.viewPager
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
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(requireActivity());
viewPager.adapter = CategoriesViewPagerAdapter(requireActivity().supportFragmentManager, tabLayout.tabCount, color)
viewPager.addOnPageChangeListener(TabLayout.TabLayoutOnPageChangeListener(tabLayout))
......@@ -57,7 +60,12 @@ class CategoriesFragment : Fragment() {
}
})
return view
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
/*
......
......@@ -21,16 +21,12 @@ import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources
import androidx.recyclerview.widget.RecyclerView
import foundation.e.apps.R
import foundation.e.apps.categories.category.CategoryActivity
import foundation.e.apps.categories.model.Category
import foundation.e.apps.databinding.CategoryListItemBinding
import foundation.e.apps.utils.Constants
class CategoriesListAdapter(private val context: Context, private var categories: ArrayList<Category>, color: Int?)
......@@ -43,17 +39,20 @@ class CategoriesListAdapter(private val context: Context, private var categories
}
class CategoryViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val categoryContainer: RelativeLayout = view.findViewById(R.id.category_container)
val categoryIcon: ImageView = view.findViewById(R.id.category_icon)
val categoryTitle: TextView = view.findViewById(R.id.category_title)
class CategoryViewHolder(binding: CategoryListItemBinding) : RecyclerView.ViewHolder(binding.root) {
val categoryContainer = binding.categoryContainer
val categoryIcon = binding.categoryIcon
val categoryTitle = binding.categoryTitle
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CategoryViewHolder {
val categoryContainer = LayoutInflater.from(parent.context).inflate(
R.layout.category_list_item,
parent, false)
return CategoryViewHolder(categoryContainer)
return CategoryViewHolder(
CategoryListItemBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
override fun getItemCount(): Int {
......
......@@ -22,62 +22,75 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import foundation.e.apps.R
import foundation.e.apps.categories.viewmodel.CategoriesViewModel
import kotlinx.android.synthetic.main.error_layout.view.*
import kotlinx.android.synthetic.main.fragment_games_categories.view.*
import foundation.e.apps.databinding.FragmentGamesCategoriesBinding
class GamesFragment() : Fragment() {
private var _binding: FragmentGamesCategoriesBinding? = null
private val binding get() = _binding!!
private lateinit var categoriesViewModel: CategoriesViewModel
var color:Int = 0;
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentGamesCategoriesBinding.inflate(inflater, container, false)
categoriesViewModel = ViewModelProvider(this).get(CategoriesViewModel::class.java)
val view = inflater.inflate(R.layout.fragment_games_categories, container, false)
view.categories_list.layoutManager = LinearLayoutManager(context)
// Fragment variables
val categoriesList = binding.categoriesList
val progressBar = binding.progressBar
val errorContainer = binding.errorLayout.errorContainer
val errorResolve = binding.errorLayout.errorResolve
val errorDescription = binding.errorLayout.errorDescription
categoriesList.layoutManager = LinearLayoutManager(context)
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
categoriesList.visibility = View.GONE
progressBar.visibility = View.VISIBLE
errorContainer.visibility = View.GONE
errorResolve.setOnClickListener {
progressBar.visibility = View.VISIBLE
categoriesViewModel.loadCategories(requireContext())
}
view.error_resolve.setTextColor(Color.parseColor("#ffffff"))
view.error_resolve.setBackgroundColor(color)
errorResolve.setTextColor(Color.parseColor("#ffffff"))
errorResolve.setBackgroundColor(color)
// Bind to the list of games categories
categoriesViewModel.getGamesCategories().observe(viewLifecycleOwner, Observer {
if (it!!.isNotEmpty()) {
view.categories_list.adapter = context?.let { context -> CategoriesListAdapter(context, it, color) }
view.categories_list.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
categoriesList.adapter = context?.let { context -> CategoriesListAdapter(context, it, color) }
categoriesList.visibility = View.VISIBLE
progressBar.visibility = View.GONE
}
})
// Bind to the screen error
categoriesViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
if (it != null) {
view.error_description.text = requireActivity().getString(it.description)
view.error_container.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
errorDescription.text = requireActivity().getString(it.description)
errorContainer.visibility = View.VISIBLE
progressBar.visibility = View.GONE
} else {
view.error_container.visibility = View.GONE
errorContainer.visibility = View.GONE
}
})
if (categoriesViewModel.getGamesCategories().value!!.isEmpty()) {
categoriesViewModel.loadCategories(requireContext())
}
return view
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
companion object{
......
......@@ -21,57 +21,69 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import foundation.e.apps.R
import foundation.e.apps.categories.viewmodel.CategoriesViewModel
import kotlinx.android.synthetic.main.error_layout.view.*
import kotlinx.android.synthetic.main.fragment_application_categories.view.*
import foundation.e.apps.databinding.FragmentApplicationCategoriesBinding
class PwasFragment : Fragment() {
private var _binding: FragmentApplicationCategoriesBinding? = null
private val binding get() = _binding!!
private lateinit var categoriesViewModel: CategoriesViewModel
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentApplicationCategoriesBinding.inflate(inflater, container, false)
categoriesViewModel = ViewModelProvider(this).get(CategoriesViewModel::class.java)
val view = inflater.inflate(R.layout.fragment_application_categories, container, false)
view.categories_list.layoutManager = LinearLayoutManager(context)
// Fragment variables
val categoriesList = binding.categoriesList
val progressBar = binding.progressBar
val errorContainer = binding.errorLayout.errorContainer
val errorResolve = binding.errorLayout.errorResolve
val errorDescription = binding.errorLayout.errorDescription
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
categoriesList.layoutManager = LinearLayoutManager(context)
categoriesList.visibility = View.GONE
progressBar.visibility = View.VISIBLE
errorContainer.visibility = View.GONE
errorResolve.setOnClickListener {
progressBar.visibility = View.VISIBLE
categoriesViewModel.loadCategories(requireContext())
}
// Bind to the list of pwas categories
categoriesViewModel.getPwasCategories().observe(viewLifecycleOwner, Observer {
if (it!!.isNotEmpty()) {
view.categories_list.adapter = context?.let { context -> CategoriesListAdapter(context, it, null) }
view.categories_list.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
categoriesList.adapter = context?.let { context -> CategoriesListAdapter(context, it, null) }
categoriesList.visibility = View.VISIBLE
progressBar.visibility = View.GONE
}
})
// Bind to the screen error
categoriesViewModel.getScreenError().observe(viewLifecycleOwner, Observer {
if (it != null) {
view.error_description.text = requireActivity().getString(it.description)
view.error_container.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
errorDescription.text = requireActivity().getString(it.description)
errorContainer.visibility = View.VISIBLE
progressBar.visibility = View.GONE
} else {
view.error_container.visibility = View.GONE
errorContainer.visibility = View.GONE
}
})
if (categoriesViewModel.getPwasCategories().value!!.isEmpty()) {
categoriesViewModel.loadCategories(requireContext())
}
return view
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
......@@ -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
}