HistoryListFragment ListView converted to RecyclerView, Adapter/ViewHolder are now in a CallHistoryAdapter separate class.
SelectableHelper edited, switched (de)select_all buttons visibility between enter/quitEditionMode, searchMode in ContactsListFragment revealed a switch error. TODO: Clean all fragments code edited during RecyclerView conversion course.
This commit is contained in:
parent
23bdb192ff
commit
7d23170577
7 changed files with 341 additions and 347 deletions
|
@ -76,7 +76,7 @@
|
|||
|
||||
<include layout="@layout/edit_list"/>
|
||||
|
||||
<ListView
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/history_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/history_whole"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp"
|
||||
android:layout_margin="5dp"
|
||||
|
@ -53,6 +54,7 @@
|
|||
android:layout_alignParentRight="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:visibility="gone"
|
||||
android:clickable="false"
|
||||
android:padding="5dp" />
|
||||
|
||||
<RelativeLayout
|
||||
|
|
233
src/android/org/linphone/call/CallHistoryAdapter.java
Normal file
233
src/android/org/linphone/call/CallHistoryAdapter.java
Normal file
|
@ -0,0 +1,233 @@
|
|||
package org.linphone.call;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.linphone.LinphoneUtils;
|
||||
import org.linphone.R;
|
||||
import org.linphone.activities.LinphoneActivity;
|
||||
import org.linphone.contacts.ContactsListAdapter;
|
||||
import org.linphone.contacts.ContactsManager;
|
||||
import org.linphone.contacts.LinphoneContact;
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.Call;
|
||||
import org.linphone.core.CallLog;
|
||||
import org.linphone.ui.SelectableAdapter;
|
||||
import org.linphone.ui.SelectableHelper;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
public class CallHistoryAdapter extends SelectableAdapter<CallHistoryAdapter.ViewHolder> {
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener,
|
||||
View.OnLongClickListener{
|
||||
public TextView contact;
|
||||
public ImageView detail;
|
||||
public CheckBox select;
|
||||
public ImageView callDirection;
|
||||
public ImageView contactPicture;
|
||||
public RelativeLayout CallContact;
|
||||
public RelativeLayout SelectContact;
|
||||
public LinearLayout separator;
|
||||
public TextView separatorText;
|
||||
private CallHistoryAdapter.ViewHolder.ClickListener listener;
|
||||
|
||||
public ViewHolder(View view, CallHistoryAdapter.ViewHolder.ClickListener listener) {
|
||||
super(view);
|
||||
contact = (TextView) view.findViewById(R.id.sip_uri);
|
||||
detail = (ImageView) view.findViewById(R.id.detail);
|
||||
select = (CheckBox) view.findViewById(R.id.delete);
|
||||
callDirection = (ImageView) view.findViewById(R.id.icon);
|
||||
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||
CallContact = (RelativeLayout) view.findViewById(R.id.history_click);
|
||||
SelectContact = (RelativeLayout) view.findViewById(R.id.history_whole);
|
||||
separator = (LinearLayout) view.findViewById(R.id.separator);
|
||||
separatorText = (TextView) view.findViewById(R.id.separator_text);
|
||||
this.listener = listener;
|
||||
view.setOnClickListener(this);
|
||||
view.setOnLongClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.onItemClicked(getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
if (listener != null) {
|
||||
return listener.onItemLongClicked(getAdapterPosition());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public interface ClickListener {
|
||||
public void onItemClicked(int position);
|
||||
public boolean onItemLongClicked(int position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private List<CallLog> mLogs;
|
||||
private Context mContext;
|
||||
private CallHistoryAdapter.ViewHolder.ClickListener clickListener;
|
||||
|
||||
public CallHistoryAdapter(Context aContext, List<CallLog> logs,CallHistoryAdapter.ViewHolder.ClickListener listener ,SelectableHelper helper) {
|
||||
super(helper);
|
||||
this.mLogs = logs;
|
||||
this.mContext = aContext;
|
||||
this.clickListener = listener;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mLogs.size();
|
||||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
return mLogs.get(position);
|
||||
}
|
||||
|
||||
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.history_cell, parent, false);
|
||||
return new ViewHolder(v, clickListener);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
|
||||
final CallLog log= mLogs.get(position);
|
||||
long timestamp = log.getStartDate() * 1000;
|
||||
Address address;
|
||||
|
||||
holder.contact.setSelected(true); // For automated horizontal scrolling of long texts
|
||||
Calendar logTime = Calendar.getInstance();
|
||||
logTime.setTimeInMillis(timestamp);
|
||||
holder.separatorText.setText(timestampToHumanDate(logTime));
|
||||
holder.select.setVisibility(isEditionEnabled() ? View.VISIBLE : View.GONE);
|
||||
holder.select.setChecked(isSelected(position));
|
||||
|
||||
|
||||
if (position > 0) {
|
||||
CallLog previousLog = mLogs.get(position-1);
|
||||
long previousTimestamp = previousLog.getStartDate() * 1000;
|
||||
Calendar previousLogTime = Calendar.getInstance();
|
||||
previousLogTime.setTimeInMillis(previousTimestamp);
|
||||
|
||||
if (isSameDay(previousLogTime, logTime)) {
|
||||
holder.separator.setVisibility(View.GONE);
|
||||
} else {
|
||||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
} else {
|
||||
holder.separator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
||||
if (log.getDir() == Call.Dir.Incoming) {
|
||||
address = log.getFromAddress();
|
||||
if (log.getStatus() == Call.Status.Missed) {
|
||||
holder.callDirection.setImageResource(R.drawable.call_status_missed);
|
||||
} else {
|
||||
holder.callDirection.setImageResource(R.drawable.call_status_incoming);
|
||||
}
|
||||
} else {
|
||||
address = log.getToAddress();
|
||||
holder.callDirection.setImageResource(R.drawable.call_status_outgoing);
|
||||
}
|
||||
|
||||
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address);
|
||||
String displayName = null;
|
||||
final String sipUri = (address != null) ? address.asString() : "";
|
||||
if (c != null) {
|
||||
displayName = c.getFullName();
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, c.getThumbnailUri());
|
||||
} else {
|
||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
}
|
||||
|
||||
if (displayName == null) {
|
||||
holder.contact.setText(LinphoneUtils.getAddressDisplayName(sipUri));
|
||||
} else {
|
||||
holder.contact.setText(displayName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
holder.detail.setVisibility(isEditionEnabled() ? View.INVISIBLE : View.VISIBLE);
|
||||
holder.detail.setOnClickListener(!isEditionEnabled() ?
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().displayHistoryDetail(sipUri, log);
|
||||
}
|
||||
}
|
||||
}
|
||||
:
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mLogs.size();
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
private String timestampToHumanDate(Calendar cal) {
|
||||
SimpleDateFormat dateFormat;
|
||||
if (isToday(cal)) {
|
||||
return mContext.getString(R.string.today);
|
||||
} else if (isYesterday(cal)) {
|
||||
return mContext.getString(R.string.yesterday);
|
||||
} else {
|
||||
dateFormat = new SimpleDateFormat(mContext.getResources().getString(R.string.history_date_format));
|
||||
}
|
||||
|
||||
return dateFormat.format(cal.getTime());
|
||||
}
|
||||
|
||||
private boolean isSameDay(Calendar cal1, Calendar cal2) {
|
||||
if (cal1 == null || cal2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
|
||||
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
||||
}
|
||||
|
||||
private boolean isToday(Calendar cal) {
|
||||
return isSameDay(cal, Calendar.getInstance());
|
||||
}
|
||||
|
||||
private boolean isYesterday(Calendar cal) {
|
||||
Calendar yesterday = Calendar.getInstance();
|
||||
yesterday.roll(Calendar.DAY_OF_MONTH, -1);
|
||||
return isSameDay(cal, yesterday);
|
||||
}
|
||||
}
|
|
@ -59,7 +59,6 @@ public class GroupInfoAdapter extends RecyclerView.Adapter<GroupInfoAdapter.View
|
|||
delete = view.findViewById(R.id.delete);
|
||||
isAdmin = view.findViewById(R.id.isAdminLayout);
|
||||
isNotAdmin = view.findViewById(R.id.isNotAdminLayout);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
|
||||
private void searchContacts(String search) {
|
||||
boolean isEditionEnabled = false;
|
||||
|
||||
// mSelectionHelper.quitEditionMode();
|
||||
if (search == null || search.length() == 0) {
|
||||
changeContactsAdapter();
|
||||
return;
|
||||
|
@ -342,6 +342,22 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClicked(int position) {
|
||||
LinphoneContact contact = (LinphoneContact) mContactAdapter.getItem(position);
|
||||
|
||||
if (mContactAdapter.isEditionEnabled()) {
|
||||
mContactAdapter.toggleSelection(position);
|
||||
|
||||
}else if (editOnClick) {
|
||||
editConsumed = true;
|
||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||
} else {
|
||||
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClicked(int position) {
|
||||
if (!mContactAdapter.isEditionEnabled()) {
|
||||
|
@ -421,19 +437,5 @@ public class ContactsListFragment extends Fragment implements OnItemClickListene
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onItemClicked(int position) {
|
||||
LinphoneContact contact = (LinphoneContact) mContactAdapter.getItem(position);
|
||||
|
||||
if (mContactAdapter.isEditionEnabled()) {
|
||||
mContactAdapter.toggleSelection(position);
|
||||
|
||||
}else if (editOnClick) {
|
||||
editConsumed = true;
|
||||
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
|
||||
} else {
|
||||
lastKnownPosition = layoutManager.findFirstVisibleItemPosition();
|
||||
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Arrays;
|
|||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import org.linphone.call.CallHistoryAdapter;
|
||||
import org.linphone.contacts.ContactsListAdapter;
|
||||
import org.linphone.contacts.ContactsManager;
|
||||
import org.linphone.contacts.ContactsUpdatedListener;
|
||||
import org.linphone.contacts.LinphoneContact;
|
||||
|
@ -36,12 +38,16 @@ import org.linphone.core.Call;
|
|||
import org.linphone.core.Address;
|
||||
import org.linphone.core.CallLog;
|
||||
import org.linphone.core.Call.Status;
|
||||
import org.linphone.ui.SelectableHelper;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.DividerItemDecoration;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
|
@ -59,8 +65,8 @@ import android.widget.ListView;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class HistoryListFragment extends Fragment implements OnClickListener, OnItemClickListener, ContactsUpdatedListener {
|
||||
private ListView historyList;
|
||||
public class HistoryListFragment extends Fragment implements OnClickListener, OnItemClickListener, CallHistoryAdapter.ViewHolder.ClickListener ,ContactsUpdatedListener,SelectableHelper.DeleteListener{
|
||||
private RecyclerView historyList;
|
||||
private LayoutInflater mInflater;
|
||||
private TextView noCallHistory, noMissedCallHistory;
|
||||
private ImageView missedCalls, allCalls, edit, selectAll, deselectAll, delete, cancel;
|
||||
|
@ -68,27 +74,46 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
private LinearLayout editList, topBar;
|
||||
private boolean onlyDisplayMissedCalls, isEditMode;
|
||||
private List<CallLog> mLogs;
|
||||
|
||||
private CallHistoryAdapter mhistoryAdapter;
|
||||
private LinearLayoutManager layoutManager;
|
||||
private Context mContext;
|
||||
private SelectableHelper mSelectionHelper;
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
mInflater = inflater;
|
||||
View view = inflater.inflate(R.layout.history, container, false);
|
||||
mContext = getActivity().getApplicationContext();
|
||||
mSelectionHelper = new SelectableHelper(view, this);
|
||||
|
||||
noCallHistory = (TextView) view.findViewById(R.id.no_call_history);
|
||||
noMissedCallHistory = (TextView) view.findViewById(R.id.no_missed_call_history);
|
||||
|
||||
historyList = (ListView) view.findViewById(R.id.history_list);
|
||||
historyList.setOnItemClickListener(this);
|
||||
historyList = (RecyclerView) view.findViewById(R.id.history_list);
|
||||
|
||||
delete = (ImageView) view.findViewById(R.id.delete);
|
||||
delete.setOnClickListener(this);
|
||||
|
||||
|
||||
layoutManager = new LinearLayoutManager(mContext);
|
||||
historyList.setLayoutManager(layoutManager);
|
||||
//Divider between items
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(historyList.getContext(),
|
||||
layoutManager.getOrientation());
|
||||
dividerItemDecoration.setDrawable(mContext.getResources().getDrawable(R.drawable.divider));
|
||||
historyList.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// delete = (ImageView) view.findViewById(R.id.delete);
|
||||
// delete.setOnClickListener(this);
|
||||
|
||||
editList = (LinearLayout) view.findViewById(R.id.edit_list);
|
||||
topBar = (LinearLayout) view.findViewById(R.id.top_bar);
|
||||
|
||||
cancel = (ImageView) view.findViewById(R.id.cancel);
|
||||
cancel.setOnClickListener(this);
|
||||
// cancel = (ImageView) view.findViewById(R.id.cancel);
|
||||
// cancel.setOnClickListener(this);
|
||||
|
||||
allCalls = (ImageView) view.findViewById(R.id.all_calls);
|
||||
allCalls.setOnClickListener(this);
|
||||
|
@ -100,17 +125,17 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
|
||||
missedCallsSelected = view.findViewById(R.id.missed_calls_select);
|
||||
|
||||
selectAll = (ImageView) view.findViewById(R.id.select_all);
|
||||
selectAll.setOnClickListener(this);
|
||||
|
||||
deselectAll = (ImageView) view.findViewById(R.id.deselect_all);
|
||||
deselectAll.setOnClickListener(this);
|
||||
// selectAll = (ImageView) view.findViewById(R.id.select_all);
|
||||
// selectAll.setOnClickListener(this);
|
||||
//
|
||||
// deselectAll = (ImageView) view.findViewById(R.id.deselect_all);
|
||||
// deselectAll.setOnClickListener(this);
|
||||
|
||||
allCalls.setEnabled(false);
|
||||
onlyDisplayMissedCalls = false;
|
||||
|
||||
edit = (ImageView) view.findViewById(R.id.edit);
|
||||
edit.setOnClickListener(this);
|
||||
// edit.setOnClickListener(this);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -119,12 +144,6 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs());
|
||||
}
|
||||
|
||||
private void selectAllList(boolean isSelectAll){
|
||||
int size = historyList.getAdapter().getCount();
|
||||
for(int i=0; i<size; i++) {
|
||||
historyList.setItemChecked(i,isSelectAll);
|
||||
}
|
||||
}
|
||||
|
||||
public void displayFirstLog(){
|
||||
if (mLogs != null && mLogs.size() > 0) {
|
||||
|
@ -141,37 +160,6 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
}
|
||||
}
|
||||
|
||||
private void removeCallLogs(){
|
||||
int size = historyList.getAdapter().getCount();
|
||||
for(int i=0; i<size; i++) {
|
||||
if(historyList.isItemChecked(i)){
|
||||
CallLog log = mLogs.get(i);
|
||||
LinphoneManager.getLc().removeCallLog(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getNbItemsChecked(){
|
||||
int size = historyList.getAdapter().getCount();
|
||||
int nb = 0;
|
||||
for(int i=0; i<size; i++) {
|
||||
if(historyList.isItemChecked(i)) {
|
||||
nb ++;
|
||||
}
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
public void enabledDeleteButton(Boolean enabled){
|
||||
if(enabled){
|
||||
delete.setEnabled(true);
|
||||
} else {
|
||||
if (getNbItemsChecked() == 0){
|
||||
delete.setEnabled(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeNotMissedCallsFromLogs() {
|
||||
if (onlyDisplayMissedCalls) {
|
||||
List<CallLog> missedCalls = new ArrayList<CallLog>();
|
||||
|
@ -217,8 +205,11 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
|
||||
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs());
|
||||
if (!hideHistoryListAndDisplayMessageIfEmpty()) {
|
||||
historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
|
||||
// historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
mhistoryAdapter= new CallHistoryAdapter(getActivity().getApplicationContext(), mLogs, this, mSelectionHelper);
|
||||
historyList.setAdapter(mhistoryAdapter);
|
||||
mSelectionHelper.setAdapter(mhistoryAdapter);
|
||||
mSelectionHelper.setDialogMessage(R.string.chat_room_delete_dialog);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,56 +233,6 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
public void onClick(View v) {
|
||||
int id = v.getId();
|
||||
|
||||
if (id == R.id.select_all) {
|
||||
deselectAll.setVisibility(View.VISIBLE);
|
||||
selectAll.setVisibility(View.GONE);
|
||||
enabledDeleteButton(true);
|
||||
selectAllList(true);
|
||||
return;
|
||||
}
|
||||
if (id == R.id.deselect_all) {
|
||||
deselectAll.setVisibility(View.GONE);
|
||||
selectAll.setVisibility(View.VISIBLE);
|
||||
enabledDeleteButton(false);
|
||||
selectAllList(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == R.id.cancel) {
|
||||
quitEditMode();
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == R.id.delete) {
|
||||
if(historyList.getCheckedItemCount() == 0) {
|
||||
quitEditMode();
|
||||
return;
|
||||
}
|
||||
|
||||
final Dialog dialog = LinphoneActivity.instance().displayDialog(getString(R.string.delete_text));
|
||||
Button delete = (Button) dialog.findViewById(R.id.delete_button);
|
||||
Button cancel = (Button) dialog.findViewById(R.id.cancel);
|
||||
|
||||
delete.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
removeCallLogs();
|
||||
dialog.dismiss();
|
||||
quitEditMode();
|
||||
}
|
||||
});
|
||||
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dialog.dismiss();
|
||||
quitEditMode();
|
||||
}
|
||||
});
|
||||
dialog.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (id == R.id.all_calls) {
|
||||
allCalls.setEnabled(false);
|
||||
allCallsSelected.setVisibility(View.VISIBLE);
|
||||
|
@ -307,247 +248,61 @@ public class HistoryListFragment extends Fragment implements OnClickListener, On
|
|||
missedCalls.setEnabled(false);
|
||||
onlyDisplayMissedCalls = true;
|
||||
}
|
||||
|
||||
if (id == R.id.edit) {
|
||||
topBar.setVisibility(View.GONE);
|
||||
editList.setVisibility(View.VISIBLE);
|
||||
enabledDeleteButton(false);
|
||||
isEditMode = true;
|
||||
}
|
||||
|
||||
if (!hideHistoryListAndDisplayMessageIfEmpty()) {
|
||||
historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
|
||||
}
|
||||
|
||||
if(isEditMode){
|
||||
deselectAll.setVisibility(View.GONE);
|
||||
selectAll.setVisibility(View.VISIBLE);
|
||||
// historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
mhistoryAdapter = new CallHistoryAdapter(mContext, mLogs, this ,mSelectionHelper);
|
||||
historyList.setAdapter(mhistoryAdapter);
|
||||
mSelectionHelper.setAdapter(mhistoryAdapter);
|
||||
mSelectionHelper.setDialogMessage(R.string.chat_room_delete_dialog);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
|
||||
if (isEditMode) {
|
||||
if (mhistoryAdapter.isEditionEnabled()) {
|
||||
CallLog log = mLogs.get(position);
|
||||
LinphoneManager.getLc().removeCallLog(log);
|
||||
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs());
|
||||
}
|
||||
}
|
||||
|
||||
public void quitEditMode(){
|
||||
isEditMode = false;
|
||||
editList.setVisibility(View.GONE);
|
||||
topBar.setVisibility(View.VISIBLE);
|
||||
|
||||
refresh();
|
||||
if (!hideHistoryListAndDisplayMessageIfEmpty()) {
|
||||
historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
|
||||
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
|
||||
}
|
||||
if (getResources().getBoolean(R.bool.isTablet)) {
|
||||
displayFirstLog();
|
||||
|
||||
@Override
|
||||
public void onDeleteSelection(Object[] objectsToDelete) {
|
||||
int size = mhistoryAdapter.getSelectedItemCount();
|
||||
for(int i=0; i<size; i++) {
|
||||
CallLog log = (CallLog) objectsToDelete[i];
|
||||
LinphoneManager.getLc().removeCallLog(log);
|
||||
onResume();
|
||||
}
|
||||
}
|
||||
|
||||
class CallHistoryAdapter extends BaseAdapter {
|
||||
private class ViewHolder {
|
||||
public TextView contact;
|
||||
public ImageView detail;
|
||||
public CheckBox select;
|
||||
public ImageView callDirection;
|
||||
public ImageView contactPicture;
|
||||
public RelativeLayout CallContact;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
contact = (TextView) view.findViewById(R.id.sip_uri);
|
||||
detail = (ImageView) view.findViewById(R.id.detail);
|
||||
select = (CheckBox) view.findViewById(R.id.delete);
|
||||
callDirection = (ImageView) view.findViewById(R.id.icon);
|
||||
contactPicture = (ImageView) view.findViewById(R.id.contact_picture);
|
||||
CallContact = (RelativeLayout) view.findViewById(R.id.history_click);
|
||||
}
|
||||
}
|
||||
|
||||
CallHistoryAdapter(Context aContext) {
|
||||
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mLogs.size();
|
||||
}
|
||||
|
||||
public Object getItem(int position) {
|
||||
return mLogs.get(position);
|
||||
}
|
||||
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
private String timestampToHumanDate(Calendar cal) {
|
||||
SimpleDateFormat dateFormat;
|
||||
if (isToday(cal)) {
|
||||
return getString(R.string.today);
|
||||
} else if (isYesterday(cal)) {
|
||||
return getString(R.string.yesterday);
|
||||
} else {
|
||||
dateFormat = new SimpleDateFormat(getResources().getString(R.string.history_date_format));
|
||||
}
|
||||
|
||||
return dateFormat.format(cal.getTime());
|
||||
}
|
||||
|
||||
private boolean isSameDay(Calendar cal1, Calendar cal2) {
|
||||
if (cal1 == null || cal2 == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
|
||||
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
||||
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
||||
}
|
||||
|
||||
private boolean isToday(Calendar cal) {
|
||||
return isSameDay(cal, Calendar.getInstance());
|
||||
}
|
||||
|
||||
private boolean isYesterday(Calendar cal) {
|
||||
Calendar yesterday = Calendar.getInstance();
|
||||
yesterday.roll(Calendar.DAY_OF_MONTH, -1);
|
||||
return isSameDay(cal, yesterday);
|
||||
}
|
||||
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
View view = null;
|
||||
ViewHolder holder = null;
|
||||
|
||||
if (convertView != null) {
|
||||
view = convertView;
|
||||
holder = (ViewHolder) view.getTag();
|
||||
} else {
|
||||
view = mInflater.inflate(R.layout.history_cell, parent,false);
|
||||
holder = new ViewHolder(view);
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
if (mLogs == null || mLogs.size() < position) return view;
|
||||
|
||||
final CallLog log = mLogs.get(position);
|
||||
long timestamp = log.getStartDate() * 1000;
|
||||
Address address;
|
||||
|
||||
holder.contact.setSelected(true); // For automated horizontal scrolling of long texts
|
||||
|
||||
LinearLayout separator = (LinearLayout) view.findViewById(R.id.separator);
|
||||
TextView separatorText = (TextView) view.findViewById(R.id.separator_text);
|
||||
Calendar logTime = Calendar.getInstance();
|
||||
logTime.setTimeInMillis(timestamp);
|
||||
separatorText.setText(timestampToHumanDate(logTime));
|
||||
|
||||
if (position > 0) {
|
||||
CallLog previousLog = mLogs.get(position-1);
|
||||
long previousTimestamp = previousLog.getStartDate() * 1000;
|
||||
Calendar previousLogTime = Calendar.getInstance();
|
||||
previousLogTime.setTimeInMillis(previousTimestamp);
|
||||
|
||||
if (isSameDay(previousLogTime, logTime)) {
|
||||
separator.setVisibility(View.GONE);
|
||||
@Override
|
||||
public void onItemClicked(int position) {
|
||||
if (mhistoryAdapter.isEditionEnabled()) {
|
||||
mhistoryAdapter.toggleSelection(position);
|
||||
}else{
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
CallLog log = mLogs.get(position);
|
||||
Address address;
|
||||
if (log.getDir() == Call.Dir.Incoming) {
|
||||
address = log.getFromAddress();
|
||||
} else {
|
||||
separator.setVisibility(View.VISIBLE);
|
||||
address = log.getToAddress();
|
||||
}
|
||||
} else {
|
||||
separator.setVisibility(View.VISIBLE);
|
||||
LinphoneActivity.instance().setAddresGoToDialerAndCall(address.asStringUriOnly(), address.getDisplayName(), null);
|
||||
}
|
||||
|
||||
if (log.getDir() == Call.Dir.Incoming) {
|
||||
address = log.getFromAddress();
|
||||
if (log.getStatus() == Call.Status.Missed) {
|
||||
holder.callDirection.setImageResource(R.drawable.call_status_missed);
|
||||
} else {
|
||||
holder.callDirection.setImageResource(R.drawable.call_status_incoming);
|
||||
}
|
||||
} else {
|
||||
address = log.getToAddress();
|
||||
holder.callDirection.setImageResource(R.drawable.call_status_outgoing);
|
||||
}
|
||||
|
||||
LinphoneContact c = ContactsManager.getInstance().findContactFromAddress(address);
|
||||
String displayName = null;
|
||||
final String sipUri = (address != null) ? address.asString() : "";
|
||||
if (c != null) {
|
||||
displayName = c.getFullName();
|
||||
LinphoneUtils.setThumbnailPictureFromUri(LinphoneActivity.instance(), holder.contactPicture, c.getThumbnailUri());
|
||||
} else {
|
||||
holder.contactPicture.setImageBitmap(ContactsManager.getInstance().getDefaultAvatarBitmap());
|
||||
}
|
||||
|
||||
if (displayName == null) {
|
||||
holder.contact.setText(LinphoneUtils.getAddressDisplayName(sipUri));
|
||||
} else {
|
||||
holder.contact.setText(displayName);
|
||||
}
|
||||
|
||||
if (isEditMode) {
|
||||
holder.CallContact.setOnClickListener(null);
|
||||
holder.select.setVisibility(View.VISIBLE);
|
||||
holder.select.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
historyList.setItemChecked(position, b);
|
||||
if(getNbItemsChecked() == getCount()){
|
||||
deselectAll.setVisibility(View.VISIBLE);
|
||||
selectAll.setVisibility(View.GONE);
|
||||
enabledDeleteButton(true);
|
||||
} else {
|
||||
if(getNbItemsChecked() == 0){
|
||||
deselectAll.setVisibility(View.GONE);
|
||||
selectAll.setVisibility(View.VISIBLE);
|
||||
enabledDeleteButton(false);
|
||||
} else {
|
||||
deselectAll.setVisibility(View.GONE);
|
||||
selectAll.setVisibility(View.VISIBLE);
|
||||
enabledDeleteButton(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.detail.setVisibility(View.INVISIBLE);
|
||||
if(historyList.isItemChecked(position)) {
|
||||
holder.select.setChecked(true);
|
||||
} else {
|
||||
holder.select.setChecked(false);
|
||||
}
|
||||
} else {
|
||||
holder.select.setVisibility(View.GONE);
|
||||
holder.detail.setVisibility(View.VISIBLE);
|
||||
holder.detail.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
LinphoneActivity.instance().displayHistoryDetail(sipUri, log);
|
||||
}
|
||||
}
|
||||
});
|
||||
holder.CallContact.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (LinphoneActivity.isInstanciated()) {
|
||||
CallLog log = mLogs.get(position);
|
||||
Address address;
|
||||
if (log.getDir() == Call.Dir.Incoming) {
|
||||
address = log.getFromAddress();
|
||||
} else {
|
||||
address = log.getToAddress();
|
||||
}
|
||||
LinphoneActivity.instance().setAddresGoToDialerAndCall(address.asStringUriOnly(), address.getDisplayName(), null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClicked(int position) {
|
||||
if (!mhistoryAdapter.isEditionEnabled()) {
|
||||
mSelectionHelper.enterEditionMode();
|
||||
}
|
||||
mhistoryAdapter.toggleSelection(position);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -67,7 +67,8 @@ public class SelectableHelper {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mAdapter.getItemCount() > 0) {
|
||||
mAdapter.enableEdition(true);
|
||||
enterEditionMode();
|
||||
// mAdapter.enableEdition(true);
|
||||
mTopBar.setVisibility(View.GONE);
|
||||
mEditTopBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -92,6 +93,8 @@ public class SelectableHelper {
|
|||
|
||||
mDeleteSelectionButton = view.findViewById(R.id.delete);
|
||||
mDeleteSelectionButton.setEnabled(false);
|
||||
|
||||
//Display confirmation for deletion
|
||||
mDeleteSelectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -149,8 +152,8 @@ public class SelectableHelper {
|
|||
mTopBar.setVisibility(View.VISIBLE);
|
||||
mEditTopBar.setVisibility(View.GONE);
|
||||
mDeleteSelectionButton.setEnabled(false);
|
||||
mSelectAllButton.setVisibility(View.VISIBLE);
|
||||
mDeselectAllButton.setVisibility(View.GONE);
|
||||
mSelectAllButton.setVisibility(View.GONE);
|
||||
mDeselectAllButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void enterEditionMode() {
|
||||
|
@ -158,8 +161,8 @@ public class SelectableHelper {
|
|||
mTopBar.setVisibility(View.GONE);
|
||||
mEditTopBar.setVisibility(View.VISIBLE);
|
||||
mDeleteSelectionButton.setEnabled(false);
|
||||
mSelectAllButton.setVisibility(View.GONE);
|
||||
mDeselectAllButton.setVisibility(View.VISIBLE);
|
||||
mSelectAllButton.setVisibility(View.VISIBLE);
|
||||
mDeselectAllButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private Object[] getSelectedObjects() {
|
||||
|
|
Loading…
Reference in a new issue