Skip to content

Commit 25a81cf

Browse files
Design updated
1 parent d17c9cc commit 25a81cf

File tree

8 files changed

+54
-128
lines changed

8 files changed

+54
-128
lines changed

DataFormMAUI/App.xaml.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ public static SQLiteDatabase Database
2424
return database;
2525
}
2626
}
27-
//protected override Window CreateWindow(IActivationState activationState)
28-
//{
29-
// var window = base.CreateWindow(activationState);
30-
// window.Width = 500;
31-
// window.Height = 00;
32-
// return window;
33-
//}
27+
protected override Window CreateWindow(IActivationState activationState)
28+
{
29+
var window = base.CreateWindow(activationState);
30+
window.Width = 400;
31+
return window;
32+
}
3433
}

DataFormMAUI/DataBase/Constants.cs renamed to DataFormMAUI/DataBase/DatabaseConstants.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace DataFormMAUI
1+
namespace DataFormMAUI
82
{
9-
public static class Constants
3+
public static class DatabaseConstants
104
{
115
public const string DatabaseFilename = "SQLiteDB.db";
126

DataFormMAUI/DataBase/SQLiteDatabase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SQLiteDatabase
88

99
public SQLiteDatabase()
1010
{
11-
_database = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags);
11+
_database = new SQLiteAsyncConnection(DatabaseConstants.DatabasePath, DatabaseConstants.Flags);
1212
_database.CreateTableAsync<ContactFormModel>();
1313
}
1414

DataFormMAUI/Model/ContactsInfoRepository.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,15 @@ namespace DataFormMAUI
44
{
55
class ContactsInfoRepository
66
{
7-
#region Fields
87

98
private Random random = new Random();
10-
119
public ContactFormModel ContactFormModel { get; set; }
1210

13-
#endregion
14-
15-
#region Constructor
16-
1711
public ContactsInfoRepository()
1812
{
1913
this.ContactFormModel = new ContactFormModel();
2014
}
2115

22-
#endregion
23-
24-
#region Get Contacts Details
25-
2616
public ObservableCollection<ContactFormModel> GetContactDetails(int count)
2717
{
2818
ObservableCollection<ContactFormModel> customerDetails = new ObservableCollection<ContactFormModel>();
@@ -32,7 +22,7 @@ public ObservableCollection<ContactFormModel> GetContactDetails(int count)
3222
var details = new ContactFormModel()
3323
{
3424
ID = i+1,
35-
Mobile = random.Next(100, 400).ToString() + "-" + random.Next(500, 800).ToString() + "-" + random.Next(1000, 2000).ToString(),
25+
Mobile = random.Next(100, 400).ToString() + random.Next(500, 800).ToString() + random.Next(1000, 2000).ToString(),
3626
ProfileImage = "People_Circle" + (i % 19) + ".png",
3727
};
3828

@@ -46,9 +36,6 @@ public ObservableCollection<ContactFormModel> GetContactDetails(int count)
4636
return customerDetails;
4737
}
4838

49-
#endregion
50-
51-
#region Contacts Information
5239

5340
int[] imagePosition = new int[]
5441
{
@@ -59,15 +46,6 @@ public ObservableCollection<ContactFormModel> GetContactDetails(int count)
5946
18
6047
};
6148

62-
string[] contactType = new string[]
63-
{
64-
"HOME",
65-
"WORK",
66-
"MOBILE",
67-
"OTHER",
68-
"BUSINESS"
69-
};
70-
7149
string[] CustomerNames_Girls =
7250
[
7351
"Kyle",
@@ -200,7 +178,5 @@ public ObservableCollection<ContactFormModel> GetContactDetails(int count)
200178
"Connor ",
201179
"Michael",
202180
};
203-
204-
#endregion
205181
}
206182
}
3.08 KB
Loading
Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,18 @@
11
using System.Collections.ObjectModel;
2-
using System.ComponentModel;
3-
using System.Linq;
42

53
namespace DataFormMAUI
64
{
7-
public class ContactsViewModel : INotifyPropertyChanged
5+
public class ContactsViewModel
86
{
9-
#region Fields
10-
11-
private ObservableCollection<ContactFormModel> contactsInfo;
12-
private ContactFormModel selectedContact;
13-
14-
#endregion
15-
16-
#region Properties
17-
public ContactFormModel SelectedItem
18-
{
19-
get
20-
{
21-
return selectedContact;
22-
}
23-
set
24-
{
25-
selectedContact = value;
26-
OnPropertyChanged("SelectedItem");
27-
}
28-
}
29-
public ObservableCollection<ContactFormModel> ContactsInfo
30-
{
31-
get
32-
{
33-
return contactsInfo;
34-
}
35-
set
36-
{
37-
contactsInfo = value;
38-
OnPropertyChanged("ContactsInfo");
39-
}
40-
}
41-
7+
public ContactFormModel SelectedItem { get; set; }
8+
public ObservableCollection<ContactFormModel> ContactsInfo { get; set; }
429
public Command CreateContactsCommand { get; set; }
4310
public Command<object> EditContactsCommand { get; set; }
4411
public Command SaveItemCommand { get; set; }
4512
public Command DeleteItemCommand { get; set; }
4613
public Command AddItemCommand { get; set; }
14+
public Command CancelEditCommand { get; set; }
4715

48-
#endregion
49-
50-
#region Constructor
5116
public ContactsViewModel()
5217
{
5318
GenerateContacts();
@@ -56,14 +21,11 @@ public ContactsViewModel()
5621
SaveItemCommand = new Command(OnSaveItem);
5722
DeleteItemCommand = new Command(OnDeleteItem);
5823
AddItemCommand = new Command(OnAddNewItem);
24+
CancelEditCommand = new Command(OnCancelEdit);
5925
}
60-
#endregion
61-
62-
#region Methods
6326

64-
private async void GenerateContacts()
27+
private void GenerateContacts()
6528
{
66-
ContactsInfo = new ObservableCollection<ContactFormModel>();
6729
ContactsInfo = new ContactsInfoRepository().GetContactDetails(20);
6830
PopulateDB();
6931
}
@@ -77,6 +39,11 @@ private async void PopulateDB()
7739
await App.Database.AddContactAsync(contact);
7840
}
7941
}
42+
private async void OnCancelEdit()
43+
{
44+
await App.Current.MainPage.Navigation.PopAsync();
45+
}
46+
8047
private async void OnAddNewItem()
8148
{
8249
await App.Database.AddContactAsync(SelectedItem);
@@ -101,29 +68,16 @@ private void OnEditContacts(object obj)
10168
{
10269
SelectedItem = (obj as Syncfusion.Maui.ListView.ItemTappedEventArgs).DataItem as ContactFormModel;
10370
var editPage = new EditPage();
104-
editPage.BindingContext = SelectedItem;
71+
editPage.BindingContext = this;
10572
App.Current.MainPage.Navigation.PushAsync(editPage);
10673
}
10774

10875
private void OnCreateContacts()
10976
{
110-
SelectedItem = new ContactFormModel() { Name = "", Mobile = "", ProfileImage = "" };
77+
SelectedItem = new ContactFormModel() { Name = "", Mobile = "", ProfileImage = "new.png" };
11178
var editPage = new EditPage();
112-
editPage.BindingContext = SelectedItem;
79+
editPage.BindingContext = this;
11380
App.Current.MainPage.Navigation.PushAsync(editPage);
11481
}
115-
#endregion
116-
117-
#region Interface Member
118-
119-
public event PropertyChangedEventHandler PropertyChanged;
120-
121-
public void OnPropertyChanged(string name)
122-
{
123-
if (this.PropertyChanged != null)
124-
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
125-
}
126-
127-
#endregion
12882
}
12983
}

DataFormMAUI/Views/EditPage.xaml

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@
1111
HasShadow="False" Grid.ColumnSpan="{OnIdiom Default=2, Desktop=1}"
1212
CornerRadius="10" Grid.Column="0" WidthRequest="{OnPlatform WinUI=400, MacCatalyst=600, Default=-1}"
1313
HorizontalOptions="{OnIdiom Desktop=Center, Default=Fill}" Padding="0">
14-
<Frame.Margin>
15-
<OnPlatform x:TypeArguments="thickness:Thickness">
16-
<On Platform="MacCatalyst" Value="20"/>
17-
<On Platform="UWP" Value="20"/>
18-
</OnPlatform>
19-
</Frame.Margin>
2014
<Grid RowDefinitions="0.9*, 1, 0.1*">
2115
<dataForm:SfDataForm x:Name="contactForm"
22-
DataObject="{Binding}"
16+
DataObject="{Binding SelectedItem}"
2317
LayoutType="TextInputLayout"
2418
AutoGenerateItems="False"
2519
ValidationMode="PropertyChanged">
@@ -30,7 +24,7 @@
3024
<dataForm:SfDataForm.Items>
3125
<dataForm:DataFormCustomItem FieldName="ProfileImage" LayoutType="Default">
3226
<dataForm:DataFormCustomItem.EditorView>
33-
<Image Source="{Binding ProfileImage}"
27+
<Image Source="{Binding SelectedItem.ProfileImage}"
3428
HeightRequest="80"/>
3529
</dataForm:DataFormCustomItem.EditorView>
3630
</dataForm:DataFormCustomItem>
@@ -50,7 +44,7 @@
5044
</dataForm:DataFormGroupItem.Items>
5145
</dataForm:DataFormGroupItem>
5246

53-
<dataForm:DataFormGroupItem Name="Mobile">
47+
<dataForm:DataFormGroupItem Name="Mobile" IsExpanded="True">
5448
<dataForm:DataFormGroupItem.Items>
5549
<dataForm:DataFormMaskedTextItem FieldName="Mobile" Mask="(###) ###-####" Keyboard="Numeric">
5650
<dataForm:DataFormMaskedTextItem.LeadingView>
@@ -65,7 +59,7 @@
6559
</dataForm:DataFormGroupItem.Items>
6660
</dataForm:DataFormGroupItem>
6761

68-
<dataForm:DataFormGroupItem Name="Address" ColumnCount="2">
62+
<dataForm:DataFormGroupItem Name="Address" ColumnCount="2" IsExpanded="False">
6963
<dataForm:DataFormGroupItem.Items>
7064
<dataForm:DataFormMultilineItem FieldName="Address" RowSpan="2">
7165
<dataForm:DataFormMultilineItem.LeadingView>
@@ -93,14 +87,24 @@
9387
</dataForm:DataFormTextItem>
9488
</dataForm:SfDataForm.Items>
9589
</dataForm:SfDataForm>
96-
<Line Grid.Row="1" Background="#F5F5F5"/>
97-
<Button Text="Save" Grid.Row="2" x:Name="saveButton" Background="{StaticResource PrimaryBrush}" TextColor="White"
98-
HeightRequest="40"
99-
VerticalOptions="Center"
100-
FontSize="16"
101-
CornerRadius="5"
102-
WidthRequest="200"
103-
HorizontalOptions="Center" />
90+
<Border Grid.Row="1" Background="#F5F5F5"/>
91+
92+
<Grid HeightRequest="35" Grid.Row="2" ColumnDefinitions="*,auto">
93+
<Button x:Name="DeleteButton" Command="{Binding DeleteItemCommand}" Margin="0,0,5,0" BorderColor="Transparent"
94+
Text="Delete" CornerRadius="10"
95+
HorizontalOptions="Start" />
96+
97+
<HorizontalStackLayout HorizontalOptions="End" Grid.Column="1" Margin="0,0,5,0">
98+
<Button CornerRadius="10" Margin="0,0,5,0" HorizontalOptions="Center" BorderColor="Transparent" x:Name="cancelButton"
99+
Text="Cancel" Command="{Binding CancelEditCommand}"/>
100+
101+
<Button Text="Save" CornerRadius="10" Grid.Row="2" x:Name="saveButton" BorderColor="Transparent" Background="{StaticResource PrimaryBrush}" TextColor="White"
102+
VerticalOptions="Center"
103+
Command="{Binding SaveItemCommand}"
104+
HorizontalOptions="Center" />
105+
106+
</HorizontalStackLayout>
107+
</Grid>
104108

105109
</Grid>
106110
</Frame>

DataFormMAUI/Views/MainPage.xaml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
</ContentPage.BindingContext>
1111

1212
<ContentPage.Content>
13-
<Grid >
14-
<syncfusion:SfListView x:Name="listView" ItemsSource="{Binding ContactsViewModel.ContactsInfo}"
13+
<Grid>
14+
<syncfusion:SfListView x:Name="listView"
1515
TapCommand="{Binding EditContactsCommand}"
1616
ScrollBarVisibility="Always"
17-
ItemSize="70">
17+
ItemSize="60">
1818
<syncfusion:SfListView.ItemTemplate>
1919
<DataTemplate>
2020
<ViewCell>
2121
<ViewCell.View>
22-
<Grid x:Name="grid" RowSpacing="0" RowDefinitions="auto,1" >
22+
<Grid x:Name="grid" RowSpacing="0" RowDefinitions="*,1" >
2323
<Grid ColumnDefinitions="70,*,auto">
2424
<Image Source="{Binding ProfileImage}"
2525
VerticalOptions="Center"
@@ -42,18 +42,17 @@
4242
FontSize="{OnPlatform Android={OnIdiom Phone=12, Tablet=14}, iOS={OnIdiom Phone=12, Tablet=14}, MacCatalyst=14, WinUI={OnIdiom Phone=12, Tablet=12, Desktop=12}}" />
4343
</Grid>
4444
</Grid>
45-
<StackLayout Grid.Row="1" BackgroundColor="#E4E4E4" HeightRequest="1"/>
45+
<Border Grid.Row="1" BackgroundColor="#E4E4E4" HeightRequest="1"/>
4646
</Grid>
4747
</ViewCell.View>
4848
</ViewCell>
4949
</DataTemplate>
5050
</syncfusion:SfListView.ItemTemplate>
5151
</syncfusion:SfListView>
5252

53-
<ImageButton Margin="15" HeightRequest="60" WidthRequest="60" Background="{StaticResource Primary}"
54-
AbsoluteLayout.LayoutFlags="PositionProportional"
55-
AbsoluteLayout.LayoutBounds="1.0,1.0,-1,-1"
53+
<ImageButton Margin="20" CornerRadius="20" HeightRequest="40" WidthRequest="40" Background="{StaticResource Primary}"
54+
VerticalOptions="End" HorizontalOptions="End"
5655
Command="{Binding CreateContactsCommand}" Source="add.png"/>
5756
</Grid>
5857
</ContentPage.Content>
59-
</ContentPage>
58+
</ContentPage>

0 commit comments

Comments
 (0)