Merge pull request #5532 from ByteHamster/delete-use-action

Fix crash when deleting feed
This commit is contained in:
ByteHamster 2021-11-07 14:57:40 +01:00 committed by GitHub
commit 58293350c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 17 deletions

View File

@ -19,18 +19,18 @@ import io.reactivex.schedulers.Schedulers;
public class RemoveFeedDialog { public class RemoveFeedDialog {
private static final String TAG = "RemoveFeedDialog"; private static final String TAG = "RemoveFeedDialog";
public static void show(Context context, Feed feed, Runnable onSuccess) { public static void show(Context context, Feed feed) {
List<Feed> feeds = Collections.singletonList(feed); List<Feed> feeds = Collections.singletonList(feed);
String message = getMessageId(context, feeds); String message = getMessageId(context, feeds);
showDialog(context, feeds, message, onSuccess); showDialog(context, feeds, message);
} }
public static void show(Context context, List<Feed> feeds, Runnable onSuccess) { public static void show(Context context, List<Feed> feeds) {
String message = getMessageId(context, feeds); String message = getMessageId(context, feeds);
showDialog(context, feeds, message, onSuccess); showDialog(context, feeds, message);
} }
private static void showDialog(Context context, List<Feed> feeds, String message, Runnable onSuccess) { private static void showDialog(Context context, List<Feed> feeds, String message) {
ConfirmationDialog dialog = new ConfirmationDialog(context, R.string.remove_feed_label, message) { ConfirmationDialog dialog = new ConfirmationDialog(context, R.string.remove_feed_label, message) {
@Override @Override
public void onConfirmButtonPressed(DialogInterface clickedDialog) { public void onConfirmButtonPressed(DialogInterface clickedDialog) {
@ -42,20 +42,16 @@ public class RemoveFeedDialog {
progressDialog.setCancelable(false); progressDialog.setCancelable(false);
progressDialog.show(); progressDialog.show();
Completable.fromCallable(() -> { Completable.fromAction(() -> {
for (Feed feed : feeds) { for (Feed feed : feeds) {
DBWriter.deleteFeed(context, feed.getId()).get(); DBWriter.deleteFeed(context, feed.getId()).get();
} }
return null;
}) })
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe( .subscribe(
() -> { () -> {
Log.d(TAG, "Feed(s) deleted"); Log.d(TAG, "Feed(s) deleted");
if (onSuccess != null) {
onSuccess.run();
}
progressDialog.dismiss(); progressDialog.dismiss();
}, error -> { }, error -> {
Log.e(TAG, Log.getStackTraceString(error)); Log.e(TAG, Log.getStackTraceString(error));

View File

@ -333,8 +333,8 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
new RenameFeedDialog(getActivity(), feed).show(); new RenameFeedDialog(getActivity(), feed).show();
return true; return true;
} else if (itemId == R.id.remove_item) { } else if (itemId == R.id.remove_item) {
RemoveFeedDialog.show(getContext(), feed, () -> ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null);
((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null)); RemoveFeedDialog.show(getContext(), feed);
return true; return true;
} else if (itemId == R.id.action_search) { } else if (itemId == R.id.action_search) {
((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance(feed.getId(), feed.getTitle())); ((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance(feed.getId(), feed.getTitle()));

View File

@ -164,9 +164,8 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
new RenameFeedDialog(getActivity(), feed).show(); new RenameFeedDialog(getActivity(), feed).show();
return true; return true;
} else if (itemId == R.id.remove_item) { } else if (itemId == R.id.remove_item) {
RemoveFeedDialog.show(getContext(), feed, () -> {
((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null); ((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null);
}); RemoveFeedDialog.show(getContext(), feed);
return true; return true;
} }
return super.onContextItemSelected(item); return super.onContextItemSelected(item);

View File

@ -351,7 +351,7 @@ public class SubscriptionFragment extends Fragment
new RenameFeedDialog(getActivity(), feed).show(); new RenameFeedDialog(getActivity(), feed).show();
return true; return true;
} else if (itemId == R.id.remove_item) { } else if (itemId == R.id.remove_item) {
RemoveFeedDialog.show(getContext(), feed, null); RemoveFeedDialog.show(getContext(), feed);
return true; return true;
} else if (itemId == R.id.multi_select) { } else if (itemId == R.id.multi_select) {
speedDialView.setVisibility(View.VISIBLE); speedDialView.setVisibility(View.VISIBLE);

View File

@ -35,7 +35,7 @@ public class FeedMultiSelectActionHandler {
public void handleAction(int id) { public void handleAction(int id) {
if (id == R.id.remove_item) { if (id == R.id.remove_item) {
RemoveFeedDialog.show(activity, selectedItems, null); RemoveFeedDialog.show(activity, selectedItems);
} else if (id == R.id.keep_updated) { } else if (id == R.id.keep_updated) {
keepUpdatedPrefHandler(); keepUpdatedPrefHandler();
} else if (id == R.id.autodownload) { } else if (id == R.id.autodownload) {