fix #230, go to the main screen after opening the app through widget and going back

This commit is contained in:
tibbi 2017-10-21 19:09:26 +02:00
parent 387269a58a
commit 879ba83574
2 changed files with 27 additions and 6 deletions

View File

@ -111,6 +111,8 @@ class MainActivity : SimpleActivity(), NavigationListener {
dbHelper.deleteEvents(ids, false) dbHelper.deleteEvents(ids, false)
config.googleSync = false config.googleSync = false
} }
checkOpenIntents()
} }
override fun onResume() { override fun onResume() {
@ -194,6 +196,23 @@ class MainActivity : SimpleActivity(), NavigationListener {
mStoredDayCode = Formatter.getTodayCode() mStoredDayCode = Formatter.getTodayCode()
} }
private fun checkOpenIntents() {
val dayCodeToOpen = intent.getStringExtra(DAY_CODE) ?: ""
if (dayCodeToOpen.isNotEmpty()) {
openDayCode(dayCodeToOpen)
}
val eventIdToOpen = intent.getIntExtra(EVENT_ID, 0)
val eventOccurrenceToOpen = intent.getIntExtra(EVENT_OCCURRENCE_TS, 0)
if (eventIdToOpen != 0 && eventOccurrenceToOpen != 0) {
Intent(this, EventActivity::class.java).apply {
putExtra(EVENT_ID, eventIdToOpen)
putExtra(EVENT_OCCURRENCE_TS, eventOccurrenceToOpen)
startActivity(this)
}
}
}
private fun showViewDialog() { private fun showViewDialog() {
val res = resources val res = resources
val items = arrayListOf( val items = arrayListOf(
@ -661,6 +680,10 @@ class MainActivity : SimpleActivity(), NavigationListener {
private fun openDayAt(timestamp: Long) { private fun openDayAt(timestamp: Long) {
val dayCode = Formatter.getDayCodeFromTS((timestamp / 1000).toInt()) val dayCode = Formatter.getDayCodeFromTS((timestamp / 1000).toInt())
openDayCode(dayCode)
}
private fun openDayCode(dayCode: String) {
Intent(this, DayActivity::class.java).apply { Intent(this, DayActivity::class.java).apply {
putExtra(DAY_CODE, dayCode) putExtra(DAY_CODE, dayCode)
startActivity(this) startActivity(this)

View File

@ -11,19 +11,17 @@ class SplashActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
if (intent.extras?.containsKey(DAY_CODE) == true) { when {
Intent(this, DayActivity::class.java).apply { intent.extras?.containsKey(DAY_CODE) == true -> Intent(this, MainActivity::class.java).apply {
putExtra(DAY_CODE, intent.getStringExtra(DAY_CODE)) putExtra(DAY_CODE, intent.getStringExtra(DAY_CODE))
startActivity(this) startActivity(this)
} }
} else if (intent.extras?.containsKey(EVENT_ID) == true) { intent.extras?.containsKey(EVENT_ID) == true -> Intent(this, MainActivity::class.java).apply {
Intent(this, EventActivity::class.java).apply {
putExtra(EVENT_ID, intent.getIntExtra(EVENT_ID, 0)) putExtra(EVENT_ID, intent.getIntExtra(EVENT_ID, 0))
putExtra(EVENT_OCCURRENCE_TS, intent.getIntExtra(EVENT_OCCURRENCE_TS, 0)) putExtra(EVENT_OCCURRENCE_TS, intent.getIntExtra(EVENT_OCCURRENCE_TS, 0))
startActivity(this) startActivity(this)
} }
} else { else -> startActivity(Intent(this, MainActivity::class.java))
startActivity(Intent(this, MainActivity::class.java))
} }
finish() finish()
} }