Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.6 #639

Merged
merged 13 commits into from
Dec 19, 2024
Merged

V1.6 #639

Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 7 additions & 6 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Run analysis and tests

on:
Expand All @@ -22,7 +17,13 @@ jobs:
- name: Flutter action
uses: subosito/[email protected]
with:
flutter-version: "3.16.5"
flutter-version: "3.22.1"

- name: Clean previous builds
run: flutter clean

- name: Install dependencies
run: flutter pub get

- name: Generate models
run: ./tools/install_bricks.sh
Expand Down
75 changes: 75 additions & 0 deletions .github/workflows/flutter-build-apk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build APK Workflow

on:
push:
branches: [ 'develop', 'master' ] # This specifies that the workflow will run on any push to the 'develop' or 'master' branches
pull_request:
branches: [ 'develop', 'master' ] # Optionally, run on pull requests targeting the 'develop' or 'master' branches

jobs:
build-apk:
runs-on: ubuntu-latest
environment: UAT

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin' # Specify the Java distribution

- name: Flutter action
uses: subosito/[email protected]
with:
flutter-version: "3.22.2"

- name: Set up Android SDK
uses: android-actions/setup-android@v2
with:
api-level: 33
build-tools: 33.0.2

- name: Install Dependencies
run: flutter pub get

- name: Create .env file
run: |
echo "BASE_URL=${{ vars.BASE_URL }}" >> apps/health_campaign_field_worker_app/.env
echo "MDMS_API_PATH=${{ vars.MDMS_API_PATH }}" >> apps/health_campaign_field_worker_app/.env
echo "TENANT_ID=${{ vars.TENANT_ID }}" >> apps/health_campaign_field_worker_app/.env
echo "ACTIONS_API_PATH=${{ vars.ACTIONS_API_PATH }}" >> apps/health_campaign_field_worker_app/.env
echo "SYNC_DOWN_RETRY_COUNT=${{ vars.SYNC_DOWN_RETRY_COUNT }}" >> apps/health_campaign_field_worker_app/.env
echo "RETRY_TIME_INTERVAL=${{ vars.RETRY_TIME_INTERVAL }}" >> apps/health_campaign_field_worker_app/.env
echo "CONNECT_TIMEOUT=${{ vars.CONNECT_TIMEOUT }}" >> apps/health_campaign_field_worker_app/.env
echo "RECEIVE_TIMEOUT=${{ vars.RECEIVE_TIMEOUT }}" >> apps/health_campaign_field_worker_app/.env
echo "SEND_TIMEOUT=${{ vars.SEND_TIMEOUT }}" >> apps/health_campaign_field_worker_app/.env
echo "CHECK_BANDWIDTH_API=${{ vars.CHECK_BANDWIDTH_API }}" >> apps/health_campaign_field_worker_app/.env
echo "HIERARCHY_TYPE=${{ vars.HIERARCHY_TYPE }}" >> apps/health_campaign_field_worker_app/.env
echo "ENV_NAME=${{ vars.ENV_NAME }}" >> apps/health_campaign_field_worker_app/.env

- name: Verify .env file
run: |
ls -l apps/health_campaign_field_worker_app/.env
cat apps/health_campaign_field_worker_app/.env

- name: Run APK build script
env:
BUILD_CONFIG: release # or profile depending on your choice
run: bash ./tools/generate-apk.sh

# Archive the APK as a build artifact so it can be downloaded
- name: Upload APKs
uses: actions/upload-artifact@v3
with:
name: app-release-apk
path: apps/health_campaign_field_worker_app/build/app/outputs/flutter-apk/app-release.apk

- name: Upload .env as artifact
uses: actions/upload-artifact@v3
with:
name: env-file
path: apps/health_campaign_field_worker_app/.env
include-hidden-files: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ migrate_working_dir/
*.iws
.idea/


# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
Expand Down Expand Up @@ -57,3 +56,7 @@ pubspec_overrides.yaml
apps/health_campaign_field_worker_app/.env
apps/health_campaign_field_worker_app/libisar.dylib
*.properties

# FVM Version Cache
.fvm/
.fvmrc
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ class _ChecklistDataShowcaseData {
import '../../../utils/i18_key_constants.dart' as i18;
import '../showcase_wrappers.dart';

part 'checklist_data.dart';
part 'survey_form_data.dart';

final checklistDataShowcaseData = _ChecklistDataShowcaseData();
```
Expand Down
4 changes: 4 additions & 0 deletions apps/health_campaign_field_worker_app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ app.*.map.json
/android/app/debug
/android/app/profile
/android/app/release

# FVM Version Cache
.fvm/
.fvmrc
44 changes: 22 additions & 22 deletions apps/health_campaign_field_worker_app/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'dev.flutter.flutter-gradle-plugin'
id 'com.google.gms.google-services'
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
Expand All @@ -6,11 +13,6 @@ if (localPropertiesFile.exists()) {
}
}

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.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
Expand All @@ -21,24 +23,18 @@ if (flutterVersionName == null) {
flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
// START: FlutterFire Configuration
apply plugin: 'com.google.gms.google-services'
// END: FlutterFire Configuration
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 34
compileSdk = flutter.compileSdkVersion
ndkVersion flutter.ndkVersion

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}

sourceSets {
Expand All @@ -50,8 +46,8 @@ android {
applicationId "com.digit.hcm"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
minSdkVersion 21
targetSdkVersion flutter.targetSdkVersion
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand All @@ -63,12 +59,16 @@ android {
signingConfig signingConfigs.debug
}
}

if (!project.hasProperty('USE_GOOGLE_SERVICES')) {
tasks.whenTaskAdded { task ->
if (task.name.contains("GoogleServices")) {
task.enabled = false
}
}
}
}

flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
<uses-permission android:name="com.android.alarm.permission.SCHEDULE_EXACT_ALARM" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
Expand All @@ -28,16 +29,16 @@
<!--#enddocregion android-queries-->
<application
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:label="HCM">
android:allowBackup="false"
android:fullBackupOnly="false"
android:fullBackupContent="false"
android:fullBackupOnly="false"
android:icon="@mipmap/ic_launcher"
android:label="HCM">
<service
android:name=".LocationService"
android:enabled="true"
android:foregroundServiceType="location"
android:exported="false" />
android:exported="false"
android:foregroundServiceType="location" />

<activity
android:name=".MainActivity"
Expand All @@ -64,9 +65,10 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>


</activity>
<service
android:name="id.flutter.flutter_background_service.BackgroundService"
android:foregroundServiceType="dataSync" />
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,82 @@
package com.digit.hcm

import io.flutter.embedding.android.FlutterActivity
import android.os.Bundle
import java.io.File
import java.io.FileOutputStream
import io.flutter.plugin.common.MethodChannel
import android.content.Intent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Environment
import androidx.core.app.ActivityCompat
import androidx.core.content.ContextCompat
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import io.flutter.embedding.android.FlutterActivity
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {
private val CHANNEL = "com.digit.location_tracker"
private val locationReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val latitude = intent?.getDoubleExtra("latitude", 0.0)
val longitude = intent?.getDoubleExtra("longitude", 0.0)
val accuracy = intent?.getFloatExtra("accuracy", 0.0f) // Retrieve accuracy here

// Handle the location data here
Toast.makeText(context, "Latitude: $latitude, Longitude: $longitude", Toast.LENGTH_LONG).show()
Toast.makeText(
context,
"Latitude: $latitude, Longitude: $longitude, Accuracy: $accuracy",
Toast.LENGTH_LONG
).show()
// Optionally, you can send this data to Flutter via MethodChannel
flutterEngine?.dartExecutor?.binaryMessenger?.let {
MethodChannel(it, CHANNEL).invokeMethod("locationUpdate", mapOf("latitude" to latitude, "longitude" to longitude))
MethodChannel(it, CHANNEL).invokeMethod(
"locationUpdate", mapOf(
"latitude" to latitude,
"longitude" to longitude,
"accuracy" to accuracy
)
)
naveenr-egov marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

MethodChannel(flutterEngine!!.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
MethodChannel(
flutterEngine!!.dartExecutor.binaryMessenger,
CHANNEL
).setMethodCallHandler { call, result ->
when (call.method) {
"startLocationUpdates" -> {
val interval = (call.argument<Number>("interval")?.toLong()) ?: 60000L
val stopAfterTimestamp = (call.argument<Number>("stopAfterTimestamp")?.toLong()) ?: (System.currentTimeMillis() + 60000L)
val stopAfterTimestamp = (call.argument<Number>("stopAfterTimestamp")?.toLong())
?: (System.currentTimeMillis() + 60000L)
if (!isMyServiceRunning(LocationService::class.java)) {
startService(interval, stopAfterTimestamp)
} else {
Toast.makeText(this, "Location service is already running", Toast.LENGTH_SHORT).show()
Toast.makeText(
this,
"Location service is already running",
Toast.LENGTH_SHORT
).show()
}
result.success(null)
}

"stopLocationUpdates" -> {
stopService()
result.success(null)
}

else -> result.notImplemented()
}
}

// Register the receiver for location updates
// Register the receiver for location updates, with proper export settings for Android 13+
val filter = IntentFilter("LocationUpdate")
registerReceiver(locationReceiver, filter)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
registerReceiver(locationReceiver, filter, Context.RECEIVER_EXPORTED)
} else {
registerReceiver(locationReceiver, filter)
}
}

override fun onDestroy() {
Expand Down Expand Up @@ -90,7 +112,8 @@ class MainActivity : FlutterActivity() {
val manager = getSystemService(Context.ACTIVITY_SERVICE) as android.app.ActivityManager
for (service in manager.getRunningServices(Int.MAX_VALUE)) {
if (serviceClass.name == service.service.className) {
Toast.makeText(this, "Location service is already running", Toast.LENGTH_SHORT).show()
Toast.makeText(this, "Location service is already running", Toast.LENGTH_SHORT)
.show()
return true
}
}
Expand Down
Loading
Loading