This commit is contained in:
Milos Kozak 2018-08-20 14:46:20 +02:00
commit e9d7a917d2
2 changed files with 16 additions and 19 deletions

View file

@ -100,7 +100,7 @@ public class CareportalFragment extends SubscriberFragment implements View.OnCli
noProfileView = view.findViewById(R.id.profileview_noprofile); noProfileView = view.findViewById(R.id.profileview_noprofile);
butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons); butonsLayout = (LinearLayout) view.findViewById(R.id.careportal_buttons);
ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile(); ProfileStore profileStore = MainApp.getConfigBuilder().getActiveProfileInterface() != null ? MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() : null;
if (profileStore == null) { if (profileStore == null) {
noProfileView.setVisibility(View.VISIBLE); noProfileView.setVisibility(View.VISIBLE);
butonsLayout.setVisibility(View.GONE); butonsLayout.setVisibility(View.GONE);

View file

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.graphics.Paint; import android.graphics.Paint;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -19,28 +20,27 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.Common.SubscriberFragment; import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.FabricPrivacy; import info.nightscout.utils.FabricPrivacy;
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload; import info.nightscout.utils.T;
/** /**
* Created by mike on 16.10.2017. * Created by mike on 16.10.2017.
*/ */
public class BGSourceFragment extends SubscriberFragment { public class BGSourceFragment extends SubscriberFragment {
private static Logger log = LoggerFactory.getLogger(BGSourceFragment.class);
RecyclerView recyclerView; RecyclerView recyclerView;
Profile profile; String units = Constants.MGDL;
final long MILLS_TO_THE_PAST = 12 * 60 * 60 * 1000L; final long MILLS_TO_THE_PAST = T.hours(12).msecs();
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -57,7 +57,8 @@ public class BGSourceFragment extends SubscriberFragment {
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false)); RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
profile = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getDefaultProfile(); if (MainApp.getConfigBuilder().getActiveProfileInterface() != null && MainApp.getConfigBuilder().getActiveProfileInterface().getProfile() != null && MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getDefaultProfile() != null)
units = MainApp.getConfigBuilder().getActiveProfileInterface().getProfile().getDefaultProfile().getUnits();
return view; return view;
} catch (Exception e) { } catch (Exception e) {
@ -68,8 +69,7 @@ public class BGSourceFragment extends SubscriberFragment {
} }
@Subscribe @Subscribe
@SuppressWarnings("unused") public void onStatusEvent(final EventNewBG unused) {
public void onStatusEvent(final EventNewBG ev) {
updateGUI(); updateGUI();
} }
@ -77,12 +77,9 @@ public class BGSourceFragment extends SubscriberFragment {
protected void updateGUI() { protected void updateGUI() {
Activity activity = getActivity(); Activity activity = getActivity();
if (activity != null) if (activity != null)
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(() -> {
@Override
public void run() {
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
recyclerView.swapAdapter(new BGSourceFragment.RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false)), true); recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getAllBgreadingsDataFromTime(now - MILLS_TO_THE_PAST, false)), true);
}
}); });
} }
@ -101,12 +98,12 @@ public class BGSourceFragment extends SubscriberFragment {
} }
@Override @Override
public void onBindViewHolder(BgReadingsViewHolder holder, int position) { public void onBindViewHolder(@NonNull BgReadingsViewHolder holder, int position) {
BgReading bgReading = bgReadings.get(position); BgReading bgReading = bgReadings.get(position);
holder.ns.setVisibility(NSUpload.isIdValid(bgReading._id) ? View.VISIBLE : View.GONE); holder.ns.setVisibility(NSUpload.isIdValid(bgReading._id) ? View.VISIBLE : View.GONE);
holder.invalid.setVisibility(!bgReading.isValid ? View.VISIBLE : View.GONE); holder.invalid.setVisibility(!bgReading.isValid ? View.VISIBLE : View.GONE);
holder.date.setText(DateUtil.dateAndTimeString(bgReading.date)); holder.date.setText(DateUtil.dateAndTimeString(bgReading.date));
holder.value.setText(bgReading.valueToUnitsToString(profile.getUnits())); holder.value.setText(bgReading.valueToUnitsToString(units));
holder.direction.setText(bgReading.directionToSymbol()); holder.direction.setText(bgReading.directionToSymbol());
holder.remove.setTag(bgReading); holder.remove.setTag(bgReading);
} }
@ -144,7 +141,7 @@ public class BGSourceFragment extends SubscriberFragment {
case R.id.bgsource_remove: case R.id.bgsource_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle(MainApp.gs(R.string.confirmation)); builder.setTitle(MainApp.gs(R.string.confirmation));
builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(profile.getUnits())); builder.setMessage(MainApp.gs(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(bgReading.date) + "\n" + bgReading.valueToUnitsToString(units));
builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() { builder.setPositiveButton(MainApp.gs(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
/* final String _id = bgReading._id; /* final String _id = bgReading._id;