[gnome-maps/wip/mlundblad/night-mode: 4/4] layersPopover: Show dark street thumbnail when night mode active



commit 720298d9f07b7a90729504f73afe318dcaf054bd
Author: Marcus Lundblad <ml update uu se>
Date:   Fri Jun 5 12:19:04 2020 +0200

    layersPopover: Show dark street thumbnail when night mode active

 src/layersPopover.js | 44 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 36 insertions(+), 8 deletions(-)
---
diff --git a/src/layersPopover.js b/src/layersPopover.js
index 118cbdc1..0526e684 100644
--- a/src/layersPopover.js
+++ b/src/layersPopover.js
@@ -22,6 +22,7 @@ const GObject = imports.gi.GObject;
 const Gtk = imports.gi.Gtk;
 const Gdk = imports.gi.Gdk;
 
+const Application = imports.application;
 const MapSource = imports.mapSource;
 const MapView = imports.mapView;
 const Service = imports.service;
@@ -97,13 +98,23 @@ var LayersPopover = GObject.registerClass({
                 source: MapSource.createStreetSource(),
                 widget: this._streetLayerImage,
                 lastLocation: { x: -1, y: -1, z: -1 }
-            },
-            aerial: {
+            }
+        };
+
+        if (Service.getService().tiles.streetDark) {
+            this._layerPreviews.streetDark = {
+                source: MapSource.createStreetDarkSource(),
+                widget: this._streetLayerImage,
+                lastLocation: { x: -1, y: -1, z: -1 }
+            };
+        }
+        if (Service.getService().tiles.aerial) {
+            this._layerPreviews.aerial = {
                 source: MapSource.createAerialSource(),
                 widget: this._aerialLayerImage,
                 lastLocation: { x: -1, y: -1, z: -1 }
-            }
-        };
+            };
+        }
 
         // disable the map type switch buttons if aerial is unavailable
         if (Service.getService().tiles.aerial) {
@@ -125,6 +136,9 @@ var LayersPopover = GObject.registerClass({
                                        this._setLayerPreviews.bind(this));
             this._mapView.view.connect("notify::longitude",
                                        this._setLayerPreviews.bind(this));
+            Application.settings.connect("changed::night-mode",
+                                         this._onNightModeChanged.bind(this));
+
         } else {
             this._streetLayerButton.visible = false;
             this._aerialLayerButton.visible = false;
@@ -136,12 +150,26 @@ var LayersPopover = GObject.registerClass({
         });
     }
 
+    _onNightModeChanged() {
+        if (Service.getService().tiles.streetDark &&
+            Application.settings.get('night-mode')) {
+            this._setLayerPreviewImage('streetDark', true);
+        } else {
+            this._setLayerPreviewImage('street', true);
+        }
+    }
+
     _setLayerPreviews() {
-        this._setLayerPreviewImage("street");
-        this._setLayerPreviewImage("aerial");
+        if (Service.getService().tiles.streetDark &&
+            Application.settings.get('night-mode')) {
+            this._setLayerPreviewImage('streetDark');
+        } else {
+            this._setLayerPreviewImage('street');
+        }
+        this._setLayerPreviewImage('aerial');
     }
 
-    _setLayerPreviewImage(layer) {
+    _setLayerPreviewImage(layer, forceUpdate = false) {
         let previewInfo = this._layerPreviews[layer];
         let source = previewInfo.source;
         let widget = previewInfo.widget;
@@ -157,7 +185,7 @@ var LayersPopover = GObject.registerClass({
         // then don't bother changing anything
         if (previewInfo.lastLocation.x == x &&
             previewInfo.lastLocation.y == y &&
-            previewInfo.lastLocation.z == z) {
+            previewInfo.lastLocation.z == z && !forceUpdate) {
 
             return;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]