1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package de.danoeh.antennapod.dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import java.util.Collections;
import java.util.List;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
import de.danoeh.antennapod.model.feed.Feed;
import de.danoeh.antennapod.core.storage.DBWriter;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class RemoveFeedDialog {
private static final String TAG = "RemoveFeedDialog";
public static void show(Context context, Feed feed) {
List<Feed> feeds = Collections.singletonList(feed);
String message = getMessageId(context, feeds);
showDialog(context, feeds, message);
}
public static void show(Context context, List<Feed> feeds) {
String message = getMessageId(context, feeds);
showDialog(context, feeds, message);
}
private static void showDialog(Context context, List<Feed> feeds, String message) {
ConfirmationDialog dialog = new ConfirmationDialog(context, R.string.remove_feed_label, message) {
@Override
public void onConfirmButtonPressed(DialogInterface clickedDialog) {
clickedDialog.dismiss();
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setMessage(context.getString(R.string.feed_remover_msg));
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.show();
Completable.fromAction(() -> {
for (Feed feed : feeds) {
DBWriter.deleteFeed(context, feed.getId()).get();
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
() -> {
Log.d(TAG, "Feed(s) deleted");
progressDialog.dismiss();
}, error -> {
Log.e(TAG, Log.getStackTraceString(error));
progressDialog.dismiss();
});
}
};
dialog.createNewDialog().show();
}
private static String getMessageId(Context context, List<Feed> feeds) {
if (feeds.size() == 1) {
if (feeds.get(0).isLocalFeed()) {
return context.getString(R.string.feed_delete_confirmation_local_msg, feeds.get(0).getTitle());
} else {
return context.getString(R.string.feed_delete_confirmation_msg, feeds.get(0).getTitle());
}
} else {
return context.getString(R.string.feed_delete_confirmation_msg_batch);
}
}
}
|