Commit af84e5ff authored by jo's avatar jo
Browse files

Use error.desciption, ldon't check if a nonNull variable is null

parent 1f8f08ce
......@@ -15,14 +15,17 @@ import android.util.TypedValue
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.*
import android.widget.ImageView
import android.widget.LinearLayout
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.*
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.ApplicationStateListener
import io.eelo.appinstaller.application.model.Downloader
import io.eelo.appinstaller.application.model.State
import io.eelo.appinstaller.application.model.data.FullData
import io.eelo.appinstaller.applicationmanager.ApplicationManager
import io.eelo.appinstaller.applicationmanager.ApplicationManagerServiceConnection
import io.eelo.appinstaller.applicationmanager.ApplicationManagerServiceConnectionCallback
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Common.toMiB
import io.eelo.appinstaller.utils.Constants
import io.eelo.appinstaller.utils.Constants.APPLICATION_DESCRIPTION_KEY
......@@ -87,7 +90,7 @@ class ApplicationActivity : AppCompatActivity(), ApplicationStateListener,
onApplicationInfoLoaded()
} else {
Snackbar.make(container,
getString(Common.getScreenErrorDescriptionId(error!!)),
getString(error!!.description),
Snackbar.LENGTH_LONG).show()
// Close activity once snackbar has hidden
......@@ -397,7 +400,7 @@ class ApplicationActivity : AppCompatActivity(), ApplicationStateListener,
// Make sure the APK is available for download
if (fullData.getLastVersion() == null) {
Snackbar.make(container,
getString(Common.getScreenErrorDescriptionId(Error.APK_UNAVAILABLE)),
getString(Error.APK_UNAVAILABLE.description),
Snackbar.LENGTH_LONG).show()
return
}
......@@ -415,12 +418,10 @@ class ApplicationActivity : AppCompatActivity(), ApplicationStateListener,
}
}
override fun anErrorHasOccurred(error: Error?) {
if (error != null) {
Snackbar.make(container,
getString(Common.getScreenErrorDescriptionId(error)),
Snackbar.LENGTH_LONG).show()
}
override fun anErrorHasOccurred(error: Error) {
Snackbar.make(container,
getString(error.description),
Snackbar.LENGTH_LONG).show()
}
override fun stateChanged(state: State) {
......
......@@ -5,9 +5,15 @@ import android.app.Activity
import android.support.design.widget.Snackbar
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.*
import android.widget.Button
import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.*
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.ApplicationStateListener
import io.eelo.appinstaller.application.model.Downloader
import io.eelo.appinstaller.application.model.State
import io.eelo.appinstaller.application.viewmodel.ApplicationViewModel
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Common.toMiB
......@@ -38,7 +44,7 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
if (application?.fullData != null &&
application!!.fullData!!.getLastVersion() == null) {
Snackbar.make(view, activity.getString(
Common.getScreenErrorDescriptionId(Error.APK_UNAVAILABLE)),
Error.APK_UNAVAILABLE.description),
Snackbar.LENGTH_LONG).show()
} else {
application?.buttonClicked(activity)
......@@ -89,11 +95,9 @@ class ApplicationViewHolder(private val activity: Activity, private val view: Vi
}
}
override fun anErrorHasOccurred(error: Error?) {
if (error != null) {
Snackbar.make(activity.findViewById(R.id.container),
activity.getString(Common.getScreenErrorDescriptionId(error)),
Snackbar.LENGTH_LONG).show()
}
override fun anErrorHasOccurred(error: Error) {
Snackbar.make(activity.findViewById(R.id.container),
activity.getString(error.description),
Snackbar.LENGTH_LONG).show()
}
}
\ No newline at end of file
......@@ -9,7 +9,10 @@ import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import io.eelo.appinstaller.R
import io.eelo.appinstaller.application.model.*
import io.eelo.appinstaller.application.model.Application
import io.eelo.appinstaller.application.model.ApplicationStateListener
import io.eelo.appinstaller.application.model.Downloader
import io.eelo.appinstaller.application.model.State
import io.eelo.appinstaller.application.viewmodel.ApplicationViewModel
import io.eelo.appinstaller.utils.Common
import io.eelo.appinstaller.utils.Common.toMiB
......@@ -36,7 +39,7 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
if (application?.fullData != null &&
application!!.fullData!!.getLastVersion() == null) {
Snackbar.make(view, activity.getString(
Common.getScreenErrorDescriptionId(Error.APK_UNAVAILABLE)),
Error.APK_UNAVAILABLE.description),
Snackbar.LENGTH_LONG).show()
} else {
application?.buttonClicked(activity)
......@@ -75,11 +78,9 @@ class SmallApplicationViewHolder(private val activity: Activity, private val vie
}
}
override fun anErrorHasOccurred(error: Error?) {
if (error != null) {
Snackbar.make(activity.findViewById(R.id.container),
activity.getString(Common.getScreenErrorDescriptionId(error)),
Snackbar.LENGTH_LONG).show()
}
override fun anErrorHasOccurred(error: Error) {
Snackbar.make(activity.findViewById(R.id.container),
activity.getString(error.description),
Snackbar.LENGTH_LONG).show()
}
}
\ No newline at end of file
......@@ -8,6 +8,6 @@ interface ApplicationStateListener {
fun downloading(downloader: Downloader)
fun anErrorHasOccurred(error: Error?)
fun anErrorHasOccurred(error: Error)
}
......@@ -54,7 +54,7 @@ class StateManager(private val info: ApplicationInfo, private val app: Applicati
}
}
fun notifyError(error: Error?) {
fun notifyError(error: Error) {
listeners.forEach { listener: ApplicationStateListener ->
listener.anErrorHasOccurred(error)
}
......
......@@ -44,7 +44,7 @@ class ApplicationsFragment : Fragment() {
// Bind to the screen error
categoriesViewModel.getScreenError().observe(this, Observer {
if (it != null) {
view.error_description.text = activity!!.getString(Common.getScreenErrorDescriptionId(it))
view.error_description.text = activity!!.getString(it.description)
view.error_container.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
} else {
......
......@@ -44,7 +44,7 @@ class GamesFragment : Fragment() {
// Bind to the screen error
categoriesViewModel.getScreenError().observe(this, Observer {
if (it != null) {
view.error_description.text = activity!!.getString(Common.getScreenErrorDescriptionId(it))
view.error_description.text = activity!!.getString(it.description)
view.error_container.visibility = View.VISIBLE
view.progress_bar.visibility = View.GONE
} else {
......
......@@ -102,7 +102,7 @@ class CategoryActivity : AppCompatActivity(), ApplicationManagerServiceConnectio
// Bind to the screen error
categoryViewModel.getScreenError().observe(this, Observer {
if (it != null) {
errorDescription.text = getString(Common.getScreenErrorDescriptionId(it))
errorDescription.text = getString(it.description)
errorContainer.visibility = View.VISIBLE
progressBar.visibility = View.GONE
loadMoreContainer.visibility = View.GONE
......
......@@ -85,7 +85,7 @@ class HomeFragment : Fragment() {
// Bind to the screen error
homeViewModel.getScreenError().observe(this, Observer {
if (it != null) {
errorDescription.text = activity!!.getString(Common.getScreenErrorDescriptionId(it))
errorDescription.text = activity!!.getString(it.description)
errorContainer.visibility = View.VISIBLE
progressBar.visibility = View.GONE
} else {
......
......@@ -130,7 +130,7 @@ class SearchFragment : Fragment(), SearchView.OnQueryTextListener, SearchView.On
// Bind to the screen error
searchViewModel.getScreenError().observe(this, Observer {
if (it != null) {
errorDescription.text = activity!!.getString(Common.getScreenErrorDescriptionId(it))
errorDescription.text = activity!!.getString(it.description)
errorContainer.visibility = View.VISIBLE
progressBar.visibility = View.GONE
loadMoreContainer.visibility = View.GONE
......
......@@ -94,7 +94,7 @@ class UpdatesFragment : Fragment() {
// Bind to the screen error
updatesViewModel.getScreenError().observe(this, Observer {
if (it != null) {
errorDescription.text = activity!!.getString(Common.getScreenErrorDescriptionId(it))
errorDescription.text = activity!!.getString(it.description)
errorContainer.visibility = View.VISIBLE
updateAll.isEnabled = false
progressBar.visibility = View.GONE
......
......@@ -22,8 +22,6 @@ object Common {
return inMiB.times(10.0).roundToInt().div(10.0)
}
fun getScreenErrorDescriptionId(screenError: Error) = screenError.description
fun isSystemApp(packageManager: PackageManager, packageName: String): Boolean {
try {
// Get package information for the app
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment