Skip to content

Commit

Permalink
Improvement of physical activity detail screen UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasrafael committed Jan 29, 2020
1 parent 9410106 commit 87a4b13
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package br.edu.uepb.nutes.ocariot.data.model.ocariot;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.Keep;
import androidx.annotation.NonNull;

Expand All @@ -16,7 +19,7 @@
* @author Copyright (c) 2018, NUTES/UEPB
*/
@Keep
public class Child extends User implements Comparable<Child> {
public class Child extends User implements Parcelable, Comparable<Child> {
@SerializedName("gender")
private String gender;

Expand All @@ -40,6 +43,26 @@ public Child(String username, String password) {
super(username, password);
}

protected Child(Parcel in) {
gender = in.readString();
age = in.readString();
lastSync = in.readString();
fitBitAccess = in.readParcelable(UserAccess.class.getClassLoader());
fitbitStatus = in.readString();
}

public static final Creator<Child> CREATOR = new Creator<Child>() {
@Override
public Child createFromParcel(Parcel in) {
return new Child(in);
}

@Override
public Child[] newArray(int size) {
return new Child[size];
}
};

public String getGender() {
return gender;
}
Expand Down Expand Up @@ -113,4 +136,18 @@ public String toString() {
public int compareTo(Child o) {
return super.getUsername().compareToIgnoreCase(o.getUsername());
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(gender);
dest.writeString(age);
dest.writeString(lastSync);
dest.writeParcelable(fitBitAccess, flags);
dest.writeString(fitbitStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import butterknife.ButterKnife;
import io.reactivex.disposables.CompositeDisposable;
import retrofit2.HttpException;
import timber.log.Timber;

import static android.view.inputmethod.InputMethodManager.HIDE_NOT_ALWAYS;

Expand Down Expand Up @@ -227,7 +228,7 @@ private void getFitBitAppData() {
.doAfterTerminate(this::openMainActivity)
.subscribe(
fitBitAppData -> appPref.addFitbitAppData(fitBitAppData),
err -> alertMessage.handleError(err)
Timber::e
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package br.edu.uepb.nutes.ocariot.view.ui.activity;

import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
Expand All @@ -9,16 +10,19 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Locale;

import br.edu.uepb.nutes.ocariot.R;
import br.edu.uepb.nutes.ocariot.data.model.ocariot.ActivityLevel;
import br.edu.uepb.nutes.ocariot.data.model.ocariot.Child;
import br.edu.uepb.nutes.ocariot.data.model.ocariot.PhysicalActivity;
import br.edu.uepb.nutes.ocariot.data.repository.local.pref.AppPreferencesHelper;
import br.edu.uepb.nutes.ocariot.utils.DateUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import timber.log.Timber;

/**
* A fragment to see the details of a physical physicalActivity.
Expand All @@ -31,9 +35,6 @@ public class PhysicalActivityDetail extends AppCompatActivity {
@BindView(R.id.toolbar)
Toolbar mToolbar;

@BindView(R.id.activity_date_tv)
TextView dateStartTextView;

@BindView(R.id.activity_date_start_details_tv)
TextView dateStartDetailsTextView;

Expand All @@ -52,18 +53,31 @@ public class PhysicalActivityDetail extends AppCompatActivity {
@BindView(R.id.activity_calories_min_tv)
TextView caloriesMinuteTextView;

@BindView(R.id.activity_title_level_sedentary_tv)
@BindView(R.id.sedentary_Level_value_tv)
TextView sedentaryTextView;

@BindView(R.id.activity_title_level_fairly_tv)
@BindView(R.id.fairly_Level_value_tv)
TextView fairlyTextView;

@BindView(R.id.activity_title_level_lightly_tv)
@BindView(R.id.lightly_Level_value_tv)
TextView lightlyTextView;

@BindView(R.id.activity_title_level_very_tv)
@BindView(R.id.very_Level_value_tv)
TextView veryTextView;

@BindView(R.id.sedentary_Level_tv)
TextView sedentaryBarTextView;

@BindView(R.id.fairly_Level_tv)
TextView fairlyBarTextView;

@BindView(R.id.lightly_Level_tv)
TextView lightlyBarTextView;

@BindView(R.id.very_Level_tv)
TextView veryBarTextView;


@BindView(R.id.hr_avg_tv)
TextView avgHeartRate;

Expand All @@ -77,7 +91,7 @@ public class PhysicalActivityDetail extends AppCompatActivity {
RelativeLayout boxHRZones;

private PhysicalActivity physicalActivity;
private AppPreferencesHelper appPref;
private Child childSeelcted;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -86,7 +100,7 @@ public void onCreate(Bundle savedInstanceState) {
ButterKnife.bind(this);
setSupportActionBar(mToolbar);

appPref = AppPreferencesHelper.getInstance();
childSeelcted = AppPreferencesHelper.getInstance().getLastSelectedChild();

if (getIntent() != null) {
physicalActivity = getIntent().getParcelableExtra(ACTIVITY_DETAIL);
Expand All @@ -109,24 +123,55 @@ private void populateLevels(List<ActivityLevel> levels) {
sedentaryTextView.setVisibility(View.VISIBLE);
fairlyTextView.setVisibility(View.VISIBLE);
lightlyTextView.setVisibility(View.VISIBLE);
sedentaryTextView.setText(getString(R.string.level_sedentary, 0));
lightlyTextView.setText(getString(R.string.level_lightly, 0));
fairlyTextView.setText(getString(R.string.level_fairly, 0));
veryTextView.setText(getString(R.string.level_very, 0));

DecimalFormat df = new DecimalFormat("#");

float total = 0;
int durationMax = Integer.MIN_VALUE;
for (ActivityLevel level : levels) {
int duration = level.getDuration() / 60000;
total += duration;
if (duration > durationMax) durationMax = duration;
}
if (total == 0) return;

int offsetBase = 500;
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
if (displaymetrics.widthPixels <= 768) offsetBase = 400;

for (ActivityLevel activityLevel : levels) {
if (activityLevel.getDuration() == 0) continue;

int duration = activityLevel.getDuration() / 60000;
double percent = (duration / total) * 100;

int widthBar = (duration * (offsetBase / durationMax)) + 50;

switch (activityLevel.getName()) {
case ActivityLevel.SEDENTARY_LEVEL:
sedentaryTextView.setText(getResources().getString(
R.string.level_sedentary, activityLevel.getDuration() / 60000));
break;
case ActivityLevel.FAIRLY_LEVEL:
fairlyTextView.setText(getResources().getString(
R.string.level_fairly, activityLevel.getDuration() / 60000));
sedentaryTextView.setText(getString(R.string.level_sedentary, duration));
sedentaryBarTextView.setText(df.format(percent).concat("%"));
sedentaryBarTextView.getLayoutParams().width = widthBar;
break;
case ActivityLevel.LIGHTLY_LEVEL:
lightlyTextView.setText(getResources().getString(
R.string.level_lightly, activityLevel.getDuration() / 60000));
lightlyTextView.setText(getString(R.string.level_lightly, duration));
lightlyBarTextView.setText(df.format(percent).concat("%"));
lightlyBarTextView.getLayoutParams().width = widthBar;
break;
case ActivityLevel.FAIRLY_LEVEL:
fairlyTextView.setText(getString(R.string.level_fairly, duration));
fairlyBarTextView.setText(df.format(percent).concat("%"));
fairlyBarTextView.getLayoutParams().width = widthBar;
break;
case ActivityLevel.VERY_LEVEL:
veryTextView.setText(getResources().getString(
R.string.level_very, activityLevel.getDuration() / 60000));
veryTextView.setText(getString(R.string.level_very, duration));
veryBarTextView.setText(df.format(percent).concat("%"));
veryBarTextView.getLayoutParams().width = widthBar;
break;
default:
break;
Expand All @@ -135,8 +180,6 @@ private void populateLevels(List<ActivityLevel> levels) {
}

private void populateView(PhysicalActivity a) {
dateStartTextView.setText(DateUtils.convertDateTimeUTCToLocale(a.getStartTime(),
getResources().getString(R.string.date_format1), null));
dateStartDetailsTextView.setText(DateUtils.convertDateTimeUTCToLocale(a.getStartTime(),
getResources().getString(R.string.date_time_abb3), null));

Expand Down Expand Up @@ -185,6 +228,6 @@ private void initToolbar() {
mActionBar.setDisplayShowTitleEnabled(true);
mActionBar.setHomeAsUpIndicator(R.drawable.ic_close_dark);
mActionBar.setTitle(physicalActivity.getName());
mActionBar.setSubtitle(appPref.getLastSelectedChild().getUsername());
mActionBar.setSubtitle(childSeelcted.getUsername());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public LoginFitBit(Context context) {
* Initialize settings to obtain authorization code.
*/
private void initConfig() {
if (appPref.getFitbitAppData() == null || appPref.getFitbitAppData().getClientId() == null
|| appPref.getFitbitAppData().getClientSecret() == null) return;

String clientId = appPref.getFitbitAppData().getClientId();
clientSecret = appPref.getFitbitAppData().getClientSecret();

Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/back_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
<corners android:radius="4dp" />
</shape>
Binary file added app/src/main/res/drawable/step.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 87a4b13

Please sign in to comment.