[blam: 1/4] Item: make unread a property



commit 62648800328e815524af76b1631e1b68f6d0cfe3
Author: Carlos Martín Nieto <cmn dwim me>
Date:   Mon Jun 17 17:01:57 2013 +0200

    Item: make unread a property
    
    Make it a property and implement INotifyPropertyChanged so we can do
    more fine-grained updating.

 src/Application.cs |    2 +-
 src/Channel.cs     |   15 ++++++++-------
 src/Item.cs        |   41 +++++++++++++++++++++++++----------------
 src/ItemList.cs    |    4 ++--
 4 files changed, 36 insertions(+), 26 deletions(-)
---
diff --git a/src/Application.cs b/src/Application.cs
index a44e119..05d22e8 100644
--- a/src/Application.cs
+++ b/src/Application.cs
@@ -366,7 +366,7 @@ namespace Imendio.Blam {
             }
 
             // Toggle unread status
-            item.SetUnread (!item.Unread);
+            item.Unread = !item.Unread;
             itemList.EmitSelectedRowChanged();
         }
 
diff --git a/src/Channel.cs b/src/Channel.cs
index 9a414f2..6a4446b 100644
--- a/src/Channel.cs
+++ b/src/Channel.cs
@@ -13,6 +13,7 @@ using System.Xml;
 using System.Xml.Serialization;
 using System.IO;
 using System.Threading.Tasks;
+using System.ComponentModel;
 using System.ServiceModel.Syndication;
 using System.Security.Cryptography.X509Certificates;
 
@@ -177,7 +178,7 @@ namespace Imendio.Blam {
                     if(item == null){
                     } else {
                         nlist.Add(id);
-                        item.Updated += ItemUpdated;
+                        item.PropertyChanged += ItemChanged;
                     }
                 }
                 item_list = nlist;
@@ -207,7 +208,7 @@ namespace Imendio.Blam {
                     }
                     item = store.Get(id);
                     if (item.Unread) {
-                        item.SetUnread (false);
+                        item.Unread = false;
                         updated = true;
                         EmitUpdated();
                     }
@@ -258,10 +259,10 @@ namespace Imendio.Blam {
                        }
                }
 
-        public void ItemUpdated(Item item)
-        {
-            EmitUpdated();
-        }
+               void ItemChanged(object sender, PropertyChangedEventArgs args)
+               {
+                       EmitUpdated();
+               }
 
         /**
          * Adds or updates the entry
@@ -278,7 +279,7 @@ namespace Imendio.Blam {
             lock(obj){
                 item_list.Add(item.Id);
             }
-            store.Get(item.Id).Updated += ItemUpdated;
+            store.Get(item.Id).PropertyChanged += ItemChanged;
         }
 
                public bool GetHasKeyword (string keyword)
diff --git a/src/Item.cs b/src/Item.cs
index caaca62..8ef1132 100644
--- a/src/Item.cs
+++ b/src/Item.cs
@@ -6,23 +6,35 @@
 
 using System.Xml.Serialization;
 using System;
+using System.ComponentModel;
 using System.Threading;
 using System.ServiceModel.Syndication;
+using System.Runtime.CompilerServices;
 
 namespace Imendio.Blam {
-       public class Item : SyndicationItem {
-               public bool    Unread = true;
+       public class Item : SyndicationItem, INotifyPropertyChanged {
                public bool     Old = false;
                public bool     Permanent = false;
 
                public string   keywords = "";
+               public event PropertyChangedEventHandler PropertyChanged;
+
+               bool unread = true;
+               public bool Unread {
+                       get {
+                               return unread;
+                       }
+                       set {
+                               if (unread != value) {
+                                       unread = value;
+                                       NotifyPropertyChanged();
+                               }
+                       }
+               }
 
         private int ref_cnt = 0;
         private Object obj = new Object();
 
-        public delegate void UpdateHandler(Item item);
-        public event UpdateHandler Updated;
-
                public string Keywords {
                        get {
                                return keywords;
@@ -68,6 +80,13 @@ namespace Imendio.Blam {
                {
                }
 
+               void NotifyPropertyChanged([CallerMemberName] string name = "")
+               {
+                       if (PropertyChanged != null) {
+                               PropertyChanged(this, new PropertyChangedEventArgs(name));
+                       }
+               }
+
         private void FillItem(SyndicationItem item)
         {
             if(this.Id == null){
@@ -129,15 +148,5 @@ namespace Imendio.Blam {
             }
             return true;
         }
-
-               public void SetUnread (bool unread) 
-               {
-                       if (Unread != unread) {
-                               Unread = unread;
-                if(Updated != null){
-                    Updated(this);
-                }
-            }
-        }
-    }
+       }
 }
diff --git a/src/ItemList.cs b/src/ItemList.cs
index e1a5fc1..f38f50b 100644
--- a/src/ItemList.cs
+++ b/src/ItemList.cs
@@ -190,7 +190,7 @@ namespace Imendio.Blam {
                        bool useTimeout = (bool) Conf.Get(Preference.MARK_ITEMS_READ, false);
 
                        if (!useTimeout) {
-                               item.SetUnread(false);
+                               item.Unread = false;
                                selection.EmitRowChanged();
                                return;
                        }
@@ -205,7 +205,7 @@ namespace Imendio.Blam {
                        }
 
                        MarkReadCancel = null;
-                       item.SetUnread(false);
+                       item.Unread = false;
                        selection.EmitRowChanged();
                }
 


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