Apply filter to meetings list + only show meetings for default account

This commit is contained in:
Sylvain Berfini 2023-10-10 10:43:24 +02:00
parent c952178749
commit b6bdca7b89
8 changed files with 62 additions and 15 deletions

View file

@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import androidx.core.view.doOnPreDraw
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
@ -36,6 +37,7 @@ import org.linphone.ui.main.chat.viewmodel.ConversationViewModel
import org.linphone.ui.main.fragment.GenericFragment
import org.linphone.utils.Event
@UiThread
class ConversationFragment : GenericFragment() {
companion object {
private const val TAG = "[Conversation Fragment]"

View file

@ -25,6 +25,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.annotation.UiThread
import androidx.core.view.doOnPreDraw
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
@ -35,6 +36,7 @@ import org.linphone.databinding.ChatFragmentBinding
import org.linphone.ui.main.fragment.GenericFragment
import org.linphone.utils.SlidingPaneBackPressedCallback
@UiThread
class ConversationsFragment : GenericFragment() {
companion object {
private const val TAG = "[Conversations Fragment]"

View file

@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import org.linphone.R
@ -36,6 +37,7 @@ import org.linphone.utils.Event
import org.linphone.utils.hideKeyboard
import org.linphone.utils.showKeyboard
@UiThread
class ConversationsListFragment : AbstractTopBarFragment() {
companion object {
private const val TAG = "[Conversations List Fragment]"

View file

@ -23,11 +23,13 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import androidx.navigation.fragment.findNavController
import org.linphone.databinding.MeetingFragmentBinding
import org.linphone.ui.main.fragment.GenericFragment
import org.linphone.utils.Event
@UiThread
class MeetingFragment : GenericFragment() {
companion object {
private const val TAG = "[Meeting Fragment]"

View file

@ -25,6 +25,7 @@ import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.annotation.UiThread
import androidx.core.view.doOnPreDraw
import androidx.navigation.findNavController
import androidx.navigation.fragment.findNavController
@ -35,6 +36,7 @@ import org.linphone.databinding.MeetingsFragmentBinding
import org.linphone.ui.main.fragment.GenericFragment
import org.linphone.utils.SlidingPaneBackPressedCallback
@UiThread
class MeetingsFragment : GenericFragment() {
companion object {
private const val TAG = "[Meetings Fragment]"

View file

@ -23,6 +23,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import org.linphone.R
@ -36,6 +37,7 @@ import org.linphone.utils.RecyclerViewHeaderDecoration
import org.linphone.utils.hideKeyboard
import org.linphone.utils.showKeyboard
@UiThread
class MeetingsListFragment : AbstractTopBarFragment() {
companion object {
private const val TAG = "[Meetings List Fragment]"
@ -80,15 +82,7 @@ class MeetingsListFragment : AbstractTopBarFragment() {
}
binding.setTodayClickListener {
val todayMeeting = listViewModel.meetings.value.orEmpty().find {
it.isToday
}
val position = if (todayMeeting != null) {
listViewModel.meetings.value.orEmpty().indexOf(todayMeeting)
} else {
0 // TODO FIXME: improve by getting closest meeting
}
binding.meetingsList.smoothScrollToPosition(position)
scrollToToday()
}
listViewModel.meetings.observe(viewLifecycleOwner) {
@ -97,7 +91,7 @@ class MeetingsListFragment : AbstractTopBarFragment() {
Log.i("$TAG Meetings list ready with [${it.size}] items")
if (currentCount < it.size) {
binding.meetingsList.scrollToPosition(0)
scrollToToday()
}
}
@ -106,6 +100,7 @@ class MeetingsListFragment : AbstractTopBarFragment() {
Log.i(
"$TAG Default account changed, updating avatar in top bar & re-computing meetings list"
)
listViewModel.applyFilter()
}
}
@ -131,4 +126,23 @@ class MeetingsListFragment : AbstractTopBarFragment() {
}
}
}
private fun scrollToToday() {
Log.i("$TAG Scrolling to today's meeting (if any)")
val todayMeeting = listViewModel.meetings.value.orEmpty().find {
it.isToday
}
val position = if (todayMeeting != null) {
val index = listViewModel.meetings.value.orEmpty().indexOf(todayMeeting)
Log.i(
"$TAG Found (at least) a meeting for today [${todayMeeting.subject.value}] at index [$index]"
)
// Return the element before so today's event will be properly displayed (due to header)
if (index > 0) index - 1 else index
} else {
Log.i("$TAG No meeting found for today")
0 // TODO FIXME: improve by getting closest meeting
}
binding.meetingsList.smoothScrollToPosition(position)
}
}

View file

@ -23,11 +23,13 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.UiThread
import androidx.navigation.fragment.findNavController
import org.linphone.databinding.MeetingScheduleFragmentBinding
import org.linphone.ui.main.fragment.GenericFragment
import org.linphone.utils.Event
@UiThread
class ScheduleMeetingFragment : GenericFragment() {
companion object {
private const val TAG = "[Schedule Meeting Fragment]"

View file

@ -79,11 +79,32 @@ class MeetingsListViewModel @UiThread constructor() : AbstractTopBarViewModel()
private fun computeMeetingsList(filter: String) {
val list = arrayListOf<MeetingModel>()
// TODO FIXME: get list from default account
for (conferenceInfo in coreContext.core.conferenceInformationList) {
val model = MeetingModel(conferenceInfo)
// TODO FIXME: apply filter
list.add(model)
var source = coreContext.core.defaultAccount?.conferenceInformationList
if (source == null) {
Log.e(
"$TAG Failed to obtain conferences information list from default account, using Core"
)
source = coreContext.core.conferenceInformationList
}
for (info: ConferenceInfo in source) {
val add = if (filter.isNotEmpty()) {
val organizerCheck = info.organizer?.asStringUriOnly()?.contains(
filter,
ignoreCase = true
) ?: false
val subjectCheck = info.subject?.contains(filter, ignoreCase = true) ?: false
val descriptionCheck = info.description?.contains(filter, ignoreCase = true) ?: false
val participantsCheck = info.participantInfos.find {
it.address.asStringUriOnly().contains(filter, ignoreCase = true)
} != null
organizerCheck || subjectCheck || descriptionCheck || participantsCheck
} else {
true
}
if (add) {
val model = MeetingModel(info)
list.add(model)
}
}
meetings.postValue(list)