public void favButtonPressed(UIButton favBtn) { Console.WriteLine("Favorite Button Pressed: {0}", favBtn); RSSItem item = BNRFeedStore.items[(int)favBtn.Tag]; BNRFeedStore.markItemAsFavorite(item); this.TableView.ReloadData(); }
public static void updateItem(RSSItem item) { string dbPath = GetDBPath(); SQLiteConnection db; db = new SQLiteConnection(dbPath); db.Update(item); db.Close(); db = null; }
static async void FetchRSSAsync(Block completionBlock) { using (var wc = new WebClient()) { string url = "http://forums.bignerdranch.com/smartfeed.php?limit=7_DAY&count_limit=25&sort_by=standard&feed_type=RSS2.0&feed_style=COMPACT"; // count_limit=10& try { string xmlData = await wc.DownloadStringTaskAsync(new Uri(url)); XDocument doc = XDocument.Parse(xmlData); channel.parseXML(doc); var allItems = doc.Descendants("item"); string dbPath = GetDBPath(); SQLiteConnection db; db = new SQLiteConnection(dbPath); db.BeginTransaction(); foreach (XElement current in allItems) { RSSItem item = new RSSItem(); item.parseXML(current); item.type = "post"; bool inItems = false; foreach(RSSItem i in items) { if (i.link == item.link) inItems = true; } int index = 0; if (!inItems) { items.Insert(index++, item); db.Insert(item); if (db.Table<RSSItem>().Count() > 100) { db.Query<RSSItem>("DELETE FROM RSSItems WHERE rowid IN (SELECT rowid FROM RSSItems ORDER BY rowid ASC LIMIT 1)"); } Console.WriteLine("Items in table: {0} ItemID: {1}", db.Table<RSSItem>().Count(), item.ID); } } db.Commit(); db.Close(); db = null; completionBlock("success"); } catch (WebException ex) { Console.WriteLine("Exception: {0}", ex.Message); completionBlock(ex.Message); } } }
public static void markItemAsFavorite(RSSItem item) { if (!item.isFavorite) { item.isFavorite = true; } else { item.isFavorite = false; } updateItem(item); }
public void listViewControllerHandleObject(ListViewController lvc, object obj) { // Cast the passed object to RSSItem RSSItem entry = obj as RSSItem; // Make sure that we are really getting an RSSItem if (entry.GetType() != typeof(RSSItem)) { return; } // Grab the info from the item and push it into the appropriate views this.webView.LoadRequest(new NSUrlRequest(new NSUrl(entry.link))); this.NavigationItem.Title = entry.title + " - " + entry.subForum; }
public RSSItem copy() { RSSItem dupItem = new RSSItem(); dupItem.ID = this.ID; dupItem.title = this.title; dupItem.link = this.link; dupItem.description = this.description; dupItem.author = this.author; dupItem.category = this.category; dupItem.comments = this.comments; dupItem.pubDate = this.pubDate; dupItem.subForum = this.subForum; dupItem.isFavorite = this.isFavorite; dupItem.isRead = this.isRead; dupItem.type = this.type; return dupItem; }
public RSSItem copy() { RSSItem dupItem = new RSSItem(); dupItem.ID = this.ID; dupItem.title = this.title; dupItem.link = this.link; dupItem.description = this.description; dupItem.author = this.author; dupItem.category = this.category; dupItem.comments = this.comments; dupItem.pubDate = this.pubDate; dupItem.subForum = this.subForum; dupItem.isFavorite = this.isFavorite; dupItem.isRead = this.isRead; dupItem.type = this.type; return(dupItem); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { if (this.SplitViewController == null) { // Push the web view controller onto the navigation stack // this implicitly creates the web view controller's view the first time through this.NavigationController.PushViewController(webViewController, true); } else { this.transferBarButtonItem(webViewController); // We have to create a new Navigation controller, as the old one // was only retained by the split view controller and is now gone UINavigationController nav = new UINavigationController(webViewController); UIViewController[] vcs = new UIViewController[] { this.NavigationController, nav }; this.SplitViewController.ViewControllers = vcs; // Make the detail view controller the delegate of the split view controller // - ignore this warning this.SplitViewController.WeakDelegate = webViewController; if (webViewController.popover != null) { webViewController.popover.Dismiss(true); } } // grab the selected item RSSItem entry = BNRFeedStore.items[indexPath.Row]; if (rssType == ListViewControllerRSSType.BNRFeed) { entry.isRead = true; BNRFeedStore.updateItem(entry); tableView.CellAt(indexPath).Accessory = UITableViewCellAccessory.Checkmark; } webViewController.listViewControllerHandleObject(this, entry); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { // get cell to reuse or create new one. UITableViewCell cell; if (rssType == ListViewControllerRSSType.BNRFeed) { cell = tableView.DequeueReusableCell("UITableViewCellBNR"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "UITableViewCellBNR"); } } else { cell = tableView.DequeueReusableCell("UITableViewCellApple"); if (cell == null) { cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "UITableViewCellApple"); } } // Get item and initialize cell with item info RSSItem item = BNRFeedStore.items[indexPath.Row]; cell.TextLabel.Text = item.title; cell.TextLabel.TextColor = UIColor.Yellow; cell.DetailTextLabel.Text = item.subForum; cell.DetailTextLabel.TextColor = UIColor.Yellow; cell.UserInteractionEnabled = true; cell.BackgroundColor = UIColor.Clear; cell.Accessory = UITableViewCellAccessory.None; cell.SelectedBackgroundView = new UIView() { Frame = cell.Frame, BackgroundColor = UIColor.FromRGB(0.3f, 0.3f, 0.3f) }; // For BNRFeed list. set up Favbutton, check if favorite, decorate button accordingly, add to cell view if (rssType == ListViewControllerRSSType.BNRFeed) { UIButton favButton = new UIButton(UIButtonType.RoundedRect); favButton.Frame = new CGRect(cell.Frame.Size.Width - 17, 0, 17, 44); favButton.AddTarget(this, new Selector("favButtonPressed:"), UIControlEvent.TouchUpInside); favButton.SetTitle("F", UIControlState.Normal); favButton.SetTitleColor(UIColor.White, UIControlState.Normal); favButton.BackgroundColor = UIColor.FromRGB(0.3f, 0.3f, 0.3f); favButton.Tag = indexPath.Row; favButton.AutoresizingMask = UIViewAutoresizing.FlexibleLeftMargin; cell.BringSubviewToFront(favButton); if (item.isFavorite) { favButton.SetTitleColor(UIColor.Green, UIControlState.Normal); favButton.BackgroundColor = UIColor.FromRGB(0.4f, 0.4f, 0.4f); } cell.AddSubview(favButton); } // Set checkmark for read items. if (item.isRead) { cell.Accessory = UITableViewCellAccessory.Checkmark; } return(cell); }
public static void markItemAsFavorite(RSSItem item) { if (!item.isFavorite) item.isFavorite = true; else item.isFavorite = false; updateItem(item); }
// Get Apple JSON rss feed public static async void FetchRSSFeedTopSongs(int count, Block completionBlock) // UITableViewController tvc) { using (var wc = new WebClient()) { string url = String.Format("http://itunes.apple.com/us/rss/topsongs/limit={0}/json", count); channel = new RSSChannel(); channel.type = "songs"; items.Clear(); // Top Songs Cache // string dbPath = GetDBPath(); // SQLiteConnection db; // if (!File.Exists(dbPath)) { // db = new SQLiteConnection(dbPath); // db.CreateTable<RSSItem>(); // db.Close(); // db = null; // } // //db = new SQLiteConnection(dbPath); // //items = db.Query<RSSItem>("SELECT * FROM RSSItems WHERE type='song'"); // // NSDate tscDate = topSongsCacheDate; // if (tscDate != null) { // NSTimeInterval cacheAge = tscDate.SecondsSinceReferenceDate; // } // // End Top Songs Cache try { string JSONData = await wc.DownloadStringTaskAsync(new Uri(url)); JObject parsedJSONData = JObject.Parse (JSONData); channel.parseJSON(parsedJSONData); var entries = parsedJSONData["feed"]["entry"]; foreach (var entry in entries) { RSSItem item = new RSSItem(); item.parseJSON(entry); item.type = "song"; items.Add(item); } completionBlock("success"); } catch (WebException ex) { completionBlock(ex.Message); } } }
static async void FetchRSSAsync(Block completionBlock) { string url = "http://blog.onobytes.com/feed/"; // count_limit=10& string xmlData = null; XDocument doc = null; using (var wc = new WebClient()) { try { xmlData = await wc.DownloadStringTaskAsync(new Uri (url)); } catch (WebException ex) { Console.WriteLine("Exception: {0}", ex.Message); completionBlock(ex.Message); } } try { xmlData = XmlConvert.VerifyXmlChars(xmlData); } catch (XmlException ex) { Console.WriteLine("Exception: {0}", ex.Message); //completionBlock ("Invalid XML received from RSS feed."); List <char> invalidChars = new List <char> () { (char)0x00, (char)0x01, (char)0x02, (char)0x03, (char)0x04, (char)0x05, (char)0x06, (char)0x07, (char)0x08, (char)0x0B, (char)0x0C, (char)0x0E, (char)0x0F, (char)0x10, (char)0x11, (char)0x12, (char)0x13, (char)0x14, (char)0x15, (char)0x16, (char)0x17, (char)0x18, (char)0x19, (char)0x1A, (char)0x1B, (char)0x1C, (char)0x1D, (char)0x1E, (char)0X1F, (char)0x7F, (char)0x80, (char)0x81, (char)0x82, (char)0x83, (char)0x84, (char)0x86, (char)0x87, (char)0x88, (char)0x88, (char)0x89, (char)0x8A, (char)0x8B, (char)0x8C, (char)0x8D, (char)0x8E, (char)0x8F, (char)0x90, (char)0x91, (char)0x92, (char)0x93, (char)0x94, (char)0x95, (char)0x96, (char)0x97, (char)0x98, (char)0x99, (char)0x9A, (char)0x9B, (char)0x9C, (char)0x9D, (char)0x9E, (char)0x9F }; foreach (char c in invalidChars) { xmlData = xmlData.Replace(c, ' '); } } doc = XDocument.Parse(xmlData); channel.parseXML(doc); var allItems = doc.Descendants("item"); string dbPath = GetDBPath(); SQLiteConnection db; db = new SQLiteConnection(dbPath); db.BeginTransaction(); foreach (XElement current in allItems) { RSSItem item = new RSSItem(); item.parseXML(current); item.type = "post"; bool inItems = false; foreach (RSSItem i in items) { if (i.link == item.link) { inItems = true; } } int index = 0; if (!inItems) { items.Insert(index++, item); db.Insert(item); if (db.Table <RSSItem>().Count() > 100) { db.Query <RSSItem>("DELETE FROM RSSItems WHERE rowid IN (SELECT rowid FROM RSSItems ORDER BY rowid ASC LIMIT 1)"); } Console.WriteLine("Items in table: {0} ItemID: {1}", db.Table <RSSItem>().Count(), item.ID); } } db.Commit(); db.Close(); db = null; completionBlock("success"); }
// Get Apple JSON rss feed public static async void FetchRSSFeedTopSongs(int count, Block completionBlock) // UITableViewController tvc) { using (var wc = new WebClient()) { string url = String.Format("http://itunes.apple.com/us/rss/topsongs/limit={0}/json", count); channel = new RSSChannel(); channel.type = "songs"; items.Clear(); // Top Songs Cache // string dbPath = GetDBPath(); // SQLiteConnection db; // if (!File.Exists(dbPath)) { // db = new SQLiteConnection(dbPath); // db.CreateTable<RSSItem>(); // db.Close(); // db = null; // } // //db = new SQLiteConnection(dbPath); // //items = db.Query<RSSItem>("SELECT * FROM RSSItems WHERE type='song'"); // // NSDate tscDate = topSongsCacheDate; // if (tscDate != null) { // NSTimeInterval cacheAge = tscDate.SecondsSinceReferenceDate; // } // // End Top Songs Cache try { string JSONData = await wc.DownloadStringTaskAsync(new Uri(url)); JObject parsedJSONData = JObject.Parse(JSONData); channel.parseJSON(parsedJSONData); var entries = parsedJSONData["feed"]["entry"]; foreach (var entry in entries) { RSSItem item = new RSSItem(); try { item.parseJSON(entry); item.type = "song"; items.Add(item); } catch (Exception ex) { Console.WriteLine("Exception: {0}", ex); if (ex.Message == "Accessed JObject values with invalid key value: 1. Object property name expected.") { Console.WriteLine("iTunes song does not have preview link. Not showing it in list."); } } } completionBlock("success"); } catch (WebException ex) { completionBlock(ex.Message); } } }