Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
e
os
App Lounge
Commits
6374a3af
Commit
6374a3af
authored
May 03, 2021
by
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
Changes
16
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
app/build.gradle
View file @
6374a3af
...
@@ -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'
...
...
app/src/main/java/foundation/e/apps/MainActivity.kt
View file @
6374a3af
...
@@ -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
_n
avigation
_v
iew
.
setOnNavigationItemSelectedListener
{
binding
.
bottom
N
avigation
V
iew
.
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
_n
avigation
_v
iew
.
setItemIconTintList
(
iconsColorStates
)
binding
.
bottom
N
avigation
V
iew
.
setItemIconTintList
(
iconsColorStates
)
bottom
_n
avigation
_v
iew
.
setItemTextColor
(
textColorStates
)
binding
.
bottom
N
avigation
V
iew
.
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
_n
avigation
_v
iew
.
menu
.
findItem
(
currentFragmentId
).
isChecked
=
true
binding
.
bottom
N
avigation
V
iew
.
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
_n
avigation
_v
iew
.
getChildAt
(
0
)
as
BottomNavigationMenuView
val
menuView
=
binding
.
bottom
N
avigation
V
iew
.
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
_n
avigation
_v
iew
.
menu
.
removeItem
(
R
.
id
.
menu_categories
)
binding
.
bottom
N
avigation
V
iew
.
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
()
}
}
}
}
...
...
app/src/main/java/foundation/e/apps/categories/ApplicationsFragment.kt
View file @
6374a3af
...
@@ -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
_l
ist
.
visibility
=
View
.
GONE
categories
L
ist
.
visibility
=
View
.
GONE
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
VISIBLE
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
visibility
=
View
.
GONE
view
.
findViewById
<
TextView
>(
R
.
id
.
error
_r
esolve
)
.
setOnClickListener
{
error
R
esolve
.
setOnClickListener
{
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
VISIBLE
categoriesViewModel
.
loadCategories
(
requireContext
())
categoriesViewModel
.
loadCategories
(
requireContext
())
}
}
view
.
error
_r
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
error
R
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
view
.
error
_r
esolve
.
setBackgroundColor
(
color
)
error
R
esolve
.
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
_l
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
categories
L
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
view
.
categories
_l
ist
.
visibility
=
View
.
VISIBLE
categories
L
ist
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
progress
B
ar
.
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
_d
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
error
D
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
view
.
error
_c
ontainer
.
visibility
=
View
.
VISIBLE
error
C
ontainer
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
progress
B
ar
.
visibility
=
View
.
GONE
}
else
{
}
else
{
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
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
()
...
...
app/src/main/java/foundation/e/apps/categories/CategoriesFragment.kt
View file @
6374a3af
...
@@ -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
}
}
/*
/*
...
...
app/src/main/java/foundation/e/apps/categories/CategoriesListAdapter.kt
View file @
6374a3af
...
@@ -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
_c
ontainer
)
val
categoryContainer
=
binding
.
category
C
ontainer
val
categoryIcon
:
ImageView
=
view
.
findViewById
(
R
.
id
.
category
_i
con
)
val
categoryIcon
=
binding
.
category
I
con
val
categoryTitle
:
TextView
=
view
.
findViewById
(
R
.
id
.
category
_t
itle
)
val
categoryTitle
=
binding
.
category
T
itle
}
}
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
{
...
...
app/src/main/java/foundation/e/apps/categories/GamesFragment.kt
View file @
6374a3af
...
@@ -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
_l
ist
.
visibility
=
View
.
GONE
categories
L
ist
.
visibility
=
View
.
GONE
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
VISIBLE
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
visibility
=
View
.
GONE
view
.
findViewById
<
TextView
>(
R
.
id
.
error
_r
esolve
)
.
setOnClickListener
{
error
R
esolve
.
setOnClickListener
{
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
VISIBLE
categoriesViewModel
.
loadCategories
(
requireContext
())
categoriesViewModel
.
loadCategories
(
requireContext
())
}
}
view
.
error
_r
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
error
R
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
view
.
error
_r
esolve
.
setBackgroundColor
(
color
)
error
R
esolve
.
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
_l
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
categories
L
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
view
.
categories
_l
ist
.
visibility
=
View
.
VISIBLE
categories
L
ist
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
progress
B
ar
.
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
_d
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
error
D
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
view
.
error
_c
ontainer
.
visibility
=
View
.
VISIBLE
error
C
ontainer
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
progress
B
ar
.
visibility
=
View
.
GONE
}
else
{
}
else
{
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
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
{
...
...
app/src/main/java/foundation/e/apps/categories/PwasFragment.kt
View file @
6374a3af
...
@@ -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
()
{