diff options
Diffstat (limited to 'app/src/main/java/ml')
6 files changed, 380 insertions, 48 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java index 87703247..0b746fc9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostGalleryActivity.java @@ -64,8 +64,10 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditGalleryPayload; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.adapters.RedditGallerySubmissionRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SelectOrCaptureImageBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; @@ -79,10 +81,12 @@ import ml.docilealligator.infinityforreddit.utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostGalleryActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostGalleryActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback, + AccountChooserBottomSheetFragment.AccountChooserListener { static final String EXTRA_SUBREDDIT_NAME = "ESN"; + private static final String SELECTED_ACCOUNT_STATE = "SAS"; private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_ICON_STATE = "SIS"; private static final String SUBREDDIT_SELECTED_STATE = "SSS"; @@ -104,6 +108,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_gallery_activity) Toolbar toolbar; + @BindView(R.id.account_linear_layout_post_gallery_activity) + LinearLayout accountLinearLayout; + @BindView(R.id.account_icon_gif_image_view_post_gallery_activity) + GifImageView accountIconImageView; + @BindView(R.id.account_name_text_view_post_gallery_activity) + TextView accountNameTextView; @BindView(R.id.subreddit_icon_gif_image_view_post_gallery_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_gallery_activity) @@ -151,6 +161,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private Account selectedAccount; private ArrayList<RedditGallerySubmissionRecyclerViewAdapter.RedditGalleryImageInfo> redditGalleryImageInfoList; private String mAccessToken; private String mAccountName; @@ -251,6 +262,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee }); if (savedInstanceState != null) { + selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); @@ -261,6 +273,19 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); redditGalleryImageInfoList = savedInstanceState.getParcelableArrayList(REDDIT_GALLERY_IMAGE_INFO_STATE); + + if (selectedAccount != null) { + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } else { + loadCurrentAccount(); + } + if (redditGalleryImageInfoList != null && !redditGalleryImageInfoList.isEmpty()) { if (redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).payload == null) { imageUri = Uri.parse(redditGalleryImageInfoList.get(redditGalleryImageInfoList.size() - 1).imageUrlString); @@ -302,6 +327,8 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee } else { isPosting = false; + loadCurrentAccount(); + if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); @@ -317,13 +344,16 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee } } - iconGifImageView.setOnClickListener(view -> { - Intent intent = new Intent(this, SubredditSelectionActivity.class); - startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); + accountLinearLayout.setOnClickListener(view -> { + AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment(); + fragment.show(getSupportFragmentManager(), fragment.getTag()); }); + iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick()); + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); + intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -388,6 +418,25 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee }); } + private void loadCurrentAccount() { + Handler handler = new Handler(); + mExecutor.execute(() -> { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + selectedAccount = account; + handler.post(() -> { + if (!isFinishing() && !isDestroyed() && account != null) { + mGlide.load(account.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(account.getAccountName()); + } + }); + }); + } + @Override protected SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; @@ -402,11 +451,12 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); + primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + accountNameTextView.setTextColor(primaryTextColor); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); - primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setDividerColor(dividerColor); @@ -579,7 +629,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee } Intent intent = new Intent(this, SubmitPostService.class); - intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, mAccessToken); + intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount); intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_GALLERY); ArrayList<RedditGalleryPayload.Item> items = new ArrayList<>(); @@ -615,6 +665,7 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount); outState.putString(SUBREDDIT_NAME_STATE, subredditName); outState.putString(SUBREDDIT_ICON_STATE, iconUrl); outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); @@ -682,6 +733,21 @@ public class PostGalleryActivity extends BaseActivity implements FlairBottomShee flairTextView.setTextColor(flairTextColor); } + @Override + public void onAccountSelected(Account account) { + if (account != null) { + selectedAccount = account; + + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } + } + public void setCaptionAndUrl(int position, String caption, String url) { if (adapter != null) { adapter.setCaptionAndUrl(position, caption, url); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java index 775ba604..3d595b09 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostImageActivity.java @@ -55,7 +55,9 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitImagePostEvent; @@ -66,10 +68,12 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostImageActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostImageActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback, + AccountChooserBottomSheetFragment.AccountChooserListener { static final String EXTRA_SUBREDDIT_NAME = "ESN"; + private static final String SELECTED_ACCOUNT_STATE = "SAS"; private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_ICON_STATE = "SIS"; private static final String SUBREDDIT_SELECTED_STATE = "SSS"; @@ -91,6 +95,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_image_activity) Toolbar toolbar; + @BindView(R.id.account_linear_layout_post_image_activity) + LinearLayout accountLinearLayout; + @BindView(R.id.account_icon_gif_image_view_post_image_activity) + GifImageView accountIconImageView; + @BindView(R.id.account_name_text_view_post_image_activity) + TextView accountNameTextView; @BindView(R.id.subreddit_icon_gif_image_view_post_image_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_image_activity) @@ -146,6 +156,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private Account selectedAccount; private String mAccessToken; private String mAccountName; private String iconUrl; @@ -204,6 +215,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); if (savedInstanceState != null) { + selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); @@ -214,6 +226,18 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); + if (selectedAccount != null) { + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } else { + loadCurrentAccount(); + } + if (savedInstanceState.getString(IMAGE_URI_STATE) != null) { imageUri = Uri.parse(savedInstanceState.getString(IMAGE_URI_STATE)); loadImage(); @@ -252,6 +276,8 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } else { isPosting = false; + loadCurrentAccount(); + if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); @@ -272,13 +298,16 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF } } - iconGifImageView.setOnClickListener(view -> { - Intent intent = new Intent(this, SubredditSelectionActivity.class); - startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); + accountLinearLayout.setOnClickListener(view -> { + AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment(); + fragment.show(getSupportFragmentManager(), fragment.getTag()); }); + iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick()); + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); + intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -372,6 +401,25 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF }); } + private void loadCurrentAccount() { + Handler handler = new Handler(); + mExecutor.execute(() -> { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + selectedAccount = account; + handler.post(() -> { + if (!isFinishing() && !isDestroyed() && account != null) { + mGlide.load(account.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(account.getAccountName()); + } + }); + }); + } + @Override public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; @@ -386,11 +434,12 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); + primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + accountNameTextView.setTextColor(primaryTextColor); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); - primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setDividerColor(dividerColor); @@ -519,7 +568,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF Intent intent = new Intent(this, SubmitPostService.class); intent.setData(imageUri); - intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, mAccessToken); + intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount); intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString()); intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair); @@ -558,6 +607,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount); outState.putString(SUBREDDIT_NAME_STATE, subredditName); outState.putString(SUBREDDIT_ICON_STATE, iconUrl); outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); @@ -624,6 +674,21 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF flairTextView.setTextColor(flairTextColor); } + @Override + public void onAccountSelected(Account account) { + if (account != null) { + selectedAccount = account; + + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { finish(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index 9dd5b6ef..3db21105 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -46,8 +46,10 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.apis.TitleSuggestion; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent; @@ -62,11 +64,13 @@ import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.scalars.ScalarsConverterFactory; -public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback, + AccountChooserBottomSheetFragment.AccountChooserListener { static final String EXTRA_SUBREDDIT_NAME = "ESN"; static final String EXTRA_LINK = "EL"; + private static final String SELECTED_ACCOUNT_STATE = "SAS"; private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_ICON_STATE = "SIS"; private static final String SUBREDDIT_SELECTED_STATE = "SSS"; @@ -85,6 +89,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_link_activity) Toolbar toolbar; + @BindView(R.id.account_linear_layout_post_link_activity) + LinearLayout accountLinearLayout; + @BindView(R.id.account_icon_gif_image_view_post_link_activity) + GifImageView accountIconImageView; + @BindView(R.id.account_name_text_view_post_link_activity) + TextView accountNameTextView; @BindView(R.id.subreddit_icon_gif_image_view_post_link_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_link_activity) @@ -131,6 +141,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private Account selectedAccount; private String mAccessToken; private String iconUrl; private String subredditName; @@ -186,6 +197,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); if (savedInstanceState != null) { + selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); @@ -196,6 +208,18 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); + if (selectedAccount != null) { + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } else { + loadCurrentAccount(); + } + if (subredditName != null) { subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); @@ -229,6 +253,8 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr } else { isPosting = false; + loadCurrentAccount(); + if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); @@ -249,13 +275,16 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr } } - iconGifImageView.setOnClickListener(view -> { - Intent intent = new Intent(this, SubredditSelectionActivity.class); - startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); + accountLinearLayout.setOnClickListener(view -> { + AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment(); + fragment.show(getSupportFragmentManager(), fragment.getTag()); }); + iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick()); + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); + intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -346,6 +375,25 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr }); } + private void loadCurrentAccount() { + Handler handler = new Handler(); + mExecutor.execute(() -> { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + selectedAccount = account; + handler.post(() -> { + if (!isFinishing() && !isDestroyed() && account != null) { + mGlide.load(account.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(account.getAccountName()); + } + }); + }); + } + @Override public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; @@ -360,11 +408,12 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); + primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + accountNameTextView.setTextColor(primaryTextColor); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); - primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setDividerColor(dividerColor); @@ -489,7 +538,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr } Intent intent = new Intent(this, SubmitPostService.class); - intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, mAccessToken); + intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount); intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString()); intent.putExtra(SubmitPostService.EXTRA_CONTENT, linkEditText.getText().toString()); @@ -523,6 +572,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount); outState.putString(SUBREDDIT_NAME_STATE, subredditName); outState.putString(SUBREDDIT_ICON_STATE, iconUrl); outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); @@ -572,6 +622,21 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr flairTextView.setTextColor(flairTextColor); } + @Override + public void onAccountSelected(Account account) { + if (account != null) { + selectedAccount = account; + + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { finish(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java index d224def6..945fb86f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java @@ -56,7 +56,9 @@ import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PollPayload; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitPollPostEvent; @@ -67,10 +69,12 @@ import ml.docilealligator.infinityforreddit.utils.Utils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostPollActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostPollActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback, + AccountChooserBottomSheetFragment.AccountChooserListener { static final String EXTRA_SUBREDDIT_NAME = "ESN"; + private static final String SELECTED_ACCOUNT_STATE = "SAS"; private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_ICON_STATE = "SIS"; private static final String SUBREDDIT_SELECTED_STATE = "SSS"; @@ -89,6 +93,12 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_poll_activity) Toolbar toolbar; + @BindView(R.id.account_linear_layout_post_poll_activity) + LinearLayout accountLinearLayout; + @BindView(R.id.account_icon_gif_image_view_post_poll_activity) + GifImageView accountIconImageView; + @BindView(R.id.account_name_text_view_post_poll_activity) + TextView accountNameTextView; @BindView(R.id.subreddit_icon_gif_image_view_post_poll_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_poll_activity) @@ -161,6 +171,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private Account selectedAccount; private String mAccessToken; private String mAccountName; private String iconUrl; @@ -219,6 +230,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr Resources resources = getResources(); if (savedInstanceState != null) { + selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); @@ -229,6 +241,18 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); + if (selectedAccount != null) { + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } else { + loadCurrentAccount(); + } + if (subredditName != null) { subredditNameTextView.setTextColor(primaryTextColor); subredditNameTextView.setText(subredditName); @@ -262,6 +286,8 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr } else { isPosting = false; + loadCurrentAccount(); + if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); @@ -277,13 +303,16 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr } } - iconGifImageView.setOnClickListener(view -> { - Intent intent = new Intent(this, SubredditSelectionActivity.class); - startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); + accountLinearLayout.setOnClickListener(view -> { + AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment(); + fragment.show(getSupportFragmentManager(), fragment.getTag()); }); + iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick()); + subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); + intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -351,6 +380,25 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr votingLengthSlider.addOnChangeListener((slider, value, fromUser) -> votingLengthTextView.setText(getString(R.string.voting_length, (int) value))); } + private void loadCurrentAccount() { + Handler handler = new Handler(); + mExecutor.execute(() -> { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + selectedAccount = account; + handler.post(() -> { + if (!isFinishing() && !isDestroyed() && account != null) { + mGlide.load(account.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(account.getAccountName()); + } + }); + }); + } + @Override protected SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; @@ -365,11 +413,12 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); + primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + accountNameTextView.setTextColor(primaryTextColor); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); - primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setDividerColor(dividerColor); @@ -580,7 +629,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr mPostingSnackbar.show(); Intent intent = new Intent(this, SubmitPostService.class); - intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, mAccessToken); + intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount); intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_POLL); PollPayload payload = new PollPayload(subredditName, titleEditText.getText().toString(), @@ -618,6 +667,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount); outState.putString(SUBREDDIT_NAME_STATE, subredditName); outState.putString(SUBREDDIT_ICON_STATE, iconUrl); outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); @@ -661,6 +711,21 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr flairTextView.setTextColor(flairTextColor); } + @Override + public void onAccountSelected(Account account) { + if (account != null) { + selectedAccount = account; + + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { finish(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index 381a4923..2b608bbf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -237,6 +237,8 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr .into(accountIconImageView); accountNameTextView.setText(selectedAccount.getAccountName()); + } else { + loadCurrentAccount(); } if (subredditName != null) { @@ -272,22 +274,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr } else { isPosting = false; - Handler handler = new Handler(); - mExecutor.execute(() -> { - Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); - selectedAccount = account; - handler.post(() -> { - if (!isFinishing() && !isDestroyed() && account != null) { - mGlide.load(account.getProfileImageUrl()) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) - .error(mGlide.load(R.drawable.subreddit_default_icon) - .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) - .into(accountIconImageView); - - accountNameTextView.setText(account.getAccountName()); - } - }); - }); + loadCurrentAccount(); if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; @@ -314,9 +301,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr fragment.show(getSupportFragmentManager(), fragment.getTag()); }); - iconGifImageView.setOnClickListener(view -> { - subredditNameTextView.performClick(); - }); + iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick()); subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); @@ -413,6 +398,25 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr markdownBottomBarRecyclerView.setAdapter(adapter); } + private void loadCurrentAccount() { + Handler handler = new Handler(); + mExecutor.execute(() -> { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + selectedAccount = account; + handler.post(() -> { + if (!isFinishing() && !isDestroyed() && account != null) { + mGlide.load(account.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(account.getAccountName()); + } + }); + }); + } + @Override public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java index d070f091..8477942e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostVideoActivity.java @@ -59,7 +59,9 @@ import ml.docilealligator.infinityforreddit.Flair; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.account.Account; import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.events.SubmitVideoOrGifPostEvent; @@ -69,10 +71,12 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostVideoActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback { +public class PostVideoActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback, + AccountChooserBottomSheetFragment.AccountChooserListener { static final String EXTRA_SUBREDDIT_NAME = "ESN"; + private static final String SELECTED_ACCOUNT_STATE = "SAS"; private static final String SUBREDDIT_NAME_STATE = "SNS"; private static final String SUBREDDIT_ICON_STATE = "SIS"; private static final String SUBREDDIT_SELECTED_STATE = "SSS"; @@ -94,6 +98,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_video_activity) Toolbar toolbar; + @BindView(R.id.account_linear_layout_post_video_activity) + LinearLayout accountLinearLayout; + @BindView(R.id.account_icon_gif_image_view_post_video_activity) + GifImageView accountIconImageView; + @BindView(R.id.account_name_text_view_post_video_activity) + TextView accountNameTextView; @BindView(R.id.subreddit_icon_gif_image_view_post_video_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_video_activity) @@ -152,6 +162,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF CustomThemeWrapper mCustomThemeWrapper; @Inject Executor mExecutor; + private Account selectedAccount; private String mAccessToken; private String mAccountName; private String iconUrl; @@ -223,6 +234,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); if (savedInstanceState != null) { + selectedAccount = savedInstanceState.getParcelable(SELECTED_ACCOUNT_STATE); subredditName = savedInstanceState.getString(SUBREDDIT_NAME_STATE); iconUrl = savedInstanceState.getString(SUBREDDIT_ICON_STATE); subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); @@ -233,6 +245,18 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); + if (selectedAccount != null) { + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } else { + loadCurrentAccount(); + } + if (savedInstanceState.getString(VIDEO_URI_STATE) != null) { videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE)); loadVideo(); @@ -271,6 +295,8 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF } else { isPosting = false; + loadCurrentAccount(); + if (getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); @@ -291,13 +317,18 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF } } + accountLinearLayout.setOnClickListener(view -> { + AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment(); + fragment.show(getSupportFragmentManager(), fragment.getTag()); + }); + iconGifImageView.setOnClickListener(view -> { - Intent intent = new Intent(this, SubredditSelectionActivity.class); - startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); + subredditNameTextView.performClick(); }); subredditNameTextView.setOnClickListener(view -> { Intent intent = new Intent(this, SubredditSelectionActivity.class); + intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); @@ -387,6 +418,25 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF }); } + private void loadCurrentAccount() { + Handler handler = new Handler(); + mExecutor.execute(() -> { + Account account = mRedditDataRoomDatabase.accountDao().getCurrentAccount(); + selectedAccount = account; + handler.post(() -> { + if (!isFinishing() && !isDestroyed() && account != null) { + mGlide.load(account.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(account.getAccountName()); + } + }); + }); + } + @Override public SharedPreferences getDefaultSharedPreferences() { return mSharedPreferences; @@ -401,11 +451,12 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF protected void applyCustomTheme() { coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar); + primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + accountNameTextView.setTextColor(primaryTextColor); int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor(); subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme()); - primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setDividerColor(dividerColor); @@ -536,7 +587,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF Intent intent = new Intent(this, SubmitPostService.class); intent.setData(videoUri); - intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, mAccessToken); + intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount); intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName); intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString()); intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair); @@ -584,6 +635,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); + outState.putParcelable(SELECTED_ACCOUNT_STATE, selectedAccount); outState.putString(SUBREDDIT_NAME_STATE, subredditName); outState.putString(SUBREDDIT_ICON_STATE, iconUrl); outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); @@ -660,6 +712,21 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF flairTextView.setTextColor(flairTextColor); } + @Override + public void onAccountSelected(Account account) { + if (account != null) { + selectedAccount = account; + + mGlide.load(selectedAccount.getProfileImageUrl()) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))) + .error(mGlide.load(R.drawable.subreddit_default_icon) + .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))) + .into(accountIconImageView); + + accountNameTextView.setText(selectedAccount.getAccountName()); + } + } + @Subscribe public void onAccountSwitchEvent(SwitchAccountEvent event) { finish(); |