diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-07-14 14:18:38 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-07-14 14:18:38 +0000 |
commit | 4363731a8113bd4c4c929223c76f1ee1e6556c9d (patch) | |
tree | 2b417af9e8d02ac865649e247fbb9d8a4f66e9b4 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | e2e7a8cdcd85e016195e71f57e61edcee70f02ca (diff) | |
download | infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.tar infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.tar.gz infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.tar.bz2 infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.tar.lz infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.tar.xz infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.tar.zst infinity-for-reddit-4363731a8113bd4c4c929223c76f1ee1e6556c9d.zip |
Choose whether receiving post reply notifications or not in PostTextActivity.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
4 files changed, 69 insertions, 34 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java index f1cd11cc..17fe8011 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -16,6 +16,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -34,6 +35,7 @@ import com.bumptech.glide.request.RequestOptions; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; +import com.google.android.material.switchmaterial.SwitchMaterial; import com.libRG.CustomTextView; import org.greenrobot.eventbus.EventBus; @@ -97,9 +99,9 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr AppBarLayout appBarLayout; @BindView(R.id.toolbar_post_text_activity) Toolbar toolbar; - @BindView(R.id.subreddit_icon_gif_image_view_search_activity) + @BindView(R.id.subreddit_icon_gif_image_view_post_text_activity) GifImageView iconGifImageView; - @BindView(R.id.subreddit_name_text_view_search_activity) + @BindView(R.id.subreddit_name_text_view_post_text_activity) TextView subredditNameTextView; @BindView(R.id.rules_button_post_text_activity) Button rulesButton; @@ -113,10 +115,18 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr CustomTextView nsfwTextView; @BindView(R.id.divider_2_post_text_activity) View divider2; - @BindView(R.id.post_title_edit_text_post_text_activity) - EditText titleEditText; + @BindView(R.id.receive_post_reply_notifications_linear_layout_post_text_activity) + LinearLayout receivePostReplyNotificationsLinearLayout; + @BindView(R.id.receive_post_reply_notifications_text_view_post_text_activity) + TextView receivePostReplyNotificationsTextView; + @BindView(R.id.receive_post_reply_notifications_switch_material_post_text_activity) + SwitchMaterial receivePostReplyNotificationsSwitchMaterial; @BindView(R.id.divider_3_post_text_activity) View divider3; + @BindView(R.id.post_title_edit_text_post_text_activity) + EditText titleEditText; + @BindView(R.id.divider_4_post_text_activity) + View divider4; @BindView(R.id.post_text_content_edit_text_post_text_activity) EditText contentEditText; @BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity) @@ -333,6 +343,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr } }); + receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> { + receivePostReplyNotificationsSwitchMaterial.performClick(); + }); + MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter( mCustomThemeWrapper, new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() { @Override @@ -376,11 +390,13 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr subredditNameTextView.setTextColor(secondaryTextColor); rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor()); rulesButton.setBackgroundTintList(ColorStateList.valueOf(mCustomThemeWrapper.getColorPrimaryLightTheme())); + primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + receivePostReplyNotificationsTextView.setTextColor(primaryTextColor); int dividerColor = mCustomThemeWrapper.getDividerColor(); divider1.setBackgroundColor(dividerColor); divider2.setBackgroundColor(dividerColor); divider3.setBackgroundColor(dividerColor); - primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor(); + divider4.setBackgroundColor(dividerColor); flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor(); flairTextColor = mCustomThemeWrapper.getFlairTextColor(); spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor(); @@ -423,9 +439,9 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) .setTitle(titleResId) .setMessage(messageResId) - .setPositiveButton(R.string.yes, (dialogInterface, i) + .setPositiveButton(R.string.discard, (dialogInterface, i) -> finish()) - .setNegativeButton(R.string.no, null) + .setNegativeButton(R.string.cancel, null) .show(); } @@ -494,6 +510,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair); intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler); intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW); + intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked()); intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK); ContextCompat.startForegroundService(this, intent); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java index b7dd5f59..bf6fdbda 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/SubmitPost.java @@ -13,7 +13,6 @@ import org.xmlpull.v1.XmlPullParserException; import java.io.File; import java.io.IOException; import java.util.HashMap; -import java.util.Locale; import java.util.Map; import java.util.concurrent.Executor; @@ -31,22 +30,24 @@ import retrofit2.Retrofit; public class SubmitPost { public static void submitTextOrLinkPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken, - Locale locale, String subredditName, String title, String content, - Flair flair, boolean isSpoiler, boolean isNSFW, String kind, + String subredditName, String title, String content, + Flair flair, boolean isSpoiler, boolean isNSFW, + boolean receivePostReplyNotifications, String kind, SubmitPostListener submitPostListener) { submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, content, - flair, isSpoiler, isNSFW, kind, null, submitPostListener); + flair, isSpoiler, isNSFW, receivePostReplyNotifications, kind, null, submitPostListener); } public static void submitImagePost(Executor executor, Handler handler, Retrofit oauthRetrofit, Retrofit uploadMediaRetrofit, String accessToken, String subredditName, String title, Bitmap image, - Flair flair, boolean isSpoiler, boolean isNSFW, SubmitPostListener submitPostListener) { + Flair flair, boolean isSpoiler, boolean isNSFW, + boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) { try { String imageUrlOrError = UploadImageUtils.uploadImage(oauthRetrofit, uploadMediaRetrofit, accessToken, image); if (imageUrlOrError != null && !imageUrlOrError.startsWith("Error: ")) { submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, imageUrlOrError, flair, isSpoiler, isNSFW, - APIUtils.KIND_IMAGE, null, submitPostListener); + receivePostReplyNotifications, APIUtils.KIND_IMAGE, null, submitPostListener); } else { submitPostListener.submitFailed(imageUrlOrError); } @@ -60,7 +61,7 @@ public class SubmitPost { Retrofit uploadVideoRetrofit, String accessToken, String subredditName, String title, File buffer, String mimeType, Bitmap posterBitmap, Flair flair, boolean isSpoiler, boolean isNSFW, - SubmitPostListener submitPostListener) { + boolean receivePostReplyNotifications, SubmitPostListener submitPostListener) { RedditAPI api = oauthRetrofit.create(RedditAPI.class); String fileType = mimeType.substring(mimeType.indexOf("/") + 1); @@ -97,11 +98,13 @@ public class SubmitPost { if (fileType.equals("gif")) { submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, url, flair, isSpoiler, isNSFW, - APIUtils.KIND_VIDEOGIF, imageUrlOrError, submitPostListener); + receivePostReplyNotifications, APIUtils.KIND_VIDEOGIF, imageUrlOrError, + submitPostListener); } else { submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, url, flair, isSpoiler, isNSFW, - APIUtils.KIND_VIDEO, imageUrlOrError, submitPostListener); + receivePostReplyNotifications, APIUtils.KIND_VIDEO, imageUrlOrError, + submitPostListener); } } else { submitPostListener.submitFailed(imageUrlOrError); @@ -119,16 +122,18 @@ public class SubmitPost { } public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken, - String subredditName, String title, String crosspostFullname, - Flair flair, boolean isSpoiler, boolean isNSFW, String kind, - SubmitPostListener submitPostListener) { + String subredditName, String title, String crosspostFullname, + Flair flair, boolean isSpoiler, boolean isNSFW, + boolean receivePostReplyNotifications, String kind, + SubmitPostListener submitPostListener) { submitPost(executor, handler, oauthRetrofit, accessToken, subredditName, title, crosspostFullname, - flair, isSpoiler, isNSFW, kind, null, submitPostListener); + flair, isSpoiler, isNSFW, receivePostReplyNotifications, kind, null, submitPostListener); } private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken, String subredditName, String title, String content, - Flair flair, boolean isSpoiler, boolean isNSFW, String kind, + Flair flair, boolean isSpoiler, boolean isNSFW, + boolean receivePostReplyNotifications, String kind, @Nullable String posterUrl, SubmitPostListener submitPostListener) { RedditAPI api = oauthRetrofit.create(RedditAPI.class); @@ -165,6 +170,7 @@ public class SubmitPost { } params.put(APIUtils.SPOILER_KEY, Boolean.toString(isSpoiler)); params.put(APIUtils.NSFW_KEY, Boolean.toString(isNSFW)); + params.put(APIUtils.SEND_REPLIES_KEY, Boolean.toString(receivePostReplyNotifications)); Call<String> submitPostCall = api.submit(APIUtils.getOAuthHeader(accessToken), params); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java index 12b4e1a5..4d21ef12 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java @@ -61,6 +61,7 @@ public class SubmitPostService extends Service { public static final String EXTRA_FLAIR = "EF"; public static final String EXTRA_IS_SPOILER = "EIS"; public static final String EXTRA_IS_NSFW = "EIN"; + public static final String EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS = "ERPRN"; public static final String EXTRA_POST_TYPE = "EPT"; public static final int EXTRA_POST_TEXT_OR_LINK = 0; public static final int EXTRA_POST_TYPE_IMAGE = 1; @@ -107,22 +108,26 @@ public class SubmitPostService extends Service { Flair flair = bundle.getParcelable(EXTRA_FLAIR); boolean isSpoiler = bundle.getBoolean(EXTRA_IS_SPOILER, false); boolean isNSFW = bundle.getBoolean(EXTRA_IS_NSFW, false); + boolean receivePostReplyNotifications = bundle.getBoolean(EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, true); int postType = bundle.getInt(EXTRA_POST_TYPE, EXTRA_POST_TEXT_OR_LINK); if (postType == EXTRA_POST_TEXT_OR_LINK) { String content = bundle.getString(EXTRA_CONTENT); String kind = bundle.getString(EXTRA_KIND); - submitTextOrLinkPost(accessToken, subredditName, title, content, flair, isSpoiler, isNSFW, kind); + submitTextOrLinkPost(accessToken, subredditName, title, content, flair, isSpoiler, isNSFW, + receivePostReplyNotifications, kind); } else if (postType == EXTRA_POST_TYPE_CROSSPOST) { String content = bundle.getString(EXTRA_CONTENT); submitCrosspost(mExecutor, handler, accessToken, subredditName, title, content, - flair, isSpoiler, isNSFW); + flair, isSpoiler, isNSFW, receivePostReplyNotifications); } else if (postType == EXTRA_POST_TYPE_IMAGE) { Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI)); - submitImagePost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW); + submitImagePost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW, + receivePostReplyNotifications); } else { Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI)); - submitVideoPost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW); + submitVideoPost(accessToken, mediaUri, subredditName, title, flair, isSpoiler, isNSFW, + receivePostReplyNotifications); } } } @@ -190,10 +195,12 @@ public class SubmitPostService extends Service { .build(); } - private void submitTextOrLinkPost(String accessToken, String subredditName, String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW, String kind) { + private void submitTextOrLinkPost(String accessToken, String subredditName, String title, String content, + Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications, + String kind) { SubmitPost.submitTextOrLinkPost(mExecutor, handler, mOauthRetrofit, accessToken, - getResources().getConfiguration().locale, subredditName, title, content, flair, isSpoiler, - isNSFW, kind, new SubmitPost.SubmitPostListener() { + subredditName, title, content, flair, isSpoiler, + isNSFW, receivePostReplyNotifications, kind, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null))); @@ -211,9 +218,11 @@ public class SubmitPostService extends Service { } private void submitCrosspost(Executor executor, Handler handler, String accessToken, String subredditName, - String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW) { + String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW, + boolean receivePostReplyNotifications) { SubmitPost.submitCrosspost(executor, handler, mOauthRetrofit, accessToken, subredditName, title, - content, flair, isSpoiler, isNSFW, APIUtils.KIND_CROSSPOST, new SubmitPost.SubmitPostListener() { + content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST, + new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { handler.post(() -> EventBus.getDefault().post(new SubmitCrosspostEvent(true, post, null))); @@ -230,11 +239,12 @@ public class SubmitPostService extends Service { }); } - private void submitImagePost(String accessToken, Uri mediaUri, String subredditName, String title, Flair flair, boolean isSpoiler, boolean isNSFW) { + private void submitImagePost(String accessToken, Uri mediaUri, String subredditName, String title, + Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications) { try { Bitmap resource = Glide.with(this).asBitmap().load(mediaUri).submit().get(); SubmitPost.submitImagePost(mExecutor, handler, mOauthRetrofit, mUploadMediaRetrofit, - accessToken, subredditName, title, resource, flair, isSpoiler, isNSFW, + accessToken, subredditName, title, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { @@ -261,7 +271,7 @@ public class SubmitPostService extends Service { } private void submitVideoPost(String accessToken, Uri mediaUri, String subredditName, String title, - Flair flair, boolean isSpoiler, boolean isNSFW) { + Flair flair, boolean isSpoiler, boolean isNSFW, boolean receivePostReplyNotifications) { try { InputStream in = getContentResolver().openInputStream(mediaUri); String type = getContentResolver().getType(mediaUri); @@ -279,7 +289,8 @@ public class SubmitPostService extends Service { if (type != null) { SubmitPost.submitVideoPost(mExecutor, handler, mOauthRetrofit, mUploadMediaRetrofit, mUploadVideoRetrofit, accessToken, subredditName, title, new File(cacheFilePath), - type, resource, flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() { + type, resource, flair, isSpoiler, isNSFW, receivePostReplyNotifications, + new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { handler.post(() -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java index 5ad14398..465a31eb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/APIUtils.java @@ -73,6 +73,7 @@ public class APIUtils { public static final String SPOILER_KEY = "spoiler"; public static final String NSFW_KEY = "nsfw"; public static final String CROSSPOST_FULLNAME_KEY = "crosspost_fullname"; + public static final String SEND_REPLIES_KEY = "sendreplies"; public static final String KIND_KEY = "kind"; public static final String KIND_SELF = "self"; public static final String KIND_LINK = "link"; |