mirror of
https://github.com/wulkanowy/wulkanowy.git
synced 2024-11-23 17:26:04 -06:00
Fix menu view initialization and restoration (#333)
This commit is contained in:
parent
b032c459d1
commit
24f58835e7
@ -11,10 +11,10 @@ cache:
|
||||
- $HOME/.gradle/caches/
|
||||
- $HOME/.gradle/wrapper/
|
||||
|
||||
#branches:
|
||||
# only:
|
||||
# - master
|
||||
# - 0.7.x
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- 0.7.x
|
||||
|
||||
android:
|
||||
licenses:
|
||||
|
@ -85,7 +85,7 @@ play {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'io.github.wulkanowy:api:0.8.0'
|
||||
implementation 'com.github.wulkanowy:api:47337a3'
|
||||
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||
|
@ -48,8 +48,8 @@
|
||||
android:theme="@style/WulkanowyTheme.NoActionBar" />
|
||||
<activity
|
||||
android:name=".ui.modules.timetablewidget.TimetableWidgetConfigureActivity"
|
||||
android:noHistory="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/WulkanowyTheme.WidgetAccountSwitcher">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
@ -57,8 +57,8 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.modules.luckynumberwidget.LuckyNumberWidgetConfigureActivity"
|
||||
android:noHistory="true"
|
||||
android:excludeFromRecents="true"
|
||||
android:noHistory="true"
|
||||
android:theme="@style/WulkanowyTheme.WidgetAccountSwitcher">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
|
||||
|
@ -15,8 +15,7 @@ import io.github.wulkanowy.data.repositories.grade.GradeRepository
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity.Companion.EXTRA_START_MENU
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.main.MainView.MenuView
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
import io.reactivex.Completable
|
||||
import javax.inject.Inject
|
||||
@ -48,8 +47,8 @@ class GradeWork @Inject constructor(
|
||||
.setDefaults(DEFAULT_ALL)
|
||||
.setColor(context.getCompatColor(R.color.colorPrimary))
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(context, 0,
|
||||
MainActivity.getStartIntent(context).putExtra(EXTRA_START_MENU, MainView.MenuView.GRADE), FLAG_UPDATE_CURRENT))
|
||||
PendingIntent.getActivity(context, MenuView.GRADE.id,
|
||||
MainActivity.getStartIntent(context, MenuView.GRADE, true), FLAG_UPDATE_CURRENT))
|
||||
.setStyle(NotificationCompat.InboxStyle().run {
|
||||
setSummaryText(context.resources.getQuantityString(R.plurals.grade_number_item, grades.size, grades.size))
|
||||
grades.forEach { addLine("${it.subject}: ${it.entry}") }
|
||||
|
@ -15,8 +15,7 @@ import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity.Companion.EXTRA_START_MENU
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.main.MainView.MenuView
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
import io.reactivex.Completable
|
||||
import javax.inject.Inject
|
||||
@ -48,9 +47,8 @@ class LuckyNumberWork @Inject constructor(
|
||||
.setPriority(PRIORITY_HIGH)
|
||||
.setColor(context.getCompatColor(R.color.colorPrimary))
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(context, MainView.MenuView.MESSAGE.id,
|
||||
MainActivity.getStartIntent(context).putExtra(EXTRA_START_MENU, MainView.MenuView.LUCKY_NUMBER)
|
||||
, FLAG_UPDATE_CURRENT))
|
||||
PendingIntent.getActivity(context, MenuView.MESSAGE.id,
|
||||
MainActivity.getStartIntent(context, MenuView.LUCKY_NUMBER, true), FLAG_UPDATE_CURRENT))
|
||||
.build())
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ import io.github.wulkanowy.data.repositories.message.MessageRepository
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity.Companion.EXTRA_START_MENU
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.main.MainView.MenuView
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
import io.reactivex.Completable
|
||||
import javax.inject.Inject
|
||||
@ -49,8 +48,8 @@ class MessageWork @Inject constructor(
|
||||
.setPriority(PRIORITY_HIGH)
|
||||
.setColor(context.getCompatColor(R.color.colorPrimary))
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(context, MainView.MenuView.MESSAGE.id, MainActivity.getStartIntent(context)
|
||||
.putExtra(EXTRA_START_MENU, MainView.MenuView.MESSAGE), FLAG_UPDATE_CURRENT)
|
||||
PendingIntent.getActivity(context, MenuView.MESSAGE.id,
|
||||
MainActivity.getStartIntent(context, MenuView.MESSAGE, true), FLAG_UPDATE_CURRENT)
|
||||
)
|
||||
.setStyle(NotificationCompat.InboxStyle().run {
|
||||
setSummaryText(context.resources.getQuantityString(R.plurals.message_number_item, messages.size, messages.size))
|
||||
|
@ -15,8 +15,7 @@ import io.github.wulkanowy.data.repositories.note.NoteRepository
|
||||
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
||||
import io.github.wulkanowy.services.sync.channels.NewEntriesChannel
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity.Companion.EXTRA_START_MENU
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.main.MainView.MenuView
|
||||
import io.github.wulkanowy.utils.getCompatColor
|
||||
import io.reactivex.Completable
|
||||
import javax.inject.Inject
|
||||
@ -48,9 +47,8 @@ class NoteWork @Inject constructor(
|
||||
.setPriority(PRIORITY_HIGH)
|
||||
.setColor(context.getCompatColor(R.color.colorPrimary))
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(context, MainView.MenuView.NOTE.id,
|
||||
MainActivity.getStartIntent(context).putExtra(EXTRA_START_MENU, MainView.MenuView.NOTE)
|
||||
, FLAG_UPDATE_CURRENT))
|
||||
PendingIntent.getActivity(context, MenuView.NOTE.id,
|
||||
MainActivity.getStartIntent(context, MenuView.NOTE, true), FLAG_UPDATE_CURRENT))
|
||||
.setStyle(NotificationCompat.InboxStyle().run {
|
||||
setSummaryText(context.resources.getQuantityString(R.plurals.note_number_item, notes.size, notes.size))
|
||||
notes.forEach { addLine("${it.teacher}: ${it.category}") }
|
||||
|
@ -15,7 +15,6 @@ import eu.davidea.flexibleadapter.common.SmoothScrollLinearLayoutManager
|
||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||
import io.github.wulkanowy.R
|
||||
import io.github.wulkanowy.ui.modules.login.LoginActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.utils.setOnItemClickListener
|
||||
import kotlinx.android.synthetic.main.dialog_account.*
|
||||
import javax.inject.Inject
|
||||
@ -97,11 +96,8 @@ class AccountDialog : DaggerAppCompatDialogFragment(), AccountView {
|
||||
}
|
||||
}
|
||||
|
||||
override fun recreateView() {
|
||||
activity?.also {
|
||||
startActivity(MainActivity.getStartIntent(it))
|
||||
it.finish()
|
||||
}
|
||||
override fun recreateMainView() {
|
||||
activity?.recreate()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -54,7 +54,7 @@ class AccountPresenter @Inject constructor(
|
||||
openClearLoginView()
|
||||
} else {
|
||||
Timber.i("Logout result: Switch to another student")
|
||||
recreateView()
|
||||
recreateMainView()
|
||||
}
|
||||
}
|
||||
}, {
|
||||
@ -73,9 +73,10 @@ class AccountPresenter @Inject constructor(
|
||||
disposable.add(studentRepository.switchStudent(item.student)
|
||||
.subscribeOn(schedulers.backgroundThread)
|
||||
.observeOn(schedulers.mainThread)
|
||||
.doFinally { view?.dismissView() }
|
||||
.subscribe({
|
||||
Timber.i("Change a student result: Success")
|
||||
view?.recreateView()
|
||||
view?.recreateMainView()
|
||||
}, {
|
||||
Timber.i("Change a student result: An exception occurred")
|
||||
errorHandler.dispatch(it)
|
||||
|
@ -16,6 +16,6 @@ interface AccountView : BaseView {
|
||||
|
||||
fun openClearLoginView()
|
||||
|
||||
fun recreateView()
|
||||
fun recreateMainView()
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package io.github.wulkanowy.ui.modules.login.studentselect
|
||||
|
||||
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
@ -58,10 +56,7 @@ class LoginStudentSelectFragment : BaseFragment(), LoginStudentSelectView {
|
||||
}
|
||||
|
||||
override fun openMainView() {
|
||||
activity?.let {
|
||||
startActivity(MainActivity.getStartIntent(it)
|
||||
.apply { addFlags(FLAG_ACTIVITY_CLEAR_TASK or FLAG_ACTIVITY_NEW_TASK) })
|
||||
}
|
||||
activity?.let { startActivity(MainActivity.getStartIntent(context = it, clear = true)) }
|
||||
}
|
||||
|
||||
override fun showProgress(show: Boolean) {
|
||||
|
@ -2,6 +2,7 @@ package io.github.wulkanowy.ui.modules.luckynumberwidget
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.app.PendingIntent
|
||||
import android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetManager.ACTION_APPWIDGET_DELETED
|
||||
import android.appwidget.AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED
|
||||
@ -26,8 +27,7 @@ import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository
|
||||
import io.github.wulkanowy.data.repositories.semester.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity.Companion.EXTRA_START_MENU
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.main.MainView.MenuView
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.reactivex.Maybe
|
||||
import timber.log.Timber
|
||||
@ -74,9 +74,8 @@ class LuckyNumberWidgetProvider : BroadcastReceiver() {
|
||||
getLuckyNumber(sharedPref.getLong(getStudentWidgetKey(appWidgetId), 0), appWidgetId)?.luckyNumber?.toString() ?: "#"
|
||||
)
|
||||
setOnClickPendingIntent(R.id.luckyNumberWidgetContainer,
|
||||
PendingIntent.getActivity(context, MainView.MenuView.LUCKY_NUMBER.id, MainActivity.getStartIntent(context).apply {
|
||||
putExtra(EXTRA_START_MENU, MainView.MenuView.LUCKY_NUMBER)
|
||||
}, PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
PendingIntent.getActivity(context, MenuView.LUCKY_NUMBER.id,
|
||||
MainActivity.getStartIntent(context, MenuView.LUCKY_NUMBER, true), FLAG_UPDATE_CURRENT))
|
||||
}.also {
|
||||
setStyles(it, intent)
|
||||
appWidgetManager.updateAppWidget(appWidgetId, it)
|
||||
|
@ -46,7 +46,13 @@ class MainActivity : BaseActivity(), MainView {
|
||||
companion object {
|
||||
const val EXTRA_START_MENU = "extraStartMenu"
|
||||
|
||||
fun getStartIntent(context: Context) = Intent(context, MainActivity::class.java)
|
||||
fun getStartIntent(context: Context, startMenu: MainView.MenuView? = null, clear: Boolean = false): Intent {
|
||||
return Intent(context, MainActivity::class.java)
|
||||
.apply {
|
||||
if (clear) flags = FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK
|
||||
startMenu?.let { putExtra(EXTRA_START_MENU, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override val isRootView: Boolean
|
||||
@ -91,7 +97,7 @@ class MainActivity : BaseActivity(), MainView {
|
||||
override fun initView() {
|
||||
mainBottomNav.run {
|
||||
addItems(
|
||||
mutableListOf(
|
||||
listOf(
|
||||
AHBottomNavigationItem(R.string.grade_title, R.drawable.ic_menu_main_grade_26dp, 0),
|
||||
AHBottomNavigationItem(R.string.attendance_title, R.drawable.ic_menu_main_attendance_24dp, 0),
|
||||
AHBottomNavigationItem(R.string.exam_title, R.drawable.ic_menu_main_exam_24dp, 0),
|
||||
@ -188,6 +194,7 @@ class MainActivity : BaseActivity(), MainView {
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
navController.onSaveInstanceState(outState)
|
||||
intent.removeExtra(EXTRA_START_MENU)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -25,7 +25,6 @@ class SplashActivity : BaseActivity(), SplashView {
|
||||
|
||||
override fun openMainView() {
|
||||
startActivity(MainActivity.getStartIntent(this))
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun showError(text: String, error: Throwable) {
|
||||
|
@ -20,8 +20,7 @@ import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.student.StudentRepository
|
||||
import io.github.wulkanowy.services.widgets.TimetableWidgetService
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity
|
||||
import io.github.wulkanowy.ui.modules.main.MainActivity.Companion.EXTRA_START_MENU
|
||||
import io.github.wulkanowy.ui.modules.main.MainView
|
||||
import io.github.wulkanowy.ui.modules.main.MainView.MenuView
|
||||
import io.github.wulkanowy.utils.FirebaseAnalyticsHelper
|
||||
import io.github.wulkanowy.utils.SchedulersProvider
|
||||
import io.github.wulkanowy.utils.nextOrSameSchoolDay
|
||||
@ -131,9 +130,8 @@ class TimetableWidgetProvider : BroadcastReceiver() {
|
||||
putExtra(EXTRA_FROM_PROVIDER, true)
|
||||
}, FLAG_UPDATE_CURRENT))
|
||||
setPendingIntentTemplate(R.id.timetableWidgetList,
|
||||
PendingIntent.getActivity(context, 1, MainActivity.getStartIntent(context).apply {
|
||||
putExtra(EXTRA_START_MENU, MainView.MenuView.TIMETABLE)
|
||||
}, FLAG_UPDATE_CURRENT))
|
||||
PendingIntent.getActivity(context, MenuView.TIMETABLE.id,
|
||||
MainActivity.getStartIntent(context, MenuView.TIMETABLE, true), FLAG_UPDATE_CURRENT))
|
||||
}.also {
|
||||
sharedPref.putLong(getDateWidgetKey(appWidgetId), date.toEpochDay(), true)
|
||||
appWidgetManager.apply {
|
||||
|
Loading…
Reference in New Issue
Block a user