From 345405e7b147aa19277823b648b69158de232af0 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Tue, 7 Jun 2022 14:22:19 +0430 Subject: [PATCH] complete --- iElection/iElection.Android/MainActivity.cs | 5 + .../Properties/AndroidManifest.xml | 12 +- .../iElection.Android.csproj | 6 + iElection/iElection.iOS/iElection.iOS.csproj | 6 + iElection/iElection/App.xaml.cs | 1 + iElection/iElection/Models/Address.cs | 1 + iElection/iElection/Models/Config/Settings.cs | 1 + iElection/iElection/Models/Dto/MainPageDto.cs | 2 +- .../iElection/Models/Entities/Activity.cs | 24 + iElection/iElection/Services/RestWrapper.cs | 4 +- .../iElection/Utilities/UserUtilities.cs | 22 + .../ViewModels/AddContactPageViewModel.cs | 4 +- .../ViewModels/LoginPageViewModel.cs | 5 +- .../iElection/ViewModels/MainPageViewModel.cs | 183 ++++++- .../ViewModels/SignUpPageViewModel.cs | 5 +- .../iElection/ViewModels/TestPageViewModel.cs | 16 + .../Views/Controllers/PostItemTemplate.xaml | 65 +++ .../Controllers/PostItemTemplate.xaml.cs | 39 ++ iElection/iElection/Views/LoginPage.xaml | 2 +- iElection/iElection/Views/MainPage.xaml | 471 ++++++++++-------- iElection/iElection/Views/TestPage.xaml | 23 + iElection/iElection/Views/TestPage.xaml.cs | 43 ++ .../iElection/Views/Themes/LightTheme.xaml | 5 +- iElection/iElection/iElection.csproj | 12 +- 24 files changed, 709 insertions(+), 248 deletions(-) create mode 100644 iElection/iElection/Models/Entities/Activity.cs create mode 100644 iElection/iElection/ViewModels/TestPageViewModel.cs create mode 100644 iElection/iElection/Views/Controllers/PostItemTemplate.xaml create mode 100644 iElection/iElection/Views/Controllers/PostItemTemplate.xaml.cs create mode 100644 iElection/iElection/Views/TestPage.xaml create mode 100644 iElection/iElection/Views/TestPage.xaml.cs diff --git a/iElection/iElection.Android/MainActivity.cs b/iElection/iElection.Android/MainActivity.cs index 3029d6b..a206ad8 100644 --- a/iElection/iElection.Android/MainActivity.cs +++ b/iElection/iElection.Android/MainActivity.cs @@ -3,6 +3,8 @@ using Android.App; using Android.Content.PM; using Android.OS; using Android.Views; +using MediaManager; +using MediaManager.Forms.Platforms.Android; using Prism; using Prism.Ioc; using Xamarin.Forms.Platform.Android; @@ -23,6 +25,9 @@ namespace iElection.Droid Xamarin.Forms.Forms.SetFlags(new string[] { "CarouselView_Experimental", "SwipeView_Experimental", "IndicatorView_Experimental" }); FFImageLoading.Forms.Platform.CachedImageRenderer.Init(true); Rg.Plugins.Popup.Popup.Init(this); + + CrossMediaManager.Current.Init(this); + global::Xamarin.Forms.Forms.Init(this, savedInstanceState); diff --git a/iElection/iElection.Android/Properties/AndroidManifest.xml b/iElection/iElection.Android/Properties/AndroidManifest.xml index 1514d2e..e8aafa5 100644 --- a/iElection/iElection.Android/Properties/AndroidManifest.xml +++ b/iElection/iElection.Android/Properties/AndroidManifest.xml @@ -1,7 +1,15 @@  - - + + + + + + + + + + \ No newline at end of file diff --git a/iElection/iElection.Android/iElection.Android.csproj b/iElection/iElection.Android/iElection.Android.csproj index cf10a66..7ab3309 100644 --- a/iElection/iElection.Android/iElection.Android.csproj +++ b/iElection/iElection.Android/iElection.Android.csproj @@ -68,6 +68,12 @@ + + 3.1.0 + + + 1.0.8 + 8.0.0.1909 diff --git a/iElection/iElection.iOS/iElection.iOS.csproj b/iElection/iElection.iOS/iElection.iOS.csproj index 166e861..00898f6 100644 --- a/iElection/iElection.iOS/iElection.iOS.csproj +++ b/iElection/iElection.iOS/iElection.iOS.csproj @@ -198,6 +198,12 @@ + + 3.1.0 + + + 1.0.8 + 8.0.0.1909 diff --git a/iElection/iElection/App.xaml.cs b/iElection/iElection/App.xaml.cs index f11b004..c368641 100644 --- a/iElection/iElection/App.xaml.cs +++ b/iElection/iElection/App.xaml.cs @@ -50,6 +50,7 @@ namespace iElection containerRegistry.RegisterForNavigation(); containerRegistry.RegisterForNavigation(); + containerRegistry.RegisterForNavigation(); } } } diff --git a/iElection/iElection/Models/Address.cs b/iElection/iElection/Models/Address.cs index 57ff1a5..805bb40 100644 --- a/iElection/iElection/Models/Address.cs +++ b/iElection/iElection/Models/Address.cs @@ -13,5 +13,6 @@ namespace iElection.Models public static string NotificationController { get; } = $"{BaseController}Notification"; public static string ContactController { get; } = $"{BaseController}Contact"; public static string PageController { get; } = $"{BaseController}Page"; + public static string ActivityController { get; } = $"{BaseController}Activity"; } } diff --git a/iElection/iElection/Models/Config/Settings.cs b/iElection/iElection/Models/Config/Settings.cs index 5205e40..a241728 100644 --- a/iElection/iElection/Models/Config/Settings.cs +++ b/iElection/iElection/Models/Config/Settings.cs @@ -7,5 +7,6 @@ namespace iElection.Models.Config public static class Settings { public static string UserToken { get; set; } = "UserToken"; + public static string FullName { get; set; } = "FullName"; } } diff --git a/iElection/iElection/Models/Dto/MainPageDto.cs b/iElection/iElection/Models/Dto/MainPageDto.cs index b6b378c..65e4d1b 100644 --- a/iElection/iElection/Models/Dto/MainPageDto.cs +++ b/iElection/iElection/Models/Dto/MainPageDto.cs @@ -10,6 +10,6 @@ namespace iElection.Models.Dto { public ObservableCollection Notifications { get; set; } = new ObservableCollection(); public ObservableCollection Contacts { get; set; } = new ObservableCollection(); - + public ObservableCollection Activities { get; set; } = new ObservableCollection(); } } diff --git a/iElection/iElection/Models/Entities/Activity.cs b/iElection/iElection/Models/Entities/Activity.cs new file mode 100644 index 0000000..55bbc72 --- /dev/null +++ b/iElection/iElection/Models/Entities/Activity.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace iElection.Models.Entities +{ + public enum ActivityType + { + Image, Clip + } + + public class Activity + { + public int Id { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public string NameFile { get; set; } + public string ImageUrl { get; set; } + public string ClipUrl { get; set; } + + public ActivityType ActivityType { get; set; } + public string CreateAt { get; set; } + } +} diff --git a/iElection/iElection/Services/RestWrapper.cs b/iElection/iElection/Services/RestWrapper.cs index bb9cf8d..dc83bcf 100644 --- a/iElection/iElection/Services/RestWrapper.cs +++ b/iElection/iElection/Services/RestWrapper.cs @@ -54,8 +54,8 @@ namespace iElection.Services await UtilitiesWrapper.Instance.PopUpUtilities.PushAsync(popup); popup.Accepted += ((sender, e) => { - //UtilitiesWrapper.Instance.UserUtilities.Logout(); - //NavigationService.NavigateAsync("myapp:///NavigationPage/LoginPage"); + UtilitiesWrapper.Instance.UserUtilities.LogOut(); + NavigationService.NavigateAsync("myapp:///NavigationPage/LoginPage"); }); } } diff --git a/iElection/iElection/Utilities/UserUtilities.cs b/iElection/iElection/Utilities/UserUtilities.cs index 7f2e701..e4755ec 100644 --- a/iElection/iElection/Utilities/UserUtilities.cs +++ b/iElection/iElection/Utilities/UserUtilities.cs @@ -23,7 +23,29 @@ namespace iElection.Utilities _userToken = value; } } + private string _fullName; + public string FullName + { + get + { + if (_fullName == null) + _fullName = Preferences.Get(Settings.FullName, string.Empty); + return _fullName; + } + set + { + Preferences.Set(Settings.FullName, value); + _fullName = value; + } + } + public void LogOut() + { + _userToken = null; + Preferences.Set(Settings.UserToken, null); + _fullName = null; + Preferences.Set(Settings.FullName, null); + } public bool IsAuthorized { get diff --git a/iElection/iElection/ViewModels/AddContactPageViewModel.cs b/iElection/iElection/ViewModels/AddContactPageViewModel.cs index 9104098..27023c7 100644 --- a/iElection/iElection/ViewModels/AddContactPageViewModel.cs +++ b/iElection/iElection/ViewModels/AddContactPageViewModel.cs @@ -115,8 +115,7 @@ namespace iElection.ViewModels { try { - if (string.IsNullOrEmpty(PageDto.FirstName)) - throw new Exception("نام را وارد کنید"); + UtilitiesWrapper.Instance.PopUpUtilities.PushIndicator(); if (string.IsNullOrEmpty(PageDto.LastName)) throw new Exception("نام خانوادگی را وارد کنید"); if (string.IsNullOrEmpty(PageDto.Phone)) @@ -129,6 +128,7 @@ namespace iElection.ViewModels .Create(PageDto, UtilitiesWrapper.Instance.UserUtilities.UserToken); if (rest.IsSuccess) { + UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); UtilitiesWrapper.Instance.PopUpUtilities.PushSuccess("افزودن مخاطب با موفقیت انجام شد"); } } diff --git a/iElection/iElection/ViewModels/LoginPageViewModel.cs b/iElection/iElection/ViewModels/LoginPageViewModel.cs index ebc1a22..4acb5dc 100644 --- a/iElection/iElection/ViewModels/LoginPageViewModel.cs +++ b/iElection/iElection/ViewModels/LoginPageViewModel.cs @@ -30,6 +30,7 @@ namespace iElection.ViewModels { try { + UtilitiesWrapper.Instance.PopUpUtilities.PushIndicator(); if (string.IsNullOrEmpty(PageDto.Phone)) throw new Exception("شماره تلفن خود را وارد کنید"); if (string.IsNullOrEmpty(PageDto.Password)) @@ -37,8 +38,10 @@ namespace iElection.ViewModels var rest = await RestWrapper.AccountApiRest.LoginUser(PageDto); if (rest.IsSuccess) { + UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); UtilitiesWrapper.Instance.UserUtilities.UserToken = "Bearer " + rest.Data.jwt; - await NavigationService.NavigateAsync("MainPage"); + UtilitiesWrapper.Instance.UserUtilities.FullName = rest.Data.fullName; + await NavigationService.NavigateAsync("myapp:///NavigationPage/MainPage"); } } catch (ApiException e) diff --git a/iElection/iElection/ViewModels/MainPageViewModel.cs b/iElection/iElection/ViewModels/MainPageViewModel.cs index d751784..dd08282 100644 --- a/iElection/iElection/ViewModels/MainPageViewModel.cs +++ b/iElection/iElection/ViewModels/MainPageViewModel.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; +using System.Threading.Tasks; using System.Windows.Input; using iElection.Models; using iElection.Models.Dto; @@ -22,8 +23,22 @@ namespace iElection.ViewModels public ICommand AddNewContactCommand { get; set; } public ICommand SelectContactCommand { get; set; } public ICommand SelectNotificationCommand { get; set; } + public ICommand ContactsRefreshCommand { get; set; } + public ICommand ActivitiesRefreshCommand { get; set; } + public ICommand ResomeRefreshCommand { get; set; } + public ICommand NotificationsRefreshCommand { get; set; } + public ICommand LogOutCommand { get; set; } public bool IsWorking { get; set; } = false; + public bool IsContactsRefreshing { get; set; } = false; + private bool isContactsRefreshing = false; + public bool IsResomeRefreshing { get; set; } = false; + private bool isResomeRefreshing = false; + public bool IsActivityRefreshing { get; set; } = false; + private bool isActivityRefreshing = false; + public bool IsNotificationRefreshing { get; set; } = false; + private bool isNotificationRefreshing = false; public string Text { get; set; } + public string FullName { get; set; } public ObservableCollection Images { get; set; } = new ObservableCollection(); public MainPageViewModel(INavigationService navigationService , IRestWrapper restWrapper) : base(navigationService,restWrapper) { @@ -36,34 +51,18 @@ namespace iElection.ViewModels { if (IsWorking) return; - PageDto.Contacts.Clear(); - PageDto.Notifications.Clear(); - Images.Clear(); IsWorking = true; - - UtilitiesWrapper.Instance.PopUpUtilities.PushIndicator(); - var rest = await RestWrapper.CrudApiRest(Address.NotificationController) - .ReadAll(UtilitiesWrapper.Instance.UserUtilities.UserToken); - if (rest.IsSuccess) - rest.Data.ForEach(n => PageDto.Notifications.Add(n)); - var restContact = await RestWrapper.CrudApiRest(Address.ContactController) - .ReadAll(UtilitiesWrapper.Instance.UserUtilities.UserToken); - if (restContact.IsSuccess) - restContact.Data.ForEach(c => PageDto.Contacts.Add(c)); - var restCV = await RestWrapper.PageRestApi.GetInfoCv(UtilitiesWrapper.Instance.UserUtilities.UserToken); - if (restCV.IsSuccess) - { - Text = restCV.Data.Text; - restCV.Data.Images.ForEach(i=>Images.Add(i)); - Title = restCV.Data.Title; - } - await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + FullName = UtilitiesWrapper.Instance.UserUtilities.FullName; + GetActivities(); + GetContacts(); + GetNotifications(); + await GetResome(); } catch (ApiException e) { await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); - RestWrapper.UnhandledExceptionRaiser(e); + RestWrapper.UnhandledExceptionRaiser(e,NavigationService); } catch (Exception e) { @@ -76,9 +75,136 @@ namespace iElection.ViewModels } } + public async Task GetActivities() + { + try + { + if (isActivityRefreshing) + return; + PageDto.Activities.Clear(); + isActivityRefreshing = true; + var restActive = await RestWrapper.CrudApiRest(Address.ActivityController) + .ReadAll(UtilitiesWrapper.Instance.UserUtilities.UserToken); + if (restActive.IsSuccess) + { + restActive.Data.ForEach(a => PageDto.Activities.Add(a)); + } + + } + catch (ApiException e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + RestWrapper.UnhandledExceptionRaiser(e, NavigationService); + } + catch (Exception e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + UtilitiesWrapper.Instance.PopUpUtilities.PushError(e.Message); + } + finally + { + isActivityRefreshing = false; + IsActivityRefreshing = false; + } + } + public async Task GetResome() + { + try + { + if (isResomeRefreshing) + return; + Images.Clear(); + isResomeRefreshing = true; + var restCV = await RestWrapper.PageRestApi.GetInfoCv(UtilitiesWrapper.Instance.UserUtilities.UserToken); + if (restCV.IsSuccess) + { + Text = restCV.Data.Text; + restCV.Data.Images.ForEach(i => Images.Add(i)); + Title = restCV.Data.Title; + } + + } + catch (ApiException e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + RestWrapper.UnhandledExceptionRaiser(e, NavigationService); + } + catch (Exception e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + UtilitiesWrapper.Instance.PopUpUtilities.PushError(e.Message); + } + finally + { + IsResomeRefreshing = false; + isResomeRefreshing = false; + } + } + public async Task GetNotifications() + { + try + { + if (isNotificationRefreshing) + return; + PageDto.Notifications.Clear(); + isNotificationRefreshing = true; + var rest = await RestWrapper.CrudApiRest(Address.NotificationController) + .ReadAll(UtilitiesWrapper.Instance.UserUtilities.UserToken); + if (rest.IsSuccess) + rest.Data.ForEach(n => PageDto.Notifications.Add(n)); + + } + catch (ApiException e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + RestWrapper.UnhandledExceptionRaiser(e, NavigationService); + } + catch (Exception e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + UtilitiesWrapper.Instance.PopUpUtilities.PushError(e.Message); + } + finally + { + isNotificationRefreshing = false; + IsNotificationRefreshing = false; + } + } + public async Task GetContacts() + { + try + { + if(isContactsRefreshing) + return; + PageDto.Contacts.Clear(); + isContactsRefreshing = true; + var restContact = await RestWrapper.CrudApiRest(Address.ContactController) + .ReadAll(UtilitiesWrapper.Instance.UserUtilities.UserToken); + if (restContact.IsSuccess) + restContact.Data.ForEach(c => PageDto.Contacts.Add(c)); + + } + catch (ApiException e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + RestWrapper.UnhandledExceptionRaiser(e, NavigationService); + } + catch (Exception e) + { + await UtilitiesWrapper.Instance.PopUpUtilities.PopAsync(); + UtilitiesWrapper.Instance.PopUpUtilities.PushError(e.Message); + } + finally + { + isContactsRefreshing = false; + IsContactsRefreshing = false; + } + } + public override void InitializeCommand() { base.InitializeCommand(); + AddNewContactCommand = new DelegateCommand(() => { NavigationService.NavigateAsync("AddContactPage"); @@ -109,7 +235,7 @@ namespace iElection.ViewModels } catch (ApiException e) { - RestWrapper.UnhandledExceptionRaiser(e); + RestWrapper.UnhandledExceptionRaiser(e, NavigationService); } catch (Exception e) { @@ -131,7 +257,7 @@ namespace iElection.ViewModels } catch (ApiException e) { - RestWrapper.UnhandledExceptionRaiser(e); + RestWrapper.UnhandledExceptionRaiser(e, NavigationService); } catch (Exception e) { @@ -139,6 +265,15 @@ namespace iElection.ViewModels } }); + ContactsRefreshCommand = new DelegateCommand(async () => await GetContacts()); + NotificationsRefreshCommand = new DelegateCommand(async () => await GetNotifications()); + ActivitiesRefreshCommand = new DelegateCommand(async () => await GetActivities()); + ResomeRefreshCommand = new DelegateCommand(async () => await GetResome()); + LogOutCommand = new DelegateCommand(async () => + { + UtilitiesWrapper.Instance.UserUtilities.LogOut(); + await NavigationService.NavigateAsync("myapp:///NavigationPage/LoginPage"); + }); } } } diff --git a/iElection/iElection/ViewModels/SignUpPageViewModel.cs b/iElection/iElection/ViewModels/SignUpPageViewModel.cs index a38f14e..75bce4a 100644 --- a/iElection/iElection/ViewModels/SignUpPageViewModel.cs +++ b/iElection/iElection/ViewModels/SignUpPageViewModel.cs @@ -19,7 +19,7 @@ namespace iElection.ViewModels public RegisterInfoDto InfoDto { get; set; } = new RegisterInfoDto(); public ICommand SignUpCommand { get; set; } public ICommand LoginCommand { get; set; } - public SignUpPageViewModel(INavigationService navigationService , IRestWrapper restWrapper):base(navigationService,restWrapper) + public SignUpPageViewModel(INavigationService navigationService, IRestWrapper restWrapper) : base(navigationService, restWrapper) { } @@ -94,7 +94,8 @@ namespace iElection.ViewModels { UtilitiesWrapper.Instance.UserUtilities.UserToken = "Bearer " + rest.Data.jwt; - await NavigationService.NavigateAsync("MainPage"); + UtilitiesWrapper.Instance.UserUtilities.FullName = rest.Data.fullName; + await NavigationService.NavigateAsync("myapp:///NavigationPage/MainPage"); UtilitiesWrapper.Instance.PopUpUtilities.PushSuccess("ثبت نام با موفقیت انجام شد"); } diff --git a/iElection/iElection/ViewModels/TestPageViewModel.cs b/iElection/iElection/ViewModels/TestPageViewModel.cs new file mode 100644 index 0000000..9920e36 --- /dev/null +++ b/iElection/iElection/ViewModels/TestPageViewModel.cs @@ -0,0 +1,16 @@ +using Prism.Commands; +using Prism.Mvvm; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace iElection.ViewModels +{ + public class TestPageViewModel : BindableBase + { + public TestPageViewModel() + { + + } + } +} diff --git a/iElection/iElection/Views/Controllers/PostItemTemplate.xaml b/iElection/iElection/Views/Controllers/PostItemTemplate.xaml new file mode 100644 index 0000000..01948e9 --- /dev/null +++ b/iElection/iElection/Views/Controllers/PostItemTemplate.xaml @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/iElection/iElection/Views/Controllers/PostItemTemplate.xaml.cs b/iElection/iElection/Views/Controllers/PostItemTemplate.xaml.cs new file mode 100644 index 0000000..c74ef87 --- /dev/null +++ b/iElection/iElection/Views/Controllers/PostItemTemplate.xaml.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using iElection.Models.Entities; +using Xamarin.Essentials; +using Xamarin.Forms; +using Xamarin.Forms.Xaml; + +namespace iElection.Views.Controllers +{ + [XamlCompilation(XamlCompilationOptions.Compile)] + public partial class PostItemTemplate : ContentView + { + public PostItemTemplate() + { + InitializeComponent(); + } + + protected override void OnBindingContextChanged() + { + base.OnBindingContextChanged(); + if (BindingContext is Activity activity) + { + if (activity.ActivityType == ActivityType.Clip) + clipButton.IsVisible = true; + else + clipButton.IsVisible = false; + } + } + + + private void PlayVideo_OnTapped(object sender, EventArgs e) + { + Launcher.OpenAsync((BindingContext as Activity).ClipUrl); + } + } +} \ No newline at end of file diff --git a/iElection/iElection/Views/LoginPage.xaml b/iElection/iElection/Views/LoginPage.xaml index bc0cb77..9366b2a 100644 --- a/iElection/iElection/Views/LoginPage.xaml +++ b/iElection/iElection/Views/LoginPage.xaml @@ -41,7 +41,7 @@ MaterialTheme="Acrylic"> - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + Text="{Binding FullName}" + TextColor="White" + VerticalOptions="Center" /> +