Skip to content

Commit

Permalink
change: intent names for ExceptionHandlingActivity.kt and MainActivit…
Browse files Browse the repository at this point in the history
…y.kt according to #93
  • Loading branch information
Jtoliveira committed Apr 14, 2021
1 parent bb8edb5 commit 7c52070
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions Project/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.fasterxml.jackson.core.JsonProcessingException
import org.ionproject.android.common.IonApplication
import org.ionproject.android.error.ERROR_KEY
import org.ionproject.android.error.ErrorActivity
import org.ionproject.android.error.*
import java.io.IOException

abstract class ExceptionHandlingActivity : AppCompatActivity() {
Expand All @@ -31,15 +30,15 @@ abstract class ExceptionHandlingActivity : AppCompatActivity() {
val intent = Intent(this, ErrorActivity::class.java)
when (throwable) {
is JsonProcessingException -> intent.putExtra(
ERROR_KEY,
ERROR_ACTIVITY_EXCEPTION_KEY,
resources.getString(R.string.label_error_loading_error)
)
is IOException -> intent.putExtra(
ERROR_KEY,
ERROR_ACTIVITY_EXCEPTION_KEY,
resources.getString(R.string.label_no_connectivity_loading_error)
)
else -> intent.putExtra(
ERROR_KEY,
ERROR_ACTIVITY_EXCEPTION_KEY,
resources.getString(R.string.label_error_loading_error)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import kotlinx.android.synthetic.main.activity_error.*
import org.ionproject.android.R
import org.ionproject.android.common.addGradientBackground

// Random value key used to pass the error message to [ErrorActivity] via the intent
const val ERROR_KEY = "12xp3m91x0meh1"
const val ERROR_ACTIVITY_EXCEPTION_KEY = "ErrorActivity.Exception.Extra"

class ErrorActivity : AppCompatActivity() {

Expand All @@ -22,7 +21,7 @@ class ErrorActivity : AppCompatActivity() {
}

// Apply error message if it was passed via the intent
intent.getStringExtra(ERROR_KEY)?.apply {
intent.getStringExtra(ERROR_ACTIVITY_EXCEPTION_KEY)?.apply {
textview_error_activity_message.text = this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import org.ionproject.android.ExceptionHandlingActivity
import org.ionproject.android.R
import org.ionproject.android.common.addGradientBackground
import org.ionproject.android.error.ErrorActivity
import org.ionproject.android.main.MAIN_ACTIVITY_ROOT_EXTRA
import org.ionproject.android.main.MainActivity

// Random value key used to pass the root object from [LoadingActivity] to [MainActivity] via the intent
const val ROOT_KEY = "m0192exe1gxe12x1"

class LoadingActivity : ExceptionHandlingActivity() {

private val loadingViewModel by lazy(LazyThreadSafetyMode.NONE) {
Expand All @@ -28,7 +26,7 @@ class LoadingActivity : ExceptionHandlingActivity() {
loadingViewModel.observeRootLiveData(this) {
if (it != null) {
val intent = Intent(this, MainActivity::class.java)
intent.putExtra(ROOT_KEY, it)
intent.putExtra(MAIN_ACTIVITY_ROOT_EXTRA, it)
this.startActivity(intent)
} else {
val intent = Intent(this, ErrorActivity::class.java)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import org.ionproject.android.SharedViewModelProvider
import org.ionproject.android.common.IonApplication
import org.ionproject.android.common.addGradientBackground
import org.ionproject.android.common.model.Root
import org.ionproject.android.loading.ROOT_KEY
import org.ionproject.android.search.SearchSuggestionsProvider

const val MAIN_ACTIVITY_ROOT_EXTRA = "MainActivity.Root.Extra"

class MainActivity : ExceptionHandlingActivity(),
DeleteSuggestionsDialogFragment.OnDeleteSuggestionsDialogListener {

Expand Down Expand Up @@ -73,7 +74,7 @@ class MainActivity : ExceptionHandlingActivity(),
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
main_activity.addGradientBackground()
val root = intent.getParcelableExtra<Root>(ROOT_KEY)
val root = intent.getParcelableExtra<Root>(MAIN_ACTIVITY_ROOT_EXTRA)
if (root != null) {
sharedViewModel.root = root
setupTopBarBehaviour()
Expand Down

0 comments on commit 7c52070

Please sign in to comment.