aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
6 files changed, 54 insertions, 166 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();
- }
}