TreatmentsFragment -> dagger
This commit is contained in:
parent
ca9486fab3
commit
f0fcd21bb9
|
@ -9,40 +9,30 @@ import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAFragment
|
|||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorFragment
|
||||
import info.nightscout.androidaps.plugins.profile.ns.NSProfileFragment
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsFragment
|
||||
|
||||
@Module
|
||||
abstract class FragmentsModule {
|
||||
|
||||
@ContributesAndroidInjector abstract fun contributesPreferencesFragment(): MyPreferenceFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSMAFragment(): OpenAPSMAFragment
|
||||
@ContributesAndroidInjector abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
|
||||
@ContributesAndroidInjector abstract fun contributesNSProfileFragment(): NSProfileFragment
|
||||
@ContributesAndroidInjector abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment
|
||||
@ContributesAndroidInjector abstract fun contributesCalibrationDialog(): CalibrationDialog
|
||||
@ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog
|
||||
@ContributesAndroidInjector abstract fun contributesCareDialog(): CareDialog
|
||||
@ContributesAndroidInjector abstract fun contributesExtendedBolusDialog(): ExtendedBolusDialog
|
||||
@ContributesAndroidInjector abstract fun contributesFillDialog(): FillDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesPreferencesFragment(): MyPreferenceFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesInsulinDialog(): InsulinDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesOpenAPSMAFragment(): OpenAPSMAFragment
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesNSProfileFragment(): NSProfileFragment
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesSmsCommunicatorFragment(): SmsCommunicatorFragment
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesTreatmentsFragment(): TreatmentsFragment
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesProfileSwitchDialog(): ProfileSwitchDialog
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesProfileViewerDialog(): ProfileViewerDialog
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesTempBasalDialog(): TempBasalDialog
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesTempTargetDialog(): TempTargetDialog
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesTreatmentDialog(): TreatmentDialog
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract fun contributesWizardDialog(): WizardDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesCalibrationDialog(): CalibrationDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesCarbsDialog(): CarbsDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesCareDialog(): CareDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesExtendedBolusDialog(): ExtendedBolusDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesFillDialog(): FillDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesInsulinDialog(): InsulinDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesProfileSwitchDialog(): ProfileSwitchDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesProfileViewerDialog(): ProfileViewerDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesTempBasalDialog(): TempBasalDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesTempTargetDialog(): TempTargetDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesTreatmentDialog(): TreatmentDialog
|
||||
@Suppress("unused") @ContributesAndroidInjector abstract fun contributesWizardDialog(): WizardDialog
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.treatments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsBolusFragment;
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsCareportalFragment;
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsExtendedBolusesFragment;
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsProfileSwitchFragment;
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTempTargetFragment;
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.TreatmentsTemporaryBasalsFragment;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class TreatmentsFragment extends Fragment implements View.OnClickListener {
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
TextView treatmentsTab;
|
||||
TextView extendedBolusesTab;
|
||||
TextView tempBasalsTab;
|
||||
TextView tempTargetTab;
|
||||
TextView profileSwitchTab;
|
||||
TextView careportalTab;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.treatments_fragment, container, false);
|
||||
|
||||
treatmentsTab = (TextView) view.findViewById(R.id.treatments_treatments);
|
||||
extendedBolusesTab = (TextView) view.findViewById(R.id.treatments_extendedboluses);
|
||||
tempBasalsTab = (TextView) view.findViewById(R.id.treatments_tempbasals);
|
||||
tempTargetTab = (TextView) view.findViewById(R.id.treatments_temptargets);
|
||||
profileSwitchTab = (TextView) view.findViewById(R.id.treatments_profileswitches);
|
||||
careportalTab = (TextView) view.findViewById(R.id.treatments_careportal);
|
||||
treatmentsTab.setOnClickListener(this);
|
||||
extendedBolusesTab.setOnClickListener(this);
|
||||
tempBasalsTab.setOnClickListener(this);
|
||||
tempTargetTab.setOnClickListener(this);
|
||||
profileSwitchTab.setOnClickListener(this);
|
||||
careportalTab.setOnClickListener(this);
|
||||
|
||||
setFragment(new TreatmentsBolusFragment());
|
||||
setBackgroundColorOnSelected(treatmentsTab);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onResume() {
|
||||
super.onResume();
|
||||
disposable.add(RxBus.INSTANCE
|
||||
.toObservable(EventExtendedBolusChange.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> updateGui(), FabricPrivacy::logException)
|
||||
);
|
||||
updateGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onPause() {
|
||||
super.onPause();
|
||||
disposable.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
switch (v.getId()) {
|
||||
case R.id.treatments_treatments:
|
||||
setFragment(new TreatmentsBolusFragment());
|
||||
setBackgroundColorOnSelected(treatmentsTab);
|
||||
break;
|
||||
case R.id.treatments_extendedboluses:
|
||||
setFragment(new TreatmentsExtendedBolusesFragment());
|
||||
setBackgroundColorOnSelected(extendedBolusesTab);
|
||||
break;
|
||||
case R.id.treatments_tempbasals:
|
||||
setFragment(new TreatmentsTemporaryBasalsFragment());
|
||||
setBackgroundColorOnSelected(tempBasalsTab);
|
||||
break;
|
||||
case R.id.treatments_temptargets:
|
||||
setFragment(new TreatmentsTempTargetFragment());
|
||||
setBackgroundColorOnSelected(tempTargetTab);
|
||||
break;
|
||||
case R.id.treatments_profileswitches:
|
||||
setFragment(new TreatmentsProfileSwitchFragment());
|
||||
setBackgroundColorOnSelected(profileSwitchTab);
|
||||
break;
|
||||
case R.id.treatments_careportal:
|
||||
setFragment(new TreatmentsCareportalFragment());
|
||||
setBackgroundColorOnSelected(careportalTab);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void setFragment(Fragment selectedFragment) {
|
||||
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.treatments_fragment_container, selectedFragment); // f2_container is your FrameLayout container
|
||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
|
||||
ft.addToBackStack(null);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
private void setBackgroundColorOnSelected(TextView selected) {
|
||||
treatmentsTab.setBackgroundColor(MainApp.gc(R.color.defaultbackground));
|
||||
extendedBolusesTab.setBackgroundColor(MainApp.gc(R.color.defaultbackground));
|
||||
tempBasalsTab.setBackgroundColor(MainApp.gc(R.color.defaultbackground));
|
||||
tempTargetTab.setBackgroundColor(MainApp.gc(R.color.defaultbackground));
|
||||
profileSwitchTab.setBackgroundColor(MainApp.gc(R.color.defaultbackground));
|
||||
careportalTab.setBackgroundColor(MainApp.gc(R.color.defaultbackground));
|
||||
selected.setBackgroundColor(MainApp.gc(R.color.tabBgColorSelected));
|
||||
}
|
||||
|
||||
private void updateGui() {
|
||||
if (ConfigBuilderPlugin.getPlugin().getActivePump().getPumpDescription().isExtendedBolusCapable
|
||||
|| TreatmentsPlugin.getPlugin().getExtendedBolusesFromHistory().size() > 0) {
|
||||
extendedBolusesTab.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
extendedBolusesTab.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
package info.nightscout.androidaps.plugins.treatments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.events.EventExtendedBolusChange
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus.toObservable
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.fragments.*
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.treatments_fragment.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class TreatmentsFragment : DaggerFragment() {
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
@Inject
|
||||
lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.treatments_fragment, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
treatments_treatments.setOnClickListener {
|
||||
setFragment(TreatmentsBolusFragment())
|
||||
setBackgroundColorOnSelected(it)
|
||||
}
|
||||
treatments_extendedboluses.setOnClickListener {
|
||||
setFragment(TreatmentsExtendedBolusesFragment())
|
||||
setBackgroundColorOnSelected(it)
|
||||
}
|
||||
treatments_tempbasals.setOnClickListener {
|
||||
setFragment(TreatmentsTemporaryBasalsFragment())
|
||||
setBackgroundColorOnSelected(it)
|
||||
}
|
||||
treatments_temptargets.setOnClickListener {
|
||||
setFragment(TreatmentsTempTargetFragment())
|
||||
setBackgroundColorOnSelected(it)
|
||||
}
|
||||
treatments_profileswitches.setOnClickListener {
|
||||
setFragment(TreatmentsProfileSwitchFragment())
|
||||
setBackgroundColorOnSelected(it)
|
||||
}
|
||||
treatments_careportal.setOnClickListener {
|
||||
setFragment(TreatmentsCareportalFragment())
|
||||
setBackgroundColorOnSelected(it)
|
||||
}
|
||||
setFragment(TreatmentsBolusFragment())
|
||||
setBackgroundColorOnSelected(treatments_treatments)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
disposable.add(toObservable(EventExtendedBolusChange::class.java)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe({ updateGui() }) { FabricPrivacy.logException(it) }
|
||||
)
|
||||
updateGui()
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
disposable.clear()
|
||||
}
|
||||
|
||||
private fun setFragment(selectedFragment: Fragment) {
|
||||
val ft = childFragmentManager.beginTransaction()
|
||||
ft.replace(R.id.treatments_fragment_container, selectedFragment) // f2_container is your FrameLayout container
|
||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
|
||||
ft.addToBackStack(null)
|
||||
ft.commit()
|
||||
}
|
||||
|
||||
private fun setBackgroundColorOnSelected(selected: View) {
|
||||
treatments_treatments.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||
treatments_extendedboluses.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||
treatments_tempbasals.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||
treatments_temptargets.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||
treatments_profileswitches.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||
treatments_careportal.setBackgroundColor(MainApp.gc(R.color.defaultbackground))
|
||||
selected.setBackgroundColor(MainApp.gc(R.color.tabBgColorSelected))
|
||||
}
|
||||
|
||||
private fun updateGui() {
|
||||
if (configBuilderPlugin.activePump?.pumpDescription?.isExtendedBolusCapable == true
|
||||
|| treatmentsPlugin.extendedBolusesFromHistory.size() > 0)
|
||||
treatments_extendedboluses?.visibility = View.VISIBLE
|
||||
else
|
||||
treatments_extendedboluses?.visibility = View.GONE
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.treatments;
|
|||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
|
@ -613,6 +614,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public Intervals<ExtendedBolus> getExtendedBolusesFromHistory() {
|
||||
synchronized (extendedBoluses) {
|
||||
return new NonOverlappingIntervals<>(extendedBoluses);
|
||||
|
@ -620,6 +622,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public NonOverlappingIntervals<TemporaryBasal> getTemporaryBasalsFromHistory() {
|
||||
synchronized (tempBasals) {
|
||||
return new NonOverlappingIntervals<>(tempBasals);
|
||||
|
|
Loading…
Reference in a new issue