Skip to content

Commit

Permalink
Implement a fist chunk of manual test data in debug mode.
Browse files Browse the repository at this point in the history
Related to #5
  • Loading branch information
hjtappe committed Dec 2, 2024
1 parent bc6b56f commit b57698e
Show file tree
Hide file tree
Showing 19 changed files with 365 additions and 73 deletions.
5 changes: 3 additions & 2 deletions lib/components/event_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ class EventListTile extends StatelessWidget {
FavoritesProvider favProvider =
Provider.of<FavoritesProvider>(context, listen: true);
bool isFavorite = favProvider.isInFavorites(item.name);
String imageUrl = item.imageUrl ?? '';
return ListTile(
leading: item.imageUrl!.startsWith("http") ?
leading: imageUrl.startsWith("http") ?
SizedBox(
width: 100.0, // Diameter of CircleAvatar
height: 100.0,
child: CachedNetworkImage(
imageUrl: item.imageUrl ?? '',
imageUrl: imageUrl,
placeholder: (context, url) =>
FittedBox(
child: CircularProgressIndicator(),
Expand Down
8 changes: 4 additions & 4 deletions lib/controls/nav_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class NavBar extends StatefulWidget {
static final List<Widget> _widgetOptions = <Widget>[
const HomePage(), // 0
const EventsPage(), // 1
const TracksPage(), // 2
const SpeakersPage(), // 3
const RoomsPage(), // 4
const PreferencesPage(), // 5
TracksPage(), // 2
SpeakersPage(), // 3
RoomsPage(), // 4
PreferencesPage(), // 5
const TravelPage(), // 6
const AboutPage(), // 7
];
Expand Down
23 changes: 23 additions & 0 deletions lib/data/appProviders/preferences_provider.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart' show SharedPreferences;

Expand Down Expand Up @@ -68,6 +69,28 @@ class PreferencesProvider {
await prefs.setBool(_calendarColorByRoomKey, value);
}

// ---------------------------------------------------------
static const String _useTestDataKey = 'useTestData';
static final ValueNotifier<bool> useTestDataNotifier = ValueNotifier(false);

static Future<void> loadUseTestData() async {
bool value = false;
if (kDebugMode) {
final prefs = await SharedPreferences.getInstance();
value = prefs.getBool(_useTestDataKey) ?? false; // Default
}
useTestDataNotifier.value = value;
}

static Future<void> setUseTestData(bool value) async {
if (kDebugMode) {
useTestDataNotifier.value = value;
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(_useTestDataKey, value);
} else {
useTestDataNotifier.value = false;
}
}
// ---------------------------------------------------------
static const String _isDayViewKey = 'isDayView';

Expand Down
23 changes: 15 additions & 8 deletions lib/data/dataProviders/events_provider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/model/event_data.dart';
import 'package:iccm_eu_app/data/testData/test_data.dart';
import 'package:iccm_eu_app/utils/debug.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand All @@ -27,16 +29,21 @@ class EventsProvider with ChangeNotifier {
}

void updateCache() {
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getEventData();
if (data != null && data.isNotEmpty) {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(EventData.fromItemData(itemData));
for (EventData item in TestData.getEvents()) {
_cacheAdd(item);
}
} else { // Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getEventData();
if (data != null && data.isNotEmpty) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(EventData.fromItemData(itemData));
}
}
_commit();
}
notifyListeners();
_commit();
}

Future<void> _loadCache() async {
Expand Down
49 changes: 25 additions & 24 deletions lib/data/dataProviders/gsheets_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'dart:convert';
import 'dart:core';

import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
import 'package:crypto/crypto.dart';
import 'package:flutter/material.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/events_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/home_provider.dart';
Expand Down Expand Up @@ -172,33 +172,34 @@ class GsheetsProvider with ChangeNotifier {
return;
}

List<String> workSheetTitles = [];
workSheetTitles.add(EventsProvider.worksheetTitle);
workSheetTitles.add(RoomsProvider.worksheetTitle);
workSheetTitles.add(SpeakersProvider.worksheetTitle);
workSheetTitles.add(TracksProvider.worksheetTitle);
workSheetTitles.add(HomeProvider.worksheetTitle);
workSheetTitles.add(TravelProvider.worksheetTitle);
workSheetTitles.add(TravelDetailsProvider.worksheetTitle);
if (!kDebugMode || !PreferencesProvider.useTestDataNotifier.value) {
List<String> workSheetTitles = [];
workSheetTitles.add(EventsProvider.worksheetTitle);
workSheetTitles.add(RoomsProvider.worksheetTitle);
workSheetTitles.add(SpeakersProvider.worksheetTitle);
workSheetTitles.add(TracksProvider.worksheetTitle);
workSheetTitles.add(HomeProvider.worksheetTitle);
workSheetTitles.add(TravelProvider.worksheetTitle);
workSheetTitles.add(TravelDetailsProvider.worksheetTitle);

await _readWorksheets(
worksheetTitles: workSheetTitles,
errorProvider: errorProvider);
await _readWorksheets(
worksheetTitles: workSheetTitles,
errorProvider: errorProvider);

// Terminate if data is empty
if (_countDataObjects(_rawData) == 0) {
_isFetchingData = false;
Debug.msg("Fetch: Not data found.");
return;
}

String cachedChecksum = await PreferencesProvider.cachedChecksum;
String dataChecksum = _generateChecksum(_rawData);
// Terminate if data is empty
if (_countDataObjects(_rawData) == 0) {
_isFetchingData = false;
Debug.msg("Fetch: Not data found.");
return;
}

if (cachedChecksum != dataChecksum || force) {
await PreferencesProvider.setCachedChecksum(dataChecksum);
await PreferencesProvider.setLastUpdated(now);
String cachedChecksum = await PreferencesProvider.cachedChecksum;
String dataChecksum = _generateChecksum(_rawData);

if (cachedChecksum != dataChecksum || force) {
await PreferencesProvider.setCachedChecksum(dataChecksum);
await PreferencesProvider.setLastUpdated(now);
}
}
notifyListeners();
Debug.msg("Fetch completed successfully.");
Expand Down
24 changes: 16 additions & 8 deletions lib/data/dataProviders/rooms_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/definitions/item_colors_dictionary.dart';
import 'package:iccm_eu_app/data/model/room_data.dart';
import 'package:iccm_eu_app/data/testData/test_data.dart';
import 'package:iccm_eu_app/utils/debug.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand All @@ -29,16 +31,22 @@ class RoomsProvider with ChangeNotifier {
}

void updateCache() {
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getRoomData();
if (data != null && data.isNotEmpty) {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(RoomData.fromItemData(itemData));
for (RoomData item in TestData.rooms) {
_cacheAdd(item);
}
} else {
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getRoomData();
if (data != null && data.isNotEmpty) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(RoomData.fromItemData(itemData));
}
}
_commit();
}
notifyListeners();
_commit();
}

Future<void> _loadCache() async {
Expand Down
24 changes: 16 additions & 8 deletions lib/data/dataProviders/speakers_provider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/model/speaker_data.dart';
import 'package:iccm_eu_app/data/testData/test_data.dart';
import 'package:iccm_eu_app/utils/debug.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand All @@ -27,16 +29,22 @@ class SpeakersProvider with ChangeNotifier {
}

void updateCache() {
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getSpeakerData();
if (data != null && data.isNotEmpty) {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(SpeakerData.fromItemData(itemData));
for (SpeakerData item in TestData.speakers) {
_cacheAdd(item);
}
} else {
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getSpeakerData();
if (data != null && data.isNotEmpty) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(SpeakerData.fromItemData(itemData));
}
}
_commit();
}
notifyListeners();
_commit();
}

Future<void> _loadCache() async {
Expand Down
25 changes: 18 additions & 7 deletions lib/data/dataProviders/tracks_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:iccm_eu_app/data/appProviders/preferences_provider.dart';
import 'package:iccm_eu_app/data/dataProviders/gsheets_provider.dart';
import 'package:iccm_eu_app/data/definitions/item_colors_dictionary.dart';
import 'package:iccm_eu_app/data/model/track_data.dart';
import 'package:iccm_eu_app/data/testData/test_data.dart';
import 'package:iccm_eu_app/utils/debug.dart';
import 'package:shared_preferences/shared_preferences.dart';

Expand Down Expand Up @@ -31,15 +33,24 @@ class TracksProvider with ChangeNotifier {
}

void updateCache() {
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getTrackData();
if (data != null && data.isNotEmpty) {
if (kDebugMode && PreferencesProvider.useTestDataNotifier.value) {
Debug.msg("Updating TrackData cache from TestData ($kDebugMode, ${PreferencesProvider.useTestDataNotifier.value}).");
_cacheClear();
for (final itemData in data) {
_cacheAdd(TrackData.fromItemData(itemData));
for (TrackData item in TestData.tracks) {
_cacheAdd(item);
}
} else {
Debug.msg("Updating TrackData cache from GSheets ($kDebugMode, ${PreferencesProvider.useTestDataNotifier.value}).");
// Process raw data from GsheetsProvider and update _tracks
var data = _gsheetsProvider.getTrackData();
if (data != null && data.isNotEmpty) {
_cacheClear();
for (final itemData in data) {
_cacheAdd(TrackData.fromItemData(itemData));
}
}
_commit();
}
_commit();
}

Future<void> _loadCache() async {
Expand Down
1 change: 0 additions & 1 deletion lib/data/dataProviders/travel_details_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ class TravelDetailsProvider with ChangeNotifier {
_cache.sort((a, b) => a.name.compareTo(b.name));
_saveCache();
_populateItemsFromCache();
Debug.msg("Found ${_items.length} travel elements");
notifyListeners();
}

Expand Down
7 changes: 7 additions & 0 deletions lib/data/model/room_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class RoomData extends ModelItem {
final String details;
late ColorsData? colors;

RoomData({
required this.imageUrl,
required this.name,
required this.details,
this.colors,
});

RoomData._({
required this.imageUrl,
required this.name,
Expand Down
6 changes: 6 additions & 0 deletions lib/data/model/speaker_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ class SpeakerData extends ModelItem {
@override
final String details;

SpeakerData({
required this.imageUrl,
required this.name,
required this.details,
});

SpeakerData._({
required this.imageUrl,
required this.name,
Expand Down
7 changes: 7 additions & 0 deletions lib/data/model/track_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ class TrackData extends ModelItem {
final String details;
late ColorsData? colors;

TrackData({
required this.imageUrl,
required this.name,
required this.details,
this.colors,
});

TrackData._({
required this.imageUrl,
required this.name,
Expand Down
Loading

0 comments on commit b57698e

Please sign in to comment.