Remove TvApp.getApplication usages in util package
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.jellyfin.androidtv.data.eventhandling;
|
||||
|
||||
import static org.koin.java.KoinJavaComponent.get;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -16,6 +18,7 @@ import org.jellyfin.androidtv.ui.playback.MediaManager;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackController;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackLauncher;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackOverlayActivity;
|
||||
import org.jellyfin.androidtv.util.MediaUtils;
|
||||
import org.jellyfin.androidtv.util.Utils;
|
||||
import org.jellyfin.androidtv.util.apiclient.PlaybackHelper;
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
|
||||
@@ -84,7 +84,7 @@ val appModule = module {
|
||||
single<ServerRepository> { ServerRepositoryImpl(get(), get(), get(), get()) }
|
||||
|
||||
viewModel { LoginViewModel(get(), get(), get()) }
|
||||
viewModel { NextUpViewModel(get(), get(), get()) }
|
||||
viewModel { NextUpViewModel(get(), get(), get(), get()) }
|
||||
|
||||
single { BackgroundService(get(), get(), get()) }
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ class LeanbackChannelWorker(
|
||||
|
||||
// Update logo
|
||||
ResourcesCompat.getDrawable(context.resources, R.drawable.app_icon, null)?.let {
|
||||
ChannelLogoUtils.storeChannelLogo(context, ContentUris.parseId(uri), it.toBitmap(80.dp, 80.dp))
|
||||
ChannelLogoUtils.storeChannelLogo(context, ContentUris.parseId(uri), it.toBitmap(80.dp(context), 80.dp(context)))
|
||||
}
|
||||
|
||||
return uri
|
||||
|
||||
@@ -64,6 +64,7 @@ import org.jellyfin.androidtv.ui.shared.BaseActivity;
|
||||
import org.jellyfin.androidtv.ui.shared.IMessageListener;
|
||||
import org.jellyfin.androidtv.util.ImageUtils;
|
||||
import org.jellyfin.androidtv.util.KeyProcessor;
|
||||
import org.jellyfin.androidtv.util.MediaUtils;
|
||||
import org.jellyfin.androidtv.util.TimeUtils;
|
||||
import org.jellyfin.androidtv.util.Utils;
|
||||
import org.jellyfin.androidtv.util.apiclient.BaseItemUtils;
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.jellyfin.androidtv.ui.playback.PlaybackLauncher;
|
||||
import org.jellyfin.androidtv.util.ImageUtils;
|
||||
import org.jellyfin.androidtv.util.InfoLayoutHelper;
|
||||
import org.jellyfin.androidtv.util.MathUtils;
|
||||
import org.jellyfin.androidtv.util.MediaUtils;
|
||||
import org.jellyfin.androidtv.util.Utils;
|
||||
import org.jellyfin.androidtv.util.apiclient.BaseItemUtils;
|
||||
import org.jellyfin.androidtv.util.apiclient.PlaybackHelper;
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jellyfin.androidtv.ui.livetv.LiveTvGuideActivity;
|
||||
import org.jellyfin.androidtv.ui.playback.MediaManager;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackLauncher;
|
||||
import org.jellyfin.androidtv.util.KeyProcessor;
|
||||
import org.jellyfin.androidtv.util.MediaUtils;
|
||||
import org.jellyfin.androidtv.util.Utils;
|
||||
import org.jellyfin.androidtv.util.apiclient.PlaybackHelper;
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
|
||||
@@ -169,11 +169,13 @@ public class ExternalPlayerActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
private void startReportLoop() {
|
||||
ReportingHelper.reportProgress(mItemsToPlay.get(mCurrentNdx), mCurrentStreamInfo, null, false);
|
||||
// FIXME: Don't use the getApplication method..
|
||||
PlaybackController playbackController = TvApp.getApplication().getPlaybackController();
|
||||
ReportingHelper.reportProgress(playbackController, mItemsToPlay.get(mCurrentNdx), mCurrentStreamInfo, null, false);
|
||||
mReportLoop = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReportingHelper.reportProgress(mItemsToPlay.get(mCurrentNdx), mCurrentStreamInfo, mPosition, false);
|
||||
ReportingHelper.reportProgress(playbackController, mItemsToPlay.get(mCurrentNdx), mCurrentStreamInfo, mPosition, false);
|
||||
mHandler.postDelayed(this, 15000);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -182,7 +182,10 @@ public class MediaManager {
|
||||
|
||||
//Report progress to server every 5 secs
|
||||
if (System.currentTimeMillis() > lastProgressReport + 5000) {
|
||||
ReportingHelper.reportProgress(mCurrentAudioItem, mCurrentAudioStreamInfo, mCurrentAudioPosition*10000, isPaused());
|
||||
|
||||
// FIXME: Don't use the getApplication method..
|
||||
PlaybackController playbackController = TvApp.getApplication().getPlaybackController();
|
||||
ReportingHelper.reportProgress(playbackController, mCurrentAudioItem, mCurrentAudioStreamInfo, mCurrentAudioPosition*10000, isPaused());
|
||||
lastProgressReport = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
@@ -971,14 +971,14 @@ public class PlaybackController {
|
||||
}
|
||||
|
||||
private void startReportLoop() {
|
||||
ReportingHelper.reportProgress(getCurrentlyPlayingItem(), getCurrentStreamInfo(), mVideoManager.getCurrentPosition() * 10000, false);
|
||||
ReportingHelper.reportProgress(this, getCurrentlyPlayingItem(), getCurrentStreamInfo(), mVideoManager.getCurrentPosition() * 10000, false);
|
||||
mReportLoop = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (mPlaybackState == PlaybackState.PLAYING) {
|
||||
long currentTime = isLiveTv ? getTimeShiftedProgress() : mVideoManager.getCurrentPosition();
|
||||
|
||||
ReportingHelper.reportProgress(getCurrentlyPlayingItem(), getCurrentStreamInfo(), currentTime * 10000, false);
|
||||
ReportingHelper.reportProgress(PlaybackController.this, getCurrentlyPlayingItem(), getCurrentStreamInfo(), currentTime * 10000, false);
|
||||
}
|
||||
if (mPlaybackState != PlaybackState.UNDEFINED && mPlaybackState != PlaybackState.IDLE) {
|
||||
mHandler.postDelayed(this, PROGRESS_REPORTING_INTERVAL);
|
||||
@@ -989,7 +989,7 @@ public class PlaybackController {
|
||||
}
|
||||
|
||||
private void startPauseReportLoop() {
|
||||
ReportingHelper.reportProgress(getCurrentlyPlayingItem(), getCurrentStreamInfo(), mVideoManager.getCurrentPosition() * 10000, false);
|
||||
ReportingHelper.reportProgress(this, getCurrentlyPlayingItem(), getCurrentStreamInfo(), mVideoManager.getCurrentPosition() * 10000, false);
|
||||
mReportLoop = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -1010,7 +1010,7 @@ public class PlaybackController {
|
||||
mFragment.setSecondaryTime(getRealTimeProgress());
|
||||
}
|
||||
|
||||
ReportingHelper.reportProgress(currentItem, getCurrentStreamInfo(), currentTime * 10000, true);
|
||||
ReportingHelper.reportProgress(PlaybackController.this, currentItem, getCurrentStreamInfo(), currentTime * 10000, true);
|
||||
mHandler.postDelayed(this, PROGRESS_REPORTING_PAUSE_INTERVAL);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.bumptech.glide.Glide
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.jellyfin.androidtv.auth.SessionRepository
|
||||
import org.jellyfin.androidtv.preference.UserPreferences
|
||||
import org.jellyfin.androidtv.preference.constant.NextUpBehavior
|
||||
import org.jellyfin.androidtv.util.apiclient.getDisplayName
|
||||
@@ -20,7 +21,8 @@ import org.jellyfin.apiclient.model.dto.ImageOptions
|
||||
class NextUpViewModel(
|
||||
private val context: Context,
|
||||
private val apiClient: ApiClient,
|
||||
private val userPreferences: UserPreferences
|
||||
private val userPreferences: UserPreferences,
|
||||
private val sessionRepository: SessionRepository,
|
||||
) : ViewModel() {
|
||||
private val _item = MutableLiveData<NextUpItemData?>()
|
||||
val item: LiveData<NextUpItemData?> = _item
|
||||
@@ -59,7 +61,8 @@ class NextUpViewModel(
|
||||
}
|
||||
|
||||
private suspend fun loadItemData(id: String) = withContext(Dispatchers.IO) {
|
||||
val item = apiClient.getItem(id) ?: return@withContext null
|
||||
val userId = sessionRepository.currentSession.value?.userId ?: return@withContext null
|
||||
val item = apiClient.getItem(id, userId) ?: return@withContext null
|
||||
|
||||
val thumbnail = when (userPreferences[UserPreferences.nextUpBehavior]) {
|
||||
NextUpBehavior.EXTENDED -> apiClient.GetImageUrl(item, ImageOptions())
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.widget.PopupMenu;
|
||||
|
||||
import org.jellyfin.androidtv.R;
|
||||
import org.jellyfin.androidtv.TvApp;
|
||||
import org.jellyfin.androidtv.auth.SessionRepository;
|
||||
import org.jellyfin.androidtv.constant.CustomMessage;
|
||||
import org.jellyfin.androidtv.data.model.DataRefreshService;
|
||||
import org.jellyfin.androidtv.data.querying.StdItemQuery;
|
||||
@@ -33,6 +34,7 @@ import org.jellyfin.apiclient.model.querying.ItemsResult;
|
||||
import org.koin.java.KoinJavaComponent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
@@ -498,8 +500,9 @@ public class KeyProcessor {
|
||||
}
|
||||
|
||||
private static void toggleLikes(Boolean likes) {
|
||||
UUID userId = KoinJavaComponent.<SessionRepository>get(SessionRepository.class).getCurrentSession().getValue().getUserId();
|
||||
if (likes == null) {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).ClearUserItemRatingAsync(mCurrentItemId, TvApp.getApplication().getCurrentUser().getId(), new Response<UserItemDataDto>() {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).ClearUserItemRatingAsync(mCurrentItemId, userId.toString(), new Response<UserItemDataDto>() {
|
||||
@Override
|
||||
public void onResponse(UserItemDataDto response) {
|
||||
if (mCurrentActivity instanceof BaseActivity)
|
||||
@@ -514,7 +517,7 @@ public class KeyProcessor {
|
||||
});
|
||||
|
||||
} else {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).UpdateUserItemRatingAsync(mCurrentItemId, TvApp.getApplication().getCurrentUser().getId(), likes, new Response<UserItemDataDto>() {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).UpdateUserItemRatingAsync(mCurrentItemId, userId.toString(), likes, new Response<UserItemDataDto>() {
|
||||
@Override
|
||||
public void onResponse(UserItemDataDto response) {
|
||||
if (mCurrentActivity instanceof BaseActivity)
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
package org.jellyfin.androidtv.util;
|
||||
|
||||
import static org.koin.java.KoinJavaComponent.get;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.media.MediaCodecInfo;
|
||||
import android.media.MediaCodecList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.jellyfin.androidtv.preference.UserPreferences;
|
||||
import org.jellyfin.androidtv.preference.constant.PreferredVideoPlayer;
|
||||
import org.jellyfin.androidtv.ui.playback.ExternalPlayerActivity;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackOverlayActivity;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemType;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MediaUtils {
|
||||
@@ -39,4 +50,26 @@ public class MediaUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static boolean useExternalPlayer(BaseItemType itemType) {
|
||||
UserPreferences userPreferences = get(UserPreferences.class);
|
||||
switch (itemType) {
|
||||
case Movie:
|
||||
case Episode:
|
||||
case Video:
|
||||
case Series:
|
||||
case Recording:
|
||||
return userPreferences.get(UserPreferences.Companion.getVideoPlayer()) == PreferredVideoPlayer.EXTERNAL;
|
||||
case TvChannel:
|
||||
case Program:
|
||||
return userPreferences.get(UserPreferences.Companion.getLiveTvVideoPlayer()) == PreferredVideoPlayer.EXTERNAL;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Class<? extends Activity> getPlaybackActivityClass(BaseItemType itemType) {
|
||||
return useExternalPlayer(itemType) ? ExternalPlayerActivity.class : PlaybackOverlayActivity.class;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package org.jellyfin.androidtv.util
|
||||
|
||||
import org.jellyfin.androidtv.TvApp
|
||||
import android.content.Context
|
||||
|
||||
/**
|
||||
* Current (pixel) value as display pixels
|
||||
*/
|
||||
val Int.dp: Int
|
||||
get() = Utils.convertDpToPixel(TvApp.getApplication()!!, this)
|
||||
fun Int.dp(context: Context): Int = Utils.convertDpToPixel(context, this)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.jellyfin.androidtv.util;
|
||||
|
||||
import static org.koin.java.KoinJavaComponent.inject;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -12,14 +14,12 @@ import org.jellyfin.androidtv.ui.playback.MediaManager;
|
||||
import kotlin.Lazy;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static org.koin.java.KoinJavaComponent.inject;
|
||||
|
||||
public class RemoteControlReceiver extends BroadcastReceiver {
|
||||
private Lazy<MediaManager> mediaManager = inject(MediaManager.class);
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
//TvApp.getApplication().getLogger().Debug("****** In remote receiver. ");
|
||||
//Timber.d("****** In remote receiver. ");
|
||||
if ((TvApp.getApplication().getCurrentActivity() == null || !(TvApp.getApplication().getCurrentActivity() instanceof AudioNowPlayingActivity )) && mediaManager.getValue().isPlayingAudio()) {
|
||||
//Respond to media button presses
|
||||
if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
|
||||
|
||||
@@ -130,6 +130,7 @@ public class Utils {
|
||||
}
|
||||
|
||||
public static boolean downMixAudio() {
|
||||
// FIXME: Require context
|
||||
AudioManager am = (AudioManager) TvApp.getApplication().getSystemService(Context.AUDIO_SERVICE);
|
||||
if (am.isBluetoothA2dpOn()) {
|
||||
Timber.i("Downmixing audio due to wired headset");
|
||||
|
||||
@@ -1,36 +1,14 @@
|
||||
package org.jellyfin.androidtv.util.apiclient
|
||||
|
||||
import org.jellyfin.androidtv.TvApp
|
||||
import org.jellyfin.apiclient.interaction.ApiClient
|
||||
import org.jellyfin.apiclient.interaction.EmptyResponse
|
||||
import org.jellyfin.apiclient.interaction.Response
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto
|
||||
import org.jellyfin.apiclient.model.dto.UserDto
|
||||
import org.jellyfin.apiclient.model.querying.ItemsResult
|
||||
import org.jellyfin.apiclient.model.querying.NextUpQuery
|
||||
import java.util.*
|
||||
import kotlin.coroutines.resume
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
/**
|
||||
* Coroutine capable version of the "getNextUpEpisodes" function
|
||||
*/
|
||||
suspend fun ApiClient.getNextUpEpisodes(query: NextUpQuery): ItemsResult? = suspendCoroutine { continuation ->
|
||||
GetNextUpEpisodesAsync(query, object : Response<ItemsResult>() {
|
||||
override fun onResponse(response: ItemsResult?) = continuation.resume(response!!)
|
||||
override fun onError(exception: Exception?) = continuation.resume(null)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Coroutine capable version of the "getPublicUsers" function
|
||||
*/
|
||||
suspend fun ApiClient.getPublicUsers(): Array<UserDto>? = suspendCoroutine { continuation ->
|
||||
GetPublicUsersAsync(object : Response<Array<UserDto>>() {
|
||||
override fun onResponse(response: Array<UserDto>?) = continuation.resume(response!!)
|
||||
override fun onError(exception: Exception?) = continuation.resume(null)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Coroutine capable version of the "getUserViews" function
|
||||
* Uses the userId of the currently signed in user
|
||||
@@ -46,8 +24,8 @@ suspend fun ApiClient.getUserViews(): ItemsResult? = suspendCoroutine { continua
|
||||
* Adds a coroutine capable version of the "GetItem" function
|
||||
* Uses the userId of the currently signed in user
|
||||
*/
|
||||
suspend fun ApiClient.getItem(id: String): BaseItemDto? = suspendCoroutine { continuation ->
|
||||
GetItemAsync(id, TvApp.getApplication()?.currentUser?.id, object : Response<BaseItemDto>() {
|
||||
suspend fun ApiClient.getItem(id: String, userId: UUID): BaseItemDto? = suspendCoroutine { continuation ->
|
||||
GetItemAsync(id, userId.toString(), object : Response<BaseItemDto>() {
|
||||
override fun onResponse(response: BaseItemDto?) = continuation.resume(response!!)
|
||||
override fun onError(exception: Exception?) = continuation.resume(null)
|
||||
})
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.jellyfin.androidtv.R;
|
||||
import org.jellyfin.androidtv.TvApp;
|
||||
import org.jellyfin.androidtv.auth.SessionRepository;
|
||||
import org.jellyfin.androidtv.preference.UserPreferences;
|
||||
import org.jellyfin.androidtv.ui.itemdetail.ItemListActivity;
|
||||
import org.jellyfin.androidtv.ui.playback.MediaManager;
|
||||
@@ -15,7 +15,6 @@ import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemType;
|
||||
import org.jellyfin.apiclient.model.dto.UserDto;
|
||||
import org.jellyfin.apiclient.model.entities.LocationType;
|
||||
import org.jellyfin.apiclient.model.livetv.ChannelInfoDto;
|
||||
import org.jellyfin.apiclient.model.querying.EpisodeQuery;
|
||||
@@ -31,6 +30,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
@@ -38,12 +38,7 @@ public class PlaybackHelper {
|
||||
private static final int ITEM_QUERY_LIMIT = 150; // limit the number of items retrieved for playback
|
||||
|
||||
public static void getItemsToPlay(final BaseItemDto mainItem, boolean allowIntros, final boolean shuffle, final Response<List<BaseItemDto>> outerResponse) {
|
||||
final UserDto currentUser = TvApp.getApplication().getCurrentUser();
|
||||
if (currentUser == null) {
|
||||
Timber.e("Unable to get items to play; current user is null");
|
||||
outerResponse.onError(new Exception("Current user is null"));
|
||||
return;
|
||||
}
|
||||
UUID userId = KoinJavaComponent.<SessionRepository>get(SessionRepository.class).getCurrentSession().getValue().getUserId();
|
||||
|
||||
final List<BaseItemDto> items = new ArrayList<>();
|
||||
ItemQuery query = new ItemQuery();
|
||||
@@ -57,7 +52,7 @@ public class PlaybackHelper {
|
||||
if (mainItem.getSeriesId() != null && mainItem.getId() != null) {
|
||||
EpisodeQuery episodeQuery = new EpisodeQuery();
|
||||
episodeQuery.setSeriesId(mainItem.getSeriesId());
|
||||
episodeQuery.setUserId(currentUser.getId());
|
||||
episodeQuery.setUserId(userId.toString());
|
||||
episodeQuery.setIsVirtualUnaired(false);
|
||||
episodeQuery.setIsMissing(false);
|
||||
episodeQuery.setFields(new ItemFields[] {
|
||||
@@ -123,7 +118,7 @@ public class PlaybackHelper {
|
||||
ItemFields.PrimaryImageAspectRatio,
|
||||
ItemFields.ChildCount
|
||||
});
|
||||
query.setUserId(currentUser.getId());
|
||||
query.setUserId(userId.toString());
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult response) {
|
||||
@@ -146,7 +141,7 @@ public class PlaybackHelper {
|
||||
ItemFields.Genres,
|
||||
ItemFields.ChildCount
|
||||
});
|
||||
query.setUserId(currentUser.getId());
|
||||
query.setUserId(userId.toString());
|
||||
query.setArtistIds(new String[]{mainItem.getId()});
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
@@ -174,7 +169,7 @@ public class PlaybackHelper {
|
||||
ItemFields.PrimaryImageAspectRatio,
|
||||
ItemFields.ChildCount
|
||||
});
|
||||
query.setUserId(currentUser.getId());
|
||||
query.setUserId(userId.toString());
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemsAsync(query, new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult response) {
|
||||
@@ -190,7 +185,7 @@ public class PlaybackHelper {
|
||||
}
|
||||
|
||||
//We retrieve the channel the program is on (which should be the program's parent)
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemAsync(mainItem.getParentId(), currentUser.getId(), new Response<BaseItemDto>() {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemAsync(mainItem.getParentId(), userId.toString(), new Response<BaseItemDto>() {
|
||||
@Override
|
||||
public void onResponse(BaseItemDto response) {
|
||||
// fill in info about the specific program for display
|
||||
@@ -211,7 +206,7 @@ public class PlaybackHelper {
|
||||
|
||||
case TvChannel:
|
||||
// Retrieve full channel info for display
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetLiveTvChannelAsync(mainItem.getId(), currentUser.getId(), new Response<ChannelInfoDto>() {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetLiveTvChannelAsync(mainItem.getId(), userId.toString(), new Response<ChannelInfoDto>() {
|
||||
@Override
|
||||
public void onResponse(ChannelInfoDto response) {
|
||||
// get current program info and fill it into our item
|
||||
@@ -230,7 +225,7 @@ public class PlaybackHelper {
|
||||
default:
|
||||
if (allowIntros && !KoinJavaComponent.<PlaybackLauncher>get(PlaybackLauncher.class).useExternalPlayer(mainItem.getBaseItemType()) && KoinJavaComponent.<UserPreferences>get(UserPreferences.class).get(UserPreferences.Companion.getCinemaModeEnabled())) {
|
||||
//Intros
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetIntrosAsync(mainItem.getId(), currentUser.getId(), new Response<ItemsResult>() {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetIntrosAsync(mainItem.getId(), userId.toString(), new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult response) {
|
||||
if (response.getTotalRecordCount() > 0){
|
||||
@@ -319,7 +314,8 @@ public class PlaybackHelper {
|
||||
}
|
||||
|
||||
public static void retrieveAndPlay(String id, final boolean shuffle, final Long position, final Context activity) {
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemAsync(id, TvApp.getApplication().getCurrentUser().getId(), new Response<BaseItemDto>() {
|
||||
UUID userId = KoinJavaComponent.<SessionRepository>get(SessionRepository.class).getCurrentSession().getValue().getUserId();
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetItemAsync(id, userId.toString(), new Response<BaseItemDto>() {
|
||||
@Override
|
||||
public void onResponse(BaseItemDto response) {
|
||||
Long pos = position != null ? position / 10000 : response.getUserData() != null ? (response.getUserData().getPlaybackPositionTicks() / 10000) - getResumePreroll() : 0;
|
||||
@@ -352,9 +348,10 @@ public class PlaybackHelper {
|
||||
}
|
||||
|
||||
public static void getInstantMixAsync(String seedId, final Response<BaseItemDto[]> outerResponse) {
|
||||
UUID userId = KoinJavaComponent.<SessionRepository>get(SessionRepository.class).getCurrentSession().getValue().getUserId();
|
||||
SimilarItemsQuery query = new SimilarItemsQuery();
|
||||
query.setId(seedId);
|
||||
query.setUserId(TvApp.getApplication().getCurrentUser().getId());
|
||||
query.setUserId(userId.toString());
|
||||
query.setFields(new ItemFields[] {
|
||||
ItemFields.PrimaryImageAspectRatio,
|
||||
ItemFields.Genres,
|
||||
@@ -377,7 +374,8 @@ public class PlaybackHelper {
|
||||
items.add(mainItem);
|
||||
if (mainItem.getPartCount() != null && mainItem.getPartCount() > 1) {
|
||||
// get additional parts
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetAdditionalParts(mainItem.getId(), TvApp.getApplication().getCurrentUser().getId(), new Response<ItemsResult>() {
|
||||
UUID userId = KoinJavaComponent.<SessionRepository>get(SessionRepository.class).getCurrentSession().getValue().getUserId();
|
||||
KoinJavaComponent.<ApiClient>get(ApiClient.class).GetAdditionalParts(mainItem.getId(), userId.toString(), new Response<ItemsResult>() {
|
||||
@Override
|
||||
public void onResponse(ItemsResult response) {
|
||||
Collections.addAll(items, response.getItems());
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.jellyfin.androidtv.util.apiclient;
|
||||
|
||||
import org.jellyfin.androidtv.TvApp;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.jellyfin.androidtv.auth.SessionRepository;
|
||||
import org.jellyfin.androidtv.data.compat.StreamInfo;
|
||||
import org.jellyfin.androidtv.data.model.DataRefreshService;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackController;
|
||||
import org.jellyfin.androidtv.ui.playback.PlaybackManager;
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
||||
@@ -12,15 +15,19 @@ import org.jellyfin.apiclient.model.session.PlaybackStartInfo;
|
||||
import org.jellyfin.apiclient.model.session.PlaybackStopInfo;
|
||||
import org.koin.java.KoinJavaComponent;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class ReportingHelper {
|
||||
public static void reportStopped(BaseItemDto item, StreamInfo streamInfo, long pos) {
|
||||
if (item != null && streamInfo != null) {
|
||||
UUID userId = KoinJavaComponent.<SessionRepository>get(SessionRepository.class).getCurrentSession().getValue().getUserId();
|
||||
|
||||
PlaybackStopInfo info = new PlaybackStopInfo();
|
||||
info.setItemId(item.getId());
|
||||
info.setPositionTicks(pos);
|
||||
KoinJavaComponent.<PlaybackManager>get(PlaybackManager.class).reportPlaybackStopped(info, streamInfo, KoinJavaComponent.<ApiClient>get(ApiClient.class).getServerInfo().getId(), TvApp.getApplication().getCurrentUser().getId(), KoinJavaComponent.<ApiClient>get(ApiClient.class), new EmptyResponse());
|
||||
KoinJavaComponent.<PlaybackManager>get(PlaybackManager.class).reportPlaybackStopped(info, streamInfo, KoinJavaComponent.<ApiClient>get(ApiClient.class).getServerInfo().getId(), userId.toString(), KoinJavaComponent.<ApiClient>get(ApiClient.class), new EmptyResponse());
|
||||
|
||||
DataRefreshService dataRefreshService = KoinJavaComponent.<DataRefreshService>get(DataRefreshService.class);
|
||||
dataRefreshService.setLastPlayback(System.currentTimeMillis());
|
||||
@@ -43,7 +50,7 @@ public class ReportingHelper {
|
||||
Timber.i("Playback of %s started.", item.getName());
|
||||
}
|
||||
|
||||
public static void reportProgress(BaseItemDto item, StreamInfo currentStreamInfo, Long position, boolean isPaused) {
|
||||
public static void reportProgress(@Nullable PlaybackController playbackController, BaseItemDto item, StreamInfo currentStreamInfo, Long position, boolean isPaused) {
|
||||
if (item != null && currentStreamInfo != null) {
|
||||
PlaybackProgressInfo info = new PlaybackProgressInfo();
|
||||
info.setItemId(item.getId());
|
||||
@@ -51,9 +58,9 @@ public class ReportingHelper {
|
||||
info.setIsPaused(isPaused);
|
||||
info.setCanSeek(currentStreamInfo.getRunTimeTicks() != null && currentStreamInfo.getRunTimeTicks() > 0);
|
||||
info.setPlayMethod(currentStreamInfo.getPlayMethod());
|
||||
if (TvApp.getApplication().getPlaybackController() != null && TvApp.getApplication().getPlaybackController().isPlaying()) {
|
||||
info.setAudioStreamIndex(TvApp.getApplication().getPlaybackController().getAudioStreamIndex());
|
||||
info.setSubtitleStreamIndex(TvApp.getApplication().getPlaybackController().getSubtitleStreamIndex());
|
||||
if (playbackController != null && playbackController.isPlaying()) {
|
||||
info.setAudioStreamIndex(playbackController.getAudioStreamIndex());
|
||||
info.setSubtitleStreamIndex(playbackController.getSubtitleStreamIndex());
|
||||
}
|
||||
KoinJavaComponent.<PlaybackManager>get(PlaybackManager.class).reportPlaybackProgress(info, currentStreamInfo, KoinJavaComponent.<ApiClient>get(ApiClient.class), new EmptyResponse());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user