ButterKnife to Dana fragment

This commit is contained in:
Milos Kozak 2018-01-26 17:18:40 +01:00
parent a7a4693e9c
commit e5d20ca996
2 changed files with 51 additions and 72 deletions

View file

@ -2,9 +2,12 @@ package info.nightscout.androidaps.plugins.Common;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import butterknife.Unbinder;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
abstract public class SubscriberFragment extends Fragment { abstract public class SubscriberFragment extends Fragment {
protected Unbinder unbinder;
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
@ -18,5 +21,12 @@ abstract public class SubscriberFragment extends Fragment {
updateGUI(); updateGUI();
} }
@Override public void onDestroyView() {
super.onDestroyView();
if (unbinder != null)
unbinder.unbind();
}
protected abstract void updateGUI(); protected abstract void updateGUI();
} }

View file

@ -21,6 +21,10 @@ import com.squareup.otto.Subscribe;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventExtendedBolusChange; import info.nightscout.androidaps.events.EventExtendedBolusChange;
@ -49,27 +53,24 @@ public class DanaRFragment extends SubscriberFragment {
} }
}; };
TextView lastConnectionView; @BindView(R.id.danar_lastconnection) TextView lastConnectionView;
TextView btConnectionView; @BindView(R.id.danar_btconnection) TextView btConnectionView;
TextView lastBolusView; @BindView(R.id.danar_lastbolus) TextView lastBolusView;
TextView dailyUnitsView; @BindView(R.id.danar_dailyunits) TextView dailyUnitsView;
TextView basaBasalRateView; @BindView(R.id.danar_basabasalrate) TextView basaBasalRateView;
TextView tempBasalView; @BindView(R.id.danar_tempbasal) TextView tempBasalView;
TextView extendedBolusView; @BindView(R.id.danar_extendedbolus) TextView extendedBolusView;
TextView batteryView; @BindView(R.id.danar_battery) TextView batteryView;
TextView reservoirView; @BindView(R.id.danar_reservoir) TextView reservoirView;
TextView iobView; @BindView(R.id.danar_iob) TextView iobView;
TextView firmwareView; @BindView(R.id.danar_firmware) TextView firmwareView;
TextView basalStepView; @BindView(R.id.danar_basalstep) TextView basalStepView;
TextView bolusStepView; @BindView(R.id.danar_bolusstep) TextView bolusStepView;
TextView serialNumberView; @BindView(R.id.danar_serialnumber) TextView serialNumberView;
TextView queueView; @BindView(R.id.danar_queue) TextView queueView;
Button viewProfileButton;
Button historyButton;
Button statsButton;
LinearLayout pumpStatusLayout; @BindView(R.id.overview_pumpstatuslayout) LinearLayout pumpStatusLayout;
TextView pumpStatusView; @BindView(R.id.overview_pumpstatus) TextView pumpStatusView;
public DanaRFragment() { public DanaRFragment() {
} }
@ -91,61 +92,10 @@ public class DanaRFragment extends SubscriberFragment {
Bundle savedInstanceState) { Bundle savedInstanceState) {
try { try {
View view = inflater.inflate(R.layout.danar_fragment, container, false); View view = inflater.inflate(R.layout.danar_fragment, container, false);
btConnectionView = (TextView) view.findViewById(R.id.danar_btconnection); unbinder = ButterKnife.bind(this, view);
lastConnectionView = (TextView) view.findViewById(R.id.danar_lastconnection);
lastBolusView = (TextView) view.findViewById(R.id.danar_lastbolus);
dailyUnitsView = (TextView) view.findViewById(R.id.danar_dailyunits);
basaBasalRateView = (TextView) view.findViewById(R.id.danar_basabasalrate);
tempBasalView = (TextView) view.findViewById(R.id.danar_tempbasal);
extendedBolusView = (TextView) view.findViewById(R.id.danar_extendedbolus);
batteryView = (TextView) view.findViewById(R.id.danar_battery);
reservoirView = (TextView) view.findViewById(R.id.danar_reservoir);
iobView = (TextView) view.findViewById(R.id.danar_iob);
firmwareView = (TextView) view.findViewById(R.id.danar_firmware);
viewProfileButton = (Button) view.findViewById(R.id.danar_viewprofile);
historyButton = (Button) view.findViewById(R.id.danar_history);
statsButton = (Button) view.findViewById(R.id.danar_stats);
basalStepView = (TextView) view.findViewById(R.id.danar_basalstep);
bolusStepView = (TextView) view.findViewById(R.id.danar_bolusstep);
serialNumberView = (TextView) view.findViewById(R.id.danar_serialnumber);
queueView = (TextView) view.findViewById(R.id.danar_queue);
pumpStatusView = (TextView) view.findViewById(R.id.overview_pumpstatus);
pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder)); pumpStatusView.setBackgroundColor(MainApp.sResources.getColor(R.color.colorInitializingBorder));
pumpStatusLayout = (LinearLayout) view.findViewById(R.id.overview_pumpstatuslayout);
viewProfileButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager manager = getFragmentManager();
ProfileViewDialog profileViewDialog = new ProfileViewDialog();
profileViewDialog.show(manager, "ProfileViewDialog");
}
});
historyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
}
});
statsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(getContext(), DanaRStatsActivity.class));
}
});
btConnectionView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
log.debug("Clicked connect to pump");
ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null);
}
});
updateGUI();
return view; return view;
} catch (Exception e) { } catch (Exception e) {
Crashlytics.logException(e); Crashlytics.logException(e);
@ -154,6 +104,25 @@ public class DanaRFragment extends SubscriberFragment {
return null; return null;
} }
@OnClick(R.id.danar_history) void onHistoryClick() {
startActivity(new Intent(getContext(), DanaRHistoryActivity.class));
}
@OnClick(R.id.danar_viewprofile) void onViewProfileClick() {
FragmentManager manager = getFragmentManager();
ProfileViewDialog profileViewDialog = new ProfileViewDialog();
profileViewDialog.show(manager, "ProfileViewDialog");
}
@OnClick(R.id.danar_stats) void onStatsClick() {
startActivity(new Intent(getContext(), DanaRStatsActivity.class));
}
@OnClick(R.id.danar_btconnection) void onBtConnectionClick() {
log.debug("Clicked connect to pump");
ConfigBuilderPlugin.getCommandQueue().readStatus("Clicked connect to pump", null);
}
@Subscribe @Subscribe
public void onStatusEvent(final EventPumpStatusChanged c) { public void onStatusEvent(final EventPumpStatusChanged c) {
Activity activity = getActivity(); Activity activity = getActivity();