diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-07-17 01:31:49 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-07-17 01:31:49 +0000 |
commit | ebf542161e94cf6c9c1691b8681717a18afd42c2 (patch) | |
tree | 475daae5efe9b1ead47916dcf567bf6743774a0c /app/src/main/java | |
parent | 116ce0bb24159d89d50296454214231bbd795de7 (diff) | |
download | infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.tar infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.tar.gz infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.tar.bz2 infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.tar.lz infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.tar.xz infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.tar.zst infinity-for-reddit-ebf542161e94cf6c9c1691b8681717a18afd42c2.zip |
Flair, spoiler and nsfw support for submitting posts.
Diffstat (limited to 'app/src/main/java')
16 files changed, 619 insertions, 31 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 8e98c5cd..da7da984 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -22,4 +22,5 @@ interface AppComponent { void inject(PostLinkActivity postLinkActivity); void inject(PostImageActivity postImageActivity); void inject(PostVideoActivity postVideoActivity); + void inject(FlairBottomSheetFragment flairBottomSheetFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairsInSubreddit.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairsInSubreddit.java new file mode 100644 index 00000000..602fd35d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairsInSubreddit.java @@ -0,0 +1,97 @@ +package ml.docilealligator.infinityforreddit; + +import android.content.SharedPreferences; +import android.os.AsyncTask; + +import androidx.annotation.NonNull; + +import org.json.JSONArray; +import org.json.JSONException; + +import java.util.ArrayList; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +class FetchFlairsInSubreddit { + interface FetchFlairsInSubredditListener { + void fetchSuccessful(ArrayList<String> flairs); + void fetchFailed(); + } + + static void fetchFlairs(Retrofit oauthRetrofit, SharedPreferences authInfoSharedPreferences, String subredditName, FetchFlairsInSubredditListener fetchFlairsInSubredditListener) { + RedditAPI api = oauthRetrofit.create(RedditAPI.class); + + String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); + Call<String> flairsCall = api.getFlairs(RedditUtils.getOAuthHeader(accessToken), subredditName); + flairsCall.enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if (response.isSuccessful()) { + new ParseFlairsAsyncTask(response.body(), new ParseFlairsAsyncTask.ParseFlairsAsyncTaskListener() { + @Override + public void parseSuccessful(ArrayList<String> flairs) { + fetchFlairsInSubredditListener.fetchSuccessful(flairs); + } + + @Override + public void parseFailed() { + fetchFlairsInSubredditListener.fetchFailed(); + } + }).execute(); + } else if(response.code() == 403) { + //No flairs + fetchFlairsInSubredditListener.fetchSuccessful(null); + } else { + fetchFlairsInSubredditListener.fetchFailed(); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + fetchFlairsInSubredditListener.fetchFailed(); + } + }); + } + + private static class ParseFlairsAsyncTask extends AsyncTask<Void, ArrayList<String>, ArrayList<String>> { + interface ParseFlairsAsyncTaskListener { + void parseSuccessful(ArrayList<String> flairs); + void parseFailed(); + } + + private String response; + private ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener; + + ParseFlairsAsyncTask(String response, ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener) { + this.response = response; + this.parseFlairsAsyncTaskListener = parseFlairsAsyncTaskListener; + } + + @Override + protected ArrayList<String> doInBackground(Void... voids) { + try { + JSONArray jsonArray = new JSONArray(response); + ArrayList<String> flairs = new ArrayList<>(); + for(int i = 0; i < jsonArray.length(); i++) { + flairs.add(jsonArray.getJSONObject(i).getString(JSONUtils.TEXT_KEY)); + } + return flairs; + } catch (JSONException e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onPostExecute(ArrayList<String> strings) { + if(strings != null) { + parseFlairsAsyncTaskListener.parseSuccessful(strings); + } else { + parseFlairsAsyncTaskListener.parseFailed(); + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java new file mode 100644 index 00000000..4e21d86d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java @@ -0,0 +1,106 @@ +package ml.docilealligator.infinityforreddit; + + +import android.app.Activity; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ProgressBar; +import android.widget.TextView; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; + +import java.util.ArrayList; + +import javax.inject.Inject; +import javax.inject.Named; + +import butterknife.BindView; +import butterknife.ButterKnife; +import retrofit2.Retrofit; + + +/** + * A simple {@link Fragment} subclass. + */ +public class FlairBottomSheetFragment extends BottomSheetDialogFragment { + + interface FlairSelectionCallback { + void flairSelected(String flair); + } + + static final String EXTRA_SUBREDDIT_NAME = "ESN"; + + @BindView(R.id.progress_bar_flair_bottom_sheet_fragment) ProgressBar progressBar; + @BindView(R.id.error_text_view_flair_bottom_sheet_fragment) TextView errorTextView; + @BindView(R.id.recycler_view_bottom_sheet_fragment) RecyclerView recyclerView; + + private Activity mAcitivity; + private FlairBottomSheetRecyclerViewAdapter mAdapter; + + @Inject + @Named("auth_info") + SharedPreferences mAuthInfoSharedPreferences; + + @Inject + @Named("oauth") + Retrofit mOauthRetrofit; + + public FlairBottomSheetFragment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_flair_bottom_sheet, container, false); + + ButterKnife.bind(this, rootView); + + mAcitivity = getActivity(); + + ((Infinity) mAcitivity.getApplication()).getmAppComponent().inject(this); + + mAdapter = new FlairBottomSheetRecyclerViewAdapter(flair -> ((FlairSelectionCallback) mAcitivity).flairSelected(flair)); + recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); + recyclerView.setAdapter(mAdapter); + + String subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME); + fetchFlairs(subredditName); + + return rootView; + } + + private void fetchFlairs(String subredditName) { + FetchFlairsInSubreddit.fetchFlairs(mOauthRetrofit, mAuthInfoSharedPreferences, + subredditName, new FetchFlairsInSubreddit.FetchFlairsInSubredditListener() { + @Override + public void fetchSuccessful(ArrayList<String> flairs) { + progressBar.setVisibility(View.GONE); + if(flairs == null || flairs.size() == 0) { + errorTextView.setVisibility(View.VISIBLE); + errorTextView.setText(R.string.no_flair); + } else { + errorTextView.setVisibility(View.GONE); + mAdapter.changeDataset(flairs); + } + } + + @Override + public void fetchFailed() { + progressBar.setVisibility(View.GONE); + errorTextView.setVisibility(View.VISIBLE); + errorTextView.setText(R.string.error_loading_flairs); + errorTextView.setOnClickListener(view -> fetchFlairs(subredditName)); + } + }); + } + +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java new file mode 100644 index 00000000..37e8d15b --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java @@ -0,0 +1,59 @@ +package ml.docilealligator.infinityforreddit; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; + +class FlairBottomSheetRecyclerViewAdapter extends RecyclerView.Adapter<FlairBottomSheetRecyclerViewAdapter.FlairViewHolder> { + interface ItemClickListener { + void onClick(String flair); + } + + private ArrayList<String> flairs; + private ItemClickListener itemClickListener; + + FlairBottomSheetRecyclerViewAdapter(ItemClickListener itemClickListener) { + this.itemClickListener = itemClickListener; + } + + @NonNull + @Override + public FlairViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new FlairViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_flair, null, false)); + } + + @Override + public void onBindViewHolder(@NonNull FlairViewHolder holder, int position) { + holder.flairTextView.setText(flairs.get(holder.getAdapterPosition())); + } + + @Override + public int getItemCount() { + return flairs == null ? 0 : flairs.size(); + } + + void changeDataset(ArrayList<String> flairs) { + this.flairs = flairs; + notifyDataSetChanged(); + } + + class FlairViewHolder extends RecyclerView.ViewHolder { + @BindView(R.id.flair_text_view_item_flair) TextView flairTextView; + + FlairViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + + flairTextView.setOnClickListener(view -> itemClickListener.onClick(flairs.get(getAdapterPosition()))); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java index 9f2c131f..c0cd0ef8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java @@ -74,4 +74,5 @@ public class JSONUtils { static final String ARGS_KEY = "args"; static final String FIELDS_KEY = "fields"; static final String VALUE_KEY = "value"; + static final String TEXT_KEY = "text"; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java index 72e8c2c2..d555a456 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MainActivity.java @@ -42,7 +42,6 @@ public class MainActivity extends AppCompatActivity { private static final String FRAGMENT_OUT_STATE = "FOS"; private static final String FETCH_USER_INFO_STATE = "FUIS"; - private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS"; private static final String IS_IN_LAZY_MODE_STATE = "IILMS"; private static final int LOGIN_ACTIVITY_REQUEST_CODE = 0; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java index 57ffcf0d..bb19e8cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java @@ -28,6 +28,7 @@ import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; +import com.libRG.CustomTextView; import java.util.ArrayList; import java.util.Locale; @@ -44,7 +45,7 @@ import retrofit2.Call; import retrofit2.Callback; import retrofit2.Retrofit; -public class PostImageActivity extends AppCompatActivity { +public class PostImageActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -54,6 +55,9 @@ public class PostImageActivity extends AppCompatActivity { private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String IMAGE_URI_STATE = "IUS"; private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS"; + private static final String FLAIR_STATE = "FS"; + private static final String IS_SPOILER_STATE = "ISS"; + private static final String IS_NSFW_STATE = "INS"; private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0; private static final int PICK_IMAGE_REQUEST_CODE = 1; @@ -62,6 +66,9 @@ public class PostImageActivity extends AppCompatActivity { @BindView(R.id.subreddit_icon_gif_image_view_post_image_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_image_activity) TextView subreditNameTextView; @BindView(R.id.rules_button_post_image_activity) Button rulesButton; + @BindView(R.id.flair_custom_text_view_post_image_activity) CustomTextView flairTextView; + @BindView(R.id.spoiler_custom_text_view_post_image_activity) CustomTextView spoilerTextView; + @BindView(R.id.nsfw_custom_text_view_post_image_activity) CustomTextView nsfwTextView; @BindView(R.id.post_title_edit_text_post_image_activity) EditText titleEditText; @BindView(R.id.select_image_constraint_layout_post_image_activity) ConstraintLayout constraintLayout; @BindView(R.id.capture_fab_post_image_activity) FloatingActionButton captureFab; @@ -76,8 +83,13 @@ public class PostImageActivity extends AppCompatActivity { private boolean loadSubredditIconSuccessful = true; private Uri imageUri; + private String flair = null; + private boolean isSpoiler = false; + private boolean isNSFW = false; + private RequestManager mGlide; private Locale mLocale; + private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @Inject @Named("oauth") @@ -117,6 +129,9 @@ public class PostImageActivity extends AppCompatActivity { subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE); loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE); + flair = savedInstanceState.getString(FLAIR_STATE); + isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); + isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if(savedInstanceState.getString(IMAGE_URI_STATE) != null) { imageUri = Uri.parse(savedInstanceState.getString(IMAGE_URI_STATE)); @@ -125,11 +140,23 @@ public class PostImageActivity extends AppCompatActivity { if(subredditName != null) { subreditNameTextView.setText(subredditName); + flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); } } displaySubredditIcon(); + + if(flair != null) { + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + } } else { if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); @@ -152,6 +179,40 @@ public class PostImageActivity extends AppCompatActivity { startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); + flairTextView.setOnClickListener(view -> { + if(flair == null) { + flairSelectionBottomSheetFragment = new FlairBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName); + flairSelectionBottomSheetFragment.setArguments(bundle); + flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); + } else { + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; + } + }); + + spoilerTextView.setOnClickListener(view -> { + if(!isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + isSpoiler = true; + } else { + spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isSpoiler = false; + } + }); + + nsfwTextView.setOnClickListener(view -> { + if(!isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + isNSFW = true; + } else { + nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isNSFW = false; + } + }); + captureFab.setOnClickListener(view -> { }); @@ -245,7 +306,7 @@ public class PostImageActivity extends AppCompatActivity { public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { SubmitPost.submitImagePost(mOauthRetrofit, mUploadMediaRetrofit, sharedPreferences, mLocale, subredditName, titleEditText.getText().toString(), resource, - false, new SubmitPost.SubmitPostListener() { + flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { RedditAPI api = mOauthRetrofit.create(RedditAPI.class); @@ -326,6 +387,9 @@ public class PostImageActivity extends AppCompatActivity { outState.putString(IMAGE_URI_STATE, imageUri.toString()); } outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful); + outState.putString(FLAIR_STATE, flair); + outState.putBoolean(IS_SPOILER_STATE, isSpoiler); + outState.putBoolean(IS_NSFW_STATE, isNSFW); } @Override @@ -341,6 +405,11 @@ public class PostImageActivity extends AppCompatActivity { subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); subreditNameTextView.setText(subredditName); displaySubredditIcon(); + + flairTextView.setVisibility(View.VISIBLE); + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; } } else if(requestCode == PICK_IMAGE_REQUEST_CODE) { if(resultCode == RESULT_OK) { @@ -354,4 +423,12 @@ public class PostImageActivity extends AppCompatActivity { } } } + + @Override + public void flairSelected(String flair) { + this.flair = flair; + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + flairSelectionBottomSheetFragment.dismiss(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java index ec979f4e..829e3261 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @@ -20,6 +21,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.snackbar.Snackbar; +import com.libRG.CustomTextView; import java.util.Locale; @@ -33,7 +35,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostLinkActivity extends AppCompatActivity { +public class PostLinkActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -42,6 +44,9 @@ public class PostLinkActivity extends AppCompatActivity { private static final String SUBREDDIT_SELECTED_STATE = "SSS"; private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS"; + private static final String FLAIR_STATE = "FS"; + private static final String IS_SPOILER_STATE = "ISS"; + private static final String IS_NSFW_STATE = "INS"; private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0; @@ -49,6 +54,9 @@ public class PostLinkActivity extends AppCompatActivity { @BindView(R.id.subreddit_icon_gif_image_view_post_link_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_link_activity) TextView subreditNameTextView; @BindView(R.id.rules_button_post_link_activity) Button rulesButton; + @BindView(R.id.flair_custom_text_view_post_link_activity) CustomTextView flairTextView; + @BindView(R.id.spoiler_custom_text_view_post_link_activity) CustomTextView spoilerTextView; + @BindView(R.id.nsfw_custom_text_view_post_link_activity) CustomTextView nsfwTextView; @BindView(R.id.post_title_edit_text_post_link_activity) EditText titleEditText; @BindView(R.id.post_link_edit_text_post_link_activity) EditText contentEditText; @@ -58,8 +66,13 @@ public class PostLinkActivity extends AppCompatActivity { private boolean subredditIsUser; private boolean loadSubredditIconSuccessful = true; + private String flair = null; + private boolean isSpoiler = false; + private boolean isNSFW = false; + private RequestManager mGlide; private Locale mLocale; + private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @Inject @Named("oauth") @@ -91,18 +104,34 @@ public class PostLinkActivity extends AppCompatActivity { subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE); loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE); + flair = savedInstanceState.getString(FLAIR_STATE); + isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); + isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if(subredditName != null) { subreditNameTextView.setText(subredditName); + flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); } } displaySubredditIcon(); + + if(flair != null) { + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + } } else { if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); subreditNameTextView.setText(subredditName); + flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); } else { mGlide.load(R.drawable.subreddit_default_icon) @@ -120,6 +149,40 @@ public class PostLinkActivity extends AppCompatActivity { Intent intent = new Intent(this, SubredditSelectionActivity.class); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); + + flairTextView.setOnClickListener(view -> { + if(flair == null) { + flairSelectionBottomSheetFragment = new FlairBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName); + flairSelectionBottomSheetFragment.setArguments(bundle); + flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); + } else { + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; + } + }); + + spoilerTextView.setOnClickListener(view -> { + if(!isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + isSpoiler = true; + } else { + spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isSpoiler = false; + } + }); + + nsfwTextView.setOnClickListener(view -> { + if(!isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + isNSFW = true; + } else { + nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isNSFW = false; + } + }); } private void displaySubredditIcon() { @@ -177,7 +240,7 @@ public class PostLinkActivity extends AppCompatActivity { SubmitPost.submitTextOrLinkPost(mOauthRetrofit, sharedPreferences, mLocale, subredditName, titleEditText.getText().toString(), contentEditText.getText().toString(), - false, RedditUtils.KIND_LINK, new SubmitPost.SubmitPostListener() { + flair, isSpoiler, isNSFW, RedditUtils.KIND_LINK, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { Intent intent = new Intent(PostLinkActivity.this, ViewPostDetailActivity.class); @@ -212,6 +275,9 @@ public class PostLinkActivity extends AppCompatActivity { outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser); outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful); + outState.putString(FLAIR_STATE, flair); + outState.putBoolean(IS_SPOILER_STATE, isSpoiler); + outState.putBoolean(IS_NSFW_STATE, isNSFW); } @Override @@ -227,7 +293,20 @@ public class PostLinkActivity extends AppCompatActivity { subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); subreditNameTextView.setText(subredditName); displaySubredditIcon(); + + flairTextView.setVisibility(View.VISIBLE); + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; } } } + + @Override + public void flairSelected(String flair) { + this.flair = flair; + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + flairSelectionBottomSheetFragment.dismiss(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 09c87319..3abc176a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -91,7 +91,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo } } - static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() { + private static final DiffUtil.ItemCallback<Post> DIFF_CALLBACK = new DiffUtil.ItemCallback<Post>() { @Override public boolean areItemsTheSame(@NonNull Post post, @NonNull Post t1) { return post.getId().equals(t1.getId()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java index 8e9df088..6f1b8c52 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java @@ -6,6 +6,7 @@ import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; +import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; @@ -20,6 +21,7 @@ import com.bumptech.glide.Glide; import com.bumptech.glide.RequestManager; import com.bumptech.glide.request.RequestOptions; import com.google.android.material.snackbar.Snackbar; +import com.libRG.CustomTextView; import java.util.Locale; @@ -33,7 +35,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostTextActivity extends AppCompatActivity { +public class PostTextActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -42,6 +44,9 @@ public class PostTextActivity extends AppCompatActivity { private static final String SUBREDDIT_SELECTED_STATE = "SSS"; private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS"; + private static final String FLAIR_STATE = "FS"; + private static final String IS_SPOILER_STATE = "ISS"; + private static final String IS_NSFW_STATE = "INS"; private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0; @@ -49,6 +54,9 @@ public class PostTextActivity extends AppCompatActivity { @BindView(R.id.subreddit_icon_gif_image_view_post_text_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_text_activity) TextView subreditNameTextView; @BindView(R.id.rules_button_post_text_activity) Button rulesButton; + @BindView(R.id.flair_custom_text_view_post_text_activity) CustomTextView flairTextView; + @BindView(R.id.spoiler_custom_text_view_post_text_activity) CustomTextView spoilerTextView; + @BindView(R.id.nsfw_custom_text_view_post_text_activity) CustomTextView nsfwTextView; @BindView(R.id.post_title_edit_text_post_text_activity) EditText titleEditText; @BindView(R.id.post_text_content_edit_text_post_text_activity) EditText contentEditText; @@ -58,8 +66,13 @@ public class PostTextActivity extends AppCompatActivity { private boolean subredditIsUser; private boolean loadSubredditIconSuccessful = true; + private String flair = null; + private boolean isSpoiler = false; + private boolean isNSFW = false; + private RequestManager mGlide; private Locale mLocale; + private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @Inject @Named("oauth") @@ -91,19 +104,35 @@ public class PostTextActivity extends AppCompatActivity { subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE); loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE); + flair = savedInstanceState.getString(FLAIR_STATE); + isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); + isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if(subredditName != null) { subreditNameTextView.setText(subredditName); + flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); } } displaySubredditIcon(); + + if(flair != null) { + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + } } else { if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { loadSubredditIconSuccessful = false; subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); subreditNameTextView.setText(subredditName); + flairTextView.setVisibility(View.VISIBLE); loadSubredditIcon(); } else { mGlide.load(R.drawable.subreddit_default_icon) @@ -121,6 +150,44 @@ public class PostTextActivity extends AppCompatActivity { Intent intent = new Intent(this, SubredditSelectionActivity.class); startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); + + flairTextView.setOnClickListener(view -> { + if(flair == null) { + flairSelectionBottomSheetFragment = new FlairBottomSheetFragment(); + Bundle bundle = new Bundle(); + if(subredditIsUser) { + bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, "u_" + subredditName); + } else { + bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName); + } + flairSelectionBottomSheetFragment.setArguments(bundle); + flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); + } else { + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; + } + }); + + spoilerTextView.setOnClickListener(view -> { + if(!isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + isSpoiler = true; + } else { + spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isSpoiler = false; + } + }); + + nsfwTextView.setOnClickListener(view -> { + if(!isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + isNSFW = true; + } else { + nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isNSFW = false; + } + }); } private void displaySubredditIcon() { @@ -178,7 +245,7 @@ public class PostTextActivity extends AppCompatActivity { SubmitPost.submitTextOrLinkPost(mOauthRetrofit, sharedPreferences, mLocale, subredditName, titleEditText.getText().toString(), contentEditText.getText().toString(), - false, RedditUtils.KIND_SELF, new SubmitPost.SubmitPostListener() { + flair, isSpoiler, isNSFW, RedditUtils.KIND_SELF, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { Intent intent = new Intent(PostTextActivity.this, ViewPostDetailActivity.class); @@ -213,6 +280,9 @@ public class PostTextActivity extends AppCompatActivity { outState.putBoolean(SUBREDDIT_SELECTED_STATE, subredditSelected); outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser); outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful); + outState.putString(FLAIR_STATE, flair); + outState.putBoolean(IS_SPOILER_STATE, isSpoiler); + outState.putBoolean(IS_NSFW_STATE, isNSFW); } @Override @@ -228,7 +298,20 @@ public class PostTextActivity extends AppCompatActivity { subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); subreditNameTextView.setText(subredditName); displaySubredditIcon(); + + flairTextView.setVisibility(View.VISIBLE); + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; } } } + + @Override + public void flairSelected(String flair) { + this.flair = flair; + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + flairSelectionBottomSheetFragment.dismiss(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java index 6a13ff16..6c1b4b07 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java @@ -30,6 +30,7 @@ import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.snackbar.Snackbar; +import com.libRG.CustomTextView; import java.io.FileInputStream; import java.io.IOException; @@ -45,7 +46,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class PostVideoActivity extends AppCompatActivity { +public class PostVideoActivity extends AppCompatActivity implements FlairBottomSheetFragment.FlairSelectionCallback { static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -55,6 +56,9 @@ public class PostVideoActivity extends AppCompatActivity { private static final String SUBREDDIT_IS_USER_STATE = "SIUS"; private static final String VIDEO_URI_STATE = "IUS"; private static final String LOAD_SUBREDDIT_ICON_STATE = "LSIS"; + private static final String FLAIR_STATE = "FS"; + private static final String IS_SPOILER_STATE = "ISS"; + private static final String IS_NSFW_STATE = "INS"; private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0; private static final int PICK_VIDEO_REQUEST_CODE = 1; @@ -63,6 +67,9 @@ public class PostVideoActivity extends AppCompatActivity { @BindView(R.id.subreddit_icon_gif_image_view_post_video_activity) GifImageView iconGifImageView; @BindView(R.id.subreddit_name_text_view_post_video_activity) TextView subreditNameTextView; @BindView(R.id.rules_button_post_video_activity) Button rulesButton; + @BindView(R.id.flair_custom_text_view_post_video_activity) CustomTextView flairTextView; + @BindView(R.id.spoiler_custom_text_view_post_video_activity) CustomTextView spoilerTextView; + @BindView(R.id.nsfw_custom_text_view_post_video_activity) CustomTextView nsfwTextView; @BindView(R.id.post_title_edit_text_post_video_activity) EditText titleEditText; @BindView(R.id.select_video_constraint_layout_post_video_activity) ConstraintLayout constraintLayout; @BindView(R.id.capture_fab_post_video_activity) FloatingActionButton captureFab; @@ -77,8 +84,13 @@ public class PostVideoActivity extends AppCompatActivity { private Uri videoUri; private boolean loadSubredditIconSuccessful = true; + private String flair = null; + private boolean isSpoiler = false; + private boolean isNSFW = false; + private RequestManager mGlide; private Locale mLocale; + private FlairBottomSheetFragment flairSelectionBottomSheetFragment; @Inject @Named("oauth") @@ -122,6 +134,9 @@ public class PostVideoActivity extends AppCompatActivity { subredditSelected = savedInstanceState.getBoolean(SUBREDDIT_SELECTED_STATE); subredditIsUser = savedInstanceState.getBoolean(SUBREDDIT_IS_USER_STATE); loadSubredditIconSuccessful = savedInstanceState.getBoolean(LOAD_SUBREDDIT_ICON_STATE); + flair = savedInstanceState.getString(FLAIR_STATE); + isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE); + isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE); if(savedInstanceState.getString(VIDEO_URI_STATE) != null) { videoUri = Uri.parse(savedInstanceState.getString(VIDEO_URI_STATE)); @@ -130,11 +145,23 @@ public class PostVideoActivity extends AppCompatActivity { if(subredditName != null) { subreditNameTextView.setText(subredditName); + flairTextView.setVisibility(View.VISIBLE); if(!loadSubredditIconSuccessful) { loadSubredditIcon(); } } displaySubredditIcon(); + + if(flair != null) { + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + } + if(isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + } } else { if(getIntent().hasExtra(EXTRA_SUBREDDIT_NAME)) { subredditName = getIntent().getExtras().getString(EXTRA_SUBREDDIT_NAME); @@ -157,6 +184,40 @@ public class PostVideoActivity extends AppCompatActivity { startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE); }); + flairTextView.setOnClickListener(view -> { + if(flair == null) { + flairSelectionBottomSheetFragment = new FlairBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putString(FlairBottomSheetFragment.EXTRA_SUBREDDIT_NAME, subredditName); + flairSelectionBottomSheetFragment.setArguments(bundle); + flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag()); + } else { + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; + } + }); + + spoilerTextView.setOnClickListener(view -> { + if(!isSpoiler) { + spoilerTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + isSpoiler = true; + } else { + spoilerTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isSpoiler = false; + } + }); + + nsfwTextView.setOnClickListener(view -> { + if(!isNSFW) { + nsfwTextView.setBackgroundColor(getResources().getColor(R.color.colorAccent)); + isNSFW = true; + } else { + nsfwTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + isNSFW = false; + } + }); + captureFab.setOnClickListener(view -> { }); @@ -255,7 +316,7 @@ public class PostVideoActivity extends AppCompatActivity { public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { SubmitPost.submitVideoPost(mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit, sharedPreferences, mLocale, subredditName, titleEditText.getText().toString(), - buffer, getContentResolver().getType(videoUri), resource, false, + buffer, getContentResolver().getType(videoUri), resource, flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { @@ -307,6 +368,9 @@ public class PostVideoActivity extends AppCompatActivity { outState.putString(VIDEO_URI_STATE, videoUri.toString()); } outState.putBoolean(LOAD_SUBREDDIT_ICON_STATE, loadSubredditIconSuccessful); + outState.putString(FLAIR_STATE, flair); + outState.putBoolean(IS_SPOILER_STATE, isSpoiler); + outState.putBoolean(IS_NSFW_STATE, isNSFW); } @Override @@ -322,6 +386,11 @@ public class PostVideoActivity extends AppCompatActivity { subreditNameTextView.setTextColor(getResources().getColor(R.color.primaryTextColor)); subreditNameTextView.setText(subredditName); displaySubredditIcon(); + + flairTextView.setVisibility(View.VISIBLE); + flairTextView.setBackgroundColor(getResources().getColor(android.R.color.transparent)); + flairTextView.setText(getString(R.string.flair)); + flair = null; } } else if(requestCode == PICK_VIDEO_REQUEST_CODE) { if(resultCode == RESULT_OK) { @@ -335,4 +404,12 @@ public class PostVideoActivity extends AppCompatActivity { } } } + + @Override + public void flairSelected(String flair) { + this.flair = flair; + flairTextView.setText(flair); + flairTextView.setBackgroundColor(getResources().getColor(R.color.textColorPrimaryDark)); + flairSelectionBottomSheetFragment.dismiss(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java index 4421b595..b4dc3d97 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditAPI.java @@ -77,21 +77,24 @@ public interface RedditAPI { @HeaderMap Map<String, String> headers); @FormUrlEncoded - @POST("/api/comment") + @POST("api/comment") Call<String> sendComment(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); @FormUrlEncoded - @POST("/api/del") + @POST("api/del") Call<String> delete(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); @FormUrlEncoded - @POST("/api/submit") + @POST("api/submit") Call<String> submit(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); @FormUrlEncoded - @POST("/api/media/asset.json?raw_json=1&gilding_detail=1") + @POST("api/media/asset.json?raw_json=1&gilding_detail=1") Call<String> uploadImage(@HeaderMap Map<String, String> headers, @FieldMap Map<String, String> params); + @GET("r/{subredditName}/api/link_flair.json?raw_json=1") + Call<String> getFlairs(@HeaderMap Map<String, String> headers, @Path("subredditName") String subredditName); + @Multipart @POST(".") Call<String> uploadMediaToAWS(@PartMap()Map<String, RequestBody> params, @Part() MultipartBody.Part file); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditUtils.java index 5246f423..670dd280 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditUtils.java @@ -63,9 +63,10 @@ public class RedditUtils { static final String SR_KEY = "sr"; static final String TITLE_KEY = "title"; + static final String FLAIR_TEXT_KEY = "flair_text"; + static final String SPOILER_KEY = "spoiler"; static final String NSFW_KEY = "nsfw"; static final String KIND_KEY = "kind"; - static final String KIND_TEXT = "text"; static final String KIND_SELF = "self"; static final String KIND_LINK = "link"; static final String KIND_IMAGE = "image"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java index bb6bf632..3d63b97a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPost.java @@ -42,23 +42,24 @@ class SubmitPost { } static void submitTextOrLinkPost(Retrofit oauthRetrofit, SharedPreferences authInfoSharedPreferences, - Locale locale, String subredditName, String title, String content, boolean isNSFW, - String kind, SubmitPostListener submitPostListener) { + Locale locale, String subredditName, String title, String content, + String flair, boolean isSpoiler, boolean isNSFW, String kind, + SubmitPostListener submitPostListener) { submitPost(oauthRetrofit, authInfoSharedPreferences, locale, subredditName, title, content, - isNSFW, kind, null, submitPostListener); + flair, isSpoiler, isNSFW, kind, null, submitPostListener); } static void submitImagePost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, SharedPreferences authInfoSharedPreferences, Locale locale, - String subredditName, String title, Bitmap image, boolean isNSFW, - SubmitPostListener submitPostListener) { + String subredditName, String title, Bitmap image, String flair, + boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) { uploadImage(oauthRetrofit, uploadMediaRetrofit, authInfoSharedPreferences, image, new UploadImageListener() { @Override public void uploaded(String imageUrl) { submitPost(oauthRetrofit, authInfoSharedPreferences, locale, - subredditName, title, imageUrl, isNSFW, RedditUtils.KIND_IMAGE, - null, submitPostListener); + subredditName, title, imageUrl, flair, isSpoiler, isNSFW, + RedditUtils.KIND_IMAGE, null, submitPostListener); } @Override @@ -71,7 +72,8 @@ class SubmitPost { static void submitVideoPost(Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, Retrofit uploadVideoRetrofit, SharedPreferences authInfoSharedPreferences, Locale locale, String subredditName, String title, byte[] buffer, String mimeType, - Bitmap posterBitmap, boolean isNSFW, SubmitPostListener submitPostListener) { + Bitmap posterBitmap, String flair, boolean isSpoiler, boolean isNSFW, + SubmitPostListener submitPostListener) { RedditAPI api = oauthRetrofit.create(RedditAPI.class); String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); @@ -115,12 +117,12 @@ class SubmitPost { public void uploaded(String imageUrl) { if(fileType.equals("gif")) { submitPost(oauthRetrofit, authInfoSharedPreferences, locale, - subredditName, title, url, isNSFW, RedditUtils.KIND_VIDEOGIF, - imageUrl, submitPostListener); + subredditName, title, url, flair, isSpoiler, isNSFW, + RedditUtils.KIND_VIDEOGIF, imageUrl, submitPostListener); } else { submitPost(oauthRetrofit, authInfoSharedPreferences, locale, - subredditName, title, url, isNSFW, RedditUtils.KIND_VIDEO, - imageUrl, submitPostListener); + subredditName, title, url, flair, isSpoiler, isNSFW, + RedditUtils.KIND_VIDEO, imageUrl, submitPostListener); } } @@ -168,8 +170,9 @@ class SubmitPost { } private static void submitPost(Retrofit oauthRetrofit, SharedPreferences authInfoSharedPreferences, - Locale locale, String subredditName, String title, String content, boolean isNSFW, - String kind, @Nullable String posterUrl, SubmitPostListener submitPostListener) { + Locale locale, String subredditName, String title, String content, + String flair, boolean isSpoiler, boolean isNSFW, String kind, + @Nullable String posterUrl, SubmitPostListener submitPostListener) { RedditAPI api = oauthRetrofit.create(RedditAPI.class); String accessToken = authInfoSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, ""); @@ -196,6 +199,8 @@ class SubmitPost { params.put(RedditUtils.VIDEO_POSTER_URL_KEY, posterUrl); break; } + params.put(RedditUtils.FLAIR_TEXT_KEY, flair); + params.put(RedditUtils.SPOILER_KEY, Boolean.toString(isSpoiler)); params.put(RedditUtils.NSFW_KEY, Boolean.toString(isNSFW)); Call<String> submitPostCall = api.submit(RedditUtils.getOAuthHeader(accessToken), params); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingRecyclerViewAdapter.java index bd1a7690..6adaecef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubredditListingRecyclerViewAdapter.java @@ -64,7 +64,7 @@ public class SubredditListingRecyclerViewAdapter extends PagedListAdapter<Subred glide = Glide.with(context.getApplicationContext()); } - static final DiffUtil.ItemCallback<SubredditData> DIFF_CALLBACK = new DiffUtil.ItemCallback<SubredditData>() { + private static final DiffUtil.ItemCallback<SubredditData> DIFF_CALLBACK = new DiffUtil.ItemCallback<SubredditData>() { @Override public boolean areItemsTheSame(@NonNull SubredditData oldItem, @NonNull SubredditData newItem) { return oldItem.getId().equals(newItem.getId()); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingRecyclerViewAdapter.java index 8ea69ae9..a67f7415 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserListingRecyclerViewAdapter.java @@ -64,7 +64,7 @@ public class UserListingRecyclerViewAdapter extends PagedListAdapter<UserData, R glide = Glide.with(context.getApplicationContext()); } - static final DiffUtil.ItemCallback<UserData> DIFF_CALLBACK = new DiffUtil.ItemCallback<UserData>() { + private static final DiffUtil.ItemCallback<UserData> DIFF_CALLBACK = new DiffUtil.ItemCallback<UserData>() { @Override public boolean areItemsTheSame(@NonNull UserData oldItem, @NonNull UserData newItem) { return oldItem.getName().equals(newItem.getName()); |