Skip to content

Commit

Permalink
fix crash when deleting new bookmarks
Browse files Browse the repository at this point in the history
(cherry picked from commit 70a2e0c)
  • Loading branch information
crackededed committed May 20, 2024
1 parent 401c0b4 commit b8b78e0
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ android {
applicationId = "com.github.andreyasadchy.xtra"
minSdk = 21
targetSdk = 34
versionCode = 237
versionName = "2.31.2"
versionCode = 238
versionName = "2.31.3"
resourceConfigurations += listOf("ar", "de", "en", "es", "fr", "in", "it", "ja", "pt-rBR", "ru", "tr", "zh-rTW", "zh-rCN")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ interface VideosDao {
@Query("SELECT * FROM videos WHERE url = :url")
fun getByUrl(url: String): OfflineVideo?

@Query("SELECT * FROM videos WHERE videoId = :id")
fun getByVideoId(id: String): List<OfflineVideo>

@Query("SELECT * FROM videos WHERE channel_id = :id")
fun getByUserId(id: Int): List<OfflineVideo>
fun getByUserId(id: String): List<OfflineVideo>

@Insert
fun insert(video: OfflineVideo): Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ class ApiRepository @Inject constructor(
addProperty("channel_id", channelId)
addProperty("broadcast_id", streamId)
addProperty("player", "site")
addProperty("user_id", userId?.toInt())
addProperty("user_id", userId?.toLong())
})
}
val spadeRequest = Base64.encodeToString(json.toString().toByteArray(), Base64.NO_WRAP).toRequestBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class BookmarksRepository @Inject constructor(
}

suspend fun deleteBookmark(context: Context, item: Bookmark) = withContext(Dispatchers.IO) {
if (!item.videoId.isNullOrBlank() && videosDao.getById(item.videoId.toInt()) == null) {
if (!item.videoId.isNullOrBlank() && videosDao.getByVideoId(item.videoId).isEmpty()) {
File(context.filesDir.path + File.separator + "thumbnails" + File.separator + "${item.videoId}.png").delete()
}
if (!item.userId.isNullOrBlank() && localFollowsChannelDao.getByUserId(item.userId) == null && videosDao.getByUserId(item.userId.toInt()).isEmpty()) {
if (!item.userId.isNullOrBlank() && localFollowsChannelDao.getByUserId(item.userId) == null && videosDao.getByUserId(item.userId).isEmpty()) {
File(context.filesDir.path + File.separator + "profile_pics" + File.separator + "${item.userId}.png").delete()
}
bookmarksDao.delete(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class LocalFollowChannelRepository @Inject constructor(
}

suspend fun deleteFollow(context: Context, item: LocalFollowChannel) = withContext(Dispatchers.IO) {
if (!item.userId.isNullOrBlank() && bookmarksDao.getByUserId(item.userId).isEmpty() && videosDao.getByUserId(item.userId.toInt()).isEmpty()) {
if (!item.userId.isNullOrBlank() && bookmarksDao.getByUserId(item.userId).isEmpty() && videosDao.getByUserId(item.userId).isEmpty()) {
File(context.filesDir.path + File.separator + "profile_pics" + File.separator + "${item.userId}.png").delete()
}
localFollowsChannelDao.delete(item)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class OfflineRepository @Inject constructor(
videosDao.getByUrl(url)
}

suspend fun getVideosByUserId(id: Int) = withContext(Dispatchers.IO) {
suspend fun getVideosByUserId(id: String) = withContext(Dispatchers.IO) {
videosDao.getByUserId(id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class FollowedChannelsDataSource(
val downloadedLogo = DownloadUtils.savePng(context, TwitchApiHelper.getTemplateUrl(profileImageURL, "profileimage"), "profile_pics", userId)
localFollowsChannel.getFollowByUserId(userId)?.let { localFollowsChannel.updateFollow(it.apply {
channelLogo = downloadedLogo }) }
for (i in offlineRepository.getVideosByUserId(userId.toInt())) {
for (i in offlineRepository.getVideosByUserId(userId)) {
offlineRepository.updateVideo(i.apply {
channelLogo = downloadedLogo })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class ChannelPagerViewModel @Inject constructor(
userLogin = user.channelLogin
userName = user.channelName
channelLogo = downloadedLogo }) }
for (i in offlineRepository.getVideosByUserId(user.channelId.toInt())) {
for (i in offlineRepository.getVideosByUserId(user.channelId)) {
offlineRepository.updateVideo(i.apply {
channelLogin = user.channelLogin
channelName = user.channelName
Expand Down

0 comments on commit b8b78e0

Please sign in to comment.