Пример #1
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);
    }
  }
}
Пример #2
0
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
   mCurser = cursor;
   indexID = mCurser.getColumnIndexOrThrow(tbd.columnName(R.string._id));
   super.onLoadFinished(loader, cursor);
 }
Пример #3
0
 @Override
 public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
   super.onLoadFinished(loader, cursor);
   columnAccountID = cursor.getColumnIndexOrThrow(tbd.columnName(R.string.column_accountID));
 }
Пример #4
0
public class FragmentPayeeListe extends AWCursorRecyclerViewFragment
    implements MonMaInterface, MonMaResultCodes, SearchView.OnQueryTextListener {
  private static final int[] fromResId = {R.string.column_partnername, R.string.column_amount};
  private static final int layout = R.layout.awlib_default_recycler_view;
  private static final int[] viewResId = {R.id.tvPayeeName, R.id.tcSummePayee};
  private static int listLayout = R.layout.payee_list_items;
  private static DBDefinition tbd = DBDefinition.VFragmentPayeeListe;
  private static final String selection = tbd.columnName(R.string.column_partnername) + " LIKE ? ";
  private int indexID;
  private Cursor mCurser;
  private String[] selectionArgs = new String[] {"%%"};

  @Override
  protected boolean onBindView(
      AWLibViewHolder holder, View view, int resID, Cursor cursor, int cursorPosition) {
    switch (resID) {
      case R.id.tcSummePayee:
        AWTextCurrency tc = (AWTextCurrency) view;
        tc.setValue(cursor.getLong(cursorPosition));
        return true;
      case R.id.tvPayeeName:
        String value = cursor.getString(cursorPosition);
        if (TextUtils.isEmpty(value)) {
          TextView tv = (TextView) view;
          tv.setText(R.string.NoPayee);
          return true;
        }
    }
    return super.onBindView(holder, view, resID, cursor, cursorPosition);
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
  }

  /** In der ActionBar die SearchView initialisieren */
  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_wplist, menu);
    SearchManager searchManager =
        (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
        (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_List_search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnQueryTextListener(this);
    super.onCreateOptionsMenu(menu, inflater);
  }

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

  @Override
  public void onLoaderReset(Loader<Cursor> p1) {
    super.onLoaderReset(p1);
    mCurser = null;
  }

  /**
   * Wird ein Wertpapier ueber das SearchWidget gesucht, wird bei jedem neuen Buchstaben die Liste
   * aktualisiert.
   *
   * @return immer true
   */
  @Override
  public boolean onQueryTextChange(String newText) {
    String[] selectionArgs = new String[] {"%" + newText + "%"};
    args.putStringArray(SELECTIONARGS, selectionArgs);
    startOrRestartLoader(layout, args);
    return true;
  }

  /**
   * Wird ein Wertpapier ueber das SearchWidget gesucht, wird bei Click auf Oeffnen die Liste der
   * Buchungen angezeigt, wenn nur ganau ein WP angezeigt wird. Ansonsten wird nichts gemacht.
   *
   * @return immer true
   */
  @Override
  public boolean onQueryTextSubmit(String query) {
    if (mCurser != null && mCurser.getCount() == 1) {
      Intent intent = new Intent(getActivity(), ActivityCash.class);
      intent.putExtra(WPID, mCurser.getLong(indexID));
      intent.putExtra(ACTION, (Parcelable) Action.ShowPayeeBuchungen);
      getActivity().startActivity(intent);
    }
    return true;
  }

  /** Anzeige der Buchungen des Empfaengers/Auftraggebers */
  @Override
  public void onRecyclerItemClick(RecyclerView recyclerView, View view, int position, long id) {
    Intent intent = new Intent(getActivity(), ActivityCash.class);
    intent.putExtra(WPID, id);
    intent.putExtra(ACTION, (Parcelable) Action.ShowPayeeBuchungen);
    getActivity().startActivity(intent);
  }

  @Override
  public boolean onRecyclerItemLongClick(
      RecyclerView recyclerView, View view, int position, long id) {
    DialogRenamePartner f = DialogRenamePartner.newInstance(id);
    f.show(getFragmentManager(), null);
    return true;
  }

  @Override
  protected void setInternalArguments(Bundle args) {
    super.setInternalArguments(args);
    args.putParcelable(DBDEFINITION, tbd);
    args.putInt(LAYOUT, layout);
    args.putInt(VIEWHOLDERLAYOUT, listLayout);
    args.putIntArray(VIEWRESIDS, viewResId);
    args.putIntArray(FROMRESIDS, fromResId);
    args.putString(SELECTION, selection);
    args.putStringArray(SELECTIONARGS, selectionArgs);
  }
}