Skip to content

Commit

Permalink
openglass restored
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Aug 6, 2024
1 parent bbd4050 commit 6e422b6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 12 deletions.
17 changes: 16 additions & 1 deletion app/lib/backend/http/api/memories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:friend_private/backend/database/geolocation.dart';
import 'package:friend_private/backend/database/memory.dart';
import 'package:friend_private/backend/database/transcript_segment.dart';
import 'package:friend_private/backend/http/shared.dart';
import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/env/env.dart';
import 'package:instabug_flutter/instabug_flutter.dart';
Expand Down Expand Up @@ -114,3 +114,18 @@ Future<ServerMemory?> getMemoryById(String memoryId) async {
}
return null;
}

Future<List<MemoryPhoto>> getMemoryPhotos(String memoryId) async {
var response = await makeApiCall(
url: '${Env.apiBaseUrl}v1/memories/$memoryId/photos',
headers: {},
method: 'GET',
body: '',
);
if (response == null) return [];
debugPrint('getMemoryPhotos: ${response.body}');
if (response.statusCode == 200) {
return (jsonDecode(response.body) as List<dynamic>).map((photo) => MemoryPhoto.fromJson(photo)).toList();
}
return [];
}
4 changes: 2 additions & 2 deletions app/lib/pages/capture/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ class CapturePageState extends State<CapturePage>
finishedAt: currentTranscriptFinishedAt,
failed: true,
source: segments.isNotEmpty ? MemorySource.friend : MemorySource.openglass,
language: SharedPreferencesUtil().recordingsLanguage,
language: segments.isNotEmpty ? SharedPreferencesUtil().recordingsLanguage : null,
);
SharedPreferencesUtil().addFailedMemory(memory);
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
Expand Down Expand Up @@ -254,7 +254,7 @@ class CapturePageState extends State<CapturePage>
}

processCachedTranscript() async {
// only applies to friend, not openglass
// TODO: only applies to friend, not openglass, fix it
debugPrint('_processCachedTranscript');
var segments = SharedPreferencesUtil().transcriptSegments;
if (segments.isEmpty) return;
Expand Down
6 changes: 5 additions & 1 deletion app/lib/pages/memories/widgets/memory_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ class _MemoryListItemState extends State<MemoryListItem> {
child: Text(
widget.memory.discarded
? 'Discarded'
: widget.memory.source?.toString() ?? widget.memory.structured.category,
: widget.memory.source == MemorySource.openglass
? 'Openglass'
: widget.memory.source == MemorySource.screenpipe
? 'Screenpipe'
: widget.memory.structured.category,
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
color: widget.memory.source == MemorySource.screenpipe ? Colors.deepPurple : Colors.white,
),
Expand Down
13 changes: 11 additions & 2 deletions app/lib/pages/memory_detail/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:friend_private/backend/database/memory.dart';
import 'package:friend_private/backend/database/transcript_segment.dart';
import 'package:friend_private/backend/http/api/memories.dart';
import 'package:friend_private/backend/preferences.dart';
import 'package:friend_private/backend/schema/memory.dart';
import 'package:friend_private/pages/memory_detail/share.dart';
Expand Down Expand Up @@ -41,6 +42,8 @@ class _MemoryDetailPageState extends State<MemoryDetailPage> with TickerProvider

bool canDisplaySeconds = true;

List<MemoryPhoto> photos = [];

@override
void initState() {
canDisplaySeconds = TranscriptSegment.canDisplaySeconds(widget.memory.transcriptSegments);
Expand All @@ -50,6 +53,12 @@ class _MemoryDetailPageState extends State<MemoryDetailPage> with TickerProvider
pluginResponseExpanded = List.filled(widget.memory.pluginsResults.length, false);
_controller = TabController(length: 2, vsync: this, initialIndex: 1);
_controller!.addListener(() => setState(() {}));
if (widget.memory.source == MemorySource.openglass) {
getMemoryPhotos(widget.memory.id).then((value) {
photos = value;
setState(() {});
});
}
super.initState();
}

Expand Down Expand Up @@ -208,9 +217,9 @@ class _MemoryDetailPageState extends State<MemoryDetailPage> with TickerProvider
}

List<Widget> _getImagesWidget() {
var photos = widget.memory.photos.map((e) => Tuple2(e.base64, e.description)).toList();
var photosData = photos.map((e) => Tuple2(e.base64, e.description)).toList();
print('Images length ${photos.length}');
return [PhotosGridComponent(photos: photos), const SizedBox(height: 32)];
return [PhotosGridComponent(photos: photosData), const SizedBox(height: 32)];
}

_reProcessMemory(
Expand Down
6 changes: 5 additions & 1 deletion app/lib/pages/memory_detail/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ List<Widget> getSummaryWidgets(
),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
child: Text(
memory.discarded ? 'Discarded' : memory.source?.toString() ?? memory.structured.category,
memory.discarded
? 'Discarded'
: memory.source == MemorySource.screenpipe
? 'screenpipe'
: memory.structured.category,
style: Theme.of(context).textTheme.titleLarge!.copyWith(
color: memory.source == MemorySource.screenpipe ? Colors.deepPurple : Colors.white,
),
Expand Down
8 changes: 6 additions & 2 deletions backend/database/memories.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import uuid
from typing import List

from google.cloud import firestore
Expand Down Expand Up @@ -88,8 +89,11 @@ def store_memory_photos(uid: str, memory_id: str, photos: List[MemoryPhoto]):
photos_ref = memory_ref.collection('photos')
batch = db.batch()
for photo in photos:
photo_ref = photos_ref.document(photo.id)
batch.set(photo_ref, photo.dict())
photo_id = str(uuid.uuid4())
photo_ref = photos_ref.document(str(uuid.uuid4()))
data = photo.dict()
data['id'] = photo_id
batch.set(photo_ref, data)
batch.commit()


Expand Down
2 changes: 0 additions & 2 deletions backend/models/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ class Geolocation(BaseModel):
google_place_id: Optional[str] = None
latitude: float
longitude: float
altitude: Optional[float] = None
accuracy: Optional[float] = None
address: Optional[str] = None
location_type: Optional[str] = None

Expand Down
4 changes: 3 additions & 1 deletion backend/routers/memories.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def create_memory(

if not language_code: # not breaking change
language_code = create_memory.language
else:
create_memory.language = language_code

memory = _process_memory(uid, language_code, create_memory)
if not trigger_integrations:
Expand All @@ -102,7 +104,7 @@ def reprocess_memory(
if memory is None:
raise HTTPException(status_code=404, detail="Memory not found")
memory = Memory(**memory)
if not language_code:
if not language_code: # not breaking change
language_code = memory.language or 'en'

return _process_memory(uid, language_code, memory, force_process=True)
Expand Down

0 comments on commit 6e422b6

Please sign in to comment.