Skip to content

Commit

Permalink
Fix codinguser#892 - Adding Accounts to Favorite Tab instantly after …
Browse files Browse the repository at this point in the history
…clicking Favorite Status Button.
  • Loading branch information
RasheeqZaman authored and Thumas committed Jun 20, 2021
1 parent 2bd5da1 commit b9d77a3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -433,7 +435,6 @@ public AccountsCursorLoader(Context context, String filter){

@Override
public Cursor loadInBackground() {

mDatabaseAdapter = AccountsDbAdapter.getInstance();
Cursor cursor;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
});
Expand All @@ -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() {
Expand Down

0 comments on commit b9d77a3

Please sign in to comment.