Skip to content

Instantly share code, notes, and snippets.

@nodoid
Created October 19, 2015 22:35
Show Gist options
  • Save nodoid/c118a7296a5e803a9c23 to your computer and use it in GitHub Desktop.
Save nodoid/c118a7296a5e803a9c23 to your computer and use it in GitHub Desktop.
// from my DTO
public class PropertyChange : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged == null)
return;
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public class Profile:PropertyChange,IIdentity
{
[PrimaryKey, AutoIncrement]
public int id { get; private set; }
public string xACCid { get; set; }
public string xACCtype { get; set; }
private string xacctitle;
public string xACCtitle
{
get
{
return xacctitle;
}
set
{
if (xacctitle != value)
{
xacctitle = value;
OnPropertyChanged("xACCtitle");
}
}
}
private string xaccfname;
public string xACCfname
{
get { return xaccfname; }
set
{
if (xaccfname != value)
{
xaccfname = value;
OnPropertyChanged("xACCfname");
}
}
}
private string xaccsname;
public string xACCsname
{
get { return xaccsname; }
set
{
if (xaccsname != value)
{
xaccsname = value;
OnPropertyChanged("xACCsname");
}
}
}
public string xACCaddr1 { get; set; }
public string xACCaddr2 { get; set; }
public string xACCtown { get; set; }
public string xACCcounty { get; set; }
public string xACCpostcode { get; set; }
public string xACCdtel { get; set; }
public string xACCetel { get; set; }
public string xACCcell { get; set; }
private string xaccupdated;
public string xACCupdated
{
get { return xaccupdated; }
set
{
if (xaccupdated != value)
{
xaccupdated = value;
OnPropertyChanged("xACCupdated");
}
}
}
string xfoldercount;
public string xFOLDERcount
{
get
{
return xfoldercount;
}
set
{
if (xfoldercount != value)
{
xfoldercount = value;
OnPropertyChanged("xFOLDERcount");
}
}
}
string xfilecount;
public string xFILEcount
{
get
{
return xfilecount;
}
set
{
if (xfilecount != value)
{
xfilecount = value;
OnPropertyChanged("xFILEcount");
}
}
}
public string xCUSTtoken { get; set; }
[Ignore]
public string status { get; set; }
[Ignore]
public string message { get; set; }
}
public class UserProfile:PropertyChange, IIdentity
{
[PrimaryKey, AutoIncrement]
public int id { get; private set; }
public string xACCid { get; set; }
public string xCUSTtoken { get; set; }
public string status { get; set; }
public string message { get; set; }
private List<Profile> prof;
[Ignore]
public List<Profile> profiles
{
get
{
return prof;
}set
{
prof = value;
OnPropertyChanged("profiles");
}
}
}
// ContentPage
public class Box
{
public BoxView VertLine()
{
return new BoxView()
{
Color = Color.FromHex("ddd"),
WidthRequest = 1,
HeightRequest = 40
};
}
}
public class Vault : ContentPage
{
UserProfile userProfile = new UserProfile();
Folders folders = new Folders();
Page thisPage;
StackLayout stackLayout;
public Vault()
{
NavigationPage.SetHasBackButton(this, false);
if (Device.OS == TargetPlatform.iOS)
{
Padding = new Thickness(0, 20, 0, 0);
}
BackgroundColor = App.Self.Background;
thisPage = this;
BindingContext = App.Current;
RunView();
}
async void RunView()
{
await GrabProfile();
}
void RunUI()
{
var topbar = new TopBar().CreateTopBar();
var btnNewProfile = new SquareButton()
{
Text = "CREATE A NEW PROFILE",
FontAttributes = FontAttributes.Italic | FontAttributes.Bold,
TextColor = Color.Black,
BackgroundColor = App.Self.Mustard,
WidthRequest = App.ScreenSize.Width * .9,
HorizontalOptions = LayoutOptions.CenterAndExpand,
HeightRequest = App.ScreenSize.Height * .1
};
btnNewProfile.Clicked += CreateNewProfile;
var lblProfile = new Label
{
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Profile",
WidthRequest = (App.ScreenSize.Width * .9) / 3,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
var lblCreated = new Label
{
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Created",
WidthRequest = (App.ScreenSize.Width * .9) / 3,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
var lblUpdated = new Label
{
BackgroundColor = Color.Black,
TextColor = Color.White,
Text = "Updated",
WidthRequest = (App.ScreenSize.Width * .9) / 3,
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.CenterAndExpand
};
var lblSpace = new Label
{
WidthRequest = (App.ScreenSize.Width * .9) * .095,
};
var stackTitle = TitleBar.CreateTopStack("Your", "Vault");
var topStack = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
WidthRequest = App.ScreenSize.Width * .9,
HeightRequest = App.ScreenSize.Height * .1,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
BackgroundColor = Color.Black,
Children =
{
new Box().VertLine(), lblProfile, new Box().VertLine(), lblCreated, new Box().VertLine(), lblUpdated, new Box().VertLine(), lblSpace
}
};
var imgFolder = new Image
{
Source = ImageSource.FromFile(Device.OS == TargetPlatform.WinPhone ? "Assets/character.png" : "character.png"),
HeightRequest = App.ScreenSize.Height * .15,
WidthRequest = App.ScreenSize.Width * .15,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.EndAndExpand
};
var data = userProfile.profiles;
var obsdata = new ObservableCollection<Profile>();
foreach (var d in data)
obsdata.Add(d);
var listView = new ListView()
{
ItemsSource = obsdata,
ItemTemplate = new DataTemplate(typeof(ProfileList)),
SeparatorVisibility = SeparatorVisibility.None,
Header = topStack,
};
listView.ItemSelected += ViewFolders;
stackLayout = new StackLayout
{
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Children =
{
new StackLayout
{
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Start,
WidthRequest = App.ScreenSize.Width,
Children = { topbar }
},
new StackLayout
{
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.CenterAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
WidthRequest = App.ScreenSize.Width * .9,
Children =
{
new StackLayout
{
Padding = new Thickness(0, 6),
HorizontalOptions = LayoutOptions.CenterAndExpand,
Children = { /*lblTitle*/ stackTitle }
},
new StackLayout
{
VerticalOptions = LayoutOptions.CenterAndExpand,
HeightRequest = App.ScreenSize.Height * .6,
Padding = new Thickness(0, 16, 0, 0),
Children =
{
//topStack,
listView,
btnNewProfile,
}
},
new StackLayout
{
VerticalOptions = LayoutOptions.End,
HorizontalOptions = LayoutOptions.CenterAndExpand,
Children = { imgFolder }
}
}
}
}
};
Content = stackLayout;
}
async void ViewFolders(object s, SelectedItemChangedEventArgs e)
{
var lv = s as ListView;
var item = e.SelectedItem as Profile;
var page = thisPage.ParentView as TabbedPage;
if (item != null)
{
page.Children.RemoveAt(0);
page.Children.Insert(0, new FolderView(item, thisPage));
page.Children[0].Title = "The Vault";
page.Children[0].Icon = Device.OS == TargetPlatform.WinPhone ? "Assets/tab_vault.png" : "tab_vault.png";
page.CurrentPage = page.Children[0];
}
if (lv != null)
lv.SelectedItem = null;
}
async Task GrabProfile()
{
userProfile.xCUSTtoken = App.Self.Settings.GetSetting<string>("token");
userProfile = await Networking.WebServiceForData(userProfile, "profiles");
if (!userProfile.status.Contains("ok"))
await DisplayAlert("Login Error", string.Format("The server has returned the following message - {0}. Please check your data and retry", userProfile.message), "OK");
else
App.Self.DBManager.AddOrUpdateProfiles(userProfile.profiles);
folders.xCUSTtoken = App.Self.Settings.GetSetting<string>("token");
folders.xACCid = userProfile.profiles[0].xACCid;
folders = await Networking.WebServiceForData(folders, "folders");
if (!folders.status.Contains("ok"))
await DisplayAlert("Login Error", string.Format("The server has returned the following message - {0}. Please check your data and retry", folders.message), "OK");
else
{
App.Self.Settings.SetSetting("SOSFolder", folders.folders.FirstOrDefault(t => t.xFOLDERtype == "SOS").xFOLDERid);
App.Self.DBManager.AddOrUpdateFolders(folders.folders);
RunUI();
}
}
void CreateNewProfile(object s, EventArgs e)
{
var cv = new NewProfile()
{
IsClippedToBounds = true,
ClassId = "0"
};
stackLayout.Children.Add(cv);
}
}
public class ProfileList : ViewCell
{
StackLayout dupView;
public ProfileList()
{
var lblfname = new Label
{
Text = "lyric",
FontSize = 12,
TextColor = App.Self.Mustard,
HorizontalOptions = LayoutOptions.StartAndExpand,
};
lblfname.SetBinding(Label.TextProperty, new Binding("xACCfname"));
var lblsname = new Label
{
Text = "lyric",
FontSize = 12,
TextColor = App.Self.Mustard,
HorizontalOptions = LayoutOptions.StartAndExpand,
};
lblsname.SetBinding(Label.TextProperty, new Binding("xACCsname"));
var stackName = new StackLayout
{
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
WidthRequest = (App.ScreenSize.Width * .9) / 4,
Orientation = StackOrientation.Vertical,
Children = { lblfname, lblsname }
};
var lblfolders = new Label
{
Text = "lyric",
FontSize = 12,
TextColor = App.Self.Mustard,
HorizontalOptions = LayoutOptions.StartAndExpand,
};
lblfolders.SetBinding(Label.TextProperty, new Binding("xFOLDERcount", stringFormat: "{0} folders"));
var lblfiles = new Label
{
Text = "lyric",
FontSize = 12,
TextColor = App.Self.Mustard,
HorizontalOptions = LayoutOptions.StartAndExpand,
};
lblfiles.SetBinding(Label.TextProperty, new Binding("xFILEcount", stringFormat: "{0} files"));
var stackFiles = new StackLayout
{
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
WidthRequest = (App.ScreenSize.Width * .9) / 4,
Orientation = StackOrientation.Vertical,
Children = { lblfolders, lblfiles }
};
var lblDate = new Label
{
Text = "lyric",
FontSize = 12,
TextColor = App.Self.Mustard,
HorizontalOptions = LayoutOptions.StartAndExpand,
};
lblDate.SetBinding(Label.TextProperty, new Binding("xACCupdated"));
/*lblDate.BindingContextChanged += (object sender, EventArgs e) =>
{
Debug.WriteLine("hello");
};*/
var stackDate = new StackLayout
{
HorizontalOptions = LayoutOptions.StartAndExpand,
VerticalOptions = LayoutOptions.CenterAndExpand,
WidthRequest = (App.ScreenSize.Width * .9) / 4,
Orientation = StackOrientation.Vertical,
Children = { lblDate }
};
var imgEdit = new Image
{
Source = ImageSource.FromFile(Device.OS == TargetPlatform.WinPhone ? "Assets/edit.png" : "edit.png"),
VerticalOptions = LayoutOptions.CenterAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
WidthRequest = 20,
HeightRequest = 20
};
imgEdit.SetBinding(Image.ClassIdProperty, new Binding("xACCid"));
var gesture = new TapGestureRecognizer()
{
NumberOfTapsRequired = 1
};
gesture.Tapped += EditProfile;
imgEdit.GestureRecognizers.Add(gesture);
dupView = new StackLayout()
{
Orientation = StackOrientation.Horizontal,
VerticalOptions = LayoutOptions.StartAndExpand,
HorizontalOptions = LayoutOptions.CenterAndExpand,
WidthRequest = App.ScreenSize.Width * .9,
Children = { new Box().VertLine(), stackName, new Box().VertLine(), stackFiles, new Box().VertLine(), stackDate, new Box().VertLine(), imgEdit, new Box().VertLine() }
};
View = dupView;
}
void EditProfile(object s, EventArgs e)
{
var obj = s as Image;
var cv = new NewProfile()
{
IsClippedToBounds = true,
ClassId = obj.ClassId
};
dupView.Children.Add(cv);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment