From ebf542161e94cf6c9c1691b8681717a18afd42c2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 17 Jul 2019 09:31:49 +0800 Subject: [PATCH] Flair, spoiler and nsfw support for submitting posts. --- .idea/caches/build_file_checksums.ser | Bin 533 -> 533 bytes .idea/caches/gradle_models.ser | Bin 252117 -> 254881 bytes app/build.gradle | 1 + .../infinityforreddit/AppComponent.java | 1 + .../FetchFlairsInSubreddit.java | 97 ++++++++++++++++ .../FlairBottomSheetFragment.java | 106 ++++++++++++++++++ .../FlairBottomSheetRecyclerViewAdapter.java | 59 ++++++++++ .../infinityforreddit/JSONUtils.java | 1 + .../infinityforreddit/MainActivity.java | 1 - .../infinityforreddit/PostImageActivity.java | 81 ++++++++++++- .../infinityforreddit/PostLinkActivity.java | 83 +++++++++++++- .../PostRecyclerViewAdapter.java | 2 +- .../infinityforreddit/PostTextActivity.java | 87 +++++++++++++- .../infinityforreddit/PostVideoActivity.java | 81 ++++++++++++- .../infinityforreddit/RedditAPI.java | 11 +- .../infinityforreddit/RedditUtils.java | 3 +- .../infinityforreddit/SubmitPost.java | 33 +++--- .../SubredditListingRecyclerViewAdapter.java | 2 +- .../UserListingRecyclerViewAdapter.java | 2 +- .../main/res/layout/activity_post_image.xml | 51 +++++++++ .../main/res/layout/activity_post_link.xml | 51 +++++++++ .../main/res/layout/activity_post_text.xml | 51 +++++++++ .../main/res/layout/activity_post_video.xml | 51 +++++++++ .../layout/fragment_flair_bottom_sheet.xml | 37 ++++++ app/src/main/res/layout/item_flair.xml | 16 +++ .../res/layout/post_type_bottom_sheet.xml | 10 +- app/src/main/res/values/strings.xml | 16 ++- 27 files changed, 893 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FetchFlairsInSubreddit.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetFragment.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FlairBottomSheetRecyclerViewAdapter.java create mode 100644 app/src/main/res/layout/fragment_flair_bottom_sheet.xml create mode 100644 app/src/main/res/layout/item_flair.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 1cfd9c5e2552a5b7e839c80466083f9336235e20..077d0a62d9b41b8531d7879c88dfcdd70fe27ed5 100644 GIT binary patch delta 33 pcmbQrGL>b*43=NV%W5{x$zT*@UTauzrh?;`z)N+@d6g;WDgf@T4psmF delta 33 pcmbQrGL>b*43>9u|BG*&lfft`ufmvAyC}f5;BCBg;j#_;D*)rk4fX&4 diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 5e1c67d60a13edc16c4d4f26bf9ce7f94853dd6b..1ed31ba22debcf58e45daceb3a68e2cf004b0131 100644 GIT binary patch delta 12794 zcma)Dc|cXw_U4>(FW?=yi1UExb4q1WL~sDanM~A7(-ax5ibISJIf0mu#M!It%1FUT z%^VSLX@#a`Y5p9_EU9N|=9D>DR#+mzC)e z=5j=|o}ZiL&dpL9XR_l>6i?^vGjXx$*&fZ3)20MYPE8upH!^u@R(9HyZ0C&ZX{pZX zk)eU1(TRzf=@}k#l|QmLs!e@PM|Q~euvK^DL2Ah$+)azg_R#oXb@#k?UHdmjHghHh zcL@pa*fG%=5fYLV9F`QC6xw;5GdZktcvy1BafzI>A>rX6Nf9Z@&ZLeh!6C^hosvVslR9>Bri2HFc1cWeCXI6@>c(~m4Rkr~_V%x7 z4mrzq{||-3*UOZ~LK2itH7+(wysdPt*~{@z>0Pr|z^_Ve#l%*uSHo&{ zc4+GV5OV);wM)&hGD_8^$y5i9>{=I+@^ zJq$K$gc{CmmGQY%XF9qkKcyu-)NlCl+c4=y5uWtuUTSmqx3TI07*o_w?ZWGzyu;$T zDE8)80q%}*>M1^?@bmBoLWHHKC;=>XqT0e;5U+0Krr+Nm6^PM%YV%qv9HxE?(b7k% z!BCOK32JMjq40%P&#~hVln7Tk3vjn`svq%@BNl&9ghBUB=Ec!-qI#0Ei=sC)#mb7_ z$l1&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4&V~N4S=5keg}a3_&ER|7k-rhV9WhN0bpnSS^;zf z=mGE!z+iyUaK`0UiK672pqP z@^=DM0Dx2E9|8~#&>SEVpsRp){ojO-@ZO34aDZ3=s6dSf;O0CidMHoesne62~ICf~v_`z{W;}6X%e&>q24zs7Wp4|Hg%c$R{!7qQ@7H@FD znfC&hwx8fE`SuTL*8NZ7#HWC+JneJVTD+8Ha5Ilp>xmEL;cytd;3Z>l5dbw|gHrm} zH?;z~X1{kQCJqL66F_fj1vKE(^H^&*Q?~zjPUW%wHd~(zTZ`sAX&Q5Q27k%w)L^Z> ayfRvMtnA6W&bn!~4*cFtwpVL8{eJ-JdxPEp diff --git a/app/build.gradle b/app/build.gradle index 38709efd..92fb64ab 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -74,4 +74,5 @@ dependencies { implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16' implementation 'com.github.Ferfalk:SimpleSearchView:0.1.3' implementation 'org.greenrobot:eventbus:3.1.1' + implementation 'com.libRG:customtextview:2.2' } 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 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 flairsCall = api.getFlairs(RedditUtils.getOAuthHeader(accessToken), subredditName); + flairsCall.enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + new ParseFlairsAsyncTask(response.body(), new ParseFlairsAsyncTask.ParseFlairsAsyncTaskListener() { + @Override + public void parseSuccessful(ArrayList 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 call, @NonNull Throwable t) { + fetchFlairsInSubredditListener.fetchFailed(); + } + }); + } + + private static class ParseFlairsAsyncTask extends AsyncTask, ArrayList> { + interface ParseFlairsAsyncTaskListener { + void parseSuccessful(ArrayList flairs); + void parseFailed(); + } + + private String response; + private ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener; + + ParseFlairsAsyncTask(String response, ParseFlairsAsyncTaskListener parseFlairsAsyncTaskListener) { + this.response = response; + this.parseFlairsAsyncTaskListener = parseFlairsAsyncTaskListener; + } + + @Override + protected ArrayList doInBackground(Void... voids) { + try { + JSONArray jsonArray = new JSONArray(response); + ArrayList 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 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 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 { + interface ItemClickListener { + void onClick(String flair); + } + + private ArrayList 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 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 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 DIFF_CALLBACK = new DiffUtil.ItemCallback() { + private static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { @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 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 headers); @FormUrlEncoded - @POST("/api/comment") + @POST("api/comment") Call sendComment(@HeaderMap Map headers, @FieldMap Map params); @FormUrlEncoded - @POST("/api/del") + @POST("api/del") Call delete(@HeaderMap Map headers, @FieldMap Map params); @FormUrlEncoded - @POST("/api/submit") + @POST("api/submit") Call submit(@HeaderMap Map headers, @FieldMap Map 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 uploadImage(@HeaderMap Map headers, @FieldMap Map params); + @GET("r/{subredditName}/api/link_flair.json?raw_json=1") + Call getFlairs(@HeaderMap Map headers, @Path("subredditName") String subredditName); + @Multipart @POST(".") Call uploadMediaToAWS(@PartMap()Map 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 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 DIFF_CALLBACK = new DiffUtil.ItemCallback() { + private static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { @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 DIFF_CALLBACK = new DiffUtil.ItemCallback() { + private static final DiffUtil.ItemCallback DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override public boolean areItemsTheSame(@NonNull UserData oldItem, @NonNull UserData newItem) { return oldItem.getName().equals(newItem.getName()); diff --git a/app/src/main/res/layout/activity_post_image.xml b/app/src/main/res/layout/activity_post_image.xml index 60a6029e..ce345d58 100644 --- a/app/src/main/res/layout/activity_post_image.xml +++ b/app/src/main/res/layout/activity_post_image.xml @@ -54,6 +54,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_flair.xml b/app/src/main/res/layout/item_flair.xml new file mode 100644 index 00000000..c6006358 --- /dev/null +++ b/app/src/main/res/layout/item_flair.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/post_type_bottom_sheet.xml b/app/src/main/res/layout/post_type_bottom_sheet.xml index 617c1aa3..092495c4 100644 --- a/app/src/main/res/layout/post_type_bottom_sheet.xml +++ b/app/src/main/res/layout/post_type_bottom_sheet.xml @@ -7,7 +7,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="16dp" - android:text="@string/dialog_post_type" + android:text="@string/bottom_sheet_post_type" android:textSize="18sp" /> @@ -58,7 +58,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/dialog_post_link" + android:text="@string/bottom_sheet_post_link" android:textColor="@color/primaryTextColor" android:textSize="18sp" /> @@ -85,7 +85,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/dialog_post_image" + android:text="@string/bottom_sheet_post_image" android:textColor="@color/primaryTextColor" android:textSize="18sp" /> @@ -113,7 +113,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" - android:text="@string/dialog_post_video" + android:text="@string/bottom_sheet_post_video" android:textColor="@color/primaryTextColor" android:textSize="18sp" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f7b748f5..d76df6b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,15 +107,21 @@ Subreddits Users - Post - Text - Link - Image - Video + Post + Text + Link + Image + Video Select a picture Select again Error getting the image Video is processing. Please wait. + + Flair + Spoiler + + No flair + Error loading flairs.\nTap to retry.