diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a68e5b5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Gradle files +.gradle/ +build/ + +# Local configuration file (sdk path, etc) +local.properties + +# Log/OS Files +*.log + +# Android Studio generated files and folders +captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json + +# IntelliJ +*.iml +.idea/ + +# Keystore files +*.jks +*.keystore + +# Google Services (e.g. APIs or Firebase) +google-services.json + +# Android Profiling +*.hprof diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..6a465ca --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,37 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.falyrion.gymtonicapp" + minSdk 26 + targetSdk 32 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.6.0' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/falyrion/gymtonicapp/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/falyrion/gymtonicapp/ExampleInstrumentedTest.java new file mode 100644 index 0000000..940c888 --- /dev/null +++ b/app/src/androidTest/java/com/falyrion/gymtonicapp/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.falyrion.gymtonicapp; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.falyrion.gymtonicapp", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..85c601b --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..706af66 Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/com/falyrion/gymtonicapp/Activity_Main.java b/app/src/main/java/com/falyrion/gymtonicapp/Activity_Main.java new file mode 100644 index 0000000..46129b2 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/Activity_Main.java @@ -0,0 +1,144 @@ +package com.falyrion.gymtonicapp; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.MenuItem; + +import com.falyrion.gymtonicapp.data.DatabaseHelper; +import com.falyrion.gymtonicapp.fragments.Fragment_Nutrition; +import com.falyrion.gymtonicapp.fragments.Fragment_Workout; +import com.falyrion.gymtonicapp.fragments.Fragment_Settings; +import com.google.android.material.bottomnavigation.BottomNavigationView; +import com.google.android.material.navigation.NavigationBarView; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +public class Activity_Main extends AppCompatActivity { + + public String date; + private int currentFragmentID = 0; + public DatabaseHelper databaseHelper; + + + private void setFragmentFood(String date) { + Fragment_Nutrition fragment = new Fragment_Nutrition(); + Bundle args = new Bundle(); + args.putString("date", date); + fragment.setArguments(args); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit(); + } + + private void setFragmentBodyStats() { + // Pass + } + + private void setFragmentWorkout() { + Fragment_Workout fragment = new Fragment_Workout(); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit(); + } + + private void setFragmentSettings() { + Fragment_Settings fragment = new Fragment_Settings(); + getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).commit(); + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // Database + databaseHelper = new DatabaseHelper(Activity_Main.this); + + // ----------------------------------------------------------------------------------------- + // Get data if activity was started by another activity + Intent intent = getIntent(); + + // Get current date + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + + // If there is a fragmentID submitted take it. Else keep previously set or default one (=0) + if (getIntent().hasExtra("fragmentID")) { + currentFragmentID = intent.getIntExtra("fragmentID", 0); + } + + // Set current fragment based on fragmentID + switch (currentFragmentID) { + case 0: + setFragmentFood(date); + break; + + case 1: + setFragmentBodyStats(); + break; + + case 2: + setFragmentWorkout(); + break; + + case 3: + setFragmentSettings(); + break; + + default: + break; + } + + // ----------------------------------------------------------------------------------------- + // Setup navigation bar + BottomNavigationView navBar = findViewById(R.id.bottom_navigation); + navBar.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + switch (item.getItemId()) { + case R.id.nav_bar_home: + if (currentFragmentID != 0) { + setFragmentFood(date); + currentFragmentID = 0; + } + return true; + + case R.id.nav_bar_stats: + if (currentFragmentID != 1) { + setFragmentBodyStats(); + currentFragmentID = 1; + } + return true; + + case R.id.nav_bar_exersises: + if (currentFragmentID != 2) { + setFragmentWorkout(); + currentFragmentID = 2; + } + return true; + + case R.id.nav_bar_settings: + if (currentFragmentID != 3) { + setFragmentSettings(); + currentFragmentID = 3; + } + return true; + } + return false; + } + }); + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Calendar.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Calendar.java new file mode 100644 index 0000000..4dcd38e --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Calendar.java @@ -0,0 +1,97 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.CalendarView; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +public class Activity_Calendar extends AppCompatActivity { + + /** + * This activity is called by pressing the calendar-button in the Fragment_Nutrition. It will display + * a calendar to choose a date and return this new date to the main activity. + */ + + private String date; + private String newDate; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_calendar); + + // Get current date + Intent intent = getIntent(); + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + newDate = date; + + // Set up toolbar + Toolbar toolbarActivityAddStats = findViewById(R.id.toolbarActivityCalendar); + toolbarActivityAddStats.setTitle("Change date"); + setSupportActionBar(toolbarActivityAddStats); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // Buttons + Button buttonConfirm = findViewById(R.id.buttonConfirmSetDate); + buttonConfirm.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Main.class); + intent.putExtra("date", newDate); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + Button buttonCancel = findViewById(R.id.buttonCancelSetDate); + buttonCancel.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Main.class); + intent.putExtra("date", date); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + // Set up calendar item + CalendarView calendarView = findViewById(R.id.calendarView); + calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() { + @Override + public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int day) { + // Convert selected date to format "dd-mm-yyyy" + String dayString = String.valueOf(day); + if (day < 10) { + dayString = "0" + dayString; + } + + String monthString = String.valueOf(month + 1); // month + 1 because january is 0 + if ((month + 1) < 10) { + monthString = "0" + monthString; + } + + newDate = dayString + "-" + monthString + "-" + String.valueOf(year); + + buttonConfirm.setBackgroundResource(R.drawable.shape_box_round_pop); + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_EditBodyStats.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_EditBodyStats.java new file mode 100644 index 0000000..9052222 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_EditBodyStats.java @@ -0,0 +1,188 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.Intent; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; + +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + + +public class Activity_EditBodyStats extends AppCompatActivity { + + private String date; + private double[] data; + private boolean savePossible = false; + + private Button saveButton; + + + private class textWatcher implements TextWatcher { + private int id; + private textWatcher(int id) { + this.id = id; + } + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void afterTextChanged(Editable editable) { + // Update value + data[id] = Double.parseDouble(editable.toString()); + + // Update background resource of save button + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + savePossible = true; + } + } + + private String convertDataToText(double value) { + // Convert given double to string. + if (value % 1 == 0) { + // -> Value has only .0 decimals. Cut it out by converting to int. + return String.valueOf((int) value); + } else { + // -> Value has decimals. Round up to 2 decimal-digits. + DecimalFormat df = new DecimalFormat("#####.##"); + return String.valueOf(df.format(value)); + } + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_edit_body_stats); + + // Get current date + Intent intent = getIntent(); + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + + if (getIntent().hasExtra("dataBody")) { + data = intent.getDoubleArrayExtra("dataBody"); + } else { + data = new double[] {0, 0, 0, 0, 0, 0, 0, 0, 0}; + } + + // ----------------------------------------------------------------------------------------- + + // Set up edit-texts + EditText editTextWeight = findViewById(R.id.editTextWeight); + editTextWeight.addTextChangedListener(new textWatcher(0)); + + EditText editTextChest = findViewById(R.id.editTextChest); + editTextChest.addTextChangedListener(new textWatcher(1)); + + EditText editTextBelly = findViewById(R.id.editTextBelly); + editTextBelly.addTextChangedListener(new textWatcher(2)); + + EditText editTextButt = findViewById(R.id.editTextButt); + editTextButt.addTextChangedListener(new textWatcher(3)); + + EditText editTextWaist = findViewById(R.id.editTextWaist); + editTextWaist.addTextChangedListener(new textWatcher(4)); + + EditText editTextArmRight = findViewById(R.id.editTextArmRight); + editTextArmRight.addTextChangedListener(new textWatcher(5)); + + EditText editTextArmLeft = findViewById(R.id.editTextArmLeft); + editTextArmLeft.addTextChangedListener(new textWatcher(6)); + + EditText editTextLegRight = findViewById(R.id.editTextThighRight); + editTextLegRight.addTextChangedListener(new textWatcher(7)); + + EditText editTextLegLeft = findViewById(R.id.editTextThighLeft); + editTextLegLeft.addTextChangedListener(new textWatcher(8)); + + // Update UI + editTextWeight.setHint(convertDataToText(data[0])); + editTextChest.setHint(convertDataToText(data[1])); + editTextBelly.setHint(convertDataToText(data[2])); + editTextButt.setHint(convertDataToText(data[3])); + editTextWaist.setHint(convertDataToText(data[4])); + editTextArmRight.setHint(convertDataToText(data[5])); + editTextArmLeft.setHint(convertDataToText(data[6])); + editTextLegRight.setHint(convertDataToText(data[7])); + editTextLegLeft.setHint(convertDataToText(data[8])); + + // ----------------------------------------------------------------------------------------- + + // Set up toolbar + Toolbar toolbarActivityAddStats = (Toolbar) findViewById(R.id.toolbarActivityAddStats); + toolbarActivityAddStats.setTitle("Edit todays stats"); + setSupportActionBar(toolbarActivityAddStats); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // Set up date-text + TextView textViewDate = findViewById(R.id.textViewEditStatsDate); + textViewDate.setText(date); + + // Set up buttons + saveButton = findViewById(R.id.buttonSaveBodyStats); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (savePossible) { + savePossible = false; + + // Save data to database + DatabaseHelper databaseHelper = new DatabaseHelper(Activity_EditBodyStats.this); + databaseHelper.addDataBody(date, data[0] , data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8]); + databaseHelper.close(); + + saveButton.setBackgroundResource(R.drawable.shape_box_round_light); + } + + + } + }); + + Button cancelButton = findViewById(R.id.buttonCancelSaveBodyStats); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Main.class); + intent.putExtra("date", date); + // intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + } + +// @Override +// public void onBackPressed() { +// Intent intent = getIntent(); +// intent.putExtra("date", date); +// +// super.onBackPressed(); +// } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_AddDailyEntry.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_AddDailyEntry.java new file mode 100644 index 0000000..277dcfd --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_AddDailyEntry.java @@ -0,0 +1,338 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.DialogInterface; +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.text.InputType; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.Spinner; +import android.widget.TextView; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; +import com.falyrion.gymtonicapp.recyclerview.Adapter_MealPresets; +import com.falyrion.gymtonicapp.recyclerview.Item_MealPreset; +import com.google.android.material.snackbar.Snackbar; + +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; + + +public class Activity_Meals_AddDailyEntry extends AppCompatActivity implements Adapter_MealPresets.mealPresetItemInterface, AdapterView.OnItemSelectedListener { + + /** + * This activity displays all meal-presets and lets the user add them to the database + * for the current day. + */ + + private String date; + private boolean savePossible = false; + + private Button saveButton; + private Button cancelButton; + TextView noEntries; + RecyclerView recyclerViewMeals; + + private String[] mealCategories; + private int currentCategoryIndex = 0; + private static final String allCategories = "All"; + private ArrayList mealsPresetList; + private Adapter_MealPresets adapterPresets; + + private DatabaseHelper databaseHelper; + + private String convertDataToText(double value) { + // Convert given double to string. + if (value % 1 == 0) { + // -> Value has only .0 decimals. Cut it out by converting to int. + return String.valueOf((int) value); + } else { + // -> Value has decimals. Round up to 2 decimal-digits. + DecimalFormat df = new DecimalFormat("#####.##"); + return String.valueOf(df.format(value)); + } + } + + private String[] loadMealCategoriesFromDatabase() { + Cursor cursorCat = databaseHelper.getPresetMealCategories(); + String[] loadedCategories = new String[0]; + + if (cursorCat.getCount() > 0) { + loadedCategories = new String[cursorCat.getCount() + 1]; + loadedCategories[0] = allCategories; + + int i = 1; + while (cursorCat.moveToNext()) { + loadedCategories[i] = cursorCat.getString(0); + i++; + } + } + cursorCat.close(); + + return loadedCategories; + } + + private ArrayList loadPresetMealsFromDatabase(String category) { + Cursor cursor; + + if (category.equals(allCategories)) { + cursor = databaseHelper.getPresetMealsSimpleAllCategories(); + } else { + cursor = databaseHelper.getPresetMealsSimpleFromCategory(category); + } + + ArrayList loadedPresets = new ArrayList(); + + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + // Create new Item_MealPreset and add it to meals-list + loadedPresets.add(cursor.getPosition(), new Item_MealPreset( + cursor.getString(1), // Title + cursor.getString(0), // UUID + (int) cursor.getDouble(2), // Calories + 0 // Amount + )); + } + } + cursor.close(); + + return loadedPresets; + } + + + // Overwrite class default methods ------------------------------------------------------------- + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_meals_adddailyentry); + + // Set loading-layout ---------------------------------------------------------------------- + FrameLayout loadingLayout = findViewById(R.id.loadingLayout); + loadingLayout.setVisibility(View.VISIBLE); + + // Get data from intent -------------------------------------------------------------------- + Intent intent = getIntent(); + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + + // Set up toolbar -------------------------------------------------------------------------- + Toolbar toolbar = findViewById(R.id.toolbarActivityAddMeal); + toolbar.setTitle("Add meals"); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // Set up categories spinner --------------------------------------------------------------- + + databaseHelper = new DatabaseHelper(Activity_Meals_AddDailyEntry.this); + + // Load categories from database + mealCategories = loadMealCategoriesFromDatabase(); + + // Set up spinner + Spinner spinner = findViewById(R.id.spinnerMealPresetCategory); + spinner.setOnItemSelectedListener(this); + ArrayAdapter adapterCategories = new ArrayAdapter(getApplicationContext(), R.layout.spinner_item_purple_dark, mealCategories); + adapterCategories.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapterCategories); + + // Create meals for recycler view ---------------------------------------------------------- + + // Load preset meals from database + mealsPresetList = loadPresetMealsFromDatabase(mealCategories[currentCategoryIndex]); + + // Set adapters and recycler views + adapterPresets = new Adapter_MealPresets(mealsPresetList, this, getApplicationContext()); + recyclerViewMeals = findViewById(R.id.recyclerViewMealsPreset); + recyclerViewMeals.setAdapter(adapterPresets); + recyclerViewMeals.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false)); + + // Update loading-layout ------------------------------------------------------------------- + noEntries = findViewById(R.id.textViewNoEntries); + if (mealsPresetList.isEmpty()) { + noEntries.setVisibility(View.VISIBLE); + } + + loadingLayout.setVisibility(View.INVISIBLE); + + TextView textViewDate = findViewById(R.id.textViewDate); + textViewDate.setText(date); + + // Set up buttons -------------------------------------------------------------------------- + Button buttonAddMeal = findViewById(R.id.buttonAddMeal); + buttonAddMeal.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Start new activity Activity_CreateMeal + Intent intent = new Intent(view.getContext(), Activity_Meals_CreateEditPreset.class); + if (date != null) { + intent.putExtra("date", date); + } + startActivity(intent); + } + }); + + saveButton = findViewById(R.id.buttonAddMealSave); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (savePossible) { + savePossible = false; + + for (Item_MealPreset currentMeal : mealsPresetList) { + if (currentMeal.getAmount() > 0) { + databaseHelper.addOrReplaceConsumedMeal(date, currentMeal.getMealUUID(), currentMeal.getAmount()); + } + } + + saveButton.setBackgroundResource(R.drawable.shape_box_round_light); + cancelButton.setText("Back"); + Snackbar.make(view, "Saved", Snackbar.LENGTH_SHORT).show(); + } + } + }); + + cancelButton = findViewById(R.id.buttonAddMealCancel); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Start new activity Activity_Main (= go back to main screen) + Intent intent = new Intent(view.getContext(), Activity_Main.class); + if (date != null) { + intent.putExtra("date", date); + } + // intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + + + // Methods from imported interface ------------------------------------------------------------- + + @Override + public void updateItemAmount(int itemPosition, String mealUUID, double newAmount) { + if (!savePossible) { + savePossible = true; + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + } + adapterPresets.notifyItemChanged(itemPosition); // Update view + } + + @Override + public void onItemClick(String mealUUID) { + // Start new activity Activity_CreateMeal + Intent intent = new Intent(getApplicationContext(), Activity_Meals_CreateEditPreset.class); + if (date != null) { + intent.putExtra("date", date); + } + intent.putExtra("mode", "edit"); + intent.putExtra("uuid", mealUUID); + startActivity(intent); + } + + @Override + public void onAmountClick(int itemPosition) { + // Show dialog to edit amount + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_edittext, null); + builder.setView(view); + + EditText editTextPlanName = view.findViewById(R.id.dialogEditText); + if (mealsPresetList.get(itemPosition).getAmount() != 0) { + editTextPlanName.setText(convertDataToText(mealsPresetList.get(itemPosition).getAmount())); + } + editTextPlanName.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); + + builder.setTitle("Change amount"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String textInput = editTextPlanName.getText().toString(); + + if (textInput.length() <= 0) { + return; + } + + mealsPresetList.get(itemPosition).setAmount(Double.parseDouble(textInput)); + adapterPresets.notifyItemChanged(itemPosition); + + if (!savePossible) { + savePossible = true; + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + } + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + + + // Methods from imported spinner interface ----------------------------------------------------- + + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long l) { + if (position == currentCategoryIndex) { + return; + } + + currentCategoryIndex = position; + + // Clear data + mealsPresetList.clear(); + adapterPresets.notifyDataSetChanged(); + + // Load new data + mealsPresetList = loadPresetMealsFromDatabase(mealCategories[position]); + + if (mealsPresetList.isEmpty()) { + noEntries.setVisibility(View.VISIBLE); + return; + } + noEntries.setVisibility(View.INVISIBLE); + + // Update recycler view + adapterPresets = new Adapter_MealPresets(mealsPresetList, this, getApplicationContext()); + recyclerViewMeals = findViewById(R.id.recyclerViewMealsPreset); + recyclerViewMeals.setAdapter(adapterPresets); + recyclerViewMeals.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false)); + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + // Pass + } +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_CreateEditPreset.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_CreateEditPreset.java new file mode 100644 index 0000000..943548c --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_CreateEditPreset.java @@ -0,0 +1,383 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; + +import java.text.DecimalFormat; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + + +public class Activity_Meals_CreateEditPreset extends AppCompatActivity implements AdapterView.OnItemSelectedListener { + + /** + * This activity lets the user create new meal-presets or edit already existing ones. + */ + + private String mealName; + private String mealUUID; + private String[] mealCategories; + private String selectedMealCategory; + private double[] mealData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + private boolean savePossible = false; + private String date; + private String mode = "create"; + + private Button saveButton; + private Button cancelButton; + private EditText editTextMealName; + + private DatabaseHelper databaseHelper; + + + private class textWatcher implements TextWatcher { + private int id; + private textWatcher(int id) { + this.id = id; + } + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void afterTextChanged(Editable editable) { + // Update value + if (id == 0) { + if (editable.toString().length() > 28) { + editTextMealName.setText(mealName); + Toast.makeText(getApplicationContext(), "Text limit reached!", Toast.LENGTH_SHORT).show(); + return; + } + mealName = editable.toString(); + } else { + mealData[id - 1] = Double.parseDouble(editable.toString()); + } + + // Update background resource of save button + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + savePossible = true; + cancelButton.setText("Cancel"); + } + } + + private String[] loadMealCategoriesFromDatabase() { + Cursor cursorCat = databaseHelper.getPresetMealCategories(); + String[] loadedCategories = new String[0]; + + if (cursorCat.getCount() > 0) { + loadedCategories = new String[cursorCat.getCount()]; + int i = 0; + while (cursorCat.moveToNext()) { + loadedCategories[i] = cursorCat.getString(0); + i++; + } + } + cursorCat.close(); + + return loadedCategories; + } + + private String convertDataToText(double value) { + // Convert given double to string. + if (value % 1 == 0) { + // -> Value has only .0 decimals. Cut it out by converting to int. + return String.valueOf((int) value); + } else { + // -> Value has decimals. Round up to 2 decimal-digits. + DecimalFormat df = new DecimalFormat("#####.##"); + return String.valueOf(df.format(value)); + } + } + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_meals_createeditpreset); + + // Connect to database + databaseHelper = new DatabaseHelper(Activity_Meals_CreateEditPreset.this); + + // Set up spinner for categories ----------------------------------------------------------- + mealCategories = loadMealCategoriesFromDatabase(); + selectedMealCategory = mealCategories[0]; + + Spinner spinner = findViewById(R.id.spinnerMealCategory); + spinner.setOnItemSelectedListener(this); + ArrayAdapter adapterCategories = new ArrayAdapter(getApplicationContext(), R.layout.spinner_item_purple_middle, mealCategories); + adapterCategories.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapterCategories); + + // ----------------------------------------------------------------------------------------- + Intent intent = getIntent(); + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } + + if (getIntent().hasExtra("mode")) { + if (intent.getStringExtra("mode").equals("edit")) { + mode = "edit"; + + String uuid = intent.getStringExtra("uuid"); + Cursor cursorData = databaseHelper.getPresetMealDetails(uuid); + if (cursorData.getCount() > 0) { + cursorData.moveToFirst(); + mealUUID = cursorData.getString(0); + mealName = cursorData.getString(1); + selectedMealCategory = cursorData.getString(2); + mealData = new double[]{ + cursorData.getDouble(3), cursorData.getDouble(4), + cursorData.getDouble(5), cursorData.getDouble(6), cursorData.getDouble(7), cursorData.getDouble(8), + cursorData.getDouble(9), cursorData.getDouble(10), cursorData.getDouble(11), cursorData.getDouble(12), + cursorData.getDouble(13), cursorData.getDouble(14), cursorData.getDouble(15), cursorData.getDouble(16), + cursorData.getDouble(17), cursorData.getDouble(18), cursorData.getDouble(19), cursorData.getDouble(20), + cursorData.getDouble(21), cursorData.getDouble(22), cursorData.getDouble(23), cursorData.getDouble(24), + cursorData.getDouble(25), cursorData.getDouble(26), cursorData.getDouble(27), cursorData.getDouble(28), + cursorData.getDouble(29), cursorData.getDouble(30), cursorData.getDouble(31), cursorData.getDouble(32), + cursorData.getDouble(33) + }; + } + cursorData.close(); + + // Set spinner item + List mealsList = Arrays.asList(mealCategories); + spinner.setSelection(mealsList.indexOf(selectedMealCategory)); + } + } + + // ----------------------------------------------------------------------------------------- + // Set up edit-texts + editTextMealName = findViewById(R.id.editTextMealName); + if (mealName != null) { + editTextMealName.setText(mealName); + } + editTextMealName.addTextChangedListener(new textWatcher(0)); + + // TODO: Add new edit texts for new items + EditText editTextCalories = findViewById(R.id.editTextCalories); + editTextCalories.setHint(convertDataToText(mealData[0])); + editTextCalories.addTextChangedListener(new textWatcher(1)); + + EditText editTextFat = findViewById(R.id.editTextFat); + editTextFat.setHint(convertDataToText(mealData[1])); + editTextFat.addTextChangedListener(new textWatcher(2)); + + EditText editTexFatSat = findViewById(R.id.editTextFatSat); + editTexFatSat.setHint(convertDataToText(mealData[2])); + editTexFatSat.addTextChangedListener(new textWatcher(3)); + + EditText editTextCarbs = findViewById(R.id.editTextCarbs); + editTextCarbs.setHint(convertDataToText(mealData[3])); + editTextCarbs.addTextChangedListener(new textWatcher(4)); + + EditText editTextSugar = findViewById(R.id.editTextSugar); + editTextSugar.setHint(convertDataToText(mealData[4])); + editTextSugar.addTextChangedListener(new textWatcher(5)); + + EditText editTextProtein = findViewById(R.id.editTextProtein); + editTextProtein.setHint(convertDataToText(mealData[5])); + editTextProtein.addTextChangedListener(new textWatcher(6)); + + EditText editTextSalt = findViewById(R.id.editTextSalt); + editTextSalt.setHint(convertDataToText(mealData[6])); + editTextSalt.addTextChangedListener(new textWatcher(7)); + + EditText editTextFiber = findViewById(R.id.editTextFiber); + editTextFiber.setHint(convertDataToText(mealData[7])); + editTextFiber.addTextChangedListener(new textWatcher(8)); + + EditText editTextChol = findViewById(R.id.editTextCholesterin); + editTextChol.setHint(convertDataToText(mealData[8])); + editTextChol.addTextChangedListener(new textWatcher(9)); + + EditText editTextCreatine = findViewById(R.id.editTextCreatine); + editTextCreatine.setHint(convertDataToText(mealData[9])); + editTextCreatine.addTextChangedListener(new textWatcher(10)); + + EditText editTextCa = findViewById(R.id.editTextCa); + editTextCa.setHint(convertDataToText(mealData[10])); + editTextCa.addTextChangedListener(new textWatcher(11)); + + EditText editTextFe = findViewById(R.id.editTextFe); + editTextFe.setHint(convertDataToText(mealData[11])); + editTextFe.addTextChangedListener(new textWatcher(12)); + + EditText editTextK = findViewById(R.id.editTextKa); + editTextK.setHint(convertDataToText(mealData[12])); + editTextK.addTextChangedListener(new textWatcher(13)); + + EditText editTextMg = findViewById(R.id.editTextMg); + editTextMg.setHint(convertDataToText(mealData[13])); + editTextMg.addTextChangedListener(new textWatcher(14)); + + EditText editTextMn = findViewById(R.id.editTextMn); + editTextMn.setHint(convertDataToText(mealData[14])); + editTextMn.addTextChangedListener(new textWatcher(15)); + + EditText editTextNa = findViewById(R.id.editTextNa); + editTextNa.setHint(convertDataToText(mealData[15])); + editTextNa.addTextChangedListener(new textWatcher(16)); + + EditText editTextP = findViewById(R.id.editTextP); + editTextP.setHint(convertDataToText(mealData[16])); + editTextP.addTextChangedListener(new textWatcher(17)); + + EditText editTextZn = findViewById(R.id.editTextZn); + editTextZn.setHint(convertDataToText(mealData[17])); + editTextZn.addTextChangedListener(new textWatcher(18)); + + EditText editTextVitA = findViewById(R.id.editTextVitA); + editTextVitA.setHint(convertDataToText(mealData[18])); + editTextVitA.addTextChangedListener(new textWatcher(19)); + + EditText editTextVitB1 = findViewById(R.id.editTextVitB1); + editTextVitB1.setHint(convertDataToText(mealData[19])); + editTextVitB1.addTextChangedListener(new textWatcher(20)); + + EditText editTextVitB2 = findViewById(R.id.editTextVitB2); + editTextVitB2.setHint(convertDataToText(mealData[20])); + editTextVitB2.addTextChangedListener(new textWatcher(21)); + + EditText editTextVitB3 = findViewById(R.id.editTextVitB3); + editTextVitB3.setHint(convertDataToText(mealData[21])); + editTextVitB3.addTextChangedListener(new textWatcher(22)); + + EditText editTextVitB5 = findViewById(R.id.editTextVitB5); + editTextVitB5.setHint(convertDataToText(mealData[22])); + editTextVitB5.addTextChangedListener(new textWatcher(23)); + + EditText editTextVitB6 = findViewById(R.id.editTextVitB6); + editTextVitB6.setHint(convertDataToText(mealData[23])); + editTextVitB6.addTextChangedListener(new textWatcher(24)); + + EditText editTextVitB7 = findViewById(R.id.editTextVitB7); + editTextVitB7.setHint(convertDataToText(mealData[24])); + editTextVitB7.addTextChangedListener(new textWatcher(25)); + + EditText editTextVitB11 = findViewById(R.id.editTextVitB11); + editTextVitB11.setHint(convertDataToText(mealData[25])); + editTextVitB11.addTextChangedListener(new textWatcher(26)); + + EditText editTextVitB12 = findViewById(R.id.editTextVitB12); + editTextVitB12.setHint(convertDataToText(mealData[26])); + editTextVitB12.addTextChangedListener(new textWatcher(27)); + + EditText editTextVitC = findViewById(R.id.editTextVitC); + editTextVitC.setHint(convertDataToText(mealData[27])); + editTextVitC.addTextChangedListener(new textWatcher(28)); + + EditText editTextVitE = findViewById(R.id.editTextVitE); + editTextVitE.setHint(convertDataToText(mealData[28])); + editTextVitE.addTextChangedListener(new textWatcher(29)); + + EditText editTextVitK = findViewById(R.id.editTextVitK); + editTextVitK.setHint(convertDataToText(mealData[29])); + editTextVitK.addTextChangedListener(new textWatcher(30)); + + EditText editTextVitH = findViewById(R.id.editTextVitH); + editTextVitH.setHint(convertDataToText(mealData[30])); + editTextVitH.addTextChangedListener(new textWatcher(31)); + + // ----------------------------------------------------------------------------------------- + // Set up toolbar + Toolbar toolbarActivityCreateMeal = (Toolbar) findViewById(R.id.toolbarActivityCreateMeal); + if (mode.equals("create")) { + toolbarActivityCreateMeal.setTitle("Create new meal preset"); + } else if (mode.equals("edit")) { + toolbarActivityCreateMeal.setTitle("Edit meal preset"); + } + + setSupportActionBar(toolbarActivityCreateMeal); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // ----------------------------------------------------------------------------------------- + // Set up buttons + saveButton = findViewById(R.id.buttonSaveNewMeal); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (savePossible) { + if (mealName == null) { + // If meal name was not set up yet remind user to add one + Toast.makeText(getApplicationContext(), "Please enter a name first!", Toast.LENGTH_SHORT).show(); + return; + } + + savePossible = false; + + // If UUID does not exist, create one + if (mealUUID == null) { + // Get only first 8 digits from UUID (no need for long "123e4567-e89b-42d3-a456-556642440000") + mealUUID = UUID.randomUUID().toString().substring(0, 8); + } + + + // Save data to database + databaseHelper.addOrReplacePresetMeal(mealUUID, mealName, selectedMealCategory, mealData); + databaseHelper.close(); + + // Change button color + saveButton.setBackgroundResource(R.drawable.shape_box_round_light); + cancelButton.setText("Back"); + } + } + }); + + cancelButton = findViewById(R.id.buttonCancelNewMeal); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Meals_AddDailyEntry.class); + if (date != null) { + intent.putExtra("date", date); + } + // intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + + // Methods from imported spinner interface ----------------------------------------------------- + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long l) { + selectedMealCategory = mealCategories[position]; + savePossible = true; + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + // Pass + } +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_MealsOfDay.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_MealsOfDay.java new file mode 100644 index 0000000..fbfcd5e --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Meals_MealsOfDay.java @@ -0,0 +1,254 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.DialogInterface; +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.text.InputType; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.TextView; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; +import com.falyrion.gymtonicapp.recyclerview.Adapter_MealPresets; +import com.falyrion.gymtonicapp.recyclerview.Item_MealPreset; +import com.google.android.material.snackbar.Snackbar; + +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Locale; + + +public class Activity_Meals_MealsOfDay extends AppCompatActivity implements Adapter_MealPresets.mealPresetItemInterface { + + /** + * This activity displays all meals that have been eaten at the selected date. + * This activity lets the user delete meals from the current date. + */ + + private String date; + private boolean savePossible = false; + + private Button saveButton; + private Button cancelButton; + + private ArrayList mealsList; + private Adapter_MealPresets adapter; + private HashMap mealsStart = new HashMap<>(); + + private DatabaseHelper databaseHelper; + + private String convertDataToText(double value) { + // Convert given double to string. + if (value % 1 == 0) { + // -> Value has only .0 decimals. Cut it out by converting to int. + return String.valueOf((int) value); + } else { + // -> Value has decimals. Round up to 2 decimal-digits. + DecimalFormat df = new DecimalFormat("#####.##"); + return String.valueOf(df.format(value)); + } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_meals_mealsofday); + + FrameLayout loadingLayout = findViewById(R.id.loadingLayout); + loadingLayout.setVisibility(View.VISIBLE); + + // Get data from intent -------------------------------------------------------------------- + Intent intent = getIntent(); + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + + // Set up toolbar -------------------------------------------------------------------------- + Toolbar toolbar = findViewById(R.id.toolbarActivityMealsOfDay); + toolbar.setTitle("Edit meals"); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // Load data from database ----------------------------------------------------------------- + mealsList = new ArrayList(); + + databaseHelper = new DatabaseHelper(Activity_Meals_MealsOfDay.this); + Cursor cursor = databaseHelper.getConsumedMeals(date); + + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + mealsList.add(cursor.getPosition(), new Item_MealPreset( + cursor.getString(1), // Title + cursor.getString(0), // UUID + (int) cursor.getDouble(2), // Calories + cursor.getDouble(3) // Amount + )); + + mealsStart.put(cursor.getString(0), cursor.getDouble(3)); + } + } + cursor.close(); + + adapter = new Adapter_MealPresets(mealsList, this, getApplicationContext()); + + RecyclerView recyclerViewMeals = findViewById(R.id.recyclerViewMealsEaten); + recyclerViewMeals.setAdapter(adapter); + recyclerViewMeals.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false)); + + // Remove loading screen ------------------------------------------------------------------- + if (mealsList.isEmpty()) { + TextView noEntries = findViewById(R.id.textViewNoEntries); + noEntries.setVisibility(View.VISIBLE); + } + + loadingLayout.setVisibility(View.INVISIBLE); + + TextView textViewDate = findViewById(R.id.textViewDate); + textViewDate.setText(date); + + // Set up buttons -------------------------------------------------------------------------- + + saveButton = findViewById(R.id.buttonAddMealSave); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (savePossible) { + savePossible = false; + + for (Item_MealPreset currentMeal : mealsList) { + String currentUUID = currentMeal.getMealUUID(); + double currentAmount = currentMeal.getAmount(); + double startAmount = mealsStart.get(currentUUID); + + if ((currentAmount > 0) && (currentAmount != startAmount)) { + // Delete entry + databaseHelper.removeConsumedMeal(date, currentUUID); + // Add entry with new amount + databaseHelper.addOrReplaceConsumedMeal(date, currentUUID, currentAmount); + } else if (currentAmount <= 0) { + // Delete entry + databaseHelper.removeConsumedMeal(date, currentUUID); + } + + mealsStart.replace(currentUUID, currentAmount); + } + + saveButton.setBackgroundResource(R.drawable.shape_box_round_light); + cancelButton.setText("Back"); + Snackbar.make(view, "Saved", Snackbar.LENGTH_SHORT).show(); + } + } + }); + + cancelButton = findViewById(R.id.buttonAddMealCancel); + cancelButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Start new activity Activity_Main (= go back to main screen) + Intent intent = new Intent(view.getContext(), Activity_Main.class); + if (date != null) { + intent.putExtra("date", date); + } + // intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + Button buttonAddMeal = findViewById(R.id.buttonAddMeal); + buttonAddMeal.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(getApplicationContext(), Activity_Meals_AddDailyEntry.class); + if (date != null) { + intent.putExtra("date", date); + } + startActivity(intent); + } + }); + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + + + // Methods from imported interface ------------------------------------------------------------- + + @Override + public void updateItemAmount(int itemPosition, String mealUUID, double newAmount) { + + if (!savePossible) { + savePossible = true; + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + } + + adapter.notifyItemChanged(itemPosition); // Update view + } + + @Override + public void onItemClick(String mealUUID) { + // Pass + } + + @Override + public void onAmountClick(int itemPosition) { + // Show dialog to edit amount + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_edittext, null); + builder.setView(view); + + EditText editTextPlanName = view.findViewById(R.id.dialogEditText); + if (mealsList.get(itemPosition).getAmount() != 0) { + editTextPlanName.setText(convertDataToText(mealsList.get(itemPosition).getAmount())); + } + editTextPlanName.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); + + builder.setTitle("Change amount"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String textInput = editTextPlanName.getText().toString(); + + if (textInput.length() <= 0) { + return; + } + + mealsList.get(itemPosition).setAmount(Double.parseDouble(textInput)); + adapter.notifyItemChanged(itemPosition); + + if (!savePossible) { + savePossible = true; + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + } + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_CreateEditExercise.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_CreateEditExercise.java new file mode 100644 index 0000000..93b198e --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_CreateEditExercise.java @@ -0,0 +1,433 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; +import com.falyrion.gymtonicapp.recyclerview.Adapter_Workout_Plans; +import com.falyrion.gymtonicapp.recyclerview.Adapter_Workout_Routine; +import com.falyrion.gymtonicapp.recyclerview.Item_Workout_Plan; +import com.falyrion.gymtonicapp.recyclerview.Item_Workout_Routine; +import com.google.android.material.snackbar.Snackbar; + +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.Locale; + + +public class Activity_Workout_CreateEditExercise extends AppCompatActivity implements Adapter_Workout_Routine.Interface_Workout_Routine, Adapter_Workout_Plans.Interface_Workout_Plans { + + /** + * This activity lets the user create or edit exercises. Changes will be saved to the database. + */ + + private String mode = "create"; + private String date; + + private String oldPlanName; + private String oldRoutineName; + private String oldExerciseName; + private String exerciseName; + private int exerciseSets = 0; + private int exerciseRepetitions = 0; + private double exerciseWeight = 0; + private boolean savePossible = false; + + private Button saveButton; + private Button cancelButton; + private Toolbar toolbarActivityCreateExercise; + private RecyclerView recyclerViewRoutines; + + private ArrayList routinesList; + private ArrayList plansList; + private Adapter_Workout_Routine adapterRoutines; + private Adapter_Workout_Plans adapterPlans; + private int currentSelectedRoutineIdx; + private int currentSelectedPlanIdx; + + private DatabaseHelper databaseHelper; + + private class textWatcher implements TextWatcher { + private int id; + private textWatcher(int id) { + this.id = id; + } + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void afterTextChanged(Editable editable) { + // Update value + switch (id) { + case 0: + if (editable.toString().equals("")) { + exerciseName = "No name"; + } else { + exerciseName = editable.toString(); + } + break; + + case 1: + if (editable.toString().equals("")) { + exerciseSets = 0; + } else { + exerciseSets = Integer.parseInt(editable.toString()); + } + break; + + case 2: + if (editable.toString().equals("")) { + exerciseRepetitions = 0; + } else { + exerciseRepetitions = Integer.parseInt(editable.toString()); + } + break; + + case 3: + if (editable.toString().equals("")) { + exerciseWeight = 0; + } else { + exerciseWeight= Double.parseDouble(editable.toString()); + } + break; + } + + // Update background resource of save + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + savePossible = true; + } + } + + private void getPlansFromDatabase() { + // Initiate list + plansList = new ArrayList(); + + // Get routines by plan + Cursor cursor = databaseHelper.getWorkoutPlans(); + + // Populate routines-list + if (cursor.getCount() > 0) { + // Add first item to list as "selected" + cursor.moveToFirst(); + plansList.add( + cursor.getPosition(), + new Item_Workout_Plan(cursor.getString(0), true) + ); + + // Add remaining items to list as "not selected" + while (cursor.moveToNext()) { + plansList.add( + cursor.getPosition(), + new Item_Workout_Plan(cursor.getString(0), false) + ); + } + + // Set up adapter + adapterPlans = new Adapter_Workout_Plans(plansList, this); + currentSelectedPlanIdx = 0; + } + cursor.close(); + } + + private void getRoutinesFromDatabase(String workoutPlanName) { + // Initiate list + routinesList = new ArrayList(); + + // Get routines by plan + Cursor cursor = databaseHelper.getWorkoutRoutines(workoutPlanName); + + // Populate routines-list + if (cursor.getCount() > 0) { + // Add first item to list as "selected" + cursor.moveToFirst(); + routinesList.add( + cursor.getPosition(), + new Item_Workout_Routine(cursor.getString(0), true) + ); + + // Add remaining items to list as "not selected" + while (cursor.moveToNext()) { + routinesList.add( + cursor.getPosition(), + new Item_Workout_Routine(cursor.getString(0), false) + ); + } + + // Set up adapter + adapterRoutines = new Adapter_Workout_Routine(routinesList, this); + currentSelectedRoutineIdx = 0; + } + cursor.close(); + } + + public void updateSelectedPlan(int newSelectedIndex) { + // Update new selected item + plansList.get(newSelectedIndex).setIsSelected(true); + adapterPlans.notifyItemChanged(newSelectedIndex); + + // Update previous selected item + plansList.get(currentSelectedPlanIdx).setIsSelected(false); + adapterPlans.notifyItemChanged(currentSelectedPlanIdx); + + // Update variable + currentSelectedPlanIdx = newSelectedIndex; + } + + public void updateSelectedRoutine(int newSelectedIndex) { + // Update new selected item + routinesList.get(newSelectedIndex).setIsSelected(true); + adapterRoutines.notifyItemChanged(newSelectedIndex); + + // Update previous selected item + routinesList.get(currentSelectedRoutineIdx).setIsSelected(false); + adapterRoutines.notifyItemChanged(currentSelectedRoutineIdx); + + // Update variable + currentSelectedRoutineIdx = newSelectedIndex; + } + + private String convertDataToText(double value) { + // Convert given double to string. + if (value % 1 == 0) { + // -> Value has only .0 decimals. Cut it out by converting to int. + return String.valueOf((int) value); + } else { + // -> Value has decimals. Round up to 2 decimal-digits. + DecimalFormat df = new DecimalFormat("#####.##"); + return String.valueOf(df.format(value)); + } + } + + + // Class overwrite methods --------------------------------------------------------------------- + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_workout_createeditexercise); + + // ----------------------------------------------------------------------------------------- + Intent intent = getIntent(); + + if (getIntent().hasExtra("date")) { + date = intent.getStringExtra("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + + // Database -------------------------------------------------------------------------------- + databaseHelper = new DatabaseHelper(Activity_Workout_CreateEditExercise.this); + + // Get plans from database + getPlansFromDatabase(); + + // Get routines from database + getRoutinesFromDatabase(plansList.get(0).getTitle()); + + // Set up recycler-view + recyclerViewRoutines = findViewById(R.id.recyclerViewRoutines); + recyclerViewRoutines.setAdapter(adapterRoutines); + recyclerViewRoutines.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); + + RecyclerView recyclerViewPlans = findViewById(R.id.recyclerViewPlans); + recyclerViewPlans.setAdapter(adapterPlans); + recyclerViewPlans.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); + + // Check mode the activity was started in -------------------------------------------------- + + // -> Overwrite default mode if available + if (getIntent().hasExtra("mode")) { + if (getIntent().getStringExtra("mode").equals("edit")) { + mode = "edit"; + + // Overwrite variables + oldPlanName = getIntent().getStringExtra("planName"); + oldRoutineName = getIntent().getStringExtra("routineName"); + exerciseName = getIntent().getStringExtra("exerciseName"); + oldExerciseName = exerciseName; + exerciseSets = getIntent().getIntExtra("exerciseSets", 0); + exerciseRepetitions = getIntent().getIntExtra("exerciseReps", 0); + exerciseWeight = getIntent().getDoubleExtra("exerciseWeight", 0); + + // Get index of plan of current exercise + int newSelectedPlanIndex = -1; + for (Item_Workout_Plan plan : plansList) { + newSelectedPlanIndex++; + if (plan.getTitle().equals(oldPlanName)) { + break; + } + } + + // Get index of routine of current exercise + int newSelectedRoutineIndex = -1; + for (Item_Workout_Routine routine : routinesList) { + newSelectedRoutineIndex++; + if (routine.getTitle().equals(oldRoutineName)) { + break; + } + } + + // Update recycler-views + if (currentSelectedRoutineIdx != newSelectedRoutineIndex) { + updateSelectedRoutine(newSelectedRoutineIndex); + } + if (currentSelectedPlanIdx != newSelectedPlanIndex) { + updateSelectedPlan(newSelectedPlanIndex); + } + + } + } + + // ----------------------------------------------------------------------------------------- + // Set up edit-texts + + EditText editTextExerciseName = findViewById(R.id.editTextExerciseName); + EditText editTextExerciseSets = findViewById(R.id.editTextCreateExerciseSets); + EditText editTextExerciseRepetitions = findViewById(R.id.editTextCreateExerciseRepetitions); + EditText editTextExerciseWeight = findViewById(R.id.editTextCreateExerciseWeight); + + if (mode.equals("edit")) { + editTextExerciseName.setText(exerciseName); + editTextExerciseSets.setText(String.valueOf(exerciseSets)); + editTextExerciseRepetitions.setText(String.valueOf(exerciseRepetitions)); + editTextExerciseWeight.setText(convertDataToText(exerciseWeight)); + } + + editTextExerciseName.addTextChangedListener(new textWatcher(0)); + editTextExerciseSets.addTextChangedListener(new textWatcher(1)); + editTextExerciseRepetitions.addTextChangedListener(new textWatcher(2)); + editTextExerciseWeight.addTextChangedListener(new textWatcher(3)); + + // ----------------------------------------------------------------------------------------- + // Set up toolbar + + toolbarActivityCreateExercise = findViewById(R.id.toolbarActivityCreateExercise); + if (mode.equals("edit")) { + toolbarActivityCreateExercise.setTitle("Edit exercise"); + } else { + toolbarActivityCreateExercise.setTitle("Add new exercise"); + } + setSupportActionBar(toolbarActivityCreateExercise); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // ----------------------------------------------------------------------------------------- + // Set up buttons + + saveButton = findViewById(R.id.buttonSaveNewExercise); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (savePossible) { + if (exerciseName == null) { + // If name was not set up yet remind user to add one + Toast.makeText(getApplicationContext(), "Please enter a name first!", Toast.LENGTH_SHORT).show(); + Snackbar.make(view, "Please enter a name first!", Snackbar.LENGTH_SHORT).show(); + return; + } + + savePossible = false; + + if (mode.equals("edit")) { + // Delete old exercise + databaseHelper.deleteWorkoutExercise(oldPlanName, oldRoutineName, oldExerciseName); + } + + // Save data to database + databaseHelper.addWorkoutExercise( + plansList.get(currentSelectedPlanIdx).getTitle(), // Get plan name + routinesList.get(currentSelectedRoutineIdx).getTitle(), // Get routine name + exerciseName, + exerciseSets, + exerciseRepetitions, + exerciseWeight + ); + databaseHelper.close(); + + + // Change to edit-mode + mode = "edit"; + oldPlanName = plansList.get(currentSelectedPlanIdx).getTitle(); + oldRoutineName = routinesList.get(currentSelectedRoutineIdx).getTitle(); + oldExerciseName = exerciseName; + + // Change button color + saveButton.setBackgroundResource(R.drawable.shape_box_round_light); + cancelButton.setText("Back"); + toolbarActivityCreateExercise.setTitle("Edit exercise"); + + Snackbar.make(view, "Exercise saved!", Snackbar.LENGTH_SHORT).show(); + } + } + }); + + cancelButton = findViewById(R.id.buttonCancelNewExercise); + cancelButton.setOnClickListener(new View.OnClickListener() { + // -> This method starts Activity_Main + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Main.class); + if (date != null) { intent.putExtra("date", date); } + intent.putExtra("fragmentID", 1); + startActivity(intent); + } + }); + + + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + + + // Interface methods --------------------------------------------------------------------------- + + @Override + public void onPlanItemClick(int itemPosition) { + // -> This method updates the selected plan visually + if (itemPosition != currentSelectedPlanIdx) { + updateSelectedPlan(itemPosition); + + // Update routines list + getRoutinesFromDatabase(plansList.get(itemPosition).getTitle()); + recyclerViewRoutines.setAdapter(adapterRoutines); + recyclerViewRoutines.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false)); + } + } + + @Override + public void onRoutineItemClick(int itemPosition) { + // -> This method updates the selected routine visually + if (itemPosition != currentSelectedRoutineIdx) { + updateSelectedRoutine(itemPosition); + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_EditPlans.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_EditPlans.java new file mode 100644 index 0000000..9f1e3ba --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_EditPlans.java @@ -0,0 +1,200 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.DialogInterface; +import android.database.Cursor; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; +import com.falyrion.gymtonicapp.recyclerview.Adapter_Item_General_001; +import com.falyrion.gymtonicapp.recyclerview.Item_General_001; + +import java.util.ArrayList; + +public class Activity_Workout_EditPlans extends AppCompatActivity implements Adapter_Item_General_001.Interface_Item_Edit { + + /** + * This activity lets the user edit workout plans. Changes will be saved to the database. + * + * - This activity is for changing values of an existing plan only. Creating new plans happens + * in the Fragment_Workout. + */ + + private boolean savePossible = false; + private int currentEditedPlanIndex; + + private ArrayList plansList; + private Adapter_Item_General_001 adapterWorkoutPlans; + private DatabaseHelper databaseHelper; + + + private ArrayList loadPlansFromDatabase() { + Cursor cursor = databaseHelper.getWorkoutPlans(); + ArrayList loadedPlans = new ArrayList(); + + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + loadedPlans.add(cursor.getPosition(), new Item_General_001(cursor.getString(0))); + } + } + + return loadedPlans; + } + + private void showDialogEditPlanName(String currentPlanName, int itemPosition) { + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_edittext, null); + builder.setView(view); + + EditText editTextPlanName = view.findViewById(R.id.dialogEditText); + editTextPlanName.setText(currentPlanName); + + builder.setTitle("Edit plan name"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String newPlanName = editTextPlanName.getText().toString(); + + if (newPlanName.length() <= 0) { + return; + } + + // Update data in database + databaseHelper.updateWorkoutPlanName(currentPlanName, newPlanName); + + // Update recycler view + plansList.get(itemPosition).setTitle(newPlanName); + adapterWorkoutPlans.notifyItemChanged(itemPosition); + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + // alertDialog.getWindow().setLayout(600, 400); + } + + private void showDialogCreatePlan() { + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_edittext, null); + builder.setView(view); + + EditText editTextPlanName = view.findViewById(R.id.dialogEditText); + editTextPlanName.setHint("Enter plan name"); + + builder.setTitle("Create New Workout Plan"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Create plan", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String text = editTextPlanName.getText().toString(); + + if (text.length() <= 0) { + return; + } + + // Add item into list + int insertIndex = plansList.size(); + plansList.add(insertIndex, new Item_General_001(text)); + adapterWorkoutPlans.notifyItemInserted(insertIndex); + + // Save to database + databaseHelper.addWorkoutPlan(text); + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + + private void showDialogError() { + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + builder.setTitle("You must have at least 1 workout plan!"); + // builder.setMessage("uwu"); + builder.setPositiveButton("Okay", null); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + + // Class overwrite methods --------------------------------------------------------------------- + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_workout_editplans); + + databaseHelper = new DatabaseHelper(Activity_Workout_EditPlans.this); + plansList = loadPlansFromDatabase(); + + adapterWorkoutPlans = new Adapter_Item_General_001(plansList, this); + RecyclerView recyclerView = findViewById(R.id.recyclerViewPlans); + recyclerView.setAdapter(adapterWorkoutPlans); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false)); + + // Toolbar --------------------------------------------------------------------------------- + + Toolbar toolbar = findViewById(R.id.toolbarActivityEditPlans); + toolbar.setTitle("Edit workout plans"); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // Buttons --------------------------------------------------------------------------------- + + Button buttonCreatePlan = findViewById(R.id.buttonCreatePlan); + buttonCreatePlan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showDialogCreatePlan(); + } + }); + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + + // Interface methods --------------------------------------------------------------------------- + + @Override + public void onItemClicked(int itemPosition) { + // Open dialog edit plan + showDialogEditPlanName(plansList.get(itemPosition).getTitle(), itemPosition); + currentEditedPlanIndex = itemPosition; + } + + @Override + public void onButtonRemoveClicked(int itemPosition) { + if (plansList.size() == 1) { + // Toast.makeText(getApplicationContext(), "You must have at least 1 workout plan", Toast.LENGTH_SHORT).show(); + showDialogError(); + return; + } + + // Delete plan from database + databaseHelper.deleteWorkoutPlan(plansList.get(itemPosition).getTitle()); + + // Update recycler view + plansList.remove(itemPosition); + adapterWorkoutPlans.notifyItemRemoved(itemPosition); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_EditRoutines.java b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_EditRoutines.java new file mode 100644 index 0000000..a0a24e0 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/activities/Activity_Workout_EditRoutines.java @@ -0,0 +1,267 @@ +package com.falyrion.gymtonicapp.activities; + +import android.content.DialogInterface; +import android.database.Cursor; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Spinner; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.data.DatabaseHelper; +import com.falyrion.gymtonicapp.recyclerview.Adapter_Item_General_001; +import com.falyrion.gymtonicapp.recyclerview.Item_General_001; + +import java.util.ArrayList; + +public class Activity_Workout_EditRoutines extends AppCompatActivity implements Adapter_Item_General_001.Interface_Item_Edit, AdapterView.OnItemSelectedListener { + + /** + * This activity lets the user edit workout routines. Changes will be saved to the database. + * + * - This activity is for changing values of an existing routines only. Creating new routines + * happens in the Fragment_Workout. + */ + + private boolean savePossible = false; + + private String[] workoutPlans; + private int selectedPlanIdx = 0; + private ArrayList routinesList; + private Adapter_Item_General_001 adapterWorkoutRoutines; + private RecyclerView recyclerViewRoutines; + private DatabaseHelper databaseHelper; + + + private String[] loadPlansFromDatabase() { + Cursor cursor = databaseHelper.getWorkoutPlans(); + String[] loadedPlans = new String[0]; + + if (cursor.getCount() > 0) { + // Initiate array with length of cursor data + loadedPlans = new String[cursor.getCount()]; + // Add plan-names to array + int j = 0; + while (cursor.moveToNext()) { + loadedPlans[j] = cursor.getString(0); + j++; + } + } + cursor.close(); + + return loadedPlans; + } + + private ArrayList loadRoutinesFromDatabase(String plan) { + Cursor cursor = databaseHelper.getWorkoutRoutines(plan); + ArrayList loadedRoutines = new ArrayList(); + + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + loadedRoutines.add(cursor.getPosition(), new Item_General_001(cursor.getString(0))); + } + } + + return loadedRoutines; + } + + private void showDialogEditRoutineName(String currentRoutineName, int itemPosition) { + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_edittext, null); + builder.setView(view); + + EditText editTextRoutineName = view.findViewById(R.id.dialogEditText); + editTextRoutineName.setText(currentRoutineName); + + builder.setTitle("Edit routine name"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String newRoutineName = editTextRoutineName.getText().toString(); + + if (newRoutineName.length() <= 0) { + return; + } + + // Update data in database + databaseHelper.updateWorkoutRoutineName(workoutPlans[selectedPlanIdx], currentRoutineName, newRoutineName); + + // Update recycler view + routinesList.get(itemPosition).setTitle(newRoutineName); + adapterWorkoutRoutines.notifyItemChanged(itemPosition); + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + + private void showDialogCreateRoutine() { + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + LayoutInflater inflater = getLayoutInflater(); + View view = inflater.inflate(R.layout.dialog_edittext, null); + builder.setView(view); + + EditText editTextRoutineName = view.findViewById(R.id.dialogEditText); + editTextRoutineName.setHint("Enter plan name"); + + builder.setTitle("Create New Workout Routine"); + builder.setNegativeButton("Cancel", null); + builder.setPositiveButton("Create routine", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + String text = editTextRoutineName.getText().toString(); + + if (text.length() <= 0) { + return; + } + + // Add item into list + int insertIndex = routinesList.size(); + routinesList.add(insertIndex, new Item_General_001(text)); + adapterWorkoutRoutines.notifyItemInserted(insertIndex); + + // Save to database + databaseHelper.addWorkoutRoutine(workoutPlans[selectedPlanIdx], text); + } + }); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + + private void showDialogError() { + AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle); + + builder.setTitle("You must have at least 1 workout plan!"); + // builder.setMessage("uwu"); + builder.setPositiveButton("Okay", null); + + AlertDialog alertDialog = builder.create(); + alertDialog.show(); + } + + // Class overwrite methods --------------------------------------------------------------------- + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_workout_editroutines); + + // Load data from database + databaseHelper = new DatabaseHelper(Activity_Workout_EditRoutines.this); + workoutPlans = loadPlansFromDatabase(); + selectedPlanIdx = 0; + routinesList = loadRoutinesFromDatabase(workoutPlans[selectedPlanIdx]); + + // Set up spinner for workout-plans + Spinner spinnerPlans = findViewById(R.id.spinnerWorkoutRoutines); + spinnerPlans.setOnItemSelectedListener(this); + ArrayAdapter adapterPlans = new ArrayAdapter(getApplicationContext(), R.layout.spinner_item_purple_middle, workoutPlans); + adapterPlans.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinnerPlans.setAdapter(adapterPlans); + + // Set up adapter for recycler-view for routines + recyclerViewRoutines = findViewById(R.id.recyclerViewRoutines); + if (!routinesList.isEmpty()) { + adapterWorkoutRoutines = new Adapter_Item_General_001(routinesList, this); + recyclerViewRoutines.setAdapter(adapterWorkoutRoutines); + recyclerViewRoutines.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false)); + } + + // Toolbar --------------------------------------------------------------------------------- + + Toolbar toolbar = findViewById(R.id.toolbarActivityEditRoutines); + toolbar.setTitle("Edit workout routines"); + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + + // Buttons --------------------------------------------------------------------------------- + +// Button buttonCancel = findViewById(R.id.buttonCancel); +// buttonCancel.setOnClickListener(new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// Intent intent = new Intent(view.getContext(), Activity_Main.class); +// intent.putExtra("fragmentID", 2); +// startActivity(intent); +// } +// }); + + Button buttonCreatePlan = findViewById(R.id.buttonCreateRoutine); + buttonCreatePlan.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + showDialogCreateRoutine(); + } + }); + } + + @Override + protected void onDestroy() { + databaseHelper.close(); + super.onDestroy(); + } + + + // Interface methods --------------------------------------------------------------------------- + + // Spinner "Plan" Methods + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long l) { + if (position == selectedPlanIdx) { + return; + } + + selectedPlanIdx = position; + + // Update routines + routinesList.clear(); + adapterWorkoutRoutines.notifyDataSetChanged(); + + routinesList = loadRoutinesFromDatabase(workoutPlans[selectedPlanIdx]); + + adapterWorkoutRoutines = new Adapter_Item_General_001(routinesList, this); + recyclerViewRoutines.setAdapter(adapterWorkoutRoutines); + recyclerViewRoutines.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false)); + + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + // Pass + } + + // "Routines" Recyclerview Adapter Methods + @Override + public void onItemClicked(int itemPosition) { + // Open dialog edit plan + showDialogEditRoutineName(routinesList.get(itemPosition).getTitle(), itemPosition); + } + + @Override + public void onButtonRemoveClicked(int itemPosition) { + // Delete plan from database + databaseHelper.deleteWorkoutRoutine(workoutPlans[selectedPlanIdx], routinesList.get(itemPosition).getTitle()); + + // Update recycler view + routinesList.remove(itemPosition); + adapterWorkoutRoutines.notifyItemRemoved(itemPosition); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/data/DatabaseHelper.java b/app/src/main/java/com/falyrion/gymtonicapp/data/DatabaseHelper.java new file mode 100644 index 0000000..2bc8d57 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/data/DatabaseHelper.java @@ -0,0 +1,709 @@ +package com.falyrion.gymtonicapp.data; + +import android.content.ContentValues; +import android.content.Context; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.database.sqlite.SQLiteOpenHelper; +import android.widget.Toast; + +import androidx.annotation.Nullable; + +public class DatabaseHelper extends SQLiteOpenHelper { + + /** + * This class contains all methods to access the database. + */ + + private Context context; + private static final String DATABASE_NAME = "gymtonicapp.db"; + private static final int DATABASE_VERSION = 40; + + // Table foods + private static final String TABLE_PM = "preset_meals"; + private static final String COL_PM_INDEX = "meal_index"; + private static final String COL_PM_NAME = "name"; + private static final String COL_PM_CATEGORY = "category"; + private static final String COL_PM_CALORIES = "calories"; + private static final String COL_PM_FAT = "fat"; + private static final String COL_PM_FAT_SAT = "fat_sat"; + private static final String COL_PM_CARBS = "carbs"; + private static final String COL_PM_SUGAR = "sugar"; + private static final String COL_PM_PROTEIN = "protein"; + private static final String COL_PM_SALT = "salt"; + private static final String COL_PM_FIBER = "fiber"; + private static final String COL_PM_CHOL = "cholesterin"; // in mg + private static final String COL_PM_CREATINE = "creatine"; + private static final String COL_PM_CA = "calcium"; // in mg + private static final String COL_PM_FE = "iron"; // in mg + private static final String COL_PM_K = "kalium"; // in mg + private static final String COL_PM_MG = "magnesium"; // in mg + private static final String COL_PM_MN = "mangan"; // in mg + private static final String COL_PM_NA = "natrium"; // in mg + private static final String COL_PM_P = "phosphor"; // in mg + private static final String COL_PM_ZN = "zinc"; // in mg + private static final String COL_PM_VIT_A = "vit_a"; // in mg + private static final String COL_PM_VIT_B1 = "vit_b1"; // in mg + private static final String COL_PM_VIT_B2 = "vit_b2"; // in mg + private static final String COL_PM_VIT_B3 = "vit_b3"; // (Niacin) in mg + private static final String COL_PM_VIT_B5 = "vit_b5"; // (Pantothensäure) in mg + private static final String COL_PM_VIT_B6 = "vit_b6"; // in mg + private static final String COL_PM_VIT_B7 = "vit_b7"; // (Biotin) in mg + private static final String COL_PM_VIT_B11 = "vit_b11"; // (Folsäure, B9) in mg + private static final String COL_PM_VIT_B12 = "vit_b12"; // in mg + private static final String COL_PM_VIT_C = "vit_c"; // in mg + private static final String COL_PM_VIT_E = "vit_e"; // in mg + private static final String COL_PM_VIT_K = "vit_k"; // in mg + private static final String COL_PM_VIT_H = "vit_h"; // (Biotin) in mg + + private static final String TABLE_PMC = "meal_categories"; + private static final String COL_PMC_NAME = "name"; + + // Table meals per day + private static final String TABLE_CM = "consumed_meals"; + private static final String COL_CM_DATE = "date"; + private static final String COL_CM_INDEX = "meal_index"; // Refers to uuid-index of a food from foods-table + private static final String COL_CM_AMOUNT = "amount"; + + // Table body-data + private static final String TABLE_BD = "bodydata"; + private static final String COLUMN_BD_DATE = "date"; + private static final String COLUMN_BD_WEIGHT = "weight"; + private static final String COLUMN_BD_CHEST = "chest"; + private static final String COLUMN_BD_BELLY = "belly"; + private static final String COLUMN_BD_BUTT = "butt"; + private static final String COLUMN_BD_WAIST = "waist"; + private static final String COLUMN_BD_ARM_R = "arm_right"; + private static final String COLUMN_BD_ARM_L = "arm_left"; + private static final String COLUMN_BD_LEG_R = "leg_right"; + private static final String COLUMN_BD_LEG_L = "leg_left"; + + // Table exercises + private static final String TABLE_WP = "workout_plans"; + private static final String COL_WP_NAME = "plan_name"; + + private static final String TABLE_WR = "workout_routines"; + private static final String COL_WR_PLAN_NAME = "plan_name"; + private static final String COL_WR_ROUTINE_NAME = "routine_name"; + + private static final String TABLE_WE = "exercises"; + private static final String COL_WE_PLAN_NAME = "plan_name"; + private static final String COL_WE_ROUTINE_NAME = "routine"; + private static final String COL_WE_EXERCISE_NAME = "exercise_name"; + private static final String COL_WE_SETS = "sets"; + private static final String COL_WE_REPETITIONS = "repetitions"; + private static final String COL_WE_WEIGHT = "weight"; + + // Table settings + private static final String TABLE_S = "settings"; + private static final String COL_S_INDEX = "goals_index"; + private static final String COL_S_GOAL_CALORIES = "goal_calories"; + private static final String COL_S_GOAL_FAT = "goal_fat"; + private static final String COL_S_GOAL_CARBS = "goal_carbs"; + private static final String COL_S_GOAL_PROTEIN = "goal_protein"; + + + // Constructor --------------------------------------------------------------------------------- + public DatabaseHelper(@Nullable Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + this.context = context; + } + + // Class default overwrite methods ------------------------------------------------------------- + + /** This method will be called upon creation of the database. This method will create all the + * necessary tables inside the database and prepopulate some tables. + * + * @param sqLiteDatabase: SQLiteDatabase that is created + */ + @Override + public void onCreate(SQLiteDatabase sqLiteDatabase) { + // Create table body-data + sqLiteDatabase.execSQL( + "CREATE TABLE " + TABLE_BD + " (" + + COLUMN_BD_DATE + " TEXT PRIMARY KEY, " + + COLUMN_BD_WEIGHT + " REAL, " + + COLUMN_BD_CHEST + " REAL, " + + COLUMN_BD_BELLY + " REAL, " + + COLUMN_BD_BUTT + " REAL, " + + COLUMN_BD_WAIST + " REAL, " + + COLUMN_BD_ARM_R + " REAL, " + + COLUMN_BD_ARM_L + " REAL, " + + COLUMN_BD_LEG_R + " REAL, " + + COLUMN_BD_LEG_L + " REAL);" + ); + + // Create table food-data + sqLiteDatabase.execSQL( + "CREATE TABLE " + TABLE_PM + " (" + + COL_PM_INDEX + " TEXT PRIMARY KEY, " + + COL_PM_NAME + " TEXT, " + + COL_PM_CATEGORY + " TEXT, " + + COL_PM_CALORIES + " REAL, " + + COL_PM_FAT + " REAL, " + + COL_PM_FAT_SAT + " REAL, " + + COL_PM_CARBS + " REAL, " + + COL_PM_SUGAR + " REAL, " + + COL_PM_PROTEIN + " REAL, " + + COL_PM_SALT + " REAL, " + + COL_PM_FIBER + " REAL, " + + COL_PM_CHOL + " REAL, " + + COL_PM_CREATINE + " REAL, " + + COL_PM_CA + " REAL, " + + COL_PM_FE + " REAL, " + + COL_PM_K + " REAL, " + + COL_PM_MG + " REAL, " + + COL_PM_MN + " REAL, " + + COL_PM_NA + " REAL, " + + COL_PM_P + " REAL, " + + COL_PM_ZN + " REAL, " + + COL_PM_VIT_A + " REAL, " + + COL_PM_VIT_B1 + " REAL, " + + COL_PM_VIT_B2 + " REAL, " + + COL_PM_VIT_B3 + " REAL, " + + COL_PM_VIT_B5 + " REAL, " + + COL_PM_VIT_B6 + " REAL, " + + COL_PM_VIT_B7 + " REAL, " + + COL_PM_VIT_B11 + " REAL, " + + COL_PM_VIT_B12 + " REAL, " + + COL_PM_VIT_C + " REAL, " + + COL_PM_VIT_E + " REAL, " + + COL_PM_VIT_K + " REAL, " + + COL_PM_VIT_H + " REAL);" + ); + + sqLiteDatabase.execSQL("CREATE TABLE " + TABLE_PMC + " (" + COL_PMC_NAME + " TEXT PRIMARY KEY);"); + + // Create table dailymeals + sqLiteDatabase.execSQL("CREATE TABLE " + TABLE_CM + " (" + + COL_CM_DATE + " TEXT, " + + COL_CM_INDEX + " TEXT, " + + COL_CM_AMOUNT + " REAL, " + + "PRIMARY KEY (" + COL_CM_INDEX + ", " + COL_CM_AMOUNT + "));" + ); + + // Create tables exercises + sqLiteDatabase.execSQL("CREATE TABLE " + TABLE_WE + " (" + + COL_WE_PLAN_NAME + " TEXT, " + + COL_WE_ROUTINE_NAME + " TEXT, " + + COL_WE_EXERCISE_NAME + " TEXT, " + + COL_WE_SETS + " INTEGER, " + + COL_WE_REPETITIONS + " INTEGER, " + + COL_WE_WEIGHT + " REAL" + + ");"); + + sqLiteDatabase.execSQL("CREATE TABLE " + TABLE_WP + " ("+ COL_WP_NAME + " TEXT PRIMARY KEY);"); + sqLiteDatabase.execSQL("CREATE TABLE " + TABLE_WR + " ("+ COL_WR_PLAN_NAME + " TEXT, " + COL_WR_ROUTINE_NAME + " TEXT, PRIMARY KEY (" + COL_WR_PLAN_NAME + ", " + COL_WR_ROUTINE_NAME + "));"); + + // Create table settings + sqLiteDatabase.execSQL("CREATE TABLE " + TABLE_S + " (" + + COL_S_INDEX + " INTEGER PRIMARY KEY, " + + COL_S_GOAL_CALORIES + " REAL, " + + COL_S_GOAL_FAT + " REAL, " + + COL_S_GOAL_CARBS + " REAL, " + + COL_S_GOAL_PROTEIN + " REAL);"); + + // Add preset data to tables --------------------------------------------------------------- + + // Preset meals + // -> Format: index + name + 6 main values + 22 optional values + // -> ('index', 'name', 'category', cal, fat, fatsat, carbs, sugar, protein, salt, fiber, cholesterin, creatine, ca, fe, k_potassium, mg, mn, na_sodium, phosphor, zn, vita, vitb1, b2, b3, b5, b6, b7, b11, b12, c, e, k, h) + // -> Preset meals indices have always 1 digit more (7 digits in total) than user created meals to prevent overlaps + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('000000000', 'Apple (100 g)', 'Fruits and Vegetables', 52, 0.17, 0, 13.81, 10.39, 0.26, 0, 2.4, 0, 0, 6, 0.12, 107, 5, 0.035, 1, 11, 0.04, 0.003, 0.017, 0.026, 0.091, 0.061, 0.041, 0, 0, 0, 4.6, 0.18, 0.022, 0)"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('000000001', 'Banana (100 g)', 'Fruits and Vegetables', 95.0, 0.33, 0.0, 22.84, 12.23, 1.0, 0.0, 2.6, 0.0, 0.0, 5.0, 0.26, 358.0, 27.0, 0.0, 0.0, 22.0, 0.15, 0.003, 0.031, 0.073, 0.665, 0.334, 0.367, 0.0, 0.0, 0.0, 8.7, 0.0, 0.0, 0.0)"); + + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('100000000', 'Long-grain brown rice (uncooked)', 'Grains and Cereals', 362.0, 2.3, 0.7, 75.0, 1.9, 7.8, 0.03, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)"); + + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('200000000', 'Oakmilk', 'Drinks', 40.0, 1.4, 0.2, 6.0, 5.2, 0.6, 0.13, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)"); + + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('300000000', 'Agave Syrup', 'Spices, Sauces, Oils', 307.0, 0.5, 0.1, 75.0, 75.0, 0.5, 0.03, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('300000001', 'Soy Sauce', 'Spices, Sauces, Oils', 41.0, 0.0, 0.0, 5.0, 1.4, 5.3, 17.77, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)"); + + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PM + " VALUES('400000000', 'Smoked Tofu', 'Veggie Products', 168.0, 9.5, 1.6, 2.0, 0.5, 18.0, 1.04, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)"); + + + // Add meal categories + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Fruits and Vegetables');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Drinks');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Grains and Cereals');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Spices, Sauces, Oils');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Veggie Products');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Sweets and Spread');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Animal Products');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Convenience Foods');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Supplements');"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_PMC + " VALUES('Custom');"); + + // Workout plan names + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WP + " VALUES('Example Workout Plan')"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WP + " VALUES('My Workout Plan')"); + + // Workout routine names + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WR + " VALUES('Example Workout Plan', 'Push Day')"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WR + " VALUES('Example Workout Plan', 'Pull Day')"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WR + " VALUES('Example Workout Plan', 'Leg Day')"); + + // Workout exercises + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WE + " VALUES('Example Workout Plan', 'Push Day', 'Chest Press', 3, 6, 20)"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WE + " VALUES('Example Workout Plan', 'Push Day', 'Shoulder Press', 3, 6, 20)"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WE + " VALUES('Example Workout Plan', 'Pull Day', 'Lat Pull Down', 3, 8, 20)"); + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_WE + " VALUES('Example Workout Plan', 'Leg Day', 'Leg Press', 3, 6, 20)"); + + // Settings + // -> (index, calories, carbs, fat, protein). First value is index. Must always be 0. + sqLiteDatabase.execSQL("INSERT INTO " + TABLE_S + " VALUES(0, 2500, 200, 100, 160)"); + } + + /** This method will be called upon upgrading the database from one version to a higher one. + * + * @param sqLiteDatabase: SQLiteDatabase; The SQLiteDatabase to upgrade. + * @param oldVersion: Integer; The old version number of the database to upgrade from. + * @param newVersion: Integer; The new version number of the database to upgrade to. + */ + @Override + public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) { + // Delete old tables + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_PM); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_PMC); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_CM); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_BD); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_WE); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_WR); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_WP); + sqLiteDatabase.execSQL("DROP TABLE IF EXISTS " + TABLE_S); + + // Create new database + onCreate(sqLiteDatabase); + } + + + // Meals Query's ------------------------------------------------------------------------------- + + public Cursor getPresetMealsSimpleAllCategories() { + // -> Return index, name, calories from table "foods" in ascending order by name + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery( + "SELECT " + COL_PM_INDEX + ", " + COL_PM_NAME + ", " + COL_PM_CALORIES + " FROM " + TABLE_PM + " ORDER BY " + COL_PM_NAME + " ASC LIMIT 100;", + null + ); + } + + return cursor; + } + + public Cursor getPresetMealsSimpleFromCategory(String category) { + // -> Return index, name, calories from specified category table "foods" in ascending order by name + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery( + "SELECT " + COL_PM_INDEX + ", " + COL_PM_NAME + ", " + COL_PM_CALORIES + " FROM " + TABLE_PM + " WHERE " + COL_PM_CATEGORY + "='" + category + "'" + " ORDER BY " + COL_PM_NAME + " ASC;", + null + ); + } + + return cursor; + } + + public Cursor getPresetMealDetails(String foodUUID) { + // -> Returns all Details for a preset meal with given UUID + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery("SELECT * FROM " + TABLE_PM + " WHERE " + COL_PM_INDEX + "='" + foodUUID + "';", null); + } + + return cursor; + } + + public Cursor getPresetMealCategories() { + // -> Returns all Details for a preset meal with given UUID + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery("SELECT DISTINCT " + COL_PMC_NAME + " FROM " + TABLE_PMC + " ORDER BY " + COL_PMC_NAME + " ASC;", null); + } + + return cursor; + } + + public Cursor getConsumedMeals(String date) { + // -> Returns index, name, calories, amount for all consumed meals for a given date + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + // SELECT food.food_index, food.name, food.calories, dailymeals.amount FROM dailymeals LEFT JOIN food ON dailymeals.food_index=food.food_index WHERE dailymeals.date=date; + // Returns -> | food.food_index | food.name | food.cal | dailymeals.amount | + cursor = sqLiteDatabase.rawQuery( + "SELECT " + TABLE_PM + "." + COL_PM_INDEX + ", " + TABLE_PM + "." + COL_PM_NAME + ", " + TABLE_PM + "." + COL_PM_CALORIES + ", " + TABLE_CM + "." + COL_CM_AMOUNT + " " + + "FROM " + TABLE_CM + " " + + "LEFT JOIN " + TABLE_PM + " ON " + TABLE_CM + "." + COL_CM_INDEX + "=" + TABLE_PM + "." + COL_PM_INDEX + " " + + "WHERE " + TABLE_CM + "." + COL_CM_DATE + "='" + date + "';", + null); + } + + return cursor; + } + + public Cursor getConsumedMealsSums(String date) { + // -> Returns sum of all details of all consumed meals for a given date + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + + // SELECT (food.calories * dailymeals.amount) [other columns here] FROM dailymeals LEFT JOIN food ON dailymeals.food_index=food.food_index WHERE dailymeals.date=date; + // Returns -> | food.food_index | food.name | food.cal | food.fat | food.fat_sat | food.carbs | food.sugar | food.protein | dailymeals.amount | + cursor = sqLiteDatabase.rawQuery( + "SELECT " + + "SUM (" + TABLE_PM + "." + COL_PM_CALORIES + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_FAT + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_FAT_SAT + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_CARBS + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_SUGAR + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_PROTEIN + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + + "SUM (" + TABLE_PM + "." + COL_PM_SALT + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_FIBER + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_CHOL + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_CREATINE + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + + "SUM (" + TABLE_PM + "." + COL_PM_CA + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_FE + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_K + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_MG + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_MN + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_NA + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_P + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_ZN + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_A + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B1 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B2 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B3 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B5 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B6 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B7 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B11 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_B12 + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_C + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_E + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_K + " * " + TABLE_CM + "." + COL_CM_AMOUNT + "), " + + "SUM (" + TABLE_PM + "." + COL_PM_VIT_H + " * " + TABLE_CM + "." + COL_CM_AMOUNT + ") " + + + "FROM " + TABLE_CM + " " + + "LEFT JOIN " + TABLE_PM + " ON " + TABLE_CM + "." + COL_CM_INDEX + "=" + TABLE_PM + "." + COL_PM_INDEX + " " + + "WHERE " + TABLE_CM + "." + COL_CM_DATE + "='" + date + "';", + null); + } + + return cursor; + } + + public void addOrReplacePresetMeal(String uuid, String name, String category, double[] data) { + // -> Inserts new preset meal to database + + // Get database + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + // Create content values to put into the database + ContentValues cv = new ContentValues(); + + cv.put(COL_PM_INDEX, uuid); + cv.put(COL_PM_NAME, name); + cv.put(COL_PM_CATEGORY, category); + cv.put(COL_PM_CALORIES, data[0]); + cv.put(COL_PM_FAT, data[1]); + cv.put(COL_PM_FAT_SAT, data[2]); + cv.put(COL_PM_CARBS, data[3]); + cv.put(COL_PM_SUGAR, data[4]); + cv.put(COL_PM_PROTEIN, data[5]); + cv.put(COL_PM_SALT, data[6]); + cv.put(COL_PM_FIBER, data[7]); + cv.put(COL_PM_CHOL, data[8]); + cv.put(COL_PM_CREATINE, data[9]); + cv.put(COL_PM_CA, data[10]); + cv.put(COL_PM_FE, data[11]); + cv.put(COL_PM_K, data[12]); + cv.put(COL_PM_MG, data[13]); + cv.put(COL_PM_MN, data[14]); + cv.put(COL_PM_NA, data[15]); + cv.put(COL_PM_P, data[16]); + cv.put(COL_PM_ZN, data[17]); + cv.put(COL_PM_VIT_A, data[18]); + cv.put(COL_PM_VIT_B1, data[19]); + cv.put(COL_PM_VIT_B2, data[20]); + cv.put(COL_PM_VIT_B3, data[21]); + cv.put(COL_PM_VIT_B5, data[22]); + cv.put(COL_PM_VIT_B6, data[23]); + cv.put(COL_PM_VIT_B7, data[24]); + cv.put(COL_PM_VIT_B11, data[25]); + cv.put(COL_PM_VIT_B12, data[26]); + cv.put(COL_PM_VIT_C, data[27]); + cv.put(COL_PM_VIT_E, data[28]); + cv.put(COL_PM_VIT_K, data[29]); + cv.put(COL_PM_VIT_H, data[30]); + + // Insert data into database + long result = sqLiteDatabase.replaceOrThrow(TABLE_PM, null, cv); + if (result == -1) { + Toast.makeText(context, "Failed to save data", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show(); + } + + } + + public void addOrReplaceConsumedMeal(String date, String mealUUID, double amount) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + ContentValues cv = new ContentValues(); + + cv.put(COL_CM_INDEX, mealUUID); + cv.put(COL_CM_DATE, date); + cv.put(COL_CM_AMOUNT, amount); + + sqLiteDatabase.replaceOrThrow(TABLE_CM, null, cv); + } + + public void removeConsumedMeal(String date, String mealUUID) { + // Remove entry from DailyMealsTable with date and UUID + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + if (sqLiteDatabase != null) { + sqLiteDatabase.delete(TABLE_CM, COL_CM_INDEX + "= ? AND " + COL_CM_DATE + "= ?", new String[] {mealUUID, date}); + // sqLiteDatabase.delete(TABLE_NAME_M, COLUMN_M_INDEX + "='" + mealUUID + "' AND " + COLUMN_M_DATE + "='" + date + "'", null); + // sqLiteDatabase.rawQuery("DELETE FROM " + TABLE_NAME_M + " WHERE " + COLUMN_M_INDEX + "='" + mealUUID + "' AND " + COLUMN_M_DATE + "='" + date + "';", null); + } + } + + // Workout Query's ----------------------------------------------------------------------------- + + public Cursor getWorkoutPlans() { + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery("SELECT DISTINCT * FROM " + TABLE_WP + ";", null); + } + + return cursor; + } + + public Cursor getWorkoutRoutines(String planName) { + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + // cursor = sqLiteDatabase.rawQuery("SELECT DISTINCT " + COL_WE_ROUTINE_NAME + " FROM " + TABLE_WE + " WHERE " + COL_WE_PLAN_NAME + "='" + plan +"';", null); + cursor = sqLiteDatabase.rawQuery("SELECT DISTINCT " + COL_WR_ROUTINE_NAME + " FROM " + TABLE_WR + " WHERE " + COL_WR_PLAN_NAME + "='" + planName + "';", null); + } + + return cursor; + } + + public Cursor getWorkoutExercises(String plan, String routine) { + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery( + "SELECT " + COL_WE_EXERCISE_NAME + ", " + COL_WE_SETS + ", " + COL_WE_REPETITIONS + ", " + COL_WE_WEIGHT + + " FROM " + TABLE_WE + + " WHERE " + COL_WE_PLAN_NAME + "='" + plan + "' AND " + COL_WE_ROUTINE_NAME + "='" + routine +"';", + null); + } + + return cursor; + } + + public void addWorkoutPlan(String planName) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + if (sqLiteDatabase != null) { + sqLiteDatabase.execSQL("INSERT OR REPLACE INTO " + TABLE_WP + " VALUES('" + planName + "')"); + } + } + + public void addWorkoutRoutine(String planName, String routineName) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + if (sqLiteDatabase != null) { + ContentValues cv = new ContentValues(); + cv.put(COL_WR_PLAN_NAME, planName); + cv.put(COL_WR_ROUTINE_NAME, routineName); + + sqLiteDatabase.replaceOrThrow(TABLE_WR, null, cv); + } + } + + public void addWorkoutExercise(String planName, String routineName, String exerciseName, int sets, int repetitions, double weight) { + // Get database + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + // Create content values to put into the database + ContentValues cv = new ContentValues(); + cv.put(COL_WE_PLAN_NAME, planName); + cv.put(COL_WE_ROUTINE_NAME, routineName); + cv.put(COL_WE_EXERCISE_NAME, exerciseName); + cv.put(COL_WE_SETS, sets); + cv.put(COL_WE_REPETITIONS, repetitions); + cv.put(COL_WE_WEIGHT, weight); + + long result = sqLiteDatabase.replaceOrThrow(TABLE_WE, null, cv); + if (result == -1) { + Toast.makeText(context, "Failed to save", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show(); + } + } + + public void updateWorkoutPlanName(String oldPlanName, String newPlanName) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + if (sqLiteDatabase != null) { + // Remove old plan name from table "plans" + sqLiteDatabase.delete(TABLE_WP, COL_WP_NAME + "= ?", new String[] {oldPlanName}); + + // Add new plan name to table "plans" + ContentValues cv = new ContentValues(); + cv.put(COL_WP_NAME, newPlanName); + sqLiteDatabase.insertOrThrow(TABLE_WP, null, cv); + + // Update plan names in table "exercises" + cv = new ContentValues(); + cv.put(COL_WE_PLAN_NAME, newPlanName); + sqLiteDatabase.update(TABLE_WE, cv, COL_WE_PLAN_NAME + "= ?", new String[]{oldPlanName}); + + // Update plan names in table "routines" + cv = new ContentValues(); + cv.put(COL_WR_PLAN_NAME, newPlanName); + sqLiteDatabase.update(TABLE_WR, cv, COL_WR_PLAN_NAME + "= ?", new String[]{oldPlanName}); + } + } + + public void updateWorkoutRoutineName(String planName, String oldRoutineName, String newRoutineName) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + if (sqLiteDatabase != null) { + // Update routine name in table "routines" + ContentValues cv = new ContentValues(); + cv.put(COL_WR_ROUTINE_NAME, newRoutineName); + sqLiteDatabase.update(TABLE_WR, cv, COL_WR_PLAN_NAME + "= ? AND " + COL_WR_ROUTINE_NAME + "= ?", new String[] {planName, oldRoutineName}); + + // Update routine names in table "exercises" + cv = new ContentValues(); + cv.put(COL_WE_ROUTINE_NAME, newRoutineName); + sqLiteDatabase.update(TABLE_WE, cv, COL_WE_ROUTINE_NAME + "= ?", new String[]{oldRoutineName}); + } + } + + public void deleteWorkoutPlan(String planName) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + // Remove plan name from table "plans" + sqLiteDatabase.delete(TABLE_WP, COL_WP_NAME + "= ?", new String[] {planName}); + + // Remove all entries for this plan in table "exercises" + sqLiteDatabase.delete(TABLE_WE, COL_WE_PLAN_NAME + "= ?", new String[] {planName}); + } + + public void deleteWorkoutRoutine(String planName, String routineName) { + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + // Remove routine name from table "routines" + sqLiteDatabase.delete(TABLE_WR, COL_WR_PLAN_NAME + "= ? AND " + COL_WR_ROUTINE_NAME + "= ?", new String[] {planName, routineName}); + + // Remove all entries for this routine in table "exercises" + sqLiteDatabase.delete(TABLE_WE, COL_WE_PLAN_NAME + "= ? AND " + COL_WE_ROUTINE_NAME + "= ?", new String[] {planName, routineName}); + } + + public void deleteWorkoutExercise(String planName, String routineName, String exerciseName) { + // Get database + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + if (sqLiteDatabase != null) { + sqLiteDatabase.delete(TABLE_WE, COL_WE_PLAN_NAME + "= ? AND " + COL_WE_ROUTINE_NAME + "= ? AND " + COL_WE_EXERCISE_NAME + "= ?", new String[] {planName, routineName, exerciseName}); + // sqLiteDatabase.rawQuery("DELETE FROM " + TABLE_NAME_WE + " WHERE " + COL_E_PLAN_NAME + "='" + planName + "' AND " + COL_E_ROUTINE_NAME + "='" + routineName + "' AND " + COL_E_EXERCISE_NAME + "='" + exerciseName +"';", null); + } + + } + + // Settings Query's ---------------------------------------------------------------------------- + + public Cursor getSettingsGoals() { + // -> Read settings from table "settings" + + SQLiteDatabase sqLiteDatabase = this.getReadableDatabase(); + Cursor cursor = null; + + if (sqLiteDatabase != null) { + cursor = sqLiteDatabase.rawQuery( + "SELECT " + COL_S_GOAL_CALORIES + ", " + COL_S_GOAL_FAT + ", " + COL_S_GOAL_CARBS + ", " + COL_S_GOAL_PROTEIN + + " FROM " + TABLE_S + ";", + null); + } + + return cursor; + } + + public void setSettingsGoals(double goalCalories, double goalFat, double goalCarbs, double goalProtein) { + // Get database + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + // Create content values to put into the database + ContentValues cv = new ContentValues(); + + cv.put(COL_S_INDEX, 0); + cv.put(COL_S_GOAL_CALORIES, goalCalories); + cv.put(COL_S_GOAL_FAT, goalFat); + cv.put(COL_S_GOAL_CARBS, goalCarbs); + cv.put(COL_S_GOAL_PROTEIN, goalProtein); + + long result = sqLiteDatabase.replaceOrThrow(TABLE_S, null, cv); + if (result == -1) { + Toast.makeText(context, "Failed to save settings", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, "Saved settings", Toast.LENGTH_SHORT).show(); + } + } + + // Body-Data Query's --------------------------------------------------------------------------- + + public void addDataBody(String date, double weight, double chest, double belly, double butt, + double waist, double arm_r, double arm_l, double leg_r, double leg_l){ + // Get database + SQLiteDatabase sqLiteDatabase = this.getWritableDatabase(); + + // Create content values to put into the database + ContentValues cv = new ContentValues(); + + cv.put(COLUMN_BD_DATE, date); + cv.put(COLUMN_BD_WEIGHT, weight); + cv.put(COLUMN_BD_CHEST, chest); + cv.put(COLUMN_BD_BELLY, belly); + cv.put(COLUMN_BD_BUTT, butt); + cv.put(COLUMN_BD_WAIST, waist); + cv.put(COLUMN_BD_ARM_R, arm_r); + cv.put(COLUMN_BD_ARM_L, arm_l); + cv.put(COLUMN_BD_LEG_R, leg_r); + cv.put(COLUMN_BD_LEG_L, leg_l); + + // Insert data into dadabase + long result = sqLiteDatabase.replaceOrThrow(TABLE_BD, null, cv); + if (result == -1) { + Toast.makeText(context, "Failed to save data", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, "Saved", Toast.LENGTH_SHORT).show(); + } + } + +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Nutrition.java b/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Nutrition.java new file mode 100644 index 0000000..56fe354 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Nutrition.java @@ -0,0 +1,297 @@ +package com.falyrion.gymtonicapp.fragments; + +import android.animation.ObjectAnimator; +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.ProgressBar; +import android.widget.TableLayout; +import android.widget.TextView; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.activities.Activity_Calendar; +import com.falyrion.gymtonicapp.activities.Activity_Meals_AddDailyEntry; +import com.falyrion.gymtonicapp.activities.Activity_Meals_MealsOfDay; + +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + + +public class Fragment_Nutrition extends Fragment { + + // TODO: - Add more nutrition details (spurenelemente, metalle, vitamine, etc) + // - in Add_Meal_Actitvity funktion hinzufügen das man auf ein preset clicken kann und es bearbeiten und löschen + // - Noch mal schauen ob datum zwischen add_meal_activity und createmealactitvity richtig hin und her gegeben wird + // - Funktion zum löschen von bereits zum tag hinzugefügten meals + // - Progress bars schöner machen + + + private String date; + private double[] dataFood; + private double[] dataGoals; + + private int percentOf(double current, double max) { + return (int) ((current / max) * 100); + } + + private String convertDataToDoubleText(double value) { + // Convert given double to string. + if (value % 1 == 0) { + // -> Value has only .0 decimals. Cut it out by converting to int. + return String.valueOf((int) value); + } else { + // -> Value has decimals. Round up to 2 decimal-digits. + DecimalFormat df = new DecimalFormat("#####.##"); + return String.valueOf(df.format(value)); + } + } + + private String convertDataToIntText(double value) { + return String.valueOf((int) value); + } + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Get date from arguments + if (getArguments().containsKey("date")) { + date = getArguments().getString("date"); + } else { + SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", Locale.ENGLISH); + date = formatter.format(new Date()); + } + + // Load data from database + Cursor cursorDataFood = ((Activity_Main) requireContext()).databaseHelper.getConsumedMealsSums(date); + if (cursorDataFood.getCount() > 0) { + cursorDataFood.moveToFirst(); + dataFood = new double[31]; + for (int i = 0; i <= 30; i++) { + dataFood[i] = cursorDataFood.getDouble(i); + } + + } else { + dataFood = new double[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + } + cursorDataFood.close(); + + Cursor cursorSettings = ((Activity_Main) requireContext()).databaseHelper.getSettingsGoals(); + if (cursorSettings.getCount() > 0) { + cursorSettings.moveToFirst(); + dataGoals = new double[] { + cursorSettings.getDouble(0), // Goal Calories + cursorSettings.getDouble(1), // Goal Fat + cursorSettings.getDouble(2), // Goal Carbohydrates + cursorSettings.getDouble(3) // Goal Protein + }; + } else { + dataGoals = new double[] {2000, 2000, 2000, 2000}; + } + cursorSettings.close(); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_nutrition, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + // Date + TextView textDate = view.findViewById(R.id.textViewDBNDate); + textDate.setText(date); + + // Set values for main-dashboard + ProgressBar progressBarMain = getView().findViewById(R.id.progressBarDBNCaloriesMain); + TextView textProgressMain = getView().findViewById(R.id.textViewDNCaloriesMain); + ObjectAnimator.ofInt(progressBarMain, "progress", percentOf(dataFood[0], dataGoals[0])).start(); + textProgressMain.setText(convertDataToIntText(dataFood[0])); + + ProgressBar progressBarFat = getView().findViewById(R.id.progressBarDBNFatMain); + TextView textProgressFat = getView().findViewById(R.id.textViewProgressDBNFatMain); + ObjectAnimator.ofInt(progressBarFat, "progress", percentOf(dataFood[1], dataGoals[1])).start(); + String textFat = convertDataToIntText(dataFood[1]) + " g"; + textProgressFat.setText(textFat); + + ProgressBar progressBarCarbohydrates = getView().findViewById(R.id.progressBarDBNCarbsMain); + TextView textProgressCarbohydrates = getView().findViewById(R.id.textViewProgressCarbohydrates); + ObjectAnimator.ofInt(progressBarCarbohydrates, "progress", percentOf(dataFood[3], dataGoals[2])).start(); + String textCarbohydrates = convertDataToIntText(dataFood[3]) + " g"; + textProgressCarbohydrates.setText(textCarbohydrates); + + ProgressBar progressBarProtein = getView().findViewById(R.id.progressBarDBNProteinMain); + TextView textProgressProtein = getView().findViewById(R.id.textViewProgressDBNProteinMain); + ObjectAnimator.ofInt(progressBarProtein, "progress", percentOf(dataFood[5], dataGoals[3])).start(); + String textProtein = convertDataToIntText(dataFood[5]) + " g"; + textProgressProtein.setText(textProtein); + + // Set values for details-dashboard + TextView textViewDetailsCal = getView().findViewById(R.id.textViewDBNDetailsCalories); + textViewDetailsCal.setText(convertDataToDoubleText(dataFood[0])); + + TextView textViewDetailsFat = getView().findViewById(R.id.textViewDBNDetailsFat); + textViewDetailsFat.setText(convertDataToDoubleText(dataFood[1])); + + TextView textViewDetailsFatSat = getView().findViewById(R.id.textViewDBNDetailsFatSat); + textViewDetailsFatSat.setText(convertDataToDoubleText(dataFood[2])); + + TextView textViewDetailsCarbs = getView().findViewById(R.id.textViewDBNDetailsCarbs); + textViewDetailsCarbs.setText(convertDataToDoubleText(dataFood[3])); + + TextView textViewDetailsSugar = getView().findViewById(R.id.textViewDBNDetailsSugar); + textViewDetailsSugar.setText(convertDataToDoubleText(dataFood[4])); + + TextView textViewDetailsProtein = getView().findViewById(R.id.textViewDBNDetailsProtein); + textViewDetailsProtein.setText(convertDataToDoubleText(dataFood[5])); + + TextView textViewDetailsSalt = getView().findViewById(R.id.textViewDBNDetailsSalt); + textViewDetailsSalt.setText(convertDataToDoubleText(dataFood[6])); + + TextView textViewDetailsFiber = getView().findViewById(R.id.textViewDBNDetailsFiber); + textViewDetailsFiber.setText(convertDataToDoubleText(dataFood[7])); + + TextView textViewDetailsChol = getView().findViewById(R.id.textViewDBNDetailsChol); + textViewDetailsChol.setText(convertDataToDoubleText(dataFood[8])); + + TextView textViewDetailsCreatine = getView().findViewById(R.id.textViewDBNDetailsCreatine); + textViewDetailsCreatine.setText(convertDataToDoubleText(dataFood[9])); + + TextView textViewDetailsCa = getView().findViewById(R.id.textViewDBNDetailsCa); + textViewDetailsCa.setText(convertDataToDoubleText(dataFood[10])); + + TextView textViewDetailsFe = getView().findViewById(R.id.textViewDBNDetailsFe); + textViewDetailsFe.setText(convertDataToDoubleText(dataFood[11])); + + TextView textViewDetailsKa = getView().findViewById(R.id.textViewDBNDetailsKa); + textViewDetailsKa.setText(convertDataToDoubleText(dataFood[12])); + + TextView textViewDetailsMg = getView().findViewById(R.id.textViewDBNDetailsMg); + textViewDetailsMg.setText(convertDataToDoubleText(dataFood[13])); + + TextView textViewDetailMn = getView().findViewById(R.id.textViewDBNDetailsMn); + textViewDetailMn.setText(convertDataToDoubleText(dataFood[14])); + + TextView textViewDetailsNa = getView().findViewById(R.id.textViewDBNDetailsNa); + textViewDetailsNa.setText(convertDataToDoubleText(dataFood[15])); + + TextView textViewDetailsP = getView().findViewById(R.id.textViewDBNDetailsP); + textViewDetailsP.setText(convertDataToDoubleText(dataFood[16])); + + TextView textViewDetailsZn = getView().findViewById(R.id.textViewDBNDetailsZn); + textViewDetailsZn.setText(convertDataToDoubleText(dataFood[17])); + + TextView textViewDetailsVitA = getView().findViewById(R.id.textViewDBNDetailsVitA); + textViewDetailsVitA.setText(convertDataToDoubleText(dataFood[18])); + + TextView textViewDetailsVitB1 = getView().findViewById(R.id.textViewDBNDetailsVitB1); + textViewDetailsVitB1.setText(convertDataToDoubleText(dataFood[19])); + + TextView textViewDetailsVitB2 = getView().findViewById(R.id.textViewDBNDetailsVitB2); + textViewDetailsVitB2.setText(convertDataToDoubleText(dataFood[20])); + + TextView textViewDetailsVitB3 = getView().findViewById(R.id.textViewDBNDetailsVitB3); + textViewDetailsVitB3.setText(convertDataToDoubleText(dataFood[21])); + + TextView textViewDetailsVitB5 = getView().findViewById(R.id.textViewDBNDetailsVitB5); + textViewDetailsVitB5.setText(convertDataToDoubleText(dataFood[22])); + + TextView textViewDetailsVitB6 = getView().findViewById(R.id.textViewDBNDetailsVitB6); + textViewDetailsVitB6.setText(convertDataToDoubleText(dataFood[23])); + + TextView textViewDetailsVitB7 = getView().findViewById(R.id.textViewDBNDetailsVitB7); + textViewDetailsVitB7.setText(convertDataToDoubleText(dataFood[24])); + + TextView textViewDetailsVitB11 = getView().findViewById(R.id.textViewDBNDetailsVitB11); + textViewDetailsVitB11.setText(convertDataToDoubleText(dataFood[25])); + + TextView textViewDetailsVitB12 = getView().findViewById(R.id.textViewDBNDetailsVitB12); + textViewDetailsVitB12.setText(convertDataToDoubleText(dataFood[26])); + + TextView textViewDetailsVitC = getView().findViewById(R.id.textViewDBNDetailsVitC); + textViewDetailsVitC.setText(convertDataToDoubleText(dataFood[27])); + + TextView textViewDetailsVitE = getView().findViewById(R.id.textViewDBNDetailsVitE); + textViewDetailsVitE.setText(convertDataToDoubleText(dataFood[28])); + + TextView textViewDetailsVitK = getView().findViewById(R.id.textViewDBNDetailsVitK); + textViewDetailsVitK.setText(convertDataToDoubleText(dataFood[29])); + + TextView textViewDetailsVitH = getView().findViewById(R.id.textViewDBNDetailsVitH); + textViewDetailsVitH.setText(convertDataToDoubleText(dataFood[30])); + + // Set buttons + Button buttonAddMeal = getView().findViewById(R.id.buttonDashboardNutritionAddMeal); + buttonAddMeal.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Meals_AddDailyEntry.class); + intent.putExtra("date", date); + intent.putExtra("fragmentID", 0); + // intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + Button buttonShowEatenMeals = getView().findViewById(R.id.buttonEatenMeals); + buttonShowEatenMeals.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Meals_MealsOfDay.class); + intent.putExtra("date", date); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + ImageButton buttonCalendar = getView().findViewById(R.id.buttonDBNCalendar); + buttonCalendar.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Calendar.class); + intent.putExtra("date", date); + intent.putExtra("fragmentID", 0); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // Start activity without animation + startActivity(intent); + } + }); + + TableLayout tableLayoutDetails = view.findViewById(R.id.tableLayoutDashboardNutritionDetails); + + ImageButton buttonToggleDetails = view.findViewById(R.id.buttonExpandNutritionDetails); + buttonToggleDetails.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (tableLayoutDetails.getVisibility() == View.GONE) { + tableLayoutDetails.setVisibility(View.VISIBLE); + buttonToggleDetails.setImageResource(R.drawable.ic_baseline_expand_less_24); + return; + } + tableLayoutDetails.setVisibility(View.GONE); + buttonToggleDetails.setImageResource(R.drawable.ic_baseline_expand_more_24); + } + }); + +// ScrollView mainLayout = view.findViewById(R.id.scrollViewMainLayout); +// mainLayout.setVisibility(View.VISIBLE); +// +// FrameLayout loadingLayout = view.findViewById(R.id.loadingLayout); +// loadingLayout.setVisibility(View.GONE); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Settings.java b/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Settings.java new file mode 100644 index 0000000..49c7c0e --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Settings.java @@ -0,0 +1,125 @@ +package com.falyrion.gymtonicapp.fragments; + +import android.database.Cursor; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.EditText; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; + + +public class Fragment_Settings extends Fragment { + + private double[] dataGoals; + private boolean savePossible = false; + + private Button saveButton; + + + private class textWatcher implements TextWatcher { + private int id; + private textWatcher(int id) { + this.id = id; + } + + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + // pass + } + + @Override + public void afterTextChanged(Editable editable) { + // Update value + dataGoals[id] = Double.parseDouble(editable.toString()); + + // Update background resource of save button + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + savePossible = true; + } + } + + private String convertDataToText(double value) { + // Convert given double to string. + // Check if double value has ".0" decimals. If yes cut it out. + if (value % 1 == 0) { + return String.valueOf((int) value); + } else { + return String.valueOf(value); + } + } + + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load data from database + Cursor cursor = ((Activity_Main) requireContext()).databaseHelper.getSettingsGoals(); + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + dataGoals = new double[] { + cursor.getDouble(0), + cursor.getDouble(1), + cursor.getDouble(2), + cursor.getDouble(3) + }; + } else { + dataGoals = new double[] {0, 0, 0, 0}; + } + cursor.close(); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_settings, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + EditText editTextCalories = getView().findViewById(R.id.editTextSettingsGoalsCal); + editTextCalories.setText(convertDataToText(dataGoals[0])); + editTextCalories.addTextChangedListener(new textWatcher(0)); + + EditText editTextFat = getView().findViewById(R.id.editTextSettingsGoalsFat); + editTextFat.setText(convertDataToText(dataGoals[1])); + editTextFat.addTextChangedListener(new textWatcher(1)); + + EditText editTextCarbs = getView().findViewById(R.id.editTextSettingsGoalsCarbs); + editTextCarbs.setText(convertDataToText(dataGoals[2])); + editTextCarbs.addTextChangedListener(new textWatcher(2)); + + EditText editTextProtein = getView().findViewById(R.id.editTextSettingsGoalsProtein); + editTextProtein.setText(convertDataToText(dataGoals[3])); + editTextProtein.addTextChangedListener(new textWatcher(3)); + + saveButton = getView().findViewById(R.id.buttonSaveSettings); + saveButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (savePossible) { + savePossible = false; + saveButton.setBackgroundResource(R.drawable.shape_box_round_pop); + + ((Activity_Main) requireContext()).databaseHelper.setSettingsGoals(dataGoals[0], dataGoals[1], dataGoals[2], dataGoals[3]); + } + } + }); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Workout.java b/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Workout.java new file mode 100644 index 0000000..233ffd8 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/fragments/Fragment_Workout.java @@ -0,0 +1,378 @@ +package com.falyrion.gymtonicapp.fragments; + +import android.content.Intent; +import android.database.Cursor; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.LinearLayout; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.Activity_Main; +import com.falyrion.gymtonicapp.R; +import com.falyrion.gymtonicapp.activities.Activity_Workout_CreateEditExercise; +import com.falyrion.gymtonicapp.activities.Activity_Workout_EditPlans; +import com.falyrion.gymtonicapp.activities.Activity_Workout_EditRoutines; +import com.falyrion.gymtonicapp.recyclerview.Adapter_Workout_Exercise; +import com.falyrion.gymtonicapp.recyclerview.Adapter_Workout_Routine; +import com.falyrion.gymtonicapp.recyclerview.Item_Workout_Exercise; +import com.falyrion.gymtonicapp.recyclerview.Item_Workout_Routine; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; + +import java.util.ArrayList; + + +public class Fragment_Workout extends Fragment implements Adapter_Workout_Routine.Interface_Workout_Routine, Adapter_Workout_Exercise.Interface_Workout_Exercises, AdapterView.OnItemSelectedListener { + + private String[] workoutPlans; + private ArrayList workoutRoutines; + private ArrayList workoutExercises; + private int selectedPlanIdx = -1; + private int selectedRoutineIdx = -1; + private RecyclerView recyclerViewRoutines; + private RecyclerView recyclerViewExercises; + private Adapter_Workout_Routine adapterRoutines; + private Adapter_Workout_Exercise adapterExercises; + + private boolean fabOpen = false; + private FloatingActionButton fabMain; + private LinearLayout linearLayoutFABSub01; + private LinearLayout linearLayoutFABSub02; + private LinearLayout linearLayoutFABSub03; + private View backgroundBlur; + + TextView sectionTitleRoutines; + TextView sectionTitleExercises; + + + private String[] loadPlansFromDatabase() { + Cursor cursor = ((Activity_Main) requireContext()).databaseHelper.getWorkoutPlans(); + String[] loadedPlans = new String[0]; + + if (cursor.getCount() > 0) { + // Initiate array with length of cursor data + loadedPlans = new String[cursor.getCount()]; + // Add plan-names to array + int j = 0; + while (cursor.moveToNext()) { + loadedPlans[j] = cursor.getString(0); + j++; + } + } + cursor.close(); + + return loadedPlans; + } + + private ArrayList loadRoutinesFromDatabase(String workoutPlan) { + Cursor cursor = ((Activity_Main) requireContext()).databaseHelper.getWorkoutRoutines(workoutPlan); + ArrayList loadedRoutines = new ArrayList(); + + if (cursor.getCount() > 0) { + cursor.moveToFirst(); + loadedRoutines.add(cursor.getPosition(), new Item_Workout_Routine(cursor.getString(0), true)); + + while (cursor.moveToNext()) { + loadedRoutines.add(cursor.getPosition(), new Item_Workout_Routine(cursor.getString(0), false)); + } + } + + return loadedRoutines; + } + + private ArrayList loadExercisesFromDatabase(String workoutPlan, String workoutRoutine) { + Cursor cursor = ((Activity_Main) requireContext()).databaseHelper.getWorkoutExercises(workoutPlan, workoutRoutine); + ArrayList loadedExercises = new ArrayList(); + + if (cursor.getCount() > 0) { + while (cursor.moveToNext()) { + loadedExercises.add( + cursor.getPosition(), + new Item_Workout_Exercise( + cursor.getString(0), // Title + cursor.getInt(1), // Sets + cursor.getInt(2), // Reps + cursor.getDouble(3) // Weight + ) + ); + } + } + + return loadedExercises; + } + + private void toggleFABMenu() { + if (fabOpen) { + // Close FAB-menu + fabOpen = false; + fabMain.setImageResource(R.drawable.ic_baseline_add_circle_24); + linearLayoutFABSub01.setTranslationY(0); + linearLayoutFABSub02.setTranslationY(0); + linearLayoutFABSub03.setTranslationY(0); + linearLayoutFABSub01.setVisibility(View.INVISIBLE); + linearLayoutFABSub02.setVisibility(View.INVISIBLE); + linearLayoutFABSub03.setVisibility(View.INVISIBLE); + backgroundBlur.setVisibility(View.GONE); + } else { + // Oben FAB-menu + fabOpen = true; + backgroundBlur.setVisibility(View.VISIBLE); + fabMain.setImageResource(R.drawable.ic_baseline_remove_circle_24); + linearLayoutFABSub01.setVisibility(View.VISIBLE); + linearLayoutFABSub02.setVisibility(View.VISIBLE); + linearLayoutFABSub03.setVisibility(View.VISIBLE); + linearLayoutFABSub01.animate().translationY(-170); + linearLayoutFABSub02.animate().translationY(-340); + linearLayoutFABSub03.animate().translationY(-510); + } + } + + + // Override class default methods -------------------------------------------------------------- + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Load data from database and fill lists and create adapters + + workoutPlans = loadPlansFromDatabase(); + selectedPlanIdx = 0; + + workoutRoutines = loadRoutinesFromDatabase(workoutPlans[0]); + + if (!workoutRoutines.isEmpty()) { + workoutExercises = loadExercisesFromDatabase(workoutPlans[0], workoutRoutines.get(0).getTitle()); + Log.d("uwu", "routines size: " + workoutRoutines.size()); + Log.d("uwu", "exerzises size: " + workoutExercises.size()); + } + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_workout, container, false); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + // Set up recycler-views + + sectionTitleRoutines = view.findViewById(R.id.sectionTitleRoutines); + sectionTitleExercises = view.findViewById(R.id.sectionTitleExercises); + + Spinner spinnerPlans = view.findViewById(R.id.spinnerWorkoutPlans); + spinnerPlans.setOnItemSelectedListener(this); + ArrayAdapter adapterPlans = new ArrayAdapter(getContext(), R.layout.spinner_item_purple_middle, workoutPlans); + adapterPlans.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinnerPlans.setAdapter(adapterPlans); + + recyclerViewRoutines = view.findViewById(R.id.recyclerViewRoutines); + if (!workoutRoutines.isEmpty()) { + adapterRoutines = new Adapter_Workout_Routine(workoutRoutines, this); + recyclerViewRoutines.setAdapter(adapterRoutines); + recyclerViewRoutines.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); + selectedRoutineIdx = 0; + } else { + sectionTitleRoutines.setVisibility(View.INVISIBLE); + } + + recyclerViewExercises = view.findViewById(R.id.recyclerViewExercises); + if (!workoutExercises.isEmpty()) { + adapterExercises = new Adapter_Workout_Exercise(workoutExercises, this); + recyclerViewExercises.setAdapter(adapterExercises); + recyclerViewExercises.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); + } else { + sectionTitleExercises.setVisibility(View.INVISIBLE); + } + + // FAB-Views ------------------------------------------------------------------------------- + + linearLayoutFABSub01 = view.findViewById(R.id.linearLayoutFAB01); + linearLayoutFABSub02 = view.findViewById(R.id.linearLayoutFAB02); + linearLayoutFABSub03 = view.findViewById(R.id.linearLayoutFAB03); + backgroundBlur = view.findViewById(R.id.fragmentExercisesBlur); + fabMain = view.findViewById(R.id.fabExercisesMain); + FloatingActionButton fabSub01 = view.findViewById(R.id.fabExercises01); + FloatingActionButton fabSub02 = view.findViewById(R.id.fabExercises02); + FloatingActionButton fabSub03 = view.findViewById(R.id.fabExercises03); + + // Main Button + fabMain.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + toggleFABMenu(); + } + }); + + // Background blur + backgroundBlur.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + toggleFABMenu(); + } + }); + + // Button "Add Exercise" + fabSub01.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (workoutRoutines.isEmpty()) { + Snackbar.make(view, "Please create at least one workout routine first!", Snackbar.LENGTH_SHORT).show(); + return; + } + + Intent intent = new Intent(view.getContext(), Activity_Workout_CreateEditExercise.class); + intent.putExtra("date", ((Activity_Main) requireContext()).date); + startActivity(intent); + } + }); + + // Button "Add Routine" + fabSub02.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + // Check if at least 1 plan exists, else do not open new activity + if (workoutPlans.length <= 0) { + Toast.makeText(getContext(), "You must create at least 1 workout plan first!", Toast.LENGTH_SHORT).show(); + return; + } + + // Start activity + Intent intent = new Intent(view.getContext(), Activity_Workout_EditRoutines.class); + startActivity(intent); + } + }); + + // Button "Add Plan" + fabSub03.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Intent intent = new Intent(view.getContext(), Activity_Workout_EditPlans.class); + startActivity(intent); + } + }); + + } + + + // Interface methods --------------------------------------------------------------------------- + + // Spinner Plan Methods + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long l) { + if (position == selectedPlanIdx) { + return; + } + + selectedPlanIdx = position; + + // Update routines + workoutRoutines.clear(); + if (adapterRoutines != null) { + adapterRoutines.notifyDataSetChanged(); + } + + workoutExercises.clear(); + if (adapterExercises != null) { + adapterExercises.notifyDataSetChanged(); + } + + workoutRoutines = loadRoutinesFromDatabase(workoutPlans[selectedPlanIdx]); + + if (workoutRoutines.isEmpty()) { + sectionTitleRoutines.setVisibility(View.INVISIBLE); + sectionTitleExercises.setVisibility(View.INVISIBLE); + return; + } + + adapterRoutines = new Adapter_Workout_Routine(workoutRoutines, this); + recyclerViewRoutines.setAdapter(adapterRoutines); + recyclerViewRoutines.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false)); + selectedRoutineIdx = 0; + sectionTitleRoutines.setVisibility(View.VISIBLE); + + // Updates exercises + workoutExercises = loadExercisesFromDatabase(workoutPlans[selectedPlanIdx], workoutRoutines.get(selectedRoutineIdx).getTitle()); + + if (!workoutExercises.isEmpty()) { + adapterExercises = new Adapter_Workout_Exercise(workoutExercises, this); + recyclerViewExercises.setAdapter(adapterExercises); + recyclerViewExercises.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); + sectionTitleExercises.setVisibility(View.VISIBLE); + } + } + + @Override + public void onNothingSelected(AdapterView adapterView) { + // Pass + } + + // Routine adapter methods + @Override + public void onRoutineItemClick(int itemPosition) { + if (selectedRoutineIdx == -1) { + return; + } + + if (itemPosition == selectedRoutineIdx) { + return; + } + + // Update routine-items visually + workoutRoutines.get(itemPosition).setIsSelected(true); + workoutRoutines.get(selectedRoutineIdx).setIsSelected(false); + adapterRoutines.notifyItemChanged(itemPosition); + adapterRoutines.notifyItemChanged(selectedRoutineIdx); + + selectedRoutineIdx = itemPosition; + + // Update exercises + workoutExercises.clear(); + if (adapterExercises != null) { + adapterExercises.notifyDataSetChanged(); + } + + + workoutExercises = loadExercisesFromDatabase(workoutPlans[selectedPlanIdx], workoutRoutines.get(selectedRoutineIdx).getTitle()); + + if (!workoutExercises.isEmpty()) { + adapterExercises = new Adapter_Workout_Exercise(workoutExercises, this); + recyclerViewExercises.setAdapter(adapterExercises); + recyclerViewExercises.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false)); + } + + + // adapterExercises.notifyDataSetChanged(); + } + + // Exercise adapter methods + @Override + public void onExerciseItemClick(int itemPosition) { + Intent intent = new Intent(getContext(), Activity_Workout_CreateEditExercise.class); + intent.putExtra("date", ((Activity_Main) requireContext()).date); + intent.putExtra("mode", "edit"); + intent.putExtra("planName", workoutPlans[selectedPlanIdx]); + intent.putExtra("routineName", workoutRoutines.get(selectedRoutineIdx).getTitle()); + intent.putExtra("exerciseName", workoutExercises.get(itemPosition).getTitle()); + intent.putExtra("exerciseSets", workoutExercises.get(itemPosition).getSets()); + intent.putExtra("exerciseReps", workoutExercises.get(itemPosition).getRepetitions()); + intent.putExtra("exerciseWeight", workoutExercises.get(itemPosition).getWeight()); + startActivity(intent); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Item_General_001.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Item_General_001.java new file mode 100644 index 0000000..a27c5e1 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Item_General_001.java @@ -0,0 +1,95 @@ +package com.falyrion.gymtonicapp.recyclerview; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; + +import java.util.List; + +public class Adapter_Item_General_001 extends RecyclerView.Adapter { + + /** + * This class is the recyclerview-adapter for the item item_005. + * This item contains a textview and a delete-button. + */ + + public class Viewholder extends RecyclerView.ViewHolder { + LinearLayout linearLayoutMain; + TextView textViewTitle; + ImageButton buttonRemove; + Interface_Item_Edit interfaceItemEdit; + + public Viewholder(@NonNull View itemView, Interface_Item_Edit interfaceItemEdit) { + super(itemView); + linearLayoutMain = itemView.findViewById(R.id.layoutMain); + textViewTitle = itemView.findViewById(R.id.textViewTitle); + buttonRemove = itemView.findViewById(R.id.buttonDeleteItem); + this.interfaceItemEdit = interfaceItemEdit; + } + } + + // Interface ----------------------------------------------------------------------------------- + + public interface Interface_Item_Edit { + void onItemClicked(int itemPosition); + void onButtonRemoveClicked(int itemPosition); + } + + // Constructor of this class ------------------------------------------------------------------- + + private List itemsList; + private Interface_Item_Edit interfaceItemEdit; + + public Adapter_Item_General_001(List itemsList, Interface_Item_Edit interfaceItemEdit) { + this.itemsList = itemsList; + this.interfaceItemEdit = interfaceItemEdit; + } + + // Functions for this class -------------------------------------------------------------------- + + @NonNull + @Override + public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate custom layout + View view = inflater.inflate(R.layout.recyclerview_item_general_001, parent, false); + + // Return new holder instance + return new Viewholder(view, interfaceItemEdit); + } + + @Override + public void onBindViewHolder(@NonNull Viewholder holder, int position) { + // Get the data-class based on position + Item_General_001 item = itemsList.get(position); + + // Set item views based on views and data-class + String itemTitle = item.getTitle(); + holder.textViewTitle.setText(itemTitle); // Title + holder.linearLayoutMain.setOnClickListener(view -> { + holder.interfaceItemEdit.onItemClicked(holder.getAdapterPosition()); + }); + + // Set onClick-Events + holder.buttonRemove.setOnClickListener(view -> { + holder.interfaceItemEdit.onButtonRemoveClicked(holder.getAdapterPosition()); + }); + + } + + @Override + public int getItemCount() { + return itemsList.size(); + } +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_MealPresets.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_MealPresets.java new file mode 100644 index 0000000..f8191cc --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_MealPresets.java @@ -0,0 +1,155 @@ +package com.falyrion.gymtonicapp.recyclerview; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; + +import java.util.List; + +public class Adapter_MealPresets extends RecyclerView.Adapter { + + /* + Adapter for RecyclerView in Activity_AddMeal. Used to display Item_MealPreset. + */ + + public class Viewholder extends RecyclerView.ViewHolder { + + TextView textViewMealTitle; + TextView textViewCalories; + TextView textViewAmount; + ImageButton buttonAdd; + ImageButton buttonRemove; + LinearLayout mealPresetFrame; + mealPresetItemInterface itemInterface; + + public Viewholder(@NonNull View itemView, mealPresetItemInterface itemInterface) { + super(itemView); + + textViewMealTitle = (TextView) itemView.findViewById(R.id.textRVAddMealTitle); + textViewCalories = (TextView) itemView.findViewById(R.id.textViewRVAddMealCalories); + textViewAmount = (TextView) itemView.findViewById(R.id.mealAmount); + buttonAdd = (ImageButton) itemView.findViewById(R.id.buttonRVAddMealAdd); + buttonRemove = (ImageButton) itemView.findViewById(R.id.buttonRVAddMealSubtract); + mealPresetFrame = (LinearLayout) itemView.findViewById(R.id.linearLayoutMealPreset); + + this.itemInterface = itemInterface; + } + } + + // --------------------------------------------------------------------------------------------- + // Public interface for methods called by meal-preset items + // -> Implemented in Activity_AddMeal + + public interface mealPresetItemInterface { + void onItemClick(String mealUUID); + void onAmountClick(int itemPosition); + void updateItemAmount(int itemPosition, String mealUUID, double newAmount); + } + + // --------------------------------------------------------------------------------------------- + // Constructor of this class + + private List mealPresetsList; + private mealPresetItemInterface itemInterface; + private Context context; + public Adapter_MealPresets(List mealPresetsList, mealPresetItemInterface itemInterface, Context context) { + this.mealPresetsList = mealPresetsList; + this.itemInterface = itemInterface; + this.context = context; + } + + // --------------------------------------------------------------------------------------------- + // Functions for this class + + private String convertDataToText(double value) { + // Convert given double to string. + // Check if double value has ".0" decimals. If yes cut it out. + if (value % 1 == 0) { + return String.valueOf((int) value); + } else { + return String.valueOf(value); + } + } + + @NonNull + @Override + public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate custom layout + View viewMealPreset = inflater.inflate(R.layout.recyclerview_item_mealpreset, parent, false); + + // Return new holder instance + return new Viewholder(viewMealPreset, itemInterface); + } + + @Override + public void onBindViewHolder(@NonNull Viewholder holder, int position) { + // Get the data-class based on position + Item_MealPreset mealPreset = mealPresetsList.get(position); + + // Set item views based on views and data-class + holder.textViewMealTitle.setText(mealPreset.getMealTitle()); // Title + holder.textViewCalories.setText(String.valueOf(mealPreset.getCalories())); // Calories + holder.textViewAmount.setText(convertDataToText(mealPreset.getAmount())); + + if (mealPreset.getAmount() > 0) { + holder.buttonAdd.setColorFilter(ContextCompat.getColor(context, R.color.text_middle)); + holder.buttonRemove.setColorFilter(ContextCompat.getColor(context, R.color.text_middle)); + holder.textViewAmount.setTextColor(ContextCompat.getColor(context, R.color.text_middle)); + } else { + holder.buttonAdd.setColorFilter(ContextCompat.getColor(context, R.color.text_low)); + holder.buttonRemove.setColorFilter(ContextCompat.getColor(context, R.color.text_low)); + holder.textViewAmount.setTextColor(ContextCompat.getColor(context, R.color.text_low)); + } + + + // OnClick Text View + holder.mealPresetFrame.setOnClickListener(view -> { + holder.itemInterface.onItemClick(mealPreset.getMealUUID()); + + }); + + // OnClick Button Add + holder.buttonAdd.setOnClickListener(view -> { + // Increase amount + mealPreset.setAmount(mealPreset.getAmount() + 1); + // holder.editTextAmount.setText(convertDataToText(mealPreset.getAmount())); + + holder.itemInterface.updateItemAmount(holder.getAdapterPosition(), mealPreset.getMealUUID(), mealPreset.getAmount()); + }); + + // OnClick Button Remove + holder.buttonRemove.setOnClickListener(view -> { + double currentAmount = mealPreset.getAmount(); + + // Make sure new amount is minimum 0 + double newAmount = currentAmount - 1; + if (newAmount < 0) { newAmount = 0; } + mealPreset.setAmount(newAmount); + + holder.itemInterface.updateItemAmount(holder.getAdapterPosition(), mealPreset.getMealUUID(), newAmount); + }); + + // On Edit Text + holder.textViewAmount.setOnClickListener(view -> { + holder.itemInterface.onAmountClick(holder.getAdapterPosition()); + }); + } + + @Override + public int getItemCount() { + return mealPresetsList.size(); + } +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Exercise.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Exercise.java new file mode 100644 index 0000000..867282a --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Exercise.java @@ -0,0 +1,110 @@ +package com.falyrion.gymtonicapp.recyclerview; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; + +import java.util.List; + +public class Adapter_Workout_Exercise extends RecyclerView.Adapter { + + /* + Adapter for RecyclerView in Fragment_Exercises. Used to display Item_Exercise. + */ + + public class Viewholder extends RecyclerView.ViewHolder { + TextView textViewTitle; + TextView textViewSets; + TextView textViewReps; + TextView textViewWeight; + LinearLayout linearLayoutMain; + Interface_Workout_Exercises interface_rv_exercises; + + public Viewholder(@NonNull View itemView, Interface_Workout_Exercises interface_rv_exercises) { + super(itemView); + + textViewTitle = itemView.findViewById(R.id.rvItemExerciseTitle); + textViewSets = itemView.findViewById(R.id.rvItemExerciseSets); + textViewReps = itemView.findViewById(R.id.rvItemExerciseRepetitions); + textViewWeight = itemView.findViewById(R.id.rvItemExerciseWeight); + linearLayoutMain = itemView.findViewById(R.id.rvItemExerciseMain); + + this.interface_rv_exercises = interface_rv_exercises; + } + } + + // --------------------------------------------------------------------------------------------- + // Interface + + public interface Interface_Workout_Exercises { + void onExerciseItemClick(int itemPosition); + } + + // --------------------------------------------------------------------------------------------- + // Constructor of this class + + private List exerciseList; + private Interface_Workout_Exercises interfaceWorkoutExercises; + + public Adapter_Workout_Exercise(List exerciseList, Interface_Workout_Exercises interfaceWorkoutExercises) { + this.exerciseList = exerciseList; + this.interfaceWorkoutExercises = interfaceWorkoutExercises; + } + + // --------------------------------------------------------------------------------------------- + // Functions for this class + + private String convertDataToText(double value) { + // Convert given double to string. + // Check if double value has ".0" decimals. If yes cut it out. + if (value % 1 == 0) { + return String.valueOf((int) value); + } else { + return String.valueOf(value); + } + } + + @NonNull + @Override + public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate custom layout + View viewExercise = inflater.inflate(R.layout.recylcerview_item_workout_exercise, parent, false); + + // Return new holder instance + return new Viewholder(viewExercise, interfaceWorkoutExercises); + } + + @Override + public void onBindViewHolder(@NonNull Viewholder holder, int position) { + // Get the data-class based on position + Item_Workout_Exercise excerciseItem = exerciseList.get(position); + + // Set item views based on views and data-class + holder.textViewTitle.setText(excerciseItem.getTitle()); // Title + holder.textViewSets.setText(String.valueOf(excerciseItem.getSets())); // Sets + holder.textViewReps.setText(String.valueOf(excerciseItem.getRepetitions())); // Repetitions + holder.textViewWeight.setText(convertDataToText(excerciseItem.getWeight())); // Weight + + // Set onClick-Events + holder.linearLayoutMain.setOnClickListener(view -> { + holder.interface_rv_exercises.onExerciseItemClick(holder.getAdapterPosition()); + }); + + } + + @Override + public int getItemCount() { + return exerciseList.size(); + } +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Plans.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Plans.java new file mode 100644 index 0000000..82dc0ab --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Plans.java @@ -0,0 +1,107 @@ +package com.falyrion.gymtonicapp.recyclerview; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; + +import java.util.List; + +public class Adapter_Workout_Plans extends RecyclerView.Adapter { + + /* + Adapter for RecyclerView in Fragment_Exercises. Used to display Item_Routine. + */ + + public class Viewholder extends RecyclerView.ViewHolder { + TextView textViewTitle; + LinearLayout linearLayout; + Interface_Workout_Plans interfaceWorkoutPlans; + + public Viewholder(@NonNull View itemView, Interface_Workout_Plans interfaceWorkoutPlans) { + super(itemView); + textViewTitle = itemView.findViewById(R.id.routineTitle); + linearLayout = itemView.findViewById(R.id.routineLayoutBackground); + this.interfaceWorkoutPlans = interfaceWorkoutPlans; + } + } + + // --------------------------------------------------------------------------------------------- + // Interface + + public interface Interface_Workout_Plans { + void onPlanItemClick(int itemPosition); + } + + // --------------------------------------------------------------------------------------------- + // Constructor of this class + + private List plansList; + private Interface_Workout_Plans interfaceWorkoutPlans; + + public Adapter_Workout_Plans(List plansList, Interface_Workout_Plans interfaceWorkoutPlans) { + this.plansList = plansList; + this.interfaceWorkoutPlans = interfaceWorkoutPlans; + } + + // --------------------------------------------------------------------------------------------- + // Functions for this class + + private String convertDataToText(double value) { + // Convert given double to string. + // Check if double value has ".0" decimals. If yes cut it out. + if (value % 1 == 0) { + return String.valueOf((int) value); + } else { + return String.valueOf(value); + } + } + + @NonNull + @Override + public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate custom layout + View view = inflater.inflate(R.layout.recyclerview_item_workout_routine, parent, false); + + // Return new holder instance + return new Viewholder(view, interfaceWorkoutPlans); + } + + @Override + public void onBindViewHolder(@NonNull Viewholder holder, int position) { + // Get the data-class based on position + Item_Workout_Plan planItem = plansList.get(position); + + // Set item views based on views and data-class + String planTitle = " " + planItem.getTitle().toUpperCase() + " "; + holder.textViewTitle.setText(planTitle); // Title + + // Set background color + if (planItem.getIsSelected()) { + holder.linearLayout.setBackgroundResource(R.drawable.shape_box_round_light); + } else { + holder.linearLayout.setBackgroundResource(R.drawable.shape_box_round_middle); + } + + // Set onClick-Events + holder.linearLayout.setOnClickListener(view -> { + holder.interfaceWorkoutPlans.onPlanItemClick(holder.getAdapterPosition()); + }); + + } + + @Override + public int getItemCount() { + return plansList.size(); + } +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Routine.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Routine.java new file mode 100644 index 0000000..4112b19 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Adapter_Workout_Routine.java @@ -0,0 +1,107 @@ +package com.falyrion.gymtonicapp.recyclerview; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import com.falyrion.gymtonicapp.R; + +import java.util.List; + +public class Adapter_Workout_Routine extends RecyclerView.Adapter { + + /* + Adapter for RecyclerView in Fragment_Exercises. Used to display Item_Routine. + */ + + public class Viewholder extends RecyclerView.ViewHolder { + TextView textViewTitle; + LinearLayout linearLayout; + Interface_Workout_Routine interfaceWorkoutRoutine; + + public Viewholder(@NonNull View itemView, Interface_Workout_Routine interfaceWorkoutRoutine) { + super(itemView); + textViewTitle = itemView.findViewById(R.id.routineTitle); + linearLayout = itemView.findViewById(R.id.routineLayoutBackground); + this.interfaceWorkoutRoutine = interfaceWorkoutRoutine; + } + } + + // --------------------------------------------------------------------------------------------- + // Interface + + public interface Interface_Workout_Routine { + void onRoutineItemClick(int itemPosition); + } + + // --------------------------------------------------------------------------------------------- + // Constructor of this class + + private List routineList; + private Interface_Workout_Routine interfaceWorkoutRoutine; + + public Adapter_Workout_Routine(List routineList, Interface_Workout_Routine interfaceWorkoutRoutine) { + this.routineList = routineList; + this.interfaceWorkoutRoutine = interfaceWorkoutRoutine; + } + + // --------------------------------------------------------------------------------------------- + // Functions for this class + + private String convertDataToText(double value) { + // Convert given double to string. + // Check if double value has ".0" decimals. If yes cut it out. + if (value % 1 == 0) { + return String.valueOf((int) value); + } else { + return String.valueOf(value); + } + } + + @NonNull + @Override + public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + Context context = parent.getContext(); + LayoutInflater inflater = LayoutInflater.from(context); + + // Inflate custom layout + View viewRoutine = inflater.inflate(R.layout.recyclerview_item_workout_routine, parent, false); + + // Return new holder instance + return new Viewholder(viewRoutine, interfaceWorkoutRoutine); + } + + @Override + public void onBindViewHolder(@NonNull Viewholder holder, int position) { + // Get the data-class based on position + Item_Workout_Routine routineItem = routineList.get(position); + + // Set item views based on views and data-class + String routineTitle = " " + routineItem.getTitle().toUpperCase() + " "; + holder.textViewTitle.setText(routineTitle); // Title + + // Set background color + if (routineItem.getIsSelected()) { + holder.linearLayout.setBackgroundResource(R.drawable.shape_box_round_light); + } else { + holder.linearLayout.setBackgroundResource(R.drawable.shape_box_round_middle); + } + + // Set onClick-Events + holder.linearLayout.setOnClickListener(view -> { + holder.interfaceWorkoutRoutine.onRoutineItemClick(holder.getAdapterPosition()); + }); + + } + + @Override + public int getItemCount() { + return routineList.size(); + } +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_General_001.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_General_001.java new file mode 100644 index 0000000..09e462e --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_General_001.java @@ -0,0 +1,15 @@ +package com.falyrion.gymtonicapp.recyclerview; + +public class Item_General_001 { + + private String title; + + public Item_General_001(String title) { + this.title = title; + } + + public String getTitle() { return this.title; } + + public void setTitle(String newTitle) { this.title = newTitle; } + +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_MealPreset.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_MealPreset.java new file mode 100644 index 0000000..59612cd --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_MealPreset.java @@ -0,0 +1,41 @@ +package com.falyrion.gymtonicapp.recyclerview; + +public class Item_MealPreset { + + /* + Item for Adapter_MealPreset. + */ + + private String _mealTitle; + private String _uuid; + private int _calories; + private double _amount; + + public Item_MealPreset(String mealTitle, String uuid, int calories, double amount){ + this._mealTitle = mealTitle; + this._uuid = uuid; + this._calories = calories; + this._amount = amount; + } + + public String getMealTitle() { + return this._mealTitle; + } + + public String getMealUUID() { + return this._uuid; + } + + public int getCalories() { + return this._calories; + } + + public double getAmount() { + return this._amount; + } + + public void setAmount(double newAmount) { + this._amount = newAmount; + } + +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Exercise.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Exercise.java new file mode 100644 index 0000000..bdb5ac0 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Exercise.java @@ -0,0 +1,37 @@ +package com.falyrion.gymtonicapp.recyclerview; + +public class Item_Workout_Exercise { + + /* + Item for Adapter_Workout_Exercise. + */ + + private String title; + private int sets; + private int repetitions; + private double weight; + + public Item_Workout_Exercise(String title, int sets, int repetitions, double weight) { + this.title = title; + this.sets = sets; + this.repetitions = repetitions; + this.weight = weight; + } + + public String getTitle() { + return this.title; + } + + public int getSets() { + return this.sets; + } + + public int getRepetitions() { + return this.repetitions; + } + + public double getWeight() { + return this.weight; + } + +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Plan.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Plan.java new file mode 100644 index 0000000..c6a1e47 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Plan.java @@ -0,0 +1,23 @@ +package com.falyrion.gymtonicapp.recyclerview; + +public class Item_Workout_Plan { + + /* + Item for Adapter_Workout_Plans + */ + + private String title; + private boolean isSelected; + + public Item_Workout_Plan(String title, boolean isSelected) { + this.title = title; + this.isSelected = isSelected; + } + + public String getTitle() { return this.title; } + + public boolean getIsSelected() { return this.isSelected; } + + public void setIsSelected(boolean newStatus) { this.isSelected = newStatus; } + +} diff --git a/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Routine.java b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Routine.java new file mode 100644 index 0000000..61a48e5 --- /dev/null +++ b/app/src/main/java/com/falyrion/gymtonicapp/recyclerview/Item_Workout_Routine.java @@ -0,0 +1,23 @@ +package com.falyrion.gymtonicapp.recyclerview; + +public class Item_Workout_Routine { + + /* + Item for Adapter_Workout_Routine. + */ + + private String title; + private boolean isSelected; + + public Item_Workout_Routine(String title, boolean isSelected) { + this.title = title; + this.isSelected = isSelected; + } + + public String getTitle() { return this.title; } + + public boolean getIsSelected() { return this.isSelected; } + + public void setIsSelected(boolean newStatus) { this.isSelected = newStatus; } + +} diff --git a/app/src/main/res/color/selector_nav_bar.xml b/app/src/main/res/color/selector_nav_bar.xml new file mode 100644 index 0000000..7c17e23 --- /dev/null +++ b/app/src/main/res/color/selector_nav_bar.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/ic_baseline_add_circle_24.xml b/app/src/main/res/drawable-v24/ic_baseline_add_circle_24.xml new file mode 100644 index 0000000..2bb63e6 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_add_circle_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_barchart_24.xml b/app/src/main/res/drawable-v24/ic_baseline_barchart_24.xml new file mode 100644 index 0000000..ed958c5 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_barchart_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_calendar_month_24.xml b/app/src/main/res/drawable-v24/ic_baseline_calendar_month_24.xml new file mode 100644 index 0000000..964ec03 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_calendar_month_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_dashboard_24.xml b/app/src/main/res/drawable-v24/ic_baseline_dashboard_24.xml new file mode 100644 index 0000000..a882fd8 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_dashboard_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_delete_24.xml b/app/src/main/res/drawable-v24/ic_baseline_delete_24.xml new file mode 100644 index 0000000..3c4030b --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_delete_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_expand_less_24.xml b/app/src/main/res/drawable-v24/ic_baseline_expand_less_24.xml new file mode 100644 index 0000000..1550145 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_expand_less_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_expand_more_24.xml b/app/src/main/res/drawable-v24/ic_baseline_expand_more_24.xml new file mode 100644 index 0000000..adc215c --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_expand_more_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_remove_circle_24.xml b/app/src/main/res/drawable-v24/ic_baseline_remove_circle_24.xml new file mode 100644 index 0000000..2c986ca --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_remove_circle_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_baseline_settings_24.xml b/app/src/main/res/drawable-v24/ic_baseline_settings_24.xml new file mode 100644 index 0000000..41a82ed --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_baseline_settings_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/drawable-v24/ic_dumbbell_24.xml b/app/src/main/res/drawable-v24/ic_dumbbell_24.xml new file mode 100644 index 0000000..0b41ffe --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_dumbbell_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable-v24/shape_box_round_bottom_middle.xml b/app/src/main/res/drawable-v24/shape_box_round_bottom_middle.xml new file mode 100644 index 0000000..0e99bda --- /dev/null +++ b/app/src/main/res/drawable-v24/shape_box_round_bottom_middle.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/shape_box_round_light.xml b/app/src/main/res/drawable-v24/shape_box_round_light.xml new file mode 100644 index 0000000..35ac979 --- /dev/null +++ b/app/src/main/res/drawable-v24/shape_box_round_light.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/shape_box_round_middle.xml b/app/src/main/res/drawable-v24/shape_box_round_middle.xml new file mode 100644 index 0000000..8e7edff --- /dev/null +++ b/app/src/main/res/drawable-v24/shape_box_round_middle.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/shape_box_round_pop.xml b/app/src/main/res/drawable-v24/shape_box_round_pop.xml new file mode 100644 index 0000000..51276ab --- /dev/null +++ b/app/src/main/res/drawable-v24/shape_box_round_pop.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v24/shape_nav_bar_background.xml b/app/src/main/res/drawable-v24/shape_nav_bar_background.xml new file mode 100644 index 0000000..3065659 --- /dev/null +++ b/app/src/main/res/drawable-v24/shape_nav_bar_background.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_calendar.xml b/app/src/main/res/layout/activity_calendar.xml new file mode 100644 index 0000000..4e91a82 --- /dev/null +++ b/app/src/main/res/layout/activity_calendar.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_edit_body_stats.xml b/app/src/main/res/layout/activity_edit_body_stats.xml new file mode 100644 index 0000000..eba3111 --- /dev/null +++ b/app/src/main/res/layout/activity_edit_body_stats.xml @@ -0,0 +1,504 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..0d3661e --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,35 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_meals_adddailyentry.xml b/app/src/main/res/layout/activity_meals_adddailyentry.xml new file mode 100644 index 0000000..39e197c --- /dev/null +++ b/app/src/main/res/layout/activity_meals_adddailyentry.xml @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_meals_createeditpreset.xml b/app/src/main/res/layout/activity_meals_createeditpreset.xml new file mode 100644 index 0000000..f9dc465 --- /dev/null +++ b/app/src/main/res/layout/activity_meals_createeditpreset.xml @@ -0,0 +1,1162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_meals_mealsofday.xml b/app/src/main/res/layout/activity_meals_mealsofday.xml new file mode 100644 index 0000000..d42e6f4 --- /dev/null +++ b/app/src/main/res/layout/activity_meals_mealsofday.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_workout_createeditexercise.xml b/app/src/main/res/layout/activity_workout_createeditexercise.xml new file mode 100644 index 0000000..8f7d47d --- /dev/null +++ b/app/src/main/res/layout/activity_workout_createeditexercise.xml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_workout_editplans.xml b/app/src/main/res/layout/activity_workout_editplans.xml new file mode 100644 index 0000000..8a6557c --- /dev/null +++ b/app/src/main/res/layout/activity_workout_editplans.xml @@ -0,0 +1,41 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_workout_editroutines.xml b/app/src/main/res/layout/activity_workout_editroutines.xml new file mode 100644 index 0000000..10a077c --- /dev/null +++ b/app/src/main/res/layout/activity_workout_editroutines.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_edittext.xml b/app/src/main/res/layout/dialog_edittext.xml new file mode 100644 index 0000000..bb9d2ac --- /dev/null +++ b/app/src/main/res/layout/dialog_edittext.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_nutrition.xml b/app/src/main/res/layout/fragment_nutrition.xml new file mode 100644 index 0000000..b4d1a6d --- /dev/null +++ b/app/src/main/res/layout/fragment_nutrition.xml @@ -0,0 +1,1331 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_settings.xml b/app/src/main/res/layout/fragment_settings.xml new file mode 100644 index 0000000..d9d9911 --- /dev/null +++ b/app/src/main/res/layout/fragment_settings.xml @@ -0,0 +1,162 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_workout.xml b/app/src/main/res/layout/fragment_workout.xml new file mode 100644 index 0000000..d2cac81 --- /dev/null +++ b/app/src/main/res/layout/fragment_workout.xml @@ -0,0 +1,211 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/recyclerview_item_general_001.xml b/app/src/main/res/layout/recyclerview_item_general_001.xml new file mode 100644 index 0000000..a40705c --- /dev/null +++ b/app/src/main/res/layout/recyclerview_item_general_001.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/recyclerview_item_mealeaten.xml b/app/src/main/res/layout/recyclerview_item_mealeaten.xml new file mode 100644 index 0000000..2df2ac9 --- /dev/null +++ b/app/src/main/res/layout/recyclerview_item_mealeaten.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/recyclerview_item_mealpreset.xml b/app/src/main/res/layout/recyclerview_item_mealpreset.xml new file mode 100644 index 0000000..61d167d --- /dev/null +++ b/app/src/main/res/layout/recyclerview_item_mealpreset.xml @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/recyclerview_item_workout_routine.xml b/app/src/main/res/layout/recyclerview_item_workout_routine.xml new file mode 100644 index 0000000..c317fe2 --- /dev/null +++ b/app/src/main/res/layout/recyclerview_item_workout_routine.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/recylcerview_item_workout_exercise.xml b/app/src/main/res/layout/recylcerview_item_workout_exercise.xml new file mode 100644 index 0000000..834ca73 --- /dev/null +++ b/app/src/main/res/layout/recylcerview_item_workout_exercise.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/spinner_item_purple_dark.xml b/app/src/main/res/layout/spinner_item_purple_dark.xml new file mode 100644 index 0000000..eb92bbc --- /dev/null +++ b/app/src/main/res/layout/spinner_item_purple_dark.xml @@ -0,0 +1,12 @@ + + \ No newline at end of file diff --git a/app/src/main/res/layout/spinner_item_purple_middle.xml b/app/src/main/res/layout/spinner_item_purple_middle.xml new file mode 100644 index 0000000..b7628cc --- /dev/null +++ b/app/src/main/res/layout/spinner_item_purple_middle.xml @@ -0,0 +1,12 @@ + + + diff --git a/app/src/main/res/menu/navigation_bar.xml b/app/src/main/res/menu/navigation_bar.xml new file mode 100644 index 0000000..565586a --- /dev/null +++ b/app/src/main/res/menu/navigation_bar.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..4ae7d12 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..4ae7d12 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..67b6a7c Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_background.png b/app/src/main/res/mipmap-hdpi/ic_launcher_background.png new file mode 100644 index 0000000..507577e Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..7fb0902 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..fbe4e4f Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..5c49471 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_background.png b/app/src/main/res/mipmap-mdpi/ic_launcher_background.png new file mode 100644 index 0000000..1d8dbaf Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..bb09f4d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..0cf621a Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..1ff4505 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png new file mode 100644 index 0000000..ace0f32 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..1edb936 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..3d2c2e4 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..51f56eb Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png new file mode 100644 index 0000000..4bed6a7 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..936cd40 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..6ea221a Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..21a5c58 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png new file mode 100644 index 0000000..830242a Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..03fdf75 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..29fcba6 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml new file mode 100644 index 0000000..48a2583 --- /dev/null +++ b/app/src/main/res/values-de/strings.xml @@ -0,0 +1,77 @@ + + + + Gymtonic + + + Kalorien + Kalorien [kcal] + Fett + Fett [g] + Gesättigte Fettsäuren + Gesättigte Fettsäuren [g] + Kohlenhydrate + Kohlenhydrate [g] + Zucker + Zucker [g] + Protein + Protein [g] + + Salz + Salz [g] + Ballaststoffe + Ballaststoffe [g] + Cholesterin + Cholesterin [mg] + Kreatin + Kreatin [g] + Calcium + Calcium [mg] + Eisen + Eisen [mg] + Kalium + Kalium [mg] + Magnesium + Magnesium [mg] + Mangan + Mangan [mg] + Natrium + Natrium [mg] + Phosphor + Phosphor [mg] + Zink + Zink [mg] + Vitamin A + Vitamin A [mg] + Vitamin B1 + Vitamin B1 [mg] + Vitamin B2 + Vitamin B2 [mg] + Vitamin B3 + Vitamin B3 [mg] + Vitamin B5 + Vitamin B5 [mg] + Vitamin B6 + Vitamin B6 [mg] + Vitamin B7 + Vitamin B7 [mg] + Vitamin B11 + Vitamin B11 [mg] + Vitamin B12 + Vitamin B12 [mg] + Vitamin C + Vitamin C [mg] + Vitamin E + Vitamin E [mg] + Vitamin K + Vitamin K [mg] + Vitamin H + Vitamin H [mg] + + + Heutige Übersicht + Details + Mahlzeit hinzufügen + Heutige Mahlzeiten + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..b6795e4 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,18 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..adab8fa --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,12 @@ + + + #FF000000 + #FFFFFFFF + #131929 + #1A2237 + #2A3752 + #60687F + #99A4C5 + #CDFFFFFF + #F97141 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..3d2cbea --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,77 @@ + + + Gymtonic + + + Calories + Calories [kcal] + Fat + Fat [g] + Saturated fats + Saturated fats [g] + Carbohydrates + Carbohydrates [g] + Sugar + Sugar [g] + Protein + Protein [g] + + Salt + Salt [g] + Fiber + Fiber [g] + Cholesterol + Cholesterol [mg] + Creatine + Creatine [g] + Calcium + Calcium [mg] + Iron + Iron [mg] + Potassium + Potassium [mg] + Magnesium + Magnesium [mg] + Manganese + Manganese [mg] + Sodium + Sodium [mg] + Phosphorus + Phosphorus [mg] + Zinc + Zinc [mg] + Vitamin A + Vitamin A [mg] + Vitamin B1 + Vitamin B1 [mg] + Vitamin B2 + Vitamin B2 [mg] + Vitamin B3 + Vitamin B3 [mg] + Vitamin B5 + Vitamin B5 [mg] + Vitamin B6 + Vitamin B6 [mg] + Vitamin B7 + Vitamin B7 [mg] + Vitamin B11 + Vitamin B11 [mg] + Vitamin B12 + Vitamin B12 [mg] + Vitamin C + Vitamin C [mg] + Vitamin E + Vitamin E [mg] + Vitamin K + Vitamin K [mg] + Vitamin H + Vitamin H [mg] + + + Today\'s Overview + Details + Add Meal + Todays Meals + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..48c630e --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..5c12a7a --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,19 @@ + + + + \ No newline at end of file diff --git a/app/src/test/java/com/falyrion/gymtonicapp/ExampleUnitTest.java b/app/src/test/java/com/falyrion/gymtonicapp/ExampleUnitTest.java new file mode 100644 index 0000000..aca8dd5 --- /dev/null +++ b/app/src/test/java/com/falyrion/gymtonicapp/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.falyrion.gymtonicapp; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..b0e1af8 --- /dev/null +++ b/build.gradle @@ -0,0 +1,9 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + id 'com.android.application' version '7.1.1' apply false + id 'com.android.library' version '7.1.1' apply false +} + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..dab7c28 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,21 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app"s APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..e708b1c Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..0c395e6 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon May 30 19:20:23 CEST 2022 +distributionBase=GRADLE_USER_HOME +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionPath=wrapper/dists +zipStorePath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..4f906e0 --- /dev/null +++ b/gradlew @@ -0,0 +1,185 @@ +#!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=`expr $i + 1` + done + case $i in + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=`save "$@"` + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..107acd3 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..ab0fad0 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,16 @@ +pluginManagement { + repositories { + gradlePluginPortal() + google() + mavenCentral() + } +} +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} +rootProject.name = "GymtonicApp" +include ':app'