Fix crash in anonymous mode in MainActivity.

This commit is contained in:
Alex Ning 2020-10-16 11:12:22 +08:00
parent 79392bbeae
commit a6f2899b75

View File

@ -31,7 +31,6 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -64,7 +63,6 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Account.Account;
import ml.docilealligator.infinityforreddit.Account.AccountViewModel;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter;
@ -835,9 +833,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
accountViewModel = new ViewModelProvider(this,
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
accountViewModel.getAccountsExceptCurrentAccountLiveData().observe(this, adapter::changeAccountsDataset);
accountViewModel.getCurrentAccountLiveData().observe(this, new Observer<Account>() {
@Override
public void onChanged(Account account) {
accountViewModel.getCurrentAccountLiveData().observe(this, account -> {
if (account != null) {
adapter.updateKarma(account.getKarma());
}
});