aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-28 02:21:32 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-28 02:21:32 +0000
commit30d2abe9c691bf1603495bd7ae1abebbc447e0a8 (patch)
tree256db97d2bc51022890c88133703314a3cf66569 /app
parent2133231d524cf40f78682d0763656fb6a99e536c (diff)
downloadinfinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.tar
infinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.tar.gz
infinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.tar.bz2
infinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.tar.lz
infinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.tar.xz
infinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.tar.zst
infinity-for-reddit-30d2abe9c691bf1603495bd7ae1abebbc447e0a8.zip
Continue submitting posts even if the user leave PostXXXActivity.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CancelSubmittingPostEvent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostImageActivity.java54
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostLinkActivity.java47
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostTextActivity.java54
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostVideoActivity.java53
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SubmitPostService.java9
-rw-r--r--app/src/main/res/layout/app_bar_main.xml2
-rw-r--r--app/src/main/res/layout/content_main.xml10
-rw-r--r--app/src/main/res/values/strings.xml4
9 files changed, 56 insertions, 180 deletions
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>