Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emergency Alerts: Loading New Themes #155

Open
englehorn opened this issue Jul 28, 2022 · 0 comments
Open

Emergency Alerts: Loading New Themes #155

englehorn opened this issue Jul 28, 2022 · 0 comments

Comments

@englehorn
Copy link
Collaborator

There are some issues with the way new themes are loading in the Android app. The MainActivity.kt getTheme() method is called before the views are instantiated in the onCreate() method. This results in the AndroidManifest.xml default theme and styles being loaded the first time a new EventStatus.js file is detected.

One solution is to check the app themeId and event status shared preferences themeId for a match when a new event is detected. If there is a match then display the correct themed alert banner. This will work, however, it requires an additional loading of the application.

MainActivity.kt

Example Code:

 // handle event banner
        eventViewModel = ViewModelProvider(this, viewModelFactory).get(EventBannerViewModel::class.java)
        eventViewModel.eventStatus.observe(this, Observer { eventResponse ->
            eventResponse.data?.let {

                val settings = PreferenceManager.getDefaultSharedPreferences(this)
                val themeId = settings.getInt(getString(R.string.pref_key_theme), 0)
                val editor = settings.edit()

                editor.putInt(getString(R.string.pref_key_theme), it.themeId)
                editor.putString(getString(R.string.pref_key_current_event), it.title)
                editor.commit()

                if (TimeUtils.currentDateInRange(it.startDate, it.endDate, "yyyy-MM-dd")) {

                    eventTitle = it.title

                    if (it.themeId == themeId) {
                        navView.menu.setGroupVisible(R.id.event_banner_group, true)
                        navView.menu.findItem(R.id.event_banner).actionView.findViewById<TextView>(R.id.event_banner_text).text =
                            it.bannerText

                    }


                } else {
                    navView.menu.setGroupVisible(R.id.event_banner_group, false)

                    editor.putString(getString(R.string.pref_key_last_seen_event), "")
                    editor.putString(getString(R.string.pref_key_current_event), "")
                    editor.putInt(getString(R.string.pref_key_theme), 0)
                    editor.apply()
                }
            }
        })

        notificationsViewModel = ViewModelProvider(this, viewModelFactory).get(
            NotificationsViewModel::class.java
        )

        notificationsViewModel.topics.observe(this, Observer { topics ->
            topics.data?.let {
                for (topic in it) {
                    notificationsViewModel.updateSubscription(
                        topic.topic,
                        topic.subscribed
                    )
                }
            }
        })

Originally posted by @englehorn in #149 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant