List all calls log for a given SIP URI in history detail

This commit is contained in:
Sylvain Berfini 2019-04-12 16:39:53 +02:00
parent 5c366f0af2
commit d3fbc2939e
6 changed files with 266 additions and 187 deletions

View file

@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.Dialog; import android.app.Dialog;
@ -957,27 +956,12 @@ public class LinphoneActivity extends LinphoneGenericActivity
String pictureUri = String pictureUri =
c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null; c != null && c.getPhotoUri() != null ? c.getPhotoUri().toString() : null;
String status;
if (log.getDir() == Call.Dir.Outgoing) {
status = getString(R.string.outgoing);
} else {
if (log.getStatus() == Call.Status.Missed) {
status = getString(R.string.missed);
} else {
status = getString(R.string.incoming);
}
}
String callTime = secondsToDisplayableString(log.getDuration());
String callDate = String.valueOf(log.getStartDate());
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2); Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
if (fragment2 != null if (fragment2 != null
&& fragment2.isVisible() && fragment2.isVisible()
&& mCurrentFragment == FragmentsAvailable.HISTORY_DETAIL) { && mCurrentFragment == FragmentsAvailable.HISTORY_DETAIL) {
HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2; HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2;
historyDetailFragment.changeDisplayedHistory( historyDetailFragment.changeDisplayedHistory(sipUri, displayName);
sipUri, displayName, status, callTime, callDate);
} else { } else {
Bundle extras = new Bundle(); Bundle extras = new Bundle();
extras.putString("SipUri", sipUri); extras.putString("SipUri", sipUri);
@ -985,9 +969,6 @@ public class LinphoneActivity extends LinphoneGenericActivity
extras.putString("DisplayName", displayName); extras.putString("DisplayName", displayName);
extras.putString("PictureUri", pictureUri); extras.putString("PictureUri", pictureUri);
} }
extras.putString("Call.Status", status);
extras.putString("CallTime", callTime);
extras.putString("CallDate", callDate);
changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras); changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras);
} }
@ -997,14 +978,6 @@ public class LinphoneActivity extends LinphoneGenericActivity
changeCurrentFragment(FragmentsAvailable.EMPTY, new Bundle()); changeCurrentFragment(FragmentsAvailable.EMPTY, new Bundle());
} }
@SuppressLint("SimpleDateFormat")
private String secondsToDisplayableString(int secs) {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.set(0, 0, 0, 0, 0, secs);
return dateFormat.format(cal.getTime());
}
public void displayContact(LinphoneContact contact, boolean chatOnly) { public void displayContact(LinphoneContact contact, boolean chatOnly) {
Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2); Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2);
if (fragment2 != null if (fragment2 != null

View file

@ -26,14 +26,18 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import java.util.Arrays;
import java.util.List;
import org.linphone.LinphoneActivity; import org.linphone.LinphoneActivity;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R; import org.linphone.R;
import org.linphone.contacts.ContactsManager; import org.linphone.contacts.ContactsManager;
import org.linphone.contacts.LinphoneContact; import org.linphone.contacts.LinphoneContact;
import org.linphone.core.Address; import org.linphone.core.Address;
import org.linphone.core.CallLog;
import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoom;
import org.linphone.core.ChatRoomBackend; import org.linphone.core.ChatRoomBackend;
import org.linphone.core.ChatRoomListenerStub; import org.linphone.core.ChatRoomListenerStub;
@ -51,22 +55,19 @@ import org.linphone.views.ContactAvatar;
public class HistoryDetailFragment extends Fragment implements OnClickListener { public class HistoryDetailFragment extends Fragment implements OnClickListener {
private ImageView mDialBack, mChat, mAddToContacts, mGoToContact, mBack; private ImageView mDialBack, mChat, mAddToContacts, mGoToContact, mBack;
private View mView; private View mView;
private ImageView mCallDirection; private TextView mContactName, mContactAddress;
private TextView mContactName, mContactAddress, mTime, mDate;
private String mSipUri, mDisplayName; private String mSipUri, mDisplayName;
private RelativeLayout mWaitLayout, mAvatarLayout, mChatSecured; private RelativeLayout mWaitLayout, mAvatarLayout, mChatSecured;
private LinphoneContact mContact; private LinphoneContact mContact;
private ChatRoom mChatRoom; private ChatRoom mChatRoom;
private ChatRoomListenerStub mChatRoomCreationListener; private ChatRoomListenerStub mChatRoomCreationListener;
private ListView mLogsList;
@Override @Override
public View onCreateView( public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mSipUri = getArguments().getString("SipUri"); mSipUri = getArguments().getString("SipUri");
mDisplayName = getArguments().getString("DisplayName"); mDisplayName = getArguments().getString("DisplayName");
String status = getArguments().getString("Call.Status");
String callTime = getArguments().getString("CallTime");
String callDate = getArguments().getString("CallDate");
mView = inflater.inflate(R.layout.history_detail, container, false); mView = inflater.inflate(R.layout.history_detail, container, false);
@ -101,17 +102,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
mGoToContact.setOnClickListener(this); mGoToContact.setOnClickListener(this);
mAvatarLayout = mView.findViewById(R.id.avatar_layout); mAvatarLayout = mView.findViewById(R.id.avatar_layout);
mContactName = mView.findViewById(R.id.contact_name); mContactName = mView.findViewById(R.id.contact_name);
mContactAddress = mView.findViewById(R.id.contact_address); mContactAddress = mView.findViewById(R.id.contact_address);
mCallDirection = mView.findViewById(R.id.direction);
mTime = mView.findViewById(R.id.time);
mDate = mView.findViewById(R.id.date);
displayHistory(status, callTime, callDate);
mChatRoomCreationListener = mChatRoomCreationListener =
new ChatRoomListenerStub() { new ChatRoomListenerStub() {
@Override @Override
@ -134,36 +127,25 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} }
}; };
mLogsList = mView.findViewById(R.id.logs_list);
displayHistory();
return mView; return mView;
} }
@Override private void displayHistory() {
public void onPause() { Address lAddress = Factory.instance().createAddress(mSipUri);
if (mChatRoom != null) {
mChatRoom.removeListener(mChatRoomCreationListener);
}
super.onPause();
}
private void displayHistory(String status, String callTime, String callDate) {
if (status.equals(getResources().getString(R.string.missed))) {
mCallDirection.setImageResource(R.drawable.call_missed);
} else if (status.equals(getResources().getString(R.string.incoming))) {
mCallDirection.setImageResource(R.drawable.call_incoming);
} else if (status.equals(getResources().getString(R.string.outgoing))) {
mCallDirection.setImageResource(R.drawable.call_outgoing);
}
mChatSecured.setVisibility(View.GONE); mChatSecured.setVisibility(View.GONE);
mTime.setText(callTime == null ? "" : callTime);
Long longDate = Long.parseLong(callDate);
mDate.setText(
LinphoneUtils.timestampToHumanDate(
getActivity(), longDate, getString(R.string.history_detail_date_format)));
Address lAddress = Factory.instance().createAddress(mSipUri);
if (lAddress != null) { if (lAddress != null) {
CallLog[] logs =
LinphoneManager.getLcIfManagerNotDestroyedOrNull()
.getCallHistoryForAddress(lAddress);
List<CallLog> logsList = Arrays.asList(logs);
mLogsList.setAdapter(
new HistoryLogAdapter(
LinphoneActivity.instance(), R.layout.history_detail_cell, logsList));
mContactAddress.setText(LinphoneUtils.getDisplayableAddress(lAddress)); mContactAddress.setText(LinphoneUtils.getDisplayableAddress(lAddress));
mContact = ContactsManager.getInstance().findContactFromAddress(lAddress); mContact = ContactsManager.getInstance().findContactFromAddress(lAddress);
@ -197,15 +179,22 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener {
} }
} }
public void changeDisplayedHistory( @Override
String sipUri, String displayName, String status, String callTime, String callDate) { public void onPause() {
if (mChatRoom != null) {
mChatRoom.removeListener(mChatRoomCreationListener);
}
super.onPause();
}
public void changeDisplayedHistory(String sipUri, String displayName) {
if (displayName == null) { if (displayName == null) {
displayName = LinphoneUtils.getUsernameFromAddress(sipUri); displayName = LinphoneUtils.getUsernameFromAddress(sipUri);
} }
mSipUri = sipUri; mSipUri = sipUri;
mDisplayName = displayName; mDisplayName = displayName;
displayHistory(status, callTime, callDate); displayHistory();
} }
@Override @Override

View file

@ -0,0 +1,115 @@
package org.linphone.history;
/*
HistoryLogAdapter.java
Copyright (C) 2019 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import org.linphone.R;
import org.linphone.core.Call;
import org.linphone.core.CallLog;
import org.linphone.utils.LinphoneUtils;
class HistoryLogAdapter extends ArrayAdapter<CallLog> {
private Context mContext;
private final List<CallLog> mItems;
private final int mResource;
HistoryLogAdapter(@NonNull Context context, int resource, @NonNull List<CallLog> objects) {
super(context, resource, objects);
mContext = context;
mResource = resource;
mItems = objects;
}
@Nullable
@Override
public CallLog getItem(int position) {
return mItems.get(position);
}
@Override
public int getCount() {
return mItems.size();
}
@SuppressLint("SimpleDateFormat")
private String secondsToDisplayableString(int secs) {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
Calendar cal = Calendar.getInstance();
cal.set(0, 0, 0, 0, 0, secs);
return dateFormat.format(cal.getTime());
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater =
(LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(mResource, parent, false);
CallLog callLog = getItem(position);
String callTime = secondsToDisplayableString(callLog.getDuration());
String callDate = String.valueOf(callLog.getStartDate());
String status;
if (callLog.getDir() == Call.Dir.Outgoing) {
status = mContext.getString(R.string.outgoing);
} else {
if (callLog.getStatus() == Call.Status.Missed) {
status = mContext.getString(R.string.missed);
} else {
status = mContext.getString(R.string.incoming);
}
}
TextView date = rowView.findViewById(R.id.date);
TextView time = rowView.findViewById(R.id.time);
ImageView callDirection = rowView.findViewById(R.id.direction);
if (status.equals(mContext.getResources().getString(R.string.missed))) {
callDirection.setImageResource(R.drawable.call_missed);
} else if (status.equals(mContext.getResources().getString(R.string.incoming))) {
callDirection.setImageResource(R.drawable.call_incoming);
} else if (status.equals(mContext.getResources().getString(R.string.outgoing))) {
callDirection.setImageResource(R.drawable.call_outgoing);
}
time.setText(callTime == null ? "" : callTime);
Long longDate = Long.parseLong(callDate);
date.setText(
LinphoneUtils.timestampToHumanDate(
mContext,
longDate,
mContext.getString(R.string.history_detail_date_format)));
return rowView;
}
}

View file

@ -54,145 +54,117 @@
</LinearLayout> </LinearLayout>
<ScrollView <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
android:padding="20dp">
<RelativeLayout
android:id="@+id/avatar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<include layout="@layout/contact_avatar_100"/>
</RelativeLayout>
<TextView
android:id="@+id/contact_name"
style="@style/big_contact_name_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/contact_address"
style="@style/sip_uri_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:gravity="center"
android:orientation="vertical" android:orientation="horizontal">
android:padding="20dp">
<ImageView
android:id="@+id/call"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:background="@drawable/round_orange_button_background"
android:contentDescription="@string/content_description_call"
android:src="@drawable/call_start_default" />
<ImageView
android:id="@+id/chat"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:background="@drawable/round_orange_button_background"
android:contentDescription="@string/content_description_chat"
android:src="@drawable/chat_start_default" />
<RelativeLayout <RelativeLayout
android:id="@+id/avatar_layout" android:id="@+id/chat_secured"
android:layout_width="match_parent" android:layout_width="65dp"
android:layout_height="wrap_content" android:layout_height="60dp"
android:gravity="center"> android:layout_margin="10dp">
<include layout="@layout/contact_avatar_100"/>
</RelativeLayout>
<TextView
android:id="@+id/contact_name"
style="@style/big_contact_name_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal" />
<TextView
android:id="@+id/contact_address"
style="@style/sip_uri_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView <ImageView
android:id="@+id/call"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
android:layout_margin="10dp" android:layout_alignParentLeft="true"
android:background="@drawable/round_orange_button_background" android:layout_centerVertical="true"
android:contentDescription="@string/content_description_call"
android:src="@drawable/call_start_default" />
<ImageView
android:id="@+id/chat"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_margin="10dp"
android:background="@drawable/round_orange_button_background" android:background="@drawable/round_orange_button_background"
android:contentDescription="@string/content_description_chat" android:contentDescription="@string/content_description_chat"
android:src="@drawable/chat_start_default" /> android:src="@drawable/chat_start_default" />
<RelativeLayout <ImageView
android:id="@+id/chat_secured" android:id="@+id/security_level"
android:layout_width="65dp" android:layout_width="20dp"
android:layout_height="60dp" android:layout_height="20dp"
android:layout_margin="10dp"> android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/security_toogle_icon_green" />
<ImageView </RelativeLayout>
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="@drawable/round_orange_button_background"
android:contentDescription="@string/content_description_chat"
android:src="@drawable/chat_start_default" />
<ImageView
android:id="@+id/security_level"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/security_toogle_icon_green" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/log_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="?attr/dividerColor" />
<TextView
style="@style/assistant_input_field_header_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:text="@string/call"
android:textAllCaps="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/date"
style="@style/call_log_detail_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp" />
<TextView
android:id="@+id/time"
style="@style/call_log_detail_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<View
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="?attr/dividerColor" />
<TextView
style="@style/assistant_input_field_header_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:text="@string/calls"
android:textAllCaps="true" />
<ListView
android:id="@+id/logs_list"
android:cacheColorHint="@color/transparent_color"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
<TextView
android:id="@+id/date"
style="@style/call_log_detail_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="10dp" />
<TextView
android:id="@+id/time"
style="@style/call_log_detail_font"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -169,6 +169,7 @@
<string name="delete_history_log">Do you want to delete selected call log?</string> <string name="delete_history_log">Do you want to delete selected call log?</string>
<string name="today">Today</string> <string name="today">Today</string>
<string name="yesterday">Yesterday</string> <string name="yesterday">Yesterday</string>
<string name="calls">Calls</string>
<!-- Contacts --> <!-- Contacts -->
<string name="no_contact">No contact in your address book.</string> <string name="no_contact">No contact in your address book.</string>