Skip to content

Commit aeb4548

Browse files
Add delete button for history items
1 parent 6621b7f commit aeb4548

7 files changed

Lines changed: 63 additions & 7 deletions

File tree

app/src/main/java/org/schabi/newpipe/local/history/HistoryViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class HistoryViewModel(
4545
dateTimeFormatter.format(it.latestAccessDate),
4646
ServiceHelper.getNameOfServiceById(it.streamEntity.serviceId),
4747
)
48-
Stream(it.streamEntity, detail)
48+
Stream(it.streamEntity, detail, it.streamId)
4949
}
5050
}
5151
.flowOn(Dispatchers.IO)

app/src/main/java/org/schabi/newpipe/ui/components/items/Info.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ class Stream(
2424
val uploaderUrl: String? = null,
2525
val duration: Long = TimeUnit.HOURS.toSeconds(1),
2626
val detailText: String = "",
27+
val streamId: Long = -1,
2728
) : Info(), Parcelable {
2829

2930
constructor(item: StreamInfoItem, detailText: String) : this(
3031
item.serviceId, item.url, item.name, item.thumbnails, item.uploaderName.orEmpty(),
3132
item.streamType, item.uploaderUrl, item.duration, detailText
3233
)
3334

34-
constructor(entry: StreamEntity, detailText: String) : this(
35-
entry.serviceId, entry.url, entry.title,
36-
ImageStrategy.dbUrlToImageList(entry.thumbnailUrl), entry.uploader,
37-
entry.streamType, entry.uploaderUrl, entry.duration, detailText
35+
constructor(entity: StreamEntity, detailText: String, streamId: Long) : this(
36+
entity.serviceId, entity.url, entity.title,
37+
ImageStrategy.dbUrlToImageList(entity.thumbnailUrl), entity.uploader,
38+
entity.streamType, entity.uploaderUrl, entity.duration, detailText, streamId
3839
)
3940

4041
fun toStreamInfoItem(): StreamInfoItem {

app/src/main/java/org/schabi/newpipe/ui/components/items/stream/StreamCardItem.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.schabi.newpipe.ui.components.items.stream
22

3+
import android.content.res.Configuration
34
import androidx.compose.foundation.ExperimentalFoundationApi
45
import androidx.compose.foundation.combinedClickable
56
import androidx.compose.foundation.layout.Arrangement
@@ -9,13 +10,17 @@ import androidx.compose.foundation.layout.Row
910
import androidx.compose.foundation.layout.fillMaxWidth
1011
import androidx.compose.foundation.layout.padding
1112
import androidx.compose.material3.MaterialTheme
13+
import androidx.compose.material3.Surface
1214
import androidx.compose.material3.Text
1315
import androidx.compose.runtime.Composable
1416
import androidx.compose.ui.Modifier
1517
import androidx.compose.ui.layout.ContentScale
1618
import androidx.compose.ui.text.style.TextOverflow
19+
import androidx.compose.ui.tooling.preview.Preview
20+
import androidx.compose.ui.tooling.preview.PreviewParameter
1721
import androidx.compose.ui.unit.dp
1822
import org.schabi.newpipe.ui.components.items.Stream
23+
import org.schabi.newpipe.ui.theme.AppTheme
1924

2025
@OptIn(ExperimentalFoundationApi::class)
2126
@Composable
@@ -71,3 +76,16 @@ fun StreamCardItem(
7176
StreamMenu(stream, isSelected, onDismissPopup)
7277
}
7378
}
79+
80+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
81+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
82+
@Composable
83+
private fun StreamCardItemPreview(
84+
@PreviewParameter(StreamItemPreviewProvider::class) stream: Stream
85+
) {
86+
AppTheme {
87+
Surface(color = MaterialTheme.colorScheme.background) {
88+
StreamCardItem(stream, showProgress = false, isSelected = false)
89+
}
90+
}
91+
}

app/src/main/java/org/schabi/newpipe/ui/components/items/stream/StreamGridItem.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package org.schabi.newpipe.ui.components.items.stream
22

3+
import android.content.res.Configuration
34
import androidx.compose.foundation.ExperimentalFoundationApi
45
import androidx.compose.foundation.combinedClickable
56
import androidx.compose.foundation.layout.Box
67
import androidx.compose.foundation.layout.Column
78
import androidx.compose.foundation.layout.padding
89
import androidx.compose.foundation.layout.size
910
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Surface
1012
import androidx.compose.material3.Text
1113
import androidx.compose.runtime.Composable
1214
import androidx.compose.ui.Modifier
1315
import androidx.compose.ui.text.style.TextOverflow
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import androidx.compose.ui.tooling.preview.PreviewParameter
1418
import androidx.compose.ui.unit.DpSize
1519
import androidx.compose.ui.unit.dp
1620
import org.schabi.newpipe.ui.components.items.Stream
21+
import org.schabi.newpipe.ui.theme.AppTheme
1722

1823
@OptIn(ExperimentalFoundationApi::class)
1924
@Composable
@@ -61,3 +66,16 @@ fun StreamGridItem(
6166
StreamMenu(stream, isSelected, onDismissPopup)
6267
}
6368
}
69+
70+
@Preview(name = "Light mode", uiMode = Configuration.UI_MODE_NIGHT_NO)
71+
@Preview(name = "Dark mode", uiMode = Configuration.UI_MODE_NIGHT_YES)
72+
@Composable
73+
private fun StreamGridItemPreview(
74+
@PreviewParameter(StreamItemPreviewProvider::class) stream: Stream
75+
) {
76+
AppTheme {
77+
Surface(color = MaterialTheme.colorScheme.background) {
78+
StreamGridItem(stream, showProgress = false, isSelected = false)
79+
}
80+
}
81+
}

app/src/main/java/org/schabi/newpipe/ui/components/items/stream/StreamMenu.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ fun StreamMenu(
7676
}
7777
}
7878
)
79+
80+
if (stream.streamId != -1L) {
81+
StreamMenuItem(
82+
text = R.string.delete,
83+
onClick = {
84+
onDismissRequest()
85+
streamViewModel.deleteStreamHistory(stream.streamId)
86+
}
87+
)
88+
}
89+
7990
StreamMenuItem(
8091
text = R.string.download,
8192
onClick = {

app/src/main/java/org/schabi/newpipe/ui/screens/HistoryScreen.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.schabi.newpipe.ui.screens
33
import android.content.res.Configuration
44
import androidx.compose.foundation.layout.Arrangement
55
import androidx.compose.foundation.layout.Column
6+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
7+
import androidx.compose.foundation.layout.FlowRow
68
import androidx.compose.foundation.layout.Row
79
import androidx.compose.foundation.layout.Spacer
810
import androidx.compose.foundation.layout.fillMaxWidth
@@ -82,7 +84,7 @@ fun HistoryScreen(viewModel: HistoryViewModel = viewModel()) {
8284
})
8385
}
8486

85-
@OptIn(ExperimentalMaterial3Api::class)
87+
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
8688
@Composable
8789
private fun HistoryHeader(
8890
sortKey: SortKey,
@@ -170,7 +172,7 @@ private fun HistoryHeader(
170172

171173
Spacer(Modifier.height(12.dp))
172174

173-
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
175+
FlowRow(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
174176
IconButtonWithLabel(
175177
icon = Icons.Default.Headphones,
176178
label = R.string.controls_background_title,

app/src/main/java/org/schabi/newpipe/viewmodels/StreamViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,10 @@ class StreamViewModel(application: Application) : AndroidViewModel(application)
2323
historyRecordManager.markAsWatched(stream).await()
2424
}
2525
}
26+
27+
fun deleteStreamHistory(streamId: Long) {
28+
viewModelScope.launch {
29+
historyRecordManager.deleteStreamHistoryAndState(streamId).await()
30+
}
31+
}
2632
}

0 commit comments

Comments
 (0)