11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/diabefriend/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/model/measurement/ResultMeasurement.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.model.measurement;
2 |
3 | import lombok.Getter;
4 |
5 | @Getter
6 |
7 | public class ResultMeasurement {
8 |
9 | private Measurement measurement;
10 | private int sugarLevelAfterMeal;
11 |
12 | public ResultMeasurement(Measurement measurement, int sugarLevelAfterMeal) {
13 | this.measurement = measurement;
14 | this.sugarLevelAfterMeal = sugarLevelAfterMeal;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_proteins.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_notifications_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_carbohydrates.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_after_meal.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_search.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_fat.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_alarm.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_restaurant.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_insulin.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/buttonshape.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
9 |
15 |
19 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/product_adapter_element.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_sad_face.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
--------------------------------------------------------------------------------
/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
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/utils/Utils.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.utils;
2 |
3 | import android.content.SharedPreferences;
4 |
5 | import com.example.diabefriend.model.measurement.Measurement;
6 | import com.google.gson.Gson;
7 |
8 | import java.text.DecimalFormat;
9 |
10 | public class Utils {
11 | public static final DecimalFormat decimalFormat = new DecimalFormat("#.##");
12 |
13 | public static String createMeasurementJsonString(Measurement measurement) {
14 | return new Gson().toJson(measurement);
15 | }
16 |
17 | public static Measurement createMeasurementFromJson(SharedPreferences preferences, String measurementString) {
18 | String measurementJson = preferences.getString(measurementString, "");
19 | return new Gson().fromJson(measurementJson, Measurement.class);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_happy_face.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/diabefriend/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.InstrumentationRegistry;
6 | import androidx.test.runner.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("com.example.diabefriend", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_choice.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_carbohydrates_summary.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/alarm/Alarm.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.alarm;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.widget.Toast;
7 |
8 | import com.example.diabefriend.R;
9 | import com.example.diabefriend.ui.summary.SummaryActivity;
10 |
11 | public class Alarm extends BroadcastReceiver {
12 |
13 | @Override
14 | public void onReceive(Context context, Intent intent) {
15 | Intent intent1 = new Intent(context, SummaryActivity.class);
16 | intent1.putExtra(
17 | context.getResources().getString(R.string.measurement_string),
18 | intent.getParcelableExtra(context.getResources().getString(R.string.measurement_string)));
19 | context.startActivity(intent1);
20 |
21 | Toast.makeText(context, "IT IS TIME TO TEST YOUR SUGAR LEVEL!", Toast.LENGTH_LONG).show();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2019 Jakub Płotnikowski
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 |
--------------------------------------------------------------------------------
/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=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_summary.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.apk
2 | *.ap_
3 | *.aab
4 | *.dex
5 | *.class
6 | bin/
7 | gen/
8 | out/
9 | release/
10 | .gradle/
11 | build/
12 |
13 | local.properties
14 |
15 | proguard/
16 |
17 | *.log
18 |
19 | .navigation/
20 |
21 | captures/
22 |
23 | *.iml
24 |
25 | .externalNativeBuild
26 |
27 | vcs.xml
28 |
29 | lint/intermediates/
30 | lint/generated/
31 | lint/outputs/
32 | lint/tmp/
33 | # lint/reports/
34 |
35 | gen-external-apklibs
36 | output.json
37 |
38 | .cxx/
39 |
40 | *.ctxt
41 |
42 | .mtj.tmp/
43 |
44 | *.jar
45 | *.war
46 | *.nar
47 | *.ear
48 | *.zip
49 | *.tar.gz
50 | *.rar
51 |
52 | hs_err_pid*
53 |
54 | .gradle
55 | .signing/
56 |
57 | /*/build/
58 | /*/local.properties
59 | /*/out
60 | /*/*/build
61 | /*/*/production
62 | *.ipr
63 | *~
64 | *.swp
65 |
66 | obj/
67 |
68 | *.iws
69 | /out/
70 |
71 | .idea/*
72 |
73 | .DS_Store
74 | .DS_Store?
75 | ._*
76 | .Spotlight-V100
77 | .Trashes
78 | ehthumbs.db
79 | Thumbs.db
80 |
81 | .classpath
82 | .project
83 | .cproject
84 | .settings/
85 | .idea_modules/
86 |
87 | atlassian-ide-plugin.xml
88 |
89 | com_crashlytics_export_strings.xml
90 | crashlytics.properties
91 | crashlytics-build.properties
92 | fabric.properties
93 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_add_measurement.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/notification/NotificationChannels.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.notification;
2 |
3 | import android.app.Application;
4 | import android.app.Notification;
5 | import android.app.NotificationChannel;
6 | import android.app.NotificationManager;
7 | import android.os.Build;
8 |
9 | public class NotificationChannels extends Application {
10 | public static final String CHANNEL_ONE_ID = "channel_high";
11 |
12 | @Override
13 | public void onCreate() {
14 | super.onCreate();
15 | createNotificationChannels();
16 | }
17 |
18 | private void createNotificationChannels() {
19 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
20 | NotificationChannel channelOne = new NotificationChannel(
21 | CHANNEL_ONE_ID,
22 | "channel one",
23 | NotificationManager.IMPORTANCE_HIGH
24 | );
25 | channelOne.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
26 | channelOne.enableLights(true);
27 |
28 | NotificationManager manager = getSystemService(NotificationManager.class);
29 | manager.createNotificationChannel(channelOne);
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/model/measurement/Measurement.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.model.measurement;
2 |
3 |
4 | import android.os.Parcel;
5 | import android.os.Parcelable;
6 |
7 | import lombok.AllArgsConstructor;
8 | import lombok.Builder;
9 | import lombok.Getter;
10 |
11 | @Getter
12 | @Builder
13 | @AllArgsConstructor
14 | public class Measurement implements Parcelable {
15 |
16 | private int carbohydratesInGrams;
17 | private float insulinInUnits;
18 | private int sugarLevelBeforeMeal;
19 |
20 | private Measurement(Parcel in) {
21 | this.carbohydratesInGrams = in.readInt();
22 | this.insulinInUnits = in.readFloat();
23 | this.sugarLevelBeforeMeal = in.readInt();
24 | }
25 |
26 | public static final Creator CREATOR = new Creator() {
27 | @Override
28 | public Measurement createFromParcel(Parcel in) {
29 | return new Measurement(in);
30 | }
31 |
32 | @Override
33 | public Measurement[] newArray(int size) {
34 | return new Measurement[size];
35 | }
36 | };
37 |
38 | @Override
39 | public int describeContents() {
40 | return 0;
41 | }
42 |
43 | @Override
44 | public void writeToParcel(Parcel dest, int flags) {
45 | dest.writeInt(carbohydratesInGrams);
46 | dest.writeFloat(insulinInUnits);
47 | dest.writeInt(sugarLevelBeforeMeal);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.example.diabefriend"
7 | minSdkVersion 22
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
24 | implementation 'me.zhanghai.android.materialprogressbar:library:1.6.1'
25 | implementation 'com.google.android.material:material:1.1.0'
26 | implementation "com.android.support:support-compat:28.0.0"
27 | implementation 'androidx.appcompat:appcompat:1.2.0-alpha02'
28 | implementation 'com.google.android.material:material:1.2.0-alpha04'
29 | implementation 'com.google.code.gson:gson:2.8.5'
30 | compileOnly 'org.projectlombok:lombok:1.18.12'
31 | annotationProcessor 'org.projectlombok:lombok:1.18.12'
32 | compileOnly 'javax.annotation:javax.annotation-api:1.3.1'
33 | implementation 'androidx.legacy:legacy-support-v4:1.0.0'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'androidx.test:runner:1.3.0-alpha03'
36 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha03'
37 | implementation 'androidx.recyclerview:recyclerview:1.1.0'
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
30 |
31 |
32 |
33 |
38 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
20 |
21 |
27 |
28 |
29 |
30 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend;
2 |
3 | import android.os.Bundle;
4 | import android.view.MenuItem;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.appcompat.app.AppCompatActivity;
8 | import androidx.appcompat.widget.Toolbar;
9 | import androidx.fragment.app.Fragment;
10 |
11 | import com.example.diabefriend.ui.measurement.MeasurementFragment;
12 | import com.example.diabefriend.ui.search.SearchForProductFragment;
13 | import com.google.android.material.bottomnavigation.BottomNavigationView;
14 |
15 | public class MainActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 | Toolbar toolbar = findViewById(R.id.toolbar);
22 | setSupportActionBar(toolbar);
23 |
24 | BottomNavigationView navigation = findViewById(R.id.navigation);
25 | navigation.setOnNavigationItemSelectedListener(createOnNavigationItemListener());
26 | navigation.setSelectedItemId(R.id.measurement);
27 | }
28 |
29 | private BottomNavigationView.OnNavigationItemSelectedListener createOnNavigationItemListener() {
30 | return new BottomNavigationView.OnNavigationItemSelectedListener() {
31 | @Override
32 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
33 | Fragment selectedFragment = null;
34 | switch (item.getItemId()) {
35 | case R.id.measurement:
36 | selectedFragment = new MeasurementFragment();
37 | break;
38 | case R.id.search_for_product:
39 | selectedFragment = new SearchForProductFragment();
40 | break;
41 | }
42 |
43 | getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer, selectedFragment).commit();
44 | return true;
45 | }
46 | };
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/data/DataManager.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.data;
2 |
3 | import android.content.Context;
4 | import android.util.Log;
5 |
6 | import com.example.diabefriend.R;
7 | import com.example.diabefriend.model.product.Product;
8 |
9 | import java.io.BufferedReader;
10 | import java.io.IOException;
11 | import java.io.InputStream;
12 | import java.io.InputStreamReader;
13 | import java.nio.charset.Charset;
14 | import java.util.ArrayList;
15 | import java.util.List;
16 |
17 | public class DataManager {
18 | private Context context;
19 |
20 | public DataManager(Context context) {
21 | this.context = context;
22 | }
23 |
24 | public List readProductsData() {
25 | List products = new ArrayList<>();
26 | InputStream inputStream = context.getResources().openRawResource(R.raw.productsdatabase);
27 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
28 |
29 | String line = "";
30 | try {
31 | while ((line = bufferedReader.readLine()) != null) {
32 | String[] tokens = line.split("\t");
33 | Product product = new Product(
34 | tokens[0],
35 | Float.parseFloat(tokens[1]),
36 | Float.parseFloat(tokens[2]),
37 | Float.parseFloat(tokens[3]),
38 | Float.parseFloat(tokens[4]),
39 | Float.parseFloat(tokens[5])
40 | );
41 | products.add(product);
42 |
43 | Log.d("Product created", "New product has just been created: " + product);
44 | }
45 | } catch (IOException e) {
46 | Log.wtf("SearchForProductsActivity", "Error while reading data from file on line" + line, e);
47 | e.printStackTrace();
48 | }
49 |
50 | return products;
51 | }
52 |
53 | public List getProductNames(List products) {
54 | List productNames = new ArrayList<>();
55 | for (Product product : products) {
56 | productNames.add(product.getName());
57 | }
58 | return productNames;
59 | }
60 |
61 | public Product getProductByName(List products, String productName) {
62 | for (Product product : products) {
63 | if (product.getName().equals(productName)) {
64 | return product;
65 | }
66 | }
67 | return null;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/model/product/ProductListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.model.product;
2 |
3 | import android.content.Context;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.recyclerview.widget.RecyclerView;
12 |
13 | import com.example.diabefriend.R;
14 |
15 | import java.util.ArrayList;
16 | import java.util.List;
17 |
18 | public class ProductListAdapter extends RecyclerView.Adapter {
19 |
20 | private final ArrayList filteredProductNames;
21 | private LayoutInflater inflater;
22 | private List productNames;
23 | private OnProductNameClick onProductNameClick;
24 |
25 |
26 | public ProductListAdapter(Context context, List productNames) {
27 | inflater = LayoutInflater.from(context);
28 | this.productNames = productNames;
29 | this.filteredProductNames = new ArrayList<>(productNames);
30 | }
31 |
32 | @NonNull
33 | @Override
34 | public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
35 | View view = inflater.inflate(R.layout.product_adapter_element, parent, false);
36 | return new ProductViewHolder(view);
37 | }
38 |
39 |
40 | @Override
41 | public void onBindViewHolder(ProductViewHolder holder, final int position) {
42 | holder.productNameTextView.setText(filteredProductNames.get(position));
43 | holder.linearLayout.setOnClickListener(new View.OnClickListener() {
44 | @Override
45 | public void onClick(View v) {
46 | onProductNameClick.click(filteredProductNames.get(position));
47 | }
48 | });
49 | }
50 |
51 | @Override
52 | public int getItemCount() {
53 | return filteredProductNames.size();
54 | }
55 |
56 | public void filter(CharSequence s) {
57 | filteredProductNames.clear();
58 | for (String productName : productNames) {
59 | if (productName.toLowerCase().contains(s.toString().toLowerCase())) {
60 | filteredProductNames.add(productName);
61 | }
62 | }
63 | notifyDataSetChanged();
64 | }
65 |
66 | public void setOnProductNameClick(OnProductNameClick onProductNameClick) {
67 | this.onProductNameClick = onProductNameClick;
68 | }
69 |
70 | class ProductViewHolder extends RecyclerView.ViewHolder {
71 | private final LinearLayout linearLayout;
72 | TextView productNameTextView;
73 |
74 | ProductViewHolder(View itemView) {
75 | super(itemView);
76 | productNameTextView = itemView.findViewById(R.id.holderTextView);
77 | linearLayout = itemView.findViewById(R.id.holderLinearLayout);
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/diabefriend/dialogs/DialogsManager.java:
--------------------------------------------------------------------------------
1 | package com.example.diabefriend.dialogs;
2 |
3 | import android.content.Context;
4 | import android.content.DialogInterface;
5 |
6 | import androidx.appcompat.app.AlertDialog;
7 |
8 | import com.example.diabefriend.R;
9 | import com.example.diabefriend.model.measurement.Measurement;
10 | import com.example.diabefriend.utils.Utils;
11 |
12 | public class DialogsManager {
13 |
14 | private void createDialogAndShow(AlertDialog.Builder builder) {
15 | AlertDialog alertDialog = builder.create();
16 | alertDialog.show();
17 | }
18 |
19 | public void showInvalidInputDialog(Context context) {
20 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
21 | builder.setTitle(R.string.invalid_input_dialog).setMessage(R.string.try_again_dialog);
22 | builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
23 | @Override
24 | public void onClick(DialogInterface dialog, int which) {
25 | dialog.dismiss();
26 | }
27 | });
28 |
29 | createDialogAndShow(builder);
30 | }
31 |
32 | public void showNoMeasurementFoundDialog(Context context) {
33 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
34 | builder.setTitle(R.string.no_measurement_found_dialog_title).setMessage(R.string.try_again_dialog);
35 | builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
36 | @Override
37 | public void onClick(DialogInterface dialog, int which) {
38 | dialog.dismiss();
39 | }
40 | });
41 |
42 | createDialogAndShow(builder);
43 | }
44 |
45 |
46 | public void showDosageInformationDialog(Measurement measurement, Context context) {
47 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
48 |
49 | String dosageMessage;
50 | if (measurement == null) {
51 | dosageMessage = "Error! No information about the measurement has been found";
52 | } else {
53 | float insulinUnitsPerGrams = measurement.getInsulinInUnits() * 10 / measurement.getCarbohydratesInGrams();
54 | String insulinUnitsPerGramsString = Utils.decimalFormat.format(insulinUnitsPerGrams);
55 |
56 | dosageMessage = "You gave yourself "
57 | + measurement.getCarbohydratesInGrams() + " grams of carbohydrates and "
58 | + measurement.getInsulinInUnits() + " insulin units\n" +
59 | "(" + insulinUnitsPerGramsString + " insulin units for every 10 grams of carbohydrates).\n" +
60 | "Your blood sugar level before the meal was " + measurement.getSugarLevelBeforeMeal();
61 | }
62 |
63 |
64 | builder.setTitle(R.string.dosage_information_title).setMessage(dosageMessage);
65 | builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
66 | @Override
67 | public void onClick(DialogInterface dialog, int which) {
68 | dialog.dismiss();
69 | }
70 | });
71 | createDialogAndShow(builder);
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | # DiaBeFriend
13 |
14 | Simple android application that is dedicated to help you handle your diabetes
15 |
16 | DiaBeFriend is not currently available on Google Play Store, but you can download it from the link below:
17 | https://1drv.ms/u/s!AhhUCOE2-Bg2-W_YY03_FiCEAkjb
18 |
19 | ## Features provided by the app:
20 |
21 | * You can use offline database with nutritional data like: kilocalories, carbohydrates, fat and proteins.
22 | Just provide app with product name (you may choose product name from the list of about 7000 products) and its weight
23 |
24 |
25 |
26 |
27 |
28 |
29 | * I am diabetic myself and for me it is crucial to be reminded about the necessity of measurement after meal.
30 | Therefore you are welcomed to use the measurement feature. You can enter how many carbohydrates there is in your meal,
31 | how many insulin units you gave yourself and sugar level before the meal. You will be reminded about testing sugar level after 2 hours.
32 | Then your whole measurement will be summarized, which will help you keep your diary.
33 |
34 |
35 |
36 |
37 |
38 | Summary examples:
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | Timer:
49 |
50 |
51 |
52 |
53 |
54 | Progress bar can be seen after a little while:
55 |
56 |