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

add option to mute Videos by default and remember muting in feed. #553

Merged
merged 2 commits into from
Feb 25, 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
3 changes: 2 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/next.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
* Fixed group deletion not updating the UI (#591)
* Added support for opening redirect links from emails (#257)
* Added pull-to-refresh and scroll-to-top on profiles (#589)
* Added support for sharing images (#556 - thanks to @ramosmauricio!)
* Added support for sharing images (#556 - thanks @ramosmauricio!)
* Added support for muting media by default (#553 - thanks @johann-gambol!)
1 change: 1 addition & 0 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const optionHomePages = 'home.pages';
const optionHomeInitialTab = 'home.initial_tab';

const optionMediaSize = 'media.size';
const optionMediaDefaultMute = 'media.mute';

const optionDownloadType = 'download.type';
const optionDownloadPath = 'download.path';
Expand Down
10 changes: 8 additions & 2 deletions lib/group/_feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:fritter/database/repository.dart';
import 'package:fritter/generated/l10n.dart';
import 'package:fritter/group/group_screen.dart';
import 'package:fritter/profile/profile.dart';
import 'package:fritter/tweet/_video.dart';
import 'package:fritter/tweet/conversation.dart';
import 'package:fritter/ui/errors.dart';
import 'package:fritter/utils/iterables.dart';
Expand Down Expand Up @@ -226,12 +227,17 @@ class _SubscriptionGroupFeedState extends State<SubscriptionGroupFeed> {
);
}

var prefs = PrefService.of(context, listen: false);

return RefreshIndicator(
onRefresh: () async {
_pagingController.refresh();
},
child: ChangeNotifierProvider<TweetContextState>(
create: (context) => TweetContextState(PrefService.of(context, listen: false).get(optionTweetsHideSensitive)),
child: MultiProvider(
providers: [
ChangeNotifierProvider<TweetContextState>(create: (_) => TweetContextState(prefs.get(optionTweetsHideSensitive))),
ChangeNotifierProvider<VideoContextState>(create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))),
],
child: PagedListView<String?, TweetChain>(
scrollController: widget.scrollController,
pagingController: _pagingController,
Expand Down
10 changes: 8 additions & 2 deletions lib/home/_saved.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:fritter/generated/l10n.dart';
import 'package:fritter/home/home_screen.dart';
import 'package:fritter/profile/profile.dart';
import 'package:fritter/saved/saved_tweet_model.dart';
import 'package:fritter/tweet/_video.dart';
import 'package:fritter/tweet/tweet.dart';
import 'package:fritter/ui/errors.dart';
import 'package:pref/pref.dart';
Expand Down Expand Up @@ -41,6 +42,8 @@ class _SavedScreenState extends State<SavedScreen> with AutomaticKeepAliveClient
Widget build(BuildContext context) {
var model = context.read<SavedTweetModel>();

var prefs = PrefService.of(context, listen: false);

return NestedScrollView(
controller: widget.scrollController,
headerSliverBuilder: (context, innerBoxIsScrolled) {
Expand All @@ -54,8 +57,11 @@ class _SavedScreenState extends State<SavedScreen> with AutomaticKeepAliveClient
)
];
},
body: ChangeNotifierProvider<TweetContextState>(
create: (context) => TweetContextState(PrefService.of(context, listen: false).get(optionTweetsHideSensitive)),
body: MultiProvider(
providers: [
ChangeNotifierProvider<TweetContextState>(create: (_) => TweetContextState(prefs.get(optionTweetsHideSensitive))),
ChangeNotifierProvider<VideoContextState>(create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))),
],
child: ScopedBuilder<SavedTweetModel, Object, List<SavedTweet>>.transition(
store: model,
onError: (_, e) => FullPageErrorWidget(
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ Future<void> main() async {
optionHomePages: defaultHomePages.map((e) => e.id).toList(),
optionLocale: optionLocaleDefault,
optionMediaSize: 'medium',
optionMediaDefaultMute: true,
optionNonConfirmationBiasMode: false,
optionShouldCheckForUpdates: true,
optionSubscriptionGroupsOrderByAscending: false,
Expand Down
9 changes: 7 additions & 2 deletions lib/profile/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:fritter/profile/_follows.dart';
import 'package:fritter/profile/_tweets.dart';
import 'package:fritter/profile/profile_model.dart';
import 'package:fritter/search/search.dart';
import 'package:fritter/tweet/_video.dart';
import 'package:fritter/ui/errors.dart';
import 'package:fritter/ui/physics.dart';
import 'package:fritter/user.dart';
Expand Down Expand Up @@ -238,6 +239,7 @@ class _ProfileScreenBodyState extends State<ProfileScreenBody> with TickerProvid
var appBarHeight = profileStuffTop + avatarHeight + metadataHeight + 8 + descriptionHeight;

var metadataTextStyle = const TextStyle(fontSize: 12.5);
var prefs = PrefService.of(context, listen: false);

return Scaffold(
body: Stack(children: [
Expand Down Expand Up @@ -481,8 +483,11 @@ class _ProfileScreenBodyState extends State<ProfileScreenBody> with TickerProvid
)))
];
},
body: ChangeNotifierProvider<TweetContextState>(
create: (context) => TweetContextState(PrefService.of(context, listen: false).get(optionTweetsHideSensitive)),
body: MultiProvider(
providers: [
ChangeNotifierProvider<TweetContextState>(create: (_) => TweetContextState(prefs.get(optionTweetsHideSensitive))),
ChangeNotifierProvider<VideoContextState>(create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))),
],
child: TabBarView(
controller: _tabController,
physics: const LessSensitiveScrollPhysics(),
Expand Down
10 changes: 8 additions & 2 deletions lib/search/search.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:fritter/generated/l10n.dart';
import 'package:fritter/profile/profile.dart';
import 'package:fritter/search/search_model.dart';
import 'package:fritter/subscriptions/users_model.dart';
import 'package:fritter/tweet/_video.dart';
import 'package:fritter/tweet/tweet.dart';
import 'package:fritter/ui/errors.dart';
import 'package:fritter/user.dart';
Expand Down Expand Up @@ -75,6 +76,8 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
Widget build(BuildContext context) {
var subscriptionsModel = context.read<SubscriptionsModel>();

var prefs = PrefService.of(context, listen: false);

var defaultTheme = Theme.of(context);
var searchTheme = defaultTheme.copyWith(
appBarTheme: AppBarTheme(
Expand Down Expand Up @@ -133,8 +136,11 @@ class _SearchScreenState extends State<_SearchScreen> with SingleTickerProviderS
Tab(icon: Icon(Icons.comment)),
]),
),
ChangeNotifierProvider<TweetContextState>(
create: (context) => TweetContextState(PrefService.of(context, listen: false).get(optionTweetsHideSensitive)),
MultiProvider(
providers: [
ChangeNotifierProvider<TweetContextState>(create: (_) => TweetContextState(prefs.get(optionTweetsHideSensitive))),
ChangeNotifierProvider<VideoContextState>(create: (_) => VideoContextState(prefs.get(optionMediaDefaultMute))),
],
child: Expanded(
child: TabBarView(controller: _tabController, children: [
TweetSearchResultList<SearchUsersModel, UserWithExtra>(
Expand Down
6 changes: 6 additions & 0 deletions lib/settings/_general.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ class SettingsGeneralFragment extends StatelessWidget {
child: Text(L10n.of(context).large),
),
]),
/// TODO: translate
PrefSwitch(
pref: optionMediaDefaultMute,
title: Text('Mute videos'),
subtitle: Text('"Whether all videos should be muted by default"'),
),
PrefCheckbox(
title: Text(L10n.of(context).hide_sensitive_tweets),
subtitle: Text(L10n.of(context).whether_to_hide_tweets_marked_as_sensitive),
Expand Down
27 changes: 27 additions & 0 deletions lib/tweet/_video.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:fritter/tweet/_video_controls.dart';
import 'package:fritter/utils/downloads.dart';
import 'package:fritter/utils/iterables.dart';
import 'package:path/path.dart' as path;
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';
import 'package:visibility_detector/visibility_detector.dart';
import 'package:wakelock/wakelock.dart';
Expand Down Expand Up @@ -71,6 +72,14 @@ class _TweetVideoState extends State<TweetVideo> {

_videoController = VideoPlayerController.network(streamUrl!);

var model = context.read<VideoContextState>();
var volume = model.isMuted ? 0.0 : _videoController!.value.volume;
_videoController!.setVolume(volume);

_videoController!.addListener(() {
model.setIsMuted(_videoController!.value!.volume);
});

_chewieController = ChewieController(
aspectRatio: widget.metadata.aspectRatio,
autoInitialize: true,
Expand Down Expand Up @@ -218,3 +227,21 @@ class _VideoState extends State<_Video> {
);
}
}

class VideoContextState extends ChangeNotifier{

bool isMuted;

VideoContextState(this.isMuted);

void setIsMuted(double volume){

if(isMuted && volume > 0 || !isMuted && volume == 0){
isMuted = !isMuted;
}

}

}