Skip to content

Commit

Permalink
[FIX] Load assetFile with fallback error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
manneohlund committed Mar 1, 2018
1 parent 0f778ef commit b66fba2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions sample/src/main/java/com/sample/jsonthemer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.sample.jsonthemer
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.Menu
import android.view.MenuItem
import android.view.View
import com.sample.jsonthemer.databinding.ActivityMainBinding
import jsonthemer.JsonThemer
import jsonthemer.model.BaseThemeModel


class MainActivity : AppCompatActivity() {

companion object {
Expand All @@ -23,10 +23,19 @@ class MainActivity : AppCompatActivity() {
var currentTheme: String = LIME_THEME
}

lateinit var binding: ActivityMainBinding
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
val theme: BaseThemeModel = JsonThemer.setup(this, currentTheme)
val theme: BaseThemeModel = let {
try {
JsonThemer.setup(this, currentTheme)
} catch (e: Exception) {
Log.e(MainActivity::class.simpleName, "Error: AssetFileNotFound, " + e.message)

// Fallback on base model
BaseThemeModel()
}
}
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.themeModel = theme
Expand Down

0 comments on commit b66fba2

Please sign in to comment.