aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-04-28 07:46:25 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-04-28 07:46:25 +0000
commit77ed06dac1c27f331d1af51e0e60c137718880b5 (patch)
tree2625e806d76e2985774d9ff3af05181506c0954e /app
parentd9172110e672d9b39727010793b719fe9dd2f894 (diff)
downloadinfinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.tar
infinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.tar.gz
infinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.tar.bz2
infinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.tar.lz
infinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.tar.xz
infinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.tar.zst
infinity-for-reddit-77ed06dac1c27f331d1af51e0e60c137718880b5.zip
Submitting crosspost using other accounts is available.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java77
-rw-r--r--app/src/main/res/layout/activity_submit_crosspost.xml27
2 files changed, 99 insertions, 5 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
index 42b260b9..9ce13935 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SubmitCrosspostActivity.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.SubmitCrosspostEvent;
@@ -67,10 +69,12 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
-public class SubmitCrosspostActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback {
+public class SubmitCrosspostActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
+ AccountChooserBottomSheetFragment.AccountChooserListener {
public static final String EXTRA_POST = "EP";
+ 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 SubmitCrosspostActivity extends BaseActivity implements FlairBottom
AppBarLayout appBarLayout;
@BindView(R.id.toolbar_submit_crosspost_activity)
Toolbar toolbar;
+ @BindView(R.id.account_linear_layout_submit_crosspost_activity)
+ LinearLayout accountLinearLayout;
+ @BindView(R.id.account_icon_gif_image_view_submit_crosspost_activity)
+ GifImageView accountIconImageView;
+ @BindView(R.id.account_name_text_view_submit_crosspost_activity)
+ TextView accountNameTextView;
@BindView(R.id.subreddit_icon_gif_image_view_submit_crosspost_activity)
GifImageView iconGifImageView;
@BindView(R.id.subreddit_name_text_view_submit_crosspost_activity)
@@ -143,6 +153,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
CustomThemeWrapper mCustomThemeWrapper;
@Inject
Executor mExecutor;
+ private Account selectedAccount;
private String mAccessToken;
private Post post;
private String iconUrl;
@@ -200,6 +211,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
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);
@@ -210,6 +222,18 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
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);
@@ -243,6 +267,8 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
} else {
isPosting = false;
+ loadCurrentAccount();
+
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.into(iconGifImageView);
@@ -293,13 +319,18 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
}
+ 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);
});
@@ -368,6 +399,25 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
});
}
+ 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());
+ }
+ });
+ });
+ }
+
@Nullable
private Post.Preview getPreview(Post post) {
ArrayList<Post.Preview> previews = post.getPreviews();
@@ -392,11 +442,12 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
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.setBackgroundColor(dividerColor);
@@ -518,7 +569,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
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());
if (post.isCrosspost()) {
@@ -556,6 +607,7 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
@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);
@@ -605,6 +657,21 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
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/res/layout/activity_submit_crosspost.xml b/app/src/main/res/layout/activity_submit_crosspost.xml
index 797f9608..50b661a6 100644
--- a/app/src/main/res/layout/activity_submit_crosspost.xml
+++ b/app/src/main/res/layout/activity_submit_crosspost.xml
@@ -33,6 +33,33 @@
android:layout_height="match_parent"
android:orientation="vertical">
+ <LinearLayout
+ android:id="@+id/account_linear_layout_submit_crosspost_activity"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground">
+
+ <pl.droidsonroids.gif.GifImageView
+ android:id="@+id/account_icon_gif_image_view_submit_crosspost_activity"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_marginStart="16dp" />
+
+ <TextView
+ android:id="@+id/account_name_text_view_submit_crosspost_activity"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginStart="32dp"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family" />
+
+ </LinearLayout>
+
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"