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