From 840b21a21350d639d9871a31682a7b97bf5e205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Sun, 13 Jan 2019 23:25:07 +0100 Subject: [PATCH] Fix dialog state (#214) --- .../wulkanowy/ui/modules/attendance/AttendanceFragment.kt | 2 +- .../java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt | 3 ++- .../ui/modules/grade/details/GradeDetailsFragment.kt | 3 ++- .../github/wulkanowy/ui/modules/homework/HomeworkFragment.kt | 3 ++- .../java/io/github/wulkanowy/ui/modules/main/MainActivity.kt | 5 +++++ .../java/io/github/wulkanowy/ui/modules/note/NoteFragment.kt | 3 ++- .../wulkanowy/ui/modules/timetable/TimetableFragment.kt | 3 ++- 7 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt index 3b60d8cb7..cdbde5075 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/attendance/AttendanceFragment.kt @@ -130,7 +130,7 @@ class AttendanceFragment : BaseSessionFragment(), AttendanceView, MainView.MainC } override fun showAttendanceDialog(lesson: Attendance) { - AttendanceDialog.newInstance(lesson).show(fragmentManager, lesson.toString()) + (activity as? MainActivity)?.showDialogFragment(AttendanceDialog.newInstance(lesson)) } override fun openSummaryView() { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt index d39688d4f..dcafeb2ee 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/exam/ExamFragment.kt @@ -13,6 +13,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Exam import io.github.wulkanowy.ui.base.session.BaseSessionFragment +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.utils.setOnItemClickListener import kotlinx.android.synthetic.main.fragment_exam.* @@ -106,7 +107,7 @@ class ExamFragment : BaseSessionFragment(), ExamView, MainView.MainChildView, Ma } override fun showExamDialog(exam: Exam) { - ExamDialog.newInstance(exam).show(fragmentManager, exam.toString()) + (activity as? MainActivity)?.showDialogFragment(ExamDialog.newInstance(exam)) } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt index e1bc1e9b2..01b18f4ba 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsFragment.kt @@ -20,6 +20,7 @@ import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.ui.base.session.BaseSessionFragment import io.github.wulkanowy.ui.modules.grade.GradeFragment import io.github.wulkanowy.ui.modules.grade.GradeView +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.utils.setOnItemClickListener import kotlinx.android.synthetic.main.fragment_grade_details.* import javax.inject.Inject @@ -131,7 +132,7 @@ class GradeDetailsFragment : BaseSessionFragment(), GradeDetailsView, GradeView. } override fun showGradeDialog(grade: Grade) { - GradeDetailsDialog.newInstance(grade).show(fragmentManager, grade.toString()) + (activity as? MainActivity)?.showDialogFragment(GradeDetailsDialog.newInstance(grade)) } override fun onParentLoadData(semesterId: Int, forceRefresh: Boolean) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkFragment.kt index 135098fbd..4d9b74708 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/homework/HomeworkFragment.kt @@ -10,6 +10,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Homework import io.github.wulkanowy.ui.base.session.BaseSessionFragment +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.utils.setOnItemClickListener import kotlinx.android.synthetic.main.fragment_homework.* @@ -95,7 +96,7 @@ class HomeworkFragment : BaseSessionFragment(), HomeworkView, MainView.TitledVie } override fun showTimetableDialog(homework: Homework) { - HomeworkDialog.newInstance(homework).show(fragmentManager, homework.toString()) + (activity as? MainActivity)?.showDialogFragment(HomeworkDialog.newInstance(homework)) } override fun onSaveInstanceState(outState: Bundle) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt index 58c2f7c95..58517302a 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/main/MainActivity.kt @@ -7,6 +7,7 @@ import android.view.Menu import android.view.MenuItem import androidx.appcompat.app.AlertDialog import androidx.core.content.ContextCompat +import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment import com.aurelhubert.ahbottomnavigation.AHBottomNavigation.TitleState.ALWAYS_SHOW import com.aurelhubert.ahbottomnavigation.AHBottomNavigationItem @@ -147,6 +148,10 @@ class MainActivity : BaseActivity(), MainView { (navController.currentStack?.get(0) as? MainView.MainChildView)?.onFragmentReselected() } + fun showDialogFragment(dialog: DialogFragment) { + navController.showDialogFragment(dialog) + } + fun pushView(fragment: Fragment) { navController.pushFragment(fragment) } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteFragment.kt index 243f25757..9ae8f83a2 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/note/NoteFragment.kt @@ -12,6 +12,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Note import io.github.wulkanowy.ui.base.session.BaseSessionFragment +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.utils.setOnItemClickListener import kotlinx.android.synthetic.main.fragment_note.* @@ -57,7 +58,7 @@ class NoteFragment : BaseSessionFragment(), NoteView, MainView.TitledView { } override fun showNoteDialog(note: Note) { - NoteDialog.newInstance(note).show(fragmentManager, note.toString()) + (activity as? MainActivity)?.showDialogFragment(NoteDialog.newInstance(note)) } override fun updateData(data: List) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt index faf17665a..71c2f70ba 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetable/TimetableFragment.kt @@ -10,6 +10,7 @@ import eu.davidea.flexibleadapter.items.AbstractFlexibleItem import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Timetable import io.github.wulkanowy.ui.base.session.BaseSessionFragment +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.utils.setOnItemClickListener import kotlinx.android.synthetic.main.fragment_timetable.* @@ -107,7 +108,7 @@ class TimetableFragment : BaseSessionFragment(), TimetableView, MainView.MainChi } override fun showTimetableDialog(lesson: Timetable) { - TimetableDialog.newInstance(lesson).show(fragmentManager, lesson.toString()) + (activity as? MainActivity)?.showDialogFragment(TimetableDialog.newInstance(lesson)) } override fun onSaveInstanceState(outState: Bundle) {