@Override public void onResume() { super.onResume(); // Showing/hiding back button if (getActivity() instanceof SherlockFragmentActivity) { ((SherlockFragmentActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(true); ((SherlockFragmentActivity) getActivity()) .getSupportActionBar() .setDisplayHomeAsUpEnabled(true); // Setting visualized ActionBar title String title = UserProducedDataRender.renderActionBarTitle(getActivity(), mCategory); ((SherlockFragmentActivity) getActivity()).getSupportActionBar().setTitle(title); } // Check if save button has to be visible or not hideOrShowSaveButton(); // Canceling any active task cancelAnyActiveTask(); // Starting new task for user produced data mUPDataTask = new UserProducedDataAsyncTask(); mUPDataTask.execute(); }
@Override public View getView(int position, View convertView, ViewGroup parent) { Holder holder = null; if (convertView == null) { // Inflate View for ListItem convertView = LayoutInflater.from(getActivity()).inflate(R.layout.item_user_produced_data, null); // Create Holder holder = new Holder(); // Find items in view holder.titleTextView = (TextView) convertView.findViewById(R.id.category_element); holder.eyeButton = (ImageButton) convertView.findViewById(R.id.eye_button); holder.cherryButton = (ImageButton) convertView.findViewById(R.id.cherry_button); // add Holder to View convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); } // Getting item final UPItem item = getItem(position); // Setting label UserProducedDataRender.renderTitle(holder.titleTextView, item.userProducedData); // Checking if we have to hide or visualize category boolean updated = mUpdatedElements.contains(item.userProducedData.getId()); boolean cherried = mCherryElements.contains(item.userProducedData.getId()); if (updated ? !item.isShown : item.isShown) { // Setting background convertView.setBackgroundResource(R.drawable.default_view_background); holder.titleTextView.setTextColor(getResources().getColor(R.color.black)); holder.eyeButton.setImageResource(R.drawable.ic_eye_selected); holder.eyeButton.setTag("selected"); if (cherried ? !item.isCherry : item.isCherry) { holder.cherryButton.setImageResource(R.drawable.ic_cherry_selected); } else { holder.cherryButton.setImageResource(R.drawable.ic_cherry_unselected); } } else { // Setting background convertView.setBackgroundResource(R.drawable.gray_view_background); holder.titleTextView.setTextColor(getResources().getColor(R.color.gray)); holder.eyeButton.setImageResource(R.drawable.ic_eye_unselected); holder.eyeButton.setTag("unselected"); holder.cherryButton.setImageResource(R.drawable.ic_cherry_unselected); } // Checking edit mode if (mEditEnabled) { holder.eyeButton.setVisibility(View.VISIBLE); holder.cherryButton.setVisibility(View.VISIBLE); holder.cherryButton.setEnabled(true); // Setting listeners holder.eyeButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // Checking if the item is sys_entry, if true show // dialog alert if (((String) v.getTag()).equalsIgnoreCase("unselected") && item.userProducedData.type.equalsIgnoreCase(Constants.SYS_SIMPLE)) { ConfirmDialogFragment confirmDialogFragment = new ConfirmDialogFragment() { @Override public void onClick(boolean positive) { if (positive) { if (mUpdatedElements.contains(item.userProducedData.getId())) { mUpdatedElements.remove(item.userProducedData.getId()); } else { mUpdatedElements.add(item.userProducedData.getId()); } // Updating UI notifyDataSetChanged(); // Hiding or show save button hideOrShowSaveButton(); } dismiss(); } }; // Preparing arguments Bundle args = ConfirmDialogFragment.prepareArguments( R.string.be_careful, R.string.sure_to_show_these_data, R.string.yes_continue, R.string.cancel); ConfirmDialogFragment.show(getSherlockActivity(), confirmDialogFragment, args); } else { // Checking if the user is trying to modify an // existent update if (mUpdatedElements.contains(item.userProducedData.getId())) { mUpdatedElements.remove(item.userProducedData.getId()); } else { mUpdatedElements.add(item.userProducedData.getId()); } // Updating UI notifyDataSetChanged(); // Hiding or show save button hideOrShowSaveButton(); } } }); holder.cherryButton.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { boolean updated = mUpdatedElements.contains(item.userProducedData.getId()); if (updated ? !item.isShown : item.isShown) { // Checking if the user is trying to modify an // existent cherry element if (mCherryElements.contains(item.userProducedData.getId())) { mCherryElements.remove(item.userProducedData.getId()); } else { mCherryElements.add(item.userProducedData.getId()); } // Updating UI notifyDataSetChanged(); // Hiding or show save button hideOrShowSaveButton(); } else { // Showing a toast to user that notifies him that // item is not shown ToastBuilder.showShort(getActivity(), R.string.item_is_not_shown); } } }); } else { holder.eyeButton.setVisibility(View.GONE); holder.cherryButton.setEnabled(false); // Checking if it's a cherry item if (cherried ? !item.isCherry : item.isCherry) { holder.cherryButton.setVisibility(View.VISIBLE); } else { holder.cherryButton.setVisibility(View.GONE); } } return convertView; }