Skip to content

Commit

Permalink
Fix: Fix crash due to new SequencedCollection API in Android 15
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Sep 12, 2024
1 parent efe3835 commit a2b3301
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,11 @@
package me.zhanghai.android.files.compat

import kotlin.comparisons.reversed as kotlinReversed
import kotlin.collections.removeFirst as kotlinRemoveFirst
import kotlin.collections.removeLast as kotlinRemoveLast

fun <T> Comparator<T>.reversedCompat(): Comparator<T> = kotlinReversed()

fun <T> MutableList<T>.removeFirstCompat(): T = kotlinRemoveFirst()

fun <T> MutableList<T>.removeLastCompat(): T = kotlinRemoveLast()
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import me.zhanghai.android.files.util.WakeWifiLock
import me.zhanghai.android.files.util.removeFirst
import java.util.concurrent.Executors
import java.util.concurrent.Future
import me.zhanghai.android.files.compat.removeFirstCompat

class FileJobService : Service() {
private lateinit var wakeWifiLock: WakeWifiLock
Expand All @@ -39,7 +40,7 @@ class FileJobService : Service() {
instance = this

while (pendingJobs.isNotEmpty()) {
startJob(pendingJobs.removeFirst())
startJob(pendingJobs.removeFirstCompat())
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ package me.zhanghai.android.files.provider.common

import android.os.Parcel
import android.os.Parcelable
import java.net.URI
import java8.nio.file.InvalidPathException
import java8.nio.file.Path
import java8.nio.file.ProviderMismatchException
import kotlin.math.min
import me.zhanghai.android.files.compat.readBooleanCompat
import me.zhanghai.android.files.compat.removeLastCompat
import me.zhanghai.android.files.compat.writeBooleanCompat
import me.zhanghai.android.files.compat.writeParcelableListCompat
import me.zhanghai.android.files.util.endsWith
import me.zhanghai.android.files.util.hash
import me.zhanghai.android.files.util.readParcelableListCompat
import me.zhanghai.android.files.util.startsWith
import java.net.URI
import kotlin.math.min

abstract class ByteStringListPath<T : ByteStringListPath<T>> : AbstractPath<T>, Parcelable {
protected val separator: Byte
Expand Down Expand Up @@ -132,8 +133,7 @@ abstract class ByteStringListPath<T : ByteStringListPath<T>> : AbstractPath<T>,
if (normalizedSegments.last() == BYTE_STRING_DOT_DOT) {
normalizedSegments += segment
} else {
@OptIn(ExperimentalStdlibApi::class)
normalizedSegments.removeLast()
normalizedSegments.removeLastCompat()
}
}
} else {
Expand Down

0 comments on commit a2b3301

Please sign in to comment.