Skip to content

Commit

Permalink
Finished android opt. and orario in profile
Browse files Browse the repository at this point in the history
  • Loading branch information
Murkrow02 committed Nov 9, 2020
1 parent f1eaf44 commit e3eb782
Show file tree
Hide file tree
Showing 16 changed files with 190 additions and 222 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified SalveminiApiCore/.DS_Store
Binary file not shown.
Binary file modified SalveminiApiCore/SalveminiApi core/.DS_Store
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.codex.salveminiapp" android:versionCode="20" android:versionName="30">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.codex.salveminiapp" android:versionCode="21" android:versionName="31">
<uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
<application android:label="Salvemini">
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
Expand Down
4 changes: 2 additions & 2 deletions SalveminiNetStandard/SalveminiApp.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Salvemini ha bisogno di verificare la tua posizione per attivare il codice</string>
<key>CFBundleVersion</key>
<string>12</string>
<string>13</string>
<key>CFBundleShortVersionString</key>
<string>31</string>
<string>32</string>
</dict>
</plist>
22 changes: 19 additions & 3 deletions SalveminiNetStandard/SalveminiApp/Controls/OrarioFoto.xaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="SalveminiApp.Controls.OrarioFoto">
<ContentView.Content>
</ContentView.Content>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:SalveminiApp" xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" xmlns:iconize="clr-namespace:Plugin.Iconize;assembly=Plugin.Iconize" x:Class="SalveminiApp.Controls.OrarioFoto">
<Frame IsClippedToBounds="True" HasShadow="False" CornerRadius="20" Padding="0" HorizontalOptions="FillAndExpand">
<Grid>
<ffimageloading:CachedImage CacheType="All" Aspect="AspectFit" HorizontalOptions="FillAndExpand" HeightRequest="250" x:Name="TimetableImage"/>
<StackLayout x:Name="TimetableButtonsLayout" Padding="10" Orientation="Horizontal">
<Frame IsVisible="False" x:Name="TimetableDownloadButtonContainer" HorizontalOptions="Center" HasShadow="False" Padding="0" WidthRequest="40" CornerRadius="10" HeightRequest="40" VerticalOptions="End">
<iconize:IconButton BackgroundColor="Transparent" Text="fas-arrow-to-bottom" Clicked="TimetableDownloadButtonContainer_Clicked" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Padding="0" FontSize="20" TextColor="White" />
</Frame>
<Frame x:Name="TimetableExpandButtonContainer" HorizontalOptions="EndAndExpand" HasShadow="False" Padding="0" WidthRequest="40" CornerRadius="10" HeightRequest="40" VerticalOptions="End">
<iconize:IconButton BackgroundColor="Transparent" Text="fas-expand" Clicked="TimetableExpandButtonContainer_Clicked" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Padding="0" FontSize="20" TextColor="White" />
</Frame>
</StackLayout>
<!--Placeholder-->
<StackLayout IsVisible="false" x:Name="NoTimetableLayout" HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<iconize:IconLabel BackgroundColor="Transparent" Text="far-clock" HorizontalOptions="Center" FontSize="30" TextColor="{x:Static local:Styles.TextGray}"/>
<Label Text="Non siamo riusciti a recuperare il tuo orario" HorizontalOptions="Center" HorizontalTextAlignment="Center" TextColor="{x:Static local:Styles.TextGray}"/>
</StackLayout>
</Grid>
</Frame>
</ContentView>
140 changes: 140 additions & 0 deletions SalveminiNetStandard/SalveminiApp/Controls/OrarioFoto.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;

namespace SalveminiApp.Controls
Expand All @@ -9,6 +11,144 @@ public partial class OrarioFoto : ContentView
public OrarioFoto()
{
InitializeComponent();

//Set colors
TimetableExpandButtonContainer.BackgroundColor = Color.FromRgba(0, 0, 0, 120);
TimetableDownloadButtonContainer.BackgroundColor = Color.FromRgba(0, 0, 0, 120);

}



public static readonly BindableProperty ClasseCorsoProperty = BindableProperty.Create(nameof(ClasseCorso), typeof(string), typeof(Orario), default(string), Xamarin.Forms.BindingMode.TwoWay);
public string ClasseCorso
{
get
{
return (string)GetValue(ClasseCorsoProperty);
}

set
{
SetValue(ClasseCorsoProperty, value);
}
}


//Update values
protected override async void OnPropertyChanged(string propertyName = null)
{
base.OnPropertyChanged(propertyName);

try
{
if (propertyName == ClasseCorsoProperty.PropertyName)
{
myClass = ClasseCorso == Preferences.Get("Classe", 0).ToString() + Preferences.Get("Corso", "");

//Hide download button if not my class and fast load image
if (myClass && !string.IsNullOrEmpty(Preferences.Get("TimeTableUrl", "")))
{
TimetableDownloadButtonContainer.IsVisible = true;

TimetableImage.Source = Preferences.Get("TimeTableUrl", "");

}
await Task.Run((Action)DownloadOrario);
}
}
catch (Exception ex){ }
}


public void DownloadOrario()
{
//Add final m for classes of 6 chars
if (ClasseCorso.Substring(ClasseCorso.Length - 2).ToLower() == "ca")
{
ClasseCorso = ClasseCorso.Remove(ClasseCorso.Length - 2) + "cam";
}
//Low "cam" string due case sensitive website
if (ClasseCorso.Contains("CAM"))
{
ClasseCorso = ClasseCorso.Remove(ClasseCorso.Length - 3) + "cam";
}

//Bool for last timetable found
bool found = false;
for (int p = 6; p < 20; p++)
{
try
{
//Try getting result from link
System.Net.WebRequest request = System.Net.WebRequest.Create($"https://www.salvemini.edu.it/orario/2020_21/p{p}/Classi/{ClasseCorso}.jpg");
//Only get <Head> tag for low data request
request.Method = "HEAD";
request.GetResponse();
//Reach this only if website is found
found = true;
}
catch
{
//First not found
if (found)
{
//Set final url
TimeTableUrl = $"https://www.salvemini.edu.it/orario/2020_21/p{p - 1}/Classi/{ClasseCorso}.jpg";
if (myClass)
Preferences.Set("TimeTableUrl", TimeTableUrl);
break;
}
}
}

Device.BeginInvokeOnMainThread(() =>
{
//Check if there is a timetable
if (string.IsNullOrEmpty(TimeTableUrl))
{
//No => show placeholder
NoTimetableLayout.IsVisible = true;
TimetableImage.IsVisible = false;
TimetableButtonsLayout.IsVisible = false;
return;
}
else
{
//Yes => Hide placeholder
NoTimetableLayout.IsVisible = false;
TimetableImage.IsVisible = true;
TimetableButtonsLayout.IsVisible = true;
}

//Set timetable image source
TimetableImage.Source = TimeTableUrl;
});
}


string TimeTableUrl = "";
bool myClass;

void TimetableExpandButtonContainer_Clicked(System.Object sender, System.EventArgs e)
{
//Create stormlion image list
var imageList = new List<PhotoBrowser.Photo>();
imageList.Add(new PhotoBrowser.Photo { Title = "Orario", URL = TimeTableUrl });
var imageViewer = new PhotoBrowser.PhotoBrowser();
imageViewer.Photos = imageList;
//Display timetable
imageViewer.Show();
}

void TimetableDownloadButtonContainer_Clicked(System.Object sender, System.EventArgs e)
{
DependencyService.Get<IPlatformSpecific>().SavePictureToDisk("Orario", TimetableImage.GetImageAsJpgAsync().Result);
}

void getOrario()
{

}
}
}
19 changes: 1 addition & 18 deletions SalveminiNetStandard/SalveminiApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,7 @@
<!--Layout-->
<StackLayout Padding="15,10,15,20" Spacing="15" x:Name="fullLayout">
<!--Orario-->
<Frame IsClippedToBounds="True" HasShadow="False" CornerRadius="20" Padding="0" HorizontalOptions="FillAndExpand">
<Grid>
<ffimageloading:CachedImage Aspect="AspectFit" HorizontalOptions="FillAndExpand" HeightRequest="250" x:Name="TimetableImage"/>
<StackLayout x:Name="TimetableButtonsLayout" Padding="10" Orientation="Horizontal">
<Frame x:Name="TimetableDownloadButtonContainer" HorizontalOptions="Center" HasShadow="False" Padding="0" WidthRequest="40" CornerRadius="10" HeightRequest="40" VerticalOptions="End">
<iconize:IconButton BackgroundColor="Transparent" Text="fas-arrow-to-bottom" Clicked="TimetableDownloadButtonContainer_Clicked" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Padding="0" FontSize="20" TextColor="White" />
</Frame>
<Frame x:Name="TimetableExpandButtonContainer" HorizontalOptions="EndAndExpand" HasShadow="False" Padding="0" WidthRequest="40" CornerRadius="10" HeightRequest="40" VerticalOptions="End">
<iconize:IconButton BackgroundColor="Transparent" Text="fas-expand" Clicked="TimetableExpandButtonContainer_Clicked" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Padding="0" FontSize="20" TextColor="White" />
</Frame>
</StackLayout>
<!--Placeholder-->
<StackLayout IsVisible="false" x:Name="NoTimetableLayout" HorizontalOptions="FillAndExpand" VerticalOptions="Center">
<iconize:IconLabel BackgroundColor="Transparent" Text="far-clock" HorizontalOptions="Center" FontSize="30" TextColor="{x:Static local:Styles.TextGray}"/>
<Label Text="Non siamo riusciti a recuperare il tuo orario" HorizontalOptions="Center" HorizontalTextAlignment="Center" TextColor="{x:Static local:Styles.TextGray}"/>
</StackLayout>
</Grid>
</Frame>
<Controls:OrarioFoto x:Name="FotoOrario"/>
<!--WidgetList-->
<StackLayout VerticalOptions="Start">
<!--Widgets-->
Expand Down
100 changes: 9 additions & 91 deletions SalveminiNetStandard/SalveminiApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ public MainPage()
{
InitializeComponent();

//Set colors
TimetableExpandButtonContainer.BackgroundColor = Color.FromRgba(0, 0, 0, 120);
TimetableDownloadButtonContainer.BackgroundColor = Color.FromRgba(0, 0, 0, 120);

//Subscribe to messaging center
//Refresh image cache
MessagingCenter.Subscribe<App, string>(this, "ReloadUserPic", (sender, arg) =>
Expand All @@ -64,81 +60,20 @@ public MainPage()

}

string TimeTableUrl = "";
void getOrario()
{
//Get stored class
var classe = Preferences.Get("Classe", 0).ToString() + Preferences.Get("Corso", "");

//Add final m for classes of 6 chars
if (classe.Substring(classe.Length - 2).ToLower() == "ca")
{
classe = classe.Remove(classe.Length - 2) + "cam";
}
//Low "cam" string due case sensitive website
if (classe.Contains("CAM"))
{
classe = classe.Remove(classe.Length - 3) + "cam";
}

//Bool for last timetable found
bool found = false;
for (int p = 6; p < 20; p++)
{
try
{
//Try getting result from link
System.Net.WebRequest request = System.Net.WebRequest.Create($"https://www.salvemini.edu.it/orario/2020_21/p{p}/Classi/{classe}.jpg");
//Only get <Head> tag for low data request
request.Method = "HEAD";
request.GetResponse();
//Reach this only if website is found
found = true;
}
catch
{
//First not found
if (found)
{
//Set final url
TimeTableUrl = $"https://www.salvemini.edu.it/orario/2020_21/p{p - 1}/Classi/{classe}.jpg";
Preferences.Set("TimeTableUrl", TimeTableUrl);
break;
}
}
}

Device.BeginInvokeOnMainThread(() =>
{
//Check if there is a timetable
if (string.IsNullOrEmpty(TimeTableUrl))
{
//No => show placeholder
NoTimetableLayout.IsVisible = true;
TimetableImage.IsVisible = false;
TimetableButtonsLayout.IsVisible = false;
return;
}
else
{
//Yes => Hide placeholder
NoTimetableLayout.IsVisible = false;
TimetableImage.IsVisible = true;
TimetableButtonsLayout.IsVisible = true;
}

//Set timetable image source
TimetableImage.Source = TimeTableUrl;
});
}


//Detect if onappearing must be triggered
public static bool forceAppearing; bool userRefreshed = true;
protected async override void OnAppearing()
{
base.OnAppearing();

//Set tabbar image
MessagingCenter.Send<App, string>((App)Xamarin.Forms.Application.Current, "changeBg", "bbar.jpg");
try
{
MessagingCenter.Send<App, string>((App)Xamarin.Forms.Application.Current, "changeBg", "bbar.jpg");
}
catch { }

//Push on notification page clicked
if (NotificationPage != null)
Expand Down Expand Up @@ -220,9 +155,6 @@ protected async override void OnAppearing()
//Show loading
userRefreshed = false; homeLoading.IsRefreshing = true; userRefreshed = true;

//Timetable Cache
TimetableImage.Source = Preferences.Get("TimeTableUrl", "");

//Argo index in background
await Task.Run((Action)GetArgoIndex);

Expand Down Expand Up @@ -274,7 +206,7 @@ protected async override void OnAppearing()
}

//Update orario in background
await Task.Run((Action)getOrario);
FotoOrario.ClasseCorso = Preferences.Get("Classe", 0).ToString() + Preferences.Get("Corso", "");

//Get last sondaggio
if (Index.ultimoSondaggio != null) //New sondaggio detected
Expand Down Expand Up @@ -820,21 +752,7 @@ void AdInfo_Clicked(object sender, EventArgs e)
DisplayAlert("Info Sponsor", "Il liceo Salvemini non lucra in alcun modo da questo progetto, tutto il guadagno è indirizzato agli sviluppatori dell'app", "Ok");
}

void TimetableExpandButtonContainer_Clicked(System.Object sender, System.EventArgs e)
{
//Create stormlion image list
var imageList = new List<PhotoBrowser.Photo>();
imageList.Add(new PhotoBrowser.Photo { Title = "Orario", URL = TimeTableUrl });
var imageViewer = new PhotoBrowser.PhotoBrowser();
imageViewer.Photos = imageList;
//Display timetable
imageViewer.Show();
}

void TimetableDownloadButtonContainer_Clicked(System.Object sender, System.EventArgs e)
{
DependencyService.Get<IPlatformSpecific>().SavePictureToDisk("Orario", TimetableImage.GetImageAsJpgAsync().Result);
}

}


Expand Down
4 changes: 2 additions & 2 deletions SalveminiNetStandard/SalveminiApp/RestApi/Models/Avviso.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Avvisi
public int idCreatore { get; set; }
public DateTime Creazione { get; set; }
public bool SendNotification { get; set; }
public Utenti Utenti { get; set; }
public Utenti IdCreatoreNavigation { get; set; }

public List<string> FullImmagini
{
Expand Down Expand Up @@ -68,7 +68,7 @@ public string nomeCreatore
{
get
{
try { return "Creato da " + Utenti.nomeCognome; } catch { return ""; }
try { return "Creato da " + IdCreatoreNavigation.nomeCognome; } catch { return ""; }
}
}

Expand Down
Loading

0 comments on commit e3eb782

Please sign in to comment.