Skip to content

Commit

Permalink
Merge pull request #295 from lamarios/feature/fix-issues-2023-08-22
Browse files Browse the repository at this point in the history
Issue fix batch
  • Loading branch information
lamarios authored Aug 22, 2023
2 parents 53b0b45 + d91dfc8 commit 1e408a6
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 28 deletions.
3 changes: 2 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<data android:scheme="clipious-auth"/>
</intent-filter>
</activity>
<!-- android:name="com.ryanheise.audioservice.AudioServiceActivity"-->
<activity
android:name="com.ryanheise.audioservice.AudioServiceActivity"
android:name=".MainActivity"
android:exported="true"
android:launchMode="singleTop"
android:supportsPictureInPicture="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package com.github.lamarios.clipious

import io.flutter.embedding.android.FlutterActivity
import cl.puntito.simple_pip_mode.PipCallbackHelper
import com.ryanheise.audioservice.AudioServiceActivity;
import androidx.annotation.NonNull;
import io.flutter.embedding.engine.FlutterEngine
import android.content.res.Configuration
class MainActivity : AudioServiceActivity() {
private var callbackHelper = PipCallbackHelper()

class MainActivity : FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
super.configureFlutterEngine(flutterEngine)
callbackHelper.configureFlutterEngine(flutterEngine)
}

override fun onPictureInPictureModeChanged(active: Boolean, newConfig: Configuration?) {
callbackHelper.onPictureInPictureModeChanged(active)
}
}
2 changes: 2 additions & 0 deletions lib/player/models/mediaEvent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ enum MediaState {
ready,
error,
completed,
enteredPip,
exitedPip,
miniDisplayChanged;
}
13 changes: 12 additions & 1 deletion lib/player/states/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class PlayerCubit extends Cubit<PlayerState> {
androidNotificationOngoing: true,
),
);
BackButtonInterceptor.add(handleBackButton, name: 'miniPlayer', zIndex: 2);
BackButtonInterceptor.add(handleBackButton, name: 'miniPlayer', zIndex: 2, ifNotYetIntercepted: true);
} else if (isTv && state.videos.isNotEmpty) {
switchToVideo(state.videos[0]);
}
Expand All @@ -109,6 +109,11 @@ class PlayerCubit extends Cubit<PlayerState> {
playNext();
_setPlaying(false);
break;
case MediaState.enteredPip:
_setPip(true);
break;
case MediaState.exitedPip:
_setPip(false);
default:
break;
}
Expand All @@ -127,6 +132,12 @@ class PlayerCubit extends Cubit<PlayerState> {
}
}

_setPip(bool pip) {
var state = this.state.copyWith();
state.isPip = pip;
emit(state);
}

@override
close() async {
BackButtonInterceptor.removeByName('miniPlayer');
Expand Down
26 changes: 22 additions & 4 deletions lib/player/states/video_player.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:better_player/better_player.dart';
import 'package:better_player/src/video_player/video_player_platform_interface.dart';
import 'package:copy_with_extension/copy_with_extension.dart';
Expand All @@ -11,6 +12,7 @@ import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/videos/models/base_video.dart';
import 'package:logging/logging.dart';
import 'package:pretty_bytes/pretty_bytes.dart';
import 'package:simple_pip_mode/simple_pip.dart';
import 'package:wakelock/wakelock.dart';

import '../../globals.dart';
Expand Down Expand Up @@ -94,8 +96,10 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {
mediaState = MediaState.loading;
break;
case BetterPlayerEventType.pipStop:
mediaState = MediaState.exitedPip;
break;
case BetterPlayerEventType.pipStart:
mediaState = MediaState.enteredPip;
break;
case BetterPlayerEventType.overflowOpened:
break;
Expand Down Expand Up @@ -201,7 +205,6 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {

@override
playVideo(bool offline, {Duration? startAt}) async {
bool wasFullscreen = this.state.videoController?.isFullScreen ?? false;
var state = this.state.copyWith();
// only used if the player is currently close because it is onReady that will actually play the video
// need better way of handling this
Expand Down Expand Up @@ -300,7 +303,7 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {
subtitlesConfiguration: BetterPlayerSubtitlesConfiguration(
fontSize: settings.state.subtitleSize,
),
controlsConfiguration: BetterPlayerControlsConfiguration(
controlsConfiguration: const BetterPlayerControlsConfiguration(
showControls: false,
// customControlsBuilder: (controller, onPlayerVisibilityChanged) => const PlayerControls(),
// enablePlayPause: false,
Expand Down Expand Up @@ -374,11 +377,18 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {
setFullScreen(bool fullScreen) {
if (fullScreen) {
state.videoController?.enterFullScreen();
BackButtonInterceptor.add(backButtonInterceptor, zIndex: 10, name: 'full screen player');
} else {
state.videoController?.exitFullScreen();
BackButtonInterceptor.remove(backButtonInterceptor);
}
}

bool backButtonInterceptor(bool stopDefaultButtonEvent, RouteInfo info) {
setFullScreen(false);
return true;
}

String _videoTrackToString(BetterPlayerAsmsTrack? track) {
return '${track?.height}p - ${prettyBytes((track?.bitrate ?? 0).toDouble(), bits: true)}/s';
}
Expand Down Expand Up @@ -487,12 +497,20 @@ class VideoPlayerCubit extends MediaPlayerCubit<VideoPlayerState> {

@override
bool supportsPip() {
return isFullScreen() == FullScreenState.notFullScreen;
return true;
}

@override
void enterPip() {
state.videoController?.enablePictureInPicture(state.key);
player.setEvent(MediaEvent(state: MediaState.enteredPip));
setFullScreen(true);
SimplePip(
onPipExited: () {
player.setEvent(MediaEvent(state: MediaState.exitedPip));
setFullScreen(false);
},
).enterPipMode();
// state.videoController?.enablePictureInPicture(state.key);
}

@override
Expand Down
31 changes: 23 additions & 8 deletions lib/player/views/components/player_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ class PlayerControls extends StatelessWidget {
create: (context) => PlayerControlsCubit(PlayerControlsState(), player),
child: BlocBuilder<PlayerControlsCubit, PlayerControlsState>(
builder: (context, _) {
bool isMini = context.select((PlayerCubit cubit) => cubit.state.isMini);
bool hasQueue = context.select((PlayerCubit cubit) => cubit.state.hasQueue);
bool isPip = context.select((PlayerCubit cubit) => cubit.state.isPip);
String videoTitle = context.select((PlayerCubit cubit) => cubit.state.currentlyPlaying?.title ?? cubit.state.offlineCurrentlyPlaying?.title ?? '');

late MediaPlayerCubit pc;
if (mediaPlayerCubit != null) {
pc = mediaPlayerCubit!;
Expand All @@ -189,7 +194,7 @@ class PlayerControls extends StatelessWidget {
} else {
pc = context.read<VideoPlayerCubit>();
}
PlayerState mpc = player.state;
// PlayerState mpc = player.state;
var event = _.event;
var cubit = context.read<PlayerControlsCubit>();
return BlocListener<PlayerCubit, PlayerState>(
Expand All @@ -204,7 +209,7 @@ class PlayerControls extends StatelessWidget {
onVerticalDragUpdate: pc.isFullScreen() == FullScreenState.fullScreen ? null : player.videoDragged,
onVerticalDragStart: pc.isFullScreen() == FullScreenState.fullScreen ? null : player.videoDragStarted,
child: Padding(
padding: EdgeInsets.all(mpc.isMini ? 8 : 0.0),
padding: EdgeInsets.all(isMini ? 8 : 0.0),
child: AspectRatio(
aspectRatio: 16 / 9,
child: Stack(
Expand All @@ -215,16 +220,26 @@ class PlayerControls extends StatelessWidget {
right: 0,
bottom: 0,
top: 0,
child: mpc.isMini
child: isMini || isPip
? const SizedBox.shrink()
: _.displayControls && !mpc.isMini
: _.displayControls
? Container(
decoration: BoxDecoration(borderRadius: BorderRadius.circular(0), color: Colors.black.withOpacity(0.6)),
decoration: BoxDecoration(borderRadius: BorderRadius.circular(0), color: Colors.black.withOpacity(0.4)),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (pc.isFullScreen() == FullScreenState.fullScreen)
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text(
videoTitle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
)),
if (pc.supportsPip()) IconButton(onPressed: pc.enterPip, icon: const Icon(Icons.picture_in_picture)),
IconButton(onPressed: () => showOptionMenu(context, _, pc), icon: const Icon(Icons.more_vert))
],
Expand Down Expand Up @@ -273,7 +288,7 @@ class PlayerControls extends StatelessWidget {
)
: const SizedBox.expand(),
),
if (_.displayControls)
if (!isMini && !isPip && _.displayControls)
Positioned(
top: 0,
left: 0,
Expand All @@ -283,7 +298,7 @@ class PlayerControls extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (mpc.hasQueue)
if (hasQueue)
IconButton(
onPressed: () => player.playPrevious(),
icon: const Icon(
Expand All @@ -306,7 +321,7 @@ class PlayerControls extends StatelessWidget {
Icons.fast_forward,
size: 30,
)),
if (mpc.hasQueue)
if (hasQueue)
IconButton(
onPressed: () => player.playNext(),
icon: const Icon(
Expand Down
12 changes: 12 additions & 0 deletions lib/settings/views/components/manager_server_inner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:invidious/app/states/app.dart';
import 'package:invidious/main.dart';
import 'package:invidious/myRouteObserver.dart';
import 'package:invidious/settings/states/server_list_settings.dart';
import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/settings/views/screens/manage_single_server.dart';
import 'package:settings_ui/settings_ui.dart';

Expand Down Expand Up @@ -139,6 +140,7 @@ class ManagerServersView extends StatelessWidget {

return BlocBuilder<ServerListSettingsCubit, ServerListSettingsState>(
builder: (ctx, _) {
SettingsCubit settings = context.watch<SettingsCubit>();
ServerListSettingsCubit cubit = context.read<ServerListSettingsCubit>();
var app = context.read<AppCubit>();
var filteredPublicServers = _.publicServers.where((s) => _.dbServers.indexWhere((element) => element.url == s.url) == -1).toList();
Expand All @@ -148,6 +150,16 @@ class ManagerServersView extends StatelessWidget {
lightTheme: theme,
darkTheme: theme,
sections: [
SettingsSection(
tiles: [
SettingsTile.switchTile(
title: Text(locals.skipSslVerification),
description: Text(locals.skipSslVerificationDescription),
initialValue: settings.state.skipSslVerification,
onToggle: settings.toggleSslVerification,
)
],
),
SettingsSection(
title: Text(locals.yourServers),
tiles: _.dbServers.isNotEmpty
Expand Down
6 changes: 0 additions & 6 deletions lib/settings/views/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,6 @@ class Settings extends StatelessWidget {
description: BlocBuilder<AppCubit, AppState>(
buildWhen: (previous, current) => previous.server != current.server, builder: (context, app) => Text(app.server != null ? locals.currentServer(app.server!.url) : "")),
onPressed: manageServers,
),
SettingsTile.switchTile(
title: Text(locals.skipSslVerification),
description: Text(locals.skipSslVerificationDescription),
initialValue: _.skipSslVerification,
onToggle: cubit.toggleSslVerification,
)
]),
SettingsSection(title: Text(locals.videoPlayer), tiles: [
Expand Down
8 changes: 8 additions & 0 deletions lib/settings/views/tv/components/manage_server_inner.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/settings/views/tv/screens/manage_single_server.dart';
import 'package:invidious/utils.dart';
import 'package:invidious/utils/views/tv/components/tv_button.dart';
Expand Down Expand Up @@ -96,8 +97,15 @@ class TvManageServersInner extends StatelessWidget {
AppLocalizations locals = AppLocalizations.of(context)!;
return BlocBuilder<ServerListSettingsCubit, ServerListSettingsState>(builder: (context, _) {
var cubit = context.read<ServerListSettingsCubit>();
var settings = context.watch<SettingsCubit>();
var filteredPublicServers = _.publicServers.where((s) => _.dbServers.indexWhere((element) => element.url == s.url) == -1).toList();
return ListView(children: [
SettingsTile(
title: locals.skipSslVerification,
description: locals.skipSslVerification,
onSelected: (context) => settings.toggleSslVerification(!settings.state.skipSslVerification),
trailing: Switch(onChanged: (value) {}, value: settings.state.skipSslVerification),
),
SettingsTitle(title: locals.yourServers),
..._.dbServers.map((s) => SettingsTile(
leading: InkWell(
Expand Down
6 changes: 0 additions & 6 deletions lib/settings/views/tv/screens/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ class TVSettings extends StatelessWidget {
buildWhen: (previous, current) => previous.server != current.server,
builder: (context, app) =>
SettingsTile(title: locals.manageServers, description: app.server != null ? locals.currentServer(db.getCurrentlySelectedServer().url) : "", onSelected: openManageServers)),
SettingsTile(
title: locals.skipSslVerification,
description: locals.skipSslVerification,
onSelected: (context) => cubit.toggleSslVerification(!_.skipSslVerification),
trailing: Switch(onChanged: (value) {}, value: _.skipSslVerification),
),
SettingsTitle(title: locals.videoPlayer),
SettingsTile(
title: locals.useDash,
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.4"
simple_pip_mode:
dependency: "direct main"
description:
name: simple_pip_mode
sha256: "89f8137fa5a8d113f39c61007d4b658048a9359362447b8cfb8bce93631882ad"
url: "https://pub.dev"
source: hosted
version: "0.8.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.14.6+4022
version: 1.14.7+4023

environment:
sdk: '>=3.0.0 <4.0.0'
Expand Down Expand Up @@ -83,6 +83,7 @@ dependencies:
flutter_bloc: 8.1.3
copy_with_extension: 5.0.4
pretty_bytes: 6.1.0
simple_pip_mode: ^0.8.0
dependency_overrides:
# wakelock_windows:
# git: # see https://github.com/creativecreatorormaybenot/wakelock/pull/203 for updates
Expand Down

0 comments on commit 1e408a6

Please sign in to comment.