Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Sections on Tableview for Email client App

$
0
0

I am retrieving emails from a pop3 mail account and present them on a tableview.I am using mailkit library. I would like to create 3 sections on my tableview. Section1 “Today”, this where display the emails that i received today. Section2 “Yesterday”, this section where display the emails that i received yesterday. Section3 “Older Emails”, this section where display the emails that i have received 2 days before today. This is my Code:

public class TableSource : UITableViewSource {
protected string[] tableItems;
protected string cellIdentifier = "TableCell";
public TableSource (string[] items)
{
    tableItems = items;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
// do something when row is selected
}
public override int RowsInSection (UITableView tableview, int section)
{
   return tableItems.Length;
}
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
// request a recycled cell to save memory
   UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);   
if (cell == null)
   cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
 cell.TextLabel.Text = tableItems[indexPath.Row];
return cell;
}
}

// This is the loop where i load items to my array and assign as a datasource to my tableview
string[] mycell = new string[200];
for (int i = 0; i < count; i++) {
     var message = client.GetMessage (count, cancel.Token);
     string m = Convert.ToString (message.Date);
     DateTime mydate = Convert.ToDateTime (m);
     string s = mydate.ToString ("MMMM dd, yyyy H:mm") + " " + "Subject:" + Convert.ToString (message.Subject) + " " + "Sender" + Convert.ToString (message.From) ;
     mycell [i] = (Convert.ToString (s));
}
tblmytable = new UITableView (View.Bounds);
Add (tblmytable);
tblmytable.Source = new TableSource (mycell);   

//Email Object
public class EmailItem
{
public DateTime RecievedDate{ get; set; }
public string Subject{ get; set; }
public string Sender{ get; set; }
public EmailItem(DateTime recieveddate, string subject, string sender)
{
   RecievedDate=recieveddate;
   Subject=subject;
   Sender = sender;
 }
}
//Function for isolate the today emails
public  void TodayEmails(EmailItem[] emailarray, EmailItem[] myemailarray)
{
   DateTime curdate = DateTime.Today;
   for (int i = 0; i < emailarray.Length; i++) {
      if (emailarray [i].RecievedDate == curdate) {
          myemailarray [i] = emailarray [i];
    }
 }
}

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>