Пример #1
0
    /* (non-Javadoc)
     * manipulates the view for amount (setting expenses to red) and
     * category (indicate transfer direction with => or <=
     * @see android.widget.CursorAdapter#getView(int, android.view.View, android.view.ViewGroup)
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      convertView = super.getView(position, convertView, parent);
      ViewHolder viewHolder = (ViewHolder) convertView.getTag();
      TextView tv1 = viewHolder.amount;
      Cursor c = getCursor();
      c.moveToPosition(position);
      if (mAccount.getId() < 0) {
        int color = c.getInt(c.getColumnIndex("color"));
        viewHolder.colorAccount.setBackgroundColor(color);
      }
      long amount = c.getLong(columnIndexAmount);
      setColor(tv1, amount < 0);
      TextView tv2 = viewHolder.category;
      CharSequence catText = tv2.getText();
      if (DbUtils.getLongOrNull(c, columnIndexTransferPeer) != null) {
        catText = ((amount < 0) ? "=> " : "<= ") + catText;
      } else {
        Long catId = DbUtils.getLongOrNull(c, KEY_CATID);
        if (SPLIT_CATID.equals(catId)) catText = getString(R.string.split_transaction);
        else if (catId == null) {
          catText = getString(R.string.no_category_assigned);
        } else {
          String label_sub = c.getString(columnIndexLabelSub);
          if (label_sub != null && label_sub.length() > 0) {
            catText = catText + categorySeparator + label_sub;
          }
        }
      }
      String referenceNumber = c.getString(columnIndexReferenceNumber);
      if (referenceNumber != null && referenceNumber.length() > 0)
        catText = "(" + referenceNumber + ") " + catText;
      SpannableStringBuilder ssb;
      String comment = c.getString(columnIndexComment);
      if (comment != null && comment.length() > 0) {
        ssb = new SpannableStringBuilder(comment);
        ssb.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, comment.length(), 0);
        catText = TextUtils.concat(catText, commentSeparator, ssb);
      }
      String payee = c.getString(columnIndexPayee);
      if (payee != null && payee.length() > 0) {
        ssb = new SpannableStringBuilder(payee);
        ssb.setSpan(new UnderlineSpan(), 0, payee.length(), 0);
        catText = TextUtils.concat(catText, commentSeparator, ssb);
      }
      tv2.setText(catText);

      if (!mAccount.type.equals(Type.CASH)) {
        CrStatus status;
        try {
          status = CrStatus.valueOf(c.getString(columnIndexCrStatus));
        } catch (IllegalArgumentException ex) {
          status = CrStatus.UNRECONCILED;
        }
        viewHolder.color1.setBackgroundColor(status.color);
        viewHolder.colorContainer.setTag(status == CrStatus.RECONCILED ? -1 : getItemId(position));
      }
      return convertView;
    }
Пример #2
0
 @Override
 public boolean dispatchCommandMultiple(
     int command, SparseBooleanArray positions, Long[] itemIds) {
   FragmentManager fm = getActivity().getSupportFragmentManager();
   switch (command) {
     case R.id.DELETE_COMMAND:
       boolean hasReconciled = false;
       if (mAccount.type != Type.CASH) {
         for (int i = 0; i < positions.size(); i++) {
           mTransactionsCursor.moveToPosition(i);
           try {
             if (CrStatus.valueOf(mTransactionsCursor.getString(columnIndexCrStatus))
                 == CrStatus.RECONCILED) {
               hasReconciled = true;
               break;
             }
           } catch (IllegalArgumentException ex) {
             continue;
           }
         }
       }
       String message =
           getResources()
               .getQuantityString(
                   R.plurals.warning_delete_transaction, itemIds.length, itemIds.length);
       if (hasReconciled) {
         message += " " + getString(R.string.warning_delete_reconciled);
       }
       MessageDialogFragment.newInstance(
               R.string.dialog_title_warning_delete_transaction,
               message,
               new MessageDialogFragment.Button(
                   R.string.menu_delete, R.id.DELETE_COMMAND_DO, itemIds),
               null,
               new MessageDialogFragment.Button(
                   android.R.string.no, R.id.CANCEL_CALLBACK_COMMAND, null))
           .show(fm, "DELETE_TRANSACTION");
       return true;
     case R.id.CLONE_TRANSACTION_COMMAND:
       ((ProtectedFragmentActivity) getActivity())
           .startTaskExecution(TaskExecutionFragment.TASK_CLONE, itemIds, null, 0);
       break;
       // super is handling deactivation of mActionMode
   }
   return super.dispatchCommandMultiple(command, positions, itemIds);
 }