Skip to content

Commit 9aa56fa

Browse files
committed
hella nice things
1 parent 07ad7b8 commit 9aa56fa

3 files changed

Lines changed: 50 additions & 5 deletions

File tree

Sora/Utils/ContinueWatching/ContinueWatchingManager.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,12 @@ class ContinueWatchingManager {
3232
}
3333
return []
3434
}
35+
36+
func remove(item: ContinueWatchingItem) {
37+
var items = fetchItems()
38+
items.removeAll { $0.id == item.id }
39+
if let data = try? JSONEncoder().encode(items) {
40+
UserDefaults.standard.set(data, forKey: storageKey)
41+
}
42+
}
3543
}

Sora/Views/HomeView.swift

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ struct HomeView: View {
159159
rootVC.present(videoPlayerViewController, animated: true, completion: nil)
160160
}
161161
}) {
162-
VStack {
162+
VStack(alignment: .leading) {
163163
ZStack {
164-
KFImage(URL(string: item.imageUrl))
164+
KFImage(URL(string: item.imageUrl.isEmpty ? "https://raw.githubusercontent.com/cranci1/Sora/refs/heads/main/assets/banner2.png" : item.imageUrl))
165165
.placeholder {
166166
RoundedRectangle(cornerRadius: 10)
167167
.fill(Color.gray.opacity(0.3))
@@ -174,6 +174,14 @@ struct HomeView: View {
174174
.frame(width: 240, height: 135)
175175
.cornerRadius(10)
176176
.clipped()
177+
.overlay(
178+
KFImage(URL(string: item.module.metadata.iconUrl))
179+
.resizable()
180+
.frame(width: 24, height: 24)
181+
.cornerRadius(4)
182+
.padding(4),
183+
alignment: .topLeading
184+
)
177185
}
178186
.overlay(
179187
ZStack {
@@ -185,7 +193,7 @@ struct HomeView: View {
185193
ProgressView(value: item.progress)
186194
.progressViewStyle(LinearProgressViewStyle(tint: .white))
187195
.padding(.horizontal, 8)
188-
.scaleEffect(x: 1, y: 2, anchor: .center)
196+
.scaleEffect(x: 1, y: 1.5, anchor: .center)
189197
},
190198
alignment: .bottom
191199
)
@@ -204,12 +212,21 @@ struct HomeView: View {
204212
}
205213
.padding(.horizontal, 8)
206214
}
215+
.frame(width: 250, height: 190)
216+
}
217+
.contextMenu {
218+
Button(action: { markContinueWatchingItemAsWatched(item: item) }) {
219+
Label("Mark as Watched", systemImage: "checkmark.circle")
220+
}
221+
Button(role: .destructive, action: { removeContinueWatchingItem(item: item) }) {
222+
Label("Remove Item", systemImage: "trash")
223+
}
207224
}
208225
}
209226
}
210-
.frame(width: 250, height: 200)
211227
.padding(.horizontal, 8)
212228
}
229+
.frame(height: 190)
213230
}
214231
}
215232
}
@@ -232,4 +249,24 @@ struct HomeView: View {
232249
}
233250
.navigationViewStyle(StackNavigationViewStyle())
234251
}
252+
253+
private func markContinueWatchingItemAsWatched(item: ContinueWatchingItem) {
254+
let key = "lastPlayedTime_\(item.fullUrl)"
255+
let totalKey = "totalTime_\(item.fullUrl)"
256+
UserDefaults.standard.set(99999999.0, forKey: key)
257+
UserDefaults.standard.set(99999999.0, forKey: totalKey)
258+
ContinueWatchingManager.shared.remove(item: item)
259+
260+
if let index = continueWatchingItems.firstIndex(where: { $0.id == item.id }) {
261+
continueWatchingItems.remove(at: index)
262+
}
263+
}
264+
265+
private func removeContinueWatchingItem(item: ContinueWatchingItem) {
266+
ContinueWatchingManager.shared.remove(item: item)
267+
268+
if let index = continueWatchingItems.firstIndex(where: { $0.id == item.id }) {
269+
continueWatchingItems.remove(at: index)
270+
}
271+
}
235272
}

Sora/Views/LibraryView/LibraryView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct LibraryView: View {
6969
.font(.subheadline)
7070
.foregroundColor(.primary)
7171
.lineLimit(2)
72-
.multilineTextAlignment(.center)
72+
.multilineTextAlignment(.leading)
7373
.padding(.horizontal, 8)
7474
}
7575
}

0 commit comments

Comments
 (0)