diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java index 23fe04876..64cc1e49d 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsActivity.java @@ -190,16 +190,16 @@ public Fragment getItem(int i) { switch (i) { case INDEX_RECENT_ACCOUNTS_FRAGMENT: - currentFragment = AccountsListFragment.newInstance(AccountsListFragment.DisplayMode.RECENT); + currentFragment = AccountsListFragment.newInstance(this, AccountsListFragment.DisplayMode.RECENT); break; case INDEX_FAVORITE_ACCOUNTS_FRAGMENT: - currentFragment = AccountsListFragment.newInstance(AccountsListFragment.DisplayMode.FAVORITES); + currentFragment = AccountsListFragment.newInstance(this, AccountsListFragment.DisplayMode.FAVORITES); break; case INDEX_TOP_LEVEL_ACCOUNTS_FRAGMENT: default: - currentFragment = AccountsListFragment.newInstance(AccountsListFragment.DisplayMode.TOP_LEVEL); + currentFragment = AccountsListFragment.newInstance(this, AccountsListFragment.DisplayMode.TOP_LEVEL); break; } @@ -235,6 +235,11 @@ public CharSequence getPageTitle(int position) { public int getCount() { return DEFAULT_NUM_PAGES; } + + @Override + public int getItemPosition(Object object){ + return POSITION_NONE; + } } public AccountsListFragment getCurrentAccountListFragment(){ diff --git a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java index 03237b975..9b0253540 100644 --- a/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java +++ b/app/src/main/java/org/gnucash/android/ui/account/AccountsListFragment.java @@ -25,9 +25,9 @@ import android.database.Cursor; import android.graphics.Color; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.LoaderManager.LoaderCallbacks; import android.support.v4.content.Loader; import android.support.v4.view.MenuItemCompat; @@ -85,6 +85,7 @@ public class AccountsListFragment extends Fragment implements AccountRecyclerAdapter mAccountRecyclerAdapter; @BindView(R.id.account_recycler_view) EmptyRecyclerView mRecyclerView; @BindView(R.id.empty_view) TextView mEmptyTextView; + private FragmentPagerAdapter accountViewPagerAdapter; /** * Describes the kinds of accounts that should be loaded in the accounts list. @@ -135,9 +136,10 @@ public enum DisplayMode { */ private android.support.v7.widget.SearchView mSearchView; - public static AccountsListFragment newInstance(DisplayMode displayMode){ + public static AccountsListFragment newInstance(FragmentPagerAdapter accountViewPagerAdapter, DisplayMode displayMode){ AccountsListFragment fragment = new AccountsListFragment(); fragment.mDisplayMode = displayMode; + fragment.accountViewPagerAdapter = accountViewPagerAdapter; return fragment; } @@ -433,7 +435,6 @@ public AccountsCursorLoader(Context context, String filter){ @Override public Cursor loadInBackground() { - mDatabaseAdapter = AccountsDbAdapter.getInstance(); Cursor cursor; @@ -496,6 +497,7 @@ public void onBindViewHolderCursor(final AccountViewHolder holder, final Cursor mAccountsDbAdapter = AccountsDbAdapter.getInstance(); holder.accoundId = mAccountsDbAdapter.getID(accountUID); + holder.accountName.setText(cursor.getString(cursor.getColumnIndexOrThrow(DatabaseSchema.AccountEntry.COLUMN_NAME))); int subAccountCount = mAccountsDbAdapter.getSubAccountCount(accountUID); @@ -570,7 +572,6 @@ public void onClick(View v) { holder.favoriteStatus.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - boolean isFavoriteAccount = mAccountsDbAdapter.isFavoriteAccount(accountUID); ContentValues contentValues = new ContentValues(); @@ -586,13 +587,13 @@ public void onClick(View v) { if (mDisplayMode == DisplayMode.FAVORITES) { refresh(); } + accountViewPagerAdapter.notifyDataSetChanged(); } }); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - onListItemClick(accountUID); } }); @@ -611,9 +612,7 @@ class AccountViewHolder extends RecyclerView.ViewHolder implements PopupMenu.OnM long accoundId; public AccountViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); optionsMenu.setOnClickListener(new View.OnClickListener() {