diff options
10 files changed, 57 insertions, 181 deletions
diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index 599bbd3b..1b44cede 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -159,7 +159,7 @@ <map> <entry key="assetSourceType" value="FILE" /> <entry key="color" value="ffffff" /> - <entry key="outputName" value="ic_notification" /> + <entry key="outputName" value="ic_ufo" /> <entry key="sourceFile" value="$USER_HOME$/Downloads/ic_notification.svg" /> </map> </option> diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CancelSubmittingPostEvent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CancelSubmittingPostEvent.java deleted file mode 100644 index 4eb26072..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CancelSubmittingPostEvent.java +++ /dev/null @@ -1,3 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -public class CancelSubmittingPostEvent {} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java index 6cbb8e7b..aedaf37b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java @@ -373,6 +373,16 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS }).execute(); } + private void promptAlertDialog(int titleResId, int messageResId) { + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(titleResId) + .setMessage(messageResId) + .setPositiveButton(R.string.yes, (dialogInterface, i) + -> finish()) + .setNegativeButton(R.string.no, null) + .show(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.post_image_activity, menu); @@ -389,29 +399,11 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS switch (item.getItemId()) { case android.R.id.home: if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); return true; } else { if(!titleEditText.getText().toString().equals("") || imageUri != null) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); return true; } } @@ -472,28 +464,10 @@ public class PostImageActivity extends AppCompatActivity implements FlairBottomS @Override public void onBackPressed() { if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); } else { if(!titleEditText.getText().toString().equals("") || imageUri != null) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); } else { finish(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java index c8e8f875..f64cdcee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java @@ -305,6 +305,15 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh }).execute(); } + private void promptAlertDialog(int titleResId, int messageResId) { + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(titleResId) + .setMessage(messageResId) + .setPositiveButton(R.string.yes, (dialogInterface, i) -> finish()) + .setNegativeButton(R.string.no, null) + .show(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.post_link_activity, menu); @@ -321,26 +330,11 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh switch (item.getItemId()) { case android.R.id.home: if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); return true; } else { if(!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> finish()) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); return true; } } @@ -397,25 +391,10 @@ public class PostLinkActivity extends AppCompatActivity implements FlairBottomSh @Override public void onBackPressed() { if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); } else { if(!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> finish()) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); } else { finish(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java index 978253d4..6364cde9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java @@ -309,6 +309,16 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh }).execute(); } + private void promptAlertDialog(int titleResId, int messageResId) { + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(titleResId) + .setMessage(messageResId) + .setPositiveButton(R.string.yes, (dialogInterface, i) + -> finish()) + .setNegativeButton(R.string.no, null) + .show(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.post_text_activity, menu); @@ -325,29 +335,11 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh switch (item.getItemId()) { case android.R.id.home: if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); return true; } else { if(!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); return true; } } @@ -399,28 +391,10 @@ public class PostTextActivity extends AppCompatActivity implements FlairBottomSh @Override public void onBackPressed() { if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); } else { if(!titleEditText.getText().toString().equals("") || !contentEditText.getText().toString().equals("")) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); } else { finish(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java index 7755121e..50ba6912 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java @@ -368,6 +368,15 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS }).execute(); } + private void promptAlertDialog(int titleResId, int messageResId) { + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(titleResId) + .setMessage(messageResId) + .setPositiveButton(R.string.yes, (dialogInterface, i) -> finish()) + .setNegativeButton(R.string.no, null) + .show(); + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.post_video_activity, menu); @@ -384,29 +393,11 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS switch (item.getItemId()) { case android.R.id.home: if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); return true; } else { if(!titleEditText.getText().toString().equals("") || videoUri != null) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); return true; } } @@ -467,28 +458,10 @@ public class PostVideoActivity extends AppCompatActivity implements FlairBottomS @Override public void onBackPressed() { if(isPosting) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.cancel_submit_post) - .setMessage(R.string.cancel_submit_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.exit_when_submit_post, R.string.exit_when_submit_post_detail); } else { if(!titleEditText.getText().toString().equals("") || videoUri != null) { - new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.discard_post) - .setMessage(R.string.discard_post_detail) - .setPositiveButton(R.string.yes, (dialogInterface, i) - -> { - EventBus.getDefault().post(new CancelSubmittingPostEvent()); - finish(); - }) - .setNegativeButton(R.string.no, null) - .show(); + promptAlertDialog(R.string.discard_post, R.string.discard_post_detail); } else { finish(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java index 3e3fc242..efb6a7df 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java @@ -22,7 +22,6 @@ import com.bumptech.glide.request.target.CustomTarget; import com.bumptech.glide.request.transition.Transition; import org.greenrobot.eventbus.EventBus; -import org.greenrobot.eventbus.Subscribe; import java.io.FileInputStream; import java.io.IOException; @@ -79,8 +78,6 @@ public class SubmitPostService extends Service { public int onStartCommand(Intent intent, int flags, int startId) { ((Infinity) getApplication()).getAppComponent().inject(this); - EventBus.getDefault().register(this); - mAccessToken = intent.getStringExtra(EXTRA_ACCESS_TOKEN); subredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME); title = intent.getStringExtra(EXTRA_TITLE); @@ -229,13 +226,7 @@ public class SubmitPostService extends Service { } private void stopService() { - EventBus.getDefault().unregister(this); stopForeground(true); stopSelf(); } - - @Subscribe - public void onCancelSubmittingPostEvent(CancelSubmittingPostEvent event) { - stopService(); - } } diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 5039ca20..5a0f4287 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -58,8 +58,6 @@ android:elevation="1dp" android:visibility="gone" /> - <!--<include layout="@layout/content_main" />--> - <androidx.viewpager.widget.ViewPager android:id="@+id/view_pager_main_activity" android:layout_width="match_parent" diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml deleted file mode 100644 index 6f29dd60..00000000 --- a/app/src/main/res/layout/content_main.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/frame_layout_content_main" - android:layout_width="match_parent" - android:layout_height="match_parent" - app:layout_behavior="@string/appbar_scrolling_view_behavior" - tools:application="ml.docilealligator.infinityforreddit.MainActivity" - tools:showIn="@layout/app_bar_main" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4dbf4a7e..85a70bbb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -280,8 +280,8 @@ <string name="no_link_available">Cannot get the link</string> - <string name="cancel_submit_post">Cancel Submitting</string> - <string name="cancel_submit_post_detail">The post may still be submitted even if you cancel here.</string> + <string name="exit_when_submit_post">Leave?</string> + <string name="exit_when_submit_post_detail">The post will still be submitted even if you leave here.</string> <string name="discard_post">Discard?</string> <string name="discard_post_detail">All the draft will not be saved.</string> <string name="yes">Yes</string> |