[chronojump/optimizeRFD] New products showing newer/older working



commit 74f255e67ca560baa920c3c030113c6d8ecf27b0
Author: Xavier de Blas <xaviblas gmail com>
Date:   Wed Dec 30 13:19:24 2020 +0100

    New products showing newer/older working

 glade/app1.glade     | 247 +++++++++++++++++++++++++++++++++------------------
 src/gui/app1/menu.cs |   8 +-
 src/gui/app1/news.cs |  65 +++++++++++++-
 src/json/json.cs     |   2 +-
 src/news.cs          |  26 +-----
 src/sqlite/news.cs   |   5 +-
 6 files changed, 238 insertions(+), 115 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index 994eb2f73..300a70090 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -42599,7 +42599,109 @@ then click this button.</property>
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
                                         <property name="border_width">4</property>
-                                        <property name="spacing">4</property>
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox453">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox447">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">6</property>
+                                                <child>
+                                                  <widget class="GtkImage" id="image_news_blue">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="stock">gtk-missing-image</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkImage" id="image_news_yellow">
+                                                    <property name="can_focus">False</property>
+                                                    <property name="stock">gtk-missing-image</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkLabel" id="label_news_frame">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="label" translatable="yes">New 
products</property>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">True</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">2</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkHBox" id="hbox452">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">False</property>
+                                                <property name="spacing">8</property>
+                                                <child>
+                                                  <widget class="GtkRadioButton" 
id="radio_news_language_english">
+                                                    <property name="label" 
translatable="yes">English</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">False</property>
+                                                    <property name="active">True</property>
+                                                    <property name="draw_indicator">False</property>
+                                                    <signal name="toggled" 
handler="on_radio_news_language_english_toggled" swapped="no"/>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">True</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
+                                                </child>
+                                                <child>
+                                                  <widget class="GtkRadioButton" 
id="radio_news_language_spanish">
+                                                    <property name="label" 
translatable="yes">Spanish</property>
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="receives_default">False</property>
+                                                    <property name="draw_indicator">False</property>
+                                                    <property 
name="group">radio_news_language_english</property>
+                                                    <signal name="toggled" 
handler="on_radio_news_language_spanish_toggled" swapped="no"/>
+                                                  </widget>
+                                                  <packing>
+                                                    <property name="expand">True</property>
+                                                    <property name="fill">True</property>
+                                                    <property name="position">1</property>
+                                                  </packing>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="pack_type">end</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="expand">False</property>
+                                            <property name="fill">False</property>
+                                            <property name="position">0</property>
+                                          </packing>
+                                        </child>
                                         <child>
                                           <widget class="GtkFrame" id="frame27">
                                             <property name="visible">True</property>
@@ -42621,19 +42723,22 @@ then click this button.</property>
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">False</property>
                                                         <child>
-                                                          <widget class="GtkHBox" id="hbox452">
-                                                            <property name="visible">True</property>
+                                                          <widget class="GtkHBox" id="hbox_news_newer_older">
                                                             <property name="can_focus">False</property>
-                                                            <property name="spacing">8</property>
+                                                            <property name="spacing">20</property>
                                                             <child>
-                                                            <widget class="GtkRadioButton" 
id="radio_news_language_english">
-                                                            <property name="label" 
translatable="yes">English</property>
+                                                            <widget class="GtkButton" id="button_news_newer">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
-                                                            <property 
name="receives_default">False</property>
-                                                            <property name="active">True</property>
-                                                            <property name="draw_indicator">False</property>
-                                                            <signal name="toggled" 
handler="on_radio_news_language_english_toggled" swapped="no"/>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_news_newer_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkArrow" id="arrow30">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="arrow_type">left</property>
+                                                            </widget>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">True</property>
@@ -42642,15 +42747,9 @@ then click this button.</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkRadioButton" 
id="radio_news_language_spanish">
-                                                            <property name="label" 
translatable="yes">Spanish</property>
+                                                            <widget class="GtkLabel" 
id="label_news_current_all">
                                                             <property name="visible">True</property>
-                                                            <property name="can_focus">True</property>
-                                                            <property 
name="receives_default">False</property>
-                                                            <property name="active">True</property>
-                                                            <property name="draw_indicator">False</property>
-                                                            <property 
name="group">radio_news_language_english</property>
-                                                            <signal name="toggled" 
handler="on_radio_news_language_spanish_toggled" swapped="no"/>
+                                                            <property name="can_focus">False</property>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">True</property>
@@ -42658,11 +42757,29 @@ then click this button.</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkButton" id="button_news_older">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <signal name="clicked" 
handler="on_button_news_older_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkArrow" id="arrow29">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">2</property>
+                                                            </packing>
+                                                            </child>
                                                           </widget>
                                                           <packing>
-                                                            <property name="expand">False</property>
+                                                            <property name="expand">True</property>
                                                             <property name="fill">False</property>
-                                                            <property name="pack_type">end</property>
                                                             <property name="position">0</property>
                                                           </packing>
                                                         </child>
@@ -42826,46 +42943,7 @@ then click this button.</property>
                                               </widget>
                                             </child>
                                             <child>
-                                              <widget class="GtkHBox" id="hbox447">
-                                                <property name="visible">True</property>
-                                                <property name="can_focus">False</property>
-                                                <property name="spacing">6</property>
-                                                <child>
-                                                  <widget class="GtkImage" id="image_news_blue">
-                                                    <property name="visible">True</property>
-                                                    <property name="can_focus">False</property>
-                                                    <property name="stock">gtk-missing-image</property>
-                                                  </widget>
-                                                  <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="fill">False</property>
-                                                    <property name="position">0</property>
-                                                  </packing>
-                                                </child>
-                                                <child>
-                                                  <widget class="GtkImage" id="image_news_yellow">
-                                                    <property name="can_focus">False</property>
-                                                    <property name="stock">gtk-missing-image</property>
-                                                  </widget>
-                                                  <packing>
-                                                    <property name="expand">False</property>
-                                                    <property name="fill">False</property>
-                                                    <property name="position">1</property>
-                                                  </packing>
-                                                </child>
-                                                <child>
-                                                  <widget class="GtkLabel" id="label_news_frame">
-                                                    <property name="visible">True</property>
-                                                    <property name="can_focus">False</property>
-                                                    <property name="label" translatable="yes">New 
products</property>
-                                                  </widget>
-                                                  <packing>
-                                                    <property name="expand">True</property>
-                                                    <property name="fill">True</property>
-                                                    <property name="position">2</property>
-                                                  </packing>
-                                                </child>
-                                              </widget>
+                                              <placeholder/>
                                               <packing>
                                                 <property name="type">label_item</property>
                                               </packing>
@@ -42874,52 +42952,53 @@ then click this button.</property>
                                           <packing>
                                             <property name="expand">True</property>
                                             <property name="fill">True</property>
-                                            <property name="position">0</property>
+                                            <property name="position">1</property>
                                           </packing>
                                         </child>
                                         <child>
-                                          <widget class="GtkHButtonBox" id="hbuttonbox10">
+                                          <widget class="GtkAlignment" id="alignment65">
                                             <property name="visible">True</property>
                                             <property name="can_focus">False</property>
+                                            <property name="top_padding">4</property>
                                             <child>
-                                              <widget class="GtkButton" id="button_news_close">
+                                              <widget class="GtkHButtonBox" id="hbuttonbox10">
                                                 <property name="visible">True</property>
-                                                <property name="can_focus">True</property>
-                                                <property name="can_default">True</property>
-                                                <property name="receives_default">False</property>
-                                                <signal name="clicked" 
handler="on_button_news_close_clicked" swapped="no"/>
-                                                <accelerator key="Escape" signal="clicked"/>
+                                                <property name="can_focus">False</property>
                                                 <child>
-                                                  <widget class="GtkEventBox" 
id="eventbox_button_news_close">
+                                                  <widget class="GtkButton" id="button_news_close">
                                                     <property name="visible">True</property>
-                                                    <property name="can_focus">False</property>
+                                                    <property name="can_focus">True</property>
+                                                    <property name="can_default">True</property>
+                                                    <property name="receives_default">False</property>
+                                                    <signal name="clicked" 
handler="on_button_news_close_clicked" swapped="no"/>
+                                                    <accelerator key="Escape" signal="clicked"/>
                                                     <child>
-                                                      <widget class="GtkLabel" id="label412">
+                                                      <widget class="GtkEventBox" 
id="eventbox_button_news_close">
                                                         <property name="visible">True</property>
                                                         <property name="can_focus">False</property>
-                                                        <property name="label" 
translatable="yes">Close</property>
+                                                        <child>
+                                                          <widget class="GtkLabel" id="label412">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label" 
translatable="yes">Close</property>
+                                                          </widget>
+                                                        </child>
                                                       </widget>
                                                     </child>
                                                   </widget>
+                                                  <packing>
+                                                    <property name="expand">False</property>
+                                                    <property name="fill">False</property>
+                                                    <property name="position">0</property>
+                                                  </packing>
                                                 </child>
                                               </widget>
-                                              <packing>
-                                                <property name="expand">False</property>
-                                                <property name="fill">False</property>
-                                                <property name="position">0</property>
-                                              </packing>
-                                            </child>
-                                            <child>
-                                              <placeholder/>
-                                            </child>
-                                            <child>
-                                              <placeholder/>
                                             </child>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
                                             <property name="fill">False</property>
-                                            <property name="position">1</property>
+                                            <property name="position">2</property>
                                           </packing>
                                         </child>
                                       </widget>
diff --git a/src/gui/app1/menu.cs b/src/gui/app1/menu.cs
index d758a6939..9c03c60a3 100644
--- a/src/gui/app1/menu.cs
+++ b/src/gui/app1/menu.cs
@@ -315,8 +315,12 @@ public partial class ChronoJumpWindow
                        return;
                */
 
-               news_setup(); //setup radios: language and arrows
-               news_fill(0, true); //fill the widget
+               //news print debug
+               foreach(News news in newsAtDB_l)
+                       LogB.Information(news.ToString());
+
+               news_setup(0); //setup radios: language and arrows
+               news_fill(true); //fill the widget
                alignment_news.Show(); // is hidden at beginning to allow being well shown when filled
 
                //sensitivity and notebook management
diff --git a/src/gui/app1/news.cs b/src/gui/app1/news.cs
index 2821d3124..3a9aaebe7 100644
--- a/src/gui/app1/news.cs
+++ b/src/gui/app1/news.cs
@@ -30,6 +30,10 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Image image_news_yellow;
        [Widget] Gtk.Label label_news_frame;
        [Widget] Gtk.Alignment alignment_news;
+       [Widget] Gtk.HBox hbox_news_newer_older;
+       [Widget] Gtk.Button button_news_newer;
+       [Widget] Gtk.Button button_news_older;
+       [Widget] Gtk.Label label_news_current_all;
        [Widget] Gtk.RadioButton radio_news_language_english;
        [Widget] Gtk.RadioButton radio_news_language_spanish;
        [Widget] Gtk.Label label_news_title;
@@ -40,17 +44,69 @@ public partial class ChronoJumpWindow
        Pixbuf image_news_pixbuf;
        private int currentNewsPos;
 
-       private void news_setup()
+       private void news_setup(int currentPos)
        {
+               currentNewsPos = currentPos;
+
                if(preferences.newsLanguageEs)
                        radio_news_language_spanish.Active = true;
                else
                        radio_news_language_english.Active = true;
+
+               news_setNewerOlderStuff();
        }
 
-       private void news_fill (int currentPos, bool textAndVideo)
+
+       // ----------------- newer, older management ---------->
+       /*
+        * code 1 is the first news in the server (the older)
+        * but newsAtDB_l is a SELECT ORDER BY code DESC
+        * so if there are three news, currentNewsPos == 0 should be the newer (that should be code 3, if 
there have not been removals on server)
+        */
+       private void news_setNewerOlderStuff()
+       {
+               //do not show newer/older controls if there is one product
+               if(newsAtDB_l.Count < 2)
+                       return;
+
+               hbox_news_newer_older.Visible = true;
+               newsNewerOlderUpdateWidgets();
+       }
+
+       private void newsNewerOlderUpdateWidgets()
+       {
+               label_news_current_all.Text = string.Format("{0} / {1}", currentNewsPos +1, newsAtDB_l.Count);
+
+               button_news_newer.Sensitive = currentNewsPos > 0;
+               button_news_older.Sensitive = currentNewsPos +1 < newsAtDB_l.Count;
+       }
+
+       private void on_button_news_newer_clicked (object o, EventArgs args)
+       {
+               //just a precaution
+               if(currentNewsPos <= 0)
+                       return;
+
+               currentNewsPos --;
+               newsNewerOlderUpdateWidgets();
+               news_fill (true);
+       }
+       private void on_button_news_older_clicked (object o, EventArgs args)
+       {
+               //just a precaution
+               if(currentNewsPos +1 >= newsAtDB_l.Count)
+                       return;
+
+               currentNewsPos ++;
+               newsNewerOlderUpdateWidgets();
+               news_fill (true);
+       }
+
+       // <----------------- end of newer, older management ----------
+
+
+       private void news_fill (bool textAndVideo)
        {
-               currentNewsPos = currentPos;
 
                News news = newsAtDB_l[currentNewsPos];
 
@@ -72,6 +128,7 @@ public partial class ChronoJumpWindow
 
        private void news_loadImage(News news)
        {
+               LogB.Information("news_loadImage: " + news.ToString());
                //TODO: share method for getting extension
                string extension = "";
                if(Util.IsJpeg(news.LinkServerImage))
@@ -107,7 +164,7 @@ public partial class ChronoJumpWindow
                Sqlite.Close();
 
                // 2) rewrite the labels
-               news_fill (currentNewsPos, false);
+               news_fill (false);
        }
 
        private void on_button_new_open_browser_clicked (object o, EventArgs args)
diff --git a/src/json/json.cs b/src/json/json.cs
index 8884326b3..87e1ac55e 100644
--- a/src/json/json.cs
+++ b/src/json/json.cs
@@ -231,7 +231,7 @@ public class Json
                        string linkEs = jsonNews ["linkEs"];
                        string descriptionEn = jsonNews ["descriptionEn"];
                        string descriptionEs = jsonNews ["descriptionEs"];
-                       string linkServerImage = jsonNews ["linkImage"];
+                       string linkServerImage = jsonNews ["linkServerImage"];
 
                        news_l.Add(new News(code, category, version, false,
                                                titleEn, titleEs, linkEn, linkEs, descriptionEn, 
descriptionEs, linkServerImage));
diff --git a/src/news.cs b/src/news.cs
index fbd359d61..6aff19026 100644
--- a/src/news.cs
+++ b/src/news.cs
@@ -22,11 +22,12 @@ using System;
 using System.IO;               //for detect OS //TextWriter
 using System.Collections.Generic; //List<T>
 
+//software will not be managed here! only products
 public class News
 {
        private int code; //regular integer
-       private int category; //at the moment: 0 software, 1 products
-       private int version; //is NOT version of the software, is version of the news, because can be updated 
with new text or image. New version of the sofware will be simply a new code
+       private int category; //unused at the moment
+       private int version; //is NOT version of the software (software is not managed here), is version of 
each news, because can be updated with new text or image. New version of the sofware will be simply a new code
        private bool viewed;
        //En and Es because there are two versions of the web site
        private string titleEn;
@@ -103,27 +104,6 @@ public class News
 
        /* public static methods */
 
-       /*
-       //this method does not use SQL, called by pingThread
-       public static bool AnythingNew (List<News> newsAtDB_l, List<News> newsAtServer_l)
-       {
-               foreach(News nAtServer in newsAtServer_l)
-               {
-                       bool found = false;
-                       foreach(News nAtDB in newsAtDB_l)
-                               if(nAtServer.Code == nAtDB.Code)
-                               {
-                                       found = true;
-                                       break;
-                               }
-                       if(! found)
-                               return true;
-               }
-
-               return false;
-       }
-       */
-
        //this method uses SQL, called by main thread
        public static bool InsertIfNeeded(List<News> newsAtDB_l, List<News> newsAtServer_l)
        {
diff --git a/src/sqlite/news.cs b/src/sqlite/news.cs
index 03d988edf..97201be73 100644
--- a/src/sqlite/news.cs
+++ b/src/sqlite/news.cs
@@ -39,7 +39,10 @@ class SqliteNews : Sqlite
 
        //server table is created like this:
        //create table news (code INT NOT NULL AUTO_INCREMENT PRIMARY KEY, category INT, version INT, titleEn 
char(255), titleEs char(255), linkEn char(255), linkEs char(255), descriptionEn char(255), descriptionEs 
char(255), linkServerImage char(255));
-       //INSERT INTO news VALUES (NULL, 1, 0, "Race Analyzer kit", "Kit Analizador Carreras", 
"https://chronojump.org/product-category/races/race_analyzer_kit/";, 
"https://chronojump.org/es/categoria-producto/carreras/kit_analizador_carreras/";, "Device that allows you to 
analyze and graph races from the time obtained every 3cm of race.\nThe mathematical model implemented by 
Chronojump allows you to graph speeds, accelerations, forces and instantaneous powers.", "Dispositivo que 
permite analizar y graficar carreras a partir del tiempo obtenido cada 3cm.\nEl modelo matemático 
implementado por Chronojump le permite graficar velocidades, aceleraciones, fuerzas y potencias 
instantáneas.", "https://chronojump.org/wp-content/uploads/2020/12/Race-Analyzer_new_products_400w.jpeg";);
+       //INSERT INTO news VALUES (NULL, 0, 0, "Race Analyzer kit", "Kit Analizador Carreras", 
"https://chronojump.org/shop/races/race_analyzer_kit/race-analyzer/";, 
"https://chronojump.org/es/shop/carreras/kit_analizador_carreras/analizador-de-carrera/";, "Measure the 
instantaneous race speed.\n\n- Encoder based (included)\n- Distance accuracy: 3 cm\n- Time accuracy: 4 
microseconds\n\nIdeal device for high accuracy analysis of the sprint applicable in the field and in many 
sports disciplines!", "Mida la velocidad instantánea.\n\n- Usa un encoder (incluído)\n- Precisión en la 
distancia: 3 cm\n- Precisión en el tiempo: 4 microseg.\n\n¡Dispositivo ideal para un análisis de alta 
precisión del sprint aplicable en el campo y en muchas disciplinas deportivas!", 
"https://chronojump.org/wp-content/uploads/2020/12/Race-Analyzer_new_products_400w.jpeg";);
+       //another (suposedly newer) to have as a test:
+       //INSERT INTO news VALUES (NULL, 0, 0, "something newer", "una cosa más nueva", 
"https://chronojump.org/shop/force-equipment/force-sensor/";, 
"https://chronojump.org/es/shop/material-de-fuerza/kit-sensor-de-fuerza/";, "Desc of force sensor", 
"Descripción del sensor de fuerza", 
"https://chronojump.org/wp-content/uploads/2016/11/chronojump-logo-web-e1589545113863.png";);
+       //INSERT INTO news VALUES (NULL, 0, 0, "something even more new spare_parts", "una cosa más y más 
nueva spare_parts", "https://chronojump.org/product-category/races/races_spare_parts/";, 
"https://chronojump.org/es/categoria-producto/carreras/productos-_de_carreras_por_separado/";, "Desc of 
spare_parts", "Descripción de spare_parts", 
"https://chronojump.org/wp-content/uploads/2020/10/web-selector-races-PARTS.png";);
 
 
        protected internal static void createTable ()


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