diff --git a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt index 36e3813a12..992b3e8771 100644 --- a/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt +++ b/app-wear-shared/shared/src/main/java/info/nightscout/rx/weardata/CustomWatchfaceFormat.kt @@ -116,8 +116,7 @@ enum class CwfMetadataKey(val key: String, @StringRes val label: Int, val isPref CWF_PREF_WATCH_SHOW_DIRECTION("key_show_direction", R.string.pref_show_direction_arrow, true), CWF_PREF_WATCH_SHOW_AGO("key_show_ago", R.string.pref_show_ago, true), CWF_PREF_WATCH_SHOW_BG("key_show_bg", R.string.pref_show_bg, true), - CWF_PREF_WATCH_SHOW_LOOP_STATUS("key_show_loop_status", R.string.pref_show_loop_status, true), - CWF_PREF_WATCH_SHOW_DATE("key_show_date", R.string.pref_show_date, true); + CWF_PREF_WATCH_SHOW_LOOP_STATUS("key_show_loop_status", R.string.pref_show_loop_status, true); companion object { @@ -126,41 +125,41 @@ enum class CwfMetadataKey(val key: String, @StringRes val label: Int, val isPref } } -enum class ViewKeys(val key: String, @StringRes val comment: Int?) { +enum class ViewKeys(val key: String, @StringRes val comment: Int) { - BACKGROUND("background", null), - CHART("chart", null), - COVER_CHART("cover_chart", null), - FREETEXT1("freetext1", null), - FREETEXT2("freetext2", null), - FREETEXT3("freetext3", null), - FREETEXT4("freetext4", null), - IOB1("iob1", null), - IOB2("iob2", null), - COB1("cob1", null), - COB2("cob2", null), - DELTA("delta", null), - AVG_DELTA("avg_delta", null), - UPLOADER_BATTERY("uploader_battery", null), - RIG_BATTERY("rig_battery", null), - BASALRATE("basalRate", null), - BGI("bgi", null), - TIME("time", null), - HOUR("hour", null), - MINUTE("minute", null), - SECOND("second", null), - TIMEPERIOD("timePeriod", null), - DAY_NAME("day_name", null), - DAY("day", null), - MONTH("month", null), - LOOP("loop", null), - DIRECTION("direction", null), - TIMESTAMP("timestamp", null), - SGV("sgv", null), - COVER_PLATE("cover_plate", null), - HOUR_HAND("hour_hand", null), - MINUTE_HAND("minute_hand", null), - SECOND_HAND("second_hand", null) + BACKGROUND("background", R.string.cwf_comment_background), + CHART("chart", R.string.cwf_comment_chart), + COVER_CHART("cover_chart", R.string.cwf_comment_cover_chart), + FREETEXT1("freetext1", R.string.cwf_comment_freetext1), + FREETEXT2("freetext2", R.string.cwf_comment_freetext2), + FREETEXT3("freetext3", R.string.cwf_comment_freetext3), + FREETEXT4("freetext4", R.string.cwf_comment_freetext4), + IOB1("iob1", R.string.cwf_comment_iob1), + IOB2("iob2", R.string.cwf_comment_iob2), + COB1("cob1", R.string.cwf_comment_cob1), + COB2("cob2", R.string.cwf_comment_cob2), + DELTA("delta", R.string.cwf_comment_delta), + AVG_DELTA("avg_delta", R.string.cwf_comment_avg_delta), + UPLOADER_BATTERY("uploader_battery", R.string.cwf_comment_uploader_battery), + RIG_BATTERY("rig_battery", R.string.cwf_comment_rig_battery), + BASALRATE("basalRate", R.string.cwf_comment_basalRate), + BGI("bgi", R.string.cwf_comment_bgi), + TIME("time", R.string.cwf_comment_time), + HOUR("hour", R.string.cwf_comment_hour), + MINUTE("minute", R.string.cwf_comment_minute), + SECOND("second", R.string.cwf_comment_second), + TIMEPERIOD("timePeriod", R.string.cwf_comment_timePeriod), + DAY_NAME("day_name", R.string.cwf_comment_day_name), + DAY("day", R.string.cwf_comment_day), + MONTH("month", R.string.cwf_comment_month), + LOOP("loop", R.string.cwf_comment_loop), + DIRECTION("direction", R.string.cwf_comment_direction), + TIMESTAMP("timestamp", R.string.cwf_comment_timestamp), + SGV("sgv", R.string.cwf_comment_sgv), + COVER_PLATE("cover_plate", R.string.cwf_comment_cover_plate), + HOUR_HAND("hour_hand", R.string.cwf_comment_hour_hand), + MINUTE_HAND("minute_hand", R.string.cwf_comment_minute_hand), + SECOND_HAND("second_hand", R.string.cwf_comment_second_hand); } enum class JsonKeys(val key: String, val viewType: ViewType, @StringRes val comment: Int?) { diff --git a/app-wear-shared/shared/src/main/res/values/strings.xml b/app-wear-shared/shared/src/main/res/values/strings.xml index 486bb43b7f..d383042197 100644 --- a/app-wear-shared/shared/src/main/res/values/strings.xml +++ b/app-wear-shared/shared/src/main/res/values/strings.xml @@ -48,7 +48,6 @@ Name: %1$s (%2$s) Comment: %1$s %1$s - Show Date Show IOB Show detailed IOB Show COB @@ -65,5 +64,38 @@ Show Ago Default watchface, you can click on EXPORT WATCHFACE button to generate a template Default Watchface + Background image + Graphs (BG, basal, prediction lines...) + Image in front of graph and behind text fields + Free text 1 + Free text 2 + Free text 3 + Free text 4 + IOB label or IOB Sum if detailed + IOB Sum or (Bolus_IOB|Basal_IOB) if detailed + COB label + COB value + Short BG delta + Average BG delta (15min) + Phone battery (%) + Global loop battery (%) + Basal Rate + BGI value + Time (HH:MM or HH:MM:SS) + Hour (HH) + Minute (MM) + Second (SS) + AM or PM + Name of day of the week + Day (DD) + Month name (short) + Loop status and ago + Direction arrow + Mintutes ago for last received BG + BG value + Cover image in front of text (dials...) + Image of hour hand (Analog Watch) + Image of minute hand (Analog Watch) + Image of second hand (Analog Watch) \ No newline at end of file diff --git a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt index d9c45ac812..8d24f7005e 100644 --- a/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt +++ b/plugins/main/src/main/java/info/nightscout/plugins/general/wear/activities/CwfInfosActivity.kt @@ -15,15 +15,19 @@ import info.nightscout.interfaces.versionChecker.VersionCheckerUtils import info.nightscout.plugins.R import info.nightscout.plugins.databinding.CwfInfosActivityBinding import info.nightscout.plugins.databinding.CwfInfosActivityPrefItemBinding +import info.nightscout.plugins.databinding.CwfInfosActivityViewItemBinding import info.nightscout.plugins.general.wear.WearPlugin import info.nightscout.rx.bus.RxBus import info.nightscout.rx.logging.AAPSLogger +import info.nightscout.rx.logging.LTag import info.nightscout.rx.weardata.CUSTOM_VERSION import info.nightscout.rx.weardata.CwfDrawableFileMap import info.nightscout.rx.weardata.CwfMetadataKey import info.nightscout.rx.weardata.CwfMetadataMap +import info.nightscout.rx.weardata.ViewKeys import info.nightscout.shared.interfaces.ResourceHelper import info.nightscout.shared.sharedPreferences.SP +import org.json.JSONObject import javax.inject.Inject class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { @@ -49,9 +53,6 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { updateGui() - - - // Add menu items without overriding methods in the Activity addMenuProvider(object : MenuProvider { override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {} @@ -87,20 +88,22 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { binding.cwfComment.text = rh.gs(CwfMetadataKey.CWF_COMMENT.label, metadata[CwfMetadataKey.CWF_COMMENT] ?: "") if (metadata.count { it.key.isPref } > 0) { binding.prefLayout.visibility = View.VISIBLE - binding.prefTitle.text = rh.gs(if (cwf_authorization) R.string.cwf_infos_pref_locked else R.string.cwf_infos_pref_requested) + binding.prefTitle.text = rh.gs(if (cwf_authorization) R.string.cwf_infos_pref_locked else R.string.cwf_infos_pref_required) binding.prefRecyclerview.layoutManager = LinearLayoutManager(this) binding.prefRecyclerview.adapter = PrefRecyclerViewAdapter( metadata.filter { it.key.isPref && (it.value.lowercase() == "true" || it.value.lowercase() == "false") }.toList() ) } else binding.prefLayout.visibility = View.GONE + binding.viewRecyclerview.layoutManager = LinearLayoutManager(this) + binding.viewRecyclerview.adapter = ViewRecyclerViewAdapter(listVisibleView(it.json)) } } - inner class PrefRecyclerViewAdapter internal constructor(private var prefList: List>) : RecyclerView.Adapter() { + inner class PrefRecyclerViewAdapter internal constructor(private var prefList: List>) : RecyclerView.Adapter() { - inner class CwfFileViewHolder(val cwfInfosActivityPrefItemBinding: CwfInfosActivityPrefItemBinding) : RecyclerView.ViewHolder(cwfInfosActivityPrefItemBinding.root) { + inner class CwfPrefViewHolder(val cwfInfosActivityPrefItemBinding: CwfInfosActivityPrefItemBinding) : RecyclerView.ViewHolder(cwfInfosActivityPrefItemBinding.root) { init { with(cwfInfosActivityPrefItemBinding) { root.isClickable = false @@ -108,16 +111,16 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { } } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CwfFileViewHolder { + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CwfPrefViewHolder { val binding = CwfInfosActivityPrefItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) - return CwfFileViewHolder(binding) + return CwfPrefViewHolder(binding) } override fun getItemCount(): Int { return prefList.size } - override fun onBindViewHolder(holder: CwfFileViewHolder, position: Int) { + override fun onBindViewHolder(holder: CwfPrefViewHolder, position: Int) { val pref = prefList[position] val key = pref.first val value = pref.second.lowercase().toBooleanStrictOrNull() // should never be null here, just safety to avoid exception @@ -128,6 +131,36 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { } } + inner class ViewRecyclerViewAdapter internal constructor(private var viewList: List>) : RecyclerView.Adapter() { + + inner class CwfViewHolder(val cwfInfosActivityViewItemBinding: CwfInfosActivityViewItemBinding) : RecyclerView.ViewHolder(cwfInfosActivityViewItemBinding.root) { + init { + with(cwfInfosActivityViewItemBinding) { + root.isClickable = false + } + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CwfViewHolder { + val binding = CwfInfosActivityViewItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return CwfViewHolder(binding) + } + + override fun getItemCount(): Int { + return viewList.size + } + + override fun onBindViewHolder(holder: CwfViewHolder, position: Int) { + val cwfView = viewList[position] + val key = cwfView.first.key + val value = cwfView.first.comment + val visible = cwfView.second // will be used if all keys included into RecyclerView + with(holder.cwfInfosActivityViewItemBinding) { + viewKey.text = "\"$key\":" + viewComment.text = rh.gs(value) + } + } + } private fun checkCustomVersion(metadata: CwfMetadataMap): Boolean { metadata[CwfMetadataKey.CWF_VERSION]?.let { version -> @@ -139,4 +172,24 @@ class CwfInfosActivity : TranslatedDaggerAppCompatActivity() { return false } + private fun listVisibleView(jsonString: String, allViews: Boolean = false): List> { + val json = JSONObject(jsonString) + + val visibleKeyPairs = mutableListOf>() + + for (viewKey in ViewKeys.values()) { + try { + val jsonValue = json.optJSONObject(viewKey.key) + if (jsonValue != null) { + val visibility = jsonValue.optString("visibility") == "visible" + if (visibility || allViews) + visibleKeyPairs.add(Pair(viewKey, visibility)) + } + } catch (e: Exception) { + aapsLogger.debug(LTag.WEAR, "Wrong key in json file: ${viewKey.key}") + } + } + return visibleKeyPairs + } + } \ No newline at end of file diff --git a/plugins/main/src/main/res/layout/cwf_infos_activity.xml b/plugins/main/src/main/res/layout/cwf_infos_activity.xml index 061c623e60..9871045d67 100644 --- a/plugins/main/src/main/res/layout/cwf_infos_activity.xml +++ b/plugins/main/src/main/res/layout/cwf_infos_activity.xml @@ -10,7 +10,7 @@ tools:context="info.nightscout.plugins.general.wear.activities.CwfInfosActivity"> @@ -117,7 +117,7 @@ android:layout_marginTop="15dp" android:paddingStart="0dp" android:paddingEnd="10dp" - android:text="@string/cwf_infos_pref_requested" + android:text="@string/cwf_infos_pref_required" android:textAlignment="viewStart" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?attr/importListFileNameColor" @@ -154,7 +154,7 @@ android:textAlignment="viewStart" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="?attr/importListFileNameColor" - android:textSize="15sp" /> + android:textSize="18sp" /> + + + + + + + + + + + + + + diff --git a/plugins/main/src/main/res/values/strings.xml b/plugins/main/src/main/res/values/strings.xml index 7670630b8c..99561c0930 100644 --- a/plugins/main/src/main/res/values/strings.xml +++ b/plugins/main/src/main/res/values/strings.xml @@ -366,9 +366,10 @@ Resend All Data Open Settings on Wear List of prefs locked by the Watchface - List of prefs requested by the Watchface + List of prefs required for the Watchface List of fields included into the Watchface + Ongoing Notification Shows an ongoing notification with a short overview of what your loop is doing diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt index c52d8a22ec..e36ed13137 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/CustomWatchface.kt @@ -496,8 +496,7 @@ class CustomWatchface : BaseWatchFace() { SHOW_AGO(CwfMetadataKey.CWF_PREF_WATCH_SHOW_AGO.key, R.string.key_show_ago), SHOW_BG(CwfMetadataKey.CWF_PREF_WATCH_SHOW_BG.key, R.string.key_show_bg), SHOW_BGI(CwfMetadataKey.CWF_PREF_WATCH_SHOW_BGI.key, R.string.key_show_bgi), - SHOW_LOOP_STATUS(CwfMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status), - SHOW_DATE(CwfMetadataKey.CWF_PREF_WATCH_SHOW_DATE.key, R.string.key_show_date) + SHOW_LOOP_STATUS(CwfMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status) } } diff --git a/wear/src/main/res/xml/watch_face_configuration_custom.xml b/wear/src/main/res/xml/watch_face_configuration_custom.xml index 52182a0608..ff998be701 100644 --- a/wear/src/main/res/xml/watch_face_configuration_custom.xml +++ b/wear/src/main/res/xml/watch_face_configuration_custom.xml @@ -9,13 +9,6 @@ app:wear_iconOff="@drawable/settings_off" app:wear_iconOn="@drawable/settings_on" /> - -