Java tutorial
/* * MonMa: Eine freie Android-Application fuer die Verwaltung privater Finanzen * * Copyright [2015] [Alexander Winkler, 2373 Dahme/Germany] * * This program is free software; you can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software Foundation; either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program; if * not, see <http://www.gnu.org/licenses/>. */ package de.aw.monma.reports; import android.database.Cursor; import android.os.Bundle; import android.support.v4.content.Loader; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.widget.CheckedTextView; import java.util.ArrayList; import de.aw.awlib.bottomsheet.AWBottomSheetDialog; import de.aw.awlib.database.AbstractDBHelper; import de.aw.monma.R; import de.aw.monma.database.DBDefinition; import de.aw.monma.enums.WPTyp; import de.aw.monma.gv.ReportStammdaten; /** * Zeigt Report zu Kategorien Wertpapiere */ public class ReportWPCats extends ReportGeldflussCats implements AWBottomSheetDialog.BottomSheetListener { private static final DBDefinition tbd = DBDefinition.ReportWP; private static final String groupBy = column_catname; private static final String orderBy = column_catname; private static final String[] projection = new String[] { column_catname, _id, AbstractDBHelper.SQLSumItem(column_amount) }; private ArrayList<Integer> selectedWPTypen = new ArrayList<>(); public static ReportWPCats newInstance(ReportStammdaten stammdaten) { Bundle args = new Bundle(); args.putParcelable(REPORTSTAMMDATEN, stammdaten); ReportWPCats fragment = new ReportWPCats(); fragment.setArguments(args); return fragment; } @Override protected String getSelection() { String selection = super.getSelection(); StringBuilder sb = new StringBuilder(selection).append(" AND ").append(column_wptyp).append(" IN ( "); if (selectedWPTypen != null && selectedWPTypen.size() > 0) { WPTyp wptyp = WPTyp.values()[selectedWPTypen.get(0)]; sb.append("'").append(wptyp.klartext).append("'"); for (Integer i = 1; i < selectedWPTypen.size(); i++) { wptyp = WPTyp.values()[selectedWPTypen.get(i)]; sb.append(", '").append(wptyp.klartext).append("' "); } } sb.append(")"); selection = sb.toString(); return selection; } @Override public void onBottomSheetItemClick(int arrayID, int position, Bundle extras, CheckedTextView view) { view.toggle(); if (view.isChecked()) { selectedWPTypen.add(position); } else { selectedWPTypen.remove((Integer) position); } getAdapter().notifyDataSetChanged(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); for (int i = 0; i < WPTyp.getKlartexte().length; i++) { selectedWPTypen.add(i); } setHasOptionsMenu(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.fragment_reportwp, menu); } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor c) { super.onLoadFinished(loader, c); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_item_reportWPTypen: AWBottomSheetDialog dlg = new AWBottomSheetDialog(getActivity(), R.id.menu_item_reportWPTypen, WPTyp.getKlartexte()); dlg.setCheckable(selectedWPTypen); dlg.setItemClickListener(this); dlg.show(); getAdapter().notifyDataSetChanged(); return true; default: return super.onOptionsItemSelected(item); } } @Override protected void setInternalArguments(Bundle args) { super.setInternalArguments(args); args.putParcelable(DBDEFINITION, tbd); args.putStringArray(PROJECTION, projection); args.putString(GROUPBY, groupBy); args.putString(ORDERBY, orderBy); } }