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.actions; import android.app.SearchManager; import android.content.Context; import android.content.Intent; import android.database.Cursor; import android.os.Bundle; import android.os.Parcelable; import android.support.v4.content.Loader; import android.support.v4.view.MenuItemCompat; import android.support.v7.widget.SearchView; import android.view.Menu; import android.view.MenuInflater; import android.view.View; import de.aw.awlib.recyclerview.AWCursorRecyclerViewFragment; import de.aw.awlib.recyclerview.AWLibViewHolder; import de.aw.monma.BR; import de.aw.monma.R; import de.aw.monma.actions.dialoge.DialogRenamePartner; import de.aw.monma.cash.ActivityCash; import de.aw.monma.database.DBDefinition; import de.aw.monma.gv.PartnerStammdaten; import de.aw.monma.monmamain.MonMaInterface; import de.aw.monma.monmamain.MonMaResultCodes; public class FragmentPayeeListe extends AWCursorRecyclerViewFragment implements MonMaInterface, MonMaResultCodes, SearchView.OnQueryTextListener { private final static String[] projection = { column_partnername, column_amount, _id }; private static final int layout = R.layout.awlib_default_recycler_view; private final static String selection = column_partnername + " LIKE ? "; private static DBDefinition tbd = DBDefinition.VFragmentPayeeListe; private static int viewHolderLayout = R.layout.payee_list_items; private int indexID; private Cursor mCurser; private String[] selectionArgs = new String[] { "%%" }; @Override public void onBindViewHolder(AWLibViewHolder holder, Cursor cursor, int position) { PartnerStammdaten item = new PartnerStammdaten(cursor); holder.setVariable(BR.partner, item); } @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(_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(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); super.onRecyclerItemClick(view, position, id); } @Override public boolean onRecyclerItemLongClick(View view, int position, long id) { super.onRecyclerItemLongClick(view, position, 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, viewHolderLayout); args.putStringArray(PROJECTION, projection); args.putString(SELECTION, selection); args.putStringArray(SELECTIONARGS, selectionArgs); } }