forked from github/szkolny
[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 pl.szczodrzynski.edziennik.App
|
||||
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.databinding.HomeworkListBinding
|
||||
import pl.szczodrzynski.edziennik.getInt
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.Themes
|
||||
|
||||
class HomeworkListFragment : Fragment() {
|
||||
|
||||
@ -26,20 +24,15 @@ class HomeworkListFragment : Fragment() {
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
activity = (getActivity() as MainActivity?) ?: return null
|
||||
if (context == null)
|
||||
return null
|
||||
context ?: return null
|
||||
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)
|
||||
return b.root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
// TODO check if app, activity, b can be null
|
||||
if (app.profile == null || !isAdded)
|
||||
if (!isAdded)
|
||||
return
|
||||
|
||||
if (arguments != null) {
|
||||
@ -47,21 +40,21 @@ class HomeworkListFragment : Fragment() {
|
||||
}
|
||||
|
||||
val layoutManager = LinearLayoutManager(context)
|
||||
layoutManager.reverseLayout = true
|
||||
layoutManager.stackFromEnd = true
|
||||
layoutManager.reverseLayout = homeworkDate == HomeworkDate.PAST
|
||||
layoutManager.stackFromEnd = homeworkDate == HomeworkDate.PAST
|
||||
|
||||
b.homeworkView.setHasFixedSize(true)
|
||||
b.homeworkView.layoutManager = layoutManager
|
||||
|
||||
val filter = when(homeworkDate) {
|
||||
HomeworkDate.CURRENT -> "eventDate > '" + Date.getToday().stringY_m_d + "'"
|
||||
else -> "eventDate <= '" + Date.getToday().stringY_m_d + "'"
|
||||
HomeworkDate.CURRENT -> "eventDate >= '" + Date.getToday().stringY_m_d + "'"
|
||||
else -> "eventDate < '" + Date.getToday().stringY_m_d + "'"
|
||||
}
|
||||
|
||||
app.db.eventDao()
|
||||
.getAllByType(App.profileId, Event.TYPE_HOMEWORK, filter)
|
||||
.observe(this, Observer { homeworkList ->
|
||||
if (app.profile == null || !isAdded) return@Observer
|
||||
if (!isAdded) return@Observer
|
||||
|
||||
if (homeworkList != null && homeworkList.size > 0) {
|
||||
val adapter = HomeworkAdapter(context, homeworkList)
|
||||
|
Loading…
Reference in New Issue
Block a user