Skip to content

Commit

Permalink
Merge pull request #320 from lamarios/feature/fixes_2023-09
Browse files Browse the repository at this point in the history
update some transition animation
  • Loading branch information
lamarios authored Sep 25, 2023
2 parents 85b76ba + a56e936 commit 8495112
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 133 deletions.
19 changes: 13 additions & 6 deletions lib/app/states/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import '../../database.dart';
import '../../globals.dart';
import '../../home/models/db/home_layout.dart';
import '../../settings/models/db/server.dart';
import '../../videos/models/db/progress.dart';

part 'app.g.dart';

final log = Logger('HomeState');

class AppCubit extends Cubit<AppState> {

AppCubit(super.initialState) {
onReady();
}
Expand All @@ -38,6 +38,16 @@ class AppCubit extends Cubit<AppState> {
selectedIndex = 0;
}
selectIndex(selectedIndex);
syncHistory();
}

syncHistory() async {
if (isLoggedIn) {
var history = await service.getUserHistory(1, 200);
for (String videoId in history) {
db.saveProgress(Progress.named(progress: 1, videoId: videoId));
}
}
}

@override
Expand All @@ -50,9 +60,7 @@ class AppCubit extends Cubit<AppState> {
try {
Uri uri = Uri.parse(url);
if (YOUTUBE_HOSTS.contains(uri.host)) {
if (uri.pathSegments.length == 1 &&
uri.pathSegments.contains("watch") &&
uri.queryParameters.containsKey('v')) {
if (uri.pathSegments.length == 1 && uri.pathSegments.contains("watch") && uri.queryParameters.containsKey('v')) {
String videoId = uri.queryParameters['v']!;
appRouter.push(VideoRoute(videoId: videoId));
}
Expand Down Expand Up @@ -83,8 +91,7 @@ class AppCubit extends Cubit<AppState> {
emit(state.copyWith(homeLayout: db.getHomeLayout()));
}

bool get isLoggedIn =>
(state.server?.authToken?.isNotEmpty ?? false) || (state.server?.sidCookie?.isNotEmpty ?? false);
bool get isLoggedIn => (state.server?.authToken?.isNotEmpty ?? false) || (state.server?.sidCookie?.isNotEmpty ?? false);
}

@CopyWith(constructor: "_")
Expand Down
4 changes: 2 additions & 2 deletions lib/channels/views/screens/channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:invidious/channels/views/components/info.dart';
import 'package:invidious/channels/views/components/playlists.dart';
import 'package:invidious/channels/views/components/videos.dart';
import 'package:invidious/globals.dart';
import 'package:invidious/utils/views/components/navigation_switcher.dart';

import '../../../settings/states/settings.dart';
import '../../../utils.dart';
Expand Down Expand Up @@ -72,8 +73,7 @@ class ChannelScreen extends StatelessWidget {
//.animate().slideY(duration: animationDuration, begin: 1, curve: Curves.easeInOutQuad),
body: SafeArea(
bottom: false,
child: AnimatedSwitcher(
duration: animationDuration,
child: NavigationSwitcher(
child: <Widget>[
_.loading
? const ChannelPlaceHolder()
Expand Down
29 changes: 2 additions & 27 deletions lib/home/views/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:invidious/router.dart';
import 'package:invidious/settings/states/settings.dart';
import 'package:invidious/utils.dart';
import 'package:invidious/utils/views/components/app_icon.dart';
import 'package:invidious/utils/views/components/navigation_switcher.dart';

import '../../../main.dart';
import '../../../notifications/notifications.dart';
Expand Down Expand Up @@ -148,13 +149,7 @@ class _HomeScreenState extends State<HomeScreen> {
left: 0,
right: 0,
bottom: 0,
child: AnimatedSwitcher(
switchInCurve: Curves.easeInOutQuad,
switchOutCurve: Curves.easeInOutQuad,
transitionBuilder: (Widget child, Animation<double> animation) {
return FadeTransition(opacity: animation, child: child);
},
duration: animationDuration,
child: NavigationSwitcher(
child: Container(
// 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),
Expand All @@ -165,26 +160,6 @@ class _HomeScreenState extends State<HomeScreen> {
child: AppIcon(
height: 200,
))),
/*
child: <Widget>[
const HomeView(
key: ValueKey(0),
),
const Trending(
key: ValueKey(1),
),
const Subscriptions(
key: ValueKey(2),
),
const AddToPlaylistList(
key: ValueKey(3),
canDeleteVideos: true,
),
const HistoryView(
key: ValueKey(4),
),
][_.selectedIndex],
*/
),
)
])));
Expand Down
4 changes: 2 additions & 2 deletions lib/player/states/player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ class PlayerCubit extends Cubit<PlayerState> {

db.saveProgress(progress);

if (progress.progress > 0.5) {
EasyDebounce.debounce('invidious-progress-sync-${progress.videoId}', const Duration(seconds: 5), () {
if (progress.progress > 0.1) {
EasyThrottle.throttle('invidious-progress-sync-${progress.videoId}', const Duration(minutes: 10), () {
if (service.isLoggedIn()) {
service.addToUserHistory(progress.videoId);
}
Expand Down
101 changes: 52 additions & 49 deletions lib/search/views/screens/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:invidious/globals.dart';
import 'package:invidious/playlists/views/components/playlist_list.dart';
import 'package:invidious/router.dart';
import 'package:invidious/search/models/search_type.dart';
import 'package:invidious/utils/views/components/navigation_switcher.dart';
import 'package:invidious/videos/models/video_in_list.dart';

import '../../../channels/models/channel.dart';
Expand Down Expand Up @@ -141,61 +142,63 @@ class SearchScreen extends StatelessWidget {
Expanded(
child: FractionallySizedBox(
widthFactor: 1,
child: [
VideoList(
paginatedVideoList: PageBasedPaginatedList<VideoInList>(
getItemsFunc: (page, maxResults) => service
.search(_.queryController.value.text,
page: page, sortBy: _.sortBy, type: SearchType.video)
.then((value) => value.videos),
maxResults: searchPageSize,
),
),
PaginatedListView<Channel>(
paginatedList: PageBasedPaginatedList<Channel>(
child: NavigationSwitcher(
child: [
VideoList(
paginatedVideoList: PageBasedPaginatedList<VideoInList>(
getItemsFunc: (page, maxResults) => service
.search(_.queryController.value.text,
page: page, sortBy: _.sortBy, type: SearchType.channel)
.then((value) => value.channels),
page: page, sortBy: _.sortBy, type: SearchType.video)
.then((value) => value.videos),
maxResults: searchPageSize,
),
itemBuilder: (e) => InkWell(
onTap: () {
AutoRouter.of(context).push(ChannelRoute(channelId: e.authorId));
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 20),
child: Row(
children: [
Expanded(
child: Text(
e.author,
style: TextStyle(color: colorScheme.primary),
)),
const Padding(
padding: EdgeInsets.only(right: 8.0),
child: Icon(
Icons.people,
size: 15,
),
PaginatedListView<Channel>(
paginatedList: PageBasedPaginatedList<Channel>(
getItemsFunc: (page, maxResults) => service
.search(_.queryController.value.text,
page: page, sortBy: _.sortBy, type: SearchType.channel)
.then((value) => value.channels),
maxResults: searchPageSize,
),
itemBuilder: (e) => InkWell(
onTap: () {
AutoRouter.of(context).push(ChannelRoute(channelId: e.authorId));
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 20),
child: Row(
children: [
Expanded(
child: Text(
e.author,
style: TextStyle(color: colorScheme.primary),
)),
const Padding(
padding: EdgeInsets.only(right: 8.0),
child: Icon(
Icons.people,
size: 15,
),
),
),
Text(compactCurrency.format(e.subCount)),
],
Text(compactCurrency.format(e.subCount)),
],
),
),
),
)),
FractionallySizedBox(
child: PlaylistList(
paginatedList: PageBasedPaginatedList<Playlist>(
getItemsFunc: (page, maxResults) => service
.search(_.queryController.value.text,
page: page, sortBy: _.sortBy, type: SearchType.playlist)
.then((value) => value.playlists),
maxResults: searchPageSize,
),
canDeleteVideos: false),
)
][_.selectedIndex],
)),
FractionallySizedBox(
child: PlaylistList(
paginatedList: PageBasedPaginatedList<Playlist>(
getItemsFunc: (page, maxResults) => service
.search(_.queryController.value.text,
page: page, sortBy: _.sortBy, type: SearchType.playlist)
.then((value) => value.playlists),
maxResults: searchPageSize,
),
canDeleteVideos: false),
)
][_.selectedIndex],
),
),
),
],
Expand Down
26 changes: 26 additions & 0 deletions lib/utils/views/components/navigation_switcher.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';

import '../../../globals.dart';

class NavigationSwitcher extends StatelessWidget {
final Widget child;
const NavigationSwitcher({super.key, required this.child});

@override
Widget build(BuildContext context) {
return AnimatedSwitcher(
switchInCurve: Curves.easeInOutQuad,
switchOutCurve: Curves.easeInOutQuad,
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(
scale: Tween<double>(begin: 0.95, end: 1).animate(animation),
child: FadeTransition(
opacity: Tween<double>(begin: 0.0, end: 1).animate(animation),
child: child),
);
},
duration: animationDuration ,
child: child,
);
}
}
Loading

0 comments on commit 8495112

Please sign in to comment.