-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced mvp to main activity and extracted some nested classes
- Loading branch information
Showing
62 changed files
with
578 additions
and
4,537 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
app/src/main/java/hrv/band/app/device/ConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,77 @@ | ||
package hrv.band.app.device; | ||
|
||
import android.app.Activity; | ||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
import android.support.annotation.NonNull; | ||
|
||
import hrv.band.app.device.antplus.AntPlusRRDataDevice; | ||
import hrv.band.app.device.msband.MSBandRRIntervalDevice; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas Czogalik on 23.04.2017 | ||
*/ | ||
public class ConnectionManager { | ||
private Activity activity; | ||
private SharedPreferences sharedPreferences; | ||
|
||
private static final String SELECTED_DEVICE_ID = "selected_device_id"; | ||
|
||
public ConnectionManager(Activity activity) { | ||
this.activity = activity; | ||
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity); | ||
} | ||
|
||
/** | ||
* Connects to ms band. | ||
*/ | ||
public HRVRRIntervalDevice connectToMSBand() { | ||
setDevice(Device.MSBAND); | ||
return connectToIntervalDevice(); | ||
} | ||
|
||
@NonNull | ||
private HRVRRIntervalDevice connectToIntervalDevice() { | ||
HRVRRIntervalDevice hrvRRIntervalDevice = getDevice(); | ||
hrvRRIntervalDevice.connect(); | ||
return hrvRRIntervalDevice; | ||
} | ||
|
||
/** | ||
* Connects to ant device. | ||
*/ | ||
public HRVRRIntervalDevice connectToAnt() { | ||
setDevice(Device.ANT); | ||
return connectToIntervalDevice(); | ||
} | ||
|
||
/** | ||
* Disconnects connected device. | ||
*/ | ||
public HRVRRIntervalDevice disconnectDevices(HRVRRIntervalDevice hrvRRIntervalDevice) { | ||
setDevice(Device.NONE); | ||
if (hrvRRIntervalDevice != null) { | ||
hrvRRIntervalDevice.notifyDeviceStatusChanged(HRVDeviceStatus.DISCONNECTED); | ||
} | ||
return null; | ||
} | ||
|
||
public HRVRRIntervalDevice getDevice() { | ||
Device device = Device.values()[sharedPreferences.getInt(SELECTED_DEVICE_ID, 0)]; | ||
switch (device) { | ||
case MSBAND: | ||
return new MSBandRRIntervalDevice(activity); | ||
case ANT: | ||
return new AntPlusRRDataDevice(activity); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
private void setDevice(Device device) { | ||
SharedPreferences.Editor prefsEditor = sharedPreferences.edit(); | ||
prefsEditor.putInt(SELECTED_DEVICE_ID, device.ordinal()); | ||
prefsEditor.apply(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,12 @@ | ||
package hrv.band.app.device; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas on 23.04.2017. | ||
* | ||
* Possible devices the user can select. | ||
*/ | ||
|
||
public enum Device { | ||
NONE, MSBAND, ANT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/hrv/band/app/ui/presenter/IMainPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,11 @@ | ||
package hrv.band.app.ui.presenter; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas on 23.04.2017. | ||
*/ | ||
|
||
public interface IMainPresenter { | ||
boolean agreedToDisclaimer(); | ||
void handleNavBar(int id); | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/hrv/band/app/ui/presenter/IMeasuringPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,17 @@ | ||
package hrv.band.app.ui.presenter; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import hrv.band.app.model.Measurement; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas Czogalik on 23.04.2017 | ||
*/ | ||
|
||
public interface IMeasuringPresenter { | ||
int getDuration(); | ||
|
||
Measurement createMeasurement(List<Double> rrInterval, Date time); | ||
} |
66 changes: 66 additions & 0 deletions
66
app/src/main/java/hrv/band/app/ui/presenter/MainPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,66 @@ | ||
package hrv.band.app.ui.presenter; | ||
|
||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
import hrv.band.app.R; | ||
import hrv.band.app.ui.view.activity.IMainView; | ||
import hrv.band.app.ui.view.activity.ImprintActivity; | ||
import hrv.band.app.ui.view.activity.IntroActivity; | ||
import hrv.band.app.ui.view.activity.SettingsActivity; | ||
import hrv.band.app.ui.view.activity.WebActivity; | ||
import hrv.band.app.ui.view.fragment.DisclaimerDialogFragment; | ||
|
||
import static hrv.band.app.ui.view.activity.web.WebsiteUrls.WEBSITE_PRIVACY_URL; | ||
import static hrv.band.app.ui.view.activity.web.WebsiteUrls.WEBSITE_URL; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas on 23.04.2017. | ||
*/ | ||
|
||
public class MainPresenter implements IMainPresenter { | ||
private IMainView mainView; | ||
|
||
public MainPresenter(IMainView mainView) { | ||
this.mainView = mainView; | ||
} | ||
|
||
@Override | ||
public boolean agreedToDisclaimer() { | ||
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mainView.getMainActivity()); | ||
return sharedPreferences.getBoolean(DisclaimerDialogFragment.DISCLAIMER_AGREEMENT, false); | ||
} | ||
|
||
@Override | ||
public void handleNavBar(int id) { | ||
switch (id) { | ||
case R.id.menu_help: | ||
mainView.startActivity(IntroActivity.class); | ||
break; | ||
case R.id.menu_website: | ||
mainView.startActivity(WebActivity.class, WebActivity.WEBSITE_URL_ID, WEBSITE_URL); | ||
break; | ||
case R.id.menu_share: | ||
mainView.openShareIntent(); | ||
break; | ||
case R.id.menu_privacy: | ||
mainView.startActivity(WebActivity.class, WebActivity.WEBSITE_URL_ID, WEBSITE_PRIVACY_URL); | ||
break; | ||
case R.id.menu_feedback: | ||
mainView.startFeedbackDialog(); | ||
break; | ||
case R.id.menu_imprint: | ||
mainView.startActivity(ImprintActivity.class); | ||
break; | ||
case R.id.menu_rate: | ||
mainView.rateApp(); | ||
break; | ||
case R.id.menu_Settings: | ||
mainView.startActivity(SettingsActivity.class); | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/src/main/java/hrv/band/app/ui/presenter/MeasuringPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,49 @@ | ||
package hrv.band.app.ui.presenter; | ||
|
||
import android.content.SharedPreferences; | ||
import android.preference.PreferenceManager; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import common.ArrayUtils; | ||
import hrv.RRData; | ||
import hrv.band.app.model.Measurement; | ||
import hrv.band.app.ui.view.fragment.IMeasuringView; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas Czogalik on 23.04.2017 | ||
*/ | ||
|
||
public class MeasuringPresenter implements IMeasuringPresenter { | ||
private SharedPreferences sharedPreferences; | ||
|
||
private static final String RECORDING_LENGTH_ID = "recording_length"; | ||
|
||
|
||
public MeasuringPresenter(IMeasuringView measuringView) { | ||
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(measuringView.getParentActivity()); | ||
} | ||
|
||
@Override | ||
public int getDuration() { | ||
//TODO: int statt string | ||
String durationPrefVal = sharedPreferences.getString(RECORDING_LENGTH_ID, "90"); | ||
return Integer.parseInt(durationPrefVal) * 1000; | ||
} | ||
|
||
@Override | ||
public Measurement createMeasurement(List<Double> rrInterval, Date time) { | ||
//start calculation | ||
double[] rrArray = convertListToDouble(rrInterval); | ||
|
||
RRData.createFromRRInterval(rrArray, units.TimeUnit.SECOND); | ||
Measurement.MeasurementBuilder measurementBuilder = Measurement.from(time, rrArray); | ||
return measurementBuilder.build(); | ||
} | ||
|
||
private double[] convertListToDouble(List<Double> doubles) { | ||
return ArrayUtils.toPrimitiveIgnoreNull(doubles.toArray(new Double[0])); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/hrv/band/app/ui/view/activity/IMainView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,25 @@ | ||
package hrv.band.app.ui.view.activity; | ||
|
||
import android.app.Activity; | ||
|
||
/** | ||
* Copyright (c) 2017 | ||
* Created by Thomas on 23.04.2017. | ||
*/ | ||
|
||
public interface IMainView { | ||
void startActivity(Class<? extends Activity> activity); | ||
|
||
void startActivity(Class<? extends Activity> activity, String extraId, String extra); | ||
|
||
void startFeedbackDialog(); | ||
|
||
Activity getMainActivity(); | ||
|
||
void openShareIntent(); | ||
|
||
void rateApp(); | ||
|
||
void stopMeasuring(); | ||
|
||
} |
Oops, something went wrong.