diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementAdapter.kt index e7c202676..62f6251ec 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementAdapter.kt @@ -2,7 +2,7 @@ package io.github.wulkanowy.ui.modules.schoolannouncement import android.view.LayoutInflater import android.view.ViewGroup -import androidx.core.text.HtmlCompat +import androidx.core.text.parseAsHtml import androidx.recyclerview.widget.RecyclerView import io.github.wulkanowy.data.db.entities.SchoolAnnouncement import io.github.wulkanowy.databinding.ItemSchoolAnnouncementBinding @@ -14,6 +14,8 @@ class SchoolAnnouncementAdapter @Inject constructor() : var items = emptyList() + var onItemClickListener: (SchoolAnnouncement) -> Unit = {} + override fun getItemCount() = items.size override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( @@ -26,9 +28,9 @@ class SchoolAnnouncementAdapter @Inject constructor() : with(holder.binding) { schoolAnnouncementItemDate.text = item.date.toFormattedString() schoolAnnouncementItemType.text = item.subject - schoolAnnouncementItemContent.text = HtmlCompat.fromHtml( - item.content, HtmlCompat.FROM_HTML_MODE_COMPACT - ) + schoolAnnouncementItemContent.text = item.content.parseAsHtml() + + root.setOnClickListener { onItemClickListener(item) } } } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementDialog.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementDialog.kt new file mode 100644 index 000000000..ed4b0ac98 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementDialog.kt @@ -0,0 +1,54 @@ +package io.github.wulkanowy.ui.modules.schoolannouncement + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.core.text.parseAsHtml +import androidx.fragment.app.DialogFragment +import io.github.wulkanowy.data.db.entities.SchoolAnnouncement +import io.github.wulkanowy.databinding.DialogSchoolAnnouncementBinding +import io.github.wulkanowy.utils.lifecycleAwareVariable +import io.github.wulkanowy.utils.toFormattedString + +class SchoolAnnouncementDialog : DialogFragment() { + + private var binding: DialogSchoolAnnouncementBinding by lifecycleAwareVariable() + + private lateinit var announcement: SchoolAnnouncement + + companion object { + + private const val ARGUMENT_KEY = "item" + + fun newInstance(exam: SchoolAnnouncement) = SchoolAnnouncementDialog().apply { + arguments = Bundle().apply { putSerializable(ARGUMENT_KEY, exam) } + } + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setStyle(STYLE_NO_TITLE, 0) + arguments?.run { + announcement = getSerializable(ARGUMENT_KEY) as SchoolAnnouncement + } + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ) = DialogSchoolAnnouncementBinding.inflate(inflater).apply { binding = this }.root + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + with(binding) { + announcementDialogSubjectValue.text = announcement.subject + announcementDialogDateValue.text = announcement.date.toFormattedString() + announcementDialogDescriptionValue.text = announcement.content.parseAsHtml() + + announcementDialogClose.setOnClickListener { dismiss() } + } + } +} diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementFragment.kt index a5a53aefc..baf2824ba 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementFragment.kt @@ -8,6 +8,7 @@ import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.SchoolAnnouncement import io.github.wulkanowy.databinding.FragmentSchoolAnnouncementBinding import io.github.wulkanowy.ui.base.BaseFragment +import io.github.wulkanowy.ui.modules.main.MainActivity import io.github.wulkanowy.ui.modules.main.MainView import io.github.wulkanowy.ui.widgets.DividerItemDecoration import io.github.wulkanowy.utils.getThemeAttrColor @@ -43,7 +44,9 @@ class SchoolAnnouncementFragment : override fun initView() { with(binding.directorInformationRecycler) { layoutManager = LinearLayoutManager(context) - adapter = schoolAnnouncementAdapter + adapter = schoolAnnouncementAdapter.apply { + onItemClickListener = presenter::onItemClickListener + } addItemDecoration(DividerItemDecoration(context)) } with(binding) { @@ -99,6 +102,10 @@ class SchoolAnnouncementFragment : binding.directorInformationSwipe.isRefreshing = show } + override fun openSchoolAnnouncementDialog(item: SchoolAnnouncement) { + (activity as? MainActivity)?.showDialogFragment(SchoolAnnouncementDialog.newInstance(item)) + } + override fun onDestroyView() { presenter.onDetachView() super.onDestroyView() diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementPresenter.kt index ba89ab1f4..88ad81465 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementPresenter.kt @@ -1,6 +1,7 @@ package io.github.wulkanowy.ui.modules.schoolannouncement import io.github.wulkanowy.data.Status +import io.github.wulkanowy.data.db.entities.SchoolAnnouncement import io.github.wulkanowy.data.repositories.SchoolAnnouncementRepository import io.github.wulkanowy.data.repositories.StudentRepository import io.github.wulkanowy.ui.base.BasePresenter @@ -46,6 +47,10 @@ class SchoolAnnouncementPresenter @Inject constructor( view?.showErrorDetailsDialog(lastError) } + fun onItemClickListener(item: SchoolAnnouncement) { + view?.openSchoolAnnouncementDialog(item) + } + private fun loadData(forceRefresh: Boolean = false) { Timber.i("Loading School announcement data started") diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementView.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementView.kt index 0553df1e7..383d0f294 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementView.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/schoolannouncement/SchoolAnnouncementView.kt @@ -19,6 +19,8 @@ interface SchoolAnnouncementView : BaseView { fun setErrorDetails(message: String) + fun openSchoolAnnouncementDialog(item: SchoolAnnouncement) + fun showProgress(show: Boolean) fun enableSwipe(enable: Boolean) 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 a79661901..1e1084a8d 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 @@ -7,7 +7,7 @@ import android.view.MenuItem import android.view.View import android.view.View.GONE import android.view.View.VISIBLE -import androidx.core.text.HtmlCompat +import androidx.core.text.parseAsHtml import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.datepicker.CalendarConstraints import com.google.android.material.datepicker.MaterialDatePicker @@ -147,9 +147,7 @@ class TimetableFragment : BaseFragment(R.layout.fragme override fun setDayHeaderMessage(message: String?) { binding.timetableEmptyMessage.visibility = if (message.isNullOrEmpty()) GONE else VISIBLE - binding.timetableEmptyMessage.text = HtmlCompat.fromHtml( - message.orEmpty(), HtmlCompat.FROM_HTML_MODE_COMPACT - ) + binding.timetableEmptyMessage.text = message.orEmpty().parseAsHtml() } override fun showErrorView(show: Boolean) { diff --git a/app/src/main/res/layout/dialog_school_announcement.xml b/app/src/main/res/layout/dialog_school_announcement.xml new file mode 100644 index 000000000..cbce4e025 --- /dev/null +++ b/app/src/main/res/layout/dialog_school_announcement.xml @@ -0,0 +1,148 @@ + + + + + + + + + + + + + + + + + + + + + + + +