Skip to content

ClickCopyPaste/HealthTracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💪 HealthTracker Android App

A full-featured health & fitness tracking Android application built with Java, Firebase, and the Gemini AI API — inspired by HealthifyMe.


✨ Features

Feature Details
🔐 Authentication Email/Password + Google Sign-In via Firebase Auth
👤 User Profiles Onboarding wizard, BMR/TDEE auto-calculation
🍽 Food Logging Meal tracking with full macro breakdown
🤖 AI Food Scan Photo or gallery image → Gemini auto-detects food & nutrition
🔍 Food Search Type a food name → Gemini returns nutrition info
💪 Workout Logging Exercises, sets, reps, weight, duration, calories burned
📊 Daily Dashboard Calorie ring, macro bars, water tracker, workout summary
📈 Progress Charts 7/14/30-day calorie trend, macro bar chart, workout duration
☁️ Real-time Sync Firestore real-time listeners — data never lost
🗃 Offline-ready Firestore offline persistence built-in

🚀 Setup Guide

1. Firebase Project

  1. Go to Firebase Console and create a new project.
  2. Add an Android app with package name: com.healthtracker
  3. Download google-services.json and place it at:
    app/google-services.json
    
  4. Enable Authentication → Sign-in methods:
    • Email/Password ✅
    • Google ✅ (copy the Web Client ID — you'll need it)
  5. Enable Cloud Firestore → Start in production mode
  6. Deploy Firestore security rules from firestore.rules

2. Google Sign-In

In app/src/main/res/values/strings.xml, replace:

<string name="default_web_client_id">YOUR_WEB_CLIENT_ID_HERE</string>

with your actual Web Client ID from Firebase Console → Authentication → Google → Web SDK configuration.

3. Gemini API Key

  1. Get a free key at Google AI Studio
  2. Add it to your local.properties file (never commit this file!):
    GEMINI_API_KEY=AIzaSy...your_key_here
    
    The build.gradle reads it automatically via BuildConfig.GEMINI_API_KEY.

4. Firestore Indexes

Some queries require composite indexes. Firestore will show error logs with direct links to create them. Create indexes for:

  • food_entries: userId ASC + dateString ASC + createdAt ASC
  • workout_entries: userId ASC + dateString ASC
  • daily_summaries: userId ASC + dateString ASC

5. Add Jitpack (for MPAndroidChart)

In your root build.gradle, add Jitpack to allprojects.repositories:

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }  // ← ADD THIS
    }
}

📁 Project Structure

app/src/main/java/com/healthtracker/
├── activities/
│   ├── SplashActivity.java          # Entry point
│   ├── LoginActivity.java           # Email + Google auth
│   ├── RegisterActivity.java        # New account creation
│   ├── OnboardingActivity.java      # 3-step profile setup
│   ├── MainActivity.java            # Bottom nav host
│   ├── FoodLogActivity.java         # Log food + AI scan
│   └── WorkoutLogActivity.java      # Log workout + exercises
├── fragments/
│   ├── DashboardFragment.java       # Home screen
│   ├── FoodFragment.java            # Food log list
│   ├── WorkoutFragment.java         # Workout list
│   ├── ProgressFragment.java        # Charts & stats
│   └── ProfileFragment.java         # User profile
├── models/
│   ├── User.java                    # User + BMR/TDEE calc
│   ├── FoodEntry.java               # Meal entry
│   ├── WorkoutEntry.java            # Workout session
│   ├── Exercise.java                # Exercise + ExerciseSet
│   └── DailySummary.java            # Aggregated daily data
├── repositories/
│   ├── FirebaseRepository.java      # All Firestore operations
│   └── GeminiRepository.java        # Gemini Vision API calls
├── viewmodels/
│   └── DashboardViewModel.java      # LiveData + business logic
└── adapters/
    ├── FoodEntryAdapter.java        # RecyclerView for food
    ├── WorkoutEntryAdapter.java     # RecyclerView for workouts
    └── ExerciseAdapter.java         # Exercises + set rows

🏗 Architecture

UI (Activities/Fragments)
        ↓ observes LiveData
ViewModel (DashboardViewModel)
        ↓ calls
Repositories (FirebaseRepository, GeminiRepository)
        ↓ reads/writes
Firebase Firestore + Gemini REST API
  • MVVM pattern with LiveData for reactive UI updates
  • Real-time listeners via addSnapshotListener — dashboard updates instantly on any device
  • Firestore transactions for atomic daily summary updates (no race conditions)
  • Gemini 1.5 Flash for fast, cost-effective food image recognition

📊 Firestore Data Schema

users/{uid}
  - name, email, age, weightKg, heightCm
  - gender, activityLevel, goal
  - dailyCalorieGoal, dailyProteinGoalG, dailyCarbGoalG, dailyFatGoalG

food_entries/{autoId}
  - userId, foodName, mealType, dateString
  - calories, proteinG, carbsG, fatG, fiberG, sugarG, sodiumMg
  - servingSize, servingUnit, aiGenerated

workout_entries/{autoId}
  - userId, workoutName, workoutType, dateString
  - durationMinutes, caloriesBurned, intensityLevel
  - exercises: [ { name, category, sets: [{setNumber, weightKg, reps}] } ]

daily_summaries/{uid_YYYY-MM-DD}
  - userId, dateString
  - totalCaloriesConsumed, totalCaloriesBurned
  - totalProteinG, totalCarbsG, totalFatG
  - calorieGoal, workoutCount, workoutMinutes, waterLitres

🔧 Dependencies

Library Purpose
Firebase Auth User authentication
Firebase Firestore Real-time cloud database
Google Play Services Auth Google Sign-In
Gemini 1.5 Flash API AI food image recognition
MPAndroidChart Progress charts
Glide Image loading
CircleImageView Profile picture
Material Components 3 UI components
OkHttp + Gson HTTP client for Gemini
Room Local caching (optional extension)

⚡ Quick Calorie Estimation

The app uses the Mifflin-St Jeor equation for BMR and adjusts for activity level (TDEE):

  • Sedentary → ×1.2
  • Light → ×1.375
  • Moderate → ×1.55
  • Active → ×1.725
  • Very Active → ×1.9

Goals adjust TDEE:

  • Lose Weight: TDEE − 500 cal
  • Maintain: TDEE
  • Gain Muscle: TDEE + 300 cal

📱 Minimum Requirements

  • Android 8.0 (API 26) or higher
  • Internet connection for Firebase + Gemini
  • Camera permission for AI food scanning

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors