Skip to content

Commit

Permalink
Implements issue #8. Number of contacts is now shown in the tab title.
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Jul 1, 2016
1 parent 8332ec7 commit c8b20e3
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -77,8 +78,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// if this was called after editing a phone contact, refresh the view
if (requestCode == EDIT_REQUEST_CODE) {
phoneContacts = phoneUtil.get();
phoneAdapter.notifyDataSetChanged();
simAdapter.notifyDataSetChanged();
update();
} else {
super.onActivityResult(requestCode, resultCode, data);
}
Expand Down Expand Up @@ -183,6 +183,18 @@ public void onClick(DialogInterface i, int which) {
simContacts = simUtil.get();
simAdapter = new SimRowAdapter(simContacts);
simView.setAdapter(simAdapter);

update();
}

private void update() {
simAdapter.notifyDataSetChanged();
phoneAdapter.notifyDataSetChanged();
TabWidget tabWidget = getTabHost().getTabWidget();
TextView labelPhone = (TextView) tabWidget.getChildAt(0).findViewById(android.R.id.title);
TextView labelSim = (TextView) tabWidget.getChildAt(1).findViewById(android.R.id.title);
labelPhone.setText(getString(R.string.phone_tab_title) + " (" + phoneContacts.size() + ")");
labelSim.setText(getString(R.string.sim_tab_title) + " (" + simContacts.size() + ")");
}

private void startContactEditActivity(Contact contact) {
Expand Down Expand Up @@ -216,11 +228,10 @@ private void copyToSim(Contact contact) throws Exception {
// create contact on SIM card
try {
simUtil.create(newSimContact);
simContacts.add(0, newSimContact);
} catch (Exception e) {
throw new Exception(getString(R.string.error_sim_contact_not_stored));
}

simContacts.add(0, newSimContact);
}

private void copyToPhone(Contact contact) throws Exception {
Expand Down Expand Up @@ -326,8 +337,7 @@ public void onClick(View v) {
try {
copyToSim((Contact) v.getTag());
message = getString(R.string.confirm_sim_contact_stored);
phoneAdapter.notifyDataSetChanged();
simAdapter.notifyDataSetChanged();
update();
} catch (Exception e) {
message = e.getMessage();
}
Expand Down Expand Up @@ -378,8 +388,7 @@ public void onClick(View v) {
Contact contact = (Contact) v.getTag();
copyToPhone(contact);
message = getString(R.string.confirm_phone_contact_number_stored, contact.getName());
phoneAdapter.notifyDataSetChanged();
simAdapter.notifyDataSetChanged();
update();
} catch (Exception e) {
message = e.getMessage();
}
Expand Down Expand Up @@ -428,8 +437,7 @@ public void onClick(DialogInterface dialog, int which) {
boolean success = false;
try {
success = deleteFromSim(contact);
simAdapter.notifyDataSetChanged();
phoneAdapter.notifyDataSetChanged();
update();
} catch (Exception e) {
// TODO: decide what to do with failed deletions
}
Expand Down Expand Up @@ -496,8 +504,7 @@ public void run() {
@Override
public void run() {
progressDialog.dismiss();
phoneAdapter.notifyDataSetChanged();
simAdapter.notifyDataSetChanged();
update();
if (failures > 0) {
String message = getString(R.string.error_bulk_copy, failures);
if (mode == COPY_ALL_TO_SIM) {
Expand Down

0 comments on commit c8b20e3

Please # to comment.