diff --git a/app/src/main/java/org/linphone/LinphoneActivity.java b/app/src/main/java/org/linphone/LinphoneActivity.java index 3ea663e1c..8063138f7 100644 --- a/app/src/main/java/org/linphone/LinphoneActivity.java +++ b/app/src/main/java/org/linphone/LinphoneActivity.java @@ -20,7 +20,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import android.Manifest; -import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; import android.app.Dialog; @@ -957,27 +956,12 @@ public class LinphoneActivity extends LinphoneGenericActivity String pictureUri = 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); if (fragment2 != null && fragment2.isVisible() && mCurrentFragment == FragmentsAvailable.HISTORY_DETAIL) { HistoryDetailFragment historyDetailFragment = (HistoryDetailFragment) fragment2; - historyDetailFragment.changeDisplayedHistory( - sipUri, displayName, status, callTime, callDate); + historyDetailFragment.changeDisplayedHistory(sipUri, displayName); } else { Bundle extras = new Bundle(); extras.putString("SipUri", sipUri); @@ -985,9 +969,6 @@ public class LinphoneActivity extends LinphoneGenericActivity extras.putString("DisplayName", displayName); extras.putString("PictureUri", pictureUri); } - extras.putString("Call.Status", status); - extras.putString("CallTime", callTime); - extras.putString("CallDate", callDate); changeCurrentFragment(FragmentsAvailable.HISTORY_DETAIL, extras); } @@ -997,14 +978,6 @@ public class LinphoneActivity extends LinphoneGenericActivity 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) { Fragment fragment2 = getFragmentManager().findFragmentById(R.id.fragmentContainer2); if (fragment2 != null diff --git a/app/src/main/java/org/linphone/history/HistoryDetailFragment.java b/app/src/main/java/org/linphone/history/HistoryDetailFragment.java index 3d0ad6ca3..d36bd66a7 100644 --- a/app/src/main/java/org/linphone/history/HistoryDetailFragment.java +++ b/app/src/main/java/org/linphone/history/HistoryDetailFragment.java @@ -26,14 +26,18 @@ import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; +import java.util.Arrays; +import java.util.List; import org.linphone.LinphoneActivity; import org.linphone.LinphoneManager; import org.linphone.R; import org.linphone.contacts.ContactsManager; import org.linphone.contacts.LinphoneContact; import org.linphone.core.Address; +import org.linphone.core.CallLog; import org.linphone.core.ChatRoom; import org.linphone.core.ChatRoomBackend; import org.linphone.core.ChatRoomListenerStub; @@ -51,22 +55,19 @@ import org.linphone.views.ContactAvatar; public class HistoryDetailFragment extends Fragment implements OnClickListener { private ImageView mDialBack, mChat, mAddToContacts, mGoToContact, mBack; private View mView; - private ImageView mCallDirection; - private TextView mContactName, mContactAddress, mTime, mDate; + private TextView mContactName, mContactAddress; private String mSipUri, mDisplayName; private RelativeLayout mWaitLayout, mAvatarLayout, mChatSecured; private LinphoneContact mContact; private ChatRoom mChatRoom; private ChatRoomListenerStub mChatRoomCreationListener; + private ListView mLogsList; @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mSipUri = getArguments().getString("SipUri"); 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); @@ -101,17 +102,9 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener { mGoToContact.setOnClickListener(this); mAvatarLayout = mView.findViewById(R.id.avatar_layout); - mContactName = mView.findViewById(R.id.contact_name); 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 = new ChatRoomListenerStub() { @Override @@ -134,36 +127,25 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener { } }; + mLogsList = mView.findViewById(R.id.logs_list); + displayHistory(); + return mView; } - @Override - public void onPause() { - 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); - } + private void displayHistory() { + Address lAddress = Factory.instance().createAddress(mSipUri); 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) { + CallLog[] logs = + LinphoneManager.getLcIfManagerNotDestroyedOrNull() + .getCallHistoryForAddress(lAddress); + List logsList = Arrays.asList(logs); + mLogsList.setAdapter( + new HistoryLogAdapter( + LinphoneActivity.instance(), R.layout.history_detail_cell, logsList)); + mContactAddress.setText(LinphoneUtils.getDisplayableAddress(lAddress)); mContact = ContactsManager.getInstance().findContactFromAddress(lAddress); @@ -197,15 +179,22 @@ public class HistoryDetailFragment extends Fragment implements OnClickListener { } } - public void changeDisplayedHistory( - String sipUri, String displayName, String status, String callTime, String callDate) { + @Override + public void onPause() { + if (mChatRoom != null) { + mChatRoom.removeListener(mChatRoomCreationListener); + } + super.onPause(); + } + + public void changeDisplayedHistory(String sipUri, String displayName) { if (displayName == null) { displayName = LinphoneUtils.getUsernameFromAddress(sipUri); } mSipUri = sipUri; mDisplayName = displayName; - displayHistory(status, callTime, callDate); + displayHistory(); } @Override diff --git a/app/src/main/java/org/linphone/history/HistoryLogAdapter.java b/app/src/main/java/org/linphone/history/HistoryLogAdapter.java new file mode 100644 index 000000000..351444913 --- /dev/null +++ b/app/src/main/java/org/linphone/history/HistoryLogAdapter.java @@ -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 { + private Context mContext; + private final List mItems; + private final int mResource; + + HistoryLogAdapter(@NonNull Context context, int resource, @NonNull List 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; + } +} diff --git a/app/src/main/res/layout/history_detail.xml b/app/src/main/res/layout/history_detail.xml index cf34d8e8f..016f1ae3a 100644 --- a/app/src/main/res/layout/history_detail.xml +++ b/app/src/main/res/layout/history_detail.xml @@ -54,145 +54,117 @@ - + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="vertical" + android:padding="20dp"> + + + + + + + + + + + android:orientation="horizontal"> + + + + - - - - - - - - - - + android:id="@+id/chat_secured" + android:layout_width="65dp" + android:layout_height="60dp" + android:layout_margin="10dp"> - - - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + + + + + + + + + + + diff --git a/app/src/main/res/layout/history_detail_cell.xml b/app/src/main/res/layout/history_detail_cell.xml new file mode 100644 index 000000000..6f022c9c8 --- /dev/null +++ b/app/src/main/res/layout/history_detail_cell.xml @@ -0,0 +1,29 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 65f5b7ae7..df3c4ccf6 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -169,6 +169,7 @@ Do you want to delete selected call log? Today Yesterday + Calls No contact in your address book.