mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[Homework] Fix homework list sorting.
This commit is contained in:
parent
1b2bdc0580
commit
0fc6f07986
@ -9,12 +9,10 @@ import androidx.lifecycle.Observer
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.MainActivity
|
import pl.szczodrzynski.edziennik.MainActivity
|
||||||
import pl.szczodrzynski.edziennik.R
|
|
||||||
import pl.szczodrzynski.edziennik.databinding.HomeworkListBinding
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
import pl.szczodrzynski.edziennik.data.db.entity.Event
|
||||||
|
import pl.szczodrzynski.edziennik.databinding.HomeworkListBinding
|
||||||
import pl.szczodrzynski.edziennik.getInt
|
import pl.szczodrzynski.edziennik.getInt
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.Themes
|
|
||||||
|
|
||||||
class HomeworkListFragment : Fragment() {
|
class HomeworkListFragment : Fragment() {
|
||||||
|
|
||||||
@ -26,20 +24,15 @@ class HomeworkListFragment : Fragment() {
|
|||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
activity = (getActivity() as MainActivity?) ?: return null
|
activity = (getActivity() as MainActivity?) ?: return null
|
||||||
if (context == null)
|
context ?: return null
|
||||||
return null
|
|
||||||
app = activity.application as App
|
app = activity.application as App
|
||||||
context!!.theme.applyStyle(Themes.appTheme, true)
|
|
||||||
if (app.profile == null)
|
|
||||||
return inflater.inflate(R.layout.fragment_loading, container, false)
|
|
||||||
// activity, context and profile is valid
|
|
||||||
b = HomeworkListBinding.inflate(inflater)
|
b = HomeworkListBinding.inflate(inflater)
|
||||||
return b.root
|
return b.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
// TODO check if app, activity, b can be null
|
// TODO check if app, activity, b can be null
|
||||||
if (app.profile == null || !isAdded)
|
if (!isAdded)
|
||||||
return
|
return
|
||||||
|
|
||||||
if (arguments != null) {
|
if (arguments != null) {
|
||||||
@ -47,21 +40,21 @@ class HomeworkListFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val layoutManager = LinearLayoutManager(context)
|
val layoutManager = LinearLayoutManager(context)
|
||||||
layoutManager.reverseLayout = true
|
layoutManager.reverseLayout = homeworkDate == HomeworkDate.PAST
|
||||||
layoutManager.stackFromEnd = true
|
layoutManager.stackFromEnd = homeworkDate == HomeworkDate.PAST
|
||||||
|
|
||||||
b.homeworkView.setHasFixedSize(true)
|
b.homeworkView.setHasFixedSize(true)
|
||||||
b.homeworkView.layoutManager = layoutManager
|
b.homeworkView.layoutManager = layoutManager
|
||||||
|
|
||||||
val filter = when(homeworkDate) {
|
val filter = when(homeworkDate) {
|
||||||
HomeworkDate.CURRENT -> "eventDate > '" + Date.getToday().stringY_m_d + "'"
|
HomeworkDate.CURRENT -> "eventDate >= '" + Date.getToday().stringY_m_d + "'"
|
||||||
else -> "eventDate <= '" + Date.getToday().stringY_m_d + "'"
|
else -> "eventDate < '" + Date.getToday().stringY_m_d + "'"
|
||||||
}
|
}
|
||||||
|
|
||||||
app.db.eventDao()
|
app.db.eventDao()
|
||||||
.getAllByType(App.profileId, Event.TYPE_HOMEWORK, filter)
|
.getAllByType(App.profileId, Event.TYPE_HOMEWORK, filter)
|
||||||
.observe(this, Observer { homeworkList ->
|
.observe(this, Observer { homeworkList ->
|
||||||
if (app.profile == null || !isAdded) return@Observer
|
if (!isAdded) return@Observer
|
||||||
|
|
||||||
if (homeworkList != null && homeworkList.size > 0) {
|
if (homeworkList != null && homeworkList.size > 0) {
|
||||||
val adapter = HomeworkAdapter(context, homeworkList)
|
val adapter = HomeworkAdapter(context, homeworkList)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user