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.Context;
|
||||||
import android.content.Intent;
|
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;
|
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;
|
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
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (context == null || intent == null) {
|
if (context == null || intent == null) {
|
||||||
@ -22,12 +37,25 @@ public class DownloadReceiver extends BroadcastReceiver {
|
|||||||
int actionType = intent.getIntExtra(EXTRA_ACTION_TYPE, ACTION_NOTIFICATION_CLICKED);
|
int actionType = intent.getIntExtra(EXTRA_ACTION_TYPE, ACTION_NOTIFICATION_CLICKED);
|
||||||
|
|
||||||
if (actionType == ACTION_NOTIFICATION_CLICKED) {
|
if (actionType == ACTION_NOTIFICATION_CLICKED) {
|
||||||
// bring running zapp instance to front
|
|
||||||
Intent zappIntent = new Intent(context, MainActivity.class);
|
ZappApplication application = (ZappApplication) context.getApplicationContext();
|
||||||
zappIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
MediathekRepository mediathekRepository = application.getMediathekRepository();
|
||||||
zappIntent.setAction(Intent.ACTION_MAIN);
|
int downloadId = intent.getIntExtra(EXTRA_DOWNLOAD_ID, 0);
|
||||||
zappIntent.addCategory(Intent.CATEGORY_LAUNCHER);
|
|
||||||
context.startActivity(zappIntent);
|
//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) {
|
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 downloadUrl = show.getMediathekShow().getVideoUrl(quality);
|
||||||
String filePath = downloadFileInfoManager.getDownloadFilePath(show.getMediathekShow(), 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);
|
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) {
|
public void stopDownload(int downloadId) {
|
||||||
fetch.getDownloadsByRequestIdentifier(showId.hashCode(), result -> {
|
fetch.cancel(downloadId);
|
||||||
for (Download download : result) {
|
|
||||||
fetch.cancel(download.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteDownload(String showId) {
|
public void deleteDownload(int downloadId) {
|
||||||
fetch.getDownloadsByRequestIdentifier(showId.hashCode(), result -> {
|
fetch.delete(downloadId);
|
||||||
for (Download download : result) {
|
|
||||||
fetch.delete(download.getId());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flowable<DownloadStatus> getDownloadStatus(String apiId) {
|
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 networkType = settingsRepository.getDownloadOverWifiOnly() ?
|
||||||
NetworkType.WIFI_ONLY : NetworkType.ALL;
|
NetworkType.WIFI_ONLY : NetworkType.ALL;
|
||||||
request.setNetworkType(networkType);
|
request.setNetworkType(networkType);
|
||||||
request.setIdentifier(persistedShow.getDownloadId());
|
|
||||||
|
|
||||||
if (settingsRepository.getDownloadOverWifiOnly() && connectivityManager.isActiveNetworkMetered()) {
|
if (settingsRepository.getDownloadOverWifiOnly() && connectivityManager.isActiveNetworkMetered()) {
|
||||||
throw new WrongNetworkConditionException("Download over metered networks prohibited.");
|
throw new WrongNetworkConditionException("Download over metered networks prohibited.");
|
||||||
@ -127,11 +117,11 @@ public class DownloadController implements FetchListener {
|
|||||||
|
|
||||||
private void updateDownloadStatus(@NonNull Download download) {
|
private void updateDownloadStatus(@NonNull Download download) {
|
||||||
DownloadStatus downloadStatus = DownloadStatus.values()[download.getStatus().getValue()];
|
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) {
|
private void updateDownloadProgress(@NonNull Download download, int progress) {
|
||||||
mediathekRepository.updateDownloadProgress(download.getIdentifier(), progress);
|
mediathekRepository.updateDownloadProgress(download.getId(), progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -148,7 +138,7 @@ public class DownloadController implements FetchListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onCompleted(@NonNull Download download) {
|
public void onCompleted(@NonNull Download download) {
|
||||||
updateDownloadStatus(download);
|
updateDownloadStatus(download);
|
||||||
mediathekRepository.updateDownloadedVideoPath(download.getIdentifier(), download.getFile());
|
mediathekRepository.updateDownloadedVideoPath(download.getId(), download.getFile());
|
||||||
downloadFileInfoManager.updateDownloadFileInMediaCollection(download);
|
downloadFileInfoManager.updateDownloadFileInMediaCollection(download);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ abstract class ZappNotificationManager(context: Context, private val mediathekRe
|
|||||||
@SuppressLint("CheckResult")
|
@SuppressLint("CheckResult")
|
||||||
override fun postDownloadUpdate(download: Download): Boolean {
|
override fun postDownloadUpdate(download: Download): Boolean {
|
||||||
mediathekRepository
|
mediathekRepository
|
||||||
.getPersistedShow(download.identifier)
|
.getPersistedShowByDownloadId(download.id)
|
||||||
.firstElement()
|
.firstElement()
|
||||||
.subscribe { persistedShow -> postDownloadUpdate(download, persistedShow) }
|
.subscribe { persistedShow -> postDownloadUpdate(download, persistedShow) }
|
||||||
|
|
||||||
@ -347,7 +347,7 @@ abstract class ZappNotificationManager(context: Context, private val mediathekRe
|
|||||||
downloadNotification.total = download.total
|
downloadNotification.total = download.total
|
||||||
downloadNotification.downloaded = download.downloaded
|
downloadNotification.downloaded = download.downloaded
|
||||||
downloadNotification.namespace = download.namespace
|
downloadNotification.namespace = download.namespace
|
||||||
downloadNotification.title = persistedShow.mediathekShow!!.title
|
downloadNotification.title = persistedShow.mediathekShow.title
|
||||||
downloadNotificationsMap[download.id] = downloadNotification
|
downloadNotificationsMap[download.id] = downloadNotification
|
||||||
|
|
||||||
if (downloadNotificationExcludeSet.contains(downloadNotification.notificationId)
|
if (downloadNotificationExcludeSet.contains(downloadNotification.notificationId)
|
||||||
@ -365,10 +365,9 @@ abstract class ZappNotificationManager(context: Context, private val mediathekRe
|
|||||||
|
|
||||||
private fun getContentIntent(downloadNotification: DownloadNotification): PendingIntent {
|
private fun getContentIntent(downloadNotification: DownloadNotification): PendingIntent {
|
||||||
synchronized(downloadNotificationsMap) {
|
synchronized(downloadNotificationsMap) {
|
||||||
val intent = Intent(notificationManagerAction)
|
val intent = DownloadReceiver.getNotificationClickedIntent(notificationManagerAction, downloadNotification.notificationId)
|
||||||
val action = DownloadReceiver.ACTION_NOTIFICATION_CLICKED
|
val requestCode = downloadNotification.notificationId + DownloadReceiver.ACTION_NOTIFICATION_CLICKED
|
||||||
intent.putExtra(EXTRA_ACTION_TYPE, action)
|
return PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||||
return PendingIntent.getBroadcast(context, downloadNotification.notificationId + action, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ class PersistedMediathekShow {
|
|||||||
@PrimaryKey(autoGenerate = true)
|
@PrimaryKey(autoGenerate = true)
|
||||||
var id : Int = 0
|
var id : Int = 0
|
||||||
|
|
||||||
var downloadId = 0L
|
var downloadId = 0
|
||||||
|
|
||||||
var downloadedVideoPath: String? = null
|
var downloadedVideoPath: String? = null
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package de.christinecoenen.code.zapp.app.mediathek.repository;
|
package de.christinecoenen.code.zapp.app.mediathek.repository;
|
||||||
|
|
||||||
import org.reactivestreams.Publisher;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -79,21 +77,21 @@ public class MediathekRepository {
|
|||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDownloadStatus(long downloadId, DownloadStatus downloadStatus) {
|
public void updateDownloadStatus(int downloadId, DownloadStatus downloadStatus) {
|
||||||
database.mediathekShowDao()
|
database.mediathekShowDao()
|
||||||
.updateDownloadStatus(downloadId, downloadStatus)
|
.updateDownloadStatus(downloadId, downloadStatus)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDownloadProgress(long downloadId, int progress) {
|
public void updateDownloadProgress(int downloadId, int progress) {
|
||||||
database.mediathekShowDao()
|
database.mediathekShowDao()
|
||||||
.updateDownloadProgress(downloadId, progress)
|
.updateDownloadProgress(downloadId, progress)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.subscribe();
|
.subscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDownloadedVideoPath(long downloadId, String videoPath) {
|
public void updateDownloadedVideoPath(int downloadId, String videoPath) {
|
||||||
database.mediathekShowDao()
|
database.mediathekShowDao()
|
||||||
.updateDownloadedVideoPath(downloadId, videoPath)
|
.updateDownloadedVideoPath(downloadId, videoPath)
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
@ -104,11 +102,7 @@ public class MediathekRepository {
|
|||||||
return database.mediathekShowDao().getFromId(id).subscribeOn(Schedulers.io());
|
return database.mediathekShowDao().getFromId(id).subscribeOn(Schedulers.io());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Flowable<PersistedMediathekShow> getPersistedShow(String apiId) {
|
public Flowable<PersistedMediathekShow> getPersistedShowByDownloadId(int downloadId) {
|
||||||
return database.mediathekShowDao().getFromApiId(apiId).subscribeOn(Schedulers.io());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Flowable<PersistedMediathekShow> getPersistedShow(long downloadId) {
|
|
||||||
return database.mediathekShowDao().getFromDownloadId(downloadId).subscribeOn(Schedulers.io());
|
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 com.google.android.material.snackbar.Snackbar;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import de.christinecoenen.code.zapp.R;
|
import de.christinecoenen.code.zapp.R;
|
||||||
import de.christinecoenen.code.zapp.app.ZappApplicationBase;
|
import de.christinecoenen.code.zapp.app.ZappApplicationBase;
|
||||||
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.DownloadController;
|
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 static final String ARG_SHOW = "ARG_SHOW";
|
||||||
|
|
||||||
|
|
||||||
private CompositeDisposable createDisposables = new CompositeDisposable();
|
private final CompositeDisposable createDisposables = new CompositeDisposable();
|
||||||
private CompositeDisposable createViewDisposables = new CompositeDisposable();
|
private final CompositeDisposable createViewDisposables = new CompositeDisposable();
|
||||||
private FragmentMediathekDetailBinding binding;
|
private FragmentMediathekDetailBinding binding;
|
||||||
private MediathekRepository mediathekRepository;
|
private MediathekRepository mediathekRepository;
|
||||||
private PersistedMediathekShow persistedMediathekShow;
|
private PersistedMediathekShow persistedMediathekShow;
|
||||||
@ -85,7 +87,7 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
|||||||
MediathekShow show = (MediathekShow) getArguments().getSerializable(ARG_SHOW);
|
MediathekShow show = (MediathekShow) getArguments().getSerializable(ARG_SHOW);
|
||||||
|
|
||||||
Disposable persistShowDisposable = mediathekRepository
|
Disposable persistShowDisposable = mediathekRepository
|
||||||
.persistOrUpdateShow(show)
|
.persistOrUpdateShow(Objects.requireNonNull(show))
|
||||||
.firstElement()
|
.firstElement()
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(this::onShowLoaded, Timber::e);
|
.subscribe(this::onShowLoaded, Timber::e);
|
||||||
@ -127,7 +129,7 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfirmDeleteDialogOkClicked() {
|
public void onConfirmDeleteDialogOkClicked() {
|
||||||
downloadController.deleteDownload(persistedMediathekShow.getMediathekShow().getApiId());
|
downloadController.deleteDownload(persistedMediathekShow.getDownloadId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -193,7 +195,7 @@ public class MediathekDetailFragment extends Fragment implements ConfirmFileDele
|
|||||||
case ADDED:
|
case ADDED:
|
||||||
case QUEUED:
|
case QUEUED:
|
||||||
case DOWNLOADING:
|
case DOWNLOADING:
|
||||||
downloadController.stopDownload(persistedMediathekShow.getMediathekShow().getApiId());
|
downloadController.stopDownload(persistedMediathekShow.getDownloadId());
|
||||||
break;
|
break;
|
||||||
case COMPLETED:
|
case COMPLETED:
|
||||||
showConfirmDeleteDialog();
|
showConfirmDeleteDialog();
|
||||||
|
Loading…
Reference in New Issue
Block a user