forked from Pikernot/xDrip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
209 additions
and
22 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/eveningoutpost/dexdrip/profileeditor/BasalProfile.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,54 @@ | ||
package com.eveningoutpost.dexdrip.profileeditor; | ||
|
||
import com.eveningoutpost.dexdrip.Models.JoH; | ||
import com.eveningoutpost.dexdrip.UtilityModels.Pref; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.List; | ||
|
||
import lombok.val; | ||
|
||
import static com.eveningoutpost.dexdrip.Models.JoH.JsonStringToFloatList; | ||
|
||
// jamorham | ||
|
||
public class BasalProfile { | ||
|
||
private static final String[] PROFILE_NAMES = {"1", "2", "3", "4", "5"}; | ||
private static final String BASAL_PREFIX = "BASAL-PROFILE-"; | ||
|
||
private static String getPrefix(final String ref) { | ||
return BASAL_PREFIX + ref; | ||
} | ||
|
||
public static void save(final String ref, final List<Float> segments) { | ||
Pref.setString(getPrefix(ref), JoH.defaultGsonInstance().toJson(segments)); | ||
//android.util.Log.d("PROFILEXX", "Saved value:" + Pref.getString(getPrefix(ref), "null")); | ||
} | ||
|
||
public static List<Float> load(final String ref) { | ||
return JsonStringToFloatList(Pref.getString(getPrefix(ref), "")); | ||
} | ||
|
||
|
||
public static String getAllProfilesAsJson() { | ||
val profiles = new JSONArray(); | ||
for (val profile : PROFILE_NAMES) { | ||
val item = new JSONObject(); | ||
try { | ||
val result = Pref.getString(getPrefix(profile), null); | ||
if (result != null && result.length() > 5) { | ||
item.put(profile, result); | ||
profiles.put(item); | ||
} | ||
} catch (final JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
return profiles.length() > 0 ? profiles.toString() : null; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.