Skip to content

Commit 78da202

Browse files
Merge branch 'development' into issue1206
2 parents ecabf03 + 4a8e037 commit 78da202

File tree

9 files changed

+152
-98
lines changed

9 files changed

+152
-98
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Badge Magic PR CI
22

33
on:
44
pull_request:
5-
branches: [ "flutter_app" ]
5+
branches: [ "development" ]
66

77
env:
88
ANDROID_EMULATOR_API: 34

.github/workflows/pull_request_closed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: Delete Screenshots
22

33
on:
44
pull_request_target:
5-
branches: [ "flutter_app" ]
5+
branches: [ "development" ]
66
types:
77
- closed
88

.github/workflows/push.yml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ name: Badge Magic Push CI
22

33
on:
44
push:
5-
branches: ["flutter_app"]
5+
branches: ["development"]
66

77
env:
88
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
99
ANDROID_EMULATOR_API: 34
1010
ANDROID_EMULATOR_ARCH: x86_64
1111
IPHONE_DEVICE_MODEL: iPhone 16 Pro Max
1212
IPAD_DEVICE_MODEL: iPad Pro 13-inch (M4)
13+
BARECHECK_GITHUB_APP_TOKEN: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
14+
ENCRYPTED_F10B5E0E5262_IV: ${{ secrets.ENCRYPTED_F10B5E0E5262_IV }}
15+
ENCRYPTED_F10B5E0E5262_KEY: ${{ secrets.ENCRYPTED_F10B5E0E5262_KEY }}
16+
ENCRYPTED_IOS_IV: ${{ secrets.ENCRYPTED_IOS_IV }}
17+
ENCRYPTED_IOS_KEY: ${{ secrets.ENCRYPTED_IOS_KEY }}
18+
STORE_PASS: ${{ secrets.STORE_PASS }}
19+
ALIAS: ${{ secrets.ALIAS }}
20+
KEY_PASS: ${{ secrets.KEY_PASS }}
21+
MATCH_GIT_BASIC_AUTHORIZATION: ${{ secrets.MATCH_GIT_BASIC_AUTHORIZATION }}
22+
MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
1323

1424
jobs:
1525
common:
@@ -23,7 +33,7 @@ jobs:
2333

2434
- name: Common Workflow
2535
uses: ./.github/actions/common
26-
36+
2737
- name: Hydrate and Update Version
2838
id: flutter-version
2939
run: |
@@ -102,14 +112,14 @@ jobs:
102112
name: AAB Generated
103113
path: build/app/outputs/bundle
104114

105-
- name: Upload APK/AAB to apk branch
115+
- name: Upload APK/AAB to app branch
106116
if: ${{ github.repository == 'fossasia/badgemagic-app' }}
107117
run: |
108118
git config --global user.name "github-actions[bot]"
109119
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
110120
111-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
112-
cd apk
121+
git clone --branch=app https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} app
122+
cd app
113123
114124
branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
115125
@@ -134,14 +144,14 @@ jobs:
134144
135145
ls
136146
137-
echo "Pushing to apk branch"
147+
echo "Pushing to app branch"
138148
139149
git checkout --orphan temporary
140150
git add --all .
141151
git commit -am "[Auto] Update APK/AAB's from $branch ($(date +%Y-%m-%d.%H:%M:%S))"
142-
git branch -D apk
143-
git branch -m apk
144-
git push --force origin apk
152+
git branch -D app
153+
git branch -m app
154+
git push --force origin app
145155
146156
- name: Push app in open testing track
147157
if: ${{ github.repository == 'fossasia/badgemagic-app' }}
@@ -220,8 +230,8 @@ jobs:
220230
- name: Create and Upload Assets
221231
run: |
222232
echo "${{ needs.common.outputs.VERSION_CODE }}" > ./versionCode.txt
223-
git clone --branch=apk https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} apk
224-
gh release upload ${{ steps.run-release-drafter.outputs.tag_name }} apk/badge-magic-flutter_app-release.apk ./versionCode.txt --clobber
233+
git clone --branch=app https://${{ github.repository_owner }}:${{ github.token }}@github.com/${{ github.repository }} app
234+
gh release upload ${{ steps.run-release-drafter.outputs.tag_name }} app/badge-magic-development-release.apk ./versionCode.txt --clobber
225235
226236
screenshots-android:
227237
name: Screenshots (Android)

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pluginManagement {
2020
plugins {
2121
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
2222
id "com.android.application" version "8.10.1" apply false
23-
id "org.jetbrains.kotlin.android" version "2.1.21" apply false
23+
id "org.jetbrains.kotlin.android" version "2.2.0" apply false
2424
}
2525

2626
include ":app"

lib/bademagic_module/bluetooth/connect_state.dart

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ class ConnectState extends RetryBleState {
2424
logger.d("Device connected");
2525
toast.showToast('Device connected successfully.');
2626

27-
return WriteState(device: scanResult.device, manager: manager);
27+
final writeState =
28+
WriteState(device: scanResult.device, manager: manager);
29+
final result = await writeState.process();
30+
try {
31+
await scanResult.device.disconnect();
32+
logger.d("Device disconnected after transfer");
33+
await Future.delayed(const Duration(seconds: 1));
34+
logger.d("Waited 1s after disconnect");
35+
} catch (e) {
36+
logger.e("Error during disconnect after transfer: $e");
37+
}
38+
return result;
2839
} else {
2940
throw Exception("Failed to connect to the device");
3041
}
@@ -33,7 +44,14 @@ class ConnectState extends RetryBleState {
3344
rethrow;
3445
} finally {
3546
if (!connected) {
36-
await scanResult.device.disconnect();
47+
try {
48+
await scanResult.device.disconnect();
49+
logger.d("Device disconnected in finally block");
50+
await Future.delayed(const Duration(seconds: 1));
51+
logger.d("Waited 1s after disconnect (finally)");
52+
} catch (e) {
53+
logger.e("Error during disconnect in finally: $e");
54+
}
3755
}
3856
}
3957
}

lib/bademagic_module/bluetooth/write_state.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ class WriteState extends NormalBleState {
4747
} catch (e) {
4848
logger.e("Failed to write characteristic: $e");
4949
throw Exception("Failed to transfer data. Please try again.");
50+
} finally {
51+
try {
52+
logger.d("Disconnecting from device after write attempt...");
53+
await device.disconnect();
54+
await Future.delayed(const Duration(milliseconds: 700));
55+
logger.d("Device disconnected and delay complete.");
56+
} catch (e) {
57+
logger.e("Error during disconnect: $e");
58+
}
5059
}
5160
}
5261
}

lib/view/draw_badge_screen.dart

Lines changed: 81 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:badgemagic/bademagic_module/utils/byte_array_utils.dart';
12
import 'package:badgemagic/bademagic_module/utils/converters.dart';
23
import 'package:badgemagic/bademagic_module/utils/file_helper.dart';
34
import 'package:badgemagic/bademagic_module/utils/toast_utils.dart';
@@ -13,24 +14,29 @@ class DrawBadge extends StatefulWidget {
1314
final bool? isSavedCard;
1415
final bool? isSavedClipart;
1516
final List<List<int>>? badgeGrid;
16-
const DrawBadge(
17-
{super.key,
18-
this.filename,
19-
this.isSavedCard = false,
20-
this.isSavedClipart = false,
21-
this.badgeGrid});
17+
18+
const DrawBadge({
19+
super.key,
20+
this.filename,
21+
this.isSavedCard = false,
22+
this.isSavedClipart = false,
23+
this.badgeGrid,
24+
});
2225

2326
@override
2427
State<DrawBadge> createState() => _DrawBadgeState();
2528
}
2629

2730
class _DrawBadgeState extends State<DrawBadge> {
28-
var drawToggle = DrawBadgeProvider();
31+
late DrawBadgeProvider drawToggle;
2932

3033
@override
31-
void didChangeDependencies() {
32-
super.didChangeDependencies();
33-
_setLandscapeOrientation();
34+
void initState() {
35+
super.initState();
36+
drawToggle = DrawBadgeProvider();
37+
WidgetsBinding.instance.addPostFrameCallback((_) {
38+
_setLandscapeOrientation();
39+
});
3440
}
3541

3642
@override
@@ -39,27 +45,67 @@ class _DrawBadgeState extends State<DrawBadge> {
3945
super.dispose();
4046
}
4147

42-
void _resetPortraitOrientation() {
43-
SystemChrome.setPreferredOrientations([
44-
DeviceOrientation.portraitUp,
45-
DeviceOrientation.portraitDown,
46-
]);
48+
Future<void> _resetPortraitOrientation() async {
49+
try {
50+
await SystemChrome.setPreferredOrientations([
51+
DeviceOrientation.portraitUp,
52+
DeviceOrientation.portraitDown,
53+
]);
54+
} catch (e) {
55+
logger.e('Error setting portrait orientation', error: e);
56+
}
57+
}
58+
59+
Future<void> _setLandscapeOrientation() async {
60+
try {
61+
await SystemChrome.setPreferredOrientations([
62+
DeviceOrientation.landscapeRight,
63+
DeviceOrientation.landscapeLeft,
64+
]);
65+
} catch (e) {
66+
logger.e('Error setting landscape orientation', error: e);
67+
}
4768
}
4869

49-
void _setLandscapeOrientation() {
50-
SystemChrome.setPreferredOrientations([
51-
DeviceOrientation.landscapeRight,
52-
DeviceOrientation.landscapeLeft,
53-
]);
70+
Future<void> _saveImage() async {
71+
try {
72+
List<List<int>> badgeGrid = drawToggle
73+
.getDrawViewGrid()
74+
.map((e) => e.map((e) => e ? 1 : 0).toList())
75+
.toList();
76+
List<String> hexString =
77+
Converters.convertBitmapToLEDHex(badgeGrid, false);
78+
79+
if (widget.isSavedCard == true) {
80+
await FileHelper().updateBadgeText(
81+
widget.filename ?? '',
82+
hexString,
83+
);
84+
} else if (widget.isSavedClipart == true) {
85+
await FileHelper().updateClipart(
86+
widget.filename ?? '',
87+
badgeGrid,
88+
);
89+
} else {
90+
await FileHelper().saveImage(drawToggle.getDrawViewGrid());
91+
}
92+
93+
await FileHelper().generateClipartCache();
94+
ToastUtils().showToast("Clipart Saved Successfully");
95+
} catch (e) {
96+
logger.e('Error saving image', error: e);
97+
}
5498
}
5599

56100
@override
57101
Widget build(BuildContext context) {
58-
FileHelper fileHelper = FileHelper();
59-
return WillPopScope(
60-
onWillPop: () async {
61-
_resetPortraitOrientation();
62-
return true; // Allows back navigation
102+
return PopScope(
103+
canPop: true,
104+
// ignore: deprecated_member_use
105+
onPopInvoked: (didPop) async {
106+
if (didPop) {
107+
await _resetPortraitOrientation();
108+
}
63109
},
64110
child: CommonScaffold(
65111
index: 1,
@@ -79,9 +125,7 @@ class _DrawBadgeState extends State<DrawBadge> {
79125
children: [
80126
Column(
81127
children: [
82-
SizedBox(
83-
width: 100,
84-
),
128+
const SizedBox(width: 100),
85129
BMBadge(
86130
providerInit: (provider) => drawToggle = provider,
87131
badgeGrid: widget.badgeGrid
@@ -110,7 +154,7 @@ class _DrawBadgeState extends State<DrawBadge> {
110154
Text(
111155
'Draw',
112156
style: TextStyle(
113-
color: drawToggle.isDrawing
157+
color: drawToggle.getIsDrawing()
114158
? colorPrimary
115159
: Colors.black,
116160
),
@@ -128,14 +172,14 @@ class _DrawBadgeState extends State<DrawBadge> {
128172
children: [
129173
Icon(
130174
Icons.delete,
131-
color: drawToggle.isDrawing
175+
color: drawToggle.getIsDrawing()
132176
? Colors.black
133177
: colorPrimary,
134178
),
135179
Text(
136180
'Erase',
137181
style: TextStyle(
138-
color: drawToggle.isDrawing
182+
color: drawToggle.getIsDrawing()
139183
? Colors.black
140184
: colorPrimary,
141185
),
@@ -151,46 +195,19 @@ class _DrawBadgeState extends State<DrawBadge> {
151195
},
152196
child: const Column(
153197
children: [
154-
Icon(
155-
Icons.refresh,
156-
color: Colors.black,
157-
),
158-
Text(
159-
'Reset',
160-
style: TextStyle(color: Colors.black),
161-
)
198+
Icon(Icons.refresh, color: Colors.black),
199+
Text('Reset',
200+
style: TextStyle(color: Colors.black))
162201
],
163202
),
164203
),
165204
TextButton(
166-
onPressed: () {
167-
List<List<int>> badgeGrid = drawToggle
168-
.getDrawViewGrid()
169-
.map((e) => e.map((e) => e ? 1 : 0).toList())
170-
.toList();
171-
List<String> hexString =
172-
Converters.convertBitmapToLEDHex(
173-
badgeGrid, false);
174-
widget.isSavedCard!
175-
? fileHelper.updateBadgeText(
176-
widget.filename!,
177-
hexString,
178-
)
179-
: widget.isSavedClipart!
180-
? fileHelper.updateClipart(
181-
widget.filename!, badgeGrid)
182-
: fileHelper.saveImage(
183-
drawToggle.getDrawViewGrid());
184-
fileHelper.generateClipartCache();
185-
ToastUtils()
186-
.showToast("Clipart Saved Successfully");
205+
onPressed: () async {
206+
await _saveImage();
187207
},
188208
child: const Column(
189209
children: [
190-
Icon(
191-
Icons.save,
192-
color: Colors.black,
193-
),
210+
Icon(Icons.save, color: Colors.black),
194211
Text('Save',
195212
style: TextStyle(color: Colors.black))
196213
],

0 commit comments

Comments
 (0)