aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountRepository.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountViewModel.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java5
4 files changed, 25 insertions, 0 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountRepository.java
index 69ad4088..70fccd02 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountRepository.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountRepository.java
@@ -11,16 +11,22 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class AccountRepository {
private AccountDao mAccountDao;
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
+ private LiveData<Account> mCurrentAccountLiveData;
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
mAccountDao = redditDataRoomDatabase.accountDao();
mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData();
+ mCurrentAccountLiveData = mAccountDao.getCurrentAccountLiveData();
}
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
return mAccountsExceptCurrentAccountLiveData;
}
+ public LiveData<Account> getCurrentAccountLiveData() {
+ return mCurrentAccountLiveData;
+ }
+
public void insert(Account Account) {
new InsertAsyncTask(mAccountDao).execute(Account);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountViewModel.java
index 55e805e8..0eab1570 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountViewModel.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Account/AccountViewModel.java
@@ -15,17 +15,23 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
public class AccountViewModel extends AndroidViewModel {
private AccountRepository mAccountRepository;
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
+ private LiveData<Account> mCurrentAccountLiveData;
public AccountViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
super(application);
mAccountRepository = new AccountRepository(redditDataRoomDatabase, id);
mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData();
+ mCurrentAccountLiveData = mAccountRepository.getCurrentAccountLiveData();
}
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
return mAccountsExceptCurrentAccountLiveData;
}
+ public LiveData<Account> getCurrentAccountLiveData() {
+ return mCurrentAccountLiveData;
+ }
+
public void insert(Account userData) {
mAccountRepository.insert(userData);
}
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 90302bea..4d42621e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -31,6 +31,7 @@ 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;
@@ -63,6 +64,7 @@ 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;
@@ -833,6 +835,12 @@ 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) {
+ adapter.updateKarma(account.getKarma());
+ }
+ });
if (getIntent().hasExtra(EXTRA_POST_TYPE)) {
String type = getIntent().getStringExtra(EXTRA_POST_TYPE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java
index d8147480..cdb73759 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/NavigationDrawerRecyclerViewAdapter.java
@@ -546,6 +546,11 @@ public class NavigationDrawerRecyclerViewAdapter extends RecyclerView.Adapter<Re
}
}
+ public void updateKarma(int karma) {
+ this.karma = karma;
+ notifyItemChanged(0);
+ }
+
public void setNSFWEnabled(boolean isNSFWEnabled) {
this.isNSFWEnabled = isNSFWEnabled;
if (isInMainPage) {