Skip to content

Commit

Permalink
Release 1.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
massone99 committed Jun 11, 2021
1 parent eec85b8 commit 3f48b81
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 41 deletions.
21 changes: 10 additions & 11 deletions app/src/main/java/com/app/trackit/model/db/TrackItRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.app.trackit.model.db.dao.PhotoDao;
import com.app.trackit.model.db.dao.WorkoutDao;
import com.app.trackit.ui.MainActivity;
import com.google.common.util.concurrent.ListenableFuture;

import java.util.Date;
import java.util.List;
Expand All @@ -38,7 +37,7 @@ public TrackItRepository(Application application) {
workoutDao = db.workoutDao();
photoDao = db.photoDao();
exercises = exerciseDao.getAllExercises();
workouts = workoutDao.getAll();
workouts = workoutDao.getObservableWorkouts();
// photos = photoDao.getAllByDate();
}

Expand Down Expand Up @@ -148,15 +147,6 @@ public List<PerformedExercise> getPerformancesForExercise(int exerciseId) {
return null;
}

public int getBestReps(int exerciseId) {
try {
return exerciseDao.getBestReps(exerciseId).get();
} catch (ExecutionException | InterruptedException e) {
Log.d(TAG, e.toString());
}
return 0;
}

public Set getBestSetForReps(int performedExerciseId) {
try {
return exerciseDao.getBestSetForReps(performedExerciseId).get();
Expand All @@ -183,6 +173,15 @@ public LiveData<List<Workout>> loadAllWorkouts() {
return workouts;
}

public List<Workout> getAllWorkouts() {
try {
return workoutDao.getWorkouts().get();
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
return null;
}

public List<PerformedExercise> getWorkoutExercises(int workoutId) {
try {
return exerciseDao.getExercisesFromWorkout(workoutId).get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ public interface WorkoutDao {
void editWorkout(int id);

@Query("SELECT * FROM workouts ORDER BY date DESC")
LiveData<List<Workout>> getAll();
LiveData<List<Workout>> getObservableWorkouts();

@Query("SELECT * FROM workouts ORDER BY date DESC")
ListenableFuture<List<Workout>> getWorkouts();

@Query("SELECT * FROM workouts WHERE workoutId = :id")
ListenableFuture<Workout> getWorkout(int id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,4 @@ public boolean isFavorite(Exercise exercise) {
return repository.isExerciseFavorite(exercise.getExerciseId());
}

// FIXME:
// A population method for the main exercises could be added here
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public WorkoutListViewModel(Application application) {
public LiveData<List<Workout>> getObservableWorkouts() {
return workouts;
}

public List<Workout> getWorkouts() {
return repository.getAllWorkouts();
}
}
12 changes: 8 additions & 4 deletions app/src/main/java/com/app/trackit/ui/ExercisesFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ public ExercisesFragment() {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
model = new ViewModelProvider(this).get(ExercisesViewModel.class);
model.getAllExercises().observe(this, exerciseList -> {
exerciseListAdapter.submitList(exerciseList);
exerciseListAdapter.notifyDataSetChanged();
});
}

@Nullable
Expand All @@ -55,6 +51,14 @@ public View onCreateView(@NonNull LayoutInflater inflater,
false);
rootView.setTag(TAG);

model.getAllExercises().observe(getViewLifecycleOwner(), exerciseList -> {
if (exerciseList.size() > 0) {
rootView.findViewById(R.id.exercise_helper).setVisibility(View.GONE);
}
exerciseListAdapter.submitList(exerciseList);
exerciseListAdapter.notifyDataSetChanged();
});

recyclerView = rootView.findViewById(R.id.exercises_recycler_view);
recyclerView.setHasFixedSize(true);
exerciseListAdapter = new ExerciseListAdapter(new ExerciseListAdapter.ExerciseDiff());
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/app/trackit/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// To disable the Night mode. It will be developed in the future releases
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
// To tolerate Uri exposure and share images with phone's gallery apps
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
repo = new TrackItRepository(getApplication());
Expand All @@ -68,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
alarmManager.setRepeating(
AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + (1000*60),
(AlarmManager.INTERVAL_FIFTEEN_MINUTES/15),
AlarmManager.INTERVAL_DAY,
pendingIntent);

BottomNavigationView navigationView = findViewById(R.id.bottom_navigation);
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/app/trackit/ui/ProgressFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

statsModel = new ViewModelProvider(requireActivity()).get(StatsViewModel.class);
workoutModel = new ViewModelProvider(requireActivity()).get(WorkoutViewModel.class);
workoutModel.getObservableFavorites().observe(this, exerciseList -> {
Log.d(TAG, exerciseList.toString());
chartAdapter.submitList(exerciseList);
chartAdapter.notifyDataSetChanged();
});
}

@Nullable
Expand All @@ -72,6 +67,14 @@ public View onCreateView(@NonNull LayoutInflater inflater,

View rootView = inflater.inflate(R.layout.fragment_progress, container, false);

workoutModel.getObservableFavorites().observe( getViewLifecycleOwner(), exerciseList -> {
if (exerciseList.size() > 0 ) {
rootView.findViewById(R.id.progress_helper).setVisibility(View.GONE);
}
chartAdapter.submitList(exerciseList);
chartAdapter.notifyDataSetChanged();
});

recyclerView = rootView.findViewById(R.id.progress_recycler_view);

linearLayoutManager = new LinearLayoutManager(getActivity());
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/com/app/trackit/ui/WorkoutsFragment.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.app.trackit.ui;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -15,13 +16,15 @@
import androidx.recyclerview.widget.RecyclerView;

import com.app.trackit.R;
import com.app.trackit.model.Workout;
import com.app.trackit.model.utility.Utilities;
import com.app.trackit.model.viewmodel.WorkoutListViewModel;
import com.app.trackit.ui.components.AddFab;
import com.app.trackit.ui.recycler_view.adapter.WorkoutListAdapter;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import java.util.Collections;
import java.util.List;

public class WorkoutsFragment extends Fragment implements LifecycleOwner {

Expand Down Expand Up @@ -53,12 +56,18 @@ public View onCreateView(@NonNull LayoutInflater inflater,
View rootView = inflater.inflate(R.layout.fragment_workouts, container, false);
rootView.setTag(TAG);

List<Workout> list = model.getWorkouts();

if (list.size() > 0) {
rootView.findViewById(R.id.workout_helper).setVisibility(View.GONE);
}

model.getObservableWorkouts().observe(getViewLifecycleOwner(), workouts -> {
workoutListAdapter.submitList(workouts);
workoutListAdapter.notifyDataSetChanged();
});

// FIXME: put this button inside the other fragments too
// FIXME: put this button inside the other fragments too, for a better UX
this.fab = new AddFab(
rootView.findViewById(R.id.fab_add),
rootView.findViewById(R.id.fab_add_exercise),
Expand All @@ -76,8 +85,6 @@ public View onCreateView(@NonNull LayoutInflater inflater,
workoutListAdapter = new WorkoutListAdapter(new WorkoutListAdapter.WorkoutDiff(), getActivity());
recyclerView.setAdapter(workoutListAdapter);

// Log.d(TAG, String.valueOf(MainActivity.repo.getBestSetForReps(1).getReps()));

return rootView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class WorkoutListViewHolder extends RecyclerView.ViewHolder {
private static final String TAG = "WorkoutListViewHolder";

private int workoutId;
private boolean edit;
private final MaterialTextView titleTextView;
private final MaterialTextView dateTextView;

Expand All @@ -40,7 +39,6 @@ public WorkoutListViewHolder(@NonNull View itemView) {
MaterialCardView cardView = itemView.findViewById(R.id.home_item_card_view);
cardView.setOnClickListener(v -> {
model.editWorkout();
edit = true;
Bundle bundle = new Bundle();
bundle.putBoolean("edit", true);
bundle.putInt("workoutId", workoutId);
Expand Down
28 changes: 27 additions & 1 deletion app/src/main/res/layout/fragment_exercise_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,38 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/exercise_helper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
app:cardCornerRadius="25dp"
app:cardElevation="2dp"
app:layout_constraintBottom_toTopOf="@id/exercises_recycler_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/your_exercises_text_view"
app:strokeColor="@color/whitesmoke"
app:strokeWidth="1dp">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/exercise_helper"
android:textAlignment="center"
android:textStyle="italic" />

</com.google.android.material.card.MaterialCardView>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/exercises_recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/your_exercises_text_view"/>
app:layout_constraintTop_toBottomOf="@+id/exercise_helper"/>
</androidx.constraintlayout.widget.ConstraintLayout>
34 changes: 25 additions & 9 deletions app/src/main/res/layout/fragment_photos.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,48 @@
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="@color/black" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/photos_helper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
app:cardCornerRadius="25dp"
app:cardElevation="2dp"
android:layout_below="@id/photos_title"
app:strokeColor="@color/whitesmoke"
app:strokeWidth="1dp">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/photos_helper"
android:textAlignment="center"
android:textStyle="italic" />

</com.google.android.material.card.MaterialCardView>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/grid_view"
android:layout_width="match_parent"
android:layout_height="550dp"
android:layout_below="@id/photos_title"
android:layout_height="500dp"
android:layout_below="@id/photos_helper"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:horizontalSpacing="8dp"
android:verticalSpacing="8dp" />

<!-- <ImageView
android:id="@+id/image_view"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_below="@id/photos_title"
android:rotation="90"/>-->

<Button
android:id="@+id/take_photo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Scatta una foto"/>
android:text="@string/take_a_photo"/>

</RelativeLayout>

Expand Down
25 changes: 24 additions & 1 deletion app/src/main/res/layout/fragment_progress.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,34 @@
android:textColor="@color/black"
tools:text="I tuoi progressi" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/progress_helper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
app:cardCornerRadius="25dp"
app:cardElevation="2dp"
android:layout_below="@id/progress_title"
app:strokeColor="@color/whitesmoke"
app:strokeWidth="1dp">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/progress_helper"
android:textAlignment="center"
android:textStyle="italic" />

</com.google.android.material.card.MaterialCardView>

<androidx.core.widget.NestedScrollView
android:id="@+id/nested_view_charts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/progress_title"
android:layout_below="@id/progress_helper"
android:layout_alignParentStart="true"
android:layout_marginStart="0dp"
android:layout_marginTop="3dp">
Expand Down
28 changes: 27 additions & 1 deletion app/src/main/res/layout/fragment_workouts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,32 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/workout_helper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="25dp"
android:layout_marginTop="25dp"
android:layout_marginBottom="25dp"
app:cardCornerRadius="25dp"
app:cardElevation="2dp"
app:layout_constraintBottom_toTopOf="@id/home_recycler_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/your_workouts_text_view"
app:strokeColor="@color/whitesmoke"
app:strokeWidth="1dp">

<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:text="@string/workout_helper"
android:textAlignment="center"
android:textStyle="italic" />

</com.google.android.material.card.MaterialCardView>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_recycler_view"
android:layout_width="match_parent"
Expand All @@ -26,7 +52,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/your_workouts_text_view" />
app:layout_constraintTop_toBottomOf="@+id/workout_helper" />

<include layout="@layout/fab_button"/>

Expand Down
Loading

0 comments on commit 3f48b81

Please sign in to comment.