├── 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
│ │ │ ├── drawable
│ │ │ │ ├── bg_task.xml
│ │ │ │ ├── bg_button.xml
│ │ │ │ ├── bg_edit.xml
│ │ │ │ ├── bg_botton_sheet.xml
│ │ │ │ ├── ic_add.xml
│ │ │ │ ├── bg_bottom_shet.xml
│ │ │ │ ├── ic_menu.xml
│ │ │ │ ├── ic_send.xml
│ │ │ │ ├── ic_next.xml
│ │ │ │ ├── ic_back.xml
│ │ │ │ ├── bg_degrade_buttom.xml
│ │ │ │ ├── ic_logout.xml
│ │ │ │ ├── container_header.xml
│ │ │ │ ├── ic_refresh.xml
│ │ │ │ ├── ic_search.xml
│ │ │ │ ├── ic_auto_graph.xml
│ │ │ │ ├── ic_calculate.xml
│ │ │ │ ├── container_resultado_ui.xml
│ │ │ │ ├── ic_logoemdiabetes.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── menu
│ │ │ │ └── menu_main.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_splash.xml
│ │ │ │ ├── fragment_base.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_diet.xml
│ │ │ │ ├── fragment_medication.xml
│ │ │ │ ├── bottom_sheet.xml
│ │ │ │ ├── fragment_home.xml
│ │ │ │ ├── fragment_glycemia.xml
│ │ │ │ ├── fragment_recover_account.xml
│ │ │ │ ├── fragment_login.xml
│ │ │ │ ├── fragment_register.xml
│ │ │ │ ├── item_adapter.xml
│ │ │ │ ├── fragment_form_medication.xml
│ │ │ │ ├── fragment_form_diet.xml
│ │ │ │ ├── fragment_calc_insulina.xml
│ │ │ │ └── fragment_form_glycemia.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── navigation
│ │ │ │ └── main_graph.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── digo
│ │ │ │ └── emdiabetes
│ │ │ │ ├── model
│ │ │ │ ├── Diet.kt
│ │ │ │ ├── Medication.kt
│ │ │ │ ├── Glycemia.kt
│ │ │ │ └── CalcularInsulina.kt
│ │ │ │ ├── helper
│ │ │ │ ├── BaseFragment.kt
│ │ │ │ ├── FirebaseHelper.kt
│ │ │ │ └── Extensions.kt
│ │ │ │ └── ui
│ │ │ │ ├── MainActivity.kt
│ │ │ │ ├── adapter
│ │ │ │ ├── ViewPagerAdapter.kt
│ │ │ │ ├── DietAdapter.kt
│ │ │ │ ├── MedicationAdapter.kt
│ │ │ │ └── GlycemiaAdapter.kt
│ │ │ │ ├── SplashFragment.kt
│ │ │ │ ├── HomeFragment.kt
│ │ │ │ ├── auth
│ │ │ │ ├── RecoverAccountFragment.kt
│ │ │ │ ├── RegisterFragment.kt
│ │ │ │ └── LoginFragment.kt
│ │ │ │ ├── form
│ │ │ │ ├── FormDietFragment.kt
│ │ │ │ ├── FormMedicationFragment.kt
│ │ │ │ └── FormGlycemiaFragment.kt
│ │ │ │ ├── CalcInsulinaFragment.kt
│ │ │ │ ├── DietFragment.kt
│ │ │ │ ├── MedicationFragment.kt
│ │ │ │ └── GlycemiaFragment.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── digo
│ │ │ └── emdiabetes
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── digo
│ │ └── emdiabetes
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
├── google-services.json
└── build.gradle
├── .idea
├── .gitignore
├── compiler.xml
├── vcs.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── LICENSE
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Rodrigo-Sarmento/EmDiabetes/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/Rodrigo-Sarmento/EmDiabetes/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/Rodrigo-Sarmento/EmDiabetes/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/Rodrigo-Sarmento/EmDiabetes/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/Rodrigo-Sarmento/EmDiabetes/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_task.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_edit.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Sep 01 15:20:23 BRT 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_botton_sheet.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_bottom_shet.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_send.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_next.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_back.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | maven { url 'https://jitpack.io' }
14 | }
15 | }
16 | rootProject.name = "EmDiabetes"
17 | include ':app'
18 |
--------------------------------------------------------------------------------
/app/src/test/java/com/digo/emdiabetes/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/model/Diet.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.model
2 |
3 | import android.os.Parcelable
4 | import com.digo.emdiabetes.helper.FirebaseHelper
5 | import kotlinx.parcelize.Parcelize
6 |
7 | @Parcelize
8 | data class Diet(
9 | var id: String = "",
10 | var refeicao: String = "",
11 | var alimento: String = "",
12 | ) : Parcelable {
13 | init {
14 | this.id = FirebaseHelper.getDatabase().push().key ?: ""
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/model/Medication.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.model
2 |
3 | import android.os.Parcelable
4 | import com.digo.emdiabetes.helper.FirebaseHelper
5 | import kotlinx.parcelize.Parcelize
6 |
7 | @Parcelize
8 | data class Medication(
9 | var id: String = "",
10 | var nome: String = "",
11 | var dosagem: String = ""
12 | ) : Parcelable {
13 | init {
14 | this.id = FirebaseHelper.getDatabase().push().key ?: ""
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
8 |
9 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_degrade_buttom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_logout.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/container_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_refresh.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/model/Glycemia.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.model
2 |
3 | import android.os.Parcelable
4 | import com.digo.emdiabetes.helper.FirebaseHelper
5 | import kotlinx.parcelize.Parcelize
6 |
7 | @Parcelize
8 | data class Glycemia(
9 | var id: String = "",
10 | var glicemia: String = "",
11 | var descricao: String = "",
12 | var dia: Int = 0,
13 | var mes: Int = 0,
14 | var ano: Int = 0
15 | ) : Parcelable {
16 | init {
17 | this.id = FirebaseHelper.getDatabase().push().key ?: ""
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_splash.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_base.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/helper/BaseFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.helper
2 |
3 | import android.content.Context
4 | import android.view.inputmethod.InputMethodManager
5 | import androidx.fragment.app.Fragment
6 |
7 | open class BaseFragment : Fragment() {
8 |
9 | fun hideKeyboard() {
10 | val view = activity?.currentFocus
11 | if (view != null) {
12 | val imm = activity?.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
13 | imm.hideSoftInputFromWindow(view.windowToken, 0)
14 | }
15 | }
16 |
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_auto_graph.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_calculate.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/container_resultado_ui.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
12 |
13 |
14 |
15 | -
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/digo/emdiabetes/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.digo.emdiabetes", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import androidx.navigation.fragment.NavHostFragment
6 | import com.digo.emdiabetes.R
7 | import com.digo.emdiabetes.databinding.ActivityMainBinding
8 | import com.digo.emdiabetes.helper.initToolbar
9 |
10 | class MainActivity : AppCompatActivity() {
11 |
12 | private lateinit var binding: ActivityMainBinding
13 |
14 | override fun onCreate(savedInstanceState: Bundle?) {
15 | super.onCreate(savedInstanceState)
16 | binding = ActivityMainBinding.inflate(layoutInflater)
17 | setContentView(binding.root)
18 |
19 | supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/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/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/adapter/ViewPagerAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.adapter
2 |
3 | import androidx.fragment.app.Fragment
4 | import androidx.fragment.app.FragmentActivity
5 | import androidx.viewpager2.adapter.FragmentStateAdapter
6 |
7 | class ViewPagerAdapter(fragmentActivity: FragmentActivity) :
8 | FragmentStateAdapter(fragmentActivity) {
9 |
10 | private val fragmentList: MutableList = ArrayList()
11 |
12 | private val titleList: MutableList = ArrayList()
13 |
14 | fun getTitle(position: Int): Int {
15 | return titleList[position]
16 | }
17 |
18 | fun addFragment(fragment: Fragment, title: Int) {
19 | fragmentList.add(fragment)
20 | titleList.add(title)
21 | }
22 |
23 | override fun createFragment(position: Int): Fragment {
24 | return fragmentList[position]
25 | }
26 |
27 | override fun getItemCount(): Int {
28 | return fragmentList.size
29 | }
30 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
11 | #7b0000
12 |
13 | #EA8383
14 | #91EC83
15 | #92E8F4
16 | #F4E98C
17 |
18 | #FF4C3B
19 | #03B6FC
20 | #04D5C1
21 |
22 | #FF7803
23 | #03B6FC
24 | #04D5C1
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
20 |
21 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Rodrigo Sarmento
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/app/google-services.json:
--------------------------------------------------------------------------------
1 | {
2 | "project_info": {
3 | "project_number": "561028915091",
4 | "project_id": "emdiabetes-177a0",
5 | "storage_bucket": "emdiabetes-177a0.appspot.com"
6 | },
7 | "client": [
8 | {
9 | "client_info": {
10 | "mobilesdk_app_id": "1:561028915091:android:e46d77206d532820e6d266",
11 | "android_client_info": {
12 | "package_name": "com.digo.emdiabetes"
13 | }
14 | },
15 | "oauth_client": [
16 | {
17 | "client_id": "561028915091-ipfuid2il3ngeuvn3j2evcjm8ufti7eb.apps.googleusercontent.com",
18 | "client_type": 3
19 | }
20 | ],
21 | "api_key": [
22 | {
23 | "current_key": "AIzaSyBotf-UdThoP0UB8CWXg40pLsvnRH7YyAA"
24 | }
25 | ],
26 | "services": {
27 | "appinvite_service": {
28 | "other_platform_oauth_client": [
29 | {
30 | "client_id": "561028915091-ipfuid2il3ngeuvn3j2evcjm8ufti7eb.apps.googleusercontent.com",
31 | "client_type": 3
32 | }
33 | ]
34 | }
35 | }
36 | }
37 | ],
38 | "configuration_version": "1"
39 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
18 |
19 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/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 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/helper/FirebaseHelper.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.helper
2 |
3 | import com.digo.emdiabetes.R
4 | import com.google.firebase.auth.FirebaseAuth
5 | import com.google.firebase.database.FirebaseDatabase
6 |
7 | class FirebaseHelper {
8 |
9 | companion object {
10 |
11 | fun getDatabase() = FirebaseDatabase.getInstance().reference
12 |
13 | private fun getAuth() = FirebaseAuth.getInstance()
14 |
15 | fun getIdUser() = getAuth().uid
16 |
17 | fun isAutenticated() = getAuth().currentUser != null
18 |
19 | fun validError(error: String): Int {
20 | return when {
21 | error.contains("There is no user record corresponding to this identifier") -> {
22 | R.string.account_not_registered_register_fragment
23 | }
24 | error.contains("The email address is badly formatted") -> {
25 | R.string.invalid_email_register_fragment
26 | }
27 | error.contains("The password is invalid or the user does not have a password") -> {
28 | R.string.invalid_password_register_fragment
29 | }
30 | error.contains("The email address is already in use by another account") -> {
31 | R.string.email_in_use_register_fragment
32 | }
33 | error.contains("Password should be at least 6 characters") -> {
34 | R.string.strong_password_register_fragment
35 | }
36 | else -> {
37 | R.string.error_generic
38 | }
39 | }
40 | }
41 |
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/helper/Extensions.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.helper
2 |
3 | import android.graphics.Color
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.appcompat.widget.Toolbar
6 | import androidx.fragment.app.Fragment
7 | import com.digo.emdiabetes.R
8 | import com.digo.emdiabetes.databinding.BottomSheetBinding
9 | import com.google.android.material.bottomsheet.BottomSheetDialog
10 |
11 | fun Fragment.initToolbar(toolbar: Toolbar) {
12 | (activity as AppCompatActivity).setSupportActionBar(toolbar)
13 | (activity as AppCompatActivity).title = ""
14 | (activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)
15 | toolbar.setNavigationOnClickListener { activity?.onBackPressed() }
16 | toolbar.setTitleTextColor(Color.parseColor("#FFFFFF"))
17 | }
18 |
19 | fun Fragment.showBottomSheet(
20 | titleDialog: Int? = null,
21 | titleButton: Int? = null,
22 | message: Int,
23 | onClick: () -> Unit = {}
24 | ) {
25 | val bottomSheetDialog = BottomSheetDialog(requireContext(), R.style.BottomSheetDialog)
26 | val bottomSheetBinding: BottomSheetBinding =
27 | BottomSheetBinding.inflate(layoutInflater, null, false)
28 |
29 | bottomSheetBinding.textTitle.text = getString(titleDialog ?: R.string.text_title_bottom_sheet)
30 | bottomSheetBinding.textMessage.text = getText(message)
31 | bottomSheetBinding.btnClick.text = getString(titleButton ?: R.string.text_button_bottom_sheet)
32 | bottomSheetBinding.btnClick.setOnClickListener {
33 | onClick()
34 | bottomSheetDialog.dismiss()
35 | }
36 |
37 | bottomSheetDialog.setContentView(bottomSheetBinding.root)
38 | bottomSheetDialog.show()
39 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/SplashFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 | import android.os.Bundle
4 | import android.os.Handler
5 | import android.os.Looper
6 | import androidx.fragment.app.Fragment
7 | import android.view.LayoutInflater
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import androidx.navigation.fragment.findNavController
11 | import com.digo.emdiabetes.R
12 | import com.digo.emdiabetes.databinding.FragmentSplashBinding
13 | import com.google.firebase.auth.FirebaseAuth
14 | import com.google.firebase.auth.ktx.auth
15 | import com.google.firebase.ktx.Firebase
16 |
17 | class SplashFragment : Fragment() {
18 |
19 | private var _binding: FragmentSplashBinding? = null
20 | private val binding get() = _binding!!
21 |
22 | private lateinit var auth: FirebaseAuth
23 |
24 | override fun onCreateView(
25 | inflater: LayoutInflater, container: ViewGroup?,
26 | savedInstanceState: Bundle?
27 | ): View {
28 | _binding = FragmentSplashBinding.inflate(inflater, container, false)
29 | return binding.root
30 | }
31 |
32 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
33 | super.onViewCreated(view, savedInstanceState)
34 |
35 | Handler(Looper.getMainLooper()).postDelayed(this::checkAuth, 3000)
36 |
37 | }
38 |
39 | private fun checkAuth() {
40 | auth = Firebase.auth
41 | if (auth.currentUser == null) {
42 | findNavController().navigate(R.id.action_splashFragment_to_authentication)
43 | } else {
44 | findNavController().navigate(R.id.action_splashFragment_to_homeFragment)
45 | }
46 | }
47 |
48 | override fun onDestroyView() {
49 | super.onDestroyView()
50 | _binding = null
51 | }
52 |
53 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/model/CalcularInsulina.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.model
2 |
3 | class CalcularInsulina {
4 |
5 | private var resultado = 0.0
6 | private var resultadoTotal = 0.0
7 |
8 | fun calcular(peso:Double, carboidrato:Double){
9 | if (peso>=45 && peso<49){
10 | resultado = carboidrato / 16
11 | resultadoTotal = resultado
12 | }else if (peso>=49 && peso<58){
13 | resultado = carboidrato / 15
14 | resultadoTotal = resultado
15 | }else if (peso>=58 && peso<63){
16 | resultado = carboidrato / 14
17 | resultadoTotal = resultado
18 | }else if (peso>=63 && peso<67){
19 | resultado = carboidrato / 13
20 | resultadoTotal = resultado
21 | }else if (peso>=67 && peso<76){
22 | resultado = carboidrato / 12
23 | resultadoTotal = resultado
24 | }else if (peso>=76 && peso<81){
25 | resultado = carboidrato / 11
26 | resultadoTotal = resultado
27 | }else if (peso>=81 && peso<85){
28 | resultado = carboidrato / 10
29 | resultadoTotal = resultado
30 | }else if (peso>=85 && peso<90){
31 | resultado = carboidrato / 9
32 | resultadoTotal = resultado
33 | }else if (peso>=90 && peso<99){
34 | resultado = carboidrato / 8
35 | resultadoTotal = resultado
36 | }else if (peso>=99 && peso<108){
37 | resultado = carboidrato / 7
38 | resultadoTotal = resultado
39 | }else if (peso>=108){
40 | resultado = carboidrato / 6
41 | resultadoTotal = resultado
42 | }else if (peso<45){
43 | resultado = carboidrato / 17
44 | resultadoTotal = resultado
45 | }
46 | }
47 |
48 | fun resultado():Double{
49 | return resultadoTotal
50 | }
51 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'com.google.gms.google-services'
5 | id 'kotlin-parcelize'
6 | id 'androidx.navigation.safeargs.kotlin'
7 | }
8 |
9 | android {
10 | compileSdk 32
11 |
12 | defaultConfig {
13 | applicationId "com.digo.emdiabetes"
14 | minSdk 21
15 | targetSdk 32
16 | versionCode 1
17 | versionName "1.0"
18 |
19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | kotlinOptions {
33 | jvmTarget = '1.8'
34 | }
35 |
36 | viewBinding {
37 | enabled true
38 | }
39 | }
40 |
41 | dependencies {
42 | //firebase
43 | implementation platform('com.google.firebase:firebase-bom:30.3.2')
44 | implementation 'com.google.firebase:firebase-analytics-ktx'
45 | implementation 'com.google.firebase:firebase-auth-ktx'
46 | implementation 'com.google.firebase:firebase-database-ktx'
47 |
48 | implementation 'androidx.core:core-ktx:1.7.0'
49 | implementation 'androidx.appcompat:appcompat:1.5.0'
50 | implementation 'com.google.android.material:material:1.6.1'
51 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
52 |
53 | testImplementation 'junit:junit:4.13.2'
54 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
55 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
56 |
57 | //navigation
58 | implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
59 | implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
60 |
61 | implementation 'com.github.Ferfalk:SimpleSearchView:0.2.0'
62 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/adapter/DietAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.adapter
2 |
3 | import android.content.Context
4 | import android.view.LayoutInflater
5 | import android.view.ViewGroup
6 | import androidx.core.content.ContextCompat
7 | import androidx.recyclerview.widget.RecyclerView
8 | import com.digo.emdiabetes.R
9 | import com.digo.emdiabetes.databinding.ItemAdapterBinding
10 | import com.digo.emdiabetes.model.Diet
11 |
12 | class DietAdapter(
13 | private val context: Context,
14 | private val dietList: List,
15 | val contactSelected: (Diet, Int) -> Unit
16 | ) : RecyclerView.Adapter() {
17 |
18 | companion object {
19 | val SELECT_BACK: Int = 1
20 | val SELECT_REMOVE: Int = 2
21 | val SELECT_EDIT: Int = 3
22 | val SELECT_DETAILS: Int = 4
23 | val SELECT_NEXT: Int = 5
24 | }
25 |
26 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
27 | return MyViewHolder(
28 | ItemAdapterBinding.inflate(
29 | LayoutInflater.from(parent.context),
30 | parent,
31 | false
32 | )
33 | )
34 | }
35 |
36 | override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
37 | val diet= dietList[position]
38 |
39 | val colorCard = ContextCompat.getColor(context, R.color.color_4)
40 |
41 | holder.binding.textDescription.text = "Refeição: "+diet.refeicao +"\nAlimento(s): "+ diet.alimento
42 |
43 | holder.binding.btnDelete.setOnClickListener { contactSelected(diet, SELECT_REMOVE) }
44 | holder.binding.btnEdit.setOnClickListener { contactSelected(diet, SELECT_EDIT) }
45 | holder.binding.btnDetails.setOnClickListener { contactSelected(diet, SELECT_DETAILS) }
46 |
47 | holder.binding.cardview.setCardBackgroundColor(colorCard)
48 | }
49 |
50 | override fun getItemCount() = dietList.size
51 |
52 | inner class MyViewHolder(val binding: ItemAdapterBinding) :
53 | RecyclerView.ViewHolder(binding.root)
54 |
55 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/adapter/MedicationAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.adapter
2 |
3 | import android.content.Context
4 | import android.view.LayoutInflater
5 | import android.view.ViewGroup
6 | import androidx.core.content.ContextCompat
7 | import androidx.recyclerview.widget.RecyclerView
8 | import com.digo.emdiabetes.R
9 | import com.digo.emdiabetes.databinding.ItemAdapterBinding
10 | import com.digo.emdiabetes.model.Medication
11 |
12 | class MedicationAdapter(
13 | private val context: Context,
14 | private val medicationList: List,
15 | val medicationSelected: (Medication, Int) -> Unit
16 | ) : RecyclerView.Adapter() {
17 |
18 | companion object {
19 | val SELECT_BACK: Int = 1
20 | val SELECT_REMOVE: Int = 2
21 | val SELECT_EDIT: Int = 3
22 | val SELECT_DETAILS: Int = 4
23 | val SELECT_NEXT: Int = 5
24 | }
25 |
26 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
27 | return MyViewHolder(
28 | ItemAdapterBinding.inflate(
29 | LayoutInflater.from(parent.context),
30 | parent,
31 | false
32 | )
33 | )
34 | }
35 |
36 | override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
37 | val medication = medicationList[position]
38 |
39 | val colorCard = ContextCompat.getColor(context, R.color.color_3)
40 |
41 | holder.binding.textDescription.text = "Nome: "+medication.nome + "\nDosagem: "+medication.dosagem
42 |
43 | holder.binding.btnDelete.setOnClickListener { medicationSelected(medication, SELECT_REMOVE) }
44 | holder.binding.btnEdit.setOnClickListener { medicationSelected(medication, SELECT_EDIT) }
45 | holder.binding.btnDetails.setOnClickListener { medicationSelected(medication, SELECT_DETAILS) }
46 |
47 | holder.binding.cardview.setCardBackgroundColor(colorCard)
48 | }
49 |
50 | override fun getItemCount() = medicationList.size
51 |
52 | inner class MyViewHolder(val binding: ItemAdapterBinding) :
53 | RecyclerView.ViewHolder(binding.root)
54 |
55 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_logoemdiabetes.xml:
--------------------------------------------------------------------------------
1 |
3 |
5 |
7 |
9 |
11 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_diet.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
28 |
29 |
34 |
35 |
43 |
44 |
45 |
46 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_medication.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
28 |
29 |
34 |
35 |
43 |
44 |
45 |
46 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/bottom_sheet.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
21 |
22 |
31 |
32 |
43 |
44 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
17 |
18 |
23 |
24 |
27 |
28 |
31 |
32 |
42 |
43 |
48 |
49 |
53 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/HomeFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 | import android.os.Bundle
4 | import android.view.*
5 | import androidx.fragment.app.Fragment
6 | import androidx.navigation.fragment.findNavController
7 | import com.digo.emdiabetes.R
8 | import com.digo.emdiabetes.databinding.FragmentHomeBinding
9 | import com.digo.emdiabetes.helper.showBottomSheet
10 | import com.digo.emdiabetes.ui.adapter.ViewPagerAdapter
11 | import com.google.android.material.tabs.TabLayoutMediator
12 | import com.google.firebase.auth.FirebaseAuth
13 | import com.google.firebase.auth.ktx.auth
14 | import com.google.firebase.ktx.Firebase
15 |
16 |
17 | class HomeFragment : Fragment() {
18 |
19 | private var _binding: FragmentHomeBinding? = null
20 | private val binding get() = _binding!!
21 |
22 | private lateinit var auth: FirebaseAuth
23 |
24 | override fun onCreateView(
25 | inflater: LayoutInflater, container: ViewGroup?,
26 | savedInstanceState: Bundle?
27 | ): View {
28 | _binding = FragmentHomeBinding.inflate(inflater, container, false)
29 | return binding.root
30 | }
31 |
32 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
33 | super.onViewCreated(view, savedInstanceState)
34 |
35 | auth = Firebase.auth
36 |
37 | configTablayout()
38 |
39 | openCalcInsu()
40 |
41 | initClicks()
42 |
43 | }
44 |
45 | private fun initClicks() {
46 | binding.ibLogout.setOnClickListener { logoutApp() }
47 | }
48 |
49 | private fun openCalcInsu(){
50 | binding.ibCalc.setOnClickListener{(findNavController().navigate(R.id.action_homeFragment_to_calcInsulinaFragment))}
51 | }
52 |
53 | private fun logoutApp() {
54 | showBottomSheet(
55 | titleButton = R.string.text_button_confirm,
56 | message = R.string.txt_message_logout,
57 | onClick = {
58 | auth.signOut()
59 | findNavController().navigate(R.id.action_homeFragment_to_authentication)
60 | })
61 | }
62 |
63 | private fun configTablayout() {
64 | val adapter = ViewPagerAdapter(requireActivity())
65 | binding.viewPager.adapter = adapter
66 |
67 | adapter.addFragment(GlycemiaFragment(), R.string.option_glycemia)
68 | adapter.addFragment(MedicationFragment(), R.string.option_medication)
69 | adapter.addFragment(DietFragment(), R.string.option_diet)
70 |
71 | binding.viewPager.offscreenPageLimit = adapter.itemCount
72 |
73 | TabLayoutMediator(
74 | binding.tabs, binding.viewPager
75 | ) { tab, position ->
76 | tab.text = getString(adapter.getTitle(position))
77 | }.attach()
78 | }
79 |
80 |
81 |
82 | override fun onDestroyView() {
83 | super.onDestroyView()
84 | _binding = null
85 | }
86 |
87 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/auth/RecoverAccountFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.auth
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.Toast
9 | import androidx.core.view.isVisible
10 | import com.digo.emdiabetes.R
11 | import com.digo.emdiabetes.databinding.FragmentRecoverAccountBinding
12 | import com.digo.emdiabetes.helper.BaseFragment
13 | import com.digo.emdiabetes.helper.FirebaseHelper
14 | import com.digo.emdiabetes.helper.initToolbar
15 | import com.digo.emdiabetes.helper.showBottomSheet
16 | import com.google.firebase.auth.FirebaseAuth
17 | import com.google.firebase.auth.ktx.auth
18 | import com.google.firebase.ktx.Firebase
19 |
20 | class RecoverAccountFragment : BaseFragment() {
21 |
22 | private var _binding: FragmentRecoverAccountBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | private lateinit var auth: FirebaseAuth
26 |
27 | override fun onCreateView(
28 | inflater: LayoutInflater, container: ViewGroup?,
29 | savedInstanceState: Bundle?
30 | ): View {
31 | _binding = FragmentRecoverAccountBinding.inflate(layoutInflater, container, false)
32 | return binding.root
33 | }
34 |
35 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
36 | super.onViewCreated(view, savedInstanceState)
37 | initToolbar(binding.toolbar)
38 |
39 | auth = Firebase.auth
40 |
41 | initClicks()
42 | }
43 |
44 | private fun initClicks() {
45 | binding.btnSend.setOnClickListener { validateData() }
46 | }
47 |
48 | private fun validateData() {
49 | val email = binding.edtEmail.text.toString().trim()
50 |
51 | if (email.isNotEmpty()) {
52 | hideKeyboard()
53 |
54 | binding.progressBar.isVisible = true
55 |
56 | recoverAccountUser(email)
57 | } else {
58 | showBottomSheet(message = R.string.text_email_empty_recover_account_fragment)
59 | }
60 | }
61 |
62 | private fun recoverAccountUser(email: String) {
63 | auth.sendPasswordResetEmail(email)
64 | .addOnCompleteListener(requireActivity()) { task ->
65 | if (task.isSuccessful) {
66 | showBottomSheet(
67 | message = R.string.text_email_send_sucess_recover_account_fragment
68 | )
69 | } else {
70 | showBottomSheet(
71 | message = FirebaseHelper.validError(task.exception?.message ?: "")
72 | )
73 | }
74 |
75 | binding.progressBar.isVisible = false
76 | }
77 | }
78 |
79 | override fun onDestroyView() {
80 | super.onDestroyView()
81 | _binding = null
82 | }
83 |
84 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/adapter/GlycemiaAdapter.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.adapter
2 |
3 | import android.content.Context
4 | import android.view.LayoutInflater
5 | import android.view.ViewGroup
6 | import androidx.core.content.ContextCompat
7 | import androidx.recyclerview.widget.RecyclerView
8 | import com.digo.emdiabetes.R
9 | import com.digo.emdiabetes.databinding.ItemAdapterBinding
10 | import com.digo.emdiabetes.model.Glycemia
11 | import com.google.firebase.database.collection.LLRBNode
12 |
13 | class GlycemiaAdapter(
14 | private val context: Context,
15 | private val glycemiaList: List,
16 | val glycemiaSelected: (Glycemia, Int) -> Unit
17 | ) : RecyclerView.Adapter() {
18 |
19 | private var glycemiaListM = glycemiaList.toMutableList()
20 |
21 | companion object {
22 | val SELECT_BACK: Int = 1
23 | val SELECT_REMOVE: Int = 2
24 | val SELECT_EDIT: Int = 3
25 | val SELECT_DETAILS: Int = 4
26 | val SELECT_NEXT: Int = 5
27 | }
28 |
29 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
30 | return MyViewHolder(
31 | ItemAdapterBinding.inflate(
32 | LayoutInflater.from(parent.context),
33 | parent,
34 | false
35 | )
36 | )
37 | }
38 |
39 | override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
40 | val glycemia= glycemiaListM[position]
41 | val colorGlicoseDesregulada = ContextCompat.getColor(context, R.color.color_1)
42 | val colorGlicoseregulada = ContextCompat.getColor(context, R.color.color_2)
43 |
44 | holder.binding.textDescription.text = "Data: "+glycemia.dia+"/"+glycemia.mes+"/"+glycemia.ano+"\nGlicemia: "+glycemia.glicemia+"mg/dL"+"\nDescrição: "+ glycemia.descricao
45 |
46 | if (glycemia.glicemia.toDouble() >= 200 || glycemia.glicemia.toDouble() <= 75){
47 | holder.binding.cardview.setCardBackgroundColor(colorGlicoseDesregulada)
48 | }else{
49 | holder.binding.cardview.setCardBackgroundColor(colorGlicoseregulada)
50 | }
51 |
52 |
53 | holder.binding.btnDelete.setOnClickListener { glycemiaSelected(glycemia, SELECT_REMOVE) }
54 | holder.binding.btnEdit.setOnClickListener { glycemiaSelected(glycemia, SELECT_EDIT) }
55 | holder.binding.btnDetails.setOnClickListener { glycemiaSelected(glycemia, SELECT_DETAILS) }
56 |
57 |
58 | }
59 |
60 | override fun getItemCount() = glycemiaListM.size
61 |
62 | fun searchGlycemia(query: String): Boolean{
63 | glycemiaListM.clear()
64 |
65 | glycemiaListM.addAll(glycemiaList.filter { it.glicemia.contains(query, true) })
66 |
67 | notifyDataSetChanged()
68 |
69 | return glycemiaListM.isEmpty()
70 | }
71 |
72 | fun clearSearchGlycemia() {
73 | glycemiaListM = glycemiaList.toMutableList()
74 | notifyDataSetChanged()
75 | }
76 |
77 | inner class MyViewHolder(val binding: ItemAdapterBinding) :
78 | RecyclerView.ViewHolder(binding.root)
79 |
80 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/auth/RegisterFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.auth
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.Toast
9 | import androidx.core.view.isVisible
10 | import androidx.navigation.fragment.findNavController
11 | import com.digo.emdiabetes.R
12 | import com.digo.emdiabetes.databinding.FragmentRegisterBinding
13 | import com.digo.emdiabetes.helper.BaseFragment
14 | import com.digo.emdiabetes.helper.FirebaseHelper
15 | import com.digo.emdiabetes.helper.initToolbar
16 | import com.digo.emdiabetes.helper.showBottomSheet
17 | import com.google.firebase.auth.FirebaseAuth
18 | import com.google.firebase.auth.ktx.auth
19 | import com.google.firebase.ktx.Firebase
20 |
21 | class RegisterFragment : BaseFragment() {
22 |
23 | private var _binding: FragmentRegisterBinding? = null
24 | private val binding get() = _binding!!
25 |
26 | private lateinit var auth: FirebaseAuth
27 |
28 | override fun onCreateView(
29 | inflater: LayoutInflater, container: ViewGroup?,
30 | savedInstanceState: Bundle?
31 | ): View {
32 | _binding = FragmentRegisterBinding.inflate(layoutInflater, container, false)
33 | return binding.root
34 | }
35 |
36 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
37 | super.onViewCreated(view, savedInstanceState)
38 | initToolbar(binding.toolbar)
39 |
40 | auth = Firebase.auth
41 |
42 | initClicks()
43 | }
44 |
45 | private fun initClicks() {
46 | binding.btnRegister.setOnClickListener { validateData() }
47 | }
48 |
49 | private fun validateData() {
50 | val email = binding.edtEmail.text.toString().trim()
51 | val password = binding.edtPassword.text.toString().trim()
52 |
53 | if (email.isNotEmpty()) {
54 | if (password.isNotEmpty()) {
55 |
56 | hideKeyboard()
57 |
58 | binding.progressBar.isVisible = true
59 |
60 | registerUser(email, password)
61 |
62 | } else {
63 | showBottomSheet(message = R.string.text_password_empty_register_fragment)
64 | }
65 | } else {
66 | showBottomSheet(message = R.string.text_email_empty_register_fragment)
67 | }
68 | }
69 |
70 | private fun registerUser(email: String, password: String) {
71 | auth.createUserWithEmailAndPassword(email, password)
72 | .addOnCompleteListener(requireActivity()) { task ->
73 | if (task.isSuccessful) {
74 | findNavController().navigate(R.id.action_global_homeFragment)
75 | } else {
76 | showBottomSheet(
77 | message = FirebaseHelper.validError(
78 | task.exception?.message ?: ""
79 | )
80 | )
81 | binding.progressBar.isVisible = false
82 | }
83 | }
84 | }
85 |
86 | override fun onDestroyView() {
87 | super.onDestroyView()
88 | _binding = null
89 | }
90 |
91 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/auth/LoginFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.auth
2 |
3 | import android.os.Bundle
4 | import androidx.fragment.app.Fragment
5 | import android.view.LayoutInflater
6 | import android.view.View
7 | import android.view.ViewGroup
8 | import android.widget.Toast
9 | import androidx.core.view.isVisible
10 | import androidx.navigation.fragment.findNavController
11 | import com.digo.emdiabetes.R
12 | import com.digo.emdiabetes.databinding.FragmentLoginBinding
13 | import com.digo.emdiabetes.helper.BaseFragment
14 | import com.digo.emdiabetes.helper.FirebaseHelper
15 | import com.digo.emdiabetes.helper.showBottomSheet
16 | import com.google.firebase.auth.FirebaseAuth
17 | import com.google.firebase.auth.ktx.auth
18 | import com.google.firebase.ktx.Firebase
19 |
20 | class LoginFragment : BaseFragment() {
21 |
22 | private var _binding: FragmentLoginBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | private lateinit var auth: FirebaseAuth
26 |
27 | override fun onCreateView(
28 | inflater: LayoutInflater, container: ViewGroup?,
29 | savedInstanceState: Bundle?
30 | ): View {
31 | _binding = FragmentLoginBinding.inflate(inflater, container, false)
32 | return binding.root
33 | }
34 |
35 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
36 | super.onViewCreated(view, savedInstanceState)
37 |
38 | auth = Firebase.auth
39 |
40 | initClicks()
41 | }
42 |
43 | private fun initClicks() {
44 | binding.btnLogin.setOnClickListener { validateData() }
45 |
46 | binding.btnRegister.setOnClickListener {
47 | findNavController().navigate(R.id.action_loginFragment_to_registerFragment)
48 | }
49 |
50 | binding.btnRecover.setOnClickListener {
51 | findNavController().navigate(R.id.action_loginFragment_to_recoverAccountFragment)
52 | }
53 | }
54 |
55 | private fun validateData() {
56 | val email = binding.edtEmail.text.toString().trim()
57 | val password = binding.edtPassword.text.toString().trim()
58 |
59 | if (email.isNotEmpty()) {
60 | if (password.isNotEmpty()) {
61 |
62 | hideKeyboard()
63 |
64 | binding.progressBar.isVisible = true
65 |
66 | loginUser(email, password)
67 |
68 | } else {
69 | showBottomSheet(
70 | message = R.string.text_password_empty_login_fragment
71 | )
72 | }
73 | } else {
74 | showBottomSheet(
75 | message = R.string.text_email_empty_login_fragment
76 | )
77 | }
78 | }
79 |
80 | private fun loginUser(email: String, password: String) {
81 | auth.signInWithEmailAndPassword(email, password)
82 | .addOnCompleteListener(requireActivity()) { task ->
83 | if (task.isSuccessful) {
84 | findNavController().navigate(R.id.action_global_homeFragment)
85 | } else {
86 | showBottomSheet(
87 | message = FirebaseHelper.validError(task.exception?.message ?: "")
88 | )
89 | binding.progressBar.isVisible = false
90 | }
91 | }
92 | }
93 |
94 | override fun onDestroyView() {
95 | super.onDestroyView()
96 | _binding = null
97 | }
98 |
99 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_home.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
20 |
21 |
38 |
39 |
49 |
50 |
62 |
63 |
64 |
65 |
66 |
67 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_glycemia.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
21 |
22 |
28 |
29 |
34 |
35 |
36 |
37 |
38 |
46 |
47 |
57 |
58 |
63 |
64 |
72 |
73 |
74 |
75 |
86 |
87 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | ### Tópicos
12 |
13 | - [Descrição do projeto](#descrição-do-projeto)
14 |
15 | - [Funcionalidades](#Funcionalidades-do-projeto)
16 |
17 | - [Aplicação](#aplicação)
18 |
19 | - [Ferramentas utilizadas](#Técnicas-e-tecnologias-utilizadas)
20 |
21 | - [Compatibilidade](#Compatibilidade)
22 |
23 | - [Acesso ao projeto](#acesso-ao-projeto)
24 |
25 | - [Abrir e rodar o projeto](#abrir-e-rodar-o-projeto)
26 |
27 | - [Desenvolvedor](#desenvolvedor)
28 |
29 | ## Descrição do projeto
30 |
31 |
32 | O EmDiabetes é um aplicativo para auxiliar pessoas acometidas por diabetes mellitus de todos os tipos na sua rotina diária com a doença.
33 |
34 | O aplicativo permitirá o controle diário e contínuo do nível de glicose no sangue (glicemia), possibilitando que familiares, cuidadores, profissionais da saúde ou o próprio paciente acompanhem o estado clínico do mesmo.
35 |
36 | O aplicativo lembrará o usuário a hora de tomar sua insulina, seus medicamentos e suas refeições.
37 |
38 | O aplicativo permitirá o usuário calcular a dosagem correta de sua insulina.
39 |
40 | O aplicativo sinalizará com a cor vermelha hiperglicemia e hipoglicemia.
41 |
42 |
43 |
44 |
45 |
46 | ## Funcionalidades do projeto
47 |
48 | :heavy_check_mark: `Funcionalidade 1:` Realizar cadastro do usuário.
49 |
50 | :heavy_check_mark: `Funcionalidade 2:` Armazenar dados do usuário, como glicemia, medicamento e dieta no banco de dados no Realtime Database.
51 |
52 | :heavy_check_mark: `Funcionalidade 3:` Calcular dosagem de insulina.
53 |
54 | :heavy_check_mark: `Funcionalidade 4:` Buscar glicemias, medicamentos e refeições.
55 |
56 | :heavy_check_mark: `Funcionalidade 5:` Alertar horário de insulina, medicamentos, refeições e de medir glicemia.
57 |
58 | :heavy_check_mark: `Funcionalidade 6:` Sinalizar hiperglicemia e hipoglicemia.
59 |
60 | ## Aplicação
61 | [videoEmD5.webm](https://user-images.githubusercontent.com/59851576/209887320-d75fe618-575c-4591-977c-cd4d9010576c.webm)
62 |
63 | ###
64 |
65 | ## Técnicas e tecnologias utilizadas
66 |
67 | - ``Android Studio``
68 | - ``Firebase Authentication``
69 | - ``Realtime Database``
70 | - ``Kotlin``
71 | - ``Navigation Component``
72 | - ``Safe Args``
73 | - ``Tablayout``
74 | - ``Adapter``
75 | - ``AlarmClock``
76 | - ``RecyclerView``
77 | - ``ViewBinding``
78 | - ``SimpleSearchView``
79 | ###
80 |
81 | ## Compatibilidade
82 |
83 | Garantia de funcionamento a partir da versão 5.0 (Lollipop) do Android
84 | ###
85 |
86 | ## Acesso ao projeto
87 |
88 | Você pode [acessar o código fonte do projeto](https://github.com/Rodrigo-Sarmento/EmDiabetes) ou [baixá-lo](https://github.com/Rodrigo-Sarmento/EmDiabetes/archive/refs/heads/main.zip).
89 |
90 | ## Abrir e rodar o projeto
91 |
92 | Após baixar o projeto, você pode abrir com o `Android Studio`. Para isso, na tela de launcher clique em:
93 |
94 | - `Open an Existing Project` (ou alguma opção similar);
95 | - Procure o local onde o projeto está e o selecione (Caso o projeto seja baixado via zip, é necessário extraí-lo antes de procurá-lo);
96 | - Por fim clique em `OK`.
97 |
98 | O `Android Studio` deve executar algumas tasks do *Gradle* para configurar o projeto, aguarde até finalizar. Ao finalizar as tasks, você pode executar o App 🏆
99 |
100 | ## Desenvolvedor
101 |
102 | | [Rodrigo Gomes Sarmento ](https://github.com/Rodrigo-Sarmento)|
103 | | :---:
104 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_recover_account.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
21 |
22 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
41 |
50 |
51 |
56 |
57 |
67 |
68 |
78 |
79 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
21 |
22 |
27 |
28 |
38 |
39 |
45 |
46 |
56 |
57 |
67 |
68 |
72 |
73 |
83 |
84 |
94 |
95 |
96 |
97 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_register.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
21 |
22 |
29 |
30 |
36 |
37 |
38 |
39 |
40 |
41 |
50 |
51 |
56 |
57 |
67 |
68 |
74 |
75 |
85 |
86 |
96 |
97 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_adapter.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
24 |
25 |
38 |
39 |
57 |
58 |
77 |
78 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/form/FormDietFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.form
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.widget.Toast
8 | import androidx.core.view.isVisible
9 | import androidx.navigation.fragment.findNavController
10 | import androidx.navigation.fragment.navArgs
11 | import com.digo.emdiabetes.R
12 | import com.digo.emdiabetes.databinding.FragmentFormDietBinding
13 | import com.digo.emdiabetes.helper.BaseFragment
14 | import com.digo.emdiabetes.helper.FirebaseHelper
15 | import com.digo.emdiabetes.helper.initToolbar
16 | import com.digo.emdiabetes.helper.showBottomSheet
17 | import com.digo.emdiabetes.model.Diet
18 |
19 | class FormDietFragment : BaseFragment() {
20 |
21 | private val args: FormDietFragmentArgs by navArgs()
22 |
23 | private var _binding: FragmentFormDietBinding? = null
24 | private val binding get() = _binding!!
25 |
26 | private lateinit var diet: Diet
27 | private var newDiet: Boolean = true
28 | // private var qtdMedication: Int = 0
29 |
30 | override fun onCreateView(
31 | inflater: LayoutInflater, container: ViewGroup?,
32 | savedInstanceState: Bundle?
33 | ): View {
34 | _binding = FragmentFormDietBinding.inflate(inflater, container, false)
35 | return binding.root
36 | }
37 |
38 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
39 | super.onViewCreated(view, savedInstanceState)
40 | initToolbar(binding.toolbar)
41 |
42 | initListeners()
43 |
44 | getArgs()
45 | }
46 |
47 | private fun getArgs() {
48 | args.diet.let {
49 | if (it != null){
50 | diet = it
51 |
52 | configDiet()
53 | }
54 | }
55 | }
56 |
57 | private fun configDiet() {
58 | newDiet = false
59 | binding.textToolbar.text = getString(R.string.text_editing_form_fragment)
60 |
61 | binding.edtDescription.setText(diet.alimento)
62 | binding.edtAlimento.setText(diet.alimento)
63 | }
64 |
65 | /*
66 | private fun setStatus() {
67 | binding.radioGroup.check(
68 | when (task.status) {
69 | 0 -> {
70 | R.id.rbTodo
71 | }
72 | 1 -> {
73 | R.id.rbDoing
74 | }
75 | else -> {
76 | R.id.rbDone
77 | }
78 | }
79 | )
80 | }
81 | */
82 |
83 | private fun initListeners() {
84 | binding.btnSave.setOnClickListener { validateData() }
85 |
86 | }
87 |
88 |
89 | private fun validateData() {
90 | val refeicao = binding.edtDescription.text.toString().trim()
91 | val alimento = binding.edtAlimento.text.toString().trim()
92 |
93 | if (refeicao.isNotEmpty()) {
94 |
95 | hideKeyboard()
96 |
97 | binding.progressBar.isVisible = true
98 |
99 | if (newDiet) diet= Diet()
100 | diet.refeicao = refeicao
101 | diet.alimento = alimento
102 | //task.status = statusTask
103 |
104 | saveDiet()
105 | } else {
106 | showBottomSheet(message = R.string.text_description_empty_form_fragment)
107 | }
108 | }
109 |
110 | private fun saveDiet() {
111 | FirebaseHelper
112 | .getDatabase()
113 | .child("diet")
114 | .child(FirebaseHelper.getIdUser() ?: "")
115 | .child(diet.id)
116 | .setValue(diet)
117 | .addOnCompleteListener { contact ->
118 | if (contact.isSuccessful) {
119 | if (newDiet) { // Nova tarefa
120 | findNavController().popBackStack()
121 | Toast.makeText(
122 | requireContext(),
123 | R.string.text_save_sucess_form_fragment,
124 | Toast.LENGTH_SHORT
125 | ).show()
126 | } else { // Editando tarefa
127 | binding.progressBar.isVisible = false
128 | Toast.makeText(
129 | requireContext(),
130 | R.string.text_update_sucess_form_fragment,
131 | Toast.LENGTH_SHORT
132 | ).show()
133 | }
134 | } else {
135 | Toast.makeText(requireContext(), R.string.text_erro_save_form_fragment, Toast.LENGTH_SHORT)
136 | .show()
137 | }
138 | }.addOnFailureListener {
139 | binding.progressBar.isVisible = false
140 | Toast.makeText(requireContext(), R.string.text_erro_save_form_fragment, Toast.LENGTH_SHORT)
141 | .show()
142 | }
143 | }
144 |
145 | override fun onDestroyView() {
146 | super.onDestroyView()
147 | _binding = null
148 | }
149 |
150 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EmDiabetes
3 |
4 |
5 | E-mail
6 | email@email.com
7 | Senha
8 | ******
9 | Criar conta
10 | Ocorreu um erro, por favor tente novamente mais tarde.
11 | Confirmar
12 | Removido com sucesso.
13 | Atualizado com sucesso.
14 |
15 |
16 | Entrar
17 | Recuperar conta
18 | Informe sua senha.
19 | Informe seu e-mail.
20 |
21 |
22 | Informe sua senha.
23 | Informe seu e-mail.
24 |
25 |
26 | Recuperar conta
27 | Enviar
28 | Informe seu e-mail.
29 | Pronto, acabamos de enviar um link para seu e-mail.
30 |
31 |
32 | Nenhuma conta encontrada com este e-mail.
33 | Insira um e-mail válido.
34 | Senha inválida, tente novamente.
35 | Este e-mail já está em uso.
36 | Insira uma senha mais forte.
37 |
38 |
39 | Nova
40 | Descrição
41 | digite aqui...
42 | Editando…
43 | Status
44 | Salvar
45 | Informe a informação solicitada.
46 | Salvo com sucesso.
47 | Atualizado com sucesso.
48 | Erro ao salvar.
49 |
50 |
51 | Medicamento
52 | Glicemia
53 | Dieta
54 |
55 |
56 | Nenhuma medicação cadastrada.
57 | Deseja realmente remover este medicamento?
58 |
59 |
60 | Nenhuma glicemia cadastrada.
61 | Deseja realmente remover esta glicemia?
62 |
63 |
64 | Nenhuma refeição cadastrada.
65 | Deseja realmente remover esta refeição?
66 |
67 |
68 | Deseja realmente sair?
69 |
70 |
71 | Seu Peso(Kg)
72 | Carboidrato(g)
73 | Calcular Dosagem de Insulina
74 | Lembrete
75 | Alarme
76 | 00
77 | :
78 | 00
79 | Informe seu peso!
80 | Informe a quantidade de carboidrato!
81 | Redefinir dados
82 | Deseja excluir todos os dados existentes?
83 | Hora de tomar insulina!
84 |
85 |
86 | Atenção
87 | Entendi
88 |
89 | Hello blank fragment
90 |
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/form/FormMedicationFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.form
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.widget.Toast
8 | import androidx.core.view.isVisible
9 | import androidx.navigation.fragment.findNavController
10 | import androidx.navigation.fragment.navArgs
11 | import com.digo.emdiabetes.R
12 | import com.digo.emdiabetes.databinding.FragmentFormMedicationBinding
13 | import com.digo.emdiabetes.helper.BaseFragment
14 | import com.digo.emdiabetes.helper.FirebaseHelper
15 | import com.digo.emdiabetes.helper.initToolbar
16 | import com.digo.emdiabetes.helper.showBottomSheet
17 | import com.digo.emdiabetes.model.Medication
18 |
19 | class FormMedicationFragment : BaseFragment() {
20 |
21 | private val args: FormMedicationFragmentArgs by navArgs()
22 |
23 | private var _binding: FragmentFormMedicationBinding? = null
24 | private val binding get() = _binding!!
25 |
26 | private lateinit var medication: Medication
27 | private var newMedication: Boolean = true
28 |
29 | override fun onCreateView(
30 | inflater: LayoutInflater, container: ViewGroup?,
31 | savedInstanceState: Bundle?
32 | ): View {
33 | _binding = FragmentFormMedicationBinding.inflate(inflater, container, false)
34 | return binding.root
35 | }
36 |
37 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
38 | super.onViewCreated(view, savedInstanceState)
39 | initToolbar(binding.toolbar)
40 |
41 | initListeners()
42 |
43 | getArgs()
44 | }
45 |
46 | private fun getArgs() {
47 | args.medication.let {
48 | if (it != null){
49 | medication = it
50 |
51 | configMedication()
52 | }
53 | }
54 | }
55 |
56 | private fun configMedication() {
57 | newMedication = false
58 | binding.textToolbar.text = getString(R.string.text_editing_form_fragment)
59 |
60 | binding.edtDescription.setText(medication.nome)
61 | binding.edtDosagem.setText(medication.dosagem)
62 | }
63 |
64 | /*
65 | private fun setStatus() {
66 | binding.radioGroup.check(
67 | when (task.status) {
68 | 0 -> {
69 | R.id.rbTodo
70 | }
71 | 1 -> {
72 | R.id.rbDoing
73 | }
74 | else -> {
75 | R.id.rbDone
76 | }
77 | }
78 | )
79 | }
80 | */
81 |
82 | private fun initListeners() {
83 | binding.btnSave.setOnClickListener { validateData() }
84 |
85 | }
86 |
87 |
88 | private fun validateData() {
89 | val nome = binding.edtDescription.text.toString().trim()
90 | val dosagem = binding.edtDosagem.text.toString().trim()
91 |
92 | if (nome.isNotEmpty()) {
93 |
94 | hideKeyboard()
95 |
96 | binding.progressBar.isVisible = true
97 |
98 | if (newMedication) medication = Medication()
99 | medication.nome = nome
100 | medication.dosagem = dosagem
101 | //task.status = statusTask
102 |
103 | saveMedication()
104 | } else {
105 | showBottomSheet(message = R.string.text_description_empty_form_fragment)
106 | }
107 | }
108 |
109 | private fun saveMedication() {
110 | FirebaseHelper
111 | .getDatabase()
112 | .child("medication")
113 | .child(FirebaseHelper.getIdUser() ?: "")
114 | .child(medication.id)
115 | .setValue(medication)
116 | .addOnCompleteListener { medication ->
117 | if (medication.isSuccessful) {
118 | if (newMedication) { // Nova tarefa
119 | findNavController().popBackStack()
120 | Toast.makeText(
121 | requireContext(),
122 | R.string.text_save_sucess_form_fragment,
123 | Toast.LENGTH_SHORT
124 | ).show()
125 | } else { // Editando tarefa
126 | binding.progressBar.isVisible = false
127 | Toast.makeText(
128 | requireContext(),
129 | R.string.text_update_sucess_form_fragment,
130 | Toast.LENGTH_SHORT
131 | ).show()
132 | }
133 | } else {
134 | Toast.makeText(requireContext(), R.string.text_erro_save_form_fragment, Toast.LENGTH_SHORT)
135 | .show()
136 | }
137 | }.addOnFailureListener {
138 | binding.progressBar.isVisible = false
139 | Toast.makeText(requireContext(), R.string.text_erro_save_form_fragment, Toast.LENGTH_SHORT)
140 | .show()
141 | }
142 | }
143 |
144 | override fun onDestroyView() {
145 | super.onDestroyView()
146 | _binding = null
147 | }
148 |
149 | }
--------------------------------------------------------------------------------
/app/src/main/res/navigation/main_graph.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
18 |
23 |
24 |
29 |
34 |
37 |
40 |
43 |
46 |
47 |
50 |
55 |
60 |
63 |
66 |
67 |
72 |
77 |
78 |
83 |
87 |
88 |
93 |
97 |
98 |
103 |
107 |
108 |
112 |
115 |
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/form/FormGlycemiaFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui.form
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import android.widget.Toast
8 | import androidx.core.view.isVisible
9 | import androidx.navigation.fragment.findNavController
10 | import androidx.navigation.fragment.navArgs
11 | import com.digo.emdiabetes.R
12 | import com.digo.emdiabetes.databinding.FragmentFormGlycemiaBinding
13 | import com.digo.emdiabetes.helper.BaseFragment
14 | import com.digo.emdiabetes.helper.FirebaseHelper
15 | import com.digo.emdiabetes.helper.initToolbar
16 | import com.digo.emdiabetes.helper.showBottomSheet
17 | import com.digo.emdiabetes.model.Glycemia
18 |
19 | class FormGlycemiaFragment : BaseFragment() {
20 |
21 | private val args: FormGlycemiaFragmentArgs by navArgs()
22 |
23 | private var _binding: FragmentFormGlycemiaBinding? = null
24 | private val binding get() = _binding!!
25 |
26 | private lateinit var glycemia: Glycemia
27 | private var newGlycemia: Boolean = true
28 |
29 | override fun onCreateView(
30 | inflater: LayoutInflater, container: ViewGroup?,
31 | savedInstanceState: Bundle?
32 | ): View {
33 | _binding = FragmentFormGlycemiaBinding.inflate(inflater, container, false)
34 | return binding.root
35 | }
36 |
37 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
38 | super.onViewCreated(view, savedInstanceState)
39 | initToolbar(binding.toolbar)
40 |
41 | initListeners()
42 |
43 | getArgs()
44 | }
45 |
46 | private fun getArgs() {
47 | args.glycemia.let {
48 | if (it != null){
49 | glycemia = it
50 |
51 | configGlycemia()
52 | }
53 | }
54 | }
55 |
56 | private fun configGlycemia() {
57 | newGlycemia = false
58 |
59 | binding.textToolbar.text = getString(R.string.text_editing_form_fragment)
60 |
61 | binding.edtDescription.setText(glycemia.descricao)
62 | binding.edtGlycemia.setText(glycemia.glicemia)
63 | binding.edtDia.setText(glycemia.dia.toString())
64 | binding.edtMes.setText(glycemia.mes.toString())
65 | binding.edtAno.setText(glycemia.ano.toString())
66 | }
67 |
68 | /*
69 | private fun setStatus() {
70 | binding.radioGroup.check(
71 | when (task.status) {
72 | 0 -> {
73 | R.id.rbTodo
74 | }
75 | 1 -> {
76 | R.id.rbDoing
77 | }
78 | else -> {
79 | R.id.rbDone
80 | }
81 | }
82 | )
83 | }
84 | */
85 |
86 | private fun initListeners() {
87 | binding.btnSave.setOnClickListener { validateData() }
88 |
89 | }
90 |
91 |
92 | private fun validateData() {
93 | //quantidade de glicemia
94 | val glicemia = binding.edtGlycemia.text.toString().trim()
95 | val descricao = binding.edtDescription.text.toString().trim()
96 | val dia = binding.edtDia.text.toString().toInt()
97 | val mes = binding.edtMes.text.toString().toInt()
98 | val ano = binding.edtAno.text.toString().toInt()
99 |
100 | if (glicemia.isNotEmpty()) {
101 |
102 | hideKeyboard()
103 |
104 | binding.progressBar.isVisible = true
105 |
106 | if (newGlycemia) glycemia= Glycemia()
107 | glycemia.glicemia = glicemia
108 | glycemia.descricao = descricao
109 | glycemia.dia = dia
110 | glycemia.mes = mes
111 | glycemia.ano = ano
112 |
113 | saveGlycemia()
114 | } else {
115 | showBottomSheet(message = R.string.text_description_empty_form_fragment)
116 | }
117 | }
118 |
119 | private fun saveGlycemia() {
120 | FirebaseHelper
121 | .getDatabase()
122 | .child("glycemia")
123 | .child(FirebaseHelper.getIdUser() ?: "")
124 | .child(glycemia.id)
125 | .setValue(glycemia)
126 | .addOnCompleteListener { glycemia ->
127 | if (glycemia.isSuccessful) {
128 | if (newGlycemia) { // Nova tarefa
129 | findNavController().popBackStack()
130 | Toast.makeText(
131 | requireContext(),
132 | R.string.text_save_sucess_form_fragment,
133 | Toast.LENGTH_SHORT
134 | ).show()
135 | } else { // Editando tarefa
136 | binding.progressBar.isVisible = false
137 | Toast.makeText(
138 | requireContext(),
139 | R.string.text_update_sucess_form_fragment,
140 | Toast.LENGTH_SHORT
141 | ).show()
142 | }
143 | } else {
144 | Toast.makeText(requireContext(), R.string.text_erro_save_form_fragment, Toast.LENGTH_SHORT)
145 | .show()
146 | }
147 | }.addOnFailureListener {
148 | binding.progressBar.isVisible = false
149 | Toast.makeText(requireContext(), R.string.text_erro_save_form_fragment, Toast.LENGTH_SHORT)
150 | .show()
151 | }
152 | }
153 |
154 | override fun onDestroyView() {
155 | super.onDestroyView()
156 | _binding = null
157 | }
158 |
159 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/CalcInsulinaFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 | import android.app.AlertDialog
4 | import android.app.TimePickerDialog
5 | import android.content.Intent
6 | import android.content.pm.PackageManager
7 | import android.os.Bundle
8 | import android.provider.AlarmClock
9 | import androidx.fragment.app.Fragment
10 | import android.view.LayoutInflater
11 | import android.view.View
12 | import android.view.ViewGroup
13 | import android.widget.*
14 | import android.widget.Toast.*
15 | import androidx.navigation.fragment.findNavController
16 | import com.digo.emdiabetes.R
17 | import com.digo.emdiabetes.databinding.FragmentCalcInsulinaBinding
18 | import com.digo.emdiabetes.model.CalcularInsulina
19 | import java.text.NumberFormat
20 | import java.util.*
21 |
22 |
23 | class CalcInsulinaFragment : Fragment() {
24 | private var _binding: FragmentCalcInsulinaBinding? = null
25 | private val binding get() = _binding!!
26 |
27 | private lateinit var edit_peso: EditText
28 | private lateinit var edit_carboidrato: EditText
29 | private lateinit var bt_calcular: Button
30 | private lateinit var txt_resultado_ui: TextView
31 | private lateinit var ic_redefinir_dados: ImageView
32 | private lateinit var bt_lembrete:Button
33 | private lateinit var bt_alarme:Button
34 | private lateinit var txt_hora: TextView
35 | private lateinit var txt_minutos: TextView
36 |
37 | private lateinit var calcularInsulina: CalcularInsulina
38 | private var resultado = 0.0
39 |
40 | lateinit var timePickerDialog: TimePickerDialog
41 | lateinit var calendario: Calendar
42 | var horaAtual = 0
43 | var minutosAtuais = 0
44 |
45 | override fun onCreateView(
46 | inflater: LayoutInflater, container: ViewGroup?,
47 | savedInstanceState: Bundle?
48 | ): View? {
49 | // Inflate the layout for this fragment
50 | _binding = FragmentCalcInsulinaBinding.inflate(inflater, container, false)
51 | return binding.root
52 | }
53 |
54 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
55 | super.onViewCreated(view, savedInstanceState)
56 |
57 | iniciarComponentes()
58 | calcularInsulina = CalcularInsulina()
59 |
60 | bt_calcular.setOnClickListener{
61 | if(edit_peso.text.toString().isEmpty()){
62 | Toast.makeText(requireContext(), R.string.toast_informe_peso, Toast.LENGTH_SHORT).show()
63 | }else if (edit_carboidrato.text.toString().isEmpty()){
64 | Toast.makeText(requireContext(), R.string.toast_informe_carboidrato, Toast.LENGTH_SHORT).show()
65 | }else{
66 | val peso = edit_peso.text.toString().toDouble()
67 | val carboidrato = edit_carboidrato.text.toString().toDouble()
68 | calcularInsulina.calcular(peso, carboidrato)
69 | resultado = calcularInsulina.resultado()
70 | val formatar = NumberFormat.getNumberInstance(Locale("pt","BR"))
71 | formatar.isGroupingUsed = false
72 | txt_resultado_ui.text = formatar.format(resultado) + " UI"
73 | }
74 | }
75 | ic_redefinir_dados.setOnClickListener{
76 | val alertDialog = AlertDialog.Builder(requireContext())
77 | alertDialog.setTitle(R.string.dialog_titulo)
78 | .setMessage(R.string.dialog_desc)
79 | .setPositiveButton("Ok",{dialogInterface, i ->
80 | edit_peso.setText("")
81 | edit_carboidrato.setText("")
82 | txt_resultado_ui.text = ""
83 | })
84 | alertDialog.setNegativeButton("Cancelar", {dialogInterface, i ->
85 |
86 | })
87 | val dialog = alertDialog.create()
88 | dialog.show()
89 | }
90 |
91 | bt_lembrete.setOnClickListener{
92 |
93 | calendario = Calendar.getInstance()
94 | horaAtual = calendario.get(Calendar.HOUR_OF_DAY)
95 | minutosAtuais = calendario.get(Calendar.MINUTE)
96 | timePickerDialog = TimePickerDialog(requireContext(), {
97 | timePicker: TimePicker, hourOfDay: Int, minutes: Int ->
98 | txt_hora.text = String.format("%02d",hourOfDay)
99 | txt_minutos.text = String.format("%02d",minutes)
100 | },horaAtual,minutosAtuais,true)
101 | timePickerDialog.show()
102 | }
103 |
104 | bt_alarme.setOnClickListener{
105 | if (!txt_hora.text.toString().isEmpty() && !txt_minutos.text.toString().isEmpty()){
106 | val intent = Intent(AlarmClock.ACTION_SET_ALARM)
107 | intent.putExtra(AlarmClock.EXTRA_HOUR, txt_hora.text.toString().toInt())
108 | intent.putExtra(AlarmClock.EXTRA_MINUTES, txt_minutos.text.toString().toInt())
109 | intent.putExtra(AlarmClock.EXTRA_MESSAGE, getString(R.string.alarme_mensagem)+" Sua dosagem é: "+txt_resultado_ui.text)
110 | startActivity(intent)
111 | }
112 | }
113 | binding.logoEmDBack.setOnClickListener{
114 | backHome()
115 | }
116 | }
117 |
118 | private fun backHome(){
119 | findNavController().navigate(R.id.action_calcInsulinaFragment_to_homeFragment)
120 | }
121 |
122 |
123 | private fun iniciarComponentes(){
124 | edit_peso = binding.editPeso
125 | edit_carboidrato = binding.editCarboidrato
126 | bt_calcular = binding.btCalcular
127 | txt_resultado_ui = binding.txtResultadoUi
128 | ic_redefinir_dados = binding.icRedefinir
129 | bt_alarme = binding.btAlarme
130 | bt_lembrete = binding.btDefinirLembrete
131 | txt_hora = binding.txtHora
132 | txt_minutos = binding.txtMinutos
133 | }
134 |
135 | override fun onDestroyView() {
136 | super.onDestroyView()
137 | _binding = null
138 | }
139 |
140 | }
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_form_medication.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
23 |
24 |
31 |
32 |
33 |
34 |
35 |
36 |
46 |
47 |
51 |
52 |
60 |
61 |
62 |
76 |
77 |
87 |
88 |
101 |
102 |
116 |
117 |
129 |
130 |
131 |
132 |
133 |
134 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_form_diet.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
23 |
24 |
31 |
32 |
33 |
34 |
35 |
36 |
46 |
47 |
51 |
52 |
60 |
61 |
62 |
76 |
77 |
78 |
88 |
89 |
103 |
104 |
119 |
120 |
132 |
133 |
134 |
135 |
136 |
137 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/DietFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 |
4 | import android.app.TimePickerDialog
5 | import android.content.Intent
6 | import android.os.Bundle
7 | import android.provider.AlarmClock
8 | import androidx.fragment.app.Fragment
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import android.widget.TimePicker
13 | import android.widget.Toast
14 | import androidx.core.view.isVisible
15 | import androidx.navigation.fragment.findNavController
16 | import androidx.recyclerview.widget.LinearLayoutManager
17 | import com.digo.emdiabetes.R
18 | import com.digo.emdiabetes.databinding.FragmentDietBinding
19 |
20 | import com.digo.emdiabetes.helper.FirebaseHelper
21 | import com.digo.emdiabetes.helper.showBottomSheet
22 | import com.digo.emdiabetes.model.Diet
23 | import com.digo.emdiabetes.ui.adapter.DietAdapter
24 | import com.google.firebase.database.DataSnapshot
25 | import com.google.firebase.database.DatabaseError
26 | import com.google.firebase.database.ValueEventListener
27 | import java.util.*
28 |
29 |
30 | class DietFragment : Fragment() {
31 |
32 | private var _binding: FragmentDietBinding? = null
33 | private val binding get() = _binding!!
34 |
35 | private lateinit var dietAdapter: DietAdapter
36 |
37 | private val dietList = mutableListOf()
38 |
39 | lateinit var timePickerDialog: TimePickerDialog
40 | lateinit var calendario: Calendar
41 | var horaAtual = 0
42 | var minutosAtuais = 0
43 |
44 | override fun onCreateView(
45 | inflater: LayoutInflater, container: ViewGroup?,
46 | savedInstanceState: Bundle?
47 | ): View {
48 | _binding = FragmentDietBinding.inflate(inflater, container, false)
49 | return binding.root
50 | }
51 |
52 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
53 | super.onViewCreated(view, savedInstanceState)
54 |
55 | initClicks()
56 |
57 | getDiet()
58 |
59 | }
60 |
61 | //botão ADD
62 | private fun initClicks() {
63 | binding.fabAddContact.setOnClickListener {
64 | val action = HomeFragmentDirections
65 | .actionHomeFragmentToFormDietFragment(null)
66 | findNavController().navigate(action)
67 | }
68 | }
69 |
70 | private fun getDiet() {
71 | FirebaseHelper
72 | .getDatabase()
73 | .child("diet")
74 | .child(FirebaseHelper.getIdUser() ?: "")
75 | .addValueEventListener(object : ValueEventListener {
76 | override fun onDataChange(snapshot: DataSnapshot) {
77 | if (snapshot.exists()) {
78 |
79 | dietList.clear()
80 | for (snap in snapshot.children) {
81 | val diet = snap.getValue(Diet::class.java) as Diet
82 |
83 | dietList.add(diet)
84 | }
85 |
86 | dietList.reverse()
87 | initAdapter()
88 | }
89 |
90 | dietEmpty()
91 |
92 | binding.progressBar.isVisible = false
93 | }
94 |
95 | override fun onCancelled(error: DatabaseError) {
96 | Toast.makeText(requireContext(), "Erro", Toast.LENGTH_SHORT).show()
97 | }
98 |
99 | })
100 | }
101 |
102 | private fun dietEmpty() {
103 | binding.textInfo.text = if (dietList.isEmpty()) {
104 | getText(R.string.text_diet_list_empty_fragment)
105 | } else {
106 | ""
107 | }
108 | }
109 |
110 | private fun initAdapter() {
111 | binding.rvTask.layoutManager = LinearLayoutManager(requireContext())
112 | binding.rvTask.setHasFixedSize(true)
113 | dietAdapter = DietAdapter(requireContext(), dietList) { diet, select ->
114 | optionSelect(diet, select)
115 | }
116 | binding.rvTask.adapter = dietAdapter
117 | }
118 |
119 | private fun alarme(diet: Diet){
120 | calendario = Calendar.getInstance()
121 | horaAtual = calendario.get(Calendar.HOUR_OF_DAY)
122 | minutosAtuais = calendario.get(Calendar.MINUTE)
123 | timePickerDialog = TimePickerDialog(requireContext(), {
124 | timePicker: TimePicker, hourOfDay: Int, minutes: Int ->
125 | val intent = Intent(AlarmClock.ACTION_SET_ALARM)
126 | intent.putExtra(AlarmClock.EXTRA_HOUR, hourOfDay)
127 | intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes)
128 | intent.putExtra(AlarmClock.EXTRA_MESSAGE, "Hora do "+diet.refeicao+"! Alimento(s):"+diet.alimento)
129 | startActivity(intent)
130 | },horaAtual,minutosAtuais,true)
131 | timePickerDialog.show()
132 | }
133 |
134 | private fun optionSelect(diet: Diet, select: Int) {
135 | when (select) {
136 | DietAdapter.SELECT_REMOVE -> {
137 | deleteDiet(diet)
138 | }
139 | DietAdapter.SELECT_EDIT -> {
140 | val action = HomeFragmentDirections
141 | .actionHomeFragmentToFormDietFragment(diet)
142 | findNavController().navigate(action)
143 | }
144 | DietAdapter.SELECT_DETAILS ->{
145 | alarme(diet)
146 | }
147 | }
148 | }
149 |
150 | private fun updateDiet(diet: Diet) {
151 | FirebaseHelper
152 | .getDatabase()
153 | .child("diet")
154 | .child(FirebaseHelper.getIdUser() ?: "")
155 | .child(diet.id)
156 | .setValue(diet)
157 | .addOnCompleteListener { diet ->
158 | if (diet.isSuccessful) {
159 | Toast.makeText(
160 | requireContext(),
161 | R.string.text_task_update_sucess,
162 | Toast.LENGTH_SHORT
163 | ).show()
164 | } else {
165 | showBottomSheet(message = R.string.error_generic)
166 | }
167 | }.addOnFailureListener {
168 | binding.progressBar.isVisible = false
169 | showBottomSheet(message = R.string.error_generic)
170 | }
171 | }
172 |
173 | private fun deleteDiet(diet: Diet) {
174 | showBottomSheet(
175 | titleButton = R.string.text_button_confirm,
176 | message = R.string.text_message_delete_diet_fragment,
177 | onClick = {
178 | FirebaseHelper
179 | .getDatabase()
180 | .child("diet")
181 | .child(FirebaseHelper.getIdUser() ?: "")
182 | .child(diet.id)
183 | .removeValue()
184 | .addOnCompleteListener { diet ->
185 | if (diet.isSuccessful) {
186 | Toast.makeText(
187 | requireContext(),
188 | R.string.text_task_update_sucess,
189 | Toast.LENGTH_SHORT
190 | ).show()
191 | } else {
192 | showBottomSheet(message = R.string.error_generic)
193 | }
194 | }.addOnFailureListener {
195 | binding.progressBar.isVisible = false
196 | showBottomSheet(message = R.string.error_generic)
197 | }
198 |
199 | dietList.remove(diet)
200 | dietAdapter.notifyDataSetChanged()
201 |
202 | Toast.makeText(requireContext(), R.string.text_task_delete_sucess, Toast.LENGTH_SHORT).show()
203 | }
204 | )
205 | }
206 |
207 | override fun onDestroyView() {
208 | super.onDestroyView()
209 | _binding = null
210 | }
211 |
212 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/MedicationFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 | import android.app.TimePickerDialog
4 | import android.content.DialogInterface
5 | import android.content.Intent
6 | import android.os.Bundle
7 | import android.provider.AlarmClock
8 | import androidx.fragment.app.Fragment
9 | import android.view.LayoutInflater
10 | import android.view.View
11 | import android.view.ViewGroup
12 | import android.widget.Button
13 | import android.widget.TimePicker
14 | import android.widget.Toast
15 | import androidx.core.view.isVisible
16 | import androidx.navigation.fragment.findNavController
17 | import androidx.recyclerview.widget.LinearLayoutManager
18 | import com.digo.emdiabetes.R
19 | import com.digo.emdiabetes.databinding.FragmentMedicationBinding
20 |
21 | import com.digo.emdiabetes.helper.FirebaseHelper
22 | import com.digo.emdiabetes.helper.showBottomSheet
23 | import com.digo.emdiabetes.model.Medication
24 | import com.digo.emdiabetes.ui.adapter.MedicationAdapter
25 | import com.google.firebase.database.DataSnapshot
26 | import com.google.firebase.database.DatabaseError
27 | import com.google.firebase.database.ValueEventListener
28 | import java.util.*
29 |
30 | class MedicationFragment : Fragment() {
31 |
32 | private var _binding: FragmentMedicationBinding? = null
33 | private val binding get() = _binding!!
34 |
35 | private lateinit var medicationAdapter: MedicationAdapter
36 |
37 | private val medicationList = mutableListOf()
38 |
39 | lateinit var timePickerDialog: TimePickerDialog
40 | lateinit var calendario: Calendar
41 | var horaAtual = 0
42 | var minutosAtuais = 0
43 |
44 | override fun onCreateView(
45 | inflater: LayoutInflater, container: ViewGroup?,
46 | savedInstanceState: Bundle?
47 | ): View {
48 | _binding = FragmentMedicationBinding.inflate(inflater, container, false)
49 | return binding.root
50 | }
51 |
52 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
53 | super.onViewCreated(view, savedInstanceState)
54 |
55 | initClicks()
56 |
57 | getMedications()
58 | }
59 |
60 | //botão ADD
61 | private fun initClicks() {
62 | binding.fabAddMedication.setOnClickListener {
63 | val action = HomeFragmentDirections
64 | .actionHomeFragmentToFormTaskFragment(null)
65 | findNavController().navigate(action)
66 | }
67 | }
68 |
69 | private fun getMedications() {
70 | FirebaseHelper
71 | .getDatabase()
72 | .child("medication")
73 | .child(FirebaseHelper.getIdUser() ?: "")
74 | .addValueEventListener(object : ValueEventListener {
75 | override fun onDataChange(snapshot: DataSnapshot) {
76 | if (snapshot.exists()) {
77 |
78 | medicationList.clear()
79 | for (snap in snapshot.children) {
80 | val medication = snap.getValue(Medication::class.java) as Medication
81 |
82 | medicationList.add(medication)
83 | }
84 |
85 | medicationList.reverse()
86 | initAdapter()
87 | }
88 |
89 | medicationsEmpty()
90 |
91 | binding.progressBar.isVisible = false
92 | }
93 |
94 | override fun onCancelled(error: DatabaseError) {
95 | Toast.makeText(requireContext(), "Erro", Toast.LENGTH_SHORT).show()
96 | }
97 |
98 | })
99 | }
100 |
101 | private fun medicationsEmpty() {
102 | binding.textInfo.text = if (medicationList.isEmpty()) {
103 | getText(R.string.text_medication_list_empty_fragment)
104 | } else {
105 | ""
106 | }
107 | }
108 |
109 | private fun initAdapter() {
110 | binding.rvTask.layoutManager = LinearLayoutManager(requireContext())
111 | binding.rvTask.setHasFixedSize(true)
112 | medicationAdapter = MedicationAdapter(requireContext(), medicationList) { task, select ->
113 | optionSelect(task, select)
114 | }
115 | binding.rvTask.adapter = medicationAdapter
116 | }
117 |
118 |
119 | private fun alarme(medication: Medication){
120 | calendario = Calendar.getInstance()
121 | horaAtual = calendario.get(Calendar.HOUR_OF_DAY)
122 | minutosAtuais = calendario.get(Calendar.MINUTE)
123 | timePickerDialog = TimePickerDialog(requireContext(), {
124 | timePicker: TimePicker, hourOfDay: Int, minutes: Int ->
125 | val intent = Intent(AlarmClock.ACTION_SET_ALARM)
126 | intent.putExtra(AlarmClock.EXTRA_HOUR, hourOfDay)
127 | intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes)
128 | intent.putExtra(AlarmClock.EXTRA_MESSAGE, "hora da medicação: "+medication.nome+" Sua dosagem é de: "+medication.dosagem)
129 | startActivity(intent)
130 | },horaAtual,minutosAtuais,true)
131 | timePickerDialog.show()
132 | }
133 |
134 |
135 |
136 | private fun optionSelect(medication: Medication, select: Int) {
137 | when (select) {
138 | MedicationAdapter.SELECT_REMOVE -> {
139 | deleteMedication(medication)
140 | }
141 | MedicationAdapter.SELECT_EDIT -> {
142 | val action = HomeFragmentDirections
143 | .actionHomeFragmentToFormTaskFragment(medication)
144 | findNavController().navigate(action)
145 | }
146 | MedicationAdapter.SELECT_DETAILS ->{
147 | alarme(medication)
148 | }
149 | }
150 | }
151 |
152 | private fun updateMedication(medication: Medication) {
153 | FirebaseHelper
154 | .getDatabase()
155 | .child("medication")
156 | .child(FirebaseHelper.getIdUser() ?: "")
157 | .child(medication.id)
158 | .setValue(medication)
159 | .addOnCompleteListener { medication ->
160 | if (medication.isSuccessful) {
161 | Toast.makeText(
162 | requireContext(),
163 | R.string.text_task_update_sucess,
164 | Toast.LENGTH_SHORT
165 | ).show()
166 | } else {
167 | showBottomSheet(message = R.string.error_generic)
168 | }
169 | }.addOnFailureListener {
170 | binding.progressBar.isVisible = false
171 | showBottomSheet(message = R.string.error_generic)
172 | }
173 | }
174 |
175 | private fun deleteMedication(medication: Medication) {
176 | showBottomSheet(
177 | titleButton = R.string.text_button_confirm,
178 | message =R.string.text_message_delete_medication_fragment,
179 | onClick = {
180 | FirebaseHelper
181 | .getDatabase()
182 | .child("medication")
183 | .child(FirebaseHelper.getIdUser() ?: "")
184 | .child(medication.id)
185 | .removeValue()
186 | .addOnCompleteListener { medication ->
187 | if (medication.isSuccessful) {
188 | Toast.makeText(
189 | requireContext(),
190 | R.string.text_task_update_sucess,
191 | Toast.LENGTH_SHORT
192 | ).show()
193 | } else {
194 | showBottomSheet(message = R.string.error_generic)
195 | }
196 | }.addOnFailureListener {
197 | binding.progressBar.isVisible = false
198 | showBottomSheet(message = R.string.error_generic)
199 | }
200 |
201 | medicationList.remove(medication)
202 | medicationAdapter.notifyDataSetChanged()
203 |
204 | Toast.makeText(requireContext(), R.string.text_task_delete_sucess, Toast.LENGTH_SHORT).show()
205 | }
206 | )
207 | }
208 |
209 | override fun onDestroyView() {
210 | super.onDestroyView()
211 | _binding = null
212 | }
213 |
214 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_calc_insulina.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
10 |
14 |
15 |
24 |
25 |
35 |
36 |
46 |
47 |
65 |
66 |
85 |
86 |
101 |
102 |
114 |
115 |
128 |
129 |
143 |
144 |
158 |
159 |
171 |
172 |
184 |
185 |
197 |
198 |
199 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_form_glycemia.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
16 |
17 |
23 |
24 |
31 |
32 |
33 |
34 |
35 |
36 |
46 |
47 |
51 |
52 |
53 |
63 |
64 |
74 |
75 |
85 |
86 |
96 |
97 |
107 |
108 |
122 |
123 |
136 |
137 |
152 |
153 |
168 |
169 |
184 |
185 |
199 |
200 |
212 |
213 |
214 |
215 |
216 |
217 |
--------------------------------------------------------------------------------
/app/src/main/java/com/digo/emdiabetes/ui/GlycemiaFragment.kt:
--------------------------------------------------------------------------------
1 | package com.digo.emdiabetes.ui
2 |
3 | import android.app.TimePickerDialog
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.provider.AlarmClock
7 | import android.view.*
8 | import androidx.fragment.app.Fragment
9 | import android.widget.TimePicker
10 | import android.widget.Toast
11 | import androidx.appcompat.app.AppCompatActivity
12 | import androidx.core.view.isVisible
13 | import androidx.navigation.fragment.findNavController
14 | import androidx.recyclerview.widget.LinearLayoutManager
15 | import com.digo.emdiabetes.R
16 | import com.digo.emdiabetes.databinding.FragmentGlycemiaBinding
17 | import com.digo.emdiabetes.helper.FirebaseHelper
18 | import com.digo.emdiabetes.helper.showBottomSheet
19 | import com.digo.emdiabetes.model.Glycemia
20 | import com.digo.emdiabetes.model.Medication
21 | import com.digo.emdiabetes.ui.adapter.GlycemiaAdapter
22 | import com.digo.emdiabetes.ui.adapter.MedicationAdapter
23 | import com.ferfalk.simplesearchview.SimpleSearchView
24 | import com.google.firebase.database.DataSnapshot
25 | import com.google.firebase.database.DatabaseError
26 | import com.google.firebase.database.ValueEventListener
27 | import java.util.*
28 |
29 |
30 | class GlycemiaFragment : Fragment() {
31 |
32 |
33 | private var _binding: FragmentGlycemiaBinding? = null
34 | private val binding get() = _binding!!
35 |
36 | private lateinit var glycemiaAdapter: GlycemiaAdapter
37 |
38 | private val glycemiaList = mutableListOf()
39 |
40 | lateinit var timePickerDialog: TimePickerDialog
41 | lateinit var calendario: Calendar
42 | var horaAtual = 0
43 | var minutosAtuais = 0
44 |
45 | override fun onCreate(savedInstanceState: Bundle?) {
46 | super.onCreate(savedInstanceState)
47 | setHasOptionsMenu(true)
48 | }
49 |
50 | override fun onCreateView(
51 | inflater: LayoutInflater, container: ViewGroup?,
52 | savedInstanceState: Bundle?
53 | ): View {
54 | _binding = FragmentGlycemiaBinding.inflate(inflater, container, false)
55 | return binding.root
56 | }
57 |
58 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
59 | super.onViewCreated(view, savedInstanceState)
60 | (activity as AppCompatActivity).setSupportActionBar(binding.toolbar)
61 |
62 | initClicks()
63 | getGlycemias()
64 | initSearchView()
65 | }
66 |
67 | private fun initSearchView(){
68 | binding.searchView.setOnQueryTextListener(object : SimpleSearchView.OnQueryTextListener {
69 | //qd aperta o botão de pesquisar
70 | override fun onQueryTextSubmit(query: String): Boolean {
71 | return false
72 | }
73 | //faz a pesquisa em tempo real, conforme for digitando
74 | override fun onQueryTextChange(query: String): Boolean {
75 | binding.textInfo.text = if(glycemiaAdapter.searchGlycemia(query)){
76 | "Nenhum resultado encontrado"
77 | }else{
78 | ""
79 | }
80 | return true
81 | }
82 | //quando limpar o texto
83 | override fun onQueryTextCleared(): Boolean {
84 | return false
85 | }
86 | })
87 | binding.searchView.setOnSearchViewListener(object : SimpleSearchView.SearchViewListener {
88 | override fun onSearchViewShown() {
89 | }
90 |
91 | override fun onSearchViewClosed() {
92 | glycemiaAdapter.clearSearchGlycemia()
93 | binding.textInfo.text = ""
94 | }
95 |
96 | override fun onSearchViewShownAnimation() {
97 | }
98 |
99 | override fun onSearchViewClosedAnimation() {
100 | }
101 | })
102 | }
103 |
104 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
105 | if (item.itemId == R.id.menu_search){
106 |
107 | }else{
108 |
109 | }
110 | return super.onOptionsItemSelected(item)
111 | }
112 |
113 | override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
114 | //val inflater: MenuInflater = getMenuInflater()
115 | inflater.inflate(R.menu.menu_main, menu)
116 |
117 | val item = menu.findItem(R.id.menu_search)
118 | binding.searchView.setMenuItem(item)
119 |
120 | //return true
121 | }
122 |
123 | //botão ADD
124 | private fun initClicks() {
125 | binding.fabAddGlycemia.setOnClickListener {
126 | val action = HomeFragmentDirections
127 | .actionHomeFragmentToFormGlycemiaFragment(null)
128 | findNavController().navigate(action)
129 | }
130 | }
131 |
132 | private fun getGlycemias() {
133 | FirebaseHelper
134 | .getDatabase()
135 | .child("glycemia")
136 | .child(FirebaseHelper.getIdUser() ?: "")
137 | .addValueEventListener(object : ValueEventListener {
138 | override fun onDataChange(snapshot: DataSnapshot) {
139 | if (snapshot.exists()) {
140 | glycemiaList.clear()
141 | for (snap in snapshot.children) {
142 | val glycemia = snap.getValue(Glycemia::class.java) as Glycemia
143 |
144 | glycemiaList.add(glycemia)
145 | }
146 |
147 | glycemiaList.reverse()
148 | initAdapter()
149 | }
150 |
151 | glycemiasEmpty()
152 | binding.progressBar.isVisible = false
153 | }
154 |
155 | override fun onCancelled(error: DatabaseError) {
156 | Toast.makeText(requireContext(), "Erro", Toast.LENGTH_SHORT).show()
157 | }
158 |
159 | })
160 | }
161 |
162 | private fun glycemiasEmpty() {
163 | binding.textInfo.text = if (glycemiaList.isEmpty()) {
164 | getText(R.string.text_glycemia_list_empty_fragment)
165 | } else {
166 | ""
167 | }
168 | }
169 |
170 | private fun initAdapter() {
171 | binding.rvTask.layoutManager = LinearLayoutManager(requireContext())
172 | binding.rvTask.setHasFixedSize(true)
173 | glycemiaAdapter = GlycemiaAdapter(requireContext(), glycemiaList) { glycemia, select ->
174 | optionSelect(glycemia, select)
175 | }
176 | binding.rvTask.adapter = glycemiaAdapter
177 | }
178 |
179 | private fun alarme(glycemia: Glycemia){
180 | calendario = Calendar.getInstance()
181 | horaAtual = calendario.get(Calendar.HOUR_OF_DAY)
182 | minutosAtuais = calendario.get(Calendar.MINUTE)
183 | timePickerDialog = TimePickerDialog(requireContext(), {
184 | timePicker: TimePicker, hourOfDay: Int, minutes: Int ->
185 | val intent = Intent(AlarmClock.ACTION_SET_ALARM)
186 | intent.putExtra(AlarmClock.EXTRA_HOUR, hourOfDay)
187 | intent.putExtra(AlarmClock.EXTRA_MINUTES, minutes)
188 | intent.putExtra(AlarmClock.EXTRA_MESSAGE, "Hora de medir a glicemia!Glicemia escolhida:"+glycemia.glicemia+"mg/dL")
189 | startActivity(intent)
190 | },horaAtual,minutosAtuais,true)
191 | timePickerDialog.show()
192 | }
193 |
194 | private fun optionSelect(glycemia: Glycemia, select: Int) {
195 | when (select) {
196 | GlycemiaAdapter.SELECT_REMOVE -> {
197 | deleteGlycemia(glycemia)
198 | }
199 | GlycemiaAdapter.SELECT_EDIT -> {
200 | val action = HomeFragmentDirections
201 | .actionHomeFragmentToFormGlycemiaFragment(glycemia)
202 | findNavController().navigate(action)
203 | }
204 | GlycemiaAdapter.SELECT_DETAILS ->{
205 | alarme(glycemia)
206 | }
207 | }
208 | }
209 |
210 | private fun updateGlycemia(glycemia: Glycemia) {
211 | FirebaseHelper
212 | .getDatabase()
213 | .child("glycemia")
214 | .child(FirebaseHelper.getIdUser() ?: "")
215 | .child(glycemia.id)
216 | .setValue(glycemia)
217 | .addOnCompleteListener { glycemia ->
218 | if (glycemia.isSuccessful) {
219 | Toast.makeText(
220 | requireContext(),
221 | R.string.text_task_update_sucess,
222 | Toast.LENGTH_SHORT
223 | ).show()
224 | } else {
225 | showBottomSheet(message = R.string.error_generic)
226 | }
227 | }.addOnFailureListener {
228 | binding.progressBar.isVisible = false
229 | showBottomSheet(message = R.string.error_generic)
230 | }
231 | }
232 |
233 | private fun deleteGlycemia(glycemia: Glycemia) {
234 | showBottomSheet(
235 | titleButton = R.string.text_button_confirm,
236 | message = R.string.text_message_delete_glycemia_fragment,
237 | onClick = {
238 | FirebaseHelper
239 | .getDatabase()
240 | .child("glycemia")
241 | .child(FirebaseHelper.getIdUser() ?: "")
242 | .child(glycemia.id)
243 | .removeValue()
244 | .addOnCompleteListener { glycemia ->
245 | if (glycemia.isSuccessful) {
246 | Toast.makeText(
247 | requireContext(),
248 | R.string.text_task_update_sucess,
249 | Toast.LENGTH_SHORT
250 | ).show()
251 | } else {
252 | showBottomSheet(message = R.string.error_generic)
253 | }
254 | }.addOnFailureListener {
255 | binding.progressBar.isVisible = false
256 | showBottomSheet(message = R.string.error_generic)
257 | }
258 |
259 | glycemiaList.remove(glycemia)
260 | glycemiaAdapter.notifyDataSetChanged()
261 |
262 | Toast.makeText(
263 | requireContext(),
264 | R.string.text_task_delete_sucess,
265 | Toast.LENGTH_SHORT
266 | ).show()
267 | }
268 | )
269 | }
270 |
271 | override fun onDestroyView() {
272 | super.onDestroyView()
273 | _binding = null
274 | }
275 |
276 | }
--------------------------------------------------------------------------------