private const string CREATE_TABLE_QUERY = "CREATE TABLE APP_INFO(NAME VARCHAR(30), SCORE FLOAT(10));";
private const string INSERT_VALUES_QUERY = "INSERT INTO APP_INFO(NAME, SCORE) VALUES('";
private const string SELECT_MAX_SCORE_QUERY = "SELECT MAX(SCORE) FROM APP_INFO;";
+ private const string SELECT_MIN_SCORE_QUERY = "SELECT MIN(SCORE) FROM APP_INFO;";
private const string UPDATE_LAUNCHED_APP_QUERY = "UPDATE APP_INFO SET SCORE = SCORE + 50.00 WHERE NAME = '";
private const string UPDATE_OTHER_APPS_QUERY = "UPDATE APP_INFO SET SCORE = SCORE * 0.90 WHERE NAME !='";
private const string DELETE_APP_QUERY = "DELETE FROM APP_INFO WHERE NAME = '";
private static void OnUninstallProgressChanged(object sender, PackageManagerEventArgs e)
{
- if (e.Progress ==0)
+ if (e.Progress == 0)
{
Package package = PackageManager.GetPackage(e.PackageId);
foreach (ApplicationInfo appInfo in package.GetApplications())
Tizen.Log.Info(Resources.LogTag, "Score Updated of App: " + appId);
}
+ public static void DecreaseScore(string appId)
+ {
+ SqliteCommand sqliteCmd = sqliteConn.CreateCommand();
+ sqliteCmd.CommandText = SELECT_MIN_SCORE_QUERY;
+ SqliteDataReader sqliteDatareader = sqliteCmd.ExecuteReader();
+ sqliteDatareader.Read();
+ float score = sqliteDatareader.GetFloat(0) * 0.90f;
+ sqliteCmd.Dispose();
+ sqliteCmd = sqliteConn.CreateCommand();
+ sqliteCmd.CommandText = "UPDATE APP_INFO SET SCORE = " + score + " WHERE NAME = '" + appId + "';";
+ sqliteCmd.ExecuteNonQuery();
+ OnDatabaseUpdate.Invoke(null, new EventArgs());
+ Tizen.Log.Info(Resources.LogTag, "App Score Decreased: " + appId);
+ }
+
private static void RemoveAppScore(string appId)
{
SqliteCommand sqliteCmd = sqliteConn.CreateCommand();
Tizen.Log.Info(Resources.LogTag, "App Removed from DB: " + appId);
}
- public static Dictionary<string,int> ReadData(int count)
+ public static Dictionary<string, int> ReadData(int count)
{
SqliteDataReader sqliteDatareader;
SqliteCommand sqliteCmd = sqliteConn.CreateCommand();
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
- <TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
- <AssemblyName>TrayApplication</AssemblyName>
+ <LangVersion>8.0</LangVersion>
+ <TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="6.0.7" />
- <PackageReference Include="Tizen.NET" Version="10.0.0.17305" />
+ <PackageReference Include="Tizen.NET" Version="10.0.0.17357" />
<PackageReference Include="Tizen.NET.Sdk" Version="1.1.8" />
</ItemGroup>
using System.Collections;
using System.Collections.Generic;
+using System.Windows.Input;
using Tizen.Applications;
using Tizen.NUI;
+using Tizen.NUI.Binding;
using TrayApplication.Common;
using TrayApplication.Core;
using TrayApplication.Models;
appScoreData = AppScoreDataBase.ReadData(appsCount - 1);
BackgroundColor = ThemeManager.PlatformThemeId == Resources.DarkPlatformThemeId ? Resources.DarkApplicationsBackground : Resources.LightApplicationsBackground;
AddButtonsInfo();
+ AppRemoveCommand = new Command(OnAppRemove);
AppScoreDataBase.OnDatabaseUpdate += OnDatabaseUpdate;
ThemeManager.ThemeChanged += (object sender, ThemeChangedEventArgs e) =>
{
get => buttonsInfo;
set => SetProperty(ref buttonsInfo, value);
}
+
+ private ICommand appRemoveCommand;
+ public ICommand AppRemoveCommand
+ {
+ get => appRemoveCommand;
+ set => SetProperty(ref appRemoveCommand, value);
+ }
+
+ private void OnAppRemove(object removedItem)
+ {
+ AppInfoModel app = (AppInfoModel)removedItem;
+ AppScoreDataBase.DecreaseScore(app.ApplicationId);
+ }
}
}
internal class AppItemView : View
{
public event EventHandler<EventArgs> LongPressed;
+ public event EventHandler<EventArgs> RemoveClicked;
private bool isMoved;
private bool isLongPressed;
{
if (isLongPressed == false && isMoved == false)
{
- AppSelectCommand.Execute(BindingContext);
+ if (RemoveMode == false)
+ {
+ AppSelectCommand.Execute(BindingContext);
+ }
+ else
+ {
+ RemoveClicked.Invoke(this, new EventArgs());
+ }
Tizen.Log.Debug(Resources.LogTag, "Clicked");
}
isLongPressed = false;
public Button CrossButton { get; internal set; }
+ public bool RemoveMode { get; set; }
+
private ICommand appSelectCommand;
public ICommand AppSelectCommand
Add(CrossButton);
RelativeLayout.SetHorizontalAlignment(CrossButton, RelativeLayout.Alignment.End);
RelativeLayout.SetVerticalAlignment(CrossButton, RelativeLayout.Alignment.Start);
+ RemoveMode = true;
+ CrossButton.Clicked += (object sender, ClickedEventArgs e) =>
+ {
+ if (RemoveMode == true)
+ {
+ RemoveClicked.Invoke(this, new EventArgs());
+ }
+ };
+ }
+ }
+
+ public void AddTouchEvent()
+ {
+ TouchEvent += OnTouched;
+ }
+
+ public void RemoveCrossButton()
+ {
+ if(CrossButton != null)
+ {
+ Remove(CrossButton);
+ CrossButton = null;
+ RemoveMode = false;
}
}
+ public void RemoveTouchEvent()
+ {
+ TouchEvent -= OnTouched;
+ }
+
protected override void Dispose(DisposeTypes type)
{
if (Disposed)
using System;
using System.Collections.Generic;
using System.Collections;
+using System.Windows.Input;
using Tizen.NUI;
using Tizen.NUI.BaseComponents;
using Tizen.NUI.Binding;
using TrayApplication.Common;
+using Tizen.NUI.Components;
namespace TrayApplication.Views
{
public class ApplicationsView : View
{
+ public event EventHandler<EventArgs> RemoveModeToggled;
+
private const int ApplicationViewHeight = 189;
private List<AppItemView> appIcons;
private readonly int maxAppsCount;
private int currentAppsCount;
+ private AlertDialog removePopup;
+ private Window removePopupWindow;
public static readonly BindableProperty AppListProperty = BindableProperty.Create(nameof(AppList), typeof(IEnumerable), typeof(ApplicationsView), null, propertyChanged: (bindable, oldValue, newValue) =>
{
},
defaultValueCreator: (bindable) => ((ApplicationsView)bindable).appList);
+ public static readonly BindableProperty AppRemoveCommandProperty = BindableProperty.Create(nameof(AppRemoveCommand), typeof(ICommand), typeof(ApplicationsView), null, propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ var instance = (ApplicationsView)bindable;
+ if (oldValue != newValue)
+ {
+ instance.appRemoveCommand = (ICommand)newValue;
+ }
+ },
+ defaultValueCreator: (bindable) => ((ApplicationsView)bindable).appRemoveCommand);
+
public ApplicationsView(int appsCount) : base()
{
Name = "ApplicationsView";
Tizen.Log.Info(Resources.LogTag, "ApplicationsView");
}
+ public void OnRemoveModeToggled(bool removeMode)
+ {
+ if(removeMode == true)
+ {
+ AddDeleteOption();
+ appIcons[^1].RemoveTouchEvent();
+ appIcons[^1].Opacity = 0.4f;
+ }
+ else
+ {
+ RemoveDeleteOption();
+ appIcons[^1].AddTouchEvent();
+ appIcons[^1].Opacity = 1.0f;
+ }
+ }
+
private void CreateDefaultAppItems()
{
appIcons = new List<AppItemView>();
itemView.Hide();
itemView.LongPressed += (object sender, EventArgs e) =>
{
- AddDeleteOption();
+ RemoveModeToggled.Invoke(this, new EventArgs());
};
appIcons.Add(itemView);
}
}
private IEnumerable appList;
+
public IEnumerable AppList
{
get => (IEnumerable)GetValue(AppListProperty);
set => SetValue(AppListProperty, value);
}
+ private ICommand appRemoveCommand;
+
+ public ICommand AppRemoveCommand
+ {
+ get => (ICommand)GetValue(AppRemoveCommandProperty);
+ set => SetValue(AppRemoveCommandProperty, value);
+ }
+
private void UpdateAppIcons()
{
List<object> appDataList = (List<object>)appList;
for(int i = 0; i < currentAppsCount - 1; i++)
{
appIcons[i].AddCrossButton();
+ appIcons[i].RemoveClicked += (object sender, EventArgs e) =>
+ {
+ AddConfirmationPopup(sender);
+ };
}
}
+ private void RemoveDeleteOption()
+ {
+ for (int i = 0; i < currentAppsCount - 1; i++)
+ {
+ appIcons[i].RemoveCrossButton();
+ }
+ }
+
+ private void AddConfirmationPopup(object appIcon)
+ {
+ Tizen.Log.Info(Resources.LogTag, "Popup Added");
+ if (removePopupWindow == null)
+ {
+ int popupWidth = (int)((DeviceInfo.IsPortrait ? DeviceInfo.DisplayHeight : DeviceInfo.DisplayWidth) * 0.36f);
+ int popupHeight = 256.SpToPx();
+ int windowPositionX = ((DeviceInfo.DisplayWidth - popupWidth) / 2) - 144.SpToPx();
+ int windowPositionY = ((DeviceInfo.DisplayHeight - popupHeight) / 2) - 32.SpToPx();
+ Button cancelButton = new Button("CancelButton");
+ Button deleteButton = new Button()
+ {
+ Size2D = new Size2D(252, 48).SpToPx(),
+ Text = "Delete",
+ };
+ if (removePopup == null)
+ {
+ removePopup = new AlertDialog()
+ {
+ StyleName = "AlertDialogBackground",
+ Size2D = new Size2D(popupWidth, popupHeight),
+ Title = "Delete App from the Tray",
+ Message = "Do you want to delete this app from the Tray? App won't be uninstalled from your device",
+ Actions = new List<Button>() { cancelButton, deleteButton },
+ };
+ }
+ removePopupWindow = new Window
+ {
+ WindowPosition = new Position2D(windowPositionX, windowPositionY),
+ WindowSize = new Size2D(popupWidth + 144.SpToPx(), popupHeight + 32.SpToPx()),
+ };
+ removePopupWindow.SetTransparency(true);
+ removePopupWindow.BackgroundColor = Color.Transparent;
+ removePopupWindow.Add(removePopup);
+ cancelButton.Clicked += (object sender, ClickedEventArgs e) =>
+ {
+ RemoveConfirmationPopup();
+ };
+ deleteButton.Clicked += (object sender, ClickedEventArgs e) =>
+ {
+ AppRemoveCommand.Execute(((AppItemView)appIcon).BindingContext);
+ RemoveConfirmationPopup();
+ };
+ }
+ }
+
+ private void RemoveConfirmationPopup()
+ {
+ removePopupWindow.Remove(removePopup);
+ removePopup.Dispose();
+ removePopup = null;
+ removePopupWindow.Dispose();
+ removePopupWindow = null;
+ RemoveModeToggled.Invoke(this, new EventArgs());
+ }
protected override void Dispose(DisposeTypes type)
{
private ApplicationsView applicationsView;
private QuickAccessView quickAccessView;
private Animation animation;
+ private bool removeMode;
public MainView() : base()
{
applicationsView.BindingContext = applicationViewModel;
applicationsView.SetBinding(BackgroundColorProperty, "BackgroundColor");
applicationsView.SetBinding(ApplicationsView.AppListProperty, "ButtonsInfo");
+ applicationsView.SetBinding(ApplicationsView.AppRemoveCommandProperty, "AppRemoveCommand");
QuickAccessViewModel quickAccessViewModel = new QuickAccessViewModel();
quickAccessView = new QuickAccessView();
Add(quickAccessView);
quickAccessView.SetBinding(BackgroundColorProperty, "BackgroundColor");
quickAccessView.SetBinding(QuickAccessView.AppListProperty, "ButtonsInfo");
ThemeManager.ThemeChanged += OnThemeUpdated;
+ removeMode = false;
+ applicationsView.RemoveModeToggled += ApplicationsViewRemoveModeToggled;
+ }
+
+ private void ApplicationsViewRemoveModeToggled(object sender, EventArgs e)
+ {
+ removeMode = !removeMode;
+ applicationsView.OnRemoveModeToggled(removeMode);
+ quickAccessView.OnRemoveModeToggled(removeMode);
}
private void OnThemeUpdated(object sender, ThemeChangedEventArgs e)
Tizen.Log.Info(Resources.LogTag, "Buttons Added");
}
+ public void OnRemoveModeToggled(bool removeMode)
+ {
+ if (removeMode == true)
+ {
+ DisableButtons();
+ Opacity = 0.4f;
+ }
+ else
+ {
+ EnableButtons();
+ Opacity = 1.0f;
+ }
+ }
+
+ private void DisableButtons()
+ {
+ foreach(Button button in defaultButtons)
+ {
+ button.IsEnabled = false;
+ button.IsSelectable = false;
+ }
+ }
+
+ private void EnableButtons()
+ {
+ foreach (Button button in defaultButtons)
+ {
+ button.IsEnabled = true;
+ button.IsSelectable = true;
+ }
+ }
+
protected override void Dispose(DisposeTypes type)
{
if (Disposed)
Id="DarkTheme">
<ViewStyle x:Key="AppItemBackGround" BackgroundColor="#16131A" />
- <TextLabelStyle x:Key="AppItemLabel" TextColor="#FDFDFD" />
+ <TextLabelStyle x:Key="AppItemLabel" TextColor="#FDFDFD" FontFamily="BreezeSans" />
<c:ButtonStyle x:Key="CrossButton" ThemeChangeSensitive="true" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
<c:ButtonStyle.Icon>
</c:ButtonStyle.Icon>
</c:ButtonStyle>
+ <c:AlertDialogStyle x:Key="AlertDialogBackground" ThemeChangeSensitive="true" BackgroundColor="#16131A">
+ <c:AlertDialogStyle.TitleTextLabel>
+ <TextLabelStyle TextColor="#FDFDFD" FontFamily="BreezeSans" PixelSize="24sp" />
+ </c:AlertDialogStyle.TitleTextLabel>
+ <c:AlertDialogStyle.MessageTextLabel>
+ <TextLabelStyle TextColor="#FDFDFD" FontFamily="BreezeSans" PixelSize="24sp" />
+ </c:AlertDialogStyle.MessageTextLabel>
+ </c:AlertDialogStyle>
+
+ <c:ButtonStyle x:Key="CancelButton" ThemeChangeSensitive="true" Size="252sp, 48sp" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent" >
+ <c:ButtonStyle.Icon>
+ <ImageViewStyle Size="252sp, 48sp">
+ <ImageViewStyle.ResourceUrl>
+ <Selector x:TypeArguments="x:String" Normal="*Resource*/images/dark/cancel_button.png" />
+ </ImageViewStyle.ResourceUrl>
+ </ImageViewStyle>
+ </c:ButtonStyle.Icon>
+ </c:ButtonStyle>
+
</Theme>
\ No newline at end of file
Id="LightTheme">
<ViewStyle x:Key="AppItemBackGround" BackgroundColor="#FAFAFA" />
- <TextLabelStyle x:Key="AppItemLabel" TextColor="#090E21" />
+ <TextLabelStyle x:Key="AppItemLabel" TextColor="#090E21" FontFamily="BreezeSans" />
<c:ButtonStyle x:Key="CrossButton" ThemeChangeSensitive="true" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent">
<c:ButtonStyle.Icon>
</c:ButtonStyle.Icon>
</c:ButtonStyle>
+ <c:AlertDialogStyle x:Key="AlertDialogBackground" ThemeChangeSensitive="true" BackgroundColor="#FAFAFA">
+ <c:AlertDialogStyle.TitleTextLabel>
+ <TextLabelStyle TextColor="#090E21" FontFamily="BreezeSans" PixelSize="24sp" />
+ </c:AlertDialogStyle.TitleTextLabel>
+ <c:AlertDialogStyle.MessageTextLabel>
+ <TextLabelStyle TextColor="#090E21" FontFamily="BreezeSans" PixelSize="24sp" />
+ </c:AlertDialogStyle.MessageTextLabel>
+ </c:AlertDialogStyle>
+
+ <c:ButtonStyle x:Key="CancelButton" ThemeChangeSensitive="true" Size="252sp, 48sp" IsSelectable="false" IsEnabled="true" BackgroundColor="Transparent" >
+ <c:ButtonStyle.Icon>
+ <ImageViewStyle Size="252sp, 48sp">
+ <ImageViewStyle.ResourceUrl>
+ <Selector x:TypeArguments="x:String" Normal="*Resource*/images/light/cancel_button.png" />
+ </ImageViewStyle.ResourceUrl>
+ </ImageViewStyle>
+ </c:ButtonStyle.Icon>
+ </c:ButtonStyle>
+
</Theme>
\ No newline at end of file