Subversion Repository Public Repository

Nextrek

Diff Revisions 38 vs 39 for /WindowsPhone/NotizieTL/NotizieTL/MainPage.xaml.cs

Diff revisions: vs.
  @@ -18,22 +18,41 @@
18 18 using System.Text.RegularExpressions;
19 19 using Microsoft.Phone.Shell;
20 20
21 + using System.Threading;
22 + using System.Windows.Controls.Primitives;
23 + using System.ComponentModel;
24 +
21 25 namespace NotizieTL
22 26 {
23 27 public partial class MainPage : PhoneApplicationPage
24 28 {
25 29 private int i = 0;
26 30
31 + PhoneApplicationService phoneAppService = PhoneApplicationService.Current;
32 +
33 + BackgroundWorker backroungWorker;
34 + Popup myPopup;
35 +
27 36 List<Articolo> listArticoli1;
28 37 List<Articolo> listArticoli3;
29 38 List<ArticoloPreferito> listArticoliP = new List<ArticoloPreferito>();
39 + Boolean esistePref;
40 +
41 + System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
42 + System.Windows.Threading.DispatcherTimer dt2 = new System.Windows.Threading.DispatcherTimer();
43 +
44 + System.Windows.Threading.DispatcherTimer dtSplashIn = new System.Windows.Threading.DispatcherTimer();
45 + System.Windows.Threading.DispatcherTimer dtSplashOut = new System.Windows.Threading.DispatcherTimer();
30 46
31 47 // Constructor
32 48 public MainPage()
33 49 {
34 50 //SystemTray.IsVisible = false;
35 51 InitializeComponent();
36 -
52 +
53 + myPopup = new Popup() { IsOpen = true, Child = new AnimatedSplashScreen() };
54 + backroungWorker = new BackgroundWorker();
55 + RunBackgroundWorker();
37 56
38 57 // Set the data context of the listbox control to the sample data
39 58 DataContext = App.ViewModel;
  @@ -49,6 +68,24 @@
49 68 }
50 69 }
51 70
71 + private void RunBackgroundWorker()
72 + {
73 + backroungWorker.DoWork += ((s, args) =>
74 + {
75 + Thread.Sleep(5000);
76 + });
77 +
78 + backroungWorker.RunWorkerCompleted += ((s, args) =>
79 + {
80 + this.Dispatcher.BeginInvoke(() =>
81 + {
82 + this.myPopup.IsOpen = false;
83 + }
84 + );
85 + });
86 + backroungWorker.RunWorkerAsync();
87 + }
88 +
52 89
53 90 private void checkConnection()
54 91 {
  @@ -60,8 +97,19 @@
60 97 }
61 98
62 99
100 +
63 101 private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
64 102 {
103 + //object myValue;
104 + //if (phoneAppService.State.ContainsKey("MyValue"))
105 + //{
106 + // if (phoneAppService.State.TryGetValue("MyValue", out myValue))
107 + // {
108 + // feedListPreferiti.ItemsSource = (List<ArticoloPreferito>)myValue;
109 + // }
110 + //}
111 +
112 +
65 113 checkConnection();
66 114 SystemTray.IsVisible = false;
67 115 feedListPreferiti.ItemsSource = listArticoliP;
  @@ -88,6 +136,7 @@
88 136 // feedListPreferiti.Visibility = System.Windows.Visibility.Collapsed;
89 137 }
90 138
139 +
91 140 // Click handler that runs when the 'Load Feed' or 'Refresh Feed' button is clicked.
92 141 //private void loadFeedButton_Click(object sender, System.Windows.RoutedEventArgs e)
93 142 //{
  @@ -485,6 +534,8 @@
485 534 //Double h = textCanvas.ActualHeight;
486 535 scroller.ScrollToVerticalOffset(0.0);
487 536
537 + nomeAppTesto.Visibility = System.Windows.Visibility.Collapsed;
538 + refreshButton.Visibility = System.Windows.Visibility.Collapsed;
488 539 notiziaCanvas.Visibility = System.Windows.Visibility.Visible;
489 540 ApplicationBar.IsVisible = true;
490 541
  @@ -555,6 +606,8 @@
555 606
556 607 private void CheckBox_Checked(object sender, RoutedEventArgs e)
557 608 {
609 +
610 +
558 611 ListBoxItem checedItem = this.feedListPreferiti.ItemContainerGenerator.ContainerFromItem((sender as CheckBox).DataContext) as ListBoxItem;
559 612 if (checedItem != null)
560 613 {
  @@ -571,6 +624,26 @@
571 624 }
572 625 }
573 626
627 +
628 + private void appBarDelete_Click(object sender, EventArgs e)
629 + {
630 +
631 + if (listArticoliP.Count > 0)
632 + {
633 + foreach (ArticoloPreferito a in listArticoliP)
634 + {
635 + if (a.IsChecked == true)
636 + {
637 + listArticoliP.Remove(a);
638 + feedListPreferiti.ItemsSource = listArticoliP;
639 + }
640 + }
641 + }
642 +
643 + //phoneAppService.State["MyValue"] = feedListPreferiti;
644 + }
645 +
646 +
574 647 private void MenuItem_Click(object sender, RoutedEventArgs e)
575 648 {
576 649
  @@ -605,34 +678,14 @@
605 678 // }
606 679 }
607 680
608 - private void appBarDelete_Click(object sender, EventArgs e)
609 - {
610 -
611 - if (listArticoliP.Count > 0)
612 - {
613 - foreach (ArticoloPreferito a in listArticoliP)
614 - {
615 - if (a.IsChecked == true)
616 - {
617 - listArticoliP.Remove(a);
618 - feedListPreferiti.ItemsSource = listArticoliP;
619 - }
620 - }
621 - }
622 - }
681 +
623 682
624 683
625 684 private void Pivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
626 685 {
627 - if (listArticoliP.Count == 0 && pivot.SelectedIndex == 1)
628 - {
629 - feedListPreferiti.Visibility = System.Windows.Visibility.Collapsed;
630 - noFavoritesText.Visibility = System.Windows.Visibility.Visible;
631 - }
632 -
633 -
634 686 if (pivot.SelectedIndex == 0 || pivot.SelectedIndex == 2)
635 687 {
688 + sfondoLoading.Height = 650.00;
636 689 ApplicationBar.IsVisible = false;
637 690 noFavoritesText.Visibility = System.Windows.Visibility.Collapsed;
638 691
  @@ -640,14 +693,16 @@
640 693 else
641 694 {
642 695 //ApplicationBar.Mode = Microsoft.Phone.Shell.ApplicationBarMode.Minimized;
696 + sfondoLoading.Height = 600.00;
643 697 ApplicationBar.IsVisible = true;
644 - feedListPreferiti.ItemsSource = listArticoliP;
698 + feedListPreferiti.ItemsSource = listArticoliP;
699 + }
645 700
646 - try
647 - {
648 - //appBarDelete.IsEnabled = false;
649 - }
650 - catch { }
701 + if (listArticoliP.Count == 0 && pivot.SelectedIndex == 1)
702 + {
703 + sfondoLoading.Height = 600.00;
704 + feedListPreferiti.Visibility = System.Windows.Visibility.Collapsed;
705 + noFavoritesText.Visibility = System.Windows.Visibility.Visible;
651 706 }
652 707
653 708
  @@ -667,54 +722,23 @@
667 722
668 723 if (notiziaCanvas.Visibility == System.Windows.Visibility.Visible && pivot.SelectedIndex == 0)
669 724 {
725 + nomeAppTesto.Visibility = System.Windows.Visibility.Visible;
726 + refreshButton.Visibility = System.Windows.Visibility.Visible;
670 727 notiziaCanvas.Visibility = System.Windows.Visibility.Collapsed;
671 728 ApplicationBar.IsVisible = false;
729 + e.Cancel = true;
672 730 }
673 731
674 - e.Cancel = true;
675 - }
676 -
677 -
678 - private void PhoneApplicationPage_LayoutUpdated(object sender, EventArgs e)
679 - {
680 - i++;
681 - if (i >= 5)
732 + if (notiziaCanvas.Visibility == System.Windows.Visibility.Visible && pivot.SelectedIndex == 1)
682 733 {
683 - feedListBoxNews1.Visibility = System.Windows.Visibility.Visible;
684 - loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
685 -
734 + nomeAppTesto.Visibility = System.Windows.Visibility.Visible;
735 + refreshButton.Visibility = System.Windows.Visibility.Visible;
736 + notiziaCanvas.Visibility = System.Windows.Visibility.Collapsed;
737 + ApplicationBar.IsVisible = true;
738 + e.Cancel = true;
686 739 }
687 - //else
688 - //{
689 - // feedListBoxNews1.Visibility = System.Windows.Visibility.Collapsed;
690 - // loadingPanel.Visibility = System.Windows.Visibility.Visible;
691 - //}
692 - }
693 -
694 - private void titolo1_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
695 - {
696 740
697 - }
698 -
699 - private void titolo1_LayoutUpdated(object sender, EventArgs e)
700 - {
701 -
702 - }
703 -
704 - private void feedListBoxNews1_LayoutUpdated(object sender, EventArgs e)
705 - {
706 - //i++;
707 - //if (i >= 4)
708 - //{
709 - // feedListBoxNews1.Visibility = System.Windows.Visibility.Visible;
710 - // loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
711 - // i = 0;
712 - //}
713 - //else
714 - //{
715 - // feedListBoxNews1.Visibility = System.Windows.Visibility.Collapsed;
716 - // loadingPanel.Visibility = System.Windows.Visibility.Visible;
717 - //}
741 +
718 742 }
719 743
720 744 private void boxArticolo_Hold(object sender, System.Windows.Input.GestureEventArgs e)
  @@ -742,6 +766,8 @@
742 766 grigliaTesto.Height = 450.00;
743 767 }
744 768
769 + nomeAppTesto.Visibility = System.Windows.Visibility.Collapsed;
770 + refreshButton.Visibility = System.Windows.Visibility.Collapsed;
745 771 notiziaCanvas.Visibility = System.Windows.Visibility.Visible;
746 772 ApplicationBar.IsVisible = true;
747 773 }
  @@ -903,15 +929,29 @@
903 929 else
904 930 stackpanel.Background = oddBackground;
905 931
906 - if (index == 8)
932 +
933 + }
934 +
935 + private void esistePreferito()
936 + {
937 + String titolo = titleCanvas.Text;
938 +
939 + foreach (ArticoloPreferito a in listArticoliP) //controlla se l'articolo preferito che stai per aggiungere esiste, se si ti avvisa
907 940 {
908 - loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
909 - feedListBoxNews1.Visibility = System.Windows.Visibility.Visible;
941 + if (a.Titolo == titolo)
942 + {
943 + MessageBox.Show("Articolo già presente nella lista dei preferiti!");
944 + esistePref = true;
945 + break;
946 + }
947 + else
948 + {
949 + esistePref = false;
950 + }
951 +
910 952 }
911 953 }
912 954
913 -
914 -
915 955 private void appBarAddFavorites_Click(object sender, EventArgs e)
916 956 {
917 957 String titolo = titleCanvas.Text;
  @@ -921,35 +961,37 @@
921 961 //List<ArticoloPreferito> listArtPref = new List<ArticoloPreferito>();
922 962 //listArtPref = listArticoliP;
923 963 ArticoloPreferito ap;
924 -
925 - //if (listArticoliP.Count > 0)
926 - //{
927 -
928 - // foreach (ArticoloPreferito a in listArtPref) //controlla se l'articolo preferito che stai per aggiungere esiste, se si ti avvisa
929 - // {
930 - // if (a.Titolo == titolo)
931 - // {
932 - // MessageBox.Show("Articolo già presente nella lista dei preferiti!");
933 - // }
934 - // else
935 - // {
936 - // ap = new ArticoloPreferito(titolo, "", testo.Substring(0, 125) + "...", testo, data, false);
937 - // listArticoliP.Add(ap);
938 - // }
939 964
940 - // }
941 - //}
965 + if (listArticoliP.Count > 0)
966 +
967 + {
968 + esistePreferito();
969 + if (!esistePref)
970 + {
971 + ap = new ArticoloPreferito(titolo, "", testo.Substring(0, 125) + "...", testo, data, nota, false);
972 + listArticoliP.Add(ap);
973 + }
974 +
975 + }
942 976
943 - //if (listArticoliP.Count == 0) //se la lista preferiti è vuota
944 - //{
977 + if (listArticoliP.Count == 0) //se la lista preferiti è vuota
978 + {
945 979 ap = new ArticoloPreferito(titolo, "", testo.Substring(0, 125) + "...", testo, data, nota, false);
946 980 listArticoliP.Add(ap);
947 - //}
981 + }
948 982
949 - feedListPreferiti.Visibility = System.Windows.Visibility.Visible;
950 - noFavoritesText.Visibility = System.Windows.Visibility.Collapsed;
983 + //listArtPref = listArticoliP;
984 + feedListPreferiti.Visibility = System.Windows.Visibility.Visible;
985 + noFavoritesText.Visibility = System.Windows.Visibility.Collapsed;
951 986
952 - //feedListPreferiti.ItemsSource = listArticoliP;
987 + feedListPreferiti.ItemsSource = listArticoliP;
988 +
989 + var y = feedListPreferiti.ItemsSource;
990 +
991 + phoneAppService.State["MyValue"] = feedListPreferiti.ItemsSource;
992 +
993 + bool b = true;
994 +
953 995
954 996 }
955 997
  @@ -988,6 +1030,8 @@
988 1030 grigliaTesto.Height = 450.00;
989 1031 }
990 1032
1033 + nomeAppTesto.Visibility = System.Windows.Visibility.Collapsed;
1034 + refreshButton.Visibility = System.Windows.Visibility.Collapsed;
991 1035 notiziaCanvas.Visibility = System.Windows.Visibility.Visible;
992 1036 ApplicationBar.IsVisible = true;
993 1037
  @@ -1039,37 +1083,68 @@
1039 1083 private void refreshButton_Click(object sender, RoutedEventArgs e)
1040 1084 {
1041 1085
1042 - //i = 3;
1043 - //PhoneApplicationPage_LayoutUpdated(sender, e);
1044 - WebClient webClient1 = new WebClient();
1045 - webClient1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient1_DownloadStringCompleted);
1046 - webClient1.DownloadStringAsync(new System.Uri("http://tuttolavoro.indicitalia.it/RSS/app.xml"));
1047 1086
1048 - //pivot.Visibility = System.Windows.Visibility.Collapsed;
1049 - loadingPanel.Visibility = System.Windows.Visibility.Visible;
1050 - feedListBoxNews1.Visibility = System.Windows.Visibility.Collapsed;
1087 + if (pivot.SelectedIndex == 0)
1088 + {
1089 + WebClient webClient1 = new WebClient();
1090 + webClient1.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient1_DownloadStringCompleted);
1091 + webClient1.DownloadStringAsync(new System.Uri("http://tuttolavoro.indicitalia.it/RSS/app.xml"));
1092 + }
1093 +
1094 + if (pivot.SelectedIndex == 2)
1095 + {
1096 + WebClient webClient3 = new WebClient();
1097 + webClient3.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient3_DownloadStringCompleted);
1098 + webClient3.DownloadStringAsync(new System.Uri("http://www.wki.it/marketing/app/tuttolavoroApp_Rel_news.xml"));
1099 + }
1100 +
1101 + dt.Interval = new TimeSpan(0, 0, 0); // 3seconds
1102 + dt.Tick += new EventHandler(dt_Tick);
1103 + dt.Start();
1104 + dt2.Start();
1105 +
1106 +
1051 1107
1052 1108 }
1053 1109
1054 - private void pivot_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
1110 + void dt_Tick(object sender, EventArgs e)
1055 1111 {
1056 1112
1057 - }
1113 + // System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
1114 + // dt.Interval = new TimeSpan(0, 0, 3); // 500 Milliseconds
1115 + // dt.Tick += new EventHandler(dt_Tick);
1116 + // dt.Start();
1058 1117
1059 - private void feedListBoxNews1_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
1060 - {
1118 + //CreateFadeInOutAnimation(1.0, 0.0).Begin();
1061 1119
1062 - }
1120 + loadingPanel.Visibility = System.Windows.Visibility.Visible;
1063 1121
1064 - private void feedListBoxNews1_Loaded(object sender, RoutedEventArgs e)
1065 - {
1122 + //if (pivot.SelectedIndex == 0)
1123 + // feedListBoxNews1.Visibility = System.Windows.Visibility.Collapsed;
1124 +
1125 + //if (pivot.SelectedIndex == 2)
1126 + // feedListBoxNews3.Visibility = System.Windows.Visibility.Collapsed;
1066 1127
1128 + dt.Stop();
1129 +
1130 + dt2.Interval = new TimeSpan(0, 0, 3); // 1seconds
1131 + dt2.Tick += new EventHandler(dt2_Tick);
1132 + dt2.Start();
1133 +
1134 +
1135 + //// Do Stuff here.
1067 1136 }
1068 1137
1069 - private void pivot_Loaded(object sender, RoutedEventArgs e)
1138 + void dt2_Tick(object sender, EventArgs e)
1070 1139 {
1140 + loadingPanel.Visibility = System.Windows.Visibility.Collapsed;
1141 + //feedListBoxNews1.Visibility = System.Windows.Visibility.Visible;
1142 + //feedListBoxNews3.Visibility = System.Windows.Visibility.Visible;
1071 1143
1144 + dt2.Stop();
1072 1145 }
1146 +
1147 +
1073 1148
1074 1149
1075 1150