fix objectives import/export
This commit is contained in:
parent
40aada0eb4
commit
3fb84636db
3 changed files with 70 additions and 37 deletions
|
@ -7,6 +7,7 @@ import android.support.v4.app.Fragment;
|
|||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Layout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -37,6 +38,8 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
RecyclerView recyclerView;
|
||||
LinearLayoutManager llm;
|
||||
CheckBox enableFake;
|
||||
LinearLayout fake_layout;
|
||||
TextView reset;
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -82,7 +85,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
ObjectivesPlugin.Objective o = (ObjectivesPlugin.Objective) v.getTag();
|
||||
o.started = new Date();
|
||||
updateGUI();
|
||||
objectivesPlugin.saveProgress();
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
});
|
||||
holder.verifyButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -91,7 +94,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
if (objectivesPlugin.requirementsMet(o.num).done || enableFake.isChecked()) {
|
||||
o.accomplished = new Date();
|
||||
updateGUI();
|
||||
objectivesPlugin.saveProgress();
|
||||
ObjectivesPlugin.saveProgress();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -185,11 +188,20 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
llm = new LinearLayoutManager(view.getContext());
|
||||
recyclerView.setLayoutManager(llm);
|
||||
enableFake = (CheckBox) view.findViewById(R.id.objectives_fake);
|
||||
fake_layout = (LinearLayout) view.findViewById(R.id.objectives_fake_layout);
|
||||
reset = (TextView) view.findViewById(R.id.objectives_reset);
|
||||
enableFake.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
reset.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
objectivesPlugin.initializeData();
|
||||
objectivesPlugin.saveProgress();
|
||||
updateGUI();
|
||||
}
|
||||
});
|
||||
|
||||
// Add correct translations to array after app is initialized
|
||||
objectivesPlugin.objectives.get(0).objective = MainApp.sResources.getString(R.string.objectives_0_objective);
|
||||
|
@ -216,7 +228,7 @@ public class ObjectivesFragment extends Fragment implements View.OnClickListener
|
|||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(objectivesPlugin.objectives);
|
||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(ObjectivesPlugin.objectives);
|
||||
recyclerView.setAdapter(adapter);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -16,6 +16,7 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
|
@ -130,66 +131,68 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
|||
}
|
||||
|
||||
|
||||
private void initializeData() {
|
||||
public void initializeData() {
|
||||
objectives = new ArrayList<>();
|
||||
objectives.add(new Objective(0,
|
||||
MainApp.sResources.getString(R.string.objectives_0_objective),
|
||||
MainApp.sResources.getString(R.string.objectives_0_gate),
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
1, // 1 day
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
objectives.add(new Objective(1,
|
||||
MainApp.sResources.getString(R.string.objectives_1_objective),
|
||||
MainApp.sResources.getString(R.string.objectives_1_gate),
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
7, // 7 days
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
objectives.add(new Objective(2,
|
||||
MainApp.sResources.getString(R.string.objectives_2_objective),
|
||||
MainApp.sResources.getString(R.string.objectives_2_gate),
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
0, // 0 days
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
objectives.add(new Objective(3,
|
||||
MainApp.sResources.getString(R.string.objectives_3_objective),
|
||||
MainApp.sResources.getString(R.string.objectives_3_gate),
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
5, // 5 days
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
objectives.add(new Objective(4,
|
||||
MainApp.sResources.getString(R.string.objectives_4_objective),
|
||||
MainApp.sResources.getString(R.string.objectives_4_gate),
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
1,
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
objectives.add(new Objective(5,
|
||||
MainApp.sResources.getString(R.string.objectives_5_objective),
|
||||
MainApp.sResources.getString(R.string.objectives_5_gate),
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
7,
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
objectives.add(new Objective(6,
|
||||
MainApp.sResources.getString(R.string.objectives_6_objective),
|
||||
"",
|
||||
new Date(0, 0, 0),
|
||||
new Date(0),
|
||||
1,
|
||||
new Date(0, 0, 0)));
|
||||
new Date(0)));
|
||||
}
|
||||
|
||||
public static void saveProgress() {
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
for (int num = 0; num < objectives.size(); num++) {
|
||||
Objective o = objectives.get(num);
|
||||
editor.putLong("Objectives" + num + "started", o.started.getTime());
|
||||
editor.putLong("Objectives" + num + "accomplished", o.accomplished.getTime());
|
||||
if (objectives != null) {
|
||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
|
||||
SharedPreferences.Editor editor = settings.edit();
|
||||
for (int num = 0; num < objectives.size(); num++) {
|
||||
Objective o = objectives.get(num);
|
||||
editor.putString("Objectives" + num + "started", Long.toString(o.started.getTime()));
|
||||
editor.putString("Objectives" + num + "accomplished", Long.toString(o.accomplished.getTime()));
|
||||
}
|
||||
editor.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS);
|
||||
editor.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
||||
editor.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts));
|
||||
editor.apply();
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Objectives stored");
|
||||
}
|
||||
editor.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS);
|
||||
editor.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
||||
editor.putInt("Objectives" + "manualEnacts", manualEnacts);
|
||||
editor.apply();
|
||||
if (Config.logPrefsChange)
|
||||
log.debug("Objectives stored");
|
||||
}
|
||||
|
||||
void loadProgress() {
|
||||
|
@ -197,8 +200,8 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
|||
for (int num = 0; num < objectives.size(); num++) {
|
||||
Objective o = objectives.get(num);
|
||||
try {
|
||||
o.started = new Date(settings.getLong("Objectives" + num + "started", 0));
|
||||
o.accomplished = new Date(settings.getLong("Objectives" + num + "accomplished", 0));
|
||||
o.started = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "started", "0")));
|
||||
o.accomplished = new Date(SafeParse.stringToLong(settings.getString("Objectives" + num + "accomplished", "0")));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -206,7 +209,7 @@ public class ObjectivesPlugin implements PluginBase, ConstraintsInterface {
|
|||
bgIsAvailableInNS = settings.getBoolean("Objectives" + "bgIsAvailableInNS", false);
|
||||
pumpStatusIsAvailableInNS = settings.getBoolean("Objectives" + "pumpStatusIsAvailableInNS", false);
|
||||
try {
|
||||
manualEnacts = settings.getInt("Objectives" + "manualEnacts", 0);
|
||||
manualEnacts = SafeParse.stringToInt(settings.getString("Objectives" + "manualEnacts", "0"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -9,11 +9,29 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enable fake time and progress"
|
||||
android:id="@+id/objectives_fake" />
|
||||
android:id="@+id/objectives_fake_layout"
|
||||
android:visibility="gone">
|
||||
|
||||
<CheckBox
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Enable fake time and progress"
|
||||
android:id="@+id/objectives_fake" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Reset"
|
||||
android:id="@+id/objectives_reset"
|
||||
android:textColor="#fef900"
|
||||
android:gravity="right"
|
||||
android:layout_weight="0.5"
|
||||
android:layout_marginRight="10dp" />
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/objectives_recyclerview"
|
||||
|
|
Loading…
Reference in a new issue