Fix edit mode in history

This commit is contained in:
Margaux Clerc 2015-09-07 17:16:13 +02:00
parent 2c178d8c5f
commit 9067c12a0c
8 changed files with 89 additions and 92 deletions

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
android:drawable="@drawable/edit_list_disabled" />
<item
android:drawable="@drawable/edit_list" />
</selector>

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/edit_list"
android:alpha="0.2" />

View file

@ -2,7 +2,7 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item <item
android:state_pressed="true" android:state_pressed="true"
android:drawable="@color/colorJ" /> android:drawable="@color/colorH" />
<item <item
android:drawable="@color/colorH" /> android:drawable="@color/colorH" />
</selector> </selector>

View file

@ -106,7 +106,7 @@
<ImageView <ImageView
android:id="@+id/edit" android:id="@+id/edit"
android:src="@drawable/edit_list" android:src="@drawable/edit_list_button"
android:background="@drawable/toolbar_button" android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_edit" android:contentDescription="@string/content_description_edit"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<string name="history_date_format">d MMM</string> <string name="history_date_format">EEE, d MMM</string>
<string name="history_detail_date_format">yyyy/MM/dd - HH:mm</string> <string name="history_detail_date_format">yyyy/MM/dd - HH:mm - </string>
<string name="messages_date_format">HH:mm d MMM</string> <string name="messages_date_format">HH:mm d MMM</string>
<string name="messages_list_date_format">dd/MM</string> <string name="messages_list_date_format">dd/MM</string>
<string name="today_date_format">HH:mm</string> <string name="today_date_format">HH:mm</string>

View file

@ -10,7 +10,7 @@
<string name="domain">Domain</string> <string name="domain">Domain</string>
<string name="remote_provisioning_url">Provisioning url</string> <string name="remote_provisioning_url">Provisioning url</string>
<string name="email">Email</string> <string name="email">Email</string>
<string name="delete_text">Are you sure you want to delete all your selection ?</string> <string name="delete_text">Are you sure you want to delete your selection ?</string>
<string name="delete">Delete</string> <string name="delete">Delete</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>

View file

@ -58,7 +58,7 @@
<style name="font10" parent="@android:style/TextAppearance.Medium"> <style name="font10" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/colorD</item> <item name="android:textColor">@color/colorD</item>
<item name="android:textSize">26sp</item> <item name="android:textSize">24sp</item>
</style> </style>
<style name="font11" parent="@android:style/TextAppearance.Small"> <style name="font11" parent="@android:style/TextAppearance.Small">
@ -67,12 +67,12 @@
</style> </style>
<style name="font12" parent="@android:style/TextAppearance.Small"> <style name="font12" parent="@android:style/TextAppearance.Small">
<item name="android:textColor">@color/colorD</item> <item name="android:textColor">@color/colorE</item>
<item name="android:textSize">25sp</item> <item name="android:textSize">25sp</item>
</style> </style>
<style name="font13" parent="@android:style/TextAppearance.Small"> <style name="font13" parent="@android:style/TextAppearance.Small">
<item name="android:textColor">@color/colorD</item> <item name="android:textColor">@color/colorE</item>
<item name="android:textSize">18sp</item> <item name="android:textSize">18sp</item>
</style> </style>

View file

@ -33,10 +33,7 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.app.Fragment; import android.app.Fragment;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -45,7 +42,6 @@ import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.Button; import android.widget.Button;
@ -64,7 +60,7 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
private ListView historyList; private ListView historyList;
private LayoutInflater mInflater; private LayoutInflater mInflater;
private TextView noCallHistory, noMissedCallHistory; private TextView noCallHistory, noMissedCallHistory;
private ImageView missedCalls, allCalls, edit, selectAll, deselectAll, deleteAll; private ImageView missedCalls, allCalls, edit, selectAll, deselectAll, delete;
private RelativeLayout allCallsSelected, missedCallsSelected; private RelativeLayout allCallsSelected, missedCallsSelected;
private boolean onlyDisplayMissedCalls, isEditMode; private boolean onlyDisplayMissedCalls, isEditMode;
private List<LinphoneCallLog> mLogs; private List<LinphoneCallLog> mLogs;
@ -80,11 +76,10 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
historyList = (ListView) view.findViewById(R.id.historyList); historyList = (ListView) view.findViewById(R.id.historyList);
historyList.setOnItemClickListener(this); historyList.setOnItemClickListener(this);
registerForContextMenu(historyList);
deleteAll = (ImageView) view.findViewById(R.id.delete); delete = (ImageView) view.findViewById(R.id.delete);
deleteAll.setOnClickListener(this); delete.setOnClickListener(this);
deleteAll.setVisibility(View.INVISIBLE); delete.setVisibility(View.INVISIBLE);
allCalls = (ImageView) view.findViewById(R.id.all_calls); allCalls = (ImageView) view.findViewById(R.id.all_calls);
allCalls.setOnClickListener(this); allCalls.setOnClickListener(this);
@ -117,6 +112,23 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs()); 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);
}
}
private void removeCallLogs(){
int size = historyList.getAdapter().getCount();
for(int i=0; i<size; i++) {
if(historyList.isItemChecked(i)){
LinphoneCallLog log = mLogs.get(i);
LinphoneManager.getLc().removeCallLog(log);
}
}
}
private void removeNotMissedCallsFromLogs() { private void removeNotMissedCallsFromLogs() {
if (onlyDisplayMissedCalls) { if (onlyDisplayMissedCalls) {
List<LinphoneCallLog> missedCalls = new ArrayList<LinphoneCallLog>(); List<LinphoneCallLog> missedCalls = new ArrayList<LinphoneCallLog>();
@ -164,76 +176,21 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
} }
} }
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, v.getId(), 0, getString(R.string.delete));
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
LinphoneCallLog log = mLogs.get(info.position);
LinphoneManager.getLc().removeCallLog(log);
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs());
if (!hideHistoryListAndDisplayMessageIfEmpty()) {
historyList.setAdapter(new CallHistoryAdapter(getActivity()));
}
return true;
}
@Override @Override
public void onClick(View v) { public void onClick(View v) {
int id = v.getId(); int id = v.getId();
if (id == R.id.edit) {
edit.setVisibility(View.GONE);
selectAll.setVisibility(View.VISIBLE);
deleteAll.setVisibility(View.VISIBLE);
isEditMode = true;
}
if (id == R.id.all_calls) {
allCalls.setEnabled(false);
allCallsSelected.setVisibility(View.VISIBLE);
missedCallsSelected.setVisibility(View.INVISIBLE);
missedCalls.setEnabled(true);
onlyDisplayMissedCalls = false;
mLogs = Arrays.asList(LinphoneManager.getLc().getCallLogs());
}
if (id == R.id.missed_calls) {
allCalls.setEnabled(true);
allCallsSelected.setVisibility(View.INVISIBLE);
missedCallsSelected.setVisibility(View.VISIBLE);
missedCalls.setEnabled(false);
onlyDisplayMissedCalls = true;
}
if (!hideHistoryListAndDisplayMessageIfEmpty() && !isEditMode) {
historyList.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE);
historyList.setAdapter(new CallHistoryAdapter(getActivity().getApplicationContext()));
}
if(isEditMode){
deselectAll.setVisibility(View.GONE);
selectAll.setVisibility(View.VISIBLE);
}
if (id == R.id.select_all) { if (id == R.id.select_all) {
deselectAll.setVisibility(View.VISIBLE); deselectAll.setVisibility(View.VISIBLE);
selectAll.setVisibility(View.GONE); selectAll.setVisibility(View.GONE);
int size = historyList.getAdapter().getCount(); selectAllList(true);
for(int i=0; i<size; i++) { return;
historyList.setItemChecked(i, true);
}
} }
if (id == R.id.deselect_all) { if (id == R.id.deselect_all) {
deselectAll.setVisibility(View.GONE); deselectAll.setVisibility(View.GONE);
selectAll.setVisibility(View.VISIBLE); selectAll.setVisibility(View.VISIBLE);
int size = historyList.getAdapter().getCount(); selectAllList(false);
for(int i=0; i<size; i++) { return;
historyList.setItemChecked(i, false);
}
} }
if (id == R.id.delete) { if (id == R.id.delete) {
@ -244,13 +201,7 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
delete.setOnClickListener(new OnClickListener() { delete.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
int size = historyList.getAdapter().getCount(); removeCallLogs();
for(int i=0; i<size; i++) {
if(historyList.isItemChecked(i)){
LinphoneCallLog log = mLogs.get(i);
LinphoneManager.getLc().removeCallLog(log);
}
}
dialog.dismiss(); dialog.dismiss();
quitEditMode(); quitEditMode();
} }
@ -264,7 +215,41 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
} }
}); });
dialog.show(); dialog.show();
return;
} }
if (id == R.id.edit) {
edit.setVisibility(View.GONE);
selectAll.setVisibility(View.VISIBLE);
delete.setVisibility(View.VISIBLE);
isEditMode = true;
}
if (id == R.id.all_calls) {
allCalls.setEnabled(false);
allCallsSelected.setVisibility(View.VISIBLE);
missedCallsSelected.setVisibility(View.INVISIBLE);
missedCalls.setEnabled(true);
onlyDisplayMissedCalls = false;
refresh();
}
if (id == R.id.missed_calls) {
allCalls.setEnabled(true);
allCallsSelected.setVisibility(View.INVISIBLE);
missedCallsSelected.setVisibility(View.VISIBLE);
missedCalls.setEnabled(false);
onlyDisplayMissedCalls = 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);
}
} }
@Override @Override
@ -288,12 +273,12 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
} }
private void hideDeleteAllButton() { private void hideDeleteAllButton() {
if (deleteAll == null || deleteAll.getVisibility() != View.VISIBLE) { if (delete == null || delete.getVisibility() != View.VISIBLE) {
return; return;
} }
if (LinphoneActivity.instance().isAnimationDisabled()) { if (LinphoneActivity.instance().isAnimationDisabled()) {
deleteAll.setVisibility(View.INVISIBLE); delete.setVisibility(View.INVISIBLE);
} else { } else {
Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_out_right_to_left); Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_out_right_to_left);
animation.setAnimationListener(new AnimationListener() { animation.setAnimationListener(new AnimationListener() {
@ -309,21 +294,21 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
deleteAll.setVisibility(View.INVISIBLE); delete.setVisibility(View.INVISIBLE);
animation.setAnimationListener(null); animation.setAnimationListener(null);
} }
}); });
deleteAll.startAnimation(animation); delete.startAnimation(animation);
} }
} }
private void showDeleteAllButton() { private void showDeleteAllButton() {
if (deleteAll == null || deleteAll.getVisibility() == View.VISIBLE) { if (delete == null || delete.getVisibility() == View.VISIBLE) {
return; return;
} }
if (LinphoneActivity.instance().isAnimationDisabled()) { if (LinphoneActivity.instance().isAnimationDisabled()) {
deleteAll.setVisibility(View.VISIBLE); delete.setVisibility(View.VISIBLE);
} else { } else {
Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_left_to_right); Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_left_to_right);
animation.setAnimationListener(new AnimationListener() { animation.setAnimationListener(new AnimationListener() {
@ -339,11 +324,11 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
@Override @Override
public void onAnimationEnd(Animation animation) { public void onAnimationEnd(Animation animation) {
deleteAll.setVisibility(View.VISIBLE); delete.setVisibility(View.VISIBLE);
animation.setAnimationListener(null); animation.setAnimationListener(null);
} }
}); });
deleteAll.startAnimation(animation); delete.startAnimation(animation);
} }
} }
@ -351,7 +336,7 @@ public class HistoryFragment extends Fragment implements OnClickListener, OnItem
isEditMode = false; isEditMode = false;
selectAll.setVisibility(View.GONE); selectAll.setVisibility(View.GONE);
deselectAll.setVisibility(View.GONE); deselectAll.setVisibility(View.GONE);
deleteAll.setVisibility(View.GONE); delete.setVisibility(View.GONE);
edit.setVisibility(View.VISIBLE); edit.setVisibility(View.VISIBLE);
refresh(); refresh();
if (!hideHistoryListAndDisplayMessageIfEmpty()){ if (!hideHistoryListAndDisplayMessageIfEmpty()){