From a6f2899b758b689b6a5b018803bb7abe166a57a2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 16 Oct 2020 11:12:22 +0800 Subject: [PATCH] Fix crash in anonymous mode in MainActivity. --- .../infinityforreddit/Activity/MainActivity.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index 4d42621e..79481f1e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -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() { - @Override - public void onChanged(Account account) { + accountViewModel.getCurrentAccountLiveData().observe(this, account -> { + if (account != null) { adapter.updateKarma(account.getKarma()); } });