Ejemplo n.º 1
0
 @Override
 public boolean onMenuItemClick(MenuItem item) {
   Bundle extras = item.getIntent().getExtras();
   long id = extras.getLong(ID, NOID);
   switch (item.getItemId()) {
     case R.id.context_menu_item_deleteReport:
       DBDefinition reportTbd = DBDefinition.ReportBasisdaten;
       String selection = tbd.columnName(R.string._id) + " = " + id;
       DBHelper db = DBHelper.getInstance();
       db.delete(reportTbd, selection, null);
       return true;
     case R.id.context_menu_item_editReport:
       DialogReportDaten d = DialogReportDaten.newInstance(id);
       d.show(getSupportFragmentManager(), d.getTAG());
       return true;
   }
   return false;
 }
Ejemplo n.º 2
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.menu_item_SplitBuchung:
       mUmsatz.removeGegenbuchung();
       showSplitBuchung();
       return true;
     case R.id.menu_item_delete_Buchung:
       final DBHelper db = DBHelper.getInstance();
       AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
       // Add the buttons
       final SplittableCashUmsatz umsatz = mUmsatz;
       builder.setPositiveButton(
           R.string.btnDelete,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
               umsatz.delete(db);
               Snackbar.make(
                       getView(),
                       getString(R.string.awlib_datensatzDeleted),
                       Snackbar.LENGTH_SHORT)
                   .show();
               FragmentAbstractBuchung.super.onActionFinishClicked();
             }
           });
       builder.setNegativeButton(
           R.string.btnVerwerfen,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
               // nix tun
             }
           });
       builder.setTitle(R.string.BankUmsatzLoeschen);
       AlertDialog dialog = builder.create();
       dialog.show();
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
Ejemplo n.º 3
0
 /**
  * Wenn 'Save' gewaehlt wurde, wird aus Payee die ID gelesen und in R.string.column_wpid
  * eingefuegt. Ist diese ID nicht belegt, wurde ein (neuer) Text eingegeben. Dieser wird als
  * Partner angelegt und dessen ID benutzt
  */
 @Override
 protected void onActionFinishClicked() {
   MonMaAutoCompleteTextView actv =
       (MonMaAutoCompleteTextView) getView().findViewById(R.id.actvPayee);
   long id = actv.getSelectionID();
   if (id == NOID) {
     String partnername = actv.getText().toString();
     mUmsatz.put(R.string.column_partnername, partnername);
   } else {
     mUmsatz.put(R.string.column_wpid, id);
   }
   DBHelper db = DBHelper.getInstance();
   if (mUmsatz.isInserted()) {
     mUmsatz.update(db);
   } else {
     mUmsatz.insert(db);
   }
   Snackbar.make(getView(), getString(R.string.awlib_datensatzSaved), Snackbar.LENGTH_SHORT)
       .show();
   super.onActionFinishClicked();
 }
Ejemplo n.º 4
0
/** Uebersicht ueber alle nicht-ausgeblendeten Depots. */
public class FragmentDepots extends AWCursorRecyclerViewFragment {
  private static final int layout = R.layout.awlib_default_recycler_view;
  private static final int viewHolderLayout = R.layout.depotuebersicht_item;
  private static final DBDefinition tbd = DBDefinition.WPBestandView;
  private static final int[] viewResIDs =
      new int[] {
        R.id.tvUebersichtName,
        R.id.tvUebersichtSaldo,
        R.id.tvEinstandsPreis,
        R.id.tvGewinnVerlust,
        R.id.tvGewinnSteuerfrei,
        R.id.tvGewinnVerlustProzent,
      };
  private static final String[] projection =
      tbd.columnNames(
          new int[] {R.string.column_accountID},
          DBHelper.getInstance().SQLSumItem(R.string.column_marktwert),
          DBHelper.getInstance().SQLSumItem(R.string.column_bruttoumsatz),
          DBHelper.getInstance().SQLSumItem(R.string.column_gewinn),
          DBHelper.getInstance().SQLSumItem(R.string.column_gewinn_stfr));
  private static final String selection = " NOT " + tbd.columnName(R.string.column_ausgeblendet);
  private static String orderBy = tbd.columnName(R.string.column_accountID);
  private static String groupBy = tbd.columnName(R.string.column_accountID);
  private int columnAccountID;
  private long mEinstand;
  private long mGewinn;

  @Override
  public AWCursorRecyclerViewAdapter getCursorAdapter() {
    return new FragmentDepotsCursorAdapter(this);
  }

  @Override
  protected boolean onBindView(
      AWLibViewHolder holder, View view, int resID, Cursor cursor, int cursorPosition) {
    switch (resID) {
      case R.id.tvEinstandsPreis:
        mEinstand = cursor.getLong(cursorPosition);
        AWTextCurrency tc = (AWTextCurrency) view;
        tc.setValue(mEinstand);
        return true;
      case R.id.tvGewinnVerlust:
        mGewinn = cursor.getLong(cursorPosition);
        tc = (AWTextCurrency) view;
        tc.setValue(mGewinn);
        return true;
      case R.id.tvUebersichtSaldo:
      case R.id.tvGewinnSteuerfrei:
        tc = (AWTextCurrency) view;
        tc.setValue(cursor.getLong(cursorPosition));
        return true;
      case R.id.tvGewinnVerlustProzent:
        TextView tv = (TextView) view;
        if (mEinstand != 0) {
          long mGewinnPercent = mGewinn * 10000 / mEinstand;
          tv.setText(DBConvert.convertPercent(mGewinnPercent));
        }
        return true;
      case R.id.tvUebersichtName:
        int mAccountID;
        tv = (TextView) view;
        mAccountID = cursor.getInt(columnAccountID);
        if (mAccountID == NOID) {
          tv.setText(getString(R.string.tvMarktwert));
        } else {
          tv.setText(Account.getAccountName(mAccountID));
        }
        return true;
      default:
        return super.onBindView(holder, view, resID, cursor, cursorPosition);
    }
  }

  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    super.onLoadFinished(loader, cursor);
    columnAccountID = cursor.getColumnIndexOrThrow(tbd.columnName(R.string.column_accountID));
  }

  @Override
  protected void setInternalArguments(Bundle args) {
    super.setInternalArguments(args);
    args.putString(SELECTION, selection);
    args.putIntArray(VIEWRESIDS, viewResIDs);
    args.putStringArray(PROJECTION, projection);
    args.putString(GROUPBY, groupBy);
    args.putString(ORDERBY, orderBy);
    args.putInt(LAYOUT, layout);
    args.putInt(VIEWHOLDERLAYOUT, viewHolderLayout);
    args.putParcelable(DBDEFINITION, tbd);
  }

  private class FragmentDepotsCursorAdapter extends AWCursorRecyclerViewAdapter
      implements AWWindowedCursor.DataBinder {
    private AWWindowedCursor mCursor = new AWWindowedCursor(projection);
    private long mEinstandGesamt;
    private long mGewinnGesamt;
    private long mSaldoGesamt;
    private long mStrfrGesamt;
    private int rowKT;

    FragmentDepotsCursorAdapter(@NonNull AWCursorRecyclerViewFragment binder) {
      super(binder, binder.getString(R.string.column_accountID));
      mCursor.setDataBinder(this);
    }

    @Override
    public void allocRow(CursorWindow data, Cursor theCursor) {
      if (rowKT == -1) {
        data.allocRow();
        rowKT = data.getNumRows() - 1;
        data.putLong(NOID, rowKT, 0);
      }
    }

    @Override
    public boolean copyValue(
        String mColum, int position, Cursor theCursor, CursorWindow data, int dataRow) {
      switch (position) {
        case 1:
          long saldo = theCursor.getLong(position);
          mSaldoGesamt += saldo;
          data.putLong(mSaldoGesamt, rowKT, position);
          break;
        case 2:
          mEinstand = theCursor.getLong(position);
          mEinstandGesamt += mEinstand;
          data.putLong(mEinstandGesamt, rowKT, position);
          break;
        case 3:
          mGewinn = theCursor.getLong(position);
          mGewinnGesamt += mGewinn;
          data.putLong(mGewinnGesamt, rowKT, position);
          break;
        case 4:
          long gewStfr = theCursor.getLong(position);
          mStrfrGesamt += gewStfr;
          data.putLong(mStrfrGesamt, rowKT, position);
          break;
      }
      return false;
    }

    @Override
    public void onSetWindow(CursorWindow data) {}

    @Override
    public Cursor swapCursor(Cursor newCursor) {
      if (newCursor == null) {
        return null;
      }
      mStrfrGesamt = 0L;
      mEinstandGesamt = 0L;
      mGewinnGesamt = 0L;
      mSaldoGesamt = 0L;
      rowKT = -1;
      mCursor.copyValues(newCursor);
      return super.swapCursor(mCursor);
    }
  }
}