Don't retrieve segments if no category is enabled

This commit is contained in:
janisslsm 2022-05-16 13:34:13 +03:00
parent 6006996d15
commit 2910aceb3f

View File

@ -322,34 +322,41 @@ class PlayerFragment : Fragment() {
return@launchWhenCreated return@launchWhenCreated
} }
if(SponsorBlockSettings.sponsorBlockEnabled) { if(SponsorBlockSettings.sponsorBlockEnabled) {
segmentData = try { val categories: ArrayList<String> = arrayListOf()
val categories: ArrayList<String> = arrayListOf() if (SponsorBlockSettings.introEnabled) {
if (SponsorBlockSettings.introEnabled) { categories.add("intro")
categories.add("intro") }
} if (SponsorBlockSettings.selfPromoEnabled) {
if (SponsorBlockSettings.selfPromoEnabled) { categories.add("selfpromo")
categories.add("selfpromo") }
} if (SponsorBlockSettings.interactionEnabled) {
if (SponsorBlockSettings.interactionEnabled) { categories.add("interaction")
categories.add("interaction") }
} if (SponsorBlockSettings.sponsorsEnabled) {
if (SponsorBlockSettings.sponsorsEnabled) { categories.add("sponsor")
categories.add("sponsor") }
} if (SponsorBlockSettings.outroEnabled) {
if (SponsorBlockSettings.outroEnabled) { categories.add("outro")
categories.add("outro") }
} if(categories.size > 0) {
segmentData = try {
RetrofitInstance.api.getSegments(videoId!!, "[\"" + TextUtils.join("\",\"", categories) + "\"]") RetrofitInstance.api.getSegments(
} catch (e: IOException) { videoId!!,
println(e) "[\"" + TextUtils.join("\",\"", categories) + "\"]"
Log.e(TAG, "IOException, you might not have internet connection") )
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show() } catch (e: IOException) {
return@launchWhenCreated println(e)
} catch (e: HttpException) { Log.e(TAG, "IOException, you might not have internet connection")
Log.e(TAG, "HttpException, unexpected response") Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT)
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT).show() .show()
return@launchWhenCreated return@launchWhenCreated
} catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response")
Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT)
.show()
return@launchWhenCreated
}
} }
} }