Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Closed #32 and fixed #9
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed May 22, 2018
1 parent 2018c97 commit 28337f4
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 106 deletions.
5 changes: 5 additions & 0 deletions Data_Manager2/Classes/DBTables/ChatMessageTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class ChatMessageTable
// Does the message is a link to an image
public bool isImage { get; set; }

// Defines if the message is a dummy message like for the personalize settings page chat preview
[Ignore]
public bool isDummyMessage { get; set; }

private static readonly Regex IMAGE_URL_REGEX = new Regex(@"http[s]?:\/\/(([^\/:\.[:space:]]+(\.[^\/:\.[:space:]]+)*)|([0-9](\.[0-9]{3})))(:[0-9]+)?((\/[^?#[:space:]]+)(\?[^#[:space:]]+)?(\#.+)?)?\.(?:jpe?g|gif|png)$");

public event EventHandler ChatMessageChanged;
Expand Down Expand Up @@ -69,6 +73,7 @@ public ChatMessageTable(MessageMessage msg, ChatTable chat)
this.type = msg.TYPE;
this.message = msg.MESSAGE;
this.date = msg.getDelay();
this.isDummyMessage = false;
if (this.date == null || this.date.Equals(DateTime.MinValue))
{
this.date = DateTime.Now;
Expand Down
1 change: 1 addition & 0 deletions Data_Manager2/Classes/SettingsConsts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class SettingsConsts
public const string HIDE_INITIAL_START_DIALOG_ALPHA = "hide_initial_start_dialog_alpha";
public const string HIDE_WHATS_NEW_DIALOG = "hide_whats_new_dialog_alpha_5_1";
public const string CHAT_BACKGROUND_IMAGE_NAME = "chat_background_image_path";
public const string CHAT_BACKGROUND_MODE = "chat_background_mode";
public const string DISABLE_SOCKET_BACKGROUND_TASK = "disable_socket_background_task";
public const string ENTER_TO_SEND_MESSAGES = "enter_to_send_messages";
public const string DONT_SEND_CHAT_STATE = "dont_send_chat_state";
Expand Down
112 changes: 104 additions & 8 deletions UWP XMPP Client/Classes/BackgroundImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ class BackgroundImageCache
#region --Attributes--
public static CustomObservableCollection<BackgroundImageTemplate> backgroundImages;
public static BackgroundImageTemplate selectedImage;
public static BackgroundImageTemplate customBackgroundImage;
public static bool loaded;

public const byte EXAMPLE_BACKGROUND = 0;
public const byte CUSTOM_BACKGROUND = 1;
public const byte NONE_BACKGROUND = 2;

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--
Expand All @@ -24,11 +29,71 @@ class BackgroundImageCache
#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
#region --Set-, Get- Methods--
public static void setCustomBackgroundImage()
{
Settings.setSetting(SettingsConsts.CHAT_BACKGROUND_MODE, CUSTOM_BACKGROUND);
if (selectedImage != null)
{
selectedImage.selected = false;
}
selectedImage = customBackgroundImage;
if (customBackgroundImage != null)
{
customBackgroundImage.selected = true;
}
}

public static void setExampleBackgroundImage(BackgroundImageTemplate img)
{
Settings.setSetting(SettingsConsts.CHAT_BACKGROUND_MODE, EXAMPLE_BACKGROUND);
if (selectedImage != null)
{
selectedImage.selected = false;
}
selectedImage = img;
img.selected = true;
}

#endregion
//--------------------------------------------------------Misc Methods:---------------------------------------------------------------\\
#region --Misc Methods (Public)--
public static void removeBackgroundImage()
{
Settings.setSetting(SettingsConsts.CHAT_BACKGROUND_MODE, NONE_BACKGROUND);
selectedImage = null;
for (int i = 0; i < backgroundImages.Count; i++)
{
backgroundImages[i].selected = false;
}

if (customBackgroundImage != null)
{
customBackgroundImage.selected = false;
}
}

public static async Task<string> saveAsBackgroundImageAsync(StorageFile file)
{
StorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("BackgroundImage", CreationCollisionOption.OpenIfExists);
if (folder != null)
{
StorageFile f = await folder.CreateFileAsync("img", CreationCollisionOption.OpenIfExists);
if (f != null)
{
await file.CopyAndReplaceAsync(f);

customBackgroundImage = new BackgroundImageTemplate()
{
imagePath = f.Path,
name = "custom",
selected = false
};
return f.Path;
}
}
return null;
}

public static void loadCache()
{
if (loaded)
Expand All @@ -42,22 +107,53 @@ public static void loadCache()
DateTime timeStart = DateTime.Now;
try
{
string selectedImageName = Settings.getSettingString(SettingsConsts.CHAT_BACKGROUND_IMAGE_NAME);
try
{
StorageFolder customImagefolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("BackgroundImage", CreationCollisionOption.OpenIfExists);
if (customImagefolder != null)
{
StorageFile f = await customImagefolder.CreateFileAsync("img", CreationCollisionOption.OpenIfExists);
if (f != null)
{
customBackgroundImage = new BackgroundImageTemplate()
{
imagePath = f.Path,
name = "custom",
selected = false
};
}
}
}
catch (Exception e)
{
Logger.Error("Error during loading the custom background image!", e);
}

byte backgroundMode = Settings.getSettingByte(SettingsConsts.CHAT_BACKGROUND_MODE);
string selectedImageName = null;
switch (backgroundMode)
{
case CUSTOM_BACKGROUND:
selectedImage = customBackgroundImage;
break;

case NONE_BACKGROUND:
selectedImage = null;
break;

default:
selectedImageName = Settings.getSettingString(SettingsConsts.CHAT_BACKGROUND_IMAGE_NAME);
break;
}

backgroundImages = new CustomObservableCollection<BackgroundImageTemplate>();
selectedImage = null;
ImageCache.Instance.MaxMemoryCacheCount = 100;
StorageFolder picturesFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(@"Assets\BackgroundImages");
foreach (StorageFile file in await picturesFolder.GetFilesAsync())
{
try
{
Uri imgUri = new Uri(file.Path);
/*await ImageCache.Instance.PreCacheAsync(imgUri, true, true);
BitmapImage img = await ImageCache.Instance.GetFromCacheAsync(imgUri);
if(img == null)
{
continue;
}*/
bool isSelectedImage = selectedImageName != null && selectedImageName.Equals(file.Name);
BackgroundImageTemplate bgI = new BackgroundImageTemplate
{
Expand Down
8 changes: 5 additions & 3 deletions UWP XMPP Client/Classes/UIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public static void setBackgroundImage(ImageEx imgControl)
{
imgControl.Source = null;
imgControl.Visibility = Visibility.Collapsed;
return;
}
imgControl.Source = new BitmapImage(new Uri(img.imagePath));
imgControl.Visibility = Visibility.Visible;
else
{
imgControl.Source = new BitmapImage(new Uri(img.imagePath));
imgControl.Visibility = Visibility.Visible;
}
}

public static string getRandomMaterialColor()
Expand Down
11 changes: 7 additions & 4 deletions UWP XMPP Client/Controls/ChatDetailsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
xmlns:datatemplates="using:UWP_XMPP_Client.DataTemplates"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Loaded="UserControl_Loaded"
Unloaded="UserControl_Unloaded"
mc:Ignorable="d">

<UserControl.Resources>
Expand Down Expand Up @@ -40,7 +41,8 @@
sendMessageTemplate="{StaticResource sendMessageTemplate}"/>
</UserControl.Resources>

<Grid Background="Transparent">
<Grid x:Name="main_grid"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
Expand Down Expand Up @@ -105,7 +107,8 @@
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<controls:AccountImageWithPresenceControl Grid.Column="0"
<controls:AccountImageWithPresenceControl x:Name="accImg_aiwp"
Grid.Column="0"
Width="30"
Height="30"
Margin="10"
Expand Down Expand Up @@ -218,14 +221,14 @@
<Button x:Name="send_btn"
Grid.Column="2"
VerticalAlignment="Bottom"
AllowFocusOnInteraction="False"
Background="{ThemeResource SystemAccentColor}"
BorderBrush="Transparent"
Click="send_btn_Click"
Content="&#xE122;"
FontFamily="Segoe MDL2 Assets"
FontSize="27"
IsEnabled="False"
AllowFocusOnInteraction="False"/>
IsEnabled="False"/>
</Grid>
</Grid>
</Grid>
Expand Down
Loading

0 comments on commit 28337f4

Please sign in to comment.