-
-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathSearchViewModel.cs
More file actions
158 lines (139 loc) · 7.79 KB
/
SearchViewModel.cs
File metadata and controls
158 lines (139 loc) · 7.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using System.Diagnostics;
namespace WpfCsMarkupExamples;
public class SearchViewModel : BaseViewModel
{
ICommand? goToOtherCommand, searchCommand, likeCommand;
public string SearchText { get; set; } = string.Empty;
public List<Tweet> SearchResults { get; set; }= new ();
public ICommand GoToOtherCommand => goToOtherCommand ??= new RelayCommand(GoToOther);
public ICommand SearchCommand => searchCommand ??= new RelayCommand(Search);
public ICommand LikeCommand => likeCommand ??= new RelayCommand<Tweet>(Like);
public SearchViewModel Initialize()
{
SearchText = "#CSharpForMarkup";
SearchResults = new List<Tweet>
{
new Tweet
{
AuthorImage = "https://pbs.twimg.com/profile_images/1382769074569154561/2ukpzO8E_400x400.jpg",
Header = "Uno Platform @UnoPlatform · Nov 30",
Body = new List<TextFragment>
{
new TextFragment { Text = "Premiered today at " },
new TextFragment { Text = "#UnoConf", IsMatch = true },
new TextFragment { Text = ":\n\n\U0001F4E2 C# Markup 2 for " },
new TextFragment { Text = "#WinUI3", IsMatch = true },
new TextFragment { Text = " and Uno Platform\n\n" },
new TextFragment { Text = "Check out the preview:\n" },
new TextFragment { Text = "https://github.com/VincentH-Net/CSharpForMarkup", IsMatch = true },
new TextFragment { Text = "\n" },
new TextFragment { Text = "#CSharpForMarkup", IsMatch = true },
new TextFragment { Text = " " },
new TextFragment { Text = "#webassembly", IsMatch = true },
new TextFragment { Text = " " },
new TextFragment { Text = "#dotnet", IsMatch = true },
},
IsLikedByMe = true
},
new Tweet
{
AuthorImage = "https://pbs.twimg.com/profile_images/2159034926/MACAW_vincenth_LThumb_400x400.jpg",
Header = "VincentH.NET @vincenth_net · Nov 30",
Body = new List<TextFragment>
{
new TextFragment { Text = "Released the first preview of\n\U0001F4E2 C# Markup 2 for " },
new TextFragment { Text = "#WinUI3", IsMatch = true },
new TextFragment { Text = " and Uno Platform!\U0001F60E\n" },
new TextFragment { Text = "https://github.com/VincentH-Net/CSharpForMarkup", IsMatch = true },
new TextFragment { Text = "\n\nSee it in action in " },
new TextFragment { Text = "#UnoConf", IsMatch = true },
new TextFragment { Text = " today\n" },
new TextFragment { Text = "#CSharpForMarkup", IsMatch = true }
},
},
new Tweet
{
AuthorImage = "https://pbs.twimg.com/profile_images/1382769074569154561/2ukpzO8E_400x400.jpg",
Header = "Uno Platform @UnoPlatform · Nov 30",
Body = new List<TextFragment>
{
new TextFragment { Text = "Shown at " },
new TextFragment { Text = "#UnoConf", IsMatch = true },
new TextFragment { Text = " today: create browser " },
new TextFragment { Text = "#webassembly", IsMatch = true },
new TextFragment { Text = " apps and native crossplatform apps completely in C# 10, .NET 6 and " },
new TextFragment { Text = "#WinUI3", IsMatch = true },
new TextFragment { Text = ". No XAML or HTML required. Check out the preview:\n\n" },
new TextFragment { Text = "C# Markup 2 for " },
new TextFragment { Text = "#WinUI3", IsMatch = true },
new TextFragment { Text = " and Uno Platform\n" },
new TextFragment { Text = "https://github.com/VincentH-Net/CSharpForMarkup", IsMatch = true },
},
IsLikedByMe = true
},
new Tweet
{
AuthorImage = "https://pbs.twimg.com/profile_images/2159034926/MACAW_vincenth_LThumb_400x400.jpg",
Header = "VincentH.NET @vincenth_net · Nov 30",
Body = new List<TextFragment>
{
new TextFragment { Text = "\U0001F60E Interested in a " },
new TextFragment { Text = "#Flutter", IsMatch = true },
new TextFragment { Text = " like development experience for @UnoPlatform? Check out C# Markup 2 for " },
new TextFragment { Text = "#WinUI3", IsMatch = true },
new TextFragment { Text = " and Uno Platform. Works with " },
new TextFragment { Text = "#dotnet", IsMatch = true },
new TextFragment { Text = " " },
new TextFragment { Text = "#hotreload", IsMatch = true },
new TextFragment { Text = "\U0001F525 in " },
new TextFragment { Text = "#VS2022", IsMatch = true },
new TextFragment { Text = "\n\n" },
new TextFragment { Text = "https://github.com/VincentH-Net/CSharpForMarkup", IsMatch = true },
new TextFragment { Text = "\n" },
new TextFragment { Text = "#CSharpForMarkup", IsMatch = true },
},
},
new Tweet
{
AuthorImage = "https://pbs.twimg.com/profile_images/2159034926/MACAW_vincenth_LThumb_400x400.jpg",
Header = "VincentH.NET @vincenth_net · Nov 15",
Body = new List<TextFragment>
{
new TextFragment { Text = "I have " },
new TextFragment { Text = "#CSharpForMarkup", IsMatch = true },
new TextFragment { Text = " gen 2 working in " },
new TextFragment { Text = "#WinUI3", IsMatch = true },
new TextFragment { Text = " on " },
new TextFragment { Text = "#dotnet6", IsMatch = true },
new TextFragment { Text = " with " },
new TextFragment { Text = "#hotreload", IsMatch = true },
new TextFragment { Text = " in " },
new TextFragment { Text = "#VS2022", IsMatch = true },
new TextFragment { Text = "\n\nNow I can use the " },
new TextFragment { Text = "#csharp10", IsMatch = true },
new TextFragment { Text = " CallerArgumentExpression attribute to eliminate nameof() in bindings\n\n" },
new TextFragment { Text = "Working towards a preview release. More soon!" }
},
IsLikedByMe = true
}
};
return this;
}
public static Uri LinkUri(string linkText) => new(linkText.StartsWith("#") == true ? TwitterSearchUri(linkText) : linkText, uriKind: UriKind.Absolute);
void GoToOther() => App.Current?.NavigateToFlutterPage();
void Search() => App.LaunchUri(new Uri(TwitterSearchUri(SearchText)));
void Like(Tweet tweet) => tweet.IsLikedByMe = !tweet.IsLikedByMe;
public static string TwitterSearchUri(string text) => $"https://twitter.com/search?q={Uri.EscapeDataString(text)}&f=live";
public class Tweet : BaseViewModel
{
public string? AuthorImage { get; set; }
public string? Header { get; set; }
public List<TextFragment>? Body { get; set; }
public bool IsLikedByMe { get; set; }
}
public class TextFragment
{
public string? Text { get; set; }
public bool IsMatch { get; set; }
}
}