Improved call hsitory detail page

This commit is contained in:
Sylvain Berfini 2020-06-24 15:55:49 +02:00
parent cadd5a84b2
commit 0e20fff7e3
7 changed files with 29 additions and 41 deletions

View file

@ -61,15 +61,17 @@ class DetailCallLogFragment : Fragment() {
ViewModelProvider(this).get(SharedMainViewModel::class.java)
} ?: throw Exception("Invalid Activity")
val callLog = sharedViewModel.selectedCallLog.value
callLog ?: return
val callLogGroup = sharedViewModel.selectedCallLogGroup.value
callLogGroup ?: return
viewModel = ViewModelProvider(
this,
CallLogViewModelFactory(callLog)
CallLogViewModelFactory(callLogGroup.lastCallLog)
)[CallLogViewModel::class.java]
binding.viewModel = viewModel
viewModel.relatedCallLogs.value = callLogGroup.callLogs
binding.setBackClickListener {
findNavController().popBackStack()
}

View file

@ -156,7 +156,7 @@ class MasterCallLogsFragment : MasterFragment() {
adapter.selectedCallLogEvent.observe(viewLifecycleOwner, Observer {
it.consume { callLog ->
sharedViewModel.selectedCallLog.value = callLog.lastCallLog
sharedViewModel.selectedCallLogGroup.value = callLog
if (!resources.getBoolean(R.bool.isTablet)) {
if (findNavController().currentDestination?.id == R.id.masterCallLogsFragment) {
findNavController().navigate(R.id.action_masterCallLogsFragment_to_detailCallLogFragment)

View file

@ -25,7 +25,6 @@ import androidx.lifecycle.ViewModelProvider
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.R
import org.linphone.contact.GenericContactViewModel
import org.linphone.core.*
@ -86,14 +85,14 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
}
val duration: String by lazy {
val dateFormat = SimpleDateFormat("HH:mm:ss", Locale.getDefault())
val dateFormat = SimpleDateFormat(if (callLog.duration >= 3600) "HH:mm:ss" else "mm:ss", Locale.getDefault())
val cal = Calendar.getInstance()
cal[0, 0, 0, 0, 0] = callLog.duration
dateFormat.format(cal.time)
}
val date: String by lazy {
TimestampUtils.toString(callLog.startDate)
TimestampUtils.toString(callLog.startDate, shortDate = false)
}
val startCallEvent: MutableLiveData<Event<Address>> by lazy {
@ -108,6 +107,8 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
val secureChatAllowed = contact.value?.friend?.getPresenceModelForUriOrTel(peerSipUri)?.hasCapability(FriendCapability.LimeX3Dh) ?: false
val relatedCallLogs = MutableLiveData<ArrayList<CallLog>>()
private val chatRoomListener = object : ChatRoomListenerStub() {
override fun onStateChanged(chatRoom: ChatRoom, state: ChatRoom.State) {
if (state == ChatRoom.State.Created) {
@ -146,9 +147,8 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
fun getCallsHistory(): ArrayList<CallLogViewModel> {
val callsHistory = ArrayList<CallLogViewModel>()
val logs = coreContext.core.getCallHistory(callLog.remoteAddress, coreContext.core.defaultProxyConfig?.identityAddress)
for (log in logs) {
callsHistory.add(CallLogViewModel(log))
for (callLog in relatedCallLogs.value.orEmpty()) {
callsHistory.add(CallLogViewModel(callLog))
}
return callsHistory
}

View file

@ -21,6 +21,7 @@ package org.linphone.activities.main.viewmodels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import org.linphone.activities.main.history.viewmodels.GroupedCallLogViewModel
import org.linphone.contact.Contact
import org.linphone.core.*
import org.linphone.utils.Event
@ -30,7 +31,7 @@ class SharedMainViewModel : ViewModel() {
/* Call history */
val selectedCallLog = MutableLiveData<CallLog>()
val selectedCallLogGroup = MutableLiveData<GroupedCallLogViewModel>()
/* Chat */

View file

@ -79,7 +79,7 @@ class TimestampUtils {
if (isSameYear(timestamp, timestampInSecs)) {
// Remove the year part of the format
dateFormat.applyPattern(
dateFormat.toPattern().replace("/?y+/?|\\s?y+\\s?".toRegex(), "")
dateFormat.toPattern().replace("/?y+/?|\\s?y+\\s?".toRegex(), if (shortDate) "" else " ")
)
}

View file

@ -31,7 +31,7 @@
<CheckBox
android:id="@+id/select"
android:onClick="@{() -> selectionListViewModel.onToggleSelect(position)}"
android:visibility="@{selectionListViewModel.isEditionEnabled ? View.VISIBLE : View.GONE}"
android:visibility="@{selectionListViewModel.isEditionEnabled ? View.VISIBLE : View.GONE, default=gone}"
android:checked="@{selectionListViewModel.selectedItems.contains(position)}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -86,7 +86,7 @@
android:paddingBottom="5dp">
<LinearLayout
android:visibility="@{viewModel.chatMessage.forward ? View.VISIBLE : View.GONE}"
android:visibility="@{viewModel.chatMessage.forward ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
@ -110,7 +110,8 @@
android:fontFamily="sans-serif"
android:textStyle="normal"
android:lineSpacingExtra="3.3sp"
android:text="@string/chat_message_forwarded" />
android:text="@string/chat_message_forwarded"
tools:ignore="SmallSp" />
</LinearLayout>
@ -145,7 +146,7 @@
android:lineSpacingExtra="-1.7sp"/>
<LinearLayout
android:visibility="@{viewModel.chatMessage.ephemeral ? View.VISIBLE : View.GONE}"
android:visibility="@{viewModel.chatMessage.ephemeral ? View.VISIBLE : View.GONE, default=gone}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
@ -178,7 +179,7 @@
<TextView
android:id="@+id/time"
android:text="@{viewModel.chatMessage.outgoing ? viewModel.time : viewModel.time + ` - ` + (viewModel.contact.fullName ?? viewModel.displayName), default=Wednesday}"
android:text="@{viewModel.chatMessage.outgoing ? viewModel.time : viewModel.time + ` - ` + (viewModel.contact.fullName ?? viewModel.displayName)}"
android:visibility="@{viewModel.hideTime ? View.GONE : View.VISIBLE}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -9,11 +9,9 @@
type="org.linphone.activities.main.history.viewmodels.CallLogViewModel" />
</data>
<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
@ -21,32 +19,18 @@
android:contentDescription="@{data.iconContentDescription}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<com.google.android.flexbox.FlexboxLayout
<org.linphone.views.MarqueeTextView
android:text="@{data.date + ` - ` + data.duration}"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:flexWrap="wrap"
app:justifyContent="center">
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:text="@{data.duration}"
android:textColor="?attr/primarySubtextDarkColor"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp" />
<TextView
android:text="@{data.date}"
android:textColor="?attr/primarySubtextDarkColor"
android:textSize="18sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.google.android.flexbox.FlexboxLayout>
</LinearLayout>
</RelativeLayout>
</layout>