Skip to content
Snippets Groups Projects
Commit ee362b69 authored by Alexandre Lision's avatar Alexandre Lision
Browse files

profiles: code clean up

Harmonize code style in profile related source code
Use ButterKnife to lighten UI setup in Smartlist.

Change-Id: I6093522167a171a52266da4b29b9e0e518654baf
Tuleap: #857
parent 787eed9d
No related branches found
No related tags found
No related merge requests found
...@@ -81,10 +81,9 @@ public class SmartListAdapter extends BaseAdapter { ...@@ -81,10 +81,9 @@ public class SmartListAdapter extends BaseAdapter {
} }
public void updateDataset(final Collection<Conversation> list, String query) { public void updateDataset(final Collection<Conversation> list, String query) {
Log.d(TAG, "updateDataset " + list.size() Log.d(TAG, "updateDataset " + list.size() + " with query: " + query);
+ " with query: " + query);
if (list.size() == 0 && mCalls.size() == 0) { if (list.isEmpty() && mCalls.isEmpty()) {
return; return;
} }
...@@ -93,9 +92,7 @@ public class SmartListAdapter extends BaseAdapter { ...@@ -93,9 +92,7 @@ public class SmartListAdapter extends BaseAdapter {
if (!c.getContact().isUnknown() if (!c.getContact().isUnknown()
|| !c.getAccountsUsed().isEmpty() || !c.getAccountsUsed().isEmpty()
|| c.getCurrentCall() != null) { || c.getCurrentCall() != null) {
if (TextUtils.isEmpty(query)) { if (TextUtils.isEmpty(query) || c.getCurrentCall() != null) {
mCalls.add(c);
} else if (c.getCurrentCall() != null) {
mCalls.add(c); mCalls.add(c);
} else if (c.getContact() != null) { } else if (c.getContact() != null) {
CallContact contact = c.getContact(); CallContact contact = c.getContact();
...@@ -137,9 +134,9 @@ public class SmartListAdapter extends BaseAdapter { ...@@ -137,9 +134,9 @@ public class SmartListAdapter extends BaseAdapter {
} }
public class ViewHolder { public class ViewHolder {
TextView conv_participants; TextView convParticipants;
TextView conv_status; TextView convStatus;
TextView conv_time; TextView convTime;
ImageView photo; ImageView photo;
int position; int position;
public Conversation conv; public Conversation conv;
...@@ -147,34 +144,35 @@ public class SmartListAdapter extends BaseAdapter { ...@@ -147,34 +144,35 @@ public class SmartListAdapter extends BaseAdapter {
@Override @Override
public View getView(final int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(cx.ring.R.layout.item_smartlist, null); convertView = LayoutInflater.from(mContext).inflate(cx.ring.R.layout.item_smartlist, null);
}
ViewHolder holder = (ViewHolder) convertView.getTag(); ViewHolder holder = (ViewHolder) convertView.getTag();
if (holder == null) { if (holder == null) {
holder = new ViewHolder(); holder = new ViewHolder();
holder.photo = (ImageView) convertView.findViewById(R.id.photo); holder.photo = (ImageView) convertView.findViewById(R.id.photo);
holder.conv_participants = (TextView) convertView.findViewById(R.id.conv_participant); holder.convParticipants = (TextView) convertView.findViewById(R.id.conv_participant);
holder.conv_status = (TextView) convertView.findViewById(R.id.conv_last_item); holder.convStatus = (TextView) convertView.findViewById(R.id.conv_last_item);
holder.conv_time = (TextView) convertView.findViewById(R.id.conv_last_time); holder.convTime = (TextView) convertView.findViewById(R.id.conv_last_time);
holder.position = -1; holder.position = -1;
convertView.setTag(holder); convertView.setTag(holder);
} }
final ViewHolder h = holder; final ViewHolder h = holder;
h.conv = mCalls.get(position); h.conv = mCalls.get(position);
h.position = position; h.position = position;
h.conv_participants.setText(h.conv.getContact().getDisplayName()); h.convParticipants.setText(h.conv.getContact().getDisplayName());
long last_interaction = h.conv.getLastInteraction().getTime(); long lastInteraction = h.conv.getLastInteraction().getTime();
h.conv_time.setText(last_interaction == 0 ? "" : DateUtils.getRelativeTimeSpanString(last_interaction, System.currentTimeMillis(), 0L, DateUtils.FORMAT_ABBREV_ALL)); h.convTime.setText(lastInteraction == 0 ? "" : DateUtils.getRelativeTimeSpanString(lastInteraction, System.currentTimeMillis(), 0L, DateUtils.FORMAT_ABBREV_ALL));
h.conv_status.setText(h.conv.getLastInteractionSumary(mContext.getResources())); h.convStatus.setText(h.conv.getLastInteractionSumary(mContext.getResources()));
if (h.conv.hasUnreadTextMessages()) { if (h.conv.hasUnreadTextMessages()) {
h.conv_participants.setTypeface(null, Typeface.BOLD); h.convParticipants.setTypeface(null, Typeface.BOLD);
h.conv_time.setTypeface(null, Typeface.BOLD); h.convTime.setTypeface(null, Typeface.BOLD);
h.conv_status.setTypeface(null, Typeface.BOLD); h.convStatus.setTypeface(null, Typeface.BOLD);
} else { } else {
h.conv_participants.setTypeface(null, Typeface.NORMAL); h.convParticipants.setTypeface(null, Typeface.NORMAL);
h.conv_time.setTypeface(null, Typeface.NORMAL); h.convTime.setTypeface(null, Typeface.NORMAL);
h.conv_status.setTypeface(null, Typeface.NORMAL); h.convStatus.setTypeface(null, Typeface.NORMAL);
} }
holder.photo.setOnClickListener(new View.OnClickListener() { holder.photo.setOnClickListener(new View.OnClickListener() {
......
...@@ -59,6 +59,9 @@ import android.widget.Toast; ...@@ -59,6 +59,9 @@ import android.widget.Toast;
import com.google.zxing.integration.android.IntentIntegrator; import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult; import com.google.zxing.integration.android.IntentResult;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cx.ring.R; import cx.ring.R;
import cx.ring.adapters.SmartListAdapter; import cx.ring.adapters.SmartListAdapter;
import cx.ring.client.ConversationActivity; import cx.ring.client.ConversationActivity;
...@@ -83,20 +86,33 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -83,20 +86,33 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS; private LocalService.Callbacks mCallbacks = LocalService.DUMMY_CALLBACKS;
private SmartListAdapter mSmartListAdapter; private SmartListAdapter mSmartListAdapter;
private FloatingActionButton mFloatingActionButton = null; @BindView(R.id.newconv_fab)
FloatingActionButton mFloatingActionButton;
private SearchView mSearchView = null; private SearchView mSearchView = null;
private MenuItem mSearchMenuItem = null; private MenuItem mSearchMenuItem = null;
private MenuItem mDialpadMenuItem = null; private MenuItem mDialpadMenuItem = null;
private ListView mList = null; @BindView(R.id.confs_list)
private ProgressBar mLoader = null; ListView mList;
private TextView mEmptyTextView = null;
private ViewGroup mNewContact; @BindView(R.id.loading_indicator)
private ViewGroup mErrorMessagePane; ProgressBar mLoader;
private TextView mErrorMessageTextView;
private ImageView mErrorImageView; @BindView(R.id.emptyTextView)
TextView mEmptyTextView = null;
@BindView(R.id.newcontact_element)
ViewGroup mNewContact;
@BindView(R.id.error_msg_pane)
ViewGroup mErrorMessagePane;
@BindView(R.id.error_msg_txt)
TextView mErrorMessageTextView;
@BindView(R.id.error_image_view)
ImageView mErrorImageView;
private Handler mUserInputHandler; private Handler mUserInputHandler;
...@@ -150,15 +166,15 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -150,15 +166,15 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
@Override @Override
public void onDetach() { public void onDetach() {
Log.d(TAG, "onDetach");
super.onDetach(); super.onDetach();
Log.d(TAG, "onDetach");
mCallbacks = LocalService.DUMMY_CALLBACKS; mCallbacks = LocalService.DUMMY_CALLBACKS;
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "onCreate");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");
IntentFilter intentFilter = new IntentFilter(); IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(LocalService.ACTION_CONF_UPDATE); intentFilter.addAction(LocalService.ACTION_CONF_UPDATE);
intentFilter.addAction(LocalService.ACTION_CONF_LOADED); intentFilter.addAction(LocalService.ACTION_CONF_LOADED);
...@@ -168,15 +184,15 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -168,15 +184,15 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
@Override @Override
public void onDestroy() { public void onDestroy() {
Log.d(TAG, "onDestroy");
super.onDestroy(); super.onDestroy();
Log.d(TAG, "onDestroy");
getActivity().unregisterReceiver(receiver); getActivity().unregisterReceiver(receiver);
} }
@Override @Override
public void onResume() { public void onResume() {
Log.d(TAG, "onResume");
super.onResume(); super.onResume();
Log.d(TAG, "onResume");
((HomeActivity) getActivity()).setToolbarState(false, R.string.app_name); ((HomeActivity) getActivity()).setToolbarState(false, R.string.app_name);
refresh(); refresh();
} }
...@@ -222,6 +238,8 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -222,6 +238,8 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
mSearchMenuItem.expandActionView(); mSearchMenuItem.expandActionView();
mSearchView.setQuery(i.getDataString(), false); mSearchView.setQuery(i.getDataString(), false);
break; break;
default:
break;
} }
} }
...@@ -241,6 +259,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -241,6 +259,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
return true; return true;
case R.id.menu_scan_qr: case R.id.menu_scan_qr:
QRCodeScannerActivity.startQRCodeScanWithFragmentReceiver(this); QRCodeScannerActivity.startQRCodeScanWithFragmentReceiver(this);
return true;
default: default:
return false; return false;
} }
...@@ -297,52 +316,18 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -297,52 +316,18 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
setHasOptionsMenu(true); setHasOptionsMenu(true);
View inflatedView = inflater.inflate(cx.ring.R.layout.frag_smartlist, container, false); View inflatedView = inflater.inflate(cx.ring.R.layout.frag_smartlist, container, false);
this.mUserInputHandler = new Handler(); ButterKnife.bind(this, inflatedView);
mFloatingActionButton = (FloatingActionButton) inflatedView.findViewById(R.id.newconv_fab); mUserInputHandler = new Handler();
mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mSearchMenuItem != null) {
mSearchMenuItem.expandActionView();
}
}
});
mList = (ListView) inflatedView.findViewById(cx.ring.R.id.confs_list);
mList.setOnItemClickListener(conversationClickListener); mList.setOnItemClickListener(conversationClickListener);
mList.setOnItemLongClickListener(conversationLongClickListener); mList.setOnItemLongClickListener(conversationLongClickListener);
this.mEmptyTextView = (TextView) inflatedView.findViewById(R.id.emptyTextView);
this.mLoader = (ProgressBar) inflatedView.findViewById(R.id.loading_indicator);
if (savedInstanceState != null) { if (savedInstanceState != null) {
this.setLoading(savedInstanceState.getBoolean(STATE_LOADING, false)); this.setLoading(savedInstanceState.getBoolean(STATE_LOADING, false));
} }
mNewContact = (ViewGroup) inflatedView.findViewById(R.id.newcontact_element);
mNewContact.setVisibility(View.GONE); mNewContact.setVisibility(View.GONE);
mNewContact.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CallContact c = (CallContact) v.getTag();
if (c == null)
return;
startConversation(c);
}
});
mNewContact.findViewById(R.id.quick_call).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CallContact c = (CallContact) mNewContact.getTag();
if (c != null)
((HomeActivity) getActivity()).onCallContact(c);
}
});
mErrorMessagePane = (ViewGroup) inflatedView.findViewById(R.id.error_msg_pane);
mErrorMessageTextView = (TextView) mErrorMessagePane.findViewById(R.id.error_msg_txt);
mErrorImageView = (ImageView) mErrorMessagePane.findViewById(R.id.error_image_view);
LocalService service = mCallbacks.getService(); LocalService service = mCallbacks.getService();
if (service != null) { if (service != null) {
...@@ -355,6 +340,29 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -355,6 +340,29 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
return inflatedView; return inflatedView;
} }
@OnClick(R.id.newcontact_element)
void newContactClicked(View v) {
CallContact c = (CallContact) v.getTag();
if (c == null) {
return;
}
startConversation(c);
}
@OnClick(R.id.quick_call)
void quickCallClicked(View v) {
CallContact c = (CallContact) mNewContact.getTag();
if (c != null)
((HomeActivity) getActivity()).onCallContact(c);
}
@OnClick(R.id.newconv_fab)
void fabButtonClicked(View v) {
if (mSearchMenuItem != null) {
mSearchMenuItem.expandActionView();
}
}
public void bindService(final Context ctx, final LocalService service) { public void bindService(final Context ctx, final LocalService service) {
mSmartListAdapter = new SmartListAdapter(ctx, mSmartListAdapter = new SmartListAdapter(ctx,
service.get40dpContactCache(), service.get40dpContactCache(),
...@@ -410,8 +418,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -410,8 +418,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
mCallbacks.getService().getRemoteService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId()); mCallbacks.getService().getRemoteService().attendedTransfer(transfer.getParticipants().get(0).getCallId(), c.getParticipants().get(0).getCallId());
mSmartListAdapter.notifyDataSetChanged(); mSmartListAdapter.notifyDataSetChanged();
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Auto-generated catch block Log.e(TAG, "Error on Transfer", e);
e.printStackTrace();
} }
Toast.makeText(getActivity(), getString(cx.ring.R.string.home_transfer_complet), Toast.LENGTH_LONG).show(); Toast.makeText(getActivity(), getString(cx.ring.R.string.home_transfer_complet), Toast.LENGTH_LONG).show();
break; break;
...@@ -425,8 +432,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -425,8 +432,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
mCallbacks.getService().getRemoteService().transfer(transfer.getParticipants().get(0).getCallId(), to); mCallbacks.getService().getRemoteService().transfer(transfer.getParticipants().get(0).getCallId(), to);
mCallbacks.getService().getRemoteService().hangUp(transfer.getParticipants().get(0).getCallId()); mCallbacks.getService().getRemoteService().hangUp(transfer.getParticipants().get(0).getCallId());
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Auto-generated catch block Log.e(TAG, "Error on Transfer", e);
e.printStackTrace();
} }
break; break;
...@@ -491,8 +497,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -491,8 +497,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
); );
} }
} catch (RemoteException e) { } catch (RemoteException e) {
// TODO Auto-generated catch block Log.e(TAG, "Error on bindCalls", e);
e.printStackTrace();
} }
} }
...@@ -627,7 +632,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex ...@@ -627,7 +632,7 @@ public class SmartListFragment extends Fragment implements SearchView.OnQueryTex
mErrorMessageTextView.setText(textResId); mErrorMessageTextView.setText(textResId);
} }
if (mErrorImageView != null) { if (mErrorImageView != null) {
int visibility = (showImage) ? View.VISIBLE : View.GONE; int visibility = showImage ? View.VISIBLE : View.GONE;
mErrorImageView.setVisibility(visibility); mErrorImageView.setVisibility(visibility);
mErrorImageView.setImageResource(imageResId); mErrorImageView.setImageResource(imageResId);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment