public void selectCategory(int category_id, boolean forceUpdate) { if (mCategoryId != category_id || forceUpdate) { mCategoryId = category_id; if ((mAdapter = getAdapter(mCategoryId)) == null) { mAdapter = new MainListAdapter( getActivity(), AccountManager.getInstance().getAccountsByCategory(mCategoryId), Application.getThemedIcons(), R.drawable.pb_unknown); mListView.postDelayed( new Runnable() { @Override public void run() { mAdapter.enableAnimation(false); } }, 100); cacheAdapter(mCategoryId, mAdapter); } mAdapter.setListener(this); mListView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); mToBeRemoved = new int[mAdapter.getCount()]; ((TextView) mListView.getEmptyView()).setText(R.string.no_accounts); mCategoryIcon = -1; mCategoryName = null; } }
public void setSearch(ArrayList<AccountManager.Account> result) { mAdapter = new MainListAdapter( getActivity(), result, Application.getThemedIcons(), R.drawable.pb_unknown); mAdapter.enableAnimation(false); mAdapter.setListener(this); mListView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); mToBeRemoved = new int[mAdapter.getCount()]; ((TextView) mListView.getEmptyView()).setText(R.string.empty_search); }
private void updateListForEditing() { if (mCategoryId != AccountManager.DEFAULT_CATEGORY_ID) { ArrayList<AccountManager.Account> accounts = AccountManager.getInstance().getAccountsByCategory(AccountManager.DEFAULT_CATEGORY_ID); if (mCategoryId == AccountManager.ALL_CATEGORY_ID) { mAdapter.addList(accounts, true); } else { mAdapter.markAll(mListView); mAdapter.addList(accounts, false); mAdapter.notifyDataSetChanged(); } } }
public void animateDeletion() { int firstVisiblePosition = mListView.getFirstVisiblePosition(); int end = mRemoveCount - 1; View v; int viewHeight = 0; mAdapter.markDeletion(mToBeRemoved, mRemoveCount, true); for (int i = end; i >= 0; --i) { v = mListView.getChildAt(mToBeRemoved[i] - firstVisiblePosition); if (v != null) { viewHeight = v.getMeasuredHeight(); mAdapter.animateDeletion(v, mToBeRemoved[i]); } } showDeleteSnackbar((AppCompatActivity) getActivity(), mRemoveCount, viewHeight); }
public void onDelete(int accountId) { int firstVisiblePos = mListView.getFirstVisiblePosition(); int removePos = mAdapter.getItemPosition(accountId, firstVisiblePos); mToBeRemoved[0] = removePos; mRemoveCount = 1; animateDeletion(); }
private void reset() { int begin = mListView.getFirstVisiblePosition(); int end = mListView.getLastVisiblePosition(); if (mAdapter.cancelSelection(mListView, begin, end) < 1 && mFromMenu) { mActionMode.finish(); } }
protected void saveCategory() { if (mCategoryId <= AccountManager.DEFAULT_CATEGORY_ID) { mCategoryId = AccountManager.getInstance().addCategory(mCategoryIcon, mCategoryName); } else { AccountManager.getInstance().setCategory(mCategoryId, mCategoryName, mCategoryIcon); } Application.showToast(getActivity(), R.string.category_saved, Toast.LENGTH_SHORT); mAdapter.moveData(mCategoryId); mListener.onCategorySaved(); }
private void updateStatsMode() { switch (currentStatsMode) { case PERCENT: statsModeText.setText(this.getString(R.string.daily)); statsModeIcon.setImageDrawable(getResources().getDrawable(R.drawable.icon_plusminus)); break; case DAY_CHANGES: statsModeText.setText(this.getString(R.string.percentage)); statsModeIcon.setImageDrawable(getResources().getDrawable(R.drawable.icon_percent)); break; default: break; } adapter.setStatsMode(currentStatsMode); adapter.notifyDataSetChanged(); Preferences.saveStatsMode(currentStatsMode, Main.this); }
private void updateMainList(List<AppInfo> apps) { if (apps != null) { if (apps.size() > 0) { footer.setVisibility(View.VISIBLE); String autosyncSet = Preferences.getAutosyncSet(Main.this, accountname); if (autosyncSet == null) { // set autosync default value AutosyncHandlerFactory.getInstance(Main.this) .setAutosyncPeriod(accountname, AutosyncHandler.DEFAULT_PERIOD); Preferences.saveAutosyncSet(Main.this, accountname); } } adapter.setAppInfos(apps); adapter.notifyDataSetChanged(); Date lastUpdateDate = null; for (int i = 0; i < apps.size(); i++) { Date dateObject = apps.get(i).getLastUpdate(); if (lastUpdateDate == null || lastUpdateDate.before(dateObject)) { lastUpdateDate = dateObject; } } if (lastUpdateDate != null) { statusText.setText("last update: " + ContentAdapter.formatDate(lastUpdateDate)); } } if (!(R.id.main_app_list == mainViewSwitcher.getCurrentView().getId())) { mainViewSwitcher.showNext(); } }
@Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.action_delete: mRemoveCount = mAdapter.getSelected(mToBeRemoved); mFromMenu = true; reset(); return true; default: mFromMenu = true; reset(); return true; } }
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int pos, long id) { mAdapter.onLongClick(view, pos); return true; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); mListView = (ListView) rootView.findViewById(android.R.id.list); if ((mAdapter = getAdapter(mCategoryId)) == null) { mAdapter = new MainListAdapter( getActivity(), AccountManager.getInstance().getAccountsByCategory(mCategoryId), Application.getThemedIcons(), R.drawable.pb_unknown); mListView.postDelayed( new Runnable() { @Override public void run() { mAdapter.enableAnimation(false); } }, 100); cacheAdapter(mCategoryId, mAdapter); } mAdapter.setListener(this); mListView.setAdapter(mAdapter); mListView.setEmptyView(rootView.findViewById(android.R.id.empty)); mListView.setOnItemClickListener(this); mListView.setOnItemLongClickListener(this); mToBeRemoved = new int[mAdapter.getCount()]; mFab = (ImageButton) rootView.findViewById(R.id.fab); mFab.setOnClickListener(this); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { LayerDrawable background = (LayerDrawable) mFab.getBackground(); background .getDrawable(1) .setColorFilter(C.ThemedColors[C.colorAccent], PorterDuff.Mode.SRC_ATOP); } if (!getResources().getBoolean(R.bool.snackbar_left_align)) { mFabToPush = (int) (getResources().getDimension(R.dimen.snackbar_height_single) + 0.5f); } else { mFabToPush = 0; } mCategoryEditView = rootView.findViewById(R.id.category_editor); EditText editCategoryName = (EditText) rootView.findViewById(R.id.category_name); editCategoryName.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) {} @Override public void afterTextChanged(Editable s) { if (mActionMode != null) { mCategoryName = s.toString(); mCategorySavable = mCategoryName.length() > 0; mActionMode.invalidate(); } } }); if (mIsEditing) { mIsEditing = false; editCategory(); } else if (mSelectionMode) { mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mActionModeCallback); } return rootView; }
@Override public Object onRetainNonConfigurationInstance() { return adapter.getAppInfos(); }