mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
User ViewModel to separate logic
This commit is contained in:
parent
15df419a5e
commit
bc47671129
3 changed files with 34 additions and 43 deletions
|
|
@ -17,9 +17,5 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
public DateTime LatestReleaseDate { get; set; }
|
||||
public DateTime DateAdded { get; set; }
|
||||
|
||||
/* Label Data for Plugin Store */
|
||||
public bool LabelNew { get; set; }
|
||||
public bool LabelInstalled { get; set; }
|
||||
public bool LabelUpdated { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
27
Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs
Normal file
27
Flow.Launcher/ViewModel/PluginStoreItemViewModel.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Flow.Launcher.Core.ExternalPlugins;
|
||||
using Flow.Launcher.Core.Plugin;
|
||||
using Flow.Launcher.Plugin;
|
||||
|
||||
namespace Flow.Launcher.ViewModel
|
||||
{
|
||||
public class PluginStoreItemViewModel : BaseModel
|
||||
{
|
||||
public PluginStoreItemViewModel(UserPlugin plugin)
|
||||
{
|
||||
_plugin = plugin;
|
||||
}
|
||||
|
||||
private UserPlugin _plugin;
|
||||
|
||||
public string Name => _plugin.Name;
|
||||
public string Description => _plugin.Description;
|
||||
public string Author => _plugin.Author;
|
||||
public string Version => _plugin.Version;
|
||||
|
||||
|
||||
public bool LabelNew => _plugin.LatestReleaseDate-DateTime.Now < TimeSpan.FromDays(7);
|
||||
public bool LabelInstalled => PluginManager.GetPluginForId(_plugin.ID) != null;
|
||||
public bool LabelUpdated => _plugin.DateAdded -DateTime.Now < TimeSpan.FromDays(7);
|
||||
}
|
||||
}
|
||||
|
|
@ -283,7 +283,7 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
public IList<UserPlugin> ExternalPlugins
|
||||
public IList<PluginStoreItemViewModel> ExternalPlugins
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -291,45 +291,13 @@ namespace Flow.Launcher.ViewModel
|
|||
}
|
||||
}
|
||||
|
||||
private IList<UserPlugin> LabelMaker(IList<UserPlugin> list)
|
||||
private IList<PluginStoreItemViewModel> LabelMaker(IList<UserPlugin> list)
|
||||
{
|
||||
foreach (UserPlugin item in list)
|
||||
{
|
||||
item.LabelNew = false;
|
||||
item.LabelInstalled = false;
|
||||
item.LabelUpdated = false;
|
||||
|
||||
foreach (var vm in PluginViewModels)
|
||||
{
|
||||
|
||||
var id = vm.PluginPair.Metadata.ID;
|
||||
if (item.ID == vm.PluginPair.Metadata.ID) // Add Installed Label
|
||||
{
|
||||
item.LabelInstalled = true;
|
||||
}
|
||||
|
||||
TimeSpan UpdatedDay = DateTime.Now.Subtract(item.LatestReleaseDate);
|
||||
int LastUpdated = UpdatedDay.Days;
|
||||
|
||||
if (LastUpdated <= 5) // Add Updated Label
|
||||
{
|
||||
item.LabelUpdated = true;
|
||||
}
|
||||
}
|
||||
TimeSpan AddedDay = DateTime.Now.Subtract(item.DateAdded);
|
||||
int DateAdded = AddedDay.Days;
|
||||
if (DateAdded <= 7)
|
||||
{
|
||||
|
||||
item.LabelNew = true; // Add New Label
|
||||
item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time.
|
||||
}
|
||||
}
|
||||
|
||||
// New first, Updated second. Installed to bottom of list.
|
||||
list = list.OrderByDescending(x => x.LabelNew).OrderByDescending(x => x.LabelUpdated).ThenBy(y => y.LabelInstalled).ToList();
|
||||
|
||||
return list;
|
||||
return list.Select(p=>new PluginStoreItemViewModel(p))
|
||||
.OrderBy(p=>p.LabelNew)
|
||||
.ThenByDescending(p=>p.LabelUpdated)
|
||||
.ThenBy(p=>p.LabelInstalled)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public Control SettingProvider
|
||||
|
|
|
|||
Loading…
Reference in a new issue