|
@@ -28,43 +28,71 @@ import de.tudarmstadt.informatik.hostage.ui2.layouts.FlowLayout;
|
|
|
import de.tudarmstadt.informatik.hostage.ui2.swipelist.SwipeListView;
|
|
|
|
|
|
/**
|
|
|
+ * This adapter creates the item views for the profile manager by making use the viewholder pattern
|
|
|
+ *
|
|
|
* @author Alexander Brakowski
|
|
|
* @created 14.01.14 18:00
|
|
|
*/
|
|
|
public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Holds our views, to reduce the number of view lookups immensly
|
|
|
+ */
|
|
|
private class ViewHolder {
|
|
|
- public TextView labelView;
|
|
|
- public TextView textView;
|
|
|
- public ImageView imageSelected;
|
|
|
- public ImageView itemIcon;
|
|
|
- public ImageButton buttonEdit;
|
|
|
- public ImageButton buttonDelete;
|
|
|
- public View seperator;
|
|
|
- public FlowLayout badgesContainer;
|
|
|
+ public TextView mLabelView;
|
|
|
+ public TextView mTextView;
|
|
|
+ public ImageView mImageSelected;
|
|
|
+ public ImageView mItemIcon;
|
|
|
+ public ImageButton mButtonEdit;
|
|
|
+ public ImageButton mButtonDelete;
|
|
|
+ public View mSeperator;
|
|
|
+ public FlowLayout mBadgesContainer;
|
|
|
}
|
|
|
|
|
|
- private final Context context;
|
|
|
- private final List<Profile> values;
|
|
|
- private SwipeListView list;
|
|
|
-
|
|
|
+ /**
|
|
|
+ * The context nedded for resource lookups
|
|
|
+ */
|
|
|
+ private final Context mContext;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * The profiles to display in the list
|
|
|
+ */
|
|
|
+ private final List<Profile> mValues;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A reference to the list view itself
|
|
|
+ */
|
|
|
+ private SwipeListView mList;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * A simple constructor to propagate this object with neccessary references to needed objects
|
|
|
+ *
|
|
|
+ * @param context needed for resource lookups
|
|
|
+ * @param objects the profiles to display
|
|
|
+ * @param list a reference to the list view
|
|
|
+ */
|
|
|
public ProfileManagerListAdapter(Context context, List<Profile> objects, SwipeListView list) {
|
|
|
super(context, R.layout.profile_manager_list_item, objects);
|
|
|
- this.context = context;
|
|
|
- this.values = objects;
|
|
|
- this.list = list;
|
|
|
+ this.mContext = context;
|
|
|
+ this.mValues = objects;
|
|
|
+ this.mList = list;
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * {@inheritDoc}
|
|
|
+ */
|
|
|
@Override
|
|
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
|
|
- LayoutInflater inflater = (LayoutInflater) context
|
|
|
+ LayoutInflater inflater = (LayoutInflater) mContext
|
|
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
|
|
|
View rowView = convertView;
|
|
|
ViewHolder holder = null;
|
|
|
|
|
|
- final Profile item = values.get(position);
|
|
|
+ final Profile item = mValues.get(position);
|
|
|
|
|
|
+ // if the current item has the show tooltip flag set, render this item as an tooltip view
|
|
|
if(item.mShowTooltip){
|
|
|
rowView = inflater.inflate(R.layout.profile_manager_list_item_help, parent, false);
|
|
|
rowView.findViewById(R.id.profile_manager_help_dismiss).setOnClickListener(new View.OnClickListener() {
|
|
@@ -72,59 +100,66 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
|
|
|
public void onClick(View v) {
|
|
|
ProfileManagerListAdapter.this.remove(item);
|
|
|
ProfileManagerListAdapter.this.notifyDataSetChanged();
|
|
|
- list.dismiss(position);
|
|
|
+ mList.dismiss(position);
|
|
|
|
|
|
+ // just show the tooltip as long as it was not dismissed
|
|
|
MainActivity.getContext().getSharedPreferences(
|
|
|
MainActivity.getContext().getString(R.string.shared_preference_path), Hostage.MODE_PRIVATE
|
|
|
).edit().putBoolean("dismissedProfileSwipeHelp", true).commit();
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
+ // put our views into an view holder, if it is new
|
|
|
if (rowView == null || rowView.getTag() == null) {
|
|
|
rowView = inflater.inflate(R.layout.profile_manager_list_item, parent, false);
|
|
|
|
|
|
holder = new ViewHolder();
|
|
|
- holder.labelView = (TextView) rowView.findViewById(R.id.profile_manager_item_label);
|
|
|
- holder.textView = (TextView) rowView.findViewById(R.id.profile_manager_item_text);
|
|
|
- holder.imageSelected = (ImageView) rowView.findViewById(R.id.profile_manager_item_activated);
|
|
|
- holder.itemIcon = (ImageView) rowView.findViewById(R.id.profile_manager_item_image);
|
|
|
- holder.buttonEdit = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_edit);
|
|
|
- holder.buttonDelete = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_delete);
|
|
|
- holder.seperator = rowView.findViewById(R.id.profile_manager_item_seperator);
|
|
|
- holder.badgesContainer = (FlowLayout) rowView.findViewById(R.id.badges_container);
|
|
|
+ holder.mLabelView = (TextView) rowView.findViewById(R.id.profile_manager_item_label);
|
|
|
+ holder.mTextView = (TextView) rowView.findViewById(R.id.profile_manager_item_text);
|
|
|
+ holder.mImageSelected = (ImageView) rowView.findViewById(R.id.profile_manager_item_activated);
|
|
|
+ holder.mItemIcon = (ImageView) rowView.findViewById(R.id.profile_manager_item_image);
|
|
|
+ holder.mButtonEdit = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_edit);
|
|
|
+ holder.mButtonDelete = (ImageButton) rowView.findViewById(R.id.profile_manager_item_button_delete);
|
|
|
+ holder.mSeperator = rowView.findViewById(R.id.profile_manager_item_seperator);
|
|
|
+ holder.mBadgesContainer = (FlowLayout) rowView.findViewById(R.id.badges_container);
|
|
|
|
|
|
rowView.setTag(holder);
|
|
|
} else {
|
|
|
+ // save the viewholder to the tag of the view, so we can reuse it later
|
|
|
holder = (ViewHolder) rowView.getTag();
|
|
|
}
|
|
|
|
|
|
+ // swipe listview needs some cleanup
|
|
|
((SwipeListView) parent).recycle(rowView, position);
|
|
|
|
|
|
- holder.textView.setText(item.mText);
|
|
|
- holder.labelView.setText(item.mLabel);
|
|
|
+ // fill the item view with the correct data
|
|
|
+ holder.mTextView.setText(item.mText);
|
|
|
+ holder.mLabelView.setText(item.mLabel);
|
|
|
|
|
|
if (item.getIconBitmap() != null) {
|
|
|
//Bitmap bitmap = Bitmap.createScaledBitmap(item.getIconBitmap(), 32, 32, true);
|
|
|
- holder.itemIcon.setImageBitmap(item.getIconBitmap());
|
|
|
+ holder.mItemIcon.setImageBitmap(item.getIconBitmap());
|
|
|
} else {
|
|
|
- holder.itemIcon.setImageBitmap(BitmapFactory.decodeResource(MainActivity.context.getResources(), R.drawable.ic_launcher));
|
|
|
+ holder.mItemIcon.setImageBitmap(BitmapFactory.decodeResource(MainActivity.context.getResources(), R.drawable.ic_launcher));
|
|
|
}
|
|
|
|
|
|
- holder.buttonEdit.setOnClickListener(new View.OnClickListener() {
|
|
|
+ // open the profile edit activity, if the edit button was pressed
|
|
|
+ holder.mButtonEdit.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- Intent intent = new Intent(context, ProfileEditActivity.class);
|
|
|
+ Intent intent = new Intent(mContext, ProfileEditActivity.class);
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
intent.putExtra("profile_id", item.mId);
|
|
|
- //intent.putExtra("profile", item);
|
|
|
- context.startActivity(intent);
|
|
|
+
|
|
|
+ mContext.startActivity(intent);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- holder.buttonDelete.setOnClickListener(new View.OnClickListener() {
|
|
|
+ // delete the profile, if the delete button was pressed. But shows an confirm dialog first.
|
|
|
+ holder.mButtonDelete.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
- new AlertDialog.Builder(context)
|
|
|
+ new AlertDialog.Builder(mContext)
|
|
|
.setTitle(R.string.delete_profile)
|
|
|
.setMessage(R.string.really_want_delete_profiel)
|
|
|
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
|
@@ -139,7 +174,7 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
|
|
|
|
|
|
profileManager.deleteProfile(item);
|
|
|
profileManager.getProfileListAdapter().notifyDataSetChanged();
|
|
|
- list.closeOpenedItems();
|
|
|
+ mList.closeOpenedItems();
|
|
|
}
|
|
|
})
|
|
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
|
@@ -147,7 +182,8 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
- holder.badgesContainer.removeAllViews();
|
|
|
+ // show all the active protocols of an profile in form of badges at the bottom of an profile list item
|
|
|
+ holder.mBadgesContainer.removeAllViews();
|
|
|
boolean hasProtocols = false;
|
|
|
|
|
|
List<String> profiles = new LinkedList<String>(item.getActiveProtocols());
|
|
@@ -158,35 +194,36 @@ public class ProfileManagerListAdapter extends ArrayAdapter<Profile> {
|
|
|
|
|
|
for (String protocol : profiles) {
|
|
|
hasProtocols = true;
|
|
|
- TextView textView = new TextView(new ContextThemeWrapper(context, R.style.ProfileManagerListBadge));
|
|
|
+ TextView textView = new TextView(new ContextThemeWrapper(mContext, R.style.ProfileManagerListBadge));
|
|
|
textView.setText(protocol);
|
|
|
- holder.badgesContainer.addView(textView);
|
|
|
+ holder.mBadgesContainer.addView(textView);
|
|
|
}
|
|
|
|
|
|
if (!hasProtocols) {
|
|
|
- holder.badgesContainer.setVisibility(View.INVISIBLE);
|
|
|
+ holder.mBadgesContainer.setVisibility(View.INVISIBLE);
|
|
|
} else {
|
|
|
- holder.badgesContainer.setVisibility(View.VISIBLE);
|
|
|
+ holder.mBadgesContainer.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
- RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.textView.getLayoutParams();
|
|
|
+ // do some styling when an profile is flagged as active
|
|
|
+ RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) holder.mTextView.getLayoutParams();
|
|
|
|
|
|
if (!item.mActivated) {
|
|
|
lp.setMargins(0, 0, 0, 0);
|
|
|
|
|
|
- holder.textView.setLayoutParams(lp);
|
|
|
+ holder.mTextView.setLayoutParams(lp);
|
|
|
|
|
|
- holder.imageSelected.setVisibility(View.GONE);
|
|
|
+ holder.mImageSelected.setVisibility(View.GONE);
|
|
|
} else {
|
|
|
- holder.imageSelected.setVisibility(View.VISIBLE);
|
|
|
+ holder.mImageSelected.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
if (!item.isEditable()) {
|
|
|
- holder.buttonDelete.setVisibility(View.GONE);
|
|
|
- holder.seperator.setVisibility(View.GONE);
|
|
|
+ holder.mButtonDelete.setVisibility(View.GONE);
|
|
|
+ holder.mSeperator.setVisibility(View.GONE);
|
|
|
} else {
|
|
|
- holder.buttonDelete.setVisibility(View.VISIBLE);
|
|
|
- holder.seperator.setVisibility(View.VISIBLE);
|
|
|
+ holder.mButtonDelete.setVisibility(View.VISIBLE);
|
|
|
+ holder.mSeperator.setVisibility(View.VISIBLE);
|
|
|
}
|
|
|
|
|
|
}
|