mirror of
https://github.com/mediathekview/zapp.git
synced 2024-09-20 20:23:04 +02:00
Open MediathekDetailActivity from Notification
This commit is contained in:
parent
88cec01d52
commit
19a98ce32c
@ -4,7 +4,13 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import de.christinecoenen.code.zapp.app.MainActivity;
|
||||
import de.christinecoenen.code.zapp.app.ZappApplication;
|
||||
import de.christinecoenen.code.zapp.app.mediathek.model.PersistedMediathekShow;
|
||||
import de.christinecoenen.code.zapp.app.mediathek.repository.MediathekRepository;
|
||||
import de.christinecoenen.code.zapp.app.mediathek.ui.detail.MediathekDetailActivity;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.tonyodev.fetch2.FetchIntent.EXTRA_ACTION_TYPE;
|
||||
|
||||
@ -13,6 +19,15 @@ public class DownloadReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final int ACTION_NOTIFICATION_CLICKED = 42;
|
||||
|
||||
private static final String EXTRA_DOWNLOAD_ID = "EXTRA_DOWNLOAD_ID";
|
||||
|
||||
public static Intent getNotificationClickedIntent(String targetAction, int downloadId) {
|
||||
Intent intent = new Intent(targetAction);
|
||||
intent.putExtra(EXTRA_ACTION_TYPE, ACTION_NOTIFICATION_CLICKED);
|
||||
intent.putExtra(EXTRA_DOWNLOAD_ID, downloadId);
|
||||
return intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (context == null || intent == null) {
|
||||
@ -22,12 +37,25 @@ public class DownloadReceiver extends BroadcastReceiver {
|
||||
int actionType = intent.getIntExtra(EXTRA_ACTION_TYPE, ACTION_NOTIFICATION_CLICKED);
|
||||
|
||||
if (actionType == ACTION_NOTIFICATION_CLICKED) {
|
||||
// bring running zapp instance to front
|
||||
Intent zappIntent = new Intent(context, MainActivity.class);
|
||||
zappIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
zappIntent.setAction(Intent.ACTION_MAIN);
|
||||
zappIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
||||
context.startActivity(zappIntent);
|
||||
|
||||
ZappApplication application = (ZappApplication) context.getApplicationContext();
|
||||
MediathekRepository mediathekRepository = application.getMediathekRepository();
|
||||
int downloadId = intent.getIntExtra(EXTRA_DOWNLOAD_ID, 0);
|
||||
|
||||
//noinspection unused
|
||||
Disposable loadShowDisposable = mediathekRepository
|
||||
.getPersistedShowByDownloadId(downloadId)
|
||||
.firstElement()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(persistedMediathekShow -> onShowLoaded(context, persistedMediathekShow), Timber::e);
|
||||
}
|
||||
}
|
||||
|
||||
private void onShowLoaded(Context context, PersistedMediathekShow persistedMediathekShow) {
|
||||
// launch MediathekDetailActivity
|
||||
Intent detailIntent = MediathekDetailActivity.getStartIntent(context, persistedMediathekShow.getMediathekShow());
|
||||
detailIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
detailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
context.startActivity(detailIntent);
|
||||
}
|
||||
}
|
||||
|
@ -60,10 +60,6 @@ public class DownloadController implements FetchListener {
|
||||
}
|
||||
|
||||
public void startDownload(PersistedMediathekShow show, Quality quality) {
|
||||
long downloadId = show.getMediathekShow().getApiId().hashCode();
|
||||
show.setDownloadId(downloadId);
|
||||
mediathekRepository.updateShow(show);
|
||||
|
||||
String downloadUrl = show.getMediathekShow().getVideoUrl(quality);
|
||||
String filePath = downloadFileInfoManager.getDownloadFilePath(show.getMediathekShow(), quality);
|
||||
|
||||
@ -75,23 +71,18 @@ public class DownloadController implements FetchListener {
|
||||
throw new DownloadException("Constructing download request failed.", e);
|
||||
}
|
||||
|
||||
enqueueDownload(show, request);
|
||||
show.setDownloadId(request.getId());
|
||||
mediathekRepository.updateShow(show);
|
||||
|
||||
enqueueDownload(request);
|
||||
}
|
||||
|
||||
public void stopDownload(String showId) {
|
||||
fetch.getDownloadsByRequestIdentifier(showId.hashCode(), result -> {
|
||||
for (Download download : result) {
|
||||
fetch.cancel(download.getId());
|
||||
}
|
||||
});
|
||||
public void stopDownload(int downloadId) {
|
||||
fetch.cancel(downloadId);
|
||||
}
|
||||
|
||||
public void deleteDownload(String showId) {
|
||||
fetch.getDownloadsByRequestIdentifier(showId.hashCode(), result -> {
|
||||
for (Download download : result) {
|
||||
fetch.delete(download.getId());
|
||||
}
|
||||
});
|
||||
public void deleteDownload(int downloadId) {
|
||||
fetch.delete(downloadId);
|
||||
}
|
||||
|
||||
public Flowable<DownloadStatus> getDownloadStatus(String apiId) {
|
||||
@ -112,11 +103,10 @@ public class DownloadController implements FetchListener {
|
||||
});
|
||||
}
|
||||
|
||||
private void enqueueDownload(PersistedMediathekShow persistedShow, Request request) {
|
||||
private void enqueueDownload(Request request) {
|
||||
NetworkType networkType = settingsRepository.getDownloadOverWifiOnly() ?
|
||||
NetworkType.WIFI_ONLY : NetworkType.ALL;
|
||||
request.setNetworkType(networkType);
|
||||
request.setIdentifier(persistedShow.getDownloadId());
|
||||
|
||||
if (settingsRepository.getDownloadOverWifiOnly() && connectivityManager.isActiveNetworkMetered()) {
|
||||
throw new WrongNetworkConditionException("Download over metered networks prohibited.");
|
||||
@ -127,11 +117,11 @@ public class DownloadController implements FetchListener {
|
||||
|
||||
private void updateDownloadStatus(@NonNull Download download) {
|
||||
DownloadStatus downloadStatus = DownloadStatus.values()[download.getStatus().getValue()];
|
||||
mediathekRepository.updateDownloadStatus(download.getIdentifier(), downloadStatus);
|
||||
mediathekRepository.updateDownloadStatus(download.getId(), downloadStatus);
|
||||
}
|
||||
|
||||
private void updateDownloadProgress(@NonNull Download download, int progress) {
|
||||
mediathekRepository.updateDownloadProgress(download.getIdentifier(), progress);
|
||||
mediathekRepository.updateDownloadProgress(download.getId(), progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -148,7 +138,7 @@ public class DownloadController implements FetchListener {
|
||||
@Override
|
||||
public void onCompleted(@NonNull Download download) {
|
||||
updateDownloadStatus(download);
|
||||
mediathekRepository.updateDownloadedVideoPath(download.getIdentifier(), download.getFile());
|
||||
mediathekRepository.updateDownloadedVideoPath(download.getId(), download.getFile());
|
||||
downloadFileInfoManager.updateDownloadFileInMediaCollection(download);
|
||||
}
|
||||
|
||||
|
@ -274,7 +274,7 @@ abstract class ZappNotificationManager(context: Context, private val mediathekRe
|
||||
@SuppressLint("CheckResult")
|
||||
override fun postDownloadUpdate(download: Download): Boolean {
|
||||
mediathekRepository
|
||||
.getPersistedShow(download.identifier)
|
||||
.getPersistedShowByDownloadId(download.id)
|
||||
.firstElement()
|
||||
.subscribe { persistedShow -> postDownloadUpdate(download, persistedShow) }
|
||||
|
||||
@ -347,7 +347,7 @@ abstract class ZappNotificationManager(context: Context, private val mediathekRe
|
||||
downloadNotification.total = download.total
|
||||
downloadNotification.downloaded = download.downloaded
|
||||
downloadNotification.namespace = download.namespace
|
||||
downloadNotification.title = persistedShow.mediathekShow!!.title
|
||||
downloadNotification.title = persistedShow.mediathekShow.title
|
||||
downloadNotificationsMap[download.id] = downloadNotification
|
||||
|
||||
if (downloadNotificationExcludeSet.contains(downloadNotification.notificationId)
|
||||
@ -365,10 +365,9 @@ abstract class ZappNotificationManager(context: Context, private val mediathekRe
|
||||
|
||||
private fun getContentIntent(downloadNotification: DownloadNotification): PendingIntent {
|
||||
synchronized(downloadNotificationsMap) {
|
||||
val intent = Intent(notificationManagerAction)
|
||||
val action = DownloadReceiver.ACTION_NOTIFICATION_CLICKED
|
||||
intent.putExtra(EXTRA_ACTION_TYPE, action)
|
||||
return PendingIntent.getBroadcast(context, downloadNotification.notificationId + action, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
val intent = DownloadReceiver.getNotificationClickedIntent(notificationManagerAction, downloadNotification.notificationId)
|
||||
val requestCode = downloadNotification.notificationId + DownloadReceiver.ACTION_NOTIFICATION_CLICKED
|
||||
return PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ class PersistedMediathekShow {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id : Int = 0
|
||||
|
||||
var downloadId = 0L
|
||||
var downloadId = 0
|
||||
|
||||
var downloadedVideoPath: String? = null
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package de.christinecoenen.code.zapp.app.mediathek.repository;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@ -79,21 +77,21 @@ public class MediathekRepository {
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public void updateDownloadStatus(long downloadId, DownloadStatus downloadStatus) {
|
||||
public void updateDownloadStatus(int downloadId, DownloadStatus downloadStatus) {
|
||||
database.mediathekShowDao()
|
||||
.updateDownloadStatus(downloadId, downloadStatus)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public void updateDownloadProgress(long downloadId, int progress) {
|
||||
public void updateDownloadProgress(int downloadId, int progress) {
|
||||
database.mediathekShowDao()
|
||||
.updateDownloadProgress(downloadId, progress)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
public void updateDownloadedVideoPath(long downloadId, String videoPath) {
|
||||
public void updateDownloadedVideoPath(int downloadId, String videoPath) {
|
||||
database.mediathekShowDao()
|
||||
.updateDownloadedVideoPath(downloadId, videoPath)
|
||||
.subscribeOn(Schedulers.io())
|
||||
@ -104,11 +102,7 @@ public class MediathekRepository {
|
||||
return database.mediathekShowDao().getFromId(id).subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
public Flowable<PersistedMediathekShow> getPersistedShow(String apiId) {
|
||||
return database.mediathekShowDao().getFromApiId(apiId).subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
public Flowable<PersistedMediathekShow> getPersistedShow(long downloadId) {
|
||||
public Flowable<PersistedMediathekShow> getPersistedShowByDownloadId(int downloadId) {
|
||||
return database.mediathekShowDao().getFromDownloadId(downloadId).subscribeOn(Schedulers.io());
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,8 @@ import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import de.christinecoenen.code.zapp.R;
|
||||
import de.christinecoenen.code.zapp.app.ZappApplicationBase;
|
||||
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.DownloadController;
|
||||
@ -42,8 +44,8 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
||||
private static final String ARG_SHOW = "ARG_SHOW";
|
||||
|
||||
|
||||
private CompositeDisposable createDisposables = new CompositeDisposable();
|
||||
private CompositeDisposable createViewDisposables = new CompositeDisposable();
|
||||
private final CompositeDisposable createDisposables = new CompositeDisposable();
|
||||
private final CompositeDisposable createViewDisposables = new CompositeDisposable();
|
||||
private FragmentMediathekDetailBinding binding;
|
||||
private MediathekRepository mediathekRepository;
|
||||
private PersistedMediathekShow persistedMediathekShow;
|
||||
@ -85,7 +87,7 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
||||
MediathekShow show = (MediathekShow) getArguments().getSerializable(ARG_SHOW);
|
||||
|
||||
Disposable persistShowDisposable = mediathekRepository
|
||||
.persistOrUpdateShow(show)
|
||||
.persistOrUpdateShow(Objects.requireNonNull(show))
|
||||
.firstElement()
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::onShowLoaded, Timber::e);
|
||||
@ -127,7 +129,7 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
||||
|
||||
@Override
|
||||
public void onConfirmDeleteDialogOkClicked() {
|
||||
downloadController.deleteDownload(persistedMediathekShow.getMediathekShow().getApiId());
|
||||
downloadController.deleteDownload(persistedMediathekShow.getDownloadId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -193,7 +195,7 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
||||
case ADDED:
|
||||
case QUEUED:
|
||||
case DOWNLOADING:
|
||||
downloadController.stopDownload(persistedMediathekShow.getMediathekShow().getApiId());
|
||||
downloadController.stopDownload(persistedMediathekShow.getDownloadId());
|
||||
break;
|
||||
case COMPLETED:
|
||||
showConfirmDeleteDialog();
|
||||
|
Loading…
Reference in New Issue
Block a user