Skip to content

Commit

Permalink
feat: auto start ref indexing
Browse files Browse the repository at this point in the history
fix: build for platforms
  • Loading branch information
Sivan22 committed Nov 17, 2024
1 parent 2093b1e commit ca39c32
Show file tree
Hide file tree
Showing 4 changed files with 295 additions and 292 deletions.
35 changes: 32 additions & 3 deletions .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
cache: true
- run: flutter pub get
- run: flutter build apk
- name: Upload apk
Expand All @@ -72,11 +72,40 @@ jobs:
cache: true
- run: flutter build macos
- name: Zip the app bundle
run: cd build/macos/Build/Products/Release && zip -r otzaria-macos.zip ./
run: cd build/macos/Build/Products/Release && zip -r otzaria-macos.zip otzaria.app
- name: Upload macos build
uses: actions/upload-artifact@v4
with:
name: otzaria-macos.zip
path: build/macos/Build/Products/Release/otzaria-macos.zip


build_ios:
runs-on: macos-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
cache: true
- run: flutter pub get
- name: Build iOS
run: |
flutter build ios --release
cd build/ios/iphoneos
mkdir Payload
cp -r Runner.app Payload
zip -r otzaria-ios.ipa Payload
- name: Upload iOS build
uses: actions/upload-artifact@v4
with:
name: otzaria-ios.ipa
path: build/ios/iphoneos/otzaria-ios.ipa
- name: Upload iOS archive
uses: actions/upload-artifact@v4
with:
name: ios-build
path: |
build/ios/archive/Runner.xcarchive
build/ios/iphoneos/
6 changes: 4 additions & 2 deletions lib/data/data_providers/isar_data_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ class IsarDataProvider {
}

Future<int> getNumberOfBooksWithRefs() async {
final allRefs = isar.refs.where().findAll();
final books = allRefs.groupBy((ref) => ref.bookTitle);
final allRefs = await isar.refs.where().findAllAsync();
final books = await Isolate.run(() {
return allRefs.groupBy((ref) => ref.bookTitle);
});
return books.length;
}

Expand Down
150 changes: 44 additions & 106 deletions lib/screens/find_ref_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ class _FindRefScreenState extends State<FindRefScreen>
Future<void> _checkIndexStatus() async {
final booksWithRefs =
await DataRepository.instance.getNumberOfBooksWithRefs();
final totalBooks = (await appModel.library).getAllBooks().length;

// If there's a difference of more than 5 books or if there are no refs at all
if (booksWithRefs == 0 || (totalBooks - booksWithRefs) > 5) {
setState(() {
_needsIndexing = true;
});
if (booksWithRefs == 0) {
appModel.createRefsFromLibrary(0);
}
}

Expand All @@ -52,55 +47,6 @@ class _FindRefScreenState extends State<FindRefScreen>
);
}

Widget _buildIndexingMessage() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'האינדקס ריק או לא מעודכן. יש לעדכן את האינדקס כדי לחפש מקורות.',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 16),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () async {
final result = await showDialog(
context: context,
builder: (context) => AlertDialog(
content: const Text(
'האם ברצונך ליצור אינדקס מקורות? הדבר יאפס את האינדקס הקיים ועלול לקחת זמן ארוך מאד.',
),
actions: <Widget>[
ElevatedButton(
child: const Text('ביטול'),
onPressed: () {
Navigator.pop(context, false);
},
),
ElevatedButton(
child: const Text('אישור'),
onPressed: () {
Navigator.pop(context, true);
},
),
],
),
);
if (result == true) {
appModel.createRefsFromLibrary(0);
setState(() {
_needsIndexing = false;
});
}
},
child: const Text('יצירת אינדקס מקורות'),
),
],
),
);
}

@override
Widget build(BuildContext context) {
super.build(context);
Expand Down Expand Up @@ -146,57 +92,49 @@ class _FindRefScreenState extends State<FindRefScreen>
},
),
Expanded(
child: _needsIndexing
? _buildIndexingMessage()
: FutureBuilder<List<Ref>>(
future: _refs,
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.data!.isEmpty &&
_searchController.text.length >= 3) {
return const Center(
child: Text(
'אין תוצאות',
style: TextStyle(fontSize: 16),
),
);
} else {
return ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(snapshot.data![index].ref),
onTap: () {
final appModel = Provider.of<AppModel>(
context,
listen: false);
if (snapshot.data![index].pdfBook) {
appModel.openBook(
PdfBook(
title: snapshot
.data![index].bookTitle,
path: snapshot
.data![index].pdfPath!),
snapshot.data![index].index);
} else {
appModel.openBook(
TextBook(
title:
snapshot.data![index].bookTitle,
),
snapshot.data![index].index);
}
});
},
);
}
child: FutureBuilder<List<Ref>>(
future: _refs,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.data!.isEmpty &&
_searchController.text.length >= 3) {
return const Center(
child: Text(
'אין תוצאות',
style: TextStyle(fontSize: 16),
),
);
} else {
return ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(snapshot.data![index].ref),
onTap: () {
final appModel =
Provider.of<AppModel>(context, listen: false);
if (snapshot.data![index].pdfBook) {
appModel.openBook(
PdfBook(
title: snapshot.data![index].bookTitle,
path: snapshot.data![index].pdfPath!),
snapshot.data![index].index);
} else {
appModel.openBook(
TextBook(
title: snapshot.data![index].bookTitle,
),
snapshot.data![index].index);
}
});
},
),
);
}
},
),
),
],
),
Expand Down
Loading

0 comments on commit ca39c32

Please sign in to comment.