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
bfc29137
Commit
bfc29137
authored
Nov 20, 2018
by
Nihar Thakkar
Browse files
Create error structure for category screen
parent
298e168e
Changes
7
Hide whitespace changes
Inline
Side-by-side
app/src/main/java/io/eelo/appinstaller/MainActivity.kt
View file @
bfc29137
...
...
@@ -2,6 +2,7 @@ package io.eelo.appinstaller
import
android.annotation.SuppressLint
import
android.content.pm.PackageManager
import
android.os.AsyncTask
import
android.os.Bundle
import
android.support.design.internal.BottomNavigationItemView
import
android.support.design.internal.BottomNavigationMenuView
...
...
@@ -35,23 +36,30 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
Common
.
EXECUTOR
.
submit
{
val
installManager
=
installManagerGetter
.
connectAndGet
(
this
)
initialiseFragments
(
installManager
)
// Show the home fragment by default
if
(
savedInstanceState
!=
null
&&
savedInstanceState
.
containsKey
(
CURRENTLY_SELECTED_FRAGMENT_KEY
))
{
if
(
selectFragment
(
savedInstanceState
.
getInt
(
CURRENTLY_SELECTED_FRAGMENT_KEY
)))
{
currentFragmentId
=
savedInstanceState
.
getInt
(
CURRENTLY_SELECTED_FRAGMENT_KEY
)
}
}
else
{
if
(
selectFragment
(
R
.
id
.
menu_home
))
{
currentFragmentId
=
R
.
id
.
menu_home
}
}
}
bottom_navigation_view
.
setOnNavigationItemSelectedListener
(
this
)
disableShiftingOfNabBarItems
()
object
:
AsyncTask
<
Void
,
Void
,
Void
>()
{
override
fun
doInBackground
(
vararg
p0
:
Void
?):
Void
?
{
val
installManager
=
installManagerGetter
.
connectAndGet
(
this
@MainActivity
)
initialiseFragments
(
installManager
)
return
null
}
override
fun
onPostExecute
(
result
:
Void
?)
{
// Show the home fragment by default
if
(
savedInstanceState
!=
null
&&
savedInstanceState
.
containsKey
(
CURRENTLY_SELECTED_FRAGMENT_KEY
))
{
if
(
selectFragment
(
savedInstanceState
.
getInt
(
CURRENTLY_SELECTED_FRAGMENT_KEY
)))
{
currentFragmentId
=
savedInstanceState
.
getInt
(
CURRENTLY_SELECTED_FRAGMENT_KEY
)
}
}
else
{
if
(
selectFragment
(
R
.
id
.
menu_home
))
{
currentFragmentId
=
R
.
id
.
menu_home
}
}
}
}.
executeOnExecutor
(
Common
.
EXECUTOR
)
}
private
fun
initialiseFragments
(
installManager
:
InstallManager
)
{
...
...
app/src/main/java/io/eelo/appinstaller/application/ApplicationActivity.kt
View file @
bfc29137
...
...
@@ -73,7 +73,7 @@ class ApplicationActivity : AppCompatActivity(), ApplicationStateListener {
intent
.
putExtra
(
APPLICATION_DESCRIPTION_KEY
,
application
.
data
.
description
)
startActivity
(
intent
)
}
app_rating
.
text
=
application
.
data
.
stars
.
toString
()
+
"/
10
"
app_rating
.
text
=
application
.
data
.
stars
.
toString
()
+
"/
5
"
app_privacy_score
.
text
=
application
.
data
.
privacyScore
.
toString
()
+
"/10"
app_energy_score
.
text
=
application
.
data
.
energyScore
.
toString
()
+
"/10"
app_install
.
setOnClickListener
{
...
...
app/src/main/java/io/eelo/appinstaller/categories/category/CategoryActivity.kt
View file @
bfc29137
...
...
@@ -2,6 +2,7 @@ package io.eelo.appinstaller.categories.category
import
android.arch.lifecycle.Observer
import
android.arch.lifecycle.ViewModelProviders
import
android.os.AsyncTask
import
android.os.Bundle
import
android.support.v7.app.AppCompatActivity
import
android.support.v7.widget.LinearLayoutManager
...
...
@@ -9,7 +10,9 @@ import android.support.v7.widget.RecyclerView
import
android.support.v7.widget.Toolbar
import
android.view.MenuItem
import
android.view.View
import
android.widget.LinearLayout
import
android.widget.ProgressBar
import
android.widget.TextView
import
io.eelo.appinstaller.R
import
io.eelo.appinstaller.application.model.Application
import
io.eelo.appinstaller.application.model.InstallManagerGetter
...
...
@@ -35,22 +38,23 @@ class CategoryActivity : AppCompatActivity() {
val
toolbar
=
findViewById
<
Toolbar
>(
R
.
id
.
toolbar
)
setSupportActionBar
(
toolbar
)
supportActionBar
?.
setDisplayHomeAsUpEnabled
(
true
)
category
=
intent
.
getSerializableExtra
(
CATEGORY_KEY
)
as
Category
supportActionBar
?.
title
=
category
.
title
categoryViewModel
=
ViewModelProviders
.
of
(
this
).
get
(
CategoryViewModel
::
class
.
java
)
Common
.
EXECUTOR
.
submit
{
val
installManager
=
installManagerGetter
.
connectAndGet
(
this
)
categoryViewModel
.
initialise
(
installManager
,
category
.
id
)
categoryViewModel
.
loadApplications
(
this
)
}
recyclerView
=
findViewById
(
R
.
id
.
app_list
)
recyclerView
.
visibility
=
View
.
GONE
progressBar
=
findViewById
(
R
.
id
.
progress_bar
)
val
errorContainer
=
findViewById
<
LinearLayout
>(
R
.
id
.
error_container
)
val
errorDescription
=
findViewById
<
TextView
>(
R
.
id
.
error_description
)
// Initialise UI elements
recyclerView
.
visibility
=
View
.
GONE
progressBar
.
visibility
=
View
.
VISIBLE
errorContainer
.
visibility
=
View
.
GONE
findViewById
<
TextView
>(
R
.
id
.
error_resolve
).
setOnClickListener
{
progressBar
.
visibility
=
View
.
VISIBLE
categoryViewModel
.
loadApplications
(
this
)
}
// Initialise recycler view
recyclerView
.
setHasFixedSize
(
true
)
...
...
@@ -68,6 +72,30 @@ class CategoryActivity : AppCompatActivity() {
recyclerView
.
scrollToPosition
(
0
)
}
})
// Bind to the screen error
categoryViewModel
.
getScreenError
().
observe
(
this
,
Observer
{
if
(
it
!=
null
)
{
errorDescription
.
text
=
getString
(
Common
.
getScreenErrorDescriptionId
(
it
))
errorContainer
.
visibility
=
View
.
VISIBLE
progressBar
.
visibility
=
View
.
GONE
}
else
{
errorContainer
.
visibility
=
View
.
GONE
}
})
object
:
AsyncTask
<
Void
,
Void
,
Void
>()
{
override
fun
doInBackground
(
vararg
p0
:
Void
?):
Void
?
{
val
installManager
=
installManagerGetter
.
connectAndGet
(
this
@CategoryActivity
)
categoryViewModel
.
initialise
(
installManager
,
category
.
id
)
return
null
}
override
fun
onPostExecute
(
result
:
Void
?)
{
categoryViewModel
.
loadApplications
(
this
@CategoryActivity
)
}
}.
executeOnExecutor
(
Common
.
EXECUTOR
)
}
override
fun
onOptionsItemSelected
(
item
:
MenuItem
?):
Boolean
{
...
...
app/src/main/java/io/eelo/appinstaller/categories/category/model/CategoryModel.kt
View file @
bfc29137
...
...
@@ -5,6 +5,7 @@ import android.content.Context
import
io.eelo.appinstaller.application.model.Application
import
io.eelo.appinstaller.application.model.InstallManager
import
io.eelo.appinstaller.utils.Common
import
io.eelo.appinstaller.utils.ScreenError
class
CategoryModel
:
CategoryModelInterface
{
...
...
@@ -12,6 +13,7 @@ class CategoryModel : CategoryModelInterface {
lateinit
var
category
:
String
private
var
page
=
1
val
categoryApplicationsList
=
MutableLiveData
<
ArrayList
<
Application
>>()
var
screenError
=
MutableLiveData
<
ScreenError
>()
init
{
if
(
categoryApplicationsList
.
value
==
null
)
{
...
...
@@ -25,9 +27,11 @@ class CategoryModel : CategoryModelInterface {
}
override
fun
loadApplications
(
context
:
Context
)
{
Loader
(
page
,
this
).
executeOnExecutor
(
Common
.
EXECUTOR
,
context
)
page
++
if
(
Common
.
isNetworkAvailable
(
context
))
{
Loader
(
page
,
this
).
executeOnExecutor
(
Common
.
EXECUTOR
,
context
)
page
++
}
else
{
screenError
.
value
=
ScreenError
.
NO_INTERNET
}
}
}
app/src/main/java/io/eelo/appinstaller/categories/category/viewmodel/CategoryViewModel.kt
View file @
bfc29137
...
...
@@ -6,6 +6,7 @@ import android.content.Context
import
io.eelo.appinstaller.application.model.Application
import
io.eelo.appinstaller.application.model.InstallManager
import
io.eelo.appinstaller.categories.category.model.CategoryModel
import
io.eelo.appinstaller.utils.ScreenError
class
CategoryViewModel
:
ViewModel
(),
CategoryViewModelInterface
{
private
val
categoryModel
=
CategoryModel
()
...
...
@@ -18,8 +19,12 @@ class CategoryViewModel : ViewModel(), CategoryViewModelInterface {
return
categoryModel
.
categoryApplicationsList
}
override
fun
getScreenError
():
MutableLiveData
<
ScreenError
>
{
return
categoryModel
.
screenError
}
override
fun
loadApplications
(
context
:
Context
)
{
categoryModel
.
screenError
.
value
=
null
categoryModel
.
loadApplications
(
context
)
}
}
app/src/main/java/io/eelo/appinstaller/categories/category/viewmodel/CategoryViewModelInterface.kt
View file @
bfc29137
...
...
@@ -4,6 +4,7 @@ import android.arch.lifecycle.MutableLiveData
import
android.content.Context
import
io.eelo.appinstaller.application.model.Application
import
io.eelo.appinstaller.application.model.InstallManager
import
io.eelo.appinstaller.utils.ScreenError
interface
CategoryViewModelInterface
{
...
...
@@ -11,6 +12,7 @@ interface CategoryViewModelInterface {
fun
getApplications
():
MutableLiveData
<
ArrayList
<
Application
>>
fun
loadApplications
(
context
:
Context
)
fun
getScreenError
():
MutableLiveData
<
ScreenError
>
}
\ No newline at end of file
fun
loadApplications
(
context
:
Context
)
}
app/src/main/res/layout/activity_category.xml
View file @
bfc29137
...
...
@@ -22,6 +22,15 @@
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/toolbar"
/>
<include
layout=
"@layout/error_layout"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/toolbar"
/>
<ProgressBar
android:id=
"@+id/progress_bar"
android:layout_width=
"wrap_content"
...
...
@@ -29,6 +38,6 @@
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_to
TopOf=
"parent
"
/>
app:layout_constraintTop_to
BottomOf=
"@id/toolbar
"
/>
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment