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 {
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'
...
...
app/src/main/java/foundation/e/apps/MainActivity.kt
View file @
6374a3af
...
...
@@ -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
_n
avigation
_v
iew
.
setOnNavigationItemSelectedListener
{
binding
.
bottom
N
avigation
V
iew
.
setOnNavigationItemSelectedListener
{
if
(
selectFragment
(
it
.
itemId
,
it
))
{
disableCategoryIfOpenSource
()
currentFragmentId
=
it
.
itemId
...
...
@@ -163,8 +163,8 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
))
bottom
_n
avigation
_v
iew
.
setItemIconTintList
(
iconsColorStates
)
bottom
_n
avigation
_v
iew
.
setItemTextColor
(
textColorStates
)
binding
.
bottom
N
avigation
V
iew
.
setItemIconTintList
(
iconsColorStates
)
binding
.
bottom
N
avigation
V
iew
.
setItemTextColor
(
textColorStates
)
}
...
...
@@ -266,7 +266,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
}
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
.
beginTransaction
()
.
replace
(
R
.
id
.
frame_layout
,
fragment
)
...
...
@@ -275,7 +275,7 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
@SuppressLint
(
"RestrictedApi"
)
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
{
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
_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
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
()
}
}
...
...
app/src/main/java/foundation/e/apps/categories/ApplicationsFragment.kt
View file @
6374a3af
...
...
@@ -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
_l
ist
.
visibility
=
View
.
GONE
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
view
.
findViewById
<
TextView
>(
R
.
id
.
error
_r
esolve
)
.
setOnClickListener
{
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
categories
L
ist
.
visibility
=
View
.
GONE
progress
B
ar
.
visibility
=
View
.
VISIBLE
error
C
ontainer
.
visibility
=
View
.
GONE
error
R
esolve
.
setOnClickListener
{
progress
B
ar
.
visibility
=
View
.
VISIBLE
categoriesViewModel
.
loadCategories
(
requireContext
())
}
view
.
error
_r
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
view
.
error
_r
esolve
.
setBackgroundColor
(
color
)
error
R
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
error
R
esolve
.
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
_l
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
view
.
categories
_l
ist
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
categories
L
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
categories
L
ist
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
GONE
}
})
// Bind to the screen error
categoriesViewModel
.
getScreenError
().
observe
(
viewLifecycleOwner
,
Observer
{
if
(
it
!=
null
)
{
view
.
error
_d
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
view
.
error
_c
ontainer
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
error
D
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
error
C
ontainer
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
GONE
}
else
{
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
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
()
...
...
app/src/main/java/foundation/e/apps/categories/CategoriesFragment.kt
View file @
6374a3af
...
...
@@ -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
}
/*
...
...
app/src/main/java/foundation/e/apps/categories/CategoriesListAdapter.kt
View file @
6374a3af
...
...
@@ -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
_c
ontainer
)
val
categoryIcon
:
ImageView
=
view
.
findViewById
(
R
.
id
.
category
_i
con
)
val
categoryTitle
:
TextView
=
view
.
findViewById
(
R
.
id
.
category
_t
itle
)
class
CategoryViewHolder
(
binding
:
CategoryListItemBinding
)
:
RecyclerView
.
ViewHolder
(
binding
.
root
)
{
val
categoryContainer
=
binding
.
category
C
ontainer
val
categoryIcon
=
binding
.
category
I
con
val
categoryTitle
=
binding
.
category
T
itle
}
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
{
...
...
app/src/main/java/foundation/e/apps/categories/GamesFragment.kt
View file @
6374a3af
...
...
@@ -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
_l
ist
.
visibility
=
View
.
GONE
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
view
.
findViewById
<
TextView
>(
R
.
id
.
error
_r
esolve
)
.
setOnClickListener
{
view
.
progress
_b
ar
.
visibility
=
View
.
VISIBLE
categories
L
ist
.
visibility
=
View
.
GONE
progress
B
ar
.
visibility
=
View
.
VISIBLE
error
C
ontainer
.
visibility
=
View
.
GONE
error
R
esolve
.
setOnClickListener
{
progress
B
ar
.
visibility
=
View
.
VISIBLE
categoriesViewModel
.
loadCategories
(
requireContext
())
}
view
.
error
_r
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
view
.
error
_r
esolve
.
setBackgroundColor
(
color
)
error
R
esolve
.
setTextColor
(
Color
.
parseColor
(
"#ffffff"
))
error
R
esolve
.
setBackgroundColor
(
color
)
// Bind to the list of games categories
categoriesViewModel
.
getGamesCategories
().
observe
(
viewLifecycleOwner
,
Observer
{
if
(
it
!!
.
isNotEmpty
())
{
view
.
categories
_l
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
view
.
categories
_l
ist
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
categories
L
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
color
)
}
categories
L
ist
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
GONE
}
})
// Bind to the screen error
categoriesViewModel
.
getScreenError
().
observe
(
viewLifecycleOwner
,
Observer
{
if
(
it
!=
null
)
{
view
.
error
_d
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
view
.
error
_c
ontainer
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
error
D
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
error
C
ontainer
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
GONE
}
else
{
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
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
{
...
...
app/src/main/java/foundation/e/apps/categories/PwasFragment.kt
View file @
6374a3af
...
...
@@ -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
_l
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
null
)
}
view
.
categories
_l
ist
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
categories
L
ist
.
adapter
=
context
?.
let
{
context
->
CategoriesListAdapter
(
context
,
it
,
null
)
}
categories
L
ist
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
GONE
}
})
// Bind to the screen error
categoriesViewModel
.
getScreenError
().
observe
(
viewLifecycleOwner
,
Observer
{
if
(
it
!=
null
)
{
view
.
error
_d
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
view
.
error
_c
ontainer
.
visibility
=
View
.
VISIBLE
view
.
progress
_b
ar
.
visibility
=
View
.
GONE
error
D
escription
.
text
=
requireActivity
().
getString
(
it
.
description
)
error
C
ontainer
.
visibility
=
View
.
VISIBLE
progress
B
ar
.
visibility
=
View
.
GONE
}
else
{
view
.
error
_c
ontainer
.
visibility
=
View
.
GONE
error
C
ontainer
.
visibility
=
View
.
GONE
}
})
if
(
categoriesViewModel
.
getPwasCategories
().
value
!!
.
isEmpty
())
{
categoriesViewModel
.
loadCategories
(
requireContext
())
}
return
view
return
binding
.
root
}
override
fun
onDestroyView
()
{
super
.
onDestroyView
()
_binding
=
null
}
}
app/src/main/java/foundation/e/apps/home/HomeFragment.kt
View file @
6374a3af
...
...
@@ -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
_r
esolve
)
.
setOnClickListener
{
error
R
esolve
.
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
}