mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-01 13:57:10 +01:00
Update karma in the navigation drawer in MainActivity.
This commit is contained in:
parent
64d56f930d
commit
d6d4e230a9
@ -11,16 +11,22 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|||||||
public class AccountRepository {
|
public class AccountRepository {
|
||||||
private AccountDao mAccountDao;
|
private AccountDao mAccountDao;
|
||||||
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
||||||
|
private LiveData<Account> mCurrentAccountLiveData;
|
||||||
|
|
||||||
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
mAccountDao = redditDataRoomDatabase.accountDao();
|
mAccountDao = redditDataRoomDatabase.accountDao();
|
||||||
mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData();
|
mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData();
|
||||||
|
mCurrentAccountLiveData = mAccountDao.getCurrentAccountLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
||||||
return mAccountsExceptCurrentAccountLiveData;
|
return mAccountsExceptCurrentAccountLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Account> getCurrentAccountLiveData() {
|
||||||
|
return mCurrentAccountLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
public void insert(Account Account) {
|
public void insert(Account Account) {
|
||||||
new InsertAsyncTask(mAccountDao).execute(Account);
|
new InsertAsyncTask(mAccountDao).execute(Account);
|
||||||
}
|
}
|
||||||
|
@ -15,17 +15,23 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|||||||
public class AccountViewModel extends AndroidViewModel {
|
public class AccountViewModel extends AndroidViewModel {
|
||||||
private AccountRepository mAccountRepository;
|
private AccountRepository mAccountRepository;
|
||||||
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
||||||
|
private LiveData<Account> mCurrentAccountLiveData;
|
||||||
|
|
||||||
public AccountViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
public AccountViewModel(Application application, RedditDataRoomDatabase redditDataRoomDatabase, String id) {
|
||||||
super(application);
|
super(application);
|
||||||
mAccountRepository = new AccountRepository(redditDataRoomDatabase, id);
|
mAccountRepository = new AccountRepository(redditDataRoomDatabase, id);
|
||||||
mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData();
|
mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData();
|
||||||
|
mCurrentAccountLiveData = mAccountRepository.getCurrentAccountLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
||||||
return mAccountsExceptCurrentAccountLiveData;
|
return mAccountsExceptCurrentAccountLiveData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Account> getCurrentAccountLiveData() {
|
||||||
|
return mCurrentAccountLiveData;
|
||||||
|
}
|
||||||
|
|
||||||
public void insert(Account userData) {
|
public void insert(Account userData) {
|
||||||
mAccountRepository.insert(userData);
|
mAccountRepository.insert(userData);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import androidx.drawerlayout.widget.DrawerLayout;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.lifecycle.Lifecycle;
|
import androidx.lifecycle.Lifecycle;
|
||||||
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@ -63,6 +64,7 @@ import javax.inject.Named;
|
|||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
import ml.docilealligator.infinityforreddit.Account.Account;
|
||||||
import ml.docilealligator.infinityforreddit.Account.AccountViewModel;
|
import ml.docilealligator.infinityforreddit.Account.AccountViewModel;
|
||||||
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
|
||||||
import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter;
|
import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter;
|
||||||
@ -833,6 +835,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
|
|||||||
accountViewModel = new ViewModelProvider(this,
|
accountViewModel = new ViewModelProvider(this,
|
||||||
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
|
new AccountViewModel.Factory(getApplication(), mRedditDataRoomDatabase, mAccountName)).get(AccountViewModel.class);
|
||||||
accountViewModel.getAccountsExceptCurrentAccountLiveData().observe(this, adapter::changeAccountsDataset);
|
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)) {
|
if (getIntent().hasExtra(EXTRA_POST_TYPE)) {
|
||||||
String type = getIntent().getStringExtra(EXTRA_POST_TYPE);
|
String type = getIntent().getStringExtra(EXTRA_POST_TYPE);
|
||||||
|
@ -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) {
|
public void setNSFWEnabled(boolean isNSFWEnabled) {
|
||||||
this.isNSFWEnabled = isNSFWEnabled;
|
this.isNSFWEnabled = isNSFWEnabled;
|
||||||
if (isInMainPage) {
|
if (isInMainPage) {
|
||||||
|
Loading…
Reference in New Issue
Block a user