Compare commits

..

1 Commits

Author SHA1 Message Date
Pritimay Sarkar
0bb54a12cc Enable Cloud Run deployments 2024-01-20 05:12:27 +00:00
21 changed files with 496 additions and 657 deletions

View File

@@ -1,88 +1,53 @@
# This file is a template, and might need editing before it works on your project. ---
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Android.gitlab-ci.yml
# Read more about this script on this blog post https://about.gitlab.com/2018/10/24/setting-up-gitlab-ci-for-android-projects/, by Jason Lenny
# If you are interested in using Android with FastLane for publishing take a look at the Android-Fastlane template.
image: eclipse-temurin:17-jdk-jammy image: eclipse-temurin:17-jdk-jammy
variables: variables:
ANDROID_COMPILE_SDK: '34'
# ANDROID_COMPILE_SDK is the version of Android you're compiling with. ANDROID_BUILD_TOOLS: 33.0.2
# It should match compileSdkVersion. ANDROID_SDK_TOOLS: '9477386'
ANDROID_COMPILE_SDK: "34"
# ANDROID_BUILD_TOOLS is the version of the Android build tools you are using.
# It should match buildToolsVersion.
ANDROID_BUILD_TOOLS: "33.0.2"
# It's what version of the command line tools we're going to download from the official site.
# Official Site-> https://developer.android.com/studio/index.html
# There, look down below at the cli tools only, sdk tools package is of format:
# commandlinetools-os_type-ANDROID_SDK_TOOLS_latest.zip
# when the script was last modified for latest compileSdkVersion, it was which is written down below
ANDROID_SDK_TOOLS: "9477386"
# Packages installation before running script
before_script: before_script:
- apt-get --quiet update --yes - apt-get --quiet update --yes
- apt-get --quiet install --yes wget unzip - apt-get --quiet install --yes wget unzip
- export ANDROID_HOME="${PWD}/android-sdk-root"
# Setup path as android_home for moving/exporting the downloaded sdk into it - install -d $ANDROID_HOME
- export ANDROID_HOME="${PWD}/android-sdk-root" - wget --no-verbose --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip
# Create a new directory at specified location - unzip -q -d "$ANDROID_HOME/cmdline-tools" "$ANDROID_HOME/cmdline-tools.zip"
- install -d $ANDROID_HOME - mv -T "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/tools"
# Here we are installing androidSDK tools from official source, - export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/cmdline-tools/tools/bin
# (the key thing here is the url from where you are downloading these sdk tool for command line, so please do note this url pattern there and here as well) - sdkmanager --version
# after that unzipping those tools and - yes | sdkmanager --licenses > /dev/null || true
# then running a series of SDK manager commands to install necessary android SDK packages that'll allow the app to build - sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
- wget --no-verbose --output-document=$ANDROID_HOME/cmdline-tools.zip https://dl.google.com/android/repository/commandlinetools-linux-${ANDROID_SDK_TOOLS}_latest.zip - sdkmanager "platform-tools"
- unzip -q -d "$ANDROID_HOME/cmdline-tools" "$ANDROID_HOME/cmdline-tools.zip" - sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}"
- mv -T "$ANDROID_HOME/cmdline-tools/cmdline-tools" "$ANDROID_HOME/cmdline-tools/tools" - chmod +x ./gradlew
- export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/cmdline-tools/tools/bin
# Nothing fancy here, just checking sdkManager version
- sdkmanager --version
# use yes to accept all licenses
- yes | sdkmanager --licenses > /dev/null || true
- sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}"
- sdkmanager "platform-tools"
- sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}"
# Not necessary, but just for surity
- chmod +x ./gradlew
# Basic android and gradle stuff
# Check linting
lintDebug: lintDebug:
interruptible: true interruptible: true
stage: build stage: build
script: script:
- ./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint - "./gradlew -Pci --console=plain :app:lintDebug -PbuildDir=lint"
artifacts: artifacts:
paths: paths:
- app/lint/reports/lint-results-debug.html - app/lint/reports/lint-results-debug.html
expose_as: "lint-report" expose_as: lint-report
when: always when: always
# Make Project
assembleDebug: assembleDebug:
interruptible: true interruptible: true
stage: build stage: build
script: script:
- ./gradlew assembleDebug - "./gradlew assembleDebug"
artifacts: artifacts:
paths: paths:
- app/build/outputs/ - app/build/outputs/
# Run all tests, if any fails, interrupt the pipeline(fail it)
debugTests: debugTests:
needs: [lintDebug, assembleDebug] needs:
- lintDebug
- assembleDebug
interruptible: true interruptible: true
stage: test stage: test
script: script:
- ./gradlew -Pci --console=plain :app:testDebug - "./gradlew -Pci --console=plain :app:testDebug"
stages:
- build
- test
- deploy
include:
- remote: https://gitlab.com/gitlab-org/incubation-engineering/five-minute-production/library/-/raw/main/gcp/cloud-run.gitlab-ci.yml

View File

@@ -16,11 +16,11 @@ android {
// prod - production, preprod - preproduction, quality - qc, dev - development // prod - production, preprod - preproduction, quality - qc, dev - development
defaultConfig { defaultConfig {
applicationId "in.sminnovations.hpostesting" applicationId "in.sminnovations.hpostesting.dev"
minSdk 21 minSdk 21
targetSdk 34 targetSdk 34
versionCode 93 versionCode 91
versionName "2.1.93" versionName "2.1.91"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@@ -108,8 +108,6 @@ dependencies {
testImplementation 'org.mockito:mockito-core:3.12.4' testImplementation 'org.mockito:mockito-core:3.12.4'
androidTestImplementation 'org.mockito:mockito-android:3.12.4' androidTestImplementation 'org.mockito:mockito-android:3.12.4'
androidTestImplementation 'org.mockito:mockito-inline:3.12.4' androidTestImplementation 'org.mockito:mockito-inline:3.12.4'
androidTestImplementation 'org.mockito:mockito-android:3.12.4'
testImplementation "androidx.arch.core:core-testing:2.2.0" testImplementation "androidx.arch.core:core-testing:2.2.0"
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1' testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1'

View File

@@ -34,35 +34,6 @@
} }
} }
}, },
{
"client_info": {
"mobilesdk_app_id": "1:650071678820:android:7865bef608cdee6f6c6471",
"android_client_info": {
"package_name": "com.smi.counselling"
}
},
"oauth_client": [
{
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAVdNGCev_AFX0qmuZJF6kxzRzXUTeAW5I"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "650071678820-to41afi9f0gi5r3k6v7pe1e5p96nupcs.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
},
{ {
"client_info": { "client_info": {
"mobilesdk_app_id": "1:650071678820:android:2925e9ce3417d2386c6471", "mobilesdk_app_id": "1:650071678820:android:2925e9ce3417d2386c6471",
@@ -205,4 +176,4 @@
} }
], ],
"configuration_version": "1" "configuration_version": "1"
} }

View File

@@ -177,7 +177,7 @@ object Constants {
const val DEVICE_ID = "DEVICE_ID" const val DEVICE_ID = "DEVICE_ID"
const val BUFFER_LED_LOWER_BOUND = 21000 const val BUFFER_LED_LOWER_BOUND = 21000
const val BUFFER_LED_UPPER_BOUND = 23500 const val BUFFER_LED_UPPER_BOUND = 24500
const val TEST_STATUS_CODE_TEST_STARTED = 1.0 const val TEST_STATUS_CODE_TEST_STARTED = 1.0
const val TEST_STATUS_CODE_CONFIG_STARTED = 2.0 const val TEST_STATUS_CODE_CONFIG_STARTED = 2.0
@@ -1175,64 +1175,64 @@ object Constants {
val BUFFER_INTENSITY_THRESHOLDS: Map<String, List<List<Int>>> = mapOf<String, List<List<Int>>>( val BUFFER_INTENSITY_THRESHOLDS: Map<String, List<List<Int>>> = mapOf<String, List<List<Int>>>(
"HCV-000-3001" to listOf( "HCV-000-3001" to listOf(
listOf(23000, 25074), listOf(20000, 25074),
listOf(23000, 24596), listOf(20000, 24596),
listOf(23000, 26065), listOf(20000, 26065),
listOf(23000, 27093), listOf(20000, 27093),
), ),
"HCV-000-3002" to listOf( "HCV-000-3002" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3003" to listOf( "HCV-000-3003" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3004" to listOf( "HCV-000-3004" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3005" to listOf( "HCV-000-3005" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3006" to listOf( "HCV-000-3006" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3007" to listOf( "HCV-000-3007" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3008" to listOf( "HCV-000-3008" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3009" to listOf( "HCV-000-3009" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3010" to listOf( "HCV-000-3010" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3011" to listOf( "HCV-000-3011" to listOf(
listOf(20000, 25074), listOf(20000, 25074),
@@ -1241,58 +1241,58 @@ object Constants {
listOf(20000, 27093), listOf(20000, 27093),
), ),
"HCV-000-3012" to listOf( "HCV-000-3012" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-1015" to listOf( "HCV-000-1015" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3014" to listOf( "HCV-000-3014" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3015" to listOf( "HCV-000-3015" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3016" to listOf( "HCV-000-3016" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3017" to listOf( "HCV-000-3017" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3018" to listOf( "HCV-000-3018" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3019" to listOf( "HCV-000-3019" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3020" to listOf( "HCV-000-3020" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3021" to listOf( "HCV-000-3021" to listOf(
listOf(20000, 25074), listOf(20000, 25074),
@@ -1301,58 +1301,58 @@ object Constants {
listOf(20000, 27093), listOf(20000, 27093),
), ),
"HCV-000-3022" to listOf( "HCV-000-3022" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3023" to listOf( "HCV-000-3023" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3024" to listOf( "HCV-000-3024" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3025" to listOf( "HCV-000-3025" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3026" to listOf( "HCV-000-3026" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3027" to listOf( "HCV-000-3027" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3028" to listOf( "HCV-000-3028" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3029" to listOf( "HCV-000-3029" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HCV-000-3030" to listOf( "HCV-000-3030" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0001" to listOf( "HPP1-0124-0001" to listOf(
listOf(20000, 25074), listOf(20000, 25074),
@@ -1361,58 +1361,58 @@ object Constants {
listOf(20000, 27093), listOf(20000, 27093),
), ),
"HPP1-0124-0002" to listOf( "HPP1-0124-0002" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0003" to listOf( "HPP1-0124-0003" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0004" to listOf( "HPP1-0124-0004" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0005" to listOf( "HPP1-0124-0005" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0006" to listOf( "HPP1-0124-0006" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0007" to listOf( "HPP1-0124-0007" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0008" to listOf( "HPP1-0124-0008" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0009" to listOf( "HPP1-0124-0009" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0010" to listOf( "HPP1-0124-0010" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0011" to listOf( "HPP1-0124-0011" to listOf(
listOf(20000, 25074), listOf(20000, 25074),
@@ -1421,118 +1421,118 @@ object Constants {
listOf(20000, 27093), listOf(20000, 27093),
), ),
"HPP1-0124-0012" to listOf( "HPP1-0124-0012" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0013" to listOf( "HPP1-0124-0013" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0014" to listOf( "HPP1-0124-0014" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0015" to listOf( "HPP1-0124-0015" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0016" to listOf( "HPP1-0124-0016" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0017" to listOf( "HPP1-0124-0017" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0018" to listOf( "HPP1-0124-0018" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0019" to listOf( "HPP1-0124-0019" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0020" to listOf( "HPP1-0124-0020" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0021" to listOf( "HPP1-0124-0021" to listOf(
listOf(23500, 26250), listOf(20000, 25074),
listOf(23500, 26250), listOf(20000, 24596),
listOf(23500, 26250), listOf(20000, 26065),
listOf(23500, 26250), listOf(20000, 27093),
), ),
"HPP1-0124-0022" to listOf( "HPP1-0124-0022" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0023" to listOf( "HPP1-0124-0023" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0024" to listOf( "HPP1-0124-0024" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0025" to listOf( "HPP1-0124-0025" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0026" to listOf( "HPP1-0124-0026" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0027" to listOf( "HPP1-0124-0027" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0028" to listOf( "HPP1-0124-0028" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0029" to listOf( "HPP1-0124-0029" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0030" to listOf( "HPP1-0124-0030" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0031" to listOf( "HPP1-0124-0031" to listOf(
listOf(20000, 25074), listOf(20000, 25074),
@@ -1541,118 +1541,118 @@ object Constants {
listOf(20000, 27093), listOf(20000, 27093),
), ),
"HPP1-0124-0032" to listOf( "HPP1-0124-0032" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0033" to listOf( "HPP1-0124-0033" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0034" to listOf( "HPP1-0124-0034" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0035" to listOf( "HPP1-0124-0035" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0036" to listOf( "HPP1-0124-0036" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0037" to listOf( "HPP1-0124-0037" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0038" to listOf( "HPP1-0124-0038" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0039" to listOf( "HPP1-0124-0039" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0040" to listOf( "HPP1-0124-0040" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0040" to listOf( "HPP1-0124-0041" to listOf(
listOf(23500, 26250), listOf(20000, 25074),
listOf(23500, 26250), listOf(20000, 24596),
listOf(23500, 26250), listOf(20000, 26065),
listOf(23500, 26250), listOf(20000, 27093),
), ),
"HPP1-0124-0042" to listOf( "HPP1-0124-0042" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0043" to listOf( "HPP1-0124-0043" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0044" to listOf( "HPP1-0124-0044" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0045" to listOf( "HPP1-0124-0045" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0046" to listOf( "HPP1-0124-0046" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0047" to listOf( "HPP1-0124-0047" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0048" to listOf( "HPP1-0124-0048" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0049" to listOf( "HPP1-0124-0049" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
), ),
"HPP1-0124-0050" to listOf( "HPP1-0124-0050" to listOf(
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
listOf(23500, 26250), listOf(24500, 26250),
) )
) )

View File

@@ -243,6 +243,8 @@ class UserListAdapter(
} }
} }
private fun isBetween15And30Minutes(createdAt: String): Long { private fun isBetween15And30Minutes(createdAt: String): Long {
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()) val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
val createdAtDate: Date = formatter.parse(createdAt)!! val createdAtDate: Date = formatter.parse(createdAt)!!

View File

@@ -1,6 +1,5 @@
package com.example.hpostesting.presentation.dashboard package com.example.hpostesting.presentation.dashboard
import android.annotation.SuppressLint
import android.app.DownloadManager import android.app.DownloadManager
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
@@ -25,6 +24,9 @@ import com.example.hpostesting.data.constant.LanguageManager
import com.example.hpostesting.presentation.NatsManager import com.example.hpostesting.presentation.NatsManager
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
import com.google.android.material.navigation.NavigationView import com.google.android.material.navigation.NavigationView
import com.google.android.material.progressindicator.LinearProgressIndicator
import com.google.android.play.core.appupdate.AppUpdateManager
import com.google.android.play.core.appupdate.AppUpdateManagerFactory
import com.google.firebase.appdistribution.FirebaseAppDistribution import com.google.firebase.appdistribution.FirebaseAppDistribution
import com.google.firebase.appdistribution.FirebaseAppDistributionException import com.google.firebase.appdistribution.FirebaseAppDistributionException
@@ -48,7 +50,6 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
var responses: String = "" var responses: String = ""
lateinit var nats: NatsManager lateinit var nats: NatsManager
private var downloadId: Long = 0 private var downloadId: Long = 0
private var isReceiverRegistered = false
// TODO: Remove hemocube viewmodel // TODO: Remove hemocube viewmodel
private val hemocubeViewModel: HemoCubeViewModel by viewModels() private val hemocubeViewModel: HemoCubeViewModel by viewModels()
@@ -71,10 +72,11 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
hemocubeViewModel.deviceUpdate.observe(this) { result -> hemocubeViewModel.deviceUpdate.observe(this) { result ->
when (result) { when (result) {
is Result.Success -> { is Result.Success -> {
// Handle success
val apkUrl = result.data val apkUrl = result.data
// val apkUrl = "https://dl.dropboxusercontent.com/s/fi/1c3nn7t0co431hicl3hrt/app-debug.apk?rlkey=e4uf13ty1dpcked614vy1aaqp&dl=0" // val apkUrl = "https://dl.dropboxusercontent.com/s/fi/1c3nn7t0co431hicl3hrt/app-debug.apk?rlkey=e4uf13ty1dpcked614vy1aaqp&dl=0"
initiateUpdate(apkUrl.toString()) initiateUpdate(apkUrl.toString())
Log.d("ApI", "APK URL For App Update: $apkUrl") Log.d("ApI", "APK URL: $apkUrl")
Toast.makeText( Toast.makeText(
this, this,
"APK UPLOAD ${result.data}", "APK UPLOAD ${result.data}",
@@ -84,9 +86,9 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
} }
is Result.Error -> { is Result.Error -> {
result.exception.let { message -> result.exception.let { message ->
Toast.makeText(this, "An error occurred On Updating App: $message", Toast.LENGTH_LONG) Toast.makeText(this, "An error occurred On Updating App: $message", Toast.LENGTH_LONG)
.show() .show()
} }
@@ -127,13 +129,17 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp() return navController.navigateUp(appBarConfiguration) || super.onSupportNavigateUp()
} }
@SuppressLint("UnspecifiedRegisterReceiverFlag")
private fun initiateUpdate(responseBody: String) { private fun initiateUpdate(responseBody: String) {
if (!isValidHttpUrl(responseBody)) { // Extract the URL from the ResponseBody
val apkUrl = responseBody
// Check if the extracted APK URL is valid
if (!isValidHttpUrl(apkUrl)) {
// Handle the case where the URL is not valid
return return
} }
val request = DownloadManager.Request(Uri.parse(responseBody)) val request = DownloadManager.Request(Uri.parse(apkUrl))
request.setTitle("App Update") request.setTitle("App Update")
request.setDescription("Downloading update...") request.setDescription("Downloading update...")
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
@@ -141,16 +147,20 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager val downloadManager = getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
downloadId = downloadManager.enqueue(request) downloadId = downloadManager.enqueue(request)
// Register a BroadcastReceiver to receive the download complete event
val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE) val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
if (!isReceiverRegistered) { registerReceiver(downloadReceiver, filter)
val filter = IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
registerReceiver(downloadReceiver, filter)
isReceiverRegistered = true
}
} }
// Function to check if a URL has a valid HTTP/HTTPS scheme
// Function to extract the APK URL from the ResponseBody
private fun extractApkUrl(responseBody: ResponseBody): String { private fun extractApkUrl(responseBody: ResponseBody): String {
// Assuming your ResponseBody contains the APK URL as a string
return responseBody.string() return responseBody.string()
} }
// Function to check if a URL has a valid HTTP/HTTPS scheme
private fun isValidHttpUrl(url: String): Boolean { private fun isValidHttpUrl(url: String): Boolean {
return url.startsWith("http://") || url.startsWith("https://") return url.startsWith("http://") || url.startsWith("https://")
} }
@@ -158,6 +168,7 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
override fun onReceive(context: Context?, intent: Intent?) { override fun onReceive(context: Context?, intent: Intent?) {
val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1) val id = intent?.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1)
if (id == downloadId) { if (id == downloadId) {
// Install the downloaded APK
installApk() installApk()
} }
} }
@@ -190,12 +201,12 @@ class DashboardActivity : AppCompatActivity(), IDataCollector {
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (isReceiverRegistered) { unregisterReceiver(downloadReceiver)
unregisterReceiver(downloadReceiver)
isReceiverRegistered = false
}
} }
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()

View File

@@ -200,9 +200,7 @@ class HomeFragment : Fragment() {
hemoCubeViewModel.login(createLoginRequestData(userID, password)) hemoCubeViewModel.login(createLoginRequestData(userID, password))
} else { } else {
isTokenAvailable = true isTokenAvailable = true
// hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData()) hemoCubeViewModel.deviceUpdate(createDeviceUpdateRequestData())
hemoCubeViewModel.deviceUpdate(createDeviceRequestData())
hemoCubeViewModel.uploadLogs() hemoCubeViewModel.uploadLogs()
hemoCubeViewModel.startPeriodicCheckUpdate() hemoCubeViewModel.startPeriodicCheckUpdate()
} }
@@ -239,6 +237,34 @@ class HomeFragment : Fragment() {
} }
} }
hemoCubeViewModel.deviceUpdate.observe(viewLifecycleOwner) { response ->
when (response) {
is Result.Success -> {
Toast.makeText(
requireContext(), response.data.toString(), Toast.LENGTH_SHORT
).show()
}
is Result.Error -> {
response.exception.let { message ->
Toast.makeText(
activity,
"An error occurred check update: $message",
Toast.LENGTH_LONG
)
.show()
}
}
is Result.Loading -> {
}
else -> {}
}
}
hemoCubeViewModel.uploadLogs.observe(viewLifecycleOwner) { response -> hemoCubeViewModel.uploadLogs.observe(viewLifecycleOwner) { response ->
when (response) { when (response) {
is Result.Success -> { is Result.Success -> {
@@ -337,10 +363,9 @@ class HomeFragment : Fragment() {
) )
} }
private fun createDeviceRequestData(): DeviceUpdateRequest { private fun createDeviceUpdateRequestData(): DeviceUpdateRequest {
return DeviceUpdateRequest( return DeviceUpdateRequest(
serial_no = Constants.DEVICE_ID serial_no = sharedPreference.getString(Constants.DEVICE_ID, "")
) )
} }

View File

@@ -34,8 +34,6 @@ import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.ActivityCalibrationBinding import `in`.sminnovations.hpostesting.databinding.ActivityCalibrationBinding
import `in`.sminnovations.hpostesting.databinding.ActivityDeviceBinding import `in`.sminnovations.hpostesting.databinding.ActivityDeviceBinding
@Suppress("MemberVisibilityCanBePrivate")
@AndroidEntryPoint @AndroidEntryPoint
class DeviceActivity : AppCompatActivity() { class DeviceActivity : AppCompatActivity() {
private lateinit var binding: ActivityDeviceBinding private lateinit var binding: ActivityDeviceBinding
@@ -112,7 +110,6 @@ class DeviceActivity : AppCompatActivity() {
} }
} }
} }
open fun connectUsb(permissionGranted: Boolean) { open fun connectUsb(permissionGranted: Boolean) {
Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted") Log.d(TAG, "connectUsb() called, permission variable = $permissionGranted")
val manager = getSystemService(Context.USB_SERVICE) as UsbManager val manager = getSystemService(Context.USB_SERVICE) as UsbManager
@@ -128,9 +125,12 @@ class DeviceActivity : AppCompatActivity() {
} else { } else {
setupService() setupService()
} }
} }
} }
fun onErrorReported(msg: String) { fun onErrorReported(msg: String) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show() Toast.makeText(this, msg, Toast.LENGTH_SHORT).show()
if (!isFinishing) onBackPressed() if (!isFinishing) onBackPressed()
@@ -142,7 +142,6 @@ class DeviceActivity : AppCompatActivity() {
supportFragmentManager.beginTransaction().replace(binding.fgDevice.id, DeviceFragment()) supportFragmentManager.beginTransaction().replace(binding.fgDevice.id, DeviceFragment())
.commit() .commit()
} }
@SuppressLint("MutableImplicitPendingIntent") @SuppressLint("MutableImplicitPendingIntent")
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) { private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
val mPendingIntent: PendingIntent val mPendingIntent: PendingIntent
@@ -164,6 +163,7 @@ class DeviceActivity : AppCompatActivity() {
manager.requestPermission(device, mPendingIntent) manager.requestPermission(device, mPendingIntent)
} }
fun setupService() { fun setupService() {
val intent = Intent(this, UsbService::class.java) val intent = Intent(this, UsbService::class.java)
bindService(intent, connection, Context.BIND_AUTO_CREATE) bindService(intent, connection, Context.BIND_AUTO_CREATE)

View File

@@ -1,14 +1,20 @@
package com.example.hpostesting.presentation.deviceinfo package com.example.hpostesting.presentation.deviceinfo
import android.content.Context import android.content.Context
import android.content.SharedPreferences
import android.util.Log
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.example.hpostesting.data.NetworkStatusLiveData import com.example.hpostesting.data.NetworkStatusLiveData
import com.example.hpostesting.data.dao.HemoCubeDao import com.example.hpostesting.data.dao.HemoCubeDao
import com.example.hpostesting.data.model.Response
import com.example.hpostesting.data.model.diagnostics.DiagnosticsData
import com.example.hpostesting.data.model.patient.DeviceData import com.example.hpostesting.data.model.patient.DeviceData
import com.example.hpostesting.data.repository.Repository import com.example.hpostesting.data.repository.Repository
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject import javax.inject.Inject
@HiltViewModel @HiltViewModel
class DeviceViewModel @Inject constructor( class DeviceViewModel @Inject constructor(

View File

@@ -62,6 +62,7 @@ class DeviceProvisionActivity : AppCompatActivity() {
} }
} }
private val connection = object : ServiceConnection { private val connection = object : ServiceConnection {
override fun onServiceConnected(className: ComponentName, service: IBinder) { override fun onServiceConnected(className: ComponentName, service: IBinder) {
val binder = service as UsbService.UsbServiceBinder val binder = service as UsbService.UsbServiceBinder

View File

@@ -1,6 +1,5 @@
package com.example.hpostesting.presentation.diagnostics package com.example.hpostesting.presentation.diagnostics
import android.annotation.SuppressLint
import android.app.PendingIntent import android.app.PendingIntent
import android.content.BroadcastReceiver import android.content.BroadcastReceiver
import android.content.ComponentName import android.content.ComponentName
@@ -32,7 +31,6 @@ import dagger.hilt.android.AndroidEntryPoint
import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.ActivityDiagnosticsBinding import `in`.sminnovations.hpostesting.databinding.ActivityDiagnosticsBinding
@Suppress("MemberVisibilityCanBePrivate")
@AndroidEntryPoint @AndroidEntryPoint
class DiagnosticsActivity : AppCompatActivity() { class DiagnosticsActivity : AppCompatActivity() {
private lateinit var binding: ActivityDiagnosticsBinding private lateinit var binding: ActivityDiagnosticsBinding
@@ -143,7 +141,6 @@ class DiagnosticsActivity : AppCompatActivity() {
.commit() .commit()
} }
@SuppressLint("MutableImplicitPendingIntent")
private fun requestUserPermission(manager: UsbManager, device: UsbDevice) { private fun requestUserPermission(manager: UsbManager, device: UsbDevice) {
val mPendingIntent: PendingIntent val mPendingIntent: PendingIntent
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S) {

View File

@@ -25,10 +25,12 @@ import com.example.hpostesting.presentation.utils.MyDialogListener
import com.example.hpostesting.presentation.utils.UIUtils import com.example.hpostesting.presentation.utils.UIUtils
import com.google.firebase.crashlytics.ktx.crashlytics import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase import com.google.firebase.ktx.Firebase
import com.google.firebase.perf.ktx.performance
import `in`.sminnovations.hpostesting.R import `in`.sminnovations.hpostesting.R
import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding import `in`.sminnovations.hpostesting.databinding.FragmentHemoCubeReferenceBinding
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.log10 import kotlin.math.log10
import kotlin.math.round
@Suppress("MemberVisibilityCanBePrivate") @Suppress("MemberVisibilityCanBePrivate")
class HemoCubeFragment : Fragment() { class HemoCubeFragment : Fragment() {
@@ -42,6 +44,7 @@ class HemoCubeFragment : Fragment() {
private var resultData: String = "" private var resultData: String = ""
private var currentResultData: String = "" private var currentResultData: String = ""
private var isUsingExistingBuffer = false private var isUsingExistingBuffer = false
private var loginId: String = ""
private var isTestOngoing = false private var isTestOngoing = false
private var startListening = MutableLiveData<Boolean>(false) private var startListening = MutableLiveData<Boolean>(false)
private var led1BufferForDevice = 0.0 private var led1BufferForDevice = 0.0
@@ -56,7 +59,7 @@ class HemoCubeFragment : Fragment() {
private var fittedAbs2 = 0.0 private var fittedAbs2 = 0.0
private var fittedAbs3 = 0.0 private var fittedAbs3 = 0.0
private var fittedAbs4 = 0.0 private var fittedAbs4 = 0.0
private var calculatedPredictedDenovixRatio = 0.0 private var _predictedDenovixRatio = 0.0
private var validationError = false private var validationError = false
private var deviceHardwareId = "" private var deviceHardwareId = ""
private var allErrorMessages = "" private var allErrorMessages = ""
@@ -208,9 +211,9 @@ class HemoCubeFragment : Fragment() {
apply { apply {
DataHolder.hemoCubeTestData?.let { DataHolder.hemoCubeTestData?.let {
currentDeviceData?.coefficients?.let { coefficients -> currentDeviceData?.coefficients?.let { coefficients ->
// val coefficient1 = coefficients[0] val coefficient1 = coefficients[0]
// val coefficient2 = coefficients[1] val coefficient2 = coefficients[1]
// val result = coefficient1 * coefficient2 val result = coefficient1 * coefficient2
} }
} }
isOnline = isNetworkAvailable isOnline = isNetworkAvailable
@@ -374,7 +377,7 @@ class HemoCubeFragment : Fragment() {
hemoCubeViewModel.deviceMessages.postValue(currentResultData) hemoCubeViewModel.deviceMessages.postValue(currentResultData)
when { when {
(resultData.contains("SNE") || resultData.contains("SN"))&& this.testStatusCode < TestStatus.CONFIG_COMPLETED.code -> { resultData.contains("SNE") && this.testStatusCode < TestStatus.CONFIG_COMPLETED.code -> {
processHardwareId(resultData) processHardwareId(resultData)
} }
@@ -391,7 +394,7 @@ class HemoCubeFragment : Fragment() {
} }
} }
(resultData.contains("#SS") || resultData.contains("#SS1")) && this.testStatusCode < TestStatus.SAMPLE_STARTED.code -> { resultData.contains("#SS1") && this.testStatusCode < TestStatus.SAMPLE_STARTED.code -> {
this.testStatusCode = TestStatus.SAMPLE_STARTED.code this.testStatusCode = TestStatus.SAMPLE_STARTED.code
activity?.runOnUiThread { activity?.runOnUiThread {
binding.tvSubtitle4.text = getString(R.string.sample_started) binding.tvSubtitle4.text = getString(R.string.sample_started)
@@ -399,7 +402,7 @@ class HemoCubeFragment : Fragment() {
} }
} }
(resultData.contains("#SC") || resultData.contains("#SC1")) && this.testStatusCode < TestStatus.SAMPLE_COMPLETED.code -> { resultData.contains("#SC1") && this.testStatusCode < TestStatus.SAMPLE_COMPLETED.code -> {
this.testStatusCode = TestStatus.SAMPLE_COMPLETED.code this.testStatusCode = TestStatus.SAMPLE_COMPLETED.code
hemoCubeViewModel.messages.postValue( hemoCubeViewModel.messages.postValue(
getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data)) getString(R.string.sample_completed) + "\n" + getString(R.string.gathering_data))
@@ -579,26 +582,17 @@ class HemoCubeFragment : Fragment() {
binding.btnPlacebuffer.visibility = View.VISIBLE binding.btnPlacebuffer.visibility = View.VISIBLE
} }
hemoCubeViewModel.messages.postValue(getString(R.string.start)) hemoCubeViewModel.messages.postValue(getString(R.string.start))
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
deviceHardwareId = "HCV-000-3001"
allErrorMessages += "Calibration configuration for this device id is not found\n"
}
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
allErrorMessages += "ADC thresholds for this device id are not found\n"
}
} else { } else {
hemoCubeViewModel.messages.postValue("Config error") hemoCubeViewModel.messages.postValue("Config error")
} }
if (!Constants.DEVICE_CONFIGURATION.containsKey(deviceHardwareId)) {
assignDefaultDevice()
allErrorMessages += "Calibration configuration for this device id is not found\n"
}
if (!Constants.BUFFER_INTENSITY_THRESHOLDS.containsKey(deviceHardwareId)) {
allErrorMessages += "ADC thresholds for this device id are not found\n"
}
}
fun assignDefaultDevice() {
deviceHardwareId = "HCV-000-3001"
testStatusCode = TestStatus.CONFIG_COMPLETED.code
activity?.runOnUiThread {
binding.btnPlacebuffer.visibility = View.VISIBLE
}
hemoCubeViewModel.messages.postValue(getString(R.string.start))
} }
fun extractMiddleString(input: String): String? { fun extractMiddleString(input: String): String? {
@@ -702,25 +696,25 @@ class HemoCubeFragment : Fragment() {
val slope1 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(1)?.get(0) val slope1 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(1)?.get(0)
val intercept1 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(1)?.get(1) val intercept1 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(1)?.get(1)
val calculatedHb1 = (led1Average - intercept1!!) / slope1!! val _hb1 = (led3Average - intercept1!!) / slope1!!
val slope2 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(0) val slope2 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(0)
val intercept = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(1) val intercept = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(1)
val calculatedHb2 = (led2Average - intercept!!) / slope2!! val _hb2 = (led4Average - intercept!!) / slope2!!
val slope3 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(2)?.get(0) val slope3 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(2)?.get(0)
val intercept3 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(2)?.get(1) val intercept3 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(2)?.get(1)
val calculatedHb3 = (led3Average - intercept3!!) / slope3!! val _hb3 = (led3Average - intercept3!!) / slope3!!
val slope4 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(0) val slope4 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(0)
val intercept4 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(1) val intercept4 = Constants.DEVICE_HB_PARAMETERS[deviceHardwareId]?.get(3)?.get(1)
val calculatedHb4 = (led4Average - intercept4!!) / slope4!! val _hb4 = (led4Average - intercept4!!) / slope4!!
calculatedPredictedDenovixRatio = fittedAbs3.div(fittedAbs1) _predictedDenovixRatio = fittedAbs3.div(fittedAbs1)
val slope = (led1Average - led2Average) / (435 - 415) val slope = (led1Average - led2Average) / (435 - 415)
val calculatedSlopeRatio = abs(led3Average / slope) val _slopeRatio = abs(led3Average / slope)
val slopeClass = slopeRatioClassification(calculatedSlopeRatio) val slopeClass = slopeRatioClassification(_slopeRatio)
if (fittedAbs1 <= fittedAbs2) { if (fittedAbs1 <= fittedAbs2) {
validationError = true validationError = true
@@ -739,7 +733,7 @@ class HemoCubeFragment : Fragment() {
} }
} }
if ((led1Average < 0.7 || led2Average < 0.7 || led3Average < 0.7 || led4Average < 0.7) && calculatedSlopeRatio > 35.0) { if ((led1Average < 0.7 || led2Average < 0.7 || led3Average < 0.7 || led4Average < 0.7) && _slopeRatio > 35.0) {
validationError = true validationError = true
activity?.runOnUiThread { activity?.runOnUiThread {
binding.errorMessage.text = "Severely Low Hb. Repeat test with 12 ul in 2 ml Buffer" binding.errorMessage.text = "Severely Low Hb. Repeat test with 12 ul in 2 ml Buffer"
@@ -775,12 +769,12 @@ class HemoCubeFragment : Fragment() {
this.abs2 = fittedAbs2 this.abs2 = fittedAbs2
this.abs3 = fittedAbs3 this.abs3 = fittedAbs3
this.abs4 = fittedAbs4 this.abs4 = fittedAbs4
this.hb3 = calculatedHb3 this.hb3 = _hb3
this.hb4 = calculatedHb4 this.hb4 = _hb4
this.deviceRatio = deviceRatio this.deviceRatio = deviceRatio
this.calculatedRatio = calculateRatio(deviceRatio) this.calculatedRatio = calculateRatio(deviceRatio)
this.predictedDenovixRatio = calculatedPredictedDenovixRatio this.predictedDenovixRatio = _predictedDenovixRatio
this.slopeRatio = calculatedSlopeRatio this.slopeRatio = _slopeRatio
this.coefficients = currentDeviceData?.coefficients?.get(0) this.coefficients = currentDeviceData?.coefficients?.get(0)
.toString() + ", " + currentDeviceData?.coefficients?.get(1).toString() .toString() + ", " + currentDeviceData?.coefficients?.get(1).toString()
this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio) this.prdClassification = absorbanceBasedClassification(predictedDenovixRatio)
@@ -789,7 +783,7 @@ class HemoCubeFragment : Fragment() {
this.classificationResult = deviceRatioClass //findResult(calculatedRatio) this.classificationResult = deviceRatioClass //findResult(calculatedRatio)
hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n") hemoCubeViewModel.messages.postValue("${this.deviceRatioClass} ${if (led4Average < 0.17) " - Low Hb" else ""}\n")
if (DataHolder.hemoCubeTestData?.testType == "HB") if (DataHolder.hemoCubeTestData?.testType == "HB")
hemoCubeViewModel.messages.postValue("HB: $calculatedHb4") hemoCubeViewModel.messages.postValue("HB: $_hb4")
this.errorMessages = allErrorMessages this.errorMessages = allErrorMessages
this.resultData = deviceLog this.resultData = deviceLog
this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString() this.batteryLevel = hemoCubeViewModel.getBatteryLevel().toString()

View File

@@ -3,6 +3,7 @@ package com.example.hpostesting.presentation.hemocube
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.SharedPreferences
import android.os.BatteryManager import android.os.BatteryManager
import android.util.Log import android.util.Log
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
@@ -34,6 +35,7 @@ import com.example.hpostesting.data.model.patient.toHemoCubeTestData
import com.example.hpostesting.data.model.updates.CheckUpdateRequest import com.example.hpostesting.data.model.updates.CheckUpdateRequest
import com.example.hpostesting.data.model.updates.CheckUpdateResponse import com.example.hpostesting.data.model.updates.CheckUpdateResponse
import com.example.hpostesting.data.model.updates.DeviceUpdateRequest import com.example.hpostesting.data.model.updates.DeviceUpdateRequest
import com.example.hpostesting.data.repository.DatabaseRepository
import com.example.hpostesting.data.repository.Repository import com.example.hpostesting.data.repository.Repository
import com.example.hpostesting.domain.CheckUpdateWorker import com.example.hpostesting.domain.CheckUpdateWorker
import com.example.hpostesting.domain.LogFileManager import com.example.hpostesting.domain.LogFileManager
@@ -45,6 +47,7 @@ import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.ResponseBody import okhttp3.ResponseBody
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Calendar import java.util.Calendar
import java.util.Date
import java.util.Locale import java.util.Locale
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject

View File

@@ -2,6 +2,7 @@ package com.example.hpostesting.presentation.testRight
import android.content.Context import android.content.Context
import android.net.Uri import android.net.Uri
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
@@ -25,6 +26,7 @@ import com.example.hpostesting.domain.TestRightResultCalculation
import com.example.hpostesting.util.MyUtils import com.example.hpostesting.util.MyUtils
import com.google.firebase.storage.FirebaseStorage import com.google.firebase.storage.FirebaseStorage
import dagger.hilt.android.lifecycle.HiltViewModel import dagger.hilt.android.lifecycle.HiltViewModel
import dagger.hilt.android.scopes.ViewModelScoped
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.tasks.await import kotlinx.coroutines.tasks.await
import java.io.File import java.io.File

View File

@@ -34,7 +34,7 @@ class UsbService : Service() {
fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) { fun connect(driver: UsbSerialDriver, connection: UsbDeviceConnection) {
mPort = driver.ports[0] // Most devices have just one port (port 0) mPort = driver.ports[0] // Most devices have just one port (port 0)
mPort.open(connection) mPort.open(connection)
mPort.setParameters(9600, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE) mPort.setParameters(115200, 8, UsbSerialPort.STOPBITS_1, UsbSerialPort.PARITY_NONE)
isUsbConnected = true isUsbConnected = true
Log.d(TAG, "My Usb Connected ${mPort.driver}") Log.d(TAG, "My Usb Connected ${mPort.driver}")

View File

@@ -83,7 +83,7 @@
android:id="@+id/btn_deviceProvision" android:id="@+id/btn_deviceProvision"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:visibility="visible" android:visibility="gone"
android:layout_marginHorizontal="16dp" android:layout_marginHorizontal="16dp"
android:layout_marginTop="24dp" android:layout_marginTop="24dp"
android:clickable="false" android:clickable="false"
@@ -92,7 +92,7 @@
app:cornerRadius="16dp" app:cornerRadius="16dp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/btn_deviceInfo" /> app:layout_constraintTop_toBottomOf="@id/btn_calibration" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/btn_deviceInfo" android:id="@+id/btn_deviceInfo"

View File

@@ -214,7 +214,7 @@
android:layout_width="414dp" android:layout_width="414dp"
android:layout_height="201dp" android:layout_height="201dp"
android:gravity="center" android:gravity="center"
android:text="no device message" android:text="#SS1\n#SC1"
android:textColor="@color/black" android:textColor="@color/black"
android:textSize="11sp" android:textSize="11sp"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

View File

@@ -1,20 +1,27 @@
package com.example.hpostesting package com.example.hpostesting
import android.content.Context import android.content.Context
import android.os.Build
import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.work.Configuration
import androidx.work.testing.SynchronousExecutor
import androidx.work.testing.WorkManagerTestInitHelper
import com.example.hpostesting.data.Result import com.example.hpostesting.data.Result
import com.example.hpostesting.data.model.login.LoginResponse import com.example.hpostesting.data.model.login.LoginResponse
import com.example.hpostesting.data.repository.Repository import com.example.hpostesting.data.repository.Repository
import com.example.hpostesting.domain.LogFileManager import com.example.hpostesting.domain.LogFileManager
import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel import com.example.hpostesting.presentation.hemocube.HemoCubeViewModel
import com.example.hpostesting.util.TestCoroutineRule import com.example.hpostesting.util.TestCoroutineRule
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every import io.mockk.every
import io.mockk.impl.annotations.MockK import io.mockk.impl.annotations.MockK
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import junit.framework.TestCase
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.junit.After import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
@@ -22,34 +29,35 @@ import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config import org.robolectric.annotation.Config
import java.io.File
@RunWith(RobolectricTestRunner::class) //@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE) //@Config(manifest = Config.NONE)
@ExperimentalCoroutinesApi //@ExperimentalCoroutinesApi
class HemocubeViewModelTest { //class HemocubeViewModelTest {
//
@get:Rule // @get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule() // val instantTaskExecutorRule = InstantTaskExecutorRule()
//
@get:Rule // @get:Rule
val coroutineRule = TestCoroutineRule() // val coroutineRule = TestCoroutineRule()
//
@MockK(relaxed = true) // @MockK(relaxed = true)
lateinit var repository: Repository // lateinit var repository: Repository
//
@MockK(relaxed = true) // @MockK(relaxed = true)
lateinit var logFileManager: LogFileManager // lateinit var logFileManager: LogFileManager
//
@MockK(relaxed = true) // @MockK(relaxed = true)
lateinit var context: Context // lateinit var context: Context
//
@MockK(relaxed = true) // @MockK(relaxed = true)
lateinit var observer: Observer<Result<LoginResponse>> // lateinit var observer: Observer<Result<LoginResponse>>
//
private lateinit var viewModel: HemoCubeViewModel // private lateinit var viewModel: HemoCubeViewModel
//
@Before // @Before
fun setup() { // fun setup() {
// MockKAnnotations.init(this) // MockKAnnotations.init(this)
// //
// val config = Configuration.Builder() // val config = Configuration.Builder()
@@ -70,34 +78,13 @@ class HemocubeViewModelTest {
// context // context
// ) // )
// viewModel.loginResponse.observeForever(observer) // viewModel.loginResponse.observeForever(observer)
} // }
//
@After // @After
fun teardown() { // fun teardown() {
// viewModel.loginResponse.removeObserver(observer) // viewModel.loginResponse.removeObserver(observer)
} // }
//
@Test
fun `testAddNumbers in HemocubeViewModelTest`() {
// Create a mock of the Calculator class using Mockito-Kotlin
val calculatorMock = mockk<Calculator>()
// Define the behavior of the add method on the mock
every { calculatorMock.add(2, 3) } returns 5
// Create an instance of MathApplication with the mock Calculator
val mathApplication = MathApplication(calculatorMock)
// Perform the test using the MathApplication
val result = mathApplication.addNumbers(2, 3)
// Verify that the add method of the mock was called with the correct parameters
verify { calculatorMock.add(2, 3) }
// Verify the result of the test
TestCase.assertEquals(5, result)
}
// @Test // @Test
// fun `login() should update LiveData with success`() = coroutineRule.runBlockingTest { // fun `login() should update LiveData with success`() = coroutineRule.runBlockingTest {
// //
@@ -137,7 +124,7 @@ class HemocubeViewModelTest {
// viewModel.uploadLogs() // viewModel.uploadLogs()
// //
// // Assert // // Assert
// verify { observer.onChanged(response as Result<LoginResponse>) } // verify { observer.onChanged(response) }
// } // }
// //
// @Test // @Test
@@ -154,4 +141,4 @@ class HemocubeViewModelTest {
// // Assert // // Assert
// verify { observer.onChanged(response) } // verify { observer.onChanged(response) }
// } // }
} //}

View File

@@ -1,15 +0,0 @@
package com.example.hpostesting
class Calculator {
fun add(a: Int, b: Int): Int {
return a + b
}
}
class MathApplication(private val calculator: Calculator) {
fun addNumbers(a: Int, b: Int): Int {
return calculator.add(a, b)
}
}

View File

@@ -1,31 +0,0 @@
package com.example.hpostesting
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import junit.framework.TestCase.assertEquals
import org.junit.Test
class MathApplicationTest {
@Test
fun testAddNumbers() {
// Create a mock of the Calculator class using Mockito-Kotlin
val calculatorMock = mockk<Calculator>()
// Define the behavior of the add method on the mock
every { calculatorMock.add(2, 3) } returns 5
// Create an instance of MathApplication with the mock Calculator
val mathApplication = MathApplication(calculatorMock)
// Perform the test using the MathApplication
val result = mathApplication.addNumbers(2, 3)
// Verify that the add method of the mock was called with the correct parameters
verify { calculatorMock.add(2, 3) }
// Verify the result of the test
assertEquals(5, result)
}
}

View File

@@ -1,77 +0,0 @@
package com.example.hpostesting
import android.content.Context
import android.net.ConnectivityManager
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import junit.framework.TestCase
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
@RunWith(MockitoJUnitRunner::class)
class NetworkStatusLiveDataTest {
@get:Rule
val instantTaskExecutorRule = InstantTaskExecutorRule()
@Mock
private lateinit var mockContext: Context
@Mock
private lateinit var mockConnectivityManager: ConnectivityManager
@Before
fun setUp() {
// mockContext = ApplicationProvider.getApplicationContext<Context>()
// mockConnectivityManager = mockContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
}
@Test
fun testAddNumbers() {
// Create a mock of the Calculator class using Mockito-Kotlin
val calculatorMock = mockk<Calculator>()
// Define the behavior of the add method on the mock
every { calculatorMock.add(2, 3) } returns 5
// Create an instance of MathApplication with the mock Calculator
val mathApplication = MathApplication(calculatorMock)
// Perform the test using the MathApplication
val result = mathApplication.addNumbers(2, 3)
// Verify that the add method of the mock was called with the correct parameters
verify { calculatorMock.add(2, 3) }
// Verify the result of the test
TestCase.assertEquals(5, result)
}
// @Test
// fun testNetworkStatusLiveData() {
// // Assuming mockConnectivityManager is a mocked ConnectivityManager instance
// val mockNetwork = mock(Network::class.java)
// val mockNetworkCapabilities = mock(NetworkCapabilities::class.java)
//
// // Define desired capabilities
// `when`(mockNetworkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)).thenReturn(true)
// `when`(mockNetworkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)).thenReturn(true)
//
// // Set up network to return mocked capabilities
// `when`(mockConnectivityManager.activeNetwork).thenReturn(mockNetwork)
// `when`(mockConnectivityManager.getNetworkCapabilities(mockNetwork)).thenReturn(mockNetworkCapabilities)
//
// // Act
// val networkStatusLiveData = NetworkStatusLiveData(mockContext)
// val isConnected = networkStatusLiveData.value
//
// // Assert
// assertTrue("Network should be connected", isConnected!!)
// }
}