Fix flair cannot be applied when submitting posts. Fix crash in FollowedUsersRecyclerViewAdapter.

This commit is contained in:
Alex Ning 2020-06-23 11:36:17 +08:00
parent 405cac91e8
commit 421315f0c6
7 changed files with 16 additions and 12 deletions

View File

@ -547,7 +547,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr
} else {
mMemu.findItem(R.id.action_send_post_link_activity).setEnabled(true);
mMemu.findItem(R.id.action_send_post_link_activity).getIcon().setAlpha(255);
if (submitTextOrLinkPostEvent.errorMessage == null) {
if (submitTextOrLinkPostEvent.errorMessage == null || submitTextOrLinkPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()

View File

@ -547,7 +547,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
} else {
mMemu.findItem(R.id.action_send_post_text_activity).setEnabled(true);
mMemu.findItem(R.id.action_send_post_text_activity).getIcon().setAlpha(255);
if (submitTextOrLinkPostEvent.errorMessage == null) {
if (submitTextOrLinkPostEvent.errorMessage == null || submitTextOrLinkPostEvent.errorMessage.equals("")) {
Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()

View File

@ -294,7 +294,7 @@ public class FollowedUsersRecyclerViewAdapter extends RecyclerView.Adapter<Recyc
@Override
public String getPopupText(int position) {
switch (getItemViewType(position)) {
case VIEW_TYPE_USER_DIVIDER:
case VIEW_TYPE_USER:
int offset = (mFavoriteSubscribedUserData != null && mFavoriteSubscribedUserData.size() > 0) ?
mFavoriteSubscribedUserData.size() + 2 : 0;
return mSubscribedUserData.get(position - offset).getName().substring(0, 1).toUpperCase();

View File

@ -21,6 +21,7 @@ import java.util.Locale;
import java.util.Map;
import ml.docilealligator.infinityforreddit.API.RedditAPI;
import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.APIUtils;
import okhttp3.MediaType;
@ -34,7 +35,7 @@ import retrofit2.Retrofit;
public class SubmitPost {
public static void submitTextOrLinkPost(Retrofit oauthRetrofit, String accessToken,
Locale locale, String subredditName, String title, String content,
String flair, boolean isSpoiler, boolean isNSFW, String kind,
Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
SubmitPostListener submitPostListener) {
submitPost(oauthRetrofit, accessToken, locale, subredditName, title, content,
flair, isSpoiler, isNSFW, kind, null, submitPostListener);
@ -42,7 +43,7 @@ public class SubmitPost {
public static void submitImagePost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
String accessToken, Locale locale,
String subredditName, String title, Bitmap image, String flair,
String subredditName, String title, Bitmap image, Flair flair,
boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) {
uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image,
new UploadImageListener() {
@ -63,7 +64,7 @@ public class SubmitPost {
public static void submitVideoPost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit,
Retrofit uploadVideoRetrofit, String accessToken,
Locale locale, String subredditName, String title, byte[] buffer, String mimeType,
Bitmap posterBitmap, String flair, boolean isSpoiler, boolean isNSFW,
Bitmap posterBitmap, Flair flair, boolean isSpoiler, boolean isNSFW,
SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
@ -157,7 +158,7 @@ public class SubmitPost {
private static void submitPost(Retrofit oauthRetrofit, String accessToken,
Locale locale, String subredditName, String title, String content,
String flair, boolean isSpoiler, boolean isNSFW, String kind,
Flair flair, boolean isSpoiler, boolean isNSFW, String kind,
@Nullable String posterUrl, SubmitPostListener submitPostListener) {
RedditAPI api = oauthRetrofit.create(RedditAPI.class);
@ -186,7 +187,8 @@ public class SubmitPost {
}
if (flair != null) {
params.put(APIUtils.FLAIR_TEXT_KEY, flair);
params.put(APIUtils.FLAIR_TEXT_KEY, flair.getText());
params.put(APIUtils.FLAIR_ID_KEY, flair.getId());
}
params.put(APIUtils.SPOILER_KEY, Boolean.toString(isSpoiler));
params.put(APIUtils.NSFW_KEY, Boolean.toString(isNSFW));

View File

@ -34,11 +34,12 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SubmitImagePostEvent;
import ml.docilealligator.infinityforreddit.Event.SubmitTextOrLinkPostEvent;
import ml.docilealligator.infinityforreddit.Event.SubmitVideoPostEvent;
import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.NotificationUtils;
import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.Post.SubmitPost;
import ml.docilealligator.infinityforreddit.R;
import retrofit2.Retrofit;
public class SubmitPostService extends Service {
@ -68,7 +69,7 @@ public class SubmitPostService extends Service {
private String mAccessToken;
private String subredditName;
private String title;
private String flair;
private Flair flair;
private boolean isSpoiler;
private boolean isNSFW;
private String content;
@ -90,7 +91,7 @@ public class SubmitPostService extends Service {
mAccessToken = intent.getStringExtra(EXTRA_ACCESS_TOKEN);
subredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
title = intent.getStringExtra(EXTRA_TITLE);
flair = intent.getStringExtra(EXTRA_FLAIR);
flair = intent.getParcelableExtra(EXTRA_FLAIR);
isSpoiler = intent.getBooleanExtra(EXTRA_IS_SPOILER, false);
isNSFW = intent.getBooleanExtra(EXTRA_IS_NSFW, false);
int postType = intent.getIntExtra(EXTRA_POST_TYPE, EXTRA_POST_TEXT_OR_LINK);

View File

@ -83,6 +83,7 @@ public class APIUtils {
public static final String LINK_KEY = "link";
public static final String FLAIR_TEMPLATE_ID_KEY = "flair_template_id";
public static final String FLAIR_ID_KEY = "flair_id";
public static final String MAKE_FAVORITE_KEY = "make_favorite";

View File

@ -16,7 +16,7 @@
android:id="@+id/markdown_recycler_view_sidebar_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:padding="8dp"
android:clipToPadding="false" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>