Skip to content

Commit bc47671

Browse files
committed
User ViewModel to separate logic
1 parent 15df419 commit bc47671

File tree

3 files changed

+34
-43
lines changed

3 files changed

+34
-43
lines changed

Flow.Launcher.Core/ExternalPlugins/UserPlugin.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,5 @@ public record UserPlugin
1717
public DateTime LatestReleaseDate { get; set; }
1818
public DateTime DateAdded { get; set; }
1919

20-
/* Label Data for Plugin Store */
21-
public bool LabelNew { get; set; }
22-
public bool LabelInstalled { get; set; }
23-
public bool LabelUpdated { get; set; }
2420
}
2521
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using Flow.Launcher.Core.ExternalPlugins;
3+
using Flow.Launcher.Core.Plugin;
4+
using Flow.Launcher.Plugin;
5+
6+
namespace Flow.Launcher.ViewModel
7+
{
8+
public class PluginStoreItemViewModel : BaseModel
9+
{
10+
public PluginStoreItemViewModel(UserPlugin plugin)
11+
{
12+
_plugin = plugin;
13+
}
14+
15+
private UserPlugin _plugin;
16+
17+
public string Name => _plugin.Name;
18+
public string Description => _plugin.Description;
19+
public string Author => _plugin.Author;
20+
public string Version => _plugin.Version;
21+
22+
23+
public bool LabelNew => _plugin.LatestReleaseDate-DateTime.Now < TimeSpan.FromDays(7);
24+
public bool LabelInstalled => PluginManager.GetPluginForId(_plugin.ID) != null;
25+
public bool LabelUpdated => _plugin.DateAdded -DateTime.Now < TimeSpan.FromDays(7);
26+
}
27+
}

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -283,53 +283,21 @@ public IList<PluginViewModel> PluginViewModels
283283
}
284284
}
285285

286-
public IList<UserPlugin> ExternalPlugins
286+
public IList<PluginStoreItemViewModel> ExternalPlugins
287287
{
288288
get
289289
{
290290
return LabelMaker(PluginsManifest.UserPlugins);
291291
}
292292
}
293293

294-
private IList<UserPlugin> LabelMaker(IList<UserPlugin> list)
294+
private IList<PluginStoreItemViewModel> LabelMaker(IList<UserPlugin> list)
295295
{
296-
foreach (UserPlugin item in list)
297-
{
298-
item.LabelNew = false;
299-
item.LabelInstalled = false;
300-
item.LabelUpdated = false;
301-
302-
foreach (var vm in PluginViewModels)
303-
{
304-
305-
var id = vm.PluginPair.Metadata.ID;
306-
if (item.ID == vm.PluginPair.Metadata.ID) // Add Installed Label
307-
{
308-
item.LabelInstalled = true;
309-
}
310-
311-
TimeSpan UpdatedDay = DateTime.Now.Subtract(item.LatestReleaseDate);
312-
int LastUpdated = UpdatedDay.Days;
313-
314-
if (LastUpdated <= 5) // Add Updated Label
315-
{
316-
item.LabelUpdated = true;
317-
}
318-
}
319-
TimeSpan AddedDay = DateTime.Now.Subtract(item.DateAdded);
320-
int DateAdded = AddedDay.Days;
321-
if (DateAdded <= 7)
322-
{
323-
324-
item.LabelNew = true; // Add New Label
325-
item.LabelUpdated = false; // Hide Updated Label when Added New Label. New and Update doesn't show both same time.
326-
}
327-
}
328-
329-
// New first, Updated second. Installed to bottom of list.
330-
list = list.OrderByDescending(x => x.LabelNew).OrderByDescending(x => x.LabelUpdated).ThenBy(y => y.LabelInstalled).ToList();
331-
332-
return list;
296+
return list.Select(p=>new PluginStoreItemViewModel(p))
297+
.OrderBy(p=>p.LabelNew)
298+
.ThenByDescending(p=>p.LabelUpdated)
299+
.ThenBy(p=>p.LabelInstalled)
300+
.ToList();
333301
}
334302

335303
public Control SettingProvider

0 commit comments

Comments
 (0)