Some changes to app list adapters
* Only change compact layout stuff when really needed * No need to use StringBuilders in some cases * No need to keep setting status and license to "" when in compact
This commit is contained in:
parent
154b0bda45
commit
533c16af0a
@ -20,6 +20,7 @@ abstract public class AppListAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
private List<DB.App> items = new ArrayList<DB.App>();
|
private List<DB.App> items = new ArrayList<DB.App>();
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private List<Boolean> compacts = new ArrayList<Boolean>();
|
||||||
|
|
||||||
public AppListAdapter(Context context) {
|
public AppListAdapter(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@ -31,10 +32,12 @@ abstract public class AppListAdapter extends BaseAdapter {
|
|||||||
|
|
||||||
public void addItem(DB.App app) {
|
public void addItem(DB.App app) {
|
||||||
items.add(app);
|
items.add(app);
|
||||||
|
compacts.add(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
items.clear();
|
items.clear();
|
||||||
|
compacts.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,29 +71,32 @@ abstract public class AppListAdapter extends BaseAdapter {
|
|||||||
TextView status = (TextView) convertView.findViewById(R.id.status);
|
TextView status = (TextView) convertView.findViewById(R.id.status);
|
||||||
TextView license = (TextView) convertView.findViewById(R.id.license);
|
TextView license = (TextView) convertView.findViewById(R.id.license);
|
||||||
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
|
ImageView icon = (ImageView) convertView.findViewById(R.id.icon);
|
||||||
LinearLayout iconContainer = (LinearLayout)convertView.findViewById(R.id.status_icons);
|
|
||||||
ImageView iconInstalled = (ImageView) convertView.findViewById(R.id.icon_status_installed);
|
|
||||||
ImageView iconUpdates = (ImageView) convertView.findViewById(R.id.icon_status_has_updates);
|
|
||||||
|
|
||||||
name.setText(app.name);
|
name.setText(app.name);
|
||||||
summary.setText(app.summary);
|
summary.setText(app.summary);
|
||||||
|
|
||||||
layoutSummary(summary);
|
Boolean storedCompact = compacts.get(position);
|
||||||
ImageLoader.getInstance().displayImage(app.iconUrl, icon);
|
if (storedCompact == null || compact != storedCompact) {
|
||||||
|
|
||||||
int visibleOnCompact = compact ? View.VISIBLE : View.GONE;
|
int visibleOnCompact = compact ? View.VISIBLE : View.GONE;
|
||||||
int notVisibleOnCompact = compact ? View.GONE : View.VISIBLE;
|
int notVisibleOnCompact = compact ? View.GONE : View.VISIBLE;
|
||||||
|
|
||||||
|
LinearLayout iconContainer = (LinearLayout)convertView.findViewById(R.id.status_icons);
|
||||||
|
|
||||||
iconContainer.setVisibility(visibleOnCompact);
|
iconContainer.setVisibility(visibleOnCompact);
|
||||||
status.setVisibility(notVisibleOnCompact);
|
status.setVisibility(notVisibleOnCompact);
|
||||||
license.setVisibility(notVisibleOnCompact);
|
license.setVisibility(notVisibleOnCompact);
|
||||||
|
compacts.set(position, compact);
|
||||||
|
layoutSummary(summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageLoader.getInstance().displayImage(app.iconUrl, icon);
|
||||||
|
|
||||||
if (!compact) {
|
if (!compact) {
|
||||||
status.setText(getVersionInfo(app));
|
status.setText(getVersionInfo(app));
|
||||||
license.setText(app.license);
|
license.setText(app.license);
|
||||||
} else {
|
} else {
|
||||||
status.setText("");
|
ImageView iconInstalled = (ImageView) convertView.findViewById(R.id.icon_status_installed);
|
||||||
license.setText("");
|
ImageView iconUpdates = (ImageView) convertView.findViewById(R.id.icon_status_has_updates);
|
||||||
|
|
||||||
iconInstalled.setImageResource(R.drawable.ic_cab_done_holo_dark);
|
iconInstalled.setImageResource(R.drawable.ic_cab_done_holo_dark);
|
||||||
iconUpdates.setImageResource(R.drawable.ic_menu_refresh);
|
iconUpdates.setImageResource(R.drawable.ic_menu_refresh);
|
||||||
@ -150,23 +156,18 @@ abstract public class AppListAdapter extends BaseAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getVersionInfo(DB.App app) {
|
private String getVersionInfo(DB.App app) {
|
||||||
StringBuilder version = new StringBuilder();
|
|
||||||
if (app.installedVersion != null) {
|
if (app.installedVersion != null) {
|
||||||
version.append(app.installedVersion);
|
|
||||||
if (app.toUpdate) {
|
if (app.toUpdate) {
|
||||||
version.append(" -> ");
|
return app.installedVersion + " -> " + app.curApk.version;
|
||||||
version.append(app.curApk.version);
|
|
||||||
}
|
}
|
||||||
|
return app.installedVersion;
|
||||||
} else {
|
} else {
|
||||||
int numav = app.apks.size();
|
int numav = app.apks.size();
|
||||||
String numVersions;
|
if (numav == 1) {
|
||||||
if (numav == 1)
|
return mContext.getString(R.string.n_version_available, numav);
|
||||||
numVersions = mContext.getString(R.string.n_version_available);
|
}
|
||||||
else
|
return mContext.getString(R.string.n_versions_available, numav);
|
||||||
numVersions = mContext.getString(R.string.n_versions_available);
|
|
||||||
version.append(String.format(numVersions, numav));
|
|
||||||
}
|
}
|
||||||
return version.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,13 @@ public class AppListFragmentPageAdapter extends FragmentPagerAdapter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int i) {
|
public Fragment getItem(int i) {
|
||||||
Fragment fragment = null;
|
|
||||||
if ( i == 0 ) {
|
if ( i == 0 ) {
|
||||||
fragment = new AvailableAppsFragment();
|
return new AvailableAppsFragment();
|
||||||
} else if ( i == 1 ) {
|
|
||||||
fragment = new InstalledAppsFragment();
|
|
||||||
} else if ( i == 2 ) {
|
|
||||||
fragment = new CanUpdateAppsFragment();
|
|
||||||
}
|
}
|
||||||
return fragment;
|
if ( i == 1 ) {
|
||||||
|
return new InstalledAppsFragment();
|
||||||
|
}
|
||||||
|
return new CanUpdateAppsFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -47,9 +45,8 @@ public class AppListFragmentPageAdapter extends FragmentPagerAdapter {
|
|||||||
case 1:
|
case 1:
|
||||||
return parent.getString(R.string.tab_installed);
|
return parent.getString(R.string.tab_installed);
|
||||||
case 2:
|
case 2:
|
||||||
String updates = parent.getString(R.string.tab_updates);
|
return parent.getString(R.string.tab_updates) + " ("
|
||||||
updates += " (" + parent.getManager().getCanUpdateAdapter().getCount() + ")";
|
+ parent.getManager().getCanUpdateAdapter().getCount() + ")";
|
||||||
return updates;
|
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user