forked from github/wulkanowy-mirror
Fix saved state in main and splash activity (#1633)
This commit is contained in:
parent
8a181c747c
commit
7e0e2fbb67
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import android.util.Log.DEBUG
|
||||
import android.util.Log.INFO
|
||||
@ -40,7 +39,6 @@ class WulkanowyApp : Application(), Configuration.Provider {
|
||||
@Inject
|
||||
lateinit var analyticsHelper: AnalyticsHelper
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageWarning")
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
initializeAppLanguage()
|
||||
|
@ -138,7 +138,7 @@ class TimetableNotificationReceiver : HiltBroadcastReceiver() {
|
||||
PendingIntent.getActivity(
|
||||
context,
|
||||
NOTIFICATION_ID,
|
||||
SplashActivity.getStartIntent(context, Destination.Timetable(), true),
|
||||
SplashActivity.getStartIntent(context, Destination.Timetable()),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
|
||||
)
|
||||
)
|
||||
|
@ -35,7 +35,7 @@ class ShortcutsHelper @Inject constructor(@ApplicationContext private val contex
|
||||
.setShortLabel(context.getString(R.string.grade_title))
|
||||
.setLongLabel(context.getString(R.string.grade_title))
|
||||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_shortcut_grade))
|
||||
.setIntent(SplashActivity.getStartIntent(context, startNewTask = true)
|
||||
.setIntent(SplashActivity.getStartIntent(context)
|
||||
.apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
putExtra(EXTRA_SHORTCUT_DESTINATION_ID, "grade")
|
||||
@ -47,7 +47,7 @@ class ShortcutsHelper @Inject constructor(@ApplicationContext private val contex
|
||||
.setShortLabel(context.getString(R.string.attendance_title))
|
||||
.setLongLabel(context.getString(R.string.attendance_title))
|
||||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_shortcut_attendance))
|
||||
.setIntent(SplashActivity.getStartIntent(context, startNewTask = true)
|
||||
.setIntent(SplashActivity.getStartIntent(context)
|
||||
.apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
putExtra(EXTRA_SHORTCUT_DESTINATION_ID, "attendance")
|
||||
@ -59,7 +59,7 @@ class ShortcutsHelper @Inject constructor(@ApplicationContext private val contex
|
||||
.setShortLabel(context.getString(R.string.exam_title))
|
||||
.setLongLabel(context.getString(R.string.exam_title))
|
||||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_shortcut_exam))
|
||||
.setIntent(SplashActivity.getStartIntent(context, startNewTask = true)
|
||||
.setIntent(SplashActivity.getStartIntent(context)
|
||||
.apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
putExtra(EXTRA_SHORTCUT_DESTINATION_ID, "exam")
|
||||
@ -71,7 +71,7 @@ class ShortcutsHelper @Inject constructor(@ApplicationContext private val contex
|
||||
.setShortLabel(context.getString(R.string.timetable_title))
|
||||
.setLongLabel(context.getString(R.string.timetable_title))
|
||||
.setIcon(IconCompat.createWithResource(context, R.drawable.ic_shortcut_timetable))
|
||||
.setIntent(SplashActivity.getStartIntent(context, startNewTask = true)
|
||||
.setIntent(SplashActivity.getStartIntent(context)
|
||||
.apply {
|
||||
action = Intent.ACTION_VIEW
|
||||
putExtra(EXTRA_SHORTCUT_DESTINATION_ID, "timetable")
|
||||
|
@ -34,8 +34,7 @@ class ChangeTimetableNotification @Inject constructor(
|
||||
content = it,
|
||||
intentToStart = SplashActivity.getStartIntent(
|
||||
context = context,
|
||||
destination = Destination.Timetable(date),
|
||||
startNewTask = true
|
||||
destination = Destination.Timetable(date)
|
||||
)
|
||||
)
|
||||
}
|
||||
@ -54,7 +53,7 @@ class ChangeTimetableNotification @Inject constructor(
|
||||
changedLessons.size,
|
||||
changedLessons.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Timetable(), true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Timetable()),
|
||||
type = NotificationType.CHANGE_TIMETABLE
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class NewAttendanceNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.attendance_notify_new_items_title, 1),
|
||||
content = it,
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Attendance, true)
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Attendance)
|
||||
)
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ class NewAttendanceNotification @Inject constructor(
|
||||
notificationDataList.size,
|
||||
notificationDataList.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Attendance, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Attendance),
|
||||
type = NotificationType.NEW_ATTENDANCE
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class NewConferenceNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.conference_notify_new_item_title, 1),
|
||||
content = it,
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Conference, true)
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Conference)
|
||||
)
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class NewConferenceNotification @Inject constructor(
|
||||
lines.size,
|
||||
lines.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Conference, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Conference),
|
||||
type = NotificationType.NEW_CONFERENCE
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class NewExamNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.exam_notify_new_item_title, 1),
|
||||
content = it,
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Exam, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Exam),
|
||||
)
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ class NewExamNotification @Inject constructor(
|
||||
lines.size,
|
||||
lines.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Exam, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Exam),
|
||||
type = NotificationType.NEW_EXAM
|
||||
)
|
||||
|
||||
|
@ -23,7 +23,7 @@ class NewGradeNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.grade_new_items, 1),
|
||||
content = "${it.subject}: ${it.entry}",
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade),
|
||||
)
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ class NewGradeNotification @Inject constructor(
|
||||
notificationDataList = notificationDataList,
|
||||
title = context.getPlural(R.plurals.grade_new_items, items.size),
|
||||
content = context.getPlural(R.plurals.grade_notify_new_items, items.size, items.size),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade),
|
||||
type = NotificationType.NEW_GRADE_DETAILS
|
||||
)
|
||||
|
||||
@ -43,7 +43,7 @@ class NewGradeNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.grade_new_items_predicted, 1),
|
||||
content = "${it.subject}: ${it.predictedGrade}",
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade),
|
||||
)
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ class NewGradeNotification @Inject constructor(
|
||||
items.size,
|
||||
items.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade),
|
||||
type = NotificationType.NEW_GRADE_PREDICTED
|
||||
)
|
||||
|
||||
@ -67,7 +67,7 @@ class NewGradeNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.grade_new_items_final, 1),
|
||||
content = "${it.subject}: ${it.finalGrade}",
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade),
|
||||
)
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ class NewGradeNotification @Inject constructor(
|
||||
items.size,
|
||||
items.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Grade),
|
||||
type = NotificationType.NEW_GRADE_FINAL
|
||||
)
|
||||
|
||||
|
@ -31,7 +31,7 @@ class NewHomeworkNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.homework_notify_new_item_title, 1),
|
||||
content = it,
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Homework, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Homework),
|
||||
)
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ class NewHomeworkNotification @Inject constructor(
|
||||
lines.size,
|
||||
lines.size
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Homework, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Homework),
|
||||
type = NotificationType.NEW_HOMEWORK,
|
||||
notificationDataList = notificationDataList
|
||||
)
|
||||
|
@ -22,7 +22,7 @@ class NewLuckyNumberNotification @Inject constructor(
|
||||
R.string.lucky_number_notify_new_item,
|
||||
item.luckyNumber.toString()
|
||||
),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.LuckyNumber, true)
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.LuckyNumber)
|
||||
)
|
||||
|
||||
appNotificationManager.sendSingleNotification(
|
||||
|
@ -22,7 +22,7 @@ class NewMessageNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(R.plurals.message_new_items, 1),
|
||||
content = "${it.sender}: ${it.subject}",
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Message, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Message),
|
||||
)
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ class NewMessageNotification @Inject constructor(
|
||||
notificationDataList = notificationDataList,
|
||||
title = context.getPlural(R.plurals.message_new_items, items.size),
|
||||
content = context.getPlural(R.plurals.message_notify_new_items, items.size, items.size),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Message, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Message),
|
||||
type = NotificationType.NEW_MESSAGE
|
||||
)
|
||||
|
||||
|
@ -29,13 +29,13 @@ class NewNoteNotification @Inject constructor(
|
||||
NotificationData(
|
||||
title = context.getPlural(titleRes, 1),
|
||||
content = "${it.teacher}: ${it.category}",
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Note, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Note),
|
||||
)
|
||||
}
|
||||
|
||||
val groupNotificationData = GroupNotificationData(
|
||||
notificationDataList = notificationDataList,
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Note, true),
|
||||
intentToStart = SplashActivity.getStartIntent(context, Destination.Note),
|
||||
title = context.getPlural(R.plurals.note_new_items, items.size),
|
||||
content = context.getPlural(R.plurals.note_notify_new_items, items.size, items.size),
|
||||
type = NotificationType.NEW_NOTE
|
||||
|
@ -22,8 +22,7 @@ class NewSchoolAnnouncementNotification @Inject constructor(
|
||||
NotificationData(
|
||||
intentToStart = SplashActivity.getStartIntent(
|
||||
context = context,
|
||||
destination = Destination.SchoolAnnouncement,
|
||||
startNewTask = true
|
||||
destination = Destination.SchoolAnnouncement
|
||||
),
|
||||
title = context.getPlural(
|
||||
R.plurals.school_announcement_notify_new_item_title,
|
||||
@ -36,8 +35,7 @@ class NewSchoolAnnouncementNotification @Inject constructor(
|
||||
type = NotificationType.NEW_ANNOUNCEMENT,
|
||||
intentToStart = SplashActivity.getStartIntent(
|
||||
context = context,
|
||||
destination = Destination.SchoolAnnouncement,
|
||||
startNewTask = true
|
||||
destination = Destination.SchoolAnnouncement
|
||||
),
|
||||
title = context.getPlural(
|
||||
R.plurals.school_announcement_notify_new_item_title,
|
||||
|
@ -20,7 +20,7 @@ open class BasePresenter<T : BaseView>(
|
||||
) {
|
||||
private val job = SupervisorJob()
|
||||
|
||||
protected val presenterScope = CoroutineScope(job + Dispatchers.Main.immediate)
|
||||
protected val presenterScope = CoroutineScope(job + Dispatchers.Main)
|
||||
|
||||
private val childrenJobs = mutableMapOf<String, Job>()
|
||||
|
||||
|
@ -62,7 +62,7 @@ class LuckyNumberWidgetProvider : AppWidgetProvider() {
|
||||
val appIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
LUCKY_NUMBER_PENDING_INTENT_ID,
|
||||
SplashActivity.getStartIntent(context, Destination.LuckyNumber, true),
|
||||
SplashActivity.getStartIntent(context, Destination.LuckyNumber),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package io.github.wulkanowy.ui.modules.main
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build.VERSION_CODES.P
|
||||
@ -88,7 +87,6 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
|
||||
private var savedInstanceState: Bundle? = null
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(ActivityMainBinding.inflate(layoutInflater).apply { binding = this }.root)
|
||||
@ -97,7 +95,8 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
messageContainer = binding.mainMessageContainer
|
||||
updateHelper.messageContainer = binding.mainFragmentContainer
|
||||
|
||||
val destination = intent.getSerializableExtra(EXTRA_START_DESTINATION) as Destination?
|
||||
val destination = (intent.getSerializableExtra(EXTRA_START_DESTINATION) as Destination?)
|
||||
?.takeIf { savedInstanceState == null }
|
||||
|
||||
presenter.onAttachView(this, destination)
|
||||
updateHelper.checkAndInstallUpdates(this)
|
||||
@ -143,6 +142,7 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
|
||||
initialize(startMenuIndex, savedInstanceState)
|
||||
}
|
||||
savedInstanceState = null
|
||||
}
|
||||
|
||||
private fun initializeToolbar() {
|
||||
@ -292,6 +292,5 @@ class MainActivity : BaseActivity<MainPresenter, ActivityMainBinding>(), MainVie
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
navController.onSaveInstanceState(outState)
|
||||
intent.removeExtra(EXTRA_START_DESTINATION)
|
||||
}
|
||||
}
|
||||
|
@ -33,17 +33,11 @@ class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView
|
||||
|
||||
private const val EXTRA_EXTERNAL_URL = "external_url"
|
||||
|
||||
fun getStartIntent(
|
||||
context: Context,
|
||||
destination: Destination? = null,
|
||||
startNewTask: Boolean = false
|
||||
) = Intent(context, SplashActivity::class.java).apply {
|
||||
putExtra(EXTRA_START_DESTINATION, destination)
|
||||
|
||||
if (startNewTask) {
|
||||
fun getStartIntent(context: Context, destination: Destination? = null) =
|
||||
Intent(context, SplashActivity::class.java).apply {
|
||||
putExtra(EXTRA_START_DESTINATION, destination)
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
@ -179,7 +179,7 @@ class TimetableWidgetProvider : HiltBroadcastReceiver() {
|
||||
val appIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
TIMETABLE_PENDING_INTENT_ID,
|
||||
SplashActivity.getStartIntent(context, Destination.Timetable(), true),
|
||||
SplashActivity.getStartIntent(context, Destination.Timetable()),
|
||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntentCompat.FLAG_IMMUTABLE
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user