Skip to content

Commit

Permalink
Merge pull request #131 from ia-toki/feature/update-proof-reading
Browse files Browse the repository at this point in the history
update struktur proof reading & create feature check version
  • Loading branch information
1234iqbal authored Feb 27, 2024
2 parents 7739f8c + 1eb2c3a commit 30a09ce
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 32 deletions.
5 changes: 5 additions & 0 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ init:
make build_runner
@echo "╠ Initialize successed!"

release:
make init
@flutter pub run flutter_launcher_icons
@flutter build appbundle

dev:
@flutter run lib/main.dart

Expand Down
1 change: 0 additions & 1 deletion app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

<application
android:label="Bebras Pandai"
Expand Down
135 changes: 124 additions & 11 deletions app/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/foundation.dart';
import 'package:injectable/injectable.dart';

import '../../../onboarding/model/version_model.dart';
import '../model/registered_user.dart';

@Injectable()
Expand Down Expand Up @@ -111,4 +112,33 @@ class RegisterUserRepository {
}
return null;
}

Future<VersionModel?> getVersionApps(String version) async {
try {
final result = await FirebaseFirestore.instance
.collection('configuration')
.doc('version')
.get();

final allVersion = result.data()?['version'] as List<dynamic>;

for (final element in allVersion) {
if (element == version) {
final storedVersion = element.toString();
return VersionModel(version: storedVersion);
}
}

return null;
} on FirebaseException catch (e) {
if (kDebugMode) {
print("Failed with error '${e.code}': '${e.message}'");
}
return null;
} catch (e) {
throw Exception(e.toString());
}
}


}
2 changes: 2 additions & 0 deletions app/lib/features/main/presentation/pages/_pages.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:intl/intl.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:yaml/yaml.dart';

import '../../../../core/bases/enum/button_type.dart';
import '../../../../core/bases/widgets/atoms/button.dart';
Expand Down
27 changes: 26 additions & 1 deletion app/lib/features/main/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ class Course {
}

class _HomePageState extends State<HomePage> {
String version = '';

@override
void initState() {
context.read<HomeCubit>().fetchUser();
_loadVersion();
super.initState();
}

Future<void> _loadVersion() async {
try {
final yamlMap =
loadYaml(await rootBundle.loadString('pubspec.yaml'));
final versionWithBuildNumber =
yamlMap['version'] as String;
final parts = versionWithBuildNumber.split('+');
setState(() {
version = parts[0];
});
} catch (e) {
print('Error loading version: $e');
}
}

@override
Widget build(BuildContext context) {
return BebrasScaffold(
Expand Down Expand Up @@ -103,7 +121,7 @@ class _HomePageState extends State<HomePage> {
text: 'Pengaturan',
),
SizedBox(
height: MediaQuery.of(context).size.height - 620,
height: MediaQuery.of(context).size.height - 640,
),
InkWell(
onTap: () async {
Expand All @@ -122,6 +140,13 @@ class _HomePageState extends State<HomePage> {
),
),
),
Center(
child: Text(
'V $version',
textAlign: TextAlign.center,
style: FontTheme.greyNormal14(),
),
),
],
),
),
Expand Down
13 changes: 13 additions & 0 deletions app/lib/features/onboarding/model/version_model.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class VersionModel {
final String version;

VersionModel({
required this.version,
});

factory VersionModel.fromJson(Map<String, dynamic> json) {
return VersionModel(
version: json['version'].toString(),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import 'dart:async';

import 'package:equatable/equatable.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import 'package:yaml/yaml.dart';

import '../../../authentication/register/repositories/register_user_repo.dart';

Expand All @@ -14,14 +16,15 @@ part 'user_initialization_state.dart';
@singleton
class UserInitializationBloc
extends Bloc<UserInitializationEvent, UserInitializationState> {

final RegisterUserRepository registerUserRepository;
// final GoogleSignIn _googleSignIn = GoogleSignIn();

UserInitializationBloc(this.registerUserRepository)
: super(UserInitializationInitial()) {
on<OnboardingAuthEvent>(_auth);
}

FutureOr<void> _auth(
OnboardingAuthEvent state,
Emitter<UserInitializationState> emit,
Expand All @@ -31,20 +34,34 @@ class UserInitializationBloc
if (creds != null) {
emit(UserAuthenticated());
final userId = creds.uid;

final yamlMap = loadYaml(await rootBundle.loadString('pubspec.yaml'));
final versionWithBuildNumber = yamlMap['version'] as String;
final parts = versionWithBuildNumber.split('+');
final version = parts[0];

final checkVersionApps = await registerUserRepository.getVersionApps(
version
);

if (checkVersionApps == null) {
return emit(UpdateAvailable());
}

try {
final data = await registerUserRepository.getById(userId);

print(data);
if (data == null) {
emit(UserUnregistered());
return emit(UserUnregistered());
} else {
emit(UserRegistered());
return emit(UserRegistered());
}
} catch (e) {
emit(UserError(e.toString()));
return emit(UserError(e.toString()));
}
} else {
emit(UserUnauthenticated());
return emit(UserUnauthenticated());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ class UserRegistered extends UserInitializationState {
List<Object> get props => [];
}

class UpdateAvailable extends UserInitializationState {
@override
List<Object> get props => [];
}

class UserGetDataLoading extends UserInitializationState {
@override
List<Object> get props => [];
Expand Down
2 changes: 2 additions & 0 deletions app/lib/features/onboarding/presentation/pages/_pages.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../../../core/constants/assets.dart';
import '../bloc/user_initialization_bloc.dart';

part 'splash_screen.dart';
part 'onboarding_page.dart';
part 'update_dialog.dart';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
part of '_pages.dart';


class SplashScreen extends StatelessWidget {
const SplashScreen({super.key});

Expand All @@ -8,7 +9,9 @@ class SplashScreen extends StatelessWidget {
final size = MediaQuery.of(context).size;
return BlocListener<UserInitializationBloc, UserInitializationState>(
listener: (context, state) {
if (state is UserUnauthenticated) {
if (state is UpdateAvailable) {
showUpdateDialog(context);
} else if (state is UserUnauthenticated) {
context.go('/onboarding');
} else if (state is UserUnregistered) {
context.go('/register');
Expand All @@ -35,3 +38,12 @@ class SplashScreen extends StatelessWidget {
);
}
}

void showUpdateDialog(BuildContext context) {
showDialog<Widget>(
context: context,
builder: (BuildContext context) {
return const UpdateDialog();
},
);
}
42 changes: 42 additions & 0 deletions app/lib/features/onboarding/presentation/pages/update_dialog.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
part of '_pages.dart';

class UpdateDialog extends StatelessWidget {
const UpdateDialog({super.key});

@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
title: const Text('Versi Baru Tersedia'),
content: const SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Sebuah versi baru dari aplikasi tersedia.'),
Text(
'Silakan perbarui ke versi terbaru untuk '
'menikmati fitur dan perbaikan baru.'
),
],
),
),
actions: <Widget>[
Center(
child: TextButton(
child: const Text('Update Sekarang'),
onPressed: () async {
// Navigator.of(context).pop();
final url = Uri.parse(
'https://play.google.com/store/apps/details?id=com.toki.bebras_pandai&hl=en-US&ah=i6XiDj6PnW-iPzIlbXBXM-jTYjA',
);
if (!await launchUrl(url)) {
throw Exception('Could not launch $url');
}
},
),
)
],
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class QuizExerciseBase {

factory QuizExerciseBase.fromJson(Map<String, dynamic> json) {
return QuizExerciseBase(
id: json['id'] as String,
id: json['doc_id'] as String,
challengeGroup: json['challenge_group'] as String,
title: json['title'] as String,
status: json['status'] as String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@ class QuizExerciseRepository {
final globalResult =
await db.collection('configuration').doc('global_variables').get();

final taskSet = globalResult.get('task_set_doc_index') as List<dynamic>;
final taskSet = globalResult.get('task_set_doc_$group') as List<dynamic>;
for (final element in taskSet) {
final challengeGroup = element['challenge_group'] as String;
if (challengeGroup == group) {
quizExerciseBaseList
.add(QuizExerciseBase.fromJson(element as Map<String, dynamic>));
}
}

return quizExerciseBaseList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,24 @@ class _TaskListPageState extends State<TaskListPage> {

return GestureDetector(
onTap: () {
String cleanedTaskId;
if (task.id.startsWith('penegak_')) {
cleanedTaskId = task.id.replaceFirst('penegak_', '');
} else if (task.id.startsWith('sikecil_')) {
cleanedTaskId = task.id.replaceFirst('sikecil_', '');
} else if (task.id.startsWith('penggalang_')) {
cleanedTaskId = task.id.replaceFirst('penggalang_', '');
} else if (task.id.startsWith('siaga_')) {
cleanedTaskId = task.id.replaceFirst('siaga_', '');
} else {
cleanedTaskId = task.id;
}

context.push(
Uri(
path: '/task_detail',
queryParameters: {
'task_id': task.id,
'task_id': cleanedTaskId,
},
).toString(),
);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ Future<void> main() async {
configureDependencies();
await FirebaseService.initialize();
await FirebaseApi().initNotifications();
await initializeDateFormatting('id_ID', null);
await initializeDateFormatting('id_ID');
runApp(const App());
}
6 changes: 3 additions & 3 deletions app/macos/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.toki.bebrasPandai.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = com.toki.bebras.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/bebras_pandai.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/bebras_pandai";
Expand All @@ -398,7 +398,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.toki.bebrasPandai.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = com.toki.bebras.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/bebras_pandai.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/bebras_pandai";
Expand All @@ -412,7 +412,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.toki.bebrasPandai.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = com.toki.bebras.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/bebras_pandai.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/bebras_pandai";
Expand Down
Loading

0 comments on commit 30a09ce

Please sign in to comment.