Skip to content

Commit ac7dbe5

Browse files
authored
Merge pull request #2 from kekayan/support_design_new
Support design new
2 parents b8ed222 + 669c87a commit ac7dbe5

60 files changed

Lines changed: 134 additions & 51 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/main/java/lk/paradox/kekayan/fabfit/EditprofileActivity.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import android.view.View;
1414
import android.widget.Button;
1515
import android.widget.EditText;
16-
import android.widget.TextView;
1716

1817
import com.bumptech.glide.Glide;
1918
import com.google.android.gms.tasks.OnFailureListener;
@@ -33,13 +32,10 @@
3332
import java.util.HashMap;
3433
import java.util.Map;
3534

36-
import static lk.paradox.kekayan.fabfit.fragments.SettingsFragment.DEFAULT_HEIGHT;
37-
import static lk.paradox.kekayan.fabfit.fragments.SettingsFragment.DEFAULT_WEIGHT;
38-
3935
public class EditprofileActivity extends AppCompatActivity {
4036
public static final int RC_PHOTO_PICKER = 1;
4137
//Declaration of UI elements
42-
private EditText mNameField, mAgeField, mWeightField,mHeightField;
38+
private EditText mNameField, mAgeField, mWeightField, mHeightField;
4339
//Image View
4440
//String values Of the user values
4541
private String userID;
@@ -102,6 +98,10 @@ public void onClick(View v) {
10298
});
10399
}
104100

101+
/**
102+
* Call this method to update the each textfields
103+
* and image to display first
104+
*/
105105
private void getUserInfo() {
106106
ValueEventListener listener = new ValueEventListener() {
107107
@Override
@@ -136,8 +136,11 @@ public void onCancelled(DatabaseError databaseError) {
136136
mDatabase.addValueEventListener(listener);
137137
}
138138

139+
/**
140+
* Call this method to update in firebase
141+
* if user didnt change profile it will update only others
142+
*/
139143
private void saveUserInformation() {
140-
141144
mName = mNameField.getText().toString();
142145
String mAge = mAgeField.getText().toString();
143146
String mWeight = mWeightField.getText().toString();
@@ -147,7 +150,13 @@ private void saveUserInformation() {
147150
userInfo.put("age", mAge);
148151
userInfo.put("weight", mWeight);
149152
userInfo.put("height", mHeight);
153+
Log.i("KEY", userInfo.toString());
150154
mDatabase.updateChildren(userInfo);
155+
SharedPreferences.Editor editor = getSharedPreferences("FabFit", MODE_PRIVATE).edit();
156+
editor.putInt("height", Integer.valueOf(mHeight));
157+
editor.putInt("weight", Integer.valueOf(mWeight));
158+
editor.apply();
159+
151160
if (resultUri != null) {
152161
StorageReference filePath = FirebaseStorage.getInstance().getReference().child("profile_images").child(userID);
153162
Bitmap bitmap = null;
@@ -185,13 +194,10 @@ public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
185194
});
186195

187196

188-
SharedPreferences.Editor editor = getSharedPreferences("FabFit", MODE_PRIVATE).edit();
189-
editor.putInt("height", Integer.valueOf(mHeight));
190-
editor.putInt("weight", Integer.valueOf(mWeight));
191-
editor.apply();
192197
} else {
193198
Log.i("KEY", "update eror");
194199
//finish();
200+
195201
}
196202

197203
}

app/src/main/java/lk/paradox/kekayan/fabfit/HistoryFragment.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package lk.paradox.kekayan.fabfit;
22

3-
import android.content.Context;
43
import android.content.SharedPreferences;
54
import android.graphics.Color;
65
import android.os.Bundle;
@@ -19,10 +18,14 @@
1918
import java.util.Date;
2019
import java.util.List;
2120
import java.util.Locale;
21+
import java.util.Objects;
2222

2323
import lk.paradox.kekayan.fabfit.db.Database;
2424
import lk.paradox.kekayan.fabfit.fragments.SettingsFragment;
2525

26+
import static android.content.Context.MODE_PRIVATE;
27+
import static lk.paradox.kekayan.fabfit.fragments.SettingsFragment.DEFAULT_HEIGHT;
28+
2629

2730
public class HistoryFragment extends Fragment {
2831
private boolean showSteps = true;
@@ -37,13 +40,11 @@ private void updateBars() {
3740
BarChart barChart = getView().findViewById(R.id.bargraph);
3841
if (barChart.getData().size() > 0) barChart.clearChart();
3942
int steps;
40-
double distance, stepsize = SettingsFragment.DEFAULT_STEP_SIZE;
43+
SharedPreferences prefs = Objects.requireNonNull(getActivity()).getSharedPreferences("FabFit", MODE_PRIVATE);
44+
double distance, stepsize = prefs.getInt("height", DEFAULT_HEIGHT) * 0.415;
4145
boolean stepsize_cm = true;
4246
if (!showSteps) {
4347
// load some more settings if distance is needed
44-
SharedPreferences prefs =
45-
getActivity().getSharedPreferences("FabFit", Context.MODE_PRIVATE);
46-
stepsize = Double.valueOf(prefs.getString("stepsize_value", String.valueOf(SettingsFragment.DEFAULT_STEP_SIZE)));
4748
stepsize_cm = prefs.getString("stepsize_unit", SettingsFragment.DEFAULT_STEP_UNIT)
4849
.equals("cm");
4950
}
@@ -68,7 +69,7 @@ private void updateBars() {
6869
distance /= 5280;
6970
}
7071
distance = Math.round(distance * 1000) / 1000f; // 3 decimals
71-
bm.setValue((float)distance);
72+
bm.setValue((float) distance);
7273
}
7374
barChart.addBar(bm);
7475
}

app/src/main/java/lk/paradox/kekayan/fabfit/MainActivity.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package lk.paradox.kekayan.fabfit;
22

33

4-
import android.content.Context;
54
import android.content.Intent;
65
import android.content.SharedPreferences;
76
import android.content.pm.PackageManager;
@@ -19,8 +18,6 @@
1918
import android.widget.TextView;
2019
import android.widget.Toast;
2120

22-
import java.util.Objects;
23-
2421
import lk.paradox.kekayan.fabfit.fragments.ProfileFragment;
2522
import lk.paradox.kekayan.fabfit.fragments.SettingsFragment;
2623
import lk.paradox.kekayan.fabfit.fragments.StepsFragment;
@@ -32,8 +29,8 @@
3229

3330
public class MainActivity extends AppCompatActivity {
3431

35-
private TweetsFragment tweetsFragment;
3632
private static final int TIME_INTERVAL = 2000;
33+
private TweetsFragment tweetsFragment;
3734
private TextView mTextMessage;
3835
private long mBackPressed;
3936
private FragmentManager fm;
@@ -118,18 +115,18 @@ protected void onCreate(Bundle savedInstanceState) {
118115
//start the sensorlistener service
119116
startService(new Intent(this, SensorListener.class));
120117

121-
//
118+
//check and put values to height and weight if not in shared prefrends
122119
SharedPreferences prefs = getSharedPreferences("FabFit", MODE_PRIVATE);
123-
int check=prefs.getInt("height",0);
124-
if(check<0) {
120+
int check = prefs.getInt("height", 0);
121+
if (check < 0) {
125122
SharedPreferences.Editor editor = getSharedPreferences("FabFit", MODE_PRIVATE).edit();
126123
editor.putInt("height", DEFAULT_HEIGHT);
127124
editor.putInt("weight", DEFAULT_WEIGHT);
128125
editor.apply();
129126

130127
}
131128

132-
//loading the stepsfragment as main when app launched
129+
//loading the stepsfragment as first when app launched
133130
FragmentManager fragmentManager = getSupportFragmentManager();
134131
Fragment fragment = fragmentManager.findFragmentById(R.id.frame_container);
135132

@@ -138,10 +135,13 @@ protected void onCreate(Bundle savedInstanceState) {
138135
fragmentManager.beginTransaction().add(R.id.frame_container, fragment).commit();
139136
}
140137

141-
BottomNavigationView navigation = findViewById(R.id.navigation);
142-
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
138+
bottomNavigationView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
143139
}
144140

141+
/**
142+
* Call this method to check
143+
* read stroage permission
144+
*/
145145
public boolean isReadStoragePermissionGranted() {
146146
if (Build.VERSION.SDK_INT >= 23) {
147147
if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
@@ -160,6 +160,11 @@ public boolean isReadStoragePermissionGranted() {
160160
}
161161
}
162162

163+
/**
164+
* Call this method to check
165+
* wrie stroage permission
166+
*/
167+
163168
public boolean isWriteStoragePermissionGranted() {
164169
if (Build.VERSION.SDK_INT >= 23) {
165170
if (checkSelfPermission(android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
@@ -179,5 +184,4 @@ public boolean isWriteStoragePermissionGranted() {
179184
}
180185

181186

182-
183187
}

app/src/main/java/lk/paradox/kekayan/fabfit/fragments/ProfileFragment.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.Intent;
6-
import android.net.Uri;
76
import android.os.Bundle;
87
import android.support.annotation.NonNull;
98
import android.support.annotation.Nullable;
@@ -39,11 +38,9 @@ public class ProfileFragment extends Fragment {
3938
private Button mBack, mConfirm;
4039
private String mName;
4140
private String mProfileImageUrl;
42-
private boolean imageloaded=false;
41+
private boolean imageloaded = false;
4342
//Url of the Resuts
4443
private com.mikhaellopez.circularimageview.CircularImageView mProfileImage;
45-
46-
private DatabaseReference mCustomerDatabase;
4744
private TextView mEmailField;
4845
private DatabaseReference mdatabase;
4946
private ValueEventListener listener;
@@ -69,7 +66,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
6966
editinfo.setOnClickListener(new View.OnClickListener() {
7067
@Override
7168
public void onClick(View v) {
72-
if(imageloaded){
69+
if (imageloaded) {
7370
intent = new Intent(getActivity(), EditprofileActivity.class);
7471
Objects.requireNonNull(getActivity()).startActivity(intent);
7572
getActivity().finish();
@@ -95,11 +92,12 @@ public void onClick(View v) {
9592
mEmailField.setText(FirebaseAuth.getInstance().getCurrentUser().getEmail());
9693
getUserInfo();
9794
}
95+
9896
private void getUserInfo() {
9997
if (getActivity() == null) {
10098
return;
10199
}
102-
listener = new ValueEventListener() {
100+
listener = new ValueEventListener() {
103101
@Override
104102
public void onDataChange(DataSnapshot dataSnapshot) {
105103
if (dataSnapshot.exists() && dataSnapshot.getChildrenCount() > 0) {
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
11
package lk.paradox.kekayan.fabfit.fragments;
22

3+
import android.content.SharedPreferences;
34
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
6+
import android.support.annotation.Nullable;
47
import android.support.v4.app.Fragment;
58
import android.view.LayoutInflater;
69
import android.view.View;
710
import android.view.ViewGroup;
11+
import android.widget.Button;
12+
import android.widget.EditText;
813

9-
import java.util.Locale;
14+
import java.util.Objects;
1015

1116
import lk.paradox.kekayan.fabfit.R;
1217

18+
import static android.content.Context.MODE_PRIVATE;
19+
1320

1421
public class SettingsFragment extends Fragment {
1522
public final static int DEFAULT_WEIGHT = 52;
1623
public final static int DEFAULT_HEIGHT = 173;
17-
private static double METRIC_AVG_FACTOR = 1.167185415740329;
18-
public final static int DEFAULT_GOAL = 10000;
19-
public final static double DEFAULT_STEP_SIZE =METRIC_AVG_FACTOR*DEFAULT_HEIGHT;
2024
public final static String DEFAULT_STEP_UNIT = "cm";
25+
public static int DEFAULT_GOAL = 10000;
2126

27+
//
28+
private Button save;
29+
private EditText dgoal;
2230

2331
@Override
2432
public View onCreateView(LayoutInflater inflater, ViewGroup container,
2533
Bundle savedInstanceState) {
2634
// Inflate the layout for this fragment
27-
return inflater.inflate(R.layout.fragment_settings, container, false);
35+
View v = inflater.inflate(R.layout.fragment_settings, container, false);
36+
save = v.findViewById(R.id.savegoalbtn);
37+
dgoal = v.findViewById(R.id.goaltxt);
38+
save.setOnClickListener(new View.OnClickListener() {
39+
@Override
40+
public void onClick(View view) {
41+
int goals = Integer.valueOf(String.valueOf(dgoal.getText()));
42+
SharedPreferences.Editor editor = Objects.requireNonNull(getActivity()).
43+
getSharedPreferences("FabFit", MODE_PRIVATE).edit();
44+
editor.putInt("dailygoal", goals);
45+
editor.apply();
46+
}
47+
});
48+
return v;
49+
2850
}
2951

3052

53+
@Override
54+
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
55+
super.onViewCreated(view, savedInstanceState);
56+
SharedPreferences prefs = Objects.requireNonNull(getActivity()).getSharedPreferences
57+
("FabFit", MODE_PRIVATE);
58+
int goals = prefs.getInt("dailygoal", DEFAULT_GOAL);
59+
dgoal.setText(String.valueOf(goals));
60+
}
3161
}

app/src/main/java/lk/paradox/kekayan/fabfit/fragments/StepsFragment.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ public class StepsFragment extends Fragment implements SensorEventListener {
4141
public final static NumberFormat formatter = NumberFormat.getInstance(Locale.getDefault());
4242
private static double WALKING_FACTOR = 0.57;
4343
ImageView footImage;
44+
SharedPreferences prefs;
4445
private TextView stepsView, totalView, averageView, caloriesView;
4546
private PieModel sliceGoal, sliceCurrent;
4647
private PieChart pg;
4748
private int todayOffset, total_start, goal, since_boot, total_days;
4849
private boolean showSteps = true;
49-
SharedPreferences prefs;
5050

5151
@Override
5252
public void onCreate(final Bundle savedInstanceState) {
@@ -73,7 +73,10 @@ public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup
7373
pg.addPieSlice(sliceCurrent);
7474

7575
// slice for the "missing" steps until reaching the goal
76-
sliceGoal = new PieModel("", SettingsFragment.DEFAULT_GOAL, Color.parseColor("#CC0000"));
76+
SharedPreferences prefs = Objects.requireNonNull(getActivity()).getSharedPreferences
77+
("FabFit", MODE_PRIVATE);
78+
int goals = prefs.getInt("dailygoal", SettingsFragment.DEFAULT_GOAL);
79+
sliceGoal = new PieModel("", goals, Color.parseColor("#CC0000"));
7780
pg.addPieSlice(sliceGoal);
7881

7982
pg.setOnClickListener(new View.OnClickListener() {
@@ -101,7 +104,7 @@ public void onResume() {
101104
SharedPreferences prefs =
102105
Objects.requireNonNull(getActivity()).getSharedPreferences("FabFit", MODE_PRIVATE);
103106

104-
goal = prefs.getInt("goal", SettingsFragment.DEFAULT_GOAL);
107+
goal = prefs.getInt("dailygoal", SettingsFragment.DEFAULT_GOAL);
105108
since_boot = db.getCurrentSteps(); // do not use the value from the sharedPreferences
106109
int pauseDifference = since_boot - prefs.getInt("pauseCount", since_boot);
107110

@@ -241,7 +244,7 @@ private void updatePie() {
241244
// update only every 10 steps when displaying distance
242245
SharedPreferences prefs =
243246
Objects.requireNonNull(getActivity()).getSharedPreferences("FabFit", MODE_PRIVATE);
244-
double stepsize = prefs.getInt("height",DEFAULT_HEIGHT) * 0.415;
247+
double stepsize = prefs.getInt("height", DEFAULT_HEIGHT) * 0.415;
245248
double distance_today = steps_today * stepsize;
246249
double distance_total = (total_start + steps_today) * stepsize;
247250
if (prefs.getString("stepsize_unit", SettingsFragment.DEFAULT_STEP_UNIT)
@@ -260,17 +263,16 @@ private void updatePie() {
260263
}
261264
SharedPreferences prefs =
262265
Objects.requireNonNull(getActivity()).getSharedPreferences("FabFit", MODE_PRIVATE);
263-
double stepsize = Double.valueOf(prefs.getString("stepsize_value", String.valueOf(SettingsFragment.DEFAULT_STEP_SIZE)));
264-
double distance_today = steps_today * stepsize;
265-
caloriesView.setText(formatter.format(calculateCalories( (steps_today))));
266+
267+
caloriesView.setText(formatter.format(calculateCalories((steps_today))));
266268
}
267269

268270
public double calculateCalories(int stepsCount) {
269-
SharedPreferences prefs = Objects.requireNonNull(getActivity()).getSharedPreferences("FabFit", MODE_PRIVATE);
271+
SharedPreferences prefs = Objects.requireNonNull(getActivity()).getSharedPreferences("FabFit", MODE_PRIVATE);
270272

271-
double CaloriesBurnedPerMile = WALKING_FACTOR * (prefs.getInt("weight",DEFAULT_WEIGHT) * 2.2);
273+
double CaloriesBurnedPerMile = WALKING_FACTOR * (prefs.getInt("weight", DEFAULT_WEIGHT) * 2.2);
272274
//https://fitness.stackexchange.com/a/25500
273-
double strip = prefs.getInt("height",DEFAULT_HEIGHT) * 0.415;
275+
double strip = prefs.getInt("height", DEFAULT_HEIGHT) * 0.415;
274276

275277
double stepCountMile = 160934.4 / strip;
276278

@@ -282,5 +284,4 @@ public double calculateCalories(int stepsCount) {
282284
}
283285

284286

285-
286287
}
-17.5 KB
Binary file not shown.
7.3 KB
-5.3 KB
Binary file not shown.
3.84 KB

0 commit comments

Comments
 (0)