Manage repo screen - constant sized list items, and update menu item.

This commit is contained in:
Peter Serwylo 2013-12-10 17:34:18 +11:00
parent 9384bc093b
commit 8d44f6e444
2 changed files with 32 additions and 8 deletions

View File

@ -46,7 +46,8 @@ import java.util.*;
public class ManageRepo extends ListActivity {
private final int ADD_REPO = 1;
private final int ADD_REPO = 1;
private final int UPDATE_REPOS = 2;
/**
* If we have a new repo added, or the address of a repo has changed, then
@ -158,11 +159,19 @@ public class ManageRepo extends ListActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuItem updateItem = menu.add(Menu.NONE, UPDATE_REPOS, 1,
R.string.menu_add_repo).setIcon(R.drawable.ic_menu_refresh);
MenuItemCompat.setShowAsAction(updateItem,
MenuItemCompat.SHOW_AS_ACTION_ALWAYS |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
MenuItem addItem = menu.add(Menu.NONE, ADD_REPO, 1, R.string.menu_add_repo).setIcon(
android.R.drawable.ic_menu_add);
MenuItemCompat.setShowAsAction(addItem,
MenuItemCompat.SHOW_AS_ACTION_IF_ROOM |
MenuItemCompat.SHOW_AS_ACTION_ALWAYS |
MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@ -250,6 +259,10 @@ public class ManageRepo extends ListActivity {
return super.onOptionsItemSelected(item);
}
private void updateRepos() {
UpdateService.updateNow(this);
}
private void showAddRepo() {
showAddRepo(getNewRepoUri(), null);
}
@ -390,12 +403,15 @@ public class ManageRepo extends ListActivity {
super.onMenuItemSelected(featureId, item);
switch (item.getItemId()) {
case ADD_REPO:
if (item.getItemId() == ADD_REPO) {
showAddRepo();
return true;
} else if (item.getItemId() == UPDATE_REPOS) {
updateRepos();
return true;
}
return true;
return false;
}
/**

View File

@ -73,15 +73,23 @@ public class RepoAdapter extends BaseAdapter {
}
});
int unsignedVisibility = repository.isSigned() ? View.GONE : View.VISIBLE;
view.findViewById(R.id.repo_unsigned).setVisibility(unsignedVisibility);
TextView nameView = (TextView)view.findViewById(R.id.repo_name);
nameView.setText(repository.getName());
RelativeLayout.LayoutParams nameViewLayout =
(RelativeLayout.LayoutParams)nameView.getLayoutParams();
nameViewLayout.addRule(RelativeLayout.LEFT_OF, switchView.getId());
// If we set the signed view to GONE instead of INVISIBLE, then the
// height of each list item varies.
View signedView = view.findViewById(R.id.repo_unsigned);
if (repository.isSigned()) {
nameViewLayout.addRule(RelativeLayout.CENTER_VERTICAL);
signedView.setVisibility(View.INVISIBLE);
} else {
nameViewLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
signedView.setVisibility(View.VISIBLE);
}
return view;
}