Wear cwf Refactoring Rename CustomWatchface by Cwf everywhere
This commit is contained in:
parent
fb9991ad4b
commit
984767d80f
11 changed files with 100 additions and 101 deletions
|
@ -1,5 +1,5 @@
|
|||
package info.nightscout.rx.events
|
||||
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
|
||||
class EventWearUpdateGui(val customWatchfaceData: CustomWatchfaceData? = null, val exportFile: Boolean = false) : Event()
|
||||
class EventWearUpdateGui(val customWatchfaceData: CwfData? = null, val exportFile: Boolean = false) : Event()
|
|
@ -19,7 +19,7 @@ import java.util.zip.ZipOutputStream
|
|||
|
||||
val CUSTOM_VERSION = "0.10"
|
||||
|
||||
enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon: Int?, val fileName: String) {
|
||||
enum class CwfDrawableFileMap(val key: String, @DrawableRes val icon: Int?, val fileName: String) {
|
||||
UNKNOWN("unknown", null, "Unknown"),
|
||||
CUSTOM_WATCHFACE("customWatchface", R.drawable.watchface_custom, "CustomWatchface"),
|
||||
BACKGROUND(ViewKeys.BACKGROUND.key, R.drawable.background, "Background"),
|
||||
|
@ -33,10 +33,10 @@ enum class CustomWatchfaceDrawableDataKey(val key: String, @DrawableRes val icon
|
|||
|
||||
companion object {
|
||||
|
||||
fun fromKey(key: String): CustomWatchfaceDrawableDataKey =
|
||||
fun fromKey(key: String): CwfDrawableFileMap =
|
||||
values().firstOrNull { it.key == key } ?: UNKNOWN
|
||||
|
||||
fun fromFileName(file: String): CustomWatchfaceDrawableDataKey = values().firstOrNull { it.fileName == file.substringBeforeLast(".") } ?: UNKNOWN
|
||||
fun fromFileName(file: String): CwfDrawableFileMap = values().firstOrNull { it.fileName == file.substringBeforeLast(".") } ?: UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,13 +87,13 @@ data class DrawableData(val value: ByteArray, val format: DrawableFormat) {
|
|||
}
|
||||
}
|
||||
|
||||
typealias CustomWatchfaceDrawableDataMap = MutableMap<CustomWatchfaceDrawableDataKey, DrawableData>
|
||||
typealias CustomWatchfaceMetadataMap = MutableMap<CustomWatchfaceMetadataKey, String>
|
||||
typealias CwfDrawableDataMap = MutableMap<CwfDrawableFileMap, DrawableData>
|
||||
typealias CwfMetadataMap = MutableMap<CwfMetadataKey, String>
|
||||
|
||||
@Serializable
|
||||
data class CustomWatchfaceData(val json: String, var metadata: CustomWatchfaceMetadataMap, val drawableDatas: CustomWatchfaceDrawableDataMap)
|
||||
data class CwfData(val json: String, var metadata: CwfMetadataMap, val drawableDatas: CwfDrawableDataMap)
|
||||
|
||||
enum class CustomWatchfaceMetadataKey(val key: String, @StringRes val label: Int, val isPref: Boolean) {
|
||||
enum class CwfMetadataKey(val key: String, @StringRes val label: Int, val isPref: Boolean) {
|
||||
|
||||
CWF_NAME("name", R.string.metadata_label_watchface_name, false),
|
||||
CWF_FILENAME("filename", R.string.metadata_wear_import_filename, false),
|
||||
|
@ -120,7 +120,7 @@ enum class CustomWatchfaceMetadataKey(val key: String, @StringRes val label: Int
|
|||
|
||||
companion object {
|
||||
|
||||
fun fromKey(key: String): CustomWatchfaceMetadataKey? =
|
||||
fun fromKey(key: String): CwfMetadataKey? =
|
||||
values().firstOrNull { it.key == key }
|
||||
}
|
||||
}
|
||||
|
@ -223,13 +223,13 @@ enum class ViewType(@StringRes val comment: Int?) {
|
|||
class ZipWatchfaceFormat {
|
||||
companion object {
|
||||
|
||||
const val CUSTOM_WF_EXTENTION = ".zip"
|
||||
const val CUSTOM_JSON_FILE = "CustomWatchface.json"
|
||||
const val CWF_EXTENTION = ".zip"
|
||||
const val CWF_JSON_FILE = "CustomWatchface.json"
|
||||
|
||||
fun loadCustomWatchface(cwfFile: File, authorization: Boolean): CustomWatchfaceData? {
|
||||
fun loadCustomWatchface(cwfFile: File, authorization: Boolean): CwfData? {
|
||||
var json = JSONObject()
|
||||
var metadata: CustomWatchfaceMetadataMap = mutableMapOf()
|
||||
val drawableDatas: CustomWatchfaceDrawableDataMap = mutableMapOf()
|
||||
var metadata: CwfMetadataMap = mutableMapOf()
|
||||
val drawableDatas: CwfDrawableDataMap = mutableMapOf()
|
||||
|
||||
try {
|
||||
val zipInputStream = ZipInputStream(cwfFile.inputStream())
|
||||
|
@ -246,25 +246,25 @@ class ZipWatchfaceFormat {
|
|||
}
|
||||
zipInputStream.closeEntry()
|
||||
|
||||
if (entryName == CUSTOM_JSON_FILE) {
|
||||
if (entryName == CWF_JSON_FILE) {
|
||||
val jsonString = byteArrayOutputStream.toByteArray().toString(Charsets.UTF_8)
|
||||
json = JSONObject(jsonString)
|
||||
metadata = loadMetadata(json)
|
||||
metadata[CustomWatchfaceMetadataKey.CWF_FILENAME] = cwfFile.name
|
||||
metadata[CustomWatchfaceMetadataKey.CWF_AUTHORIZATION] = authorization.toString()
|
||||
metadata[CwfMetadataKey.CWF_FILENAME] = cwfFile.name
|
||||
metadata[CwfMetadataKey.CWF_AUTHORIZATION] = authorization.toString()
|
||||
} else {
|
||||
val customWatchfaceDrawableData = CustomWatchfaceDrawableDataKey.fromFileName(entryName)
|
||||
val cwfDrawableFileMap = CwfDrawableFileMap.fromFileName(entryName)
|
||||
val drawableFormat = DrawableFormat.fromFileName(entryName)
|
||||
if (customWatchfaceDrawableData != CustomWatchfaceDrawableDataKey.UNKNOWN && drawableFormat != DrawableFormat.UNKNOWN) {
|
||||
drawableDatas[customWatchfaceDrawableData] = DrawableData(byteArrayOutputStream.toByteArray(), drawableFormat)
|
||||
if (cwfDrawableFileMap != CwfDrawableFileMap.UNKNOWN && drawableFormat != DrawableFormat.UNKNOWN) {
|
||||
drawableDatas[cwfDrawableFileMap] = DrawableData(byteArrayOutputStream.toByteArray(), drawableFormat)
|
||||
}
|
||||
}
|
||||
zipEntry = zipInputStream.nextEntry
|
||||
}
|
||||
|
||||
// Valid CWF file must contains a valid json file with a name within metadata and a custom watchface image
|
||||
if (metadata.containsKey(CustomWatchfaceMetadataKey.CWF_NAME) && drawableDatas.containsKey(CustomWatchfaceDrawableDataKey.CUSTOM_WATCHFACE))
|
||||
return CustomWatchfaceData(json.toString(4), metadata, drawableDatas)
|
||||
if (metadata.containsKey(CwfMetadataKey.CWF_NAME) && drawableDatas.containsKey(CwfDrawableFileMap.CUSTOM_WATCHFACE))
|
||||
return CwfData(json.toString(4), metadata, drawableDatas)
|
||||
else
|
||||
return null
|
||||
|
||||
|
@ -273,14 +273,14 @@ class ZipWatchfaceFormat {
|
|||
}
|
||||
}
|
||||
|
||||
fun saveCustomWatchface(file: File, customWatchface: CustomWatchfaceData) {
|
||||
fun saveCustomWatchface(file: File, customWatchface: CwfData) {
|
||||
|
||||
try {
|
||||
val outputStream = FileOutputStream(file)
|
||||
val zipOutputStream = ZipOutputStream(BufferedOutputStream(outputStream))
|
||||
|
||||
// Ajouter le fichier JSON au ZIP
|
||||
val jsonEntry = ZipEntry(CUSTOM_JSON_FILE)
|
||||
val jsonEntry = ZipEntry(CWF_JSON_FILE)
|
||||
zipOutputStream.putNextEntry(jsonEntry)
|
||||
zipOutputStream.write(customWatchface.json.toByteArray())
|
||||
zipOutputStream.closeEntry()
|
||||
|
@ -299,13 +299,13 @@ class ZipWatchfaceFormat {
|
|||
|
||||
}
|
||||
|
||||
fun loadMetadata(contents: JSONObject): CustomWatchfaceMetadataMap {
|
||||
val metadata: CustomWatchfaceMetadataMap = mutableMapOf()
|
||||
fun loadMetadata(contents: JSONObject): CwfMetadataMap {
|
||||
val metadata: CwfMetadataMap = mutableMapOf()
|
||||
|
||||
if (contents.has(JsonKeys.METADATA.key)) {
|
||||
val meta = contents.getJSONObject(JsonKeys.METADATA.key)
|
||||
for (key in meta.keys()) {
|
||||
val metaKey = CustomWatchfaceMetadataKey.fromKey(key)
|
||||
val metaKey = CwfMetadataKey.fromKey(key)
|
||||
if (metaKey != null) {
|
||||
metadata[metaKey] = meta.getString(key)
|
||||
}
|
||||
|
|
|
@ -284,7 +284,7 @@ sealed class EventData : Event() {
|
|||
}
|
||||
@Serializable
|
||||
data class ActionSetCustomWatchface(
|
||||
val customWatchfaceData: CustomWatchfaceData
|
||||
val customWatchfaceData: CwfData
|
||||
) : EventData()
|
||||
|
||||
@Serializable
|
||||
|
|
|
@ -2,7 +2,7 @@ package info.nightscout.interfaces.maintenance
|
|||
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
|
||||
interface ImportExportPrefs {
|
||||
|
||||
|
@ -11,7 +11,7 @@ interface ImportExportPrefs {
|
|||
fun importSharedPreferences(fragment: Fragment)
|
||||
fun importCustomWatchface(activity: FragmentActivity)
|
||||
fun importCustomWatchface(fragment: Fragment)
|
||||
fun exportCustomWatchface(customWatchface: CustomWatchfaceData)
|
||||
fun exportCustomWatchface(customWatchface: CwfData)
|
||||
fun prefsFileExists(): Boolean
|
||||
fun verifyStoragePermissions(fragment: Fragment, onGranted: Runnable)
|
||||
fun exportSharedPreferences(f: Fragment)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package info.nightscout.interfaces.maintenance
|
||||
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import java.io.File
|
||||
|
||||
interface PrefFileListProvider {
|
||||
|
@ -13,7 +13,7 @@ interface PrefFileListProvider {
|
|||
fun newExportCsvFile(): File
|
||||
fun newCwfFile(filename: String): File
|
||||
fun listPreferenceFiles(loadMetadata: Boolean = false): MutableList<PrefsFile>
|
||||
fun listCustomWatchfaceFiles(): MutableList<CustomWatchfaceData>
|
||||
fun listCustomWatchfaceFiles(): MutableList<CwfData>
|
||||
fun checkMetadata(metadata: Map<PrefsMetadataKey, PrefMetadata>): Map<PrefsMetadataKey, PrefMetadata>
|
||||
fun formatExportedAgo(utcTime: String): String
|
||||
}
|
|
@ -55,8 +55,8 @@ import info.nightscout.rx.events.EventAppExit
|
|||
import info.nightscout.rx.events.EventDiaconnG8PumpLogReset
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import info.nightscout.rx.weardata.CwfMetadataKey
|
||||
import info.nightscout.rx.weardata.ZipWatchfaceFormat
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -315,9 +315,9 @@ class ImportExportPrefsImpl @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
override fun exportCustomWatchface(customWatchface: CustomWatchfaceData) {
|
||||
override fun exportCustomWatchface(customWatchface: CwfData) {
|
||||
prefFileList.ensureExportDirExists()
|
||||
val newFile = prefFileList.newCwfFile(customWatchface.metadata[CustomWatchfaceMetadataKey.CWF_FILENAME] ?:"")
|
||||
val newFile = prefFileList.newCwfFile(customWatchface.metadata[CwfMetadataKey.CWF_FILENAME] ?:"")
|
||||
ZipWatchfaceFormat.saveCustomWatchface(newFile, customWatchface)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import info.nightscout.interfaces.maintenance.PrefsMetadataKey
|
|||
import info.nightscout.interfaces.maintenance.PrefsStatus
|
||||
import info.nightscout.interfaces.storage.Storage
|
||||
import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import info.nightscout.rx.weardata.ZipWatchfaceFormat
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -92,11 +92,11 @@ class PrefFileListProviderImpl @Inject constructor(
|
|||
return prefFiles
|
||||
}
|
||||
|
||||
override fun listCustomWatchfaceFiles(): MutableList<CustomWatchfaceData> {
|
||||
val customWatchfaceFiles = mutableListOf<CustomWatchfaceData>()
|
||||
override fun listCustomWatchfaceFiles(): MutableList<CwfData> {
|
||||
val customWatchfaceFiles = mutableListOf<CwfData>()
|
||||
val customAwtchfaceAuthorization = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false)
|
||||
// searching dedicated dir, only for new CWF format
|
||||
exportsPath.walk().filter { it.isFile && it.name.endsWith(ZipWatchfaceFormat.CUSTOM_WF_EXTENTION) }.forEach { file ->
|
||||
exportsPath.walk().filter { it.isFile && it.name.endsWith(ZipWatchfaceFormat.CWF_EXTENTION) }.forEach { file ->
|
||||
// Here loadCustomWatchface will unzip, check and load CustomWatchface
|
||||
ZipWatchfaceFormat.loadCustomWatchface(file, customAwtchfaceAuthorization)?.also { customWatchface ->
|
||||
customWatchfaceFiles.add(customWatchface)
|
||||
|
@ -148,7 +148,7 @@ class PrefFileListProviderImpl @Inject constructor(
|
|||
}
|
||||
override fun newCwfFile(filename: String): File {
|
||||
val timeLocal = LocalDateTime.now().toString(DateTimeFormat.forPattern("yyyy-MM-dd'_'HHmmss"))
|
||||
return File(exportsPath, "${filename}_$timeLocal${ZipWatchfaceFormat.CUSTOM_WF_EXTENTION}")
|
||||
return File(exportsPath, "${filename}_$timeLocal${ZipWatchfaceFormat.CWF_EXTENTION}")
|
||||
}
|
||||
|
||||
// check metadata for known issues, change their status and add info with explanations
|
||||
|
|
|
@ -19,10 +19,10 @@ import info.nightscout.rx.bus.RxBus
|
|||
import info.nightscout.rx.events.EventMobileDataToWear
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.weardata.CUSTOM_VERSION
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataKey
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey.*
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataMap
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import info.nightscout.rx.weardata.CwfDrawableFileMap
|
||||
import info.nightscout.rx.weardata.CwfMetadataKey.*
|
||||
import info.nightscout.rx.weardata.CwfMetadataMap
|
||||
import info.nightscout.rx.weardata.EventData
|
||||
import info.nightscout.shared.extensions.toVisibility
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
|
@ -55,7 +55,7 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
|
|||
binding.recyclerview.adapter = RecyclerViewAdapter(prefFileListProvider.listCustomWatchfaceFiles())
|
||||
}
|
||||
|
||||
inner class RecyclerViewAdapter internal constructor(private var customWatchfaceFileList: List<CustomWatchfaceData>) : RecyclerView.Adapter<RecyclerViewAdapter.PrefFileViewHolder>() {
|
||||
inner class RecyclerViewAdapter internal constructor(private var customWatchfaceFileList: List<CwfData>) : RecyclerView.Adapter<RecyclerViewAdapter.PrefFileViewHolder>() {
|
||||
|
||||
inner class PrefFileViewHolder(val customWatchfaceImportListItemBinding: CustomWatchfaceImportListItemBinding) : RecyclerView.ViewHolder(customWatchfaceImportListItemBinding.root) {
|
||||
|
||||
|
@ -63,7 +63,7 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
|
|||
with(customWatchfaceImportListItemBinding) {
|
||||
root.isClickable = true
|
||||
customWatchfaceImportListItemBinding.root.setOnClickListener {
|
||||
val customWatchfaceFile = filelistName.tag as CustomWatchfaceData
|
||||
val customWatchfaceFile = filelistName.tag as CwfData
|
||||
val customWF = EventData.ActionSetCustomWatchface(customWatchfaceFile)
|
||||
val i = Intent()
|
||||
setResult(FragmentActivity.RESULT_OK, i)
|
||||
|
@ -86,7 +86,7 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
|
|||
override fun onBindViewHolder(holder: PrefFileViewHolder, position: Int) {
|
||||
val customWatchfaceFile = customWatchfaceFileList[position]
|
||||
val metadata = customWatchfaceFile.metadata
|
||||
val drawable = customWatchfaceFile.drawableDatas[CustomWatchfaceDrawableDataKey
|
||||
val drawable = customWatchfaceFile.drawableDatas[CwfDrawableFileMap
|
||||
.CUSTOM_WATCHFACE]?.toDrawable(resources)
|
||||
with(holder.customWatchfaceImportListItemBinding) {
|
||||
filelistName.text = rh.gs(info.nightscout.shared.R.string.metadata_wear_import_filename, metadata[CWF_FILENAME])
|
||||
|
@ -115,7 +115,7 @@ class CustomWatchfaceImportListActivity: TranslatedDaggerAppCompatActivity() {
|
|||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private fun checkCustomVersion(metadata: CustomWatchfaceMetadataMap): Boolean {
|
||||
private fun checkCustomVersion(metadata: CwfMetadataMap): Boolean {
|
||||
metadata[CWF_VERSION]?.let { version ->
|
||||
val currentAppVer = versionCheckerUtils.versionDigits(CUSTOM_VERSION)
|
||||
val metadataVer = versionCheckerUtils.versionDigits(version)
|
||||
|
|
|
@ -4,7 +4,6 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.StringRes
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.core.ui.toast.ToastUtils
|
||||
import info.nightscout.core.utils.fabric.FabricPrivacy
|
||||
|
@ -16,9 +15,9 @@ import info.nightscout.rx.bus.RxBus
|
|||
import info.nightscout.rx.events.EventMobileToWear
|
||||
import info.nightscout.rx.events.EventWearUpdateGui
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataKey
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import info.nightscout.rx.weardata.CwfDrawableFileMap
|
||||
import info.nightscout.rx.weardata.CwfMetadataKey
|
||||
import info.nightscout.rx.weardata.EventData
|
||||
import info.nightscout.shared.extensions.toVisibility
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
|
@ -106,8 +105,8 @@ class WearFragment : DaggerFragment() {
|
|||
_binding ?: return
|
||||
wearPlugin.savedCustomWatchface?.let {
|
||||
wearPlugin.checkCustomWatchfacePreferences()
|
||||
binding.customName.text = rh.gs(R.string.wear_custom_watchface, it.metadata[CustomWatchfaceMetadataKey.CWF_NAME])
|
||||
binding.coverChart.setImageDrawable(it.drawableDatas[CustomWatchfaceDrawableDataKey.CUSTOM_WATCHFACE]?.toDrawable(resources))
|
||||
binding.customName.text = rh.gs(R.string.wear_custom_watchface, it.metadata[CwfMetadataKey.CWF_NAME])
|
||||
binding.coverChart.setImageDrawable(it.drawableDatas[CwfDrawableFileMap.CUSTOM_WATCHFACE]?.toDrawable(resources))
|
||||
} ?:apply {
|
||||
binding.customName.text = rh.gs(R.string.wear_custom_watchface, rh.gs(info.nightscout.shared.R.string.wear_default_watchface))
|
||||
binding.coverChart.setImageDrawable(null)
|
||||
|
@ -116,7 +115,7 @@ class WearFragment : DaggerFragment() {
|
|||
binding.customWatchfaceLayout.visibility = (wearPlugin.connectedDevice != rh.gs(R.string.no_watch_connected)).toVisibility()
|
||||
}
|
||||
|
||||
private fun loadCustom(cwf: CustomWatchfaceData) {
|
||||
private fun loadCustom(cwf: CwfData) {
|
||||
wearPlugin.savedCustomWatchface = cwf
|
||||
}
|
||||
}
|
|
@ -20,8 +20,8 @@ import info.nightscout.rx.events.EventOverviewBolusProgress
|
|||
import info.nightscout.rx.events.EventPreferenceChange
|
||||
import info.nightscout.rx.events.EventWearUpdateGui
|
||||
import info.nightscout.rx.logging.AAPSLogger
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import info.nightscout.rx.weardata.CwfMetadataKey
|
||||
import info.nightscout.rx.weardata.EventData
|
||||
import info.nightscout.shared.interfaces.ResourceHelper
|
||||
import info.nightscout.shared.sharedPreferences.SP
|
||||
|
@ -58,7 +58,7 @@ class WearPlugin @Inject constructor(
|
|||
private val disposable = CompositeDisposable()
|
||||
|
||||
var connectedDevice = "---"
|
||||
var savedCustomWatchface: CustomWatchfaceData? = null
|
||||
var savedCustomWatchface: CwfData? = null
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
|
@ -113,10 +113,10 @@ class WearPlugin @Inject constructor(
|
|||
fun checkCustomWatchfacePreferences() {
|
||||
savedCustomWatchface?.let { cwf ->
|
||||
val cwf_authorization = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false)
|
||||
if (cwf_authorization != cwf.metadata[CustomWatchfaceMetadataKey.CWF_AUTHORIZATION]?.toBooleanStrictOrNull()) {
|
||||
if (cwf_authorization != cwf.metadata[CwfMetadataKey.CWF_AUTHORIZATION]?.toBooleanStrictOrNull()) {
|
||||
// resend new customWatchface to Watch with updated authorization for preferences update
|
||||
val newCwf = cwf.copy()
|
||||
newCwf.metadata[CustomWatchfaceMetadataKey.CWF_AUTHORIZATION] = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false).toString()
|
||||
newCwf.metadata[CwfMetadataKey.CWF_AUTHORIZATION] = sp.getBoolean(info.nightscout.core.utils.R.string.key_wear_custom_watchface_autorization, false).toString()
|
||||
rxBus.send(EventMobileDataToWear(EventData.ActionSetCustomWatchface(newCwf)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,11 +33,11 @@ import info.nightscout.androidaps.databinding.ActivityCustomBinding
|
|||
import info.nightscout.androidaps.watchfaces.utils.BaseWatchFace
|
||||
import info.nightscout.rx.logging.LTag
|
||||
import info.nightscout.rx.weardata.CUSTOM_VERSION
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceData
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataKey
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceDrawableDataMap
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataKey
|
||||
import info.nightscout.rx.weardata.CustomWatchfaceMetadataMap
|
||||
import info.nightscout.rx.weardata.CwfData
|
||||
import info.nightscout.rx.weardata.CwfDrawableFileMap
|
||||
import info.nightscout.rx.weardata.CwfDrawableDataMap
|
||||
import info.nightscout.rx.weardata.CwfMetadataKey
|
||||
import info.nightscout.rx.weardata.CwfMetadataMap
|
||||
import info.nightscout.rx.weardata.DrawableData
|
||||
import info.nightscout.rx.weardata.DrawableFormat
|
||||
import info.nightscout.rx.weardata.EventData
|
||||
|
@ -166,10 +166,10 @@ class CustomWatchface : BaseWatchFace() {
|
|||
else -> midColor
|
||||
}
|
||||
val backGroundDrawable = when (singleBg.sgvLevel) {
|
||||
1L -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND_HIGH]?.toDrawable(resources) ?: drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||
0L -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||
-1L -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND_LOW]?.toDrawable(resources) ?: drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||
else -> drawableDataMap[CustomWatchfaceDrawableDataKey.BACKGROUND]?.toDrawable(resources)
|
||||
1L -> drawableDataMap[CwfDrawableFileMap.BACKGROUND_HIGH]?.toDrawable(resources) ?: drawableDataMap[CwfDrawableFileMap.BACKGROUND]?.toDrawable(resources)
|
||||
0L -> drawableDataMap[CwfDrawableFileMap.BACKGROUND]?.toDrawable(resources)
|
||||
-1L -> drawableDataMap[CwfDrawableFileMap.BACKGROUND_LOW]?.toDrawable(resources) ?: drawableDataMap[CwfDrawableFileMap.BACKGROUND]?.toDrawable(resources)
|
||||
else -> drawableDataMap[CwfDrawableFileMap.BACKGROUND]?.toDrawable(resources)
|
||||
}
|
||||
|
||||
binding.mainLayout.forEach { view ->
|
||||
|
@ -201,10 +201,10 @@ class CustomWatchface : BaseWatchFace() {
|
|||
|
||||
if (view is ImageView) {
|
||||
view.clearColorFilter()
|
||||
val drawable = if (id.key == CustomWatchfaceDrawableDataKey.BACKGROUND.key)
|
||||
val drawable = if (id.key == CwfDrawableFileMap.BACKGROUND.key)
|
||||
backGroundDrawable
|
||||
else
|
||||
drawableDataMap[CustomWatchfaceDrawableDataKey.fromKey(id.key)]?.toDrawable(resources)
|
||||
drawableDataMap[CwfDrawableFileMap.fromKey(id.key)]?.toDrawable(resources)
|
||||
drawable?.let {
|
||||
if (viewJson.has(COLOR.key))
|
||||
it.colorFilter = changeDrawableColor(getColor(viewJson.getString(COLOR.key)))
|
||||
|
@ -212,7 +212,7 @@ class CustomWatchface : BaseWatchFace() {
|
|||
it.clearColorFilter()
|
||||
view.setImageDrawable(it)
|
||||
} ?: apply {
|
||||
view.setImageDrawable(CustomWatchfaceDrawableDataKey.fromKey(id.key).icon?.let { context.getDrawable(it) })
|
||||
view.setImageDrawable(CwfDrawableFileMap.fromKey(id.key).icon?.let { context.getDrawable(it) })
|
||||
if (viewJson.has(COLOR.key))
|
||||
view.setColorFilter(getColor(viewJson.getString(COLOR.key)))
|
||||
else
|
||||
|
@ -237,12 +237,12 @@ class CustomWatchface : BaseWatchFace() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun updatePref(metadata: CustomWatchfaceMetadataMap) {
|
||||
val cwf_authorization = metadata[CustomWatchfaceMetadataKey.CWF_AUTHORIZATION]?.toBooleanStrictOrNull()
|
||||
private fun updatePref(metadata: CwfMetadataMap) {
|
||||
val cwf_authorization = metadata[CwfMetadataKey.CWF_AUTHORIZATION]?.toBooleanStrictOrNull()
|
||||
cwf_authorization?.let { authorization ->
|
||||
if (authorization) {
|
||||
PrefMap.values().forEach { pref ->
|
||||
metadata[CustomWatchfaceMetadataKey.fromKey(pref.key)]?.toBooleanStrictOrNull()?.let { sp.putBoolean(pref.prefKey, it) }
|
||||
metadata[CwfMetadataKey.fromKey(pref.key)]?.toBooleanStrictOrNull()?.let { sp.putBoolean(pref.prefKey, it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -250,13 +250,13 @@ class CustomWatchface : BaseWatchFace() {
|
|||
|
||||
private fun defaultWatchface(): EventData.ActionSetCustomWatchface {
|
||||
val metadata = JSONObject()
|
||||
.put(CustomWatchfaceMetadataKey.CWF_NAME.key, getString(info.nightscout.shared.R.string.wear_default_watchface))
|
||||
.put(CustomWatchfaceMetadataKey.CWF_FILENAME.key, getString(info.nightscout.shared.R.string.wear_default_watchface))
|
||||
.put(CustomWatchfaceMetadataKey.CWF_AUTHOR.key, "Philoul")
|
||||
.put(CustomWatchfaceMetadataKey.CWF_CREATED_AT.key, dateUtil.dateString(dateUtil.now()))
|
||||
.put(CustomWatchfaceMetadataKey.CWF_AUTHOR_VERSION.key, CUSTOM_VERSION)
|
||||
.put(CustomWatchfaceMetadataKey.CWF_VERSION.key, CUSTOM_VERSION)
|
||||
.put(CustomWatchfaceMetadataKey.CWF_COMMENT.key, getString(info.nightscout.shared.R.string.default_custom_watchface_comment))
|
||||
.put(CwfMetadataKey.CWF_NAME.key, getString(info.nightscout.shared.R.string.wear_default_watchface))
|
||||
.put(CwfMetadataKey.CWF_FILENAME.key, getString(info.nightscout.shared.R.string.wear_default_watchface))
|
||||
.put(CwfMetadataKey.CWF_AUTHOR.key, "Philoul")
|
||||
.put(CwfMetadataKey.CWF_CREATED_AT.key, dateUtil.dateString(dateUtil.now()))
|
||||
.put(CwfMetadataKey.CWF_AUTHOR_VERSION.key, CUSTOM_VERSION)
|
||||
.put(CwfMetadataKey.CWF_VERSION.key, CUSTOM_VERSION)
|
||||
.put(CwfMetadataKey.CWF_COMMENT.key, getString(info.nightscout.shared.R.string.default_custom_watchface_comment))
|
||||
val json = JSONObject()
|
||||
.put(METADATA.key, metadata)
|
||||
.put(HIGHCOLOR.key, String.format("#%06X", 0xFFFFFF and highColor))
|
||||
|
@ -304,12 +304,12 @@ class CustomWatchface : BaseWatchFace() {
|
|||
}
|
||||
}
|
||||
val metadataMap = ZipWatchfaceFormat.loadMetadata(json)
|
||||
val drawableDataMap: CustomWatchfaceDrawableDataMap = mutableMapOf()
|
||||
val drawableDataMap: CwfDrawableDataMap = mutableMapOf()
|
||||
getResourceByteArray(info.nightscout.shared.R.drawable.watchface_custom)?.let {
|
||||
val drawableData = DrawableData(it, DrawableFormat.PNG)
|
||||
drawableDataMap[CustomWatchfaceDrawableDataKey.CUSTOM_WATCHFACE] = drawableData
|
||||
drawableDataMap[CwfDrawableFileMap.CUSTOM_WATCHFACE] = drawableData
|
||||
}
|
||||
return EventData.ActionSetCustomWatchface(CustomWatchfaceData(json.toString(4), metadataMap, drawableDataMap))
|
||||
return EventData.ActionSetCustomWatchface(CwfData(json.toString(4), metadataMap, drawableDataMap))
|
||||
}
|
||||
|
||||
private fun setDefaultColors() {
|
||||
|
@ -483,20 +483,20 @@ class CustomWatchface : BaseWatchFace() {
|
|||
|
||||
// This class containt mapping between keys used within json of Custom Watchface and preferences
|
||||
private enum class PrefMap(val key: String, @StringRes val prefKey: Int) {
|
||||
SHOW_IOB(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_IOB.key, R.string.key_show_iob),
|
||||
SHOW_DETAILED_IOB(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_DETAILED_IOB.key, R.string.key_show_detailed_iob),
|
||||
SHOW_COB(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_COB.key, R.string.key_show_cob),
|
||||
SHOW_DELTA(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_DELTA.key, R.string.key_show_delta),
|
||||
SHOW_AVG_DELTA(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_AVG_DELTA.key, R.string.key_show_avg_delta),
|
||||
SHOW_DETAILED_DELTA(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_DETAILED_DELTA.key, R.string.key_show_detailed_delta),
|
||||
SHOW_UPLOADER_BATTERY(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_UPLOADER_BATTERY.key, R.string.key_show_uploader_battery),
|
||||
SHOW_RIG_BATTERY(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_RIG_BATTERY.key, R.string.key_show_rig_battery),
|
||||
SHOW_TEMP_BASAL(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_TEMP_BASAL.key, R.string.key_show_temp_basal),
|
||||
SHOW_DIRECTION(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_DIRECTION.key, R.string.key_show_direction),
|
||||
SHOW_AGO(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_AGO.key, R.string.key_show_ago),
|
||||
SHOW_BG(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_BG.key, R.string.key_show_bg),
|
||||
SHOW_BGI(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_BGI.key, R.string.key_show_bgi),
|
||||
SHOW_LOOP_STATUS(CustomWatchfaceMetadataKey.CWF_PREF_WATCH_SHOW_LOOP_STATUS.key, R.string.key_show_external_status)
|
||||
SHOW_IOB(CwfMetadataKey.CWF_PREF_WATCH_SHOW_IOB.key, R.string.key_show_iob),
|
||||
SHOW_DETAILED_IOB(CwfMetadataKey.CWF_PREF_WATCH_SHOW_DETAILED_IOB.key, R.string.key_show_detailed_iob),
|
||||
SHOW_COB(CwfMetadataKey.CWF_PREF_WATCH_SHOW_COB.key, R.string.key_show_cob),
|
||||
SHOW_DELTA(CwfMetadataKey.CWF_PREF_WATCH_SHOW_DELTA.key, R.string.key_show_delta),
|
||||
SHOW_AVG_DELTA(CwfMetadataKey.CWF_PREF_WATCH_SHOW_AVG_DELTA.key, R.string.key_show_avg_delta),
|
||||
SHOW_DETAILED_DELTA(CwfMetadataKey.CWF_PREF_WATCH_SHOW_DETAILED_DELTA.key, R.string.key_show_detailed_delta),
|
||||
SHOW_UPLOADER_BATTERY(CwfMetadataKey.CWF_PREF_WATCH_SHOW_UPLOADER_BATTERY.key, R.string.key_show_uploader_battery),
|
||||
SHOW_RIG_BATTERY(CwfMetadataKey.CWF_PREF_WATCH_SHOW_RIG_BATTERY.key, R.string.key_show_rig_battery),
|
||||
SHOW_TEMP_BASAL(CwfMetadataKey.CWF_PREF_WATCH_SHOW_TEMP_BASAL.key, R.string.key_show_temp_basal),
|
||||
SHOW_DIRECTION(CwfMetadataKey.CWF_PREF_WATCH_SHOW_DIRECTION.key, R.string.key_show_direction),
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue