Merge pull request #5532 from ByteHamster/delete-use-action
Fix crash when deleting feed
This commit is contained in:
commit
58293350c7
|
@ -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));
|
||||||
|
|
|
@ -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()));
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in New Issue