Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

자가진단 v0.3.0 #5

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
73 changes: 39 additions & 34 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.nlog.jaga_jindan"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
compileSdkVersion 28
compileSdkVersion rootProject.ext.compileSdkVersion

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.nlog.jaga_jindan"
minSdkVersion 16
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName

targetSdkVersion rootProject.ext.targetSdkVersion
}

buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}

flutter {
source '../..'
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
androidTestImplementation 'androidx.test:runner:1.3.0' // or higher
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' // or higher
}
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.nlog.jaga_jindan">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Expand All @@ -13,6 +14,7 @@
<application
android:name="io.flutter.app.FlutterApplication"
android:label="자동 자가진단"
tools:replace="android:label"
android:icon="@drawable/app_icon">
<receiver android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
Expand Down
43 changes: 27 additions & 16 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
ext.kotlin_version = '1.3.0' // Must use 1.3.0 or higher.
ext {
compileSdkVersion = 28 // or higher
targetSdkVersion = 28 // or higher
appCompatVersion = "1.1.0" // or higher
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
}
repositories {
google()
jcenter()
maven {
// [required] background_fetch
url "${project(':background_fetch').projectDir}/libs"
}
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
delete rootProject.buildDir
}
2 changes: 2 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation;
import 'package:jaga_jindan/ui/MainPage.dart';
import 'package:jaga_jindan/util/notify.dart';
import 'package:timezone/data/latest.dart' as tz;

void main() {
timeDilation = 2.0;
tz.initializeTimeZones();
runApp(MyApp());
}

Expand Down
37 changes: 29 additions & 8 deletions lib/type/JagaJindanData.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,44 @@
import 'package:timezone/standalone.dart' as tz;

class JagaJindanData {
String name, birthday, school, edu, password;
bool force, agree = false, startup = false, useNotification = false, submitLimitation = false;
bool agree = false,
startup = false,
useNotification = false,
submitLimitation = false, autoSubmit = false;
tz.TZDateTime submitTime;

static JagaJindanData readFromJSON(dynamic json) {
var tm;
try {
tm = tz.TZDateTime.parse(tz.getLocation('Asia/Seoul'), json["submitTime"]);
} catch (e) {}
return new JagaJindanData(
json["name"] ?? "",
json["birthday"] ?? "",
json["school"] ?? "",
json["edu"] ?? "",
json["password"] ?? "",
json["force"] ?? false,
json["agree"] ?? false,
json["startup"] ?? false,
json["noti"] ?? false,
json["submitLimitation"] ?? false
);
json["submitLimitation"] ?? false,
json["autoSubmit"] ?? false,
tm);
}

JagaJindanData(this.name, this.birthday, this.school, this.edu, this.password,
this.force, this.agree, this.startup, this.useNotification, this.submitLimitation);
JagaJindanData(
this.name,
this.birthday,
this.school,
this.edu,
this.password,
this.agree,
this.startup,
this.useNotification,
this.submitLimitation,
this.autoSubmit,
this.submitTime);

dynamic toJSON() {
return {
Expand All @@ -27,11 +47,12 @@ class JagaJindanData {
"school": this.school,
"edu": this.edu,
"password": this.password,
"force": this.force,
"agree": this.agree,
"startup": this.startup,
"noti": this.useNotification,
"submitLimitation": this.submitLimitation
"submitLimitation": this.submitLimitation,
"autoSubmit": this.autoSubmit,
"submitTime": this.submitTime?.toString()
};
}
}
18 changes: 13 additions & 5 deletions lib/ui/MainPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import 'MainPageState.dart';
import 'component/agree.dart';

class MainPage extends StatefulWidget {
JagaJindanData data =
JagaJindanData("", "", "", "", "", false, false, false, false, false);
JagaJindanData data = JagaJindanData(
"", "", "", "", "", false, false, false, false, false, null);

TextEditingController nameController = TextEditingController(),
birthdayController = TextEditingController(),
schoolController = TextEditingController(),
eduController = TextEditingController(),
passwordController = TextEditingController(),
forceController = TextEditingController();
timeController = TextEditingController();

MainPageState pageState;

Expand All @@ -29,10 +29,18 @@ class MainPage extends StatefulWidget {
this.eduController.text = this.data.edu;
this.passwordController.text = this.data.password;

if (this.data.startup) sendSurvey(this.data, true);
var tm = this.data.submitTime;
if (tm != null && tm.minute != null && tm.hour != null)
this.timeController.text =
"${tm.hour < 10 ? '0' : ''}${tm.hour}:${tm.minute < 10 ? '0' : ''}${tm.minute}";

//setBackgroundProcess(this.data);
backgroundFetchHeadlessTask(FB_TASK_ID);

//if (this.data.startup) sendSurvey(this.data, true);

agree(pageState);
await pageState.setState(() {});
pageState.setState(() {});
}

writeJSON() async {
Expand Down
54 changes: 51 additions & 3 deletions lib/ui/MainPageState.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,72 @@
import 'dart:async';
import 'dart:convert';

import 'package:background_fetch/background_fetch.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:jaga_jindan/ui/component/JagaJindanForm.dart';
import 'package:jaga_jindan/ui/component/setting.dart';
import 'package:jaga_jindan/util/notify.dart';
import 'package:jaga_jindan/util/school.dart';

import 'package:jaga_jindan/util/sendSurvey.dart';
import 'package:package_info/package_info.dart';

import 'MainPage.dart';

class MainPageState extends State<MainPage> {
final formKey = GlobalKey<FormState>();
String edu = "서울특별시", school = "1", selectedSchoolCode = "";
List<School> schools = [];
bool flag = false, initBackground = false;
String appVer, newVer = "불러오는 중";

TextEditingController searchSchoolController;

Future<void> initBackgroundService() async {
if (!initBackground) {
BackgroundFetch.registerHeadlessTask(backgroundFetchHeadlessTask);
BackgroundFetch.configure(
BackgroundFetchConfig(
minimumFetchInterval: 15,
stopOnTerminate: false,
enableHeadless: true,
forceAlarmManager: true,
startOnBoot: true), backgroundFetchHeadlessTask);
}
initBackground = true;
}

@override
Widget build(BuildContext context) {
this.widget.pageState = this;
searchSchoolController = TextEditingController();
initBackgroundService();

if (!flag) {
PackageInfo.fromPlatform().then((value) => setState(() {
appVer = value.version;
}));

http
.get(
"https://api.github.com/repos/eduro-hcs/jaga_jindan/releases/latest")
.then((data) {
try {
setState(() {
newVer = jsonDecode(data.body)["tag_name"];
newVer = newVer.substring(1);
if (newVer != appVer) {
noti("새로운 버전이 있습니다.", "현재 버전 : $appVer, 새 버전 : $newVer",
"https://github.com/eduro-hcs/jaga_jindan/releases/latest");
}
});
} catch (e) {
newVer = "(error)";
}
});
}
flag = true;

return Scaffold(
appBar: AppBar(
Expand All @@ -38,7 +86,7 @@ class MainPageState extends State<MainPage> {
alignment: Alignment.bottomLeft,
child: FloatingActionButton(
onPressed: () async {
showCredit(this);
showCredit(this, appVer, newVer);
},
child: Icon(Icons.settings),
tooltip: "설정 및 정보",
Expand All @@ -48,7 +96,7 @@ class MainPageState extends State<MainPage> {
alignment: Alignment.bottomRight,
child: FloatingActionButton(
onPressed: () {
if (formKey.currentState.validate()) {
if (formKey.currentState?.validate() == true) {
sendSurvey(this.widget.data);
}
},
Expand Down
Loading