diff --git a/rileylink/src/main/AndroidManifest.xml b/rileylink/src/main/AndroidManifest.xml index f0c84c9b02..2efb9aa635 100644 --- a/rileylink/src/main/AndroidManifest.xml +++ b/rileylink/src/main/AndroidManifest.xml @@ -24,6 +24,7 @@ diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RefreshableInterface.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RefreshableInterface.java deleted file mode 100644 index df84750152..0000000000 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/dialog/RefreshableInterface.java +++ /dev/null @@ -1,11 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.dialog; - -/** - * Created by andy on 5/19/18. - */ - -public interface RefreshableInterface { - - void refreshData(); - -} diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java deleted file mode 100644 index 40fc09fd55..0000000000 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.java +++ /dev/null @@ -1,104 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog; - -import android.os.Bundle; - -import androidx.annotation.NonNull; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentPagerAdapter; -import androidx.viewpager.widget.ViewPager; - -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.tabs.TabLayout; - -import java.util.ArrayList; -import java.util.List; - -import javax.inject.Inject; - -import info.nightscout.androidaps.activities.NoSplashAppCompatActivity; -import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R; -import info.nightscout.androidaps.utils.resources.ResourceHelper; - -public class RileyLinkStatusActivity extends NoSplashAppCompatActivity { - - @Inject ResourceHelper rh; - - private SectionsPagerAdapter sectionsPagerAdapter; - private TabLayout tabLayout; - /** - * The {@link ViewPager} that will host the section contents. - */ - private ViewPager viewPager; - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.rileylink_status); - - // Create the adapter that will return a fragment for each of the three - // primary sections of the activity. - - // Set up the ViewPager with the sections adapter. - viewPager = findViewById(R.id.rileylink_settings_container); - // mViewPager.setAdapter(mSectionsPagerAdapter); - setupViewPager(); - - tabLayout = findViewById(R.id.rileylink_settings_tabs); - tabLayout.setupWithViewPager(viewPager); - - FloatingActionButton floatingActionButton = findViewById(R.id.rileylink_settings_fab); - floatingActionButton.setOnClickListener(v -> { - - RefreshableInterface selectableInterface = (RefreshableInterface) sectionsPagerAdapter - .getItem(tabLayout.getSelectedTabPosition()); - selectableInterface.refreshData(); - }); - } - - public void setupViewPager() { - sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - - sectionsPagerAdapter.addFragment(new RileyLinkStatusGeneralFragment(), rh.gs(R.string.rileylink_settings_tab1)); - sectionsPagerAdapter.addFragment(new RileyLinkStatusHistoryFragment(), rh.gs(R.string.rileylink_settings_tab2)); - viewPager.setAdapter(sectionsPagerAdapter); - } - - /** - * A {@link FragmentPagerAdapter} that returns a fragment corresponding to - * one of the sections/tabs/pages. - */ - public static class SectionsPagerAdapter extends FragmentPagerAdapter { - - List fragmentList = new ArrayList<>(); - List fragmentTitle = new ArrayList<>(); - int lastSelectedPosition = 0; - - public SectionsPagerAdapter(FragmentManager fm) { - super(fm); - } - - @NonNull @Override - public Fragment getItem(int position) { - this.lastSelectedPosition = position; - return fragmentList.get(position); - } - - @Override - public int getCount() { - // Show 3 total pages. - return fragmentList.size(); - } - - public void addFragment(Fragment fragment, String title) { - this.fragmentList.add(fragment); - this.fragmentTitle.add(title); - } - - @Override - public CharSequence getPageTitle(int position) { - return fragmentTitle.get(position); - } - } -} diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.kt new file mode 100644 index 0000000000..be2d1108b3 --- /dev/null +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusActivity.kt @@ -0,0 +1,48 @@ +package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity +import androidx.fragment.app.Fragment +import androidx.viewpager2.adapter.FragmentStateAdapter +import com.google.android.material.tabs.TabLayoutMediator +import info.nightscout.androidaps.activities.NoSplashAppCompatActivity +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.databinding.RileylinkStatusBinding + +class RileyLinkStatusActivity : NoSplashAppCompatActivity() { + + private lateinit var binding: RileylinkStatusBinding + + private var sectionsPagerAdapter: SectionsPagerAdapter? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = RileylinkStatusBinding.inflate(layoutInflater) + setContentView(binding.root) + + sectionsPagerAdapter = SectionsPagerAdapter(this) + sectionsPagerAdapter?.addFragment(RileyLinkStatusGeneralFragment::class.java.name, rh.gs(R.string.rileylink_settings_tab1)) + sectionsPagerAdapter?.addFragment(RileyLinkStatusHistoryFragment::class.java.name, rh.gs(R.string.rileylink_settings_tab2)) + + binding.pager.adapter = sectionsPagerAdapter + + TabLayoutMediator(binding.tabLayout, binding.pager) { tab, position -> + tab.text = sectionsPagerAdapter?.getPageTitle(position) + }.attach() + } + + class SectionsPagerAdapter(private val activity: AppCompatActivity) : FragmentStateAdapter(activity) { + + private val fragmentList: MutableList = ArrayList() + private val fragmentTitle: MutableList = ArrayList() + override fun getItemCount(): Int = fragmentList.size + override fun createFragment(position: Int): Fragment = + activity.supportFragmentManager.fragmentFactory.instantiate(ClassLoader.getSystemClassLoader(), fragmentList[position]) + + fun getPageTitle(position: Int): CharSequence = fragmentTitle[position] + fun addFragment(fragment: String, title: String) { + fragmentList.add(fragment) + fragmentTitle.add(title) + } + } +} \ No newline at end of file diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusDevice.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusDevice.java deleted file mode 100644 index 8bc967bd9f..0000000000 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusDevice.java +++ /dev/null @@ -1,152 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.BaseAdapter; -import android.widget.Button; -import android.widget.ListView; -import android.widget.TextView; - -import androidx.fragment.app.Fragment; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.CommandValueDefinition; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.CommandValueDefinitionType; - - -/** - * Created by andy on 5/19/18. - */ - -// FIXME needs to be implemented - -public class RileyLinkStatusDevice extends Fragment implements RefreshableInterface { - - ListView listView; - - RileyLinkCommandListAdapter adapter; - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.rileylink_status_device, container, false); - - adapter = new RileyLinkCommandListAdapter(); - - return rootView; - } - - - @Override - public void onStart() { - super.onStart(); - - this.listView = getActivity().findViewById(R.id.rileyLinkDeviceList); - - listView.setAdapter(adapter); - - setElements(); - } - - - private void setElements() { - - } - - - @Override - public void refreshData() { - // adapter.addItemsAndClean(RileyLinkUtil.getRileyLinkHistory()); - } - - static class ViewHolder { - - TextView itemDescription; - Button itemValue; - } - - private class RileyLinkCommandListAdapter extends BaseAdapter { - - private final List commandValueList; - private Map commandValueMap; - private final LayoutInflater mInflator; - - - public RileyLinkCommandListAdapter() { - super(); - commandValueList = new ArrayList<>(); - mInflator = RileyLinkStatusDevice.this.getLayoutInflater(); - } - - - public void addItems(List list) { - commandValueList.addAll(list); - - for (CommandValueDefinition commandValueDefinition : list) { - commandValueMap.put(commandValueDefinition.definitionType, commandValueDefinition); - } - - notifyDataSetChanged(); - } - - - public CommandValueDefinition getCommandValueItem(int position) { - return commandValueList.get(position); - } - - - public void clear() { - commandValueList.clear(); - notifyDataSetChanged(); - } - - - @Override - public int getCount() { - return commandValueList.size(); - } - - - @Override - public Object getItem(int i) { - return commandValueList.get(i); - } - - - @Override - public long getItemId(int i) { - return i; - } - - - @Override - public View getView(int i, View view, ViewGroup viewGroup) { - RileyLinkStatusDevice.ViewHolder viewHolder; - // General ListView optimization code. - if (view == null) { - view = mInflator.inflate(R.layout.rileylink_status_device_item, null); - viewHolder = new RileyLinkStatusDevice.ViewHolder(); - viewHolder.itemDescription = view.findViewById(R.id.rileylink_device_label); - viewHolder.itemValue = view.findViewById(R.id.rileylink_device_action); - view.setTag(viewHolder); - } else { - viewHolder = (RileyLinkStatusDevice.ViewHolder) view.getTag(); - } - // Z - // RLHistoryItem item = historyItemList.get(i); - // viewHolder.itemTime.setText(StringUtil.toDateTimeString(item.getDateTime())); - // viewHolder.itemSource.setText("Riley Link"); // for now - // viewHolder.itemDescription.setText(item.getDescription()); - - return view; - } - } - -} diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java deleted file mode 100644 index 88a9f1de6b..0000000000 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.java +++ /dev/null @@ -1,144 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import org.joda.time.LocalDateTime; - -import java.util.Optional; - -import javax.inject.Inject; - -import dagger.android.support.DaggerFragment; -import info.nightscout.androidaps.interfaces.ActivePlugin; -import info.nightscout.shared.logging.AAPSLogger; -import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkError; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpInfo; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData; -import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.shared.sharedPreferences.SP; - -/** - * Created by andy on 5/19/18. - */ - -public class RileyLinkStatusGeneralFragment extends DaggerFragment implements RefreshableInterface { - - private static final String PLACEHOLDER = "-"; - - @Inject ActivePlugin activePlugin; - @Inject ResourceHelper rh; - @Inject AAPSLogger aapsLogger; - @Inject RileyLinkServiceData rileyLinkServiceData; - @Inject DateUtil dateUtil; - @Inject SP sp; - - private TextView connectionStatus; - private TextView configuredRileyLinkAddress; - private TextView configuredRileyLinkName; - private View batteryLevelRow; - private TextView batteryLevel; - private TextView connectionError; - private View connectedDeviceDetails; - private TextView deviceType; - private TextView configuredDeviceModel; - private TextView connectedDeviceModel; - private TextView serialNumber; - private TextView pumpFrequency; - private TextView lastUsedFrequency; - private TextView lastDeviceContact; - private TextView firmwareVersion; - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(R.layout.rileylink_status_general, container, false); - } - - @Override - public void onResume() { - super.onResume(); - - this.connectionStatus = getActivity().findViewById(R.id.rls_t1_connection_status); - this.configuredRileyLinkAddress = getActivity().findViewById(R.id.rls_t1_configured_riley_link_address); - this.configuredRileyLinkName = getActivity().findViewById(R.id.rls_t1_configured_riley_link_name); - this.batteryLevelRow = getActivity().findViewById(R.id.rls_t1_battery_level_row); - this.batteryLevel = getActivity().findViewById(R.id.rls_t1_battery_level); - this.connectionError = getActivity().findViewById(R.id.rls_t1_connection_error); - this.connectedDeviceDetails = getActivity().findViewById(R.id.rls_t1_connected_device_details); - this.deviceType = getActivity().findViewById(R.id.rls_t1_device_type); - this.configuredDeviceModel = getActivity().findViewById(R.id.rls_t1_configured_device_model); - this.connectedDeviceModel = getActivity().findViewById(R.id.rls_t1_connected_device_model); - this.serialNumber = getActivity().findViewById(R.id.rls_t1_serial_number); - this.pumpFrequency = getActivity().findViewById(R.id.rls_t1_pump_frequency); - this.lastUsedFrequency = getActivity().findViewById(R.id.rls_t1_last_used_frequency); - this.lastDeviceContact = getActivity().findViewById(R.id.rls_t1_last_device_contact); - this.firmwareVersion = getActivity().findViewById(R.id.rls_t1_firmware_version); - - refreshData(); - } - - @Override public void refreshData() { - RileyLinkTargetDevice targetDevice = rileyLinkServiceData.targetDevice; - - this.connectionStatus.setText(rh.gs(rileyLinkServiceData.rileyLinkServiceState.getResourceId())); - - this.configuredRileyLinkAddress.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkAddress).orElse(PLACEHOLDER)); - this.configuredRileyLinkName.setText(Optional.ofNullable(rileyLinkServiceData.rileyLinkName).orElse(PLACEHOLDER)); - - if (sp.getBoolean(rh.gs(R.string.key_riley_link_show_battery_level), false)) { - batteryLevelRow.setVisibility(View.VISIBLE); - Integer batteryLevel = rileyLinkServiceData.batteryLevel; - this.batteryLevel.setText(batteryLevel == null ? PLACEHOLDER : rh.gs(R.string.rileylink_battery_level_value, batteryLevel)); - } else { - batteryLevelRow.setVisibility(View.GONE); - } - - RileyLinkError rileyLinkError = rileyLinkServiceData.rileyLinkError; - this.connectionError.setText(rileyLinkError == null ? PLACEHOLDER : rh.gs(rileyLinkError.getResourceId(targetDevice))); - - - if (rileyLinkServiceData.isOrange && rileyLinkServiceData.versionOrangeFirmware!=null) { - this.firmwareVersion.setText(rh.gs(R.string.rileylink_firmware_version_value_orange, - rileyLinkServiceData.versionOrangeFirmware, - Optional.ofNullable(rileyLinkServiceData.versionOrangeHardware).orElse(PLACEHOLDER))); - } else { - this.firmwareVersion.setText(rh.gs(R.string.rileylink_firmware_version_value, - Optional.ofNullable(rileyLinkServiceData.versionBLE113).orElse(PLACEHOLDER), - Optional.ofNullable(rileyLinkServiceData.versionCC110).orElse(PLACEHOLDER))); - } - - RileyLinkPumpDevice rileyLinkPumpDevice = (RileyLinkPumpDevice) activePlugin.getActivePump(); - RileyLinkPumpInfo rileyLinkPumpInfo = rileyLinkPumpDevice.getPumpInfo(); - this.deviceType.setText(targetDevice.getResourceId()); - if (targetDevice == RileyLinkTargetDevice.MedtronicPump) { - this.connectedDeviceDetails.setVisibility(View.VISIBLE); - this.configuredDeviceModel.setText(activePlugin.getActivePump().getPumpDescription().getPumpType().getDescription()); - this.connectedDeviceModel.setText(rileyLinkPumpInfo.getConnectedDeviceModel()); - } else { - this.connectedDeviceDetails.setVisibility(View.GONE); - } - this.serialNumber.setText(rileyLinkPumpInfo.getConnectedDeviceSerialNumber()); - this.pumpFrequency.setText(rileyLinkPumpInfo.getPumpFrequency()); - - if (rileyLinkServiceData.lastGoodFrequency != null) { - this.lastUsedFrequency.setText(rh.gs(R.string.rileylink_pump_frequency_value, rileyLinkServiceData.lastGoodFrequency)); - } - - long lastConnectionTimeMillis = rileyLinkPumpDevice.getLastConnectionTimeMillis(); - if (lastConnectionTimeMillis == 0) { - this.lastDeviceContact.setText(rh.gs(R.string.riley_link_ble_config_connected_never)); - } else { - this.lastDeviceContact.setText(StringUtil.toDateTimeString(dateUtil, new LocalDateTime(lastConnectionTimeMillis))); - } - } - -} diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.kt new file mode 100644 index 0000000000..4d0688e985 --- /dev/null +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusGeneralFragment.kt @@ -0,0 +1,95 @@ +package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import dagger.android.support.DaggerFragment +import info.nightscout.androidaps.interfaces.ActivePlugin +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.databinding.RileylinkStatusGeneralBinding +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkPumpDevice +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.defs.RileyLinkTargetDevice +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.service.RileyLinkServiceData +import info.nightscout.androidaps.plugins.pump.common.utils.StringUtil +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.resources.ResourceHelper +import info.nightscout.shared.logging.AAPSLogger +import info.nightscout.shared.sharedPreferences.SP +import org.joda.time.LocalDateTime +import javax.inject.Inject + +class RileyLinkStatusGeneralFragment : DaggerFragment() { + + @Inject lateinit var activePlugin: ActivePlugin + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var rileyLinkServiceData: RileyLinkServiceData + @Inject lateinit var dateUtil: DateUtil + @Inject lateinit var sp: SP + + private var _binding: RileylinkStatusGeneralBinding? = null + + // This property is only valid between onCreateView and onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + RileylinkStatusGeneralBinding.inflate(inflater, container, false).also { _binding = it }.root + + override fun onResume() { + super.onResume() + refreshData() + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + binding.refresh.setOnClickListener { refreshData() } + } + + private fun refreshData() { + val targetDevice = rileyLinkServiceData.targetDevice + binding.connectionStatus.text = rh.gs(rileyLinkServiceData.rileyLinkServiceState.resourceId) + binding.configuredRileyLinkAddress.text = rileyLinkServiceData.rileyLinkAddress ?: EMPTY + binding.configuredRileyLinkName.text = rileyLinkServiceData.rileyLinkName ?: EMPTY + if (sp.getBoolean(rh.gs(R.string.key_riley_link_show_battery_level), false)) { + binding.batteryLevelRow.visibility = View.VISIBLE + val batteryLevel = rileyLinkServiceData.batteryLevel + binding.batteryLevel.text = batteryLevel?.let { rh.gs(R.string.rileylink_battery_level_value, it) } ?: EMPTY + } else binding.batteryLevelRow.visibility = View.GONE + binding.connectionError.text = rileyLinkServiceData.rileyLinkError?.let { rh.gs(it.getResourceId(targetDevice)) } ?: EMPTY + if (rileyLinkServiceData.isOrange && rileyLinkServiceData.versionOrangeFirmware != null) { + binding.firmwareVersion.text = rh.gs( + R.string.rileylink_firmware_version_value_orange, + rileyLinkServiceData.versionOrangeFirmware, + rileyLinkServiceData.versionOrangeHardware ?: EMPTY + ) + } else { + binding.firmwareVersion.text = rh.gs( + R.string.rileylink_firmware_version_value, + rileyLinkServiceData.versionBLE113 ?: EMPTY, + rileyLinkServiceData.versionCC110 ?: EMPTY + ) + } + val rileyLinkPumpDevice = activePlugin.activePump as RileyLinkPumpDevice + val rileyLinkPumpInfo = rileyLinkPumpDevice.pumpInfo + binding.deviceType.setText(targetDevice.resourceId) + if (targetDevice == RileyLinkTargetDevice.MedtronicPump) { + binding.connectedDeviceDetails.visibility = View.VISIBLE + binding.configuredDeviceModel.text = activePlugin.activePump.pumpDescription.pumpType.description + binding.connectedDeviceModel.text = rileyLinkPumpInfo.connectedDeviceModel + } else binding.connectedDeviceDetails.visibility = View.GONE + binding.serialNumber.text = rileyLinkPumpInfo.connectedDeviceSerialNumber + binding.pumpFrequency.text = rileyLinkPumpInfo.pumpFrequency + if (rileyLinkServiceData.lastGoodFrequency != null) { + binding.lastUsedFrequency.text = rh.gs(R.string.rileylink_pump_frequency_value, rileyLinkServiceData.lastGoodFrequency) + } + val lastConnectionTimeMillis = rileyLinkPumpDevice.lastConnectionTimeMillis + if (lastConnectionTimeMillis == 0L) binding.lastDeviceContact.text = rh.gs(R.string.riley_link_ble_config_connected_never) + else binding.lastDeviceContact.text = StringUtil.toDateTimeString(dateUtil, LocalDateTime(lastConnectionTimeMillis)) + } + + companion object { + + private const val EMPTY = "-" + } +} \ No newline at end of file diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java deleted file mode 100644 index 862b6b343c..0000000000 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.java +++ /dev/null @@ -1,171 +0,0 @@ -package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog; - -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.TextView; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import javax.inject.Inject; - -import dagger.android.support.DaggerFragment; -import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState; -import info.nightscout.androidaps.plugins.pump.common.dialog.RefreshableInterface; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil; -import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.resources.ResourceHelper; - -/** - * Created by andy on 5/19/18. - */ - -public class RileyLinkStatusHistoryFragment extends DaggerFragment implements RefreshableInterface { - - @Inject RileyLinkUtil rileyLinkUtil; - @Inject ResourceHelper rh; - @Inject DateUtil dateUtil; - - RecyclerView recyclerView; - RecyclerViewAdapter recyclerViewAdapter; - - LinearLayoutManager llm; - List filteredHistoryList = new ArrayList<>(); - - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.rileylink_status_history, container, false); - - recyclerView = rootView.findViewById(R.id.rileylink_history_list); - - recyclerView.setHasFixedSize(true); - llm = new LinearLayoutManager(rootView.getContext()); - recyclerView.setLayoutManager(llm); - - recyclerViewAdapter = new RecyclerViewAdapter(filteredHistoryList); - recyclerView.setAdapter(recyclerViewAdapter); - - return rootView; - } - - - @Override - public void onStart() { - super.onStart(); - - refreshData(); - } - - - @Override - public void refreshData() { - if (rileyLinkUtil.getRileyLinkHistory() != null) { - recyclerViewAdapter.addItemsAndClean(rileyLinkUtil.getRileyLinkHistory()); - } - } - - - public class RecyclerViewAdapter extends RecyclerView.Adapter { - - List historyList; - - - RecyclerViewAdapter(List historyList) { - this.historyList = historyList; - } - - - public void setHistoryList(List historyList) { - this.historyList = historyList; - } - - - public void addItemsAndClean(List items) { - this.historyList.clear(); - - Collections.sort(items, new RLHistoryItem.Comparator()); - - for (RLHistoryItem item : items) { - - if (!historyList.contains(item) && isValidItem(item)) { - historyList.add(item); - } - } - - notifyDataSetChanged(); - } - - - private boolean isValidItem(RLHistoryItem item) { - - PumpDeviceState pumpState = item.getPumpDeviceState(); - - // - // - return pumpState != PumpDeviceState.Sleeping && // - pumpState != PumpDeviceState.Active && // - pumpState != PumpDeviceState.WakingUp; - - } - - - @NonNull - @Override - public RecyclerViewAdapter.HistoryViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { - View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.rileylink_status_history_item, // - viewGroup, false); - return new RecyclerViewAdapter.HistoryViewHolder(v); - } - - - @Override - public void onBindViewHolder(RecyclerViewAdapter.HistoryViewHolder holder, int position) { - RLHistoryItem item = historyList.get(position); - - if (item != null) { - holder.timeView.setText(dateUtil.dateAndTimeAndSecondsString(item.getDateTime().toDateTime().getMillis())); - holder.typeView.setText(item.getSource().getDesc()); - holder.valueView.setText(item.getDescription(rh)); - } - } - - - @Override - public int getItemCount() { - return historyList.size(); - } - - - @Override - public void onAttachedToRecyclerView(RecyclerView recyclerView) { - super.onAttachedToRecyclerView(recyclerView); - } - - class HistoryViewHolder extends RecyclerView.ViewHolder { - - TextView timeView; - TextView typeView; - TextView valueView; - - - HistoryViewHolder(View itemView) { - super(itemView); - - timeView = itemView.findViewById(R.id.rileylink_history_time); - typeView = itemView.findViewById(R.id.rileylink_history_source); - valueView = itemView.findViewById(R.id.rileylink_history_description); - } - } - } - -} diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.kt new file mode 100644 index 0000000000..eeaf5bc11a --- /dev/null +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/dialog/RileyLinkStatusHistoryFragment.kt @@ -0,0 +1,82 @@ +package info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import dagger.android.support.DaggerFragment +import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.R +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkUtil +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.data.RLHistoryItem +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.databinding.RileylinkStatusHistoryBinding +import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.databinding.RileylinkStatusHistoryItemBinding +import info.nightscout.androidaps.utils.DateUtil +import info.nightscout.androidaps.utils.resources.ResourceHelper +import javax.inject.Inject + +class RileyLinkStatusHistoryFragment : DaggerFragment() { + + @Inject lateinit var rileyLinkUtil: RileyLinkUtil + @Inject lateinit var rh: ResourceHelper + @Inject lateinit var dateUtil: DateUtil + + private var _binding: RileylinkStatusHistoryBinding? = null + + // This property is only valid between onCreateView and onDestroyView. + private val binding get() = _binding!! + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = + RileylinkStatusHistoryBinding.inflate(inflater, container, false).also { _binding = it }.root + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + binding.historyList.setHasFixedSize(true) + binding.historyList.layoutManager = LinearLayoutManager(view.context) + binding.refresh.setOnClickListener { refreshData() } + } + + override fun onResume() { + super.onResume() + refreshData() + } + + private fun refreshData() { + binding.historyList.adapter = + RecyclerViewAdapter(rileyLinkUtil.rileyLinkHistory + ?.filter { isValidItem(it) } + ?.sortedWith(RLHistoryItem.Comparator()) + ?: ArrayList() + ) + } + + private fun isValidItem(item: RLHistoryItem): Boolean = + item.pumpDeviceState !== PumpDeviceState.Sleeping && + item.pumpDeviceState !== PumpDeviceState.Active && + item.pumpDeviceState !== PumpDeviceState.WakingUp + + inner class RecyclerViewAdapter internal constructor(private val historyList: List) : RecyclerView.Adapter() { + + override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder { + val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.rileylink_status_history_item, viewGroup, false) + return HistoryViewHolder(v) + } + + override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) { + val item = historyList[position] + holder.binding.historyTime.text = dateUtil.dateAndTimeAndSecondsString(item.dateTime.toDateTime().millis) + holder.binding.historySource.text = item.source.desc + holder.binding.historyDescription.text = item.getDescription(rh) + } + + override fun getItemCount(): Int = historyList.size + + inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { + + val binding = RileylinkStatusHistoryItemBinding.bind(itemView) + } + } +} \ No newline at end of file diff --git a/rileylink/src/main/res/layout/rileylink_status.xml b/rileylink/src/main/res/layout/rileylink_status.xml index efa0be2f6f..9193b5bb0f 100644 --- a/rileylink/src/main/res/layout/rileylink_status.xml +++ b/rileylink/src/main/res/layout/rileylink_status.xml @@ -1,41 +1,29 @@ - - + android:paddingTop="@dimen/appbar_padding_top"> + android:layout_height="match_parent" /> - + - - - - - - + diff --git a/rileylink/src/main/res/layout/rileylink_status_device.xml b/rileylink/src/main/res/layout/rileylink_status_device.xml deleted file mode 100644 index e8d1a63552..0000000000 --- a/rileylink/src/main/res/layout/rileylink_status_device.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - diff --git a/rileylink/src/main/res/layout/rileylink_status_general.xml b/rileylink/src/main/res/layout/rileylink_status_general.xml index dd3293ba48..3ef25590ff 100644 --- a/rileylink/src/main/res/layout/rileylink_status_general.xml +++ b/rileylink/src/main/res/layout/rileylink_status_general.xml @@ -1,260 +1,258 @@ - + tools:context="info.nightscout.androidaps.plugins.pump.common.hw.rileylink.dialog.RileyLinkStatusGeneralFragment"> - + android:layout_height="wrap_content" + android:orientation="vertical"> - + + + android:layout_gravity="center" + android:layout_marginStart="4dp" + android:layout_marginTop="4dp" + android:layout_marginEnd="4dp" + app:cardCornerRadius="4dp" + app:cardElevation="4dp" + app:cardUseCompatPadding="false" + app:contentPadding="2dp"> - + android:layout_height="wrap_content" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:orientation="vertical"> - - - - - - - - - - + android:orientation="horizontal"> + android:text="@string/rileylink_device_type" /> + android:textAlignment="center" + tools:ignore="RtlCompat" /> + + + + + + + + + + + + + + + + + + + + + + android:orientation="horizontal"> + android:text="@string/rileylink_pump_serial_number" /> + android:textAlignment="center" + tools:ignore="RtlCompat" /> + + + + + + + + + + + + + + + + + + + + + - + - + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/rileylink/src/main/res/layout/rileylink_status_history.xml b/rileylink/src/main/res/layout/rileylink_status_history.xml index 21a37379cb..9f29a05061 100644 --- a/rileylink/src/main/res/layout/rileylink_status_history.xml +++ b/rileylink/src/main/res/layout/rileylink_status_history.xml @@ -9,17 +9,20 @@ android:layout_height="match_parent" android:orientation="vertical"> - - + android:layout_height="wrap_content" /> + + diff --git a/rileylink/src/main/res/layout/rileylink_status_history_item.xml b/rileylink/src/main/res/layout/rileylink_status_history_item.xml index 4e522c8899..f7098d42a8 100644 --- a/rileylink/src/main/res/layout/rileylink_status_history_item.xml +++ b/rileylink/src/main/res/layout/rileylink_status_history_item.xml @@ -1,34 +1,50 @@ - + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_marginStart="4dp" + android:layout_marginBottom="4dp" + app:cardCornerRadius="4dp" + app:contentPadding="2dp"> - + - + - + - + + + + +