|
6 | 6 | import android.content.Intent;
|
7 | 7 | import android.content.SharedPreferences;
|
8 | 8 | import android.content.res.Resources;
|
9 |
| -import android.os.Build; |
10 | 9 | import android.os.Bundle;
|
11 | 10 | import android.os.Handler;
|
12 | 11 | import android.os.PersistableBundle;
|
|
16 | 15 | import android.webkit.URLUtil;
|
17 | 16 | import android.widget.Toast;
|
18 | 17 |
|
| 18 | +import androidx.activity.OnBackPressedCallback; |
19 | 19 | import androidx.annotation.NonNull;
|
20 | 20 | import androidx.annotation.Nullable;
|
21 | 21 | import androidx.core.graphics.Insets;
|
|
39 | 39 | import javax.inject.Named;
|
40 | 40 |
|
41 | 41 | import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
|
42 |
| -import ml.docilealligator.infinityforreddit.subreddit.Flair; |
43 | 42 | import ml.docilealligator.infinityforreddit.Infinity;
|
44 | 43 | import ml.docilealligator.infinityforreddit.R;
|
45 | 44 | import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
|
46 |
| -import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; |
47 | 45 | import ml.docilealligator.infinityforreddit.account.Account;
|
48 | 46 | import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter;
|
49 | 47 | import ml.docilealligator.infinityforreddit.apis.TitleSuggestion;
|
|
56 | 54 | import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent;
|
57 | 55 | import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
|
58 | 56 | import ml.docilealligator.infinityforreddit.services.SubmitPostService;
|
| 57 | +import ml.docilealligator.infinityforreddit.subreddit.Flair; |
| 58 | +import ml.docilealligator.infinityforreddit.thing.SelectThingReturnKey; |
59 | 59 | import ml.docilealligator.infinityforreddit.utils.APIUtils;
|
60 | 60 | import retrofit2.Call;
|
61 | 61 | import retrofit2.Callback;
|
@@ -391,6 +391,24 @@ public void onUploadImage() {
|
391 | 391 | binding.markdownBottomBarRecyclerViewPostLinkActivity.setLayoutManager(new LinearLayoutManagerBugFixed(this,
|
392 | 392 | LinearLayoutManager.HORIZONTAL, true).setStackFromEndAndReturnCurrentObject());
|
393 | 393 | binding.markdownBottomBarRecyclerViewPostLinkActivity.setAdapter(adapter);
|
| 394 | + |
| 395 | + getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { |
| 396 | + @Override |
| 397 | + public void handleOnBackPressed() { |
| 398 | + if (isPosting) { |
| 399 | + promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail); |
| 400 | + } else { |
| 401 | + if (!binding.postTitleEditTextPostLinkActivity.getText().toString().isEmpty() |
| 402 | + || !binding.postContentEditTextPostLinkActivity.getText().toString().isEmpty() |
| 403 | + || !binding.postLinkEditTextPostLinkActivity.getText().toString().isEmpty()) { |
| 404 | + promptAlertDialog(R.string.discard, R.string.discard_detail); |
| 405 | + } else { |
| 406 | + setEnabled(false); |
| 407 | + triggerBackPress(); |
| 408 | + } |
| 409 | + } |
| 410 | + } |
| 411 | + }); |
394 | 412 | }
|
395 | 413 |
|
396 | 414 | private void loadCurrentAccount() {
|
@@ -522,18 +540,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
|
522 | 540 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
523 | 541 | int itemId = item.getItemId();
|
524 | 542 | if (itemId == android.R.id.home) {
|
525 |
| - if (isPosting) { |
526 |
| - promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail); |
527 |
| - return true; |
528 |
| - } else { |
529 |
| - if (!binding.postTitleEditTextPostLinkActivity.getText().toString().isEmpty() |
530 |
| - || !binding.postContentEditTextPostLinkActivity.getText().toString().isEmpty() |
531 |
| - || !binding.postLinkEditTextPostLinkActivity.getText().toString().isEmpty()) { |
532 |
| - promptAlertDialog(R.string.discard, R.string.discard_detail); |
533 |
| - return true; |
534 |
| - } |
535 |
| - } |
536 |
| - finish(); |
| 543 | + triggerBackPress(); |
537 | 544 | return true;
|
538 | 545 | } else if (itemId == R.id.action_send_post_link_activity) {
|
539 | 546 | if (!subredditSelected) {
|
@@ -614,21 +621,6 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
614 | 621 | return false;
|
615 | 622 | }
|
616 | 623 |
|
617 |
| - @Override |
618 |
| - public void onBackPressed() { |
619 |
| - if (isPosting) { |
620 |
| - promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail); |
621 |
| - } else { |
622 |
| - if (!binding.postTitleEditTextPostLinkActivity.getText().toString().isEmpty() |
623 |
| - || !binding.postContentEditTextPostLinkActivity.getText().toString().isEmpty() |
624 |
| - || !binding.postLinkEditTextPostLinkActivity.getText().toString().isEmpty()) { |
625 |
| - promptAlertDialog(R.string.discard, R.string.discard_detail); |
626 |
| - } else { |
627 |
| - finish(); |
628 |
| - } |
629 |
| - } |
630 |
| - } |
631 |
| - |
632 | 624 | @Override
|
633 | 625 | protected void onSaveInstanceState(@NonNull Bundle outState) {
|
634 | 626 | super.onSaveInstanceState(outState);
|
|
0 commit comments