├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-mdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-xxxhdpi │ │ │ │ ├── ic_launcher.webp │ │ │ │ └── ic_launcher_round.webp │ │ │ ├── mipmap-anydpi-v26 │ │ │ │ ├── ic_launcher.xml │ │ │ │ └── ic_launcher_round.xml │ │ │ ├── drawable │ │ │ │ ├── ic_baseline_smartphone_24.xml │ │ │ │ ├── ic_baseline_contact_support_24.xml │ │ │ │ ├── ic_baseline_phonelink_ring_24.xml │ │ │ │ ├── ic_baseline_phone_24.xml │ │ │ │ ├── ic_baseline_phonelink_lock_24.xml │ │ │ │ ├── ic_baseline_settings_24.xml │ │ │ │ └── ic_launcher_background.xml │ │ │ ├── values │ │ │ │ ├── themes.xml │ │ │ │ ├── colors.xml │ │ │ │ └── strings.xml │ │ │ ├── values-night │ │ │ │ └── themes.xml │ │ │ ├── drawable-v24 │ │ │ │ └── ic_launcher_foreground.xml │ │ │ └── layout │ │ │ │ ├── activity_welcome.xml │ │ │ │ └── activity_home.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── ape │ │ │ │ └── apps │ │ │ │ └── sample │ │ │ │ └── baypilot │ │ │ │ ├── App.kt │ │ │ │ ├── util │ │ │ │ ├── extension │ │ │ │ │ └── ImageView.kt │ │ │ │ ├── sharedpreferences │ │ │ │ │ └── SharedPreferenceLiveData.kt │ │ │ │ ├── boot │ │ │ │ │ └── BootReceiver.kt │ │ │ │ ├── firebase │ │ │ │ │ ├── FirebaseDatabaseManager.kt │ │ │ │ │ └── BayPilotFirebaseMessagingService.kt │ │ │ │ ├── alarm │ │ │ │ │ ├── AlarmReceiver.kt │ │ │ │ │ └── AlarmSetter.kt │ │ │ │ ├── date │ │ │ │ │ └── DateTimeHelper.kt │ │ │ │ ├── dlc │ │ │ │ │ ├── DeviceLockServiceProtocol.kt │ │ │ │ │ └── DeviceLockMessenger.kt │ │ │ │ ├── network │ │ │ │ │ └── InternetConnectivity.kt │ │ │ │ └── worker │ │ │ │ │ └── DatabaseSyncWorker.kt │ │ │ │ ├── data │ │ │ │ ├── FieldNames.kt │ │ │ │ ├── creditplan │ │ │ │ │ └── CreditPlanInfo.kt │ │ │ │ └── sharedprefs │ │ │ │ │ └── SharedPreferencesManager.kt │ │ │ │ └── ui │ │ │ │ ├── home │ │ │ │ ├── HomeViewModel.kt │ │ │ │ └── HomeActivity.kt │ │ │ │ └── welcome │ │ │ │ ├── WelcomeActivity.kt │ │ │ │ └── WelcomeViewModel.kt │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── ape │ │ │ └── apps │ │ │ └── sample │ │ │ └── baypilot │ │ │ └── ExampleUnitTest.kt │ └── androidTest │ │ └── java │ │ └── com │ │ └── ape │ │ └── apps │ │ └── sample │ │ └── baypilot │ │ └── ExampleInstrumentedTest.kt ├── proguard-rules.pro └── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── docs └── imgs │ └── kioskapprefere--ugvo40yvr9l.png ├── settings.gradle ├── gradle.properties ├── CONTRIBUTING.md ├── gradlew.bat ├── README.md ├── bay-pilot └── .idea │ └── workspace.xml ├── gradlew └── LICENSE.md /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /docs/imgs/kioskapprefere--ugvo40yvr9l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/docs/imgs/kioskapprefere--ugvo40yvr9l.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/kiosk-app-reference-implementation/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Nov 08 05:07:09 UTC 2021 2 | distributionBase=GRADLE_USER_HOME 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/App.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot 18 | 19 | import android.app.Application 20 | 21 | class App : Application() { 22 | 23 | companion object { 24 | private const val TAG = "BayPilotApplication" 25 | } 26 | 27 | } -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | dependencyResolutionManagement { 16 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 17 | repositories { 18 | google() 19 | mavenCentral() 20 | jcenter() // Warning: this repository is going to shut down soon 21 | } 22 | } 23 | rootProject.name = "Bay Pilot" 24 | include ':app' 25 | -------------------------------------------------------------------------------- /app/src/test/java/com/ape/apps/sample/baypilot/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot 18 | 19 | import org.junit.Assert.assertEquals 20 | import org.junit.Test 21 | 22 | /** 23 | * Example local unit test, which will execute on the development machine (host). 24 | * 25 | * See [testing documentation](http://d.android.com/tools/testing). 26 | */ 27 | class ExampleUnitTest { 28 | @Test 29 | fun addition_isCorrect() { 30 | assertEquals(4, 2 + 2) 31 | } 32 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_smartphone_24.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/util/extension/ImageView.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.util.extension 18 | 19 | import android.content.res.ColorStateList 20 | import android.widget.ImageView 21 | import androidx.annotation.ColorRes 22 | import androidx.core.content.ContextCompat 23 | import androidx.core.widget.ImageViewCompat 24 | 25 | fun ImageView.setTint(@ColorRes colorRes: Int) { 26 | ImageViewCompat.setImageTintList(this, ColorStateList.valueOf(ContextCompat.getColor(context, colorRes))) 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/data/FieldNames.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.data 18 | 19 | object FieldNames { 20 | 21 | const val imei = "Imei" 22 | const val firebaseToken = "FirebaseToken" 23 | 24 | object CreditPlanInfo { 25 | const val plan = "Plan" 26 | 27 | object Plan { 28 | const val totalAmount = "Total Amount" 29 | const val dueDate = "Due Date" 30 | const val nextInstallmentAmount = "Next Installment Amount" 31 | const val planType = "Plan Type" 32 | const val totalPaidAmount = "Total Paid Amount" 33 | } 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app"s APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_contact_support_24.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_phonelink_ring_24.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_phone_24.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_phonelink_lock_24.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ape/apps/sample/baypilot/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot 18 | 19 | import androidx.test.ext.junit.runners.AndroidJUnit4 20 | import androidx.test.platform.app.InstrumentationRegistry 21 | import org.junit.Assert.assertEquals 22 | import org.junit.Test 23 | import org.junit.runner.RunWith 24 | 25 | /** 26 | * Instrumented test, which will execute on an Android device. 27 | * 28 | * See [testing documentation](http://d.android.com/tools/testing). 29 | */ 30 | @RunWith(AndroidJUnit4::class) 31 | class ExampleInstrumentedTest { 32 | @Test 33 | fun useAppContext() { 34 | // Context of the app under test. 35 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 36 | assertEquals("com.ape.apps.sample.baypilot", appContext.packageName) 37 | } 38 | } -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #FFBB86FC 20 | #FF6200EE 21 | #FF3700B3 22 | #FF03DAC5 23 | #FF018786 24 | #FF000000 25 | #FFFFFFFF 26 | 27 | #2196F3 28 | #1976D2 29 | #388E3C 30 | #EEEEEE 31 | #616161 32 | #F44336 33 | 34 | @color/blue_500 35 | @color/blue_700 36 | @color/green_700 37 | @color/grey_700 38 | @color/grey_300 39 | @color/red_500 40 | 41 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to become a contributor and submit your own code 2 | 3 | ## Contributor License Agreements 4 | 5 | We'd love to accept your sample apps and patches! Before we can take them, we 6 | have to jump a couple of legal hurdles. 7 | 8 | Please fill out either the individual or corporate Contributor License Agreement 9 | (CLA). 10 | 11 | * If you are an individual writing original source code and you're sure you 12 | own the intellectual property, then you'll need to sign an [individual CLA](https://developers.google.com/open-source/cla/individual). 13 | * If you work for a company that wants to allow you to contribute your work, 14 | then you'll need to sign a [corporate CLA](https://developers.google.com/open-source/cla/corporate). 15 | 16 | Follow either of the two links above to access the appropriate CLA and 17 | instructions for how to sign and return it. Once we receive it, we'll be able to 18 | accept your pull requests. 19 | 20 | ## Contributing A Patch 21 | 22 | 1. Submit an issue describing your proposed change to the repo in question. 23 | 2. The repo owner will respond to your issue promptly. 24 | 3. If your proposed change is accepted, and you haven't already done so, sign a 25 | Contributor License Agreement (see details above). 26 | 4. Fork the desired repo, develop and test your code changes. 27 | 5. Ensure that your code adheres to the existing style in the sample to which 28 | you are contributing. Refer to the 29 | [Android Code Style Guide](https://source.android.com/source/code-style.html) for the 30 | recommended coding standards for this organization. 31 | 6. Ensure that your code has an appropriate set of unit tests which all pass. 32 | 7. Submit a pull request. 33 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_settings_24.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/util/sharedpreferences/SharedPreferenceLiveData.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.util.sharedpreferences 18 | 19 | import android.content.SharedPreferences 20 | import androidx.lifecycle.LiveData 21 | 22 | abstract class SharedPreferenceLiveData( 23 | val sharedPrefs: SharedPreferences, 24 | private val key: String, 25 | private val defValue: T 26 | ) : LiveData() { 27 | 28 | private val preferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key -> 29 | if (key == this.key) { 30 | value = getValueFromPreferences(key, defValue) 31 | } 32 | } 33 | 34 | abstract fun getValueFromPreferences(key: String, defValue: T): T 35 | 36 | override fun onActive() { 37 | super.onActive() 38 | 39 | value = getValueFromPreferences(key, defValue) 40 | sharedPrefs.registerOnSharedPreferenceChangeListener(preferenceChangeListener) 41 | } 42 | 43 | override fun onInactive() { 44 | sharedPrefs.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener) 45 | super.onInactive() 46 | } 47 | } 48 | 49 | class SharedPreferenceIntLiveData(sharedPrefs: SharedPreferences, key: String, defValue: Int) : 50 | SharedPreferenceLiveData(sharedPrefs, key, defValue) { 51 | override fun getValueFromPreferences(key: String, defValue: Int): Int = sharedPrefs.getInt(key, defValue) 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/ui/home/HomeViewModel.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.ui.home 18 | 19 | import android.content.Context 20 | import android.util.Log 21 | import androidx.lifecycle.* 22 | import com.ape.apps.sample.baypilot.data.creditplan.CreditPlanInfo 23 | import com.ape.apps.sample.baypilot.data.sharedprefs.SharedPreferencesManager 24 | import com.ape.apps.sample.baypilot.util.sharedpreferences.SharedPreferenceIntLiveData 25 | import kotlinx.coroutines.flow.collect 26 | import kotlinx.coroutines.launch 27 | 28 | class HomeViewModel : ViewModel() { 29 | 30 | companion object { 31 | private const val TAG = "BayPilotHomeViewModel" 32 | } 33 | 34 | private val _creditPlanInfo = MutableLiveData() 35 | val creditPlanInfo: LiveData 36 | get() = _creditPlanInfo 37 | 38 | fun observeCreditPlanInfo(context: Context) { 39 | Log.d(TAG, "observeCreditPlanInfo() called with: context") 40 | 41 | val sharedPreferencesManager = SharedPreferencesManager(context) 42 | 43 | viewModelScope.launch { 44 | SharedPreferenceIntLiveData( 45 | sharedPreferencesManager.sharedPreferences, 46 | SharedPreferencesManager.KEY_CREDIT_PLAN_SAVE_ID, 47 | 0 48 | ).asFlow().collect { 49 | Log.d(TAG, "observeCreditPlanInfo() asFlow().collect called with: creditPlanSaveId = $it") 50 | 51 | _creditPlanInfo.value = sharedPreferencesManager.readCreditPlan() 52 | } 53 | } 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/util/boot/BootReceiver.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.util.boot 18 | 19 | import android.content.BroadcastReceiver 20 | import android.content.Context 21 | import android.content.Intent 22 | import android.util.Log 23 | import com.ape.apps.sample.baypilot.data.sharedprefs.SharedPreferencesManager 24 | import com.ape.apps.sample.baypilot.util.alarm.AlarmSetter 25 | import com.ape.apps.sample.baypilot.util.worker.DatabaseSyncWorker 26 | 27 | // Class to reset LOCK/Notification alarms after phone is restarted. 28 | // When phone is restarted it loses all pending alarms so we need to Register for BootReceiver and set the alarms again. 29 | class BootReceiver : BroadcastReceiver() { 30 | 31 | companion object { 32 | private const val TAG = "BayPilotBootReceiver" 33 | } 34 | 35 | override fun onReceive(context: Context, intent: Intent?) { 36 | // Get CreditPlanInfo stored locally in device in sharedPreferences. 37 | val sharedPreferencesManager = SharedPreferencesManager(context) 38 | val creditPlanInfo = sharedPreferencesManager.readCreditPlan() ?: return 39 | 40 | // Set Alarms 41 | Log.d(TAG, "Setting Alarms after boot") 42 | val alarmSetter = AlarmSetter(context) 43 | alarmSetter.setCreditAlarms(creditPlanInfo) 44 | 45 | // Schedule a sync to server when Internet connectivity available to make 46 | // sure we don't lose any update in case phone was switched on after long time. 47 | DatabaseSyncWorker.scheduleSync(context) 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 23 | 24 | 25 | 31 | 34 | 37 | 38 | 39 | 40 | 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/data/creditplan/CreditPlanInfo.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.data.creditplan 18 | 19 | import com.google.gson.Gson 20 | 21 | enum class CreditPlanType { 22 | MONTHLY, WEEKLY, DAILY; 23 | 24 | companion object { 25 | fun toString(creditPlanType: CreditPlanType?): String? { 26 | return when (creditPlanType) { 27 | MONTHLY -> "MONTHLY" 28 | WEEKLY -> "WEEKLY" 29 | DAILY -> "DAILY" 30 | else -> null 31 | } 32 | } 33 | 34 | fun toCreditPlanType(planType: String?): CreditPlanType? { 35 | return when (planType) { 36 | "DAILY" -> DAILY 37 | "WEEKLY" -> WEEKLY 38 | "MONTHLY" -> MONTHLY 39 | else -> null 40 | } 41 | } 42 | } 43 | } 44 | 45 | // Class to store all details related to device credit plan. 46 | // TODO: Currently it has only few essential members for testing, add others. 47 | class CreditPlanInfo( 48 | val totalAmount: Int? = 0, 49 | val totalPaidAmount: Int? = 0, 50 | val dueDate: String? = null, 51 | val nextDueAmount: Int? = 0, 52 | val planType: CreditPlanType? = null 53 | ) { 54 | 55 | companion object { 56 | // Serialize a single object. 57 | fun serializeToJson(cpi: CreditPlanInfo?): String? { 58 | val gson = Gson() 59 | return gson.toJson(cpi) 60 | } 61 | 62 | // Deserialize to single object. 63 | fun deserializeFromJson(jsonString: String?): CreditPlanInfo? { 64 | val gson = Gson() 65 | return gson.fromJson(jsonString, CreditPlanInfo::class.java) 66 | } 67 | } 68 | 69 | fun toDebugString(): String { 70 | return "Credit Plan details: Due Date = $dueDate, Total device cost = $totalAmount, " + 71 | "Amount paid till now: $totalPaidAmount Next installment due = $nextDueAmount, Plan type = $planType" 72 | } 73 | 74 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ape/apps/sample/baypilot/util/firebase/FirebaseDatabaseManager.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.ape.apps.sample.baypilot.util.firebase 18 | 19 | import android.content.Context 20 | import android.util.Log 21 | import com.ape.apps.sample.baypilot.data.FieldNames 22 | import com.ape.apps.sample.baypilot.data.creditplan.CreditPlanInfo 23 | import com.ape.apps.sample.baypilot.data.sharedprefs.SharedPreferencesManager 24 | import com.google.firebase.database.FirebaseDatabase 25 | import kotlinx.coroutines.tasks.await 26 | 27 | // Class to connect app to Realtime Database. 28 | // Used to fetch credit plan details for device IMEI and store FCM token device in database. 29 | class FirebaseDatabaseManager { 30 | 31 | companion object { 32 | private const val TAG = "BayPilotFirebaseDatabaseManager" 33 | } 34 | 35 | private val firebaseDatabase = FirebaseDatabase.getInstance() 36 | 37 | // Read credit plan details from Database. 38 | suspend fun readCreditPlanInfoFromDatabase(context: Context, deviceImei: String): CreditPlanInfo? { 39 | Log.d(TAG, "readCreditPlanInfoFromDatabase() called with: context, deviceImei = $deviceImei") 40 | 41 | return try { 42 | val result = firebaseDatabase.getReference(deviceImei).get().await() 43 | 44 | result?.child(FieldNames.CreditPlanInfo.plan)?.getValue(CreditPlanInfo::class.java) 45 | } catch (exception: Exception) { 46 | Log.d( 47 | TAG, 48 | "readCreditPlanInfoFromDatabase firebaseDatabase.getReference or result?.child called with exception = $exception" 49 | ) 50 | 51 | SharedPreferencesManager(context).setCreditPlanInvalid() 52 | null 53 | } 54 | } 55 | 56 | // Store FCM token in database under device imei. 57 | fun storeFcmToken(token: String, imei: String) { 58 | val imeiRef = firebaseDatabase.getReference(imei) 59 | imeiRef.child(FieldNames.firebaseToken).setValue(token) 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_welcome.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 24 | 25 | 36 | 37 |