-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5737 from ByteHamster/show-error-in-dialog
Show feed error in dialog instead of opening download log screen
- Loading branch information
Showing
3 changed files
with
107 additions
and
73 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
app/src/main/java/de/danoeh/antennapod/dialog/DownloadLogDetailsDialog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package de.danoeh.antennapod.dialog; | ||
|
||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.widget.TextView; | ||
import androidx.annotation.NonNull; | ||
import androidx.appcompat.app.AlertDialog; | ||
import de.danoeh.antennapod.R; | ||
import de.danoeh.antennapod.core.service.download.DownloadStatus; | ||
import de.danoeh.antennapod.core.storage.DBReader; | ||
import de.danoeh.antennapod.event.MessageEvent; | ||
import de.danoeh.antennapod.model.feed.Feed; | ||
import de.danoeh.antennapod.model.feed.FeedMedia; | ||
import org.greenrobot.eventbus.EventBus; | ||
|
||
public class DownloadLogDetailsDialog extends AlertDialog.Builder { | ||
|
||
public DownloadLogDetailsDialog(@NonNull Context context, DownloadStatus status) { | ||
super(context); | ||
|
||
String url = "unknown"; | ||
String message = context.getString(R.string.download_successful); | ||
if (status.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) { | ||
FeedMedia media = DBReader.getFeedMedia(status.getFeedfileId()); | ||
if (media != null) { | ||
url = media.getDownload_url(); | ||
} | ||
} else if (status.getFeedfileType() == Feed.FEEDFILETYPE_FEED) { | ||
Feed feed = DBReader.getFeed(status.getFeedfileId()); | ||
if (feed != null) { | ||
url = feed.getDownload_url(); | ||
} | ||
} | ||
|
||
if (!status.isSuccessful()) { | ||
message = status.getReasonDetailed(); | ||
} | ||
|
||
String messageFull = context.getString(R.string.download_error_details_message, message, url); | ||
setTitle(R.string.download_error_details); | ||
setMessage(messageFull); | ||
setPositiveButton(android.R.string.ok, null); | ||
setNeutralButton(R.string.copy_to_clipboard, (dialog, which) -> { | ||
ClipboardManager clipboard = (ClipboardManager) getContext() | ||
.getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData clip = ClipData.newPlainText(context.getString(R.string.download_error_details), messageFull); | ||
clipboard.setPrimaryClip(clip); | ||
EventBus.getDefault().post(new MessageEvent(context.getString(R.string.copied_to_clipboard))); | ||
}); | ||
} | ||
|
||
@Override | ||
public AlertDialog show() { | ||
AlertDialog dialog = super.show(); | ||
((TextView) dialog.findViewById(android.R.id.message)).setTextIsSelectable(true); | ||
return dialog; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters