Add option to edit feed URL (#6185)
This commit is contained in:
parent
807e09ecdd
commit
d62ea313d7
|
@ -0,0 +1,88 @@
|
|||
package de.danoeh.antennapod.dialog;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.CountDownTimer;
|
||||
import android.view.LayoutInflater;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.databinding.EditTextDialogBinding;
|
||||
import de.danoeh.antennapod.model.feed.Feed;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public abstract class EditUrlSettingsDialog {
|
||||
public static final String TAG = "EditUrlSettingsDialog";
|
||||
private final WeakReference<Activity> activityRef;
|
||||
private final Feed feed;
|
||||
|
||||
public EditUrlSettingsDialog(Activity activity, Feed feed) {
|
||||
this.activityRef = new WeakReference<>(activity);
|
||||
this.feed = feed;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
Activity activity = activityRef.get();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EditTextDialogBinding binding = EditTextDialogBinding.inflate(LayoutInflater.from(activity));
|
||||
|
||||
binding.urlEditText.setText(feed.getDownload_url());
|
||||
|
||||
new MaterialAlertDialogBuilder(activity)
|
||||
.setView(binding.getRoot())
|
||||
.setTitle(R.string.edit_url_menu)
|
||||
.setPositiveButton(android.R.string.ok, (d, input) ->
|
||||
showConfirmAlertDialog(String.valueOf(binding.urlEditText.getText())))
|
||||
.setNegativeButton(R.string.cancel_label, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void onConfirmed(String original, String updated) {
|
||||
try {
|
||||
DBWriter.updateFeedDownloadURL(original, updated).get();
|
||||
feed.setDownload_url(updated);
|
||||
DBTasks.forceRefreshFeed(activityRef.get(), feed, false);
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void showConfirmAlertDialog(String url) {
|
||||
Activity activity = activityRef.get();
|
||||
|
||||
AlertDialog alertDialog = new MaterialAlertDialogBuilder(activity)
|
||||
.setTitle(R.string.edit_url_menu)
|
||||
.setMessage(R.string.edit_url_confirmation_msg)
|
||||
.setPositiveButton(android.R.string.ok, (d, input) -> {
|
||||
onConfirmed(feed.getDownload_url(), url);
|
||||
setUrl(url);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel_label, null)
|
||||
.show();
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
|
||||
|
||||
new CountDownTimer(15000, 1000) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(
|
||||
String.format(Locale.getDefault(), "%s (%d)",
|
||||
activity.getString(android.R.string.ok), millisUntilFinished / 1000 + 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(true);
|
||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(android.R.string.ok);
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
protected abstract void setUrl(String url);
|
||||
}
|
|
@ -40,6 +40,7 @@ import de.danoeh.antennapod.core.storage.DBReader;
|
|||
import de.danoeh.antennapod.core.storage.DBTasks;
|
||||
import de.danoeh.antennapod.core.util.IntentUtils;
|
||||
import de.danoeh.antennapod.core.util.syndication.HtmlToPlainText;
|
||||
import de.danoeh.antennapod.dialog.EditUrlSettingsDialog;
|
||||
import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
|
||||
import de.danoeh.antennapod.model.feed.Feed;
|
||||
import de.danoeh.antennapod.model.feed.FeedFunding;
|
||||
|
@ -277,6 +278,7 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
|
|||
toolbar.getMenu().findItem(R.id.share_item).setVisible(feed != null && !feed.isLocalFeed());
|
||||
toolbar.getMenu().findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null
|
||||
&& IntentUtils.isCallable(getContext(), new Intent(Intent.ACTION_VIEW, Uri.parse(feed.getLink()))));
|
||||
toolbar.getMenu().findItem(R.id.edit_feed_url_item).setVisible(feed != null && !feed.isLocalFeed());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -303,6 +305,19 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
|
|||
return true;
|
||||
}
|
||||
|
||||
if (item.getItemId() == R.id.edit_feed_url_item) {
|
||||
new EditUrlSettingsDialog(getActivity(), feed) {
|
||||
@Override
|
||||
protected void setUrl(String url) {
|
||||
feed.setDownload_url(url);
|
||||
txtvUrl.setText(feed.getDownload_url() + " {fa-paperclip}");
|
||||
Iconify.addIcons(txtvUrl);
|
||||
}
|
||||
}.show();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,4 +18,7 @@
|
|||
custom:showAsAction="collapseActionView"
|
||||
android:title="@string/reconnect_local_folder"
|
||||
android:visible="false" />
|
||||
<item
|
||||
android:id="@+id/edit_feed_url_item"
|
||||
android:title="@string/edit_url_menu" />
|
||||
</menu>
|
|
@ -706,6 +706,8 @@
|
|||
<string name="statistics_episodes_started_total">Episodes started/total:</string>
|
||||
<string name="statistics_view_all">View for all podcasts »</string>
|
||||
<string name="wait_icon" translatable="false">{fa-spinner}</string>
|
||||
<string name="edit_url_menu">Edit feed URL</string>
|
||||
<string name="edit_url_confirmation_msg">Changing the RSS address can easily break the playback state and episode listings of the podcast. We do NOT recommend changing it and will NOT provide support if anything goes wrong. This cannot be undone. The broken subscription CANNOT be repaired by simply changing the address back. We suggest creating a backup before continuing.</string>
|
||||
|
||||
<!-- AntennaPodSP -->
|
||||
<string name="sp_apps_importing_feeds_msg">Importing subscriptions from single-purpose apps…</string>
|
||||
|
|
Loading…
Reference in New Issue