Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace easy to implement libraries with own implementation to reduce… #306

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<item name="android:windowFullscreen">false</item>
<item name="android:windowDrawsSystemBarBackgrounds">false</item>
<item name="android:windowLayoutInDisplayCutoutMode">shortEdges</item>
<item name="android:defaultFocusHighlightEnabled">false</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Expand All @@ -18,5 +19,6 @@
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
<item name="android:defaultFocusHighlightEnabled">false</item>
</style>
</resources>
2 changes: 1 addition & 1 deletion assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 35 additions & 15 deletions lib/app/views/tv/screens/tv_home.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:application_icon/application_icon.dart';
import 'package:flutter/material.dart';
import 'package:flutter_animate/flutter_animate.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:invidious/app/states/tv_home.dart';
Expand All @@ -14,6 +14,7 @@ import 'package:invidious/videos/views/components/subscriptions.dart';
import 'package:invidious/videos/views/components/trending.dart';
import 'package:invidious/videos/views/tv/screens/video_grid_view.dart';

import '../../../../utils/views/components/app_icon.dart';
import '../../../../videos/views/components/popular.dart';
import '../../../states/app.dart';

Expand Down Expand Up @@ -78,7 +79,7 @@ class TvHome extends StatelessWidget {
body: BlocBuilder<TvHomeCubit, bool>(builder: (context, expandMenu) {
var cubit = context.read<TvHomeCubit>();
return BlocBuilder<AppCubit, AppState>(buildWhen: (previous, current) {
return previous.server != current.server;
return previous.server != current.server;
}, builder: (context, _) {
var app = context.read<AppCubit>();
return DefaultTextStyle(
Expand All @@ -100,13 +101,17 @@ class TvHome extends StatelessWidget {
height: 50,
child: Row(
children: [
const AppIconImage(),
Visibility(
visible: expandMenu,
child: Text(
'Clipious',
style: textTheme.titleLarge!.copyWith(color: colors.primary),
))
const AppIcon(
width: 50,
height: 50,
),
if (expandMenu)
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: MenuItemText(
'Clipious',
style: textTheme.titleLarge!.copyWith(color: colors.primary),
))
],
)),
),
Expand All @@ -124,7 +129,7 @@ class TvHome extends StatelessWidget {
padding: EdgeInsets.only(right: 8.0),
child: Icon(Icons.search),
),
expandMenu ? Text(locals.search) : const SizedBox.shrink()
if (expandMenu) MenuItemText(locals.search)
],
),
),
Expand All @@ -146,7 +151,7 @@ class TvHome extends StatelessWidget {
padding: EdgeInsets.only(right: 8.0),
child: Icon(Icons.subscriptions),
),
expandMenu ? Text(locals.subscriptions) : const SizedBox.shrink()
if (expandMenu) MenuItemText(locals.subscriptions)
],
),
),
Expand All @@ -169,7 +174,7 @@ class TvHome extends StatelessWidget {
padding: EdgeInsets.only(right: 8.0),
child: Icon(Icons.playlist_play),
),
expandMenu ? Text(locals.playlists) : const SizedBox.shrink()
if (expandMenu) MenuItemText(locals.playlists)
],
),
),
Expand All @@ -190,7 +195,7 @@ class TvHome extends StatelessWidget {
padding: EdgeInsets.only(right: 8.0),
child: Icon(Icons.local_fire_department),
),
expandMenu ? Text(locals.popular) : const SizedBox.shrink()
if (expandMenu) MenuItemText(locals.popular)
],
),
),
Expand All @@ -210,7 +215,7 @@ class TvHome extends StatelessWidget {
padding: EdgeInsets.only(right: 8.0),
child: Icon(Icons.trending_up),
),
expandMenu ? Text(locals.trending) : const SizedBox.shrink()
if (expandMenu) MenuItemText(locals.trending)
],
),
),
Expand All @@ -228,7 +233,7 @@ class TvHome extends StatelessWidget {
padding: EdgeInsets.only(right: 8.0),
child: Icon(Icons.settings),
),
expandMenu ? Text(locals.settings) : const SizedBox.shrink()
if (expandMenu) MenuItemText(locals.settings)
],
),
),
Expand Down Expand Up @@ -278,3 +283,18 @@ class TvHome extends StatelessWidget {
);
}
}

class MenuItemText extends StatelessWidget {
final String text;
final TextStyle? style;

const MenuItemText(this.text, {super.key, this.style});

@override
Widget build(BuildContext context) {
return Text(
text,
style: style,
).animate().fadeIn(delay: animationDuration ~/ 2, duration: animationDuration).slideX(curve: Curves.easeInOutQuad);
}
}
8 changes: 6 additions & 2 deletions lib/home/views/components/home.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:application_icon/application_icon.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand All @@ -9,6 +8,7 @@ import 'package:invidious/home/states/home.dart';

import '../../../main.dart';
import '../../../search/views/screens/search.dart';
import '../../../utils/views/components/app_icon.dart';

const double smallVideoViewHeight = 140;

Expand Down Expand Up @@ -78,7 +78,11 @@ class HomeView extends StatelessWidget {
padding: const EdgeInsets.only(left: innerHorizontalPadding),
color: colors.background,
child: layout.smallSources.isEmpty && !layout.showBigSource
? const Opacity(opacity: 0.2, child: AppIconImage())
? const Opacity(
opacity: 0.2,
child: AppIcon(
height: 200,
))
: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
9 changes: 7 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:async';
import 'dart:io';

import 'package:after_layout/after_layout.dart';
import 'package:application_icon/application_icon.dart';
import 'package:back_button_interceptor/back_button_interceptor.dart';
import 'package:dynamic_color/dynamic_color.dart';
import 'package:flutter/foundation.dart';
Expand All @@ -28,6 +27,7 @@ import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/settings/views/screens/settings.dart';
import 'package:invidious/subscription_management/view/screens/manage_subscriptions.dart';
import 'package:invidious/utils.dart';
import 'package:invidious/utils/views/components/app_icon.dart';
import 'package:invidious/videos/views/screens/video.dart';
import 'package:invidious/welcome_wizard/views/screens/welcome_wizard.dart';
import 'package:invidious/welcome_wizard/views/tv/screens/welcome_wizard.dart';
Expand Down Expand Up @@ -369,7 +369,12 @@ class _HomeState extends State<Home> with AfterLayoutMixin {
// home handles its own padding because we don't want to cut horizontal scroll lists on the right
padding: EdgeInsets.symmetric(horizontal: selectedPage == HomeDataSource.home ? 0 : innerHorizontalPadding),
key: ValueKey(selectedPage),
child: selectedPage?.build(context, false) ?? const Opacity(opacity: 0.2, child: AppIconImage())),
child: selectedPage?.build(context, false) ??
const Opacity(
opacity: 0.2,
child: AppIcon(
height: 200,
))),
/*
child: <Widget>[
const HomeView(
Expand Down
20 changes: 0 additions & 20 deletions lib/myRouteObserver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,6 @@ class MyRouteObserver extends RouteObserver<PageRoute<dynamic>> {

stopPlayingOnPop(PageRoute<dynamic>? newRoute, PageRoute<dynamic>? poppedRoute) {
newRoute?.navigator?.context.read<PlayerCubit>().showMiniPlayer();
if (newRoute != null) {
switch (newRoute.settings) {
case ROUTE_SETTINGS:
case ROUTE_PLAYLIST:
case ROUTE_SETTINGS_MANAGE_SERVERS:
case ROUTE_SETTINGS_MANAGE_ONE_SERVER:
case ROUTE_SETTINGS_SPONSOR_BLOCK:
case ROUTE_SETTINGS_VIDEO_FILTERS:
case ROUTE_VIDEO:
case ROUTE_PLAYLIST_LIST:
case ROUTE_CHANNEL:
case ROUTE_MANAGE_SUBSCRIPTIONS:
log.fine('We should stop playing video');
// MiniPlayerController.to()?.showMiniPlayer();
break;
default:
log.fine('keep playing video');
break;
}
}
}

@override
Expand Down
6 changes: 5 additions & 1 deletion lib/player/states/audio_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class AudioPlayerCubit extends MediaPlayerCubit<AudioPlayerState> {
initPlayer() {
if (state.player == null) {
state.player = AudioPlayer();
state.player?.playerStateStream.listen(onStateStreamChange);
state.player?.playerStateStream.listen(onStateStreamChange, onError: (e, st) {
print('ERRRRRROOOORR');
return globalPlayer.setEvent(MediaEvent(state: MediaState.error));
});
state.player?.positionStream.listen(onPositionChanged);
state.player?.durationStream.listen(onDurationChanged);
}
Expand Down Expand Up @@ -129,6 +132,7 @@ class AudioPlayerCubit extends MediaPlayerCubit<AudioPlayerState> {
}
} catch (e) {
log.severe("Couldn't play video", e);
globalPlayer.setEvent(MediaEvent(state: MediaState.error));
state.error = e.toString();
state.loading = false;
if (!isClosed) emit(state);
Expand Down
15 changes: 13 additions & 2 deletions lib/player/states/player_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ class PlayerControlsCubit extends Cubit<PlayerControlsState> {
hideControls();
state = this.state.copyWith();
break;
case MediaState.error:
hideControls();
state = this.state.copyWith();
state.errored = true;
default:
break;
}

switch (event.type) {
case MediaEventType.progress:
state.audioPosition = event.value;
state.errored = false;
break;
case MediaEventType.seek:
showControls();
Expand All @@ -63,7 +68,7 @@ class PlayerControlsCubit extends Cubit<PlayerControlsState> {
void hideControls() {
var state = this.state.copyWith();
state.displayControls = false;
if(!isClosed) {
if (!isClosed) {
emit(state);
}
}
Expand Down Expand Up @@ -100,16 +105,22 @@ class PlayerControlsCubit extends Cubit<PlayerControlsState> {
void setPlaybackSpeed(double d) {
player.setSpeed(d);
}

void removeError() {
emit(state.copyWith(errored: false));
}
}

@CopyWith(constructor: "_")
class PlayerControlsState {
PlayerControlsState();

bool errored = false;

MediaEvent event = MediaEvent(state: MediaState.idle);
Duration audioPosition = Duration.zero;

bool displayControls = false;

PlayerControlsState._(this.event, this.audioPosition, this.displayControls);
PlayerControlsState._(this.event, this.audioPosition, this.displayControls, this.errored);
}
11 changes: 11 additions & 0 deletions lib/player/states/player_controls.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading