Replace Serializable to Parcelable in Destination (#1823)

This commit is contained in:
Rafał Borcz 2022-04-06 08:01:41 +02:00 committed by GitHub
parent 679cf2554d
commit cb4ae21903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package io.github.wulkanowy.ui.modules
import android.os.Parcelable
import androidx.fragment.app.Fragment
import io.github.wulkanowy.data.serializers.LocalDateSerializer
import io.github.wulkanowy.ui.modules.attendance.AttendanceFragment
@ -15,11 +16,12 @@ import io.github.wulkanowy.ui.modules.note.NoteFragment
import io.github.wulkanowy.ui.modules.schoolandteachers.school.SchoolFragment
import io.github.wulkanowy.ui.modules.schoolannouncement.SchoolAnnouncementFragment
import io.github.wulkanowy.ui.modules.timetable.TimetableFragment
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
import java.time.LocalDate
@Serializable
sealed class Destination private constructor() : java.io.Serializable {
sealed class Destination private constructor() : Parcelable {
/*
Type in children classes have to be as getter to avoid null in enums
@ -45,30 +47,35 @@ sealed class Destination private constructor() : java.io.Serializable {
MESSAGE(Message);
}
@Parcelize
@Serializable
object Dashboard : Destination() {
override val type get() = Type.DASHBOARD
override val fragment get() = DashboardFragment.newInstance()
}
@Parcelize
@Serializable
object Grade : Destination() {
override val type get() = Type.GRADE
override val fragment get() = GradeFragment.newInstance()
}
@Parcelize
@Serializable
object Attendance : Destination() {
override val type get() = Type.ATTENDANCE
override val fragment get() = AttendanceFragment.newInstance()
}
@Parcelize
@Serializable
object Exam : Destination() {
override val type get() = Type.EXAM
override val fragment get() = ExamFragment.newInstance()
}
@Parcelize
@Serializable
data class Timetable(
@Serializable(with = LocalDateSerializer::class)
@ -78,51 +85,59 @@ sealed class Destination private constructor() : java.io.Serializable {
override val fragment get() = TimetableFragment.newInstance(date)
}
@Parcelize
@Serializable
object Homework : Destination() {
override val type get() = Type.HOMEWORK
override val fragment get() = HomeworkFragment.newInstance()
}
@Parcelize
@Serializable
object Note : Destination() {
override val type get() = Type.NOTE
override val fragment get() = NoteFragment.newInstance()
}
@Parcelize
@Serializable
object Conference : Destination() {
override val type get() = Type.CONFERENCE
override val fragment get() = ConferenceFragment.newInstance()
}
@Parcelize
@Serializable
object SchoolAnnouncement : Destination() {
override val type get() = Type.SCHOOL_ANNOUNCEMENT
override val fragment get() = SchoolAnnouncementFragment.newInstance()
}
@Parcelize
@Serializable
object School : Destination() {
override val type get() = Type.SCHOOL
override val fragment get() = SchoolFragment.newInstance()
}
@Parcelize
@Serializable
object LuckyNumber : Destination() {
override val type get() = Type.LUCKY_NUMBER
override val fragment get() = LuckyNumberFragment.newInstance()
}
@Parcelize
@Serializable
object More : Destination() {
override val type get() = Type.MORE
override val fragment get() = MoreFragment.newInstance()
}
@Parcelize
@Serializable
object Message : Destination() {
override val type get() = Type.MESSAGE
override val fragment get() = MessageFragment.newInstance()
}
}
}

View File

@ -86,7 +86,7 @@ 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.getParcelableExtra(EXTRA_START_DESTINATION) as Destination?)
?.takeIf { savedInstanceState == null }
presenter.onAttachView(this, destination)

View File

@ -45,7 +45,7 @@ class SplashActivity : BaseActivity<SplashPresenter, ViewBinding>(), SplashView
installSplashScreen().setKeepOnScreenCondition { true }
val externalLink = intent?.getStringExtra(EXTRA_EXTERNAL_URL)
val startDestination = intent?.getSerializableExtra(EXTRA_START_DESTINATION) as Destination?
val startDestination = intent?.getParcelableExtra(EXTRA_START_DESTINATION) as Destination?
?: shortcutsHelper.getDestination(intent)
presenter.onAttachView(this, externalLink, startDestination)