mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-02-02 21:04:48 +01:00
Continue submitting posts even if the user leave PostXXXActivity.
This commit is contained in:
parent
2133231d52
commit
30d2abe9c6
2
.idea/assetWizardSettings.xml
generated
2
.idea/assetWizardSettings.xml
generated
@ -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>
|
||||
|
@ -1,3 +0,0 @@
|
||||
package ml.docilealligator.infinityforreddit;
|
||||
|
||||
public class CancelSubmittingPostEvent {}
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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" />
|
@ -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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user