Skip to content

Commit

Permalink
Make Student Card Picture hideable on Home (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobkoerber authored Dec 10, 2024
1 parent 4e6cbe2 commit 8879717
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 113 deletions.
3 changes: 2 additions & 1 deletion assets/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,6 @@
"suggested": "Interessante {}",
"more": "Mehr",
"visibility": "Sichtbarkeit",
"utilizationAt": "Auslastung bei {}%"
"utilizationAt": "Auslastung bei {}%",
"showStudentCardPicture": "Student Card Bild zeigen"
}
3 changes: 2 additions & 1 deletion assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,6 @@
"suggested": "Suggested {}",
"more": "More",
"visibility": "Visibility",
"utilizationAt": "Utilization at {}%"
"utilizationAt": "Utilization at {}%",
"showStudentCardPicture": "Show Student Card Picture"
}
49 changes: 25 additions & 24 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ PODS:
- Firebase/RemoteConfig (11.4.0):
- Firebase/CoreOnly
- FirebaseRemoteConfig (~> 11.4.0)
- firebase_core (3.8.0):
- firebase_core (3.8.1):
- Firebase/CoreOnly (= 11.4.0)
- Flutter
- firebase_crashlytics (4.1.5):
- firebase_crashlytics (4.2.0):
- Firebase/Crashlytics (= 11.4.0)
- firebase_core
- Flutter
- firebase_remote_config (5.1.5):
- firebase_remote_config (5.2.0):
- Firebase/RemoteConfig (= 11.4.0)
- firebase_core
- Flutter
Expand All @@ -28,7 +28,7 @@ PODS:
- GoogleUtilities/Logger (~> 8.0)
- FirebaseCoreExtension (11.4.1):
- FirebaseCore (~> 11.0)
- FirebaseCoreInternal (11.5.0):
- FirebaseCoreInternal (11.6.0):
- "GoogleUtilities/NSData+zlib (~> 8.0)"
- FirebaseCrashlytics (11.4.0):
- FirebaseCore (~> 11.4)
Expand All @@ -52,7 +52,7 @@ PODS:
- FirebaseSharedSwift (~> 11.0)
- GoogleUtilities/Environment (~> 8.0)
- "GoogleUtilities/NSData+zlib (~> 8.0)"
- FirebaseRemoteConfigInterop (11.5.0)
- FirebaseRemoteConfigInterop (11.6.0)
- FirebaseSessions (11.4.0):
- FirebaseCore (~> 11.4)
- FirebaseCoreExtension (~> 11.4)
Expand All @@ -62,7 +62,7 @@ PODS:
- GoogleUtilities/UserDefaults (~> 8.0)
- nanopb (~> 3.30910.0)
- PromisesSwift (~> 2.1)
- FirebaseSharedSwift (11.5.0)
- FirebaseSharedSwift (11.6.0)
- Flutter (1.0.0)
- flutter_native_splash (2.4.3):
- Flutter
Expand Down Expand Up @@ -122,20 +122,21 @@ PODS:
- sqflite_darwin (0.0.4):
- Flutter
- FlutterMacOS
- sqlite3 (3.47.0):
- sqlite3/common (= 3.47.0)
- sqlite3/common (3.47.0)
- sqlite3/dbstatvtab (3.47.0):
- sqlite3 (3.47.1):
- sqlite3/common (= 3.47.1)
- sqlite3/common (3.47.1)
- sqlite3/dbstatvtab (3.47.1):
- sqlite3/common
- sqlite3/fts5 (3.47.0):
- sqlite3/fts5 (3.47.1):
- sqlite3/common
- sqlite3/perf-threadsafe (3.47.0):
- sqlite3/perf-threadsafe (3.47.1):
- sqlite3/common
- sqlite3/rtree (3.47.0):
- sqlite3/rtree (3.47.1):
- sqlite3/common
- sqlite3_flutter_libs (0.0.1):
- Flutter
- sqlite3 (~> 3.47.0)
- FlutterMacOS
- sqlite3 (~> 3.47.1)
- sqlite3/dbstatvtab
- sqlite3/fts5
- sqlite3/perf-threadsafe
Expand Down Expand Up @@ -164,7 +165,7 @@ DEPENDENCIES:
- quick_actions_ios (from `.symlinks/plugins/quick_actions_ios/ios`)
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
- sqflite_darwin (from `.symlinks/plugins/sqflite_darwin/darwin`)
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/ios`)
- sqlite3_flutter_libs (from `.symlinks/plugins/sqlite3_flutter_libs/darwin`)
- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)
- video_player_avfoundation (from `.symlinks/plugins/video_player_avfoundation/darwin`)

Expand Down Expand Up @@ -226,7 +227,7 @@ EXTERNAL SOURCES:
sqflite_darwin:
:path: ".symlinks/plugins/sqflite_darwin/darwin"
sqlite3_flutter_libs:
:path: ".symlinks/plugins/sqlite3_flutter_libs/ios"
:path: ".symlinks/plugins/sqlite3_flutter_libs/darwin"
url_launcher_ios:
:path: ".symlinks/plugins/url_launcher_ios/ios"
video_player_avfoundation:
Expand All @@ -235,19 +236,19 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
device_info_plus: bf2e3232933866d73fe290f2942f2156cdd10342
Firebase: cf1b19f21410b029b6786a54e9764a0cacad3c99
firebase_core: 9efc3ecf689cdbc90f13f4dc58108c83ea46b266
firebase_crashlytics: 72a8b504422ba8bb435a7a0c0a9341320cbcbe29
firebase_remote_config: 96a9b7e79624c5d9d16befdef60791966bb83919
firebase_core: 418aed674e9a0b8b6088aec16cde82a811f6261f
firebase_crashlytics: 757e252772ed3dd37c07638f9fcd4dceb5f101c8
firebase_remote_config: 015a36be218a38943c2273d63b33bc983b3d7bb6
FirebaseABTesting: aef1719704fade00b200827e7973f352efc4caee
FirebaseCore: e0510f1523bc0eb21653cac00792e1e2bd6f1771
FirebaseCoreExtension: f1bc67a4702931a7caa097d8e4ac0a1b0d16720e
FirebaseCoreInternal: f47dd28ae7782e6a4738aad3106071a8fe0af604
FirebaseCoreInternal: d98ab91e2d80a56d7b246856a8885443b302c0c2
FirebaseCrashlytics: 41bbdd2b514a8523cede0c217aee6ef7ecf38401
FirebaseInstallations: 6ef4a1c7eb2a61ee1f74727d7f6ce2e72acf1414
FirebaseRemoteConfig: 7655681d02417bc9b287338edb9d721ff79e1a4a
FirebaseRemoteConfigInterop: 7a7aebb9342d53913a5c890efa88e289d9e5c1bc
FirebaseRemoteConfigInterop: e75e348953352a000331eb77caf01e424248e176
FirebaseSessions: 3f56f177d9e53a85021d16b31f9a111849d1dd8b
FirebaseSharedSwift: 302ac5967857ad7e7388b15382d705b8c8d892aa
FirebaseSharedSwift: a4e5dfca3e210633bb3a3dfb94176c019211948b
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_native_splash: e8a1e01082d97a8099d973f919f57904c925008a
flutter_secure_storage: d33dac7ae2ea08509be337e775f6b59f1ff45f12
Expand All @@ -268,8 +269,8 @@ SPEC CHECKSUMS:
quick_actions_ios: 56f3cbaa71e94f212838d1f9fe354bd0734779bf
shared_preferences_foundation: fcdcbc04712aee1108ac7fda236f363274528f78
sqflite_darwin: 5a7236e3b501866c1c9befc6771dfd73ffb8702d
sqlite3: 0aa20658a9b238a3b1ff7175eb7bdd863b0ab4fd
sqlite3_flutter_libs: b55ef23cfafea5318ae5081e0bf3fbbce8417c94
sqlite3: 1e522f0938463e44b7faf50393b40bdc1e1e456d
sqlite3_flutter_libs: 1b4e98da20ebd4e9b1240269b78cdcf492dbe9f3
url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe
video_player_avfoundation: 7c6c11d8470e1675df7397027218274b6d2360b3

Expand Down
1 change: 1 addition & 0 deletions lib/base/enums/user_preference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum UserPreference {
theme(int),
calendarColors(String),
browser(bool),
studentCardPicture(bool),
failedGrades(bool),
weekends(bool),
hiddenCalendarEntries(bool),
Expand Down
19 changes: 11 additions & 8 deletions lib/homeComponent/view/contactCard/contact_card_loading_view.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:campus_flutter/base/enums/device.dart';
import 'package:campus_flutter/base/services/device_type_service.dart';
import 'package:campus_flutter/base/util/placeholder_text.dart';
import 'package:campus_flutter/base/util/shimmer_view.dart';
import 'package:campus_flutter/homeComponent/view/contactCard/contact_card_view.dart';
Expand All @@ -20,15 +22,16 @@ class ContactCardLoadingView extends StatelessWidget {
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShimmerView(
child: PlaceholderText(
text: "StudentCard".toUpperCase(),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey,
fontWeight: FontWeight.w700,
),
if (DeviceService.getType(context) == Device.phone)
ShimmerView(
child: PlaceholderText(
text: "StudentCard".toUpperCase(),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey,
fontWeight: FontWeight.w700,
),
),
),
),
ShimmerView(
child: PlaceholderText(
text: "Max Mustermann",
Expand Down
63 changes: 37 additions & 26 deletions lib/homeComponent/view/contactCard/contact_card_view.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:campus_flutter/base/enums/device.dart';
import 'package:campus_flutter/base/extensions/base_64_decode_image_data.dart';
import 'package:campus_flutter/base/services/device_type_service.dart';
import 'package:campus_flutter/base/util/delayed_loading_indicator.dart';
import 'package:campus_flutter/homeComponent/view/contactCard/contact_card_loading_view.dart';
import 'package:campus_flutter/navigation_service.dart';
import 'package:campus_flutter/personComponent/model/personDetails/person_details.dart';
import 'package:campus_flutter/personComponent/model/profile/profile.dart';
import 'package:campus_flutter/personComponent/viewModel/person_details_viewmodel.dart';
import 'package:campus_flutter/studentCardComponent/model/student_card.dart';
import 'package:campus_flutter/settingsComponent/views/settings_view.dart';
import 'package:campus_flutter/studentCardComponent/viewModel/student_card_viewmodel.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -60,20 +62,21 @@ class _ContactCardViewState extends ConsumerState<ContactCardView> {
padding: const EdgeInsets.all(10.0),
child: Row(
children: [
profilePicture(),
profilePicture(data),
const Padding(padding: EdgeInsets.only(left: 15)),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"StudentCard".toUpperCase(),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey,
fontWeight: FontWeight.w700,
),
),
if (DeviceService.getType(context) == Device.phone)
Text(
"StudentCard".toUpperCase(),
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey,
fontWeight: FontWeight.w700,
),
),
Text(
data?.fullName ?? profile.fullName,
style: Theme.of(context).textTheme.headlineSmall,
Expand All @@ -95,27 +98,35 @@ class _ContactCardViewState extends ConsumerState<ContactCardView> {
);
}

Widget profilePicture() {
return StreamBuilder(
stream: ref.watch(studentCardViewModel).studentCard,
builder: (context, snapshot) {
if (snapshot.hasData || snapshot.hasError) {
return CircleAvatar(
backgroundImage: imageData(snapshot),
backgroundColor: Theme.of(context).cardTheme.color,
radius: contactImageSize / 2,
);
} else {
return SizedBox(height: contactImageSize, width: contactImageSize);
}
},
Widget profilePicture(PersonDetails? data) {
if (ref.read(showStudentCardPicture)) {
return StreamBuilder(
stream: ref.watch(studentCardViewModel).studentCard,
builder: (context, snapshot) {
if (snapshot.hasData || snapshot.hasError) {
return image(snapshot.data?.firstOrNull?.image);
} else {
return SizedBox(height: contactImageSize, width: contactImageSize);
}
},
);
} else {
return image(data?.imageData);
}
}

Widget image(String? imageData) {
return CircleAvatar(
backgroundImage: provideImage(imageData),
backgroundColor: Theme.of(context).cardTheme.color,
radius: contactImageSize / 2,
);
}

ImageProvider<Object> imageData(AsyncSnapshot<List<StudentCard>?> snapshot) {
if (snapshot.hasData && snapshot.data!.isNotEmpty) {
ImageProvider<Object> provideImage(String? imageData) {
if (imageData != null) {
return Image.memory(
base64DecodeImageData(snapshot.data!.first.image),
base64DecodeImageData(imageData),
).image;
} else {
return const AssetImage(
Expand Down
5 changes: 2 additions & 3 deletions lib/personComponent/model/personDetails/person_details.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import 'package:campus_flutter/base/enums/gender.dart';
import 'package:campus_flutter/personComponent/model/personDetails/contact_info.dart';
import 'package:campus_flutter/personComponent/model/personDetails/organisation.dart';
import 'package:campus_flutter/personComponent/model/personDetails/phone_extension.dart';
import 'package:campus_flutter/personComponent/model/personDetails/room.dart';
import 'package:json_annotation/json_annotation.dart';

import '../../../base/enums/gender.dart';
import 'organisation.dart';

part 'person_details.g.dart';

@JsonSerializable()
Expand Down
4 changes: 4 additions & 0 deletions lib/settingsComponent/viewModels/settings_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SettingsViewModel {
Appearance.values[value as int];
case UserPreference.browser:
ref.read(useWebView.notifier).state = value as bool;
case UserPreference.studentCardPicture:
ref.read(showStudentCardPicture.notifier).state = value as bool;
case UserPreference.failedGrades:
ref.read(hideFailedGrades.notifier).state = value as bool;
case UserPreference.weekends:
Expand All @@ -53,6 +55,8 @@ class SettingsViewModel {
value = value.index;
case UserPreference.browser:
ref.read(useWebView.notifier).state = value as bool;
case UserPreference.studentCardPicture:
ref.read(showStudentCardPicture.notifier).state = value as bool;
case UserPreference.failedGrades:
ref.read(hideFailedGrades.notifier).state = value as bool;
case UserPreference.weekends:
Expand Down
22 changes: 22 additions & 0 deletions lib/settingsComponent/views/appearance_settings_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:campus_flutter/base/enums/appearance.dart';
import 'package:campus_flutter/base/enums/user_preference.dart';
import 'package:campus_flutter/base/util/seperated_list.dart';
import 'package:campus_flutter/personComponent/viewModel/profile_viewmodel.dart';
import 'package:campus_flutter/studiesComponent/viewModel/grade_viewmodel.dart';
import 'package:campus_flutter/homeComponent/view/widget/widget_frame_view.dart';
import 'package:campus_flutter/main.dart';
Expand All @@ -22,6 +23,7 @@ class AppearanceSettingsView extends ConsumerWidget {
widgets: [
_appearanceSelection(context, ref),
_useWebView(context, ref),
_showStudentCardPicture(context, ref),
_hideFailedGrades(context, ref),
],
),
Expand Down Expand Up @@ -71,6 +73,26 @@ class AppearanceSettingsView extends ConsumerWidget {
);
}

Widget _showStudentCardPicture(BuildContext context, WidgetRef ref) {
return ListTile(
dense: true,
title: Text(
context.tr("showStudentCardPicture"),
style: Theme.of(context).textTheme.bodyMedium,
),
trailing: Switch(
value: ref.watch(showStudentCardPicture),
onChanged: (value) {
ref.read(settingsViewModel).savePreference(
UserPreference.studentCardPicture,
value,
);
ref.read(profileViewModel).fetch(false);
},
),
);
}

Widget _hideFailedGrades(BuildContext context, WidgetRef ref) {
return ListTile(
dense: true,
Expand Down
1 change: 1 addition & 0 deletions lib/settingsComponent/views/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import 'package:go_router/go_router.dart';
import 'package:package_info_plus/package_info_plus.dart';

final useWebView = StateProvider<bool>((ref) => true);
final showStudentCardPicture = StateProvider<bool>((ref) => true);
final hideFailedGrades = StateProvider<bool>((ref) => false);
final showWeekends = StateProvider<bool>((ref) => false);
final showHiddenCalendarEntries = StateProvider<bool>((ref) => false);
Expand Down
Loading

0 comments on commit 8879717

Please sign in to comment.