forked from github/wulkanowy-mirror
Fix crash in message preview (#762)
This commit is contained in:
parent
0a18fefb1f
commit
299345b864
@ -22,6 +22,9 @@ interface StudentDao {
|
|||||||
@Query("SELECT * FROM Students WHERE is_current = 1")
|
@Query("SELECT * FROM Students WHERE is_current = 1")
|
||||||
fun loadCurrent(): Maybe<Student>
|
fun loadCurrent(): Maybe<Student>
|
||||||
|
|
||||||
|
@Query("SELECT * FROM Students WHERE id = :id")
|
||||||
|
fun loadById(id: Int): Maybe<Student>
|
||||||
|
|
||||||
@Query("SELECT * FROM Students")
|
@Query("SELECT * FROM Students")
|
||||||
fun loadAll(): Maybe<List<Student>>
|
fun loadAll(): Maybe<List<Student>>
|
||||||
|
|
||||||
|
@ -33,6 +33,14 @@ class StudentLocal @Inject constructor(
|
|||||||
.filter { it.isNotEmpty() }
|
.filter { it.isNotEmpty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getStudentById(id: Int): Maybe<Student> {
|
||||||
|
return studentDb.loadById(id).map {
|
||||||
|
it.apply {
|
||||||
|
if (Sdk.Mode.valueOf(loginMode) != Sdk.Mode.API) password = decrypt(password)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getCurrentStudent(decryptPass: Boolean): Maybe<Student> {
|
fun getCurrentStudent(decryptPass: Boolean): Maybe<Student> {
|
||||||
return studentDb.loadCurrent().map {
|
return studentDb.loadCurrent().map {
|
||||||
it.apply {
|
it.apply {
|
||||||
|
@ -47,6 +47,12 @@ class StudentRepository @Inject constructor(
|
|||||||
return local.getStudents(decryptPass).toSingle(emptyList())
|
return local.getStudents(decryptPass).toSingle(emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getStudentById(id: Int): Single<Student> {
|
||||||
|
return local.getStudentById(id)
|
||||||
|
.switchIfEmpty(Maybe.error(NoCurrentStudentException()))
|
||||||
|
.toSingle()
|
||||||
|
}
|
||||||
|
|
||||||
fun getCurrentStudent(decryptPass: Boolean = true): Single<Student> {
|
fun getCurrentStudent(decryptPass: Boolean = true): Single<Student> {
|
||||||
return local.getCurrentStudent(decryptPass)
|
return local.getCurrentStudent(decryptPass)
|
||||||
.switchIfEmpty(Maybe.error(NoCurrentStudentException()))
|
.switchIfEmpty(Maybe.error(NoCurrentStudentException()))
|
||||||
|
@ -63,7 +63,7 @@ class MessagePreviewFragment : BaseFragment(), MessagePreviewView, MainView.Titl
|
|||||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||||
super.onActivityCreated(savedInstanceState)
|
super.onActivityCreated(savedInstanceState)
|
||||||
messageContainer = messagePreviewContainer
|
messageContainer = messagePreviewContainer
|
||||||
presenter.onAttachView(this, (savedInstanceState ?: arguments)?.getSerializable(MESSAGE_ID_KEY) as Message)
|
presenter.onAttachView(this, (savedInstanceState ?: arguments)?.getSerializable(MESSAGE_ID_KEY) as? Message)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initView() {
|
override fun initView() {
|
||||||
@ -150,8 +150,8 @@ class MessagePreviewFragment : BaseFragment(), MessagePreviewView, MainView.Titl
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
|
||||||
outState.putSerializable(MESSAGE_ID_KEY, presenter.message)
|
outState.putSerializable(MESSAGE_ID_KEY, presenter.message)
|
||||||
|
super.onSaveInstanceState(outState)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
|
@ -24,11 +24,12 @@ class MessagePreviewPresenter @Inject constructor(
|
|||||||
|
|
||||||
private var retryCallback: () -> Unit = {}
|
private var retryCallback: () -> Unit = {}
|
||||||
|
|
||||||
fun onAttachView(view: MessagePreviewView, message: Message) {
|
fun onAttachView(view: MessagePreviewView, message: Message?) {
|
||||||
super.onAttachView(view)
|
super.onAttachView(view)
|
||||||
view.initView()
|
view.initView()
|
||||||
errorHandler.showErrorMessage = ::showErrorViewOnError
|
errorHandler.showErrorMessage = ::showErrorViewOnError
|
||||||
loadData(message)
|
this.message = message
|
||||||
|
loadData(requireNotNull(message))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onMessageLoadRetry(message: Message) {
|
private fun onMessageLoadRetry(message: Message) {
|
||||||
@ -47,7 +48,7 @@ class MessagePreviewPresenter @Inject constructor(
|
|||||||
Timber.i("Loading message ${message.messageId} preview started")
|
Timber.i("Loading message ${message.messageId} preview started")
|
||||||
disposable.apply {
|
disposable.apply {
|
||||||
clear()
|
clear()
|
||||||
add(studentRepository.getCurrentStudent()
|
add(studentRepository.getStudentById(message.studentId)
|
||||||
.flatMap { messageRepository.getMessage(it, message, true) }
|
.flatMap { messageRepository.getMessage(it, message, true) }
|
||||||
.subscribeOn(schedulers.backgroundThread)
|
.subscribeOn(schedulers.backgroundThread)
|
||||||
.observeOn(schedulers.mainThread)
|
.observeOn(schedulers.mainThread)
|
||||||
|
@ -18,7 +18,7 @@ class DebugLogTree : Timber.DebugTree() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Bundle?.checkSavedState() = if (this == null) "(STATE IS NULL)" else ""
|
private fun Bundle?.checkSavedState() = if (this == null) "(STATE IS NULL)" else "(STATE IS NOT NULL)"
|
||||||
|
|
||||||
class ActivityLifecycleLogger : Application.ActivityLifecycleCallbacks {
|
class ActivityLifecycleLogger : Application.ActivityLifecycleCallbacks {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user