diff --git a/mobile/src/main/java/org/openhab/habdroid/model/ServerProperties.kt b/mobile/src/main/java/org/openhab/habdroid/model/ServerProperties.kt index 919d073a69..c8e780bdde 100644 --- a/mobile/src/main/java/org/openhab/habdroid/model/ServerProperties.kt +++ b/mobile/src/main/java/org/openhab/habdroid/model/ServerProperties.kt @@ -61,6 +61,7 @@ data class ServerProperties(val flags: Int, val sitemaps: List) : Parce const val SERVER_FLAG_SITEMAP_HAS_INVISIBLE_WIDGETS = 1 shl 5 const val SERVER_FLAG_SUPPORTS_ANY_FORMAT_ICON = 1 shl 6 const val SERVER_FLAG_OH3_UI = 1 shl 7 + const val SERVER_FLAG_TRANSPARENT_CHARTS = 1 shl 8 class UpdateHandle internal constructor(internal val scope: CoroutineScope) { internal var job: Job? = null @@ -125,6 +126,9 @@ data class ServerProperties(val flags: Int, val sitemaps: List) : Parce if (version >= 4) { flags = flags or SERVER_FLAG_OH3_UI } + if (version >= 5) { + flags = flags or SERVER_FLAG_TRANSPARENT_CHARTS + } } catch (nfe: NumberFormatException) { // ignored: older versions without SSE support didn't return a number Log.i(TAG, "Server has rest api version < 1") diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/ChartActivity.kt b/mobile/src/main/java/org/openhab/habdroid/ui/ChartActivity.kt index faddb55fe8..416a319fb9 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/ChartActivity.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/ChartActivity.kt @@ -16,7 +16,6 @@ package org.openhab.habdroid.ui import android.content.res.Configuration import android.os.Bundle import android.util.Log -import android.util.TypedValue import android.view.Menu import android.view.MenuItem import androidx.swiperefreshlayout.widget.SwipeRefreshLayout @@ -27,6 +26,7 @@ import org.openhab.habdroid.model.Widget import org.openhab.habdroid.ui.widget.WidgetImageView import org.openhab.habdroid.util.ScreenLockMode import org.openhab.habdroid.util.determineDataUsagePolicy +import org.openhab.habdroid.util.getChartTheme import org.openhab.habdroid.util.getPrefs import org.openhab.habdroid.util.orDefaultIfEmpty @@ -36,6 +36,7 @@ class ChartActivity : AbstractBaseActivity(), SwipeRefreshLayout.OnRefreshListen private lateinit var period: String private lateinit var widget: Widget private lateinit var chartTheme: CharSequence + private var serverFlags: Int = 0 private var density: Int = 0 private var showLegend: Boolean = true @@ -44,11 +45,13 @@ class ChartActivity : AbstractBaseActivity(), SwipeRefreshLayout.OnRefreshListen setContentView(R.layout.activity_chart) - widget = intent.getParcelableExtra(WIDGET)!! + widget = intent.getParcelableExtra(EXTRA_WIDGET)!! period = widget.period // If Widget#legend is null, show legend only for groups showLegend = widget.legend ?: widget.item?.type === Item.Type.Group + serverFlags = intent.getIntExtra(EXTRA_SERVER_FLAGS, 0) + setSupportActionBar(findViewById(R.id.openhab_toolbar)) supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.title = widget.label.orDefaultIfEmpty(getString(R.string.chart_activity_title)) @@ -187,9 +190,7 @@ class ChartActivity : AbstractBaseActivity(), SwipeRefreshLayout.OnRefreshListen } private fun updateChartTheme() { - val tv = TypedValue() - theme.resolveAttribute(R.attr.chartTheme, tv, true) - chartTheme = tv.string + chartTheme = getChartTheme(serverFlags) } companion object { @@ -197,6 +198,7 @@ class ChartActivity : AbstractBaseActivity(), SwipeRefreshLayout.OnRefreshListen private const val SHOW_LEGEND = "show_legend" private const val PERIOD = "period" - const val WIDGET = "widget" + const val EXTRA_WIDGET = "widget" + const val EXTRA_SERVER_FLAGS = "server_flags" } } diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt index e5bc65269d..fbeb321f11 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetAdapter.kt @@ -93,6 +93,7 @@ import org.openhab.habdroid.util.HttpClient import org.openhab.habdroid.util.MjpegStreamer import org.openhab.habdroid.util.beautify import org.openhab.habdroid.util.determineDataUsagePolicy +import org.openhab.habdroid.util.getChartTheme import org.openhab.habdroid.util.getImageWidgetScalingType import org.openhab.habdroid.util.getPrefs import org.openhab.habdroid.util.orDefaultIfEmpty @@ -103,6 +104,7 @@ import org.openhab.habdroid.util.orDefaultIfEmpty class WidgetAdapter( context: Context, + val serverFlags: Int, private val connection: Connection, private val itemClickListener: ItemClickListener ) : RecyclerView.Adapter(), View.OnClickListener { @@ -113,7 +115,7 @@ class WidgetAdapter( get() = items.any { widget -> shouldShowWidget(widget) } private val inflater = LayoutInflater.from(context) - private val chartTheme: CharSequence + private val chartTheme: CharSequence = context.getChartTheme(serverFlags) private var selectedPosition = RecyclerView.NO_POSITION private var firstVisibleWidgetPosition = RecyclerView.NO_POSITION private val colorMapper = ColorMapper(context) @@ -122,12 +124,6 @@ class WidgetAdapter( fun onItemClicked(widget: Widget): Boolean // returns whether click was handled } - init { - val tv = TypedValue() - context.theme.resolveAttribute(R.attr.chartTheme, tv, true) - chartTheme = tv.string - } - @SuppressLint("NotifyDataSetChanged") fun update(widgets: List, forceFullUpdate: Boolean) { val compatibleUpdate = !forceFullUpdate && @@ -189,7 +185,7 @@ class WidgetAdapter( TYPE_SECTIONSWITCH -> SectionSwitchViewHolder(inflater, parent, connection, colorMapper) TYPE_ROLLERSHUTTER -> RollerShutterViewHolder(inflater, parent, connection, colorMapper) TYPE_SETPOINT -> SetpointViewHolder(inflater, parent, connection, colorMapper) - TYPE_CHART -> ChartViewHolder(inflater, parent, chartTheme, connection) + TYPE_CHART -> ChartViewHolder(inflater, parent, chartTheme, connection, serverFlags) TYPE_VIDEO -> VideoViewHolder(inflater, parent, connection) TYPE_WEB -> WebViewHolder(inflater, parent, connection) TYPE_COLOR -> ColorViewHolder(inflater, parent, connection, colorMapper) @@ -1001,7 +997,8 @@ class WidgetAdapter( inflater: LayoutInflater, parent: ViewGroup, private val chartTheme: CharSequence?, - connection: Connection + connection: Connection, + private val serverFlags: Int ) : HeavyDataViewHolder(inflater, parent, R.layout.widgetlist_chartitem, connection), View.OnClickListener { private val chart = widgetContentView as WidgetImageView private val prefs: SharedPreferences @@ -1044,7 +1041,8 @@ class WidgetAdapter( val context = v?.context ?: return boundWidget?.let { val intent = Intent(context, ChartActivity::class.java) - intent.putExtra(ChartActivity.WIDGET, it) + intent.putExtra(ChartActivity.EXTRA_WIDGET, it) + intent.putExtra(ChartActivity.EXTRA_SERVER_FLAGS, serverFlags) context.startActivity(intent) } } diff --git a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt index 84725f0a1d..6520f3dfd5 100644 --- a/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt +++ b/mobile/src/main/java/org/openhab/habdroid/ui/WidgetListFragment.kt @@ -121,7 +121,9 @@ class WidgetListFragment : Fragment(), WidgetAdapter.ItemClickListener, super.onViewCreated(view, savedInstanceState) val activity = activity as MainActivity - adapter = activity.connection?.let { conn -> WidgetAdapter(activity, conn, this) } + adapter = activity.connection?.let { conn -> + WidgetAdapter(activity, activity.serverProperties!!.flags, conn, this) + } layoutManager = LinearLayoutManager(activity) layoutManager.recycleChildrenOnDetach = true diff --git a/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt b/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt index 9e22809f38..3df6de7b47 100644 --- a/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt +++ b/mobile/src/main/java/org/openhab/habdroid/util/ExtensionFuncs.kt @@ -75,6 +75,7 @@ import org.openhab.habdroid.R import org.openhab.habdroid.core.OpenHabApplication import org.openhab.habdroid.model.ServerConfiguration import org.openhab.habdroid.model.ServerPath +import org.openhab.habdroid.model.ServerProperties import org.openhab.habdroid.util.Util.TAG import org.w3c.dom.Node import org.w3c.dom.NodeList @@ -451,6 +452,17 @@ fun Context.resolveThemedColor(@AttrRes colorAttr: Int, @ColorInt fallbackColor: } } +fun Context.getChartTheme(serverFlags: Int): CharSequence { + val tv = TypedValue() + if (serverFlags and ServerProperties.SERVER_FLAG_TRANSPARENT_CHARTS == 0) { + theme.resolveAttribute(R.attr.chartTheme, tv, true) + } else { + theme.resolveAttribute(R.attr.transparentChartTheme, tv, true) + } + + return tv.string +} + fun Context.isDarkModeActive(): Boolean { return when (getPrefs().getDayNightMode(this)) { AppCompatDelegate.MODE_NIGHT_NO -> false diff --git a/mobile/src/main/res/values-night/themes.xml b/mobile/src/main/res/values-night/themes.xml index 0d8618b6c4..bb6ac2feb3 100644 --- a/mobile/src/main/res/values-night/themes.xml +++ b/mobile/src/main/res/values-night/themes.xml @@ -2,6 +2,7 @@ diff --git a/mobile/src/main/res/values/attrs.xml b/mobile/src/main/res/values/attrs.xml index 1252590bf6..39851a52f8 100644 --- a/mobile/src/main/res/values/attrs.xml +++ b/mobile/src/main/res/values/attrs.xml @@ -33,6 +33,7 @@ + diff --git a/mobile/src/main/res/values/themes.xml b/mobile/src/main/res/values/themes.xml index 0d0c28144a..59f966ce36 100644 --- a/mobile/src/main/res/values/themes.xml +++ b/mobile/src/main/res/values/themes.xml @@ -13,6 +13,7 @@ @@ -48,16 +49,19 @@