mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-07 11:17:25 +01:00
Finish MainActivity if clicking a notification for another user.
This commit is contained in:
parent
5bf002629d
commit
556047aa42
@ -37,6 +37,9 @@ public interface AccountDao {
|
|||||||
@Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1")
|
@Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1")
|
||||||
Account getCurrentAccount();
|
Account getCurrentAccount();
|
||||||
|
|
||||||
|
@Query("SELECT * FROM accounts WHERE is_current_user = 1 LIMIT 1")
|
||||||
|
LiveData<Account> getCurrentAccountLiveData();
|
||||||
|
|
||||||
@Query("UPDATE accounts SET profile_image_url = :profileImageUrl, banner_image_url = :bannerImageUrl, " +
|
@Query("UPDATE accounts SET profile_image_url = :profileImageUrl, banner_image_url = :bannerImageUrl, " +
|
||||||
"karma = :karma WHERE username = :username")
|
"karma = :karma WHERE username = :username")
|
||||||
void updateAccountInfo(String username, String profileImageUrl, String bannerImageUrl, int karma);
|
void updateAccountInfo(String username, String profileImageUrl, String bannerImageUrl, int karma);
|
||||||
|
@ -10,19 +10,13 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|||||||
|
|
||||||
public class AccountRepository {
|
public class AccountRepository {
|
||||||
private AccountDao mAccountDao;
|
private AccountDao mAccountDao;
|
||||||
private LiveData<Account> mAccountLiveData;
|
|
||||||
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
||||||
|
|
||||||
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
AccountRepository(RedditDataRoomDatabase redditDataRoomDatabase, String username) {
|
||||||
mAccountDao = redditDataRoomDatabase.accountDao();
|
mAccountDao = redditDataRoomDatabase.accountDao();
|
||||||
mAccountLiveData = mAccountDao.getAccountLiveData(username);
|
|
||||||
mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData();
|
mAccountsExceptCurrentAccountLiveData = mAccountDao.getAccountsExceptCurrentAccountLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
LiveData<Account> getAccountLiveData() {
|
|
||||||
return mAccountLiveData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
||||||
return mAccountsExceptCurrentAccountLiveData;
|
return mAccountsExceptCurrentAccountLiveData;
|
||||||
}
|
}
|
||||||
|
@ -14,20 +14,14 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
|||||||
|
|
||||||
public class AccountViewModel extends AndroidViewModel {
|
public class AccountViewModel extends AndroidViewModel {
|
||||||
private AccountRepository mAccountRepository;
|
private AccountRepository mAccountRepository;
|
||||||
private LiveData<Account> mAccountLiveData;
|
|
||||||
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
private LiveData<List<Account>> mAccountsExceptCurrentAccountLiveData;
|
||||||
|
|
||||||
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);
|
||||||
mAccountLiveData = mAccountRepository.getAccountLiveData();
|
|
||||||
mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData();
|
mAccountsExceptCurrentAccountLiveData = mAccountRepository.getAccountsExceptCurrentAccountLiveData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<Account> getAccountLiveData() {
|
|
||||||
return mAccountLiveData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
public LiveData<List<Account>> getAccountsExceptCurrentAccountLiveData() {
|
||||||
return mAccountsExceptCurrentAccountLiveData;
|
return mAccountsExceptCurrentAccountLiveData;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,9 @@ import com.google.android.material.appbar.CollapsingToolbarLayout;
|
|||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
@ -85,9 +88,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
@BindView(R.id.collapsing_toolbar_layout_main_activity) CollapsingToolbarLayout collapsingToolbarLayout;
|
@BindView(R.id.collapsing_toolbar_layout_main_activity) CollapsingToolbarLayout collapsingToolbarLayout;
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
@BindView(R.id.all_drawer_items_linear_layout_main_activity) LinearLayout allDrawerItemsLinearLayout;
|
@BindView(R.id.all_drawer_items_linear_layout_main_activity) LinearLayout allDrawerItemsLinearLayout;
|
||||||
|
@BindView(R.id.account_label_main_activity) TextView accountLabelTextView;
|
||||||
@BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout;
|
@BindView(R.id.profile_linear_layout_main_activity) LinearLayout profileLinearLayout;
|
||||||
@BindView(R.id.subscriptions_linear_layout_main_activity) LinearLayout subscriptionLinearLayout;
|
@BindView(R.id.subscriptions_linear_layout_main_activity) LinearLayout subscriptionLinearLayout;
|
||||||
@BindView(R.id.inbox_linear_layout_main_activity) LinearLayout inboxLinearLayout;
|
@BindView(R.id.inbox_linear_layout_main_activity) LinearLayout inboxLinearLayout;
|
||||||
|
@BindView(R.id.post_label_main_activity) TextView postLabelTextView;
|
||||||
@BindView(R.id.upvoted_linear_layout_main_activity) LinearLayout upvotedLinearLayout;
|
@BindView(R.id.upvoted_linear_layout_main_activity) LinearLayout upvotedLinearLayout;
|
||||||
@BindView(R.id.downvoted_linear_layout_main_activity) LinearLayout downvotedLinearLayout;
|
@BindView(R.id.downvoted_linear_layout_main_activity) LinearLayout downvotedLinearLayout;
|
||||||
@BindView(R.id.hidden_linear_layout_main_activity) LinearLayout hiddenLinearLayout;
|
@BindView(R.id.hidden_linear_layout_main_activity) LinearLayout hiddenLinearLayout;
|
||||||
@ -146,6 +151,8 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
|
|
||||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||||
|
|
||||||
|
EventBus.getDefault().register(this);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
Resources resources = getResources();
|
Resources resources = getResources();
|
||||||
|
|
||||||
@ -241,12 +248,35 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void getCurrentAccountAndBindView() {
|
||||||
if(mNewAccountName != null) {
|
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, () -> {
|
|
||||||
mNewAccountName = null;
|
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
if(account == null) {
|
if(mNewAccountName != null) {
|
||||||
|
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
||||||
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
||||||
|
mNewAccountName = null;
|
||||||
|
if(newAccount == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = newAccount.getAccessToken();
|
||||||
|
mAccountName = newAccount.getUsername();
|
||||||
|
mProfileImageUrl = newAccount.getProfileImageUrl();
|
||||||
|
mBannerImageUrl = newAccount.getBannerImageUrl();
|
||||||
|
mKarma = newAccount.getKarma();
|
||||||
|
|
||||||
|
Constraints constraints = new Constraints.Builder()
|
||||||
|
.setRequiredNetworkType(NetworkType.CONNECTED)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
PeriodicWorkRequest pullNotificationRequest =
|
||||||
|
new PeriodicWorkRequest.Builder(PullNotificationWorker.class, 1, TimeUnit.HOURS)
|
||||||
|
.setConstraints(constraints)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
bindView();
|
||||||
|
}).execute();
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = account.getAccessToken();
|
mAccessToken = account.getAccessToken();
|
||||||
mAccountName = account.getUsername();
|
mAccountName = account.getUsername();
|
||||||
@ -264,13 +294,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.KEEP, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
}
|
|
||||||
bindView();
|
bindView();
|
||||||
}).execute();
|
}
|
||||||
}).execute();
|
|
||||||
} else {
|
} else {
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
|
||||||
if(account == null) {
|
if(account == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
} else {
|
} else {
|
||||||
@ -292,12 +320,14 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
WorkManager.getInstance(this).enqueueUniquePeriodicWork(PullNotificationWorker.WORKER_TAG,
|
||||||
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
ExistingPeriodicWorkPolicy.REPLACE, pullNotificationRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}).execute();
|
|
||||||
}
|
}
|
||||||
|
}).execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
|
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
viewPager.setAdapter(sectionsPagerAdapter);
|
viewPager.setAdapter(sectionsPagerAdapter);
|
||||||
viewPager.setOffscreenPageLimit(2);
|
viewPager.setOffscreenPageLimit(2);
|
||||||
@ -328,7 +358,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
new AccountRecyclerViewAdapter.ItemSelectedListener() {
|
new AccountRecyclerViewAdapter.ItemSelectedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void accountSelected(Account account) {
|
public void accountSelected(Account account) {
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, account.getUsername(), () -> {
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, account.getUsername(), newAccount -> {
|
||||||
Intent intent = new Intent(MainActivity.this, MainActivity.class);
|
Intent intent = new Intent(MainActivity.this, MainActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
finish();
|
finish();
|
||||||
@ -436,9 +466,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
} else {
|
} else {
|
||||||
mKarmaTextView.setText(R.string.press_here_to_login);
|
mKarmaTextView.setText(R.string.press_here_to_login);
|
||||||
mAccountNameTextView.setText(R.string.anonymous_account);
|
mAccountNameTextView.setText(R.string.anonymous_account);
|
||||||
|
accountLabelTextView.setVisibility(View.GONE);
|
||||||
profileLinearLayout.setVisibility(View.GONE);
|
profileLinearLayout.setVisibility(View.GONE);
|
||||||
subscriptionLinearLayout.setVisibility(View.GONE);
|
subscriptionLinearLayout.setVisibility(View.GONE);
|
||||||
inboxLinearLayout.setVisibility(View.GONE);
|
inboxLinearLayout.setVisibility(View.GONE);
|
||||||
|
postLabelTextView.setVisibility(View.GONE);
|
||||||
upvotedLinearLayout.setVisibility(View.GONE);
|
upvotedLinearLayout.setVisibility(View.GONE);
|
||||||
downvotedLinearLayout.setVisibility(View.GONE);
|
downvotedLinearLayout.setVisibility(View.GONE);
|
||||||
hiddenLinearLayout.setVisibility(View.GONE);
|
hiddenLinearLayout.setVisibility(View.GONE);
|
||||||
@ -666,6 +698,12 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
outState.putString(NEW_ACCOUNT_NAME_STATE, mNewAccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
super.onDestroy();
|
||||||
|
EventBus.getDefault().unregister(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sortTypeSelected(String sortType) {
|
public void sortTypeSelected(String sortType) {
|
||||||
sectionsPagerAdapter.changeSortType(sortType);
|
sectionsPagerAdapter.changeSortType(sortType);
|
||||||
@ -693,6 +731,11 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onAccountSwitchEvent(SwitchAccountEvent event) {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
|
||||||
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
private class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||||
private PostFragment frontPagePostFragment;
|
private PostFragment frontPagePostFragment;
|
||||||
private PostFragment popularPostFragment;
|
private PostFragment popularPostFragment;
|
||||||
|
@ -213,6 +213,7 @@ class ParseComment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static CommentData parseSingleComment(JSONObject singleCommentData, int depth, Locale locale) throws JSONException {
|
static CommentData parseSingleComment(JSONObject singleCommentData, int depth, Locale locale) throws JSONException {
|
||||||
|
Log.i("adfasdf", singleCommentData.toString());
|
||||||
String id = singleCommentData.getString(JSONUtils.ID_KEY);
|
String id = singleCommentData.getString(JSONUtils.ID_KEY);
|
||||||
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
|
String fullName = singleCommentData.getString(JSONUtils.NAME_KEY);
|
||||||
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY);
|
String author = singleCommentData.getString(JSONUtils.AUTHOR_KEY);
|
||||||
|
@ -60,8 +60,6 @@ public class PullNotificationWorker extends Worker {
|
|||||||
Account account = accounts.get(accountIndex);
|
Account account = accounts.get(accountIndex);
|
||||||
String accountName = account.getUsername();
|
String accountName = account.getUsername();
|
||||||
|
|
||||||
Log.i("workmanager", accountName + " " + account.getAccessToken());
|
|
||||||
|
|
||||||
Response<String> response = fetchMessages(account);
|
Response<String> response = fetchMessages(account);
|
||||||
|
|
||||||
if(response != null && response.isSuccessful()) {
|
if(response != null && response.isSuccessful()) {
|
||||||
|
@ -2,13 +2,16 @@ package ml.docilealligator.infinityforreddit;
|
|||||||
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import Account.Account;
|
||||||
|
|
||||||
class SwitchAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
class SwitchAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
interface SwitchAccountAsyncTaskListener {
|
interface SwitchAccountAsyncTaskListener {
|
||||||
void switched();
|
void switched(Account account);
|
||||||
}
|
}
|
||||||
|
|
||||||
private RedditDataRoomDatabase redditDataRoomDatabase;
|
private RedditDataRoomDatabase redditDataRoomDatabase;
|
||||||
private String newAccountName;
|
private String newAccountName;
|
||||||
|
private Account account;
|
||||||
private SwitchAccountAsyncTaskListener switchAccountAsyncTaskListener;
|
private SwitchAccountAsyncTaskListener switchAccountAsyncTaskListener;
|
||||||
|
|
||||||
SwitchAccountAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String newAccountName,
|
SwitchAccountAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, String newAccountName,
|
||||||
@ -22,11 +25,12 @@ class SwitchAccountAsyncTask extends AsyncTask<Void, Void, Void> {
|
|||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
redditDataRoomDatabase.accountDao().markAllAccountsNonCurrent();
|
redditDataRoomDatabase.accountDao().markAllAccountsNonCurrent();
|
||||||
redditDataRoomDatabase.accountDao().markAccountCurrent(newAccountName);
|
redditDataRoomDatabase.accountDao().markAccountCurrent(newAccountName);
|
||||||
|
account = redditDataRoomDatabase.accountDao().getCurrentAccount();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
switchAccountAsyncTaskListener.switched();
|
switchAccountAsyncTaskListener.switched(account);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
|
public class SwitchAccountEvent {
|
||||||
|
public void accountSwitched(){}
|
||||||
|
}
|
@ -28,6 +28,8 @@ import com.google.android.material.appbar.AppBarLayout;
|
|||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -146,30 +148,34 @@ public class ViewMessageActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndFetchMessage() {
|
private void getCurrentAccountAndFetchMessage() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
if(mNewAccountName != null) {
|
if(mNewAccountName != null) {
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, () -> {
|
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
||||||
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
||||||
|
EventBus.getDefault().post(new SwitchAccountEvent());
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
if(newAccount == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = newAccount.getAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
bindView();
|
||||||
|
}).execute();
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if(account == null) {
|
if(account == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = account.getAccessToken();
|
mAccessToken = account.getAccessToken();
|
||||||
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
}).execute();
|
|
||||||
} else {
|
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
|
||||||
if(account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
|
|
||||||
bindView();
|
|
||||||
}
|
|
||||||
}).execute();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
|
@ -218,10 +218,27 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void getCurrentAccountAndBindView() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
if(mNewAccountName != null) {
|
if(mNewAccountName != null) {
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, () -> {
|
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
||||||
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
||||||
|
EventBus.getDefault().post(new SwitchAccountEvent());
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
if(newAccount == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = newAccount.getAccessToken();
|
||||||
|
mAccountName = newAccount.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
bindView();
|
||||||
|
}).execute();
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
bindView();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if(account == null) {
|
if(account == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
} else {
|
} else {
|
||||||
@ -230,21 +247,9 @@ public class ViewPostDetailActivity extends AppCompatActivity implements FlairBo
|
|||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
bindView();
|
||||||
}).execute();
|
|
||||||
}).execute();
|
|
||||||
} else {
|
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
|
||||||
if(account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getUsername();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView();
|
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void bindView() {
|
private void bindView() {
|
||||||
if(mAccessToken != null && mMessageFullname != null) {
|
if(mAccessToken != null && mMessageFullname != null) {
|
||||||
|
@ -31,6 +31,8 @@ import com.google.android.material.chip.Chip;
|
|||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -267,31 +269,38 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndBindView() {
|
private void getCurrentAccountAndBindView() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
if(mNewAccountName != null) {
|
if(mNewAccountName != null) {
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, () -> {
|
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
||||||
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
||||||
|
EventBus.getDefault().post(new SwitchAccountEvent());
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
if(newAccount == null) {
|
||||||
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = newAccount.getAccessToken();
|
||||||
|
mAccountName = newAccount.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
bindView(true);
|
||||||
|
}).execute();
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
bindView(true);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if(account == null) {
|
if(account == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = account.getAccessToken();
|
mAccessToken = account.getAccessToken();
|
||||||
mAccountName = account.getUsername();
|
mAccountName = account.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
bindView(true);
|
bindView(true);
|
||||||
}).execute();
|
|
||||||
}).execute();
|
|
||||||
} else {
|
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
|
||||||
if(account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getUsername();
|
|
||||||
}
|
}
|
||||||
bindView(true);
|
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void fetchSubredditData() {
|
private void fetchSubredditData() {
|
||||||
if(!mFetchSubredditInfoSuccess) {
|
if(!mFetchSubredditInfoSuccess) {
|
||||||
|
@ -35,6 +35,8 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
|||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.google.android.material.tabs.TabLayout;
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
@ -347,31 +349,38 @@ public class ViewUserDetailActivity extends AppCompatActivity implements UserThi
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void getCurrentAccountAndInitializeViewPager() {
|
private void getCurrentAccountAndInitializeViewPager() {
|
||||||
|
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
||||||
if(mNewAccountName != null) {
|
if(mNewAccountName != null) {
|
||||||
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, () -> {
|
if(account == null || !account.getUsername().equals(mNewAccountName)) {
|
||||||
|
new SwitchAccountAsyncTask(mRedditDataRoomDatabase, mNewAccountName, newAccount -> {
|
||||||
|
EventBus.getDefault().post(new SwitchAccountEvent());
|
||||||
mNewAccountName = null;
|
mNewAccountName = null;
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
if(newAccount == null) {
|
||||||
if (account == null) {
|
mNullAccessToken = true;
|
||||||
|
} else {
|
||||||
|
mAccessToken = newAccount.getAccessToken();
|
||||||
|
mAccountName = newAccount.getUsername();
|
||||||
|
}
|
||||||
|
|
||||||
|
initializeViewPager();
|
||||||
|
}).execute();
|
||||||
|
} else {
|
||||||
|
mAccessToken = account.getAccessToken();
|
||||||
|
mAccountName = account.getUsername();
|
||||||
|
initializeViewPager();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if(account == null) {
|
||||||
mNullAccessToken = true;
|
mNullAccessToken = true;
|
||||||
} else {
|
} else {
|
||||||
mAccessToken = account.getAccessToken();
|
mAccessToken = account.getAccessToken();
|
||||||
mAccountName = account.getUsername();
|
mAccountName = account.getUsername();
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeViewPager();
|
initializeViewPager();
|
||||||
}).execute();
|
|
||||||
}).execute();
|
|
||||||
} else {
|
|
||||||
new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> {
|
|
||||||
if (account == null) {
|
|
||||||
mNullAccessToken = true;
|
|
||||||
} else {
|
|
||||||
mAccessToken = account.getAccessToken();
|
|
||||||
mAccountName = account.getUsername();
|
|
||||||
}
|
}
|
||||||
initializeViewPager();
|
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeViewPager() {
|
private void initializeViewPager() {
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
|
||||||
|
@ -38,6 +38,13 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/account_label_main_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:text="@string/label_account" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/profile_linear_layout_main_activity"
|
android:id="@+id/profile_linear_layout_main_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -116,6 +123,13 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/post_label_main_activity"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="16dp"
|
||||||
|
android:text="@string/label_post" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/upvoted_linear_layout_main_activity"
|
android:id="@+id/upvoted_linear_layout_main_activity"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -231,4 +231,7 @@
|
|||||||
<string name="notification_summary_subreddit">Subreddit</string>
|
<string name="notification_summary_subreddit">Subreddit</string>
|
||||||
<string name="notification_summary_award">Award</string>
|
<string name="notification_summary_award">Award</string>
|
||||||
<string name="notification_new_messages">%1$d New Messages</string>
|
<string name="notification_new_messages">%1$d New Messages</string>
|
||||||
|
|
||||||
|
<string name="label_account">Account</string>
|
||||||
|
<string name="label_post">Post</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user