Skip to content

Commit

Permalink
#111 Renamed Activities
Browse files Browse the repository at this point in the history
#107 Wrote Tests for Activities and Fragments
  • Loading branch information
thomcz committed Jan 31, 2017
1 parent 8f94f4c commit 493b187
Show file tree
Hide file tree
Showing 37 changed files with 941 additions and 451 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dependencies {
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile "org.robolectric:robolectric:3.2.2"
testCompile "org.robolectric:shadows-support-v4:3.0"
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/hrv/band/app/view/AbstractHRVActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import hrv.band.app.Control.HRVParameters;
import hrv.band.app.R;
import hrv.band.app.view.adapter.SectionPagerAdapter;
import hrv.band.app.view.fragment.MeasureRRFragment;
import hrv.band.app.view.fragment.MeasureValueFragment;
import hrv.band.app.view.fragment.MeasuredRRFragment;
import hrv.band.app.view.fragment.MeasuredValueFragment;

/**
* Copyright (c) 2017
Expand Down Expand Up @@ -85,8 +85,8 @@ private void setContentView() {
* Adds Fragments to this Activity.
*/
private void createFragments() {
fragments.add(MeasureValueFragment.newInstance(parameter));
fragments.add(MeasureRRFragment.newInstance(parameter));
fragments.add(MeasuredValueFragment.newInstance(parameter));
fragments.add(MeasuredRRFragment.newInstance(parameter));
addDetailsFragment(fragments);
}

Expand Down
21 changes: 12 additions & 9 deletions app/src/main/java/hrv/band/app/view/HRVMeasurementActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import hrv.band.app.R;
import hrv.band.app.storage.IStorage;
import hrv.band.app.storage.SQLite.SQLController;
import hrv.band.app.view.fragment.MeasureDetailsEditFragment;
import hrv.band.app.view.adapter.MeasurementCategoryAdapter;
import hrv.band.app.view.fragment.MeasuredDetailsEditFragment;

/**
* Copyright (c) 2017
Expand Down Expand Up @@ -37,7 +38,7 @@ protected int getTabID() {

@Override
protected void addDetailsFragment(List<Fragment> fragments) {
fragments.add(MeasureDetailsEditFragment.newInstance());
fragments.add(MeasuredDetailsEditFragment.newInstance());
}

/**
Expand All @@ -56,16 +57,18 @@ public void saveMeasurement(View view) {
* Sets the details of the actual measured and calculated HRV parameter.
*/
private void setMeasurementDetails() {
MeasureDetailsEditFragment fragment = null;
MeasuredDetailsEditFragment fragment = null;
List<Fragment> fragments = getSupportFragmentManager().getFragments();
for (int i = 0; i < fragments.size(); i++) {
if (fragments.get(i) instanceof MeasureDetailsEditFragment) {
fragment = (MeasureDetailsEditFragment) fragments.get(i);
break;
if (fragments != null) {
for (int i = 0; i < fragments.size(); i++) {
if (fragments.get(i) instanceof MeasuredDetailsEditFragment) {
fragment = (MeasuredDetailsEditFragment) fragments.get(i);
break;
}
}
}
getParameter().setRating(fragment != null ? fragment.getRating() : 0);
getParameter().setCategory(fragment != null ? fragment.getCategory() : null);
getParameter().setNote(fragment != null ? fragment.getNote() : null);
getParameter().setCategory(fragment != null ? fragment.getCategory() : MeasurementCategoryAdapter.MeasureCategory.GENERAL);
getParameter().setNote(fragment != null ? fragment.getNote() : "");
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/hrv/band/app/view/HRVValueActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import hrv.band.app.R;
import hrv.band.app.storage.IStorage;
import hrv.band.app.storage.SQLite.SQLController;
import hrv.band.app.view.fragment.MeasureDetailsFragment;
import hrv.band.app.view.fragment.MeasuredDetailsFragment;

import static hrv.band.app.view.StatisticActivity.RESULT_DELETED;

Expand Down Expand Up @@ -37,7 +37,7 @@ protected int getTabID() {

@Override
protected void addDetailsFragment(List<Fragment> fragments) {
fragments.add(MeasureDetailsFragment.newInstance(getParameter()));
fragments.add(MeasuredDetailsFragment.newInstance(getParameter()));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/hrv/band/app/view/ImprintActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private String[] getPageTitles() {
*/
public void sendFeedback(View view) {
FeedbackDialogFragment picker = new FeedbackDialogFragment();
picker.show(getFragmentManager(), "Feedback");
picker.show(getSupportFragmentManager(), "Feedback");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/hrv/band/app/view/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
} else if (id == R.id.menu_privacy) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(WEBSITE_PRIVACY_URL)));
} else if (id == R.id.menu_feedback) {
new FeedbackDialogFragment().show(getFragmentManager(), "Feedback");
new FeedbackDialogFragment().show(getSupportFragmentManager(), "Feedback");
} else if (id == R.id.menu_imprint) {
startActivity(new Intent(this, ImprintActivity.class));
} else if (id == R.id.menu_rate) {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/hrv/band/app/view/StatisticActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ protected void onCreate(Bundle savedInstanceState) {
}
}

@Override
public void onPause() {
super.onPause();
storage = null;
}

@Override
public void onStop() {
super.onStop();
storage = null;
}

/**
* Creates a fragment for each HRV value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected void onCreate(Bundle savedInstanceState) {

//int position = getIntent().getIntExtra(MainActivity.HRV_VALUE_ID, 0);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_more);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected Context getContext() {
}

@Override
protected List<Category> getCategories() {
public List<Category> getCategories() {
List<Category> categories = new ArrayList<>();
for (FeedbackCategory category : FeedbackCategory.values()) {
categories.add(new Category(category.text, category.icon));
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/hrv/band/app/view/adapter/ValueAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

import hrv.band.app.Control.HRVParameters;
import hrv.band.app.R;
import hrv.band.app.view.fragment.MeasureValueFragment;
import hrv.band.app.view.fragment.MeasuredValueFragment;

/**
* Copyright (c) 2017
* Created by Thomas Czogalik on 19.01.2017
*
* This adapter holds the hrv parameters to show in the {@link MeasureValueFragment}.
* This adapter holds the hrv parameters to show in the {@link MeasuredValueFragment}.
*/
public class ValueAdapter extends BaseAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.EditText;
import android.widget.Spinner;
Expand All @@ -24,6 +24,14 @@ public class FeedbackDialogFragment extends DialogFragment {
private static final String FEEDBACK_EMAIL = "hrvband+feedback@gmail.com";
private View view;

/**
* Returns a new instance of this fragment.
* @return a new instance of this fragment.
*/
public static FeedbackDialogFragment newInstance() {
return new FeedbackDialogFragment();
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
public class ImportFragment extends DialogFragment {

/**
* Returns a new instance of this fragment.
* @return a new instance of this fragment.
*/
public static ImportFragment newInstance() {
return new ImportFragment();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* Fragment allowing the user to set the details of a measurement.
*/
public class MeasureDetailsEditFragment extends Fragment {
public class MeasuredDetailsEditFragment extends Fragment {

/** rootView of this Fragment. **/
private View rootView;
Expand All @@ -28,8 +28,8 @@ public class MeasureDetailsEditFragment extends Fragment {
* Returns a new instance of this fragment.
* @return a new instance of this fragment.
*/
public static MeasureDetailsEditFragment newInstance() {
return new MeasureDetailsEditFragment();
public static MeasuredDetailsEditFragment newInstance() {
return new MeasuredDetailsEditFragment();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
*
* Fragment showing the details of a measurement.
*/
public class MeasureDetailsFragment extends Fragment {
public class MeasuredDetailsFragment extends Fragment {

/**
* Returns a new instance of this fragment.
* @param parameter the hrv parameter to get details from.
* @return a new instance of this fragment.
*/
public static MeasureDetailsFragment newInstance(HRVParameters parameter) {
MeasureDetailsFragment fragment = new MeasureDetailsFragment();
public static MeasuredDetailsFragment newInstance(HRVParameters parameter) {
MeasuredDetailsFragment fragment = new MeasuredDetailsFragment();
Bundle args = new Bundle();
args.putParcelable(MainActivity.HRV_VALUE, parameter);
fragment.setArguments(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* Fragment showing the rr intervals of a measurement.
*/
public class MeasureRRFragment extends Fragment {
public class MeasuredRRFragment extends Fragment {

/** The chart showing rr intervals **/
private ColumnChartView mChart;
Expand All @@ -41,8 +41,8 @@ public class MeasureRRFragment extends Fragment {
* @param parameter the hrv parameter to get rr intervals from.
* @return a new instance of this fragment.
*/
public static MeasureRRFragment newInstance(HRVParameters parameter) {
MeasureRRFragment fragment = new MeasureRRFragment();
public static MeasuredRRFragment newInstance(HRVParameters parameter) {
MeasuredRRFragment fragment = new MeasuredRRFragment();
Bundle args = new Bundle();
args.putParcelable(MainActivity.HRV_VALUE, parameter);
fragment.setArguments(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
*
* Fragment showing the hrv values from a measurement.
*/
public class MeasureValueFragment extends Fragment {
public class MeasuredValueFragment extends Fragment {

/**
* Returns a new instance of this fragment.
* @param parameter the hrv parameter to get rr intervals from.
* @return a new instance of this fragment.
*/
public static MeasureValueFragment newInstance(HRVParameters parameter) {
MeasureValueFragment fragment = new MeasureValueFragment();
public static MeasuredValueFragment newInstance(HRVParameters parameter) {
MeasuredValueFragment fragment = new MeasuredValueFragment();
Bundle args = new Bundle();
args.putParcelable(MainActivity.HRV_VALUE, parameter);
fragment.setArguments(args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
MeasurementClickListener clickListener = new MeasurementClickListener(this);

progressBar.setOnClickListener(clickListener);
connectToBandFAB.setOnClickListener(clickListener);
connectToAntPlusFAB.setOnClickListener(clickListener);
disconnectDevices.setOnClickListener(clickListener);
if (connectToBandFAB != null) {
connectToBandFAB.setOnClickListener(clickListener);
}
if (connectToAntPlusFAB != null) {
connectToAntPlusFAB.setOnClickListener(clickListener);
}
if (disconnectDevices != null) {
disconnectDevices.setOnClickListener(clickListener);
}

setProgressBarSize();

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_hrv_measurement.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:id="@+id/fab_save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_statistic.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:id="@+id/fab_calender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_value_description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<include layout="@layout/content_value_description" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:id="@+id/fab_more"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
Expand Down
Loading

0 comments on commit 493b187

Please sign in to comment.