Skip to content

Commit

Permalink
Refactor: Use core library desugaring instead of ThreeTenABP and andr…
Browse files Browse the repository at this point in the history
…oid-restrostreeams
  • Loading branch information
zhanghai committed Sep 22, 2024
1 parent eba9501 commit 2e1a4db
Show file tree
Hide file tree
Showing 29 changed files with 83 additions and 92 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ android {
generateLocaleConfig true
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand Down Expand Up @@ -109,7 +110,7 @@ repositories {
}
}
dependencies {
implementation('com.github.zhanghai:dav4jvm:c317607') {
implementation('com.github.bitfireAT:dav4jvm:c1bc143') {
exclude group: 'org.ogce', module: 'xpp3'
}
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
Expand All @@ -119,6 +120,8 @@ dependencies {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.2")

// kotlinx-coroutines-android depends on kotlin-stdlib-jdk8
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
def kotlinx_coroutines_version = '1.9.0'
Expand Down Expand Up @@ -159,7 +162,6 @@ dependencies {
implementation ('com.hierynomus:sshj:0.35.0') {
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
}
implementation 'com.jakewharton.threetenabp:threetenabp:1.4.6'
implementation 'com.leinardi.android:speed-dial:3.3.0'
implementation ('com.rapid7.client:dcerpc:0.12.1') {
// SMBJ-RPC depends on the JRE flavor of Guava which targets Java 8.
Expand Down Expand Up @@ -195,9 +197,8 @@ dependencies {
implementation 'me.zhanghai.android.foregroundcompat:library:1.0.2'
implementation 'me.zhanghai.android.libarchive:library:1.1.1'
implementation 'me.zhanghai.android.libselinux:library:2.1.0'
implementation 'me.zhanghai.android.retrofile:library:1.1.1'
implementation 'me.zhanghai.android.retrofile:library:1.2.0'
implementation 'me.zhanghai.android.systemuihelper:library:1.0.0'
implementation 'net.sourceforge.streamsupport:android-retrostreams:1.7.4'
implementation 'org.apache.ftpserver:ftpserver-core:1.2.0'
// This is a dependency of org.apache.ftpserver:ftpserver-core but org.apache.mina:mina-core
// 2.1.3+ became incompatible before API 24 due to dependency on StandardSocketOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package me.zhanghai.android.files.app
import android.os.AsyncTask
import android.os.Build
import android.webkit.WebView
import com.jakewharton.threetenabp.AndroidThreeTen
import jcifs.context.SingletonContext
import me.zhanghai.android.files.BuildConfig
import me.zhanghai.android.files.coil.initializeCoil
Expand All @@ -31,9 +30,15 @@ import me.zhanghai.android.files.provider.smb.client.Client as SmbClient
import me.zhanghai.android.files.provider.webdav.client.Client as WebDavClient

val appInitializers = listOf(
::initializeCrashlytics, ::disableHiddenApiChecks, ::initializeThreeTen,
::initializeWebViewDebugging, ::initializeCoil, ::initializeFileSystemProviders, ::upgradeApp,
::initializeLiveDataObjects, ::initializeCustomTheme, ::initializeNightMode,
::initializeCrashlytics,
::disableHiddenApiChecks,
::initializeWebViewDebugging,
::initializeCoil,
::initializeFileSystemProviders,
::upgradeApp,
::initializeLiveDataObjects,
::initializeCustomTheme,
::initializeNightMode,
::createNotificationChannels
)

Expand All @@ -47,10 +52,6 @@ private fun disableHiddenApiChecks() {
HiddenApi.disableHiddenApiChecks()
}

private fun initializeThreeTen() {
AndroidThreeTen.init(application)
}

private fun initializeWebViewDebugging() {
if (BuildConfig.DEBUG) {
WebView.setWebContentsDebuggingEnabled(true)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package me.zhanghai.android.files.file

import java.time.Instant
import java8.nio.file.attribute.BasicFileAttributes
import org.threeten.bp.Instant

val BasicFileAttributes.fileSize: FileSize
get() = size().asFileSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
package me.zhanghai.android.files.file

import android.text.format.DateUtils
import org.threeten.bp.Duration
import java.time.Duration

fun Duration.format(): String = DateUtils.formatElapsedTime(seconds)
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ package me.zhanghai.android.files.file
import android.content.Context
import android.text.format.DateUtils
import android.text.format.Time
import org.threeten.bp.Instant
import org.threeten.bp.ZoneId
import org.threeten.bp.format.DateTimeFormatter
import org.threeten.bp.format.FormatStyle
import java.time.Instant
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.format.FormatStyle

/* @see com.android.documentsui.base.Shared#formatTime(Context, long) */
@Suppress("DEPRECATION")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
package me.zhanghai.android.files.fileproperties

import android.media.MediaMetadataRetriever
import me.zhanghai.android.files.util.takeIfNotBlank
import org.threeten.bp.Instant
import java.text.ParsePosition
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.Locale
import java.util.TimeZone
import kotlin.math.max
import me.zhanghai.android.files.util.takeIfNotBlank

fun MediaMetadataRetriever.extractMetadataNotBlank(keyCode: Int): String? =
extractMetadata(keyCode)?.takeIfNotBlank()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package me.zhanghai.android.files.fileproperties.audio

import org.threeten.bp.Duration
import java.time.Duration

// @see com.android.providers.media.scan.ModernMediaScanner.scanItemAudio
// @see com.android.documentsui.inspector.MediaView.showAudioData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package me.zhanghai.android.files.fileproperties.audio
import android.media.MediaMetadataRetriever
import android.os.AsyncTask
import android.os.Build
import java.time.Duration
import java8.nio.file.Path
import me.zhanghai.android.files.compat.METADATA_KEY_SAMPLERATE
import me.zhanghai.android.files.compat.use
Expand All @@ -19,7 +20,6 @@ import me.zhanghai.android.files.util.Stateful
import me.zhanghai.android.files.util.Success
import me.zhanghai.android.files.util.setDataSource
import me.zhanghai.android.files.util.valueCompat
import org.threeten.bp.Duration

class AudioInfoLiveData(path: Path) : PathObserverLiveData<Stateful<AudioInfo>>(path) {
init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package me.zhanghai.android.files.fileproperties.image

import android.annotation.SuppressLint
import androidx.exifinterface.media.ExifInterface
import me.zhanghai.android.files.util.takeIfNotBlank
import org.threeten.bp.Duration
import org.threeten.bp.Instant
import org.threeten.bp.ZoneId
import org.threeten.bp.ZoneOffset
import java.time.Duration
import java.time.Instant
import java.time.ZoneId
import java.time.ZoneOffset
import kotlin.math.roundToLong
import me.zhanghai.android.files.util.takeIfNotBlank

fun ExifInterface.getAttributeNotBlank(tag: String): String? =
getAttribute(tag)?.takeIfNotBlank()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package me.zhanghai.android.files.fileproperties.image

import android.util.Size
import org.threeten.bp.Instant
import java.time.Instant

class ImageInfo(
val dimensions: Size?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
package me.zhanghai.android.files.fileproperties.video

import android.util.Size
import org.threeten.bp.Duration
import org.threeten.bp.Instant
import java.time.Duration
import java.time.Instant

// @see com.android.providers.media.scan.ModernMediaScanner.scanItemVideo
// @see com.android.documentsui.inspector.MediaView.showVideoData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package me.zhanghai.android.files.fileproperties.video
import android.media.MediaMetadataRetriever
import android.os.AsyncTask
import android.util.Size
import java.time.Duration
import java8.nio.file.Path
import me.zhanghai.android.files.compat.use
import me.zhanghai.android.files.fileproperties.PathObserverLiveData
Expand All @@ -20,7 +21,6 @@ import me.zhanghai.android.files.util.Stateful
import me.zhanghai.android.files.util.Success
import me.zhanghai.android.files.util.setDataSource
import me.zhanghai.android.files.util.valueCompat
import org.threeten.bp.Duration

class VideoInfoLiveData(path: Path) : PathObserverLiveData<Stateful<VideoInfo>>(path) {
init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
package me.zhanghai.android.files.provider.archive.archiver

import android.system.OsConstants
import java.io.Closeable
import java.io.IOException
import java.io.InputStream
import java.io.InterruptedIOException
import java.nio.ByteBuffer
import java.nio.charset.Charset
import java.time.Instant
import java8.nio.channels.SeekableByteChannel
import java8.nio.charset.StandardCharsets
import java8.nio.file.attribute.FileTime
Expand All @@ -18,13 +25,6 @@ import me.zhanghai.android.files.provider.common.toByteString
import me.zhanghai.android.libarchive.Archive
import me.zhanghai.android.libarchive.ArchiveEntry
import me.zhanghai.android.libarchive.ArchiveException
import org.threeten.bp.Instant
import java.io.Closeable
import java.io.IOException
import java.io.InputStream
import java.io.InterruptedIOException
import java.nio.ByteBuffer
import java.nio.charset.Charset

class ReadArchive : Closeable {
private val archive = Archive.readNew()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

package me.zhanghai.android.files.provider.common

import java.time.Instant
import java8.nio.file.attribute.FileTime
import org.threeten.bp.Instant
import kotlin.reflect.KClass

val KClass<FileTime>.EPOCH: FileTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
package me.zhanghai.android.files.provider.common

import android.os.Parcel
import java.time.Instant
import java8.nio.file.attribute.FileTime
import kotlinx.parcelize.Parceler
import me.zhanghai.android.files.compat.readSerializableCompat
import org.threeten.bp.Instant

object FileTimeParceler : Parceler<FileTime?> {
override fun create(parcel: Parcel): FileTime? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package me.zhanghai.android.files.provider.document

import android.net.Uri
import android.os.Parcelable
import java.time.Instant
import java8.nio.file.attribute.FileTime
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.WriteWith
import me.zhanghai.android.files.provider.common.AbstractContentProviderFileAttributes
import me.zhanghai.android.files.provider.common.FileTimeParceler
import org.threeten.bp.Instant

@Parcelize
internal class DocumentFileAttributes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package me.zhanghai.android.files.provider.ftp
import java8.nio.file.FileAlreadyExistsException
import java8.nio.file.NoSuchFileException
import java8.nio.file.StandardCopyOption
import me.zhanghai.android.files.compat.toInstantCompat
import me.zhanghai.android.files.provider.common.CopyOptions
import me.zhanghai.android.files.provider.common.copyTo
import me.zhanghai.android.files.provider.ftp.client.Client
Expand Down Expand Up @@ -105,7 +104,7 @@ internal object FtpCopyMove {
val timestamp = sourceFile.timestamp
if (timestamp != null) {
try {
Client.setLastModifiedTime(target, timestamp.toInstantCompat())
Client.setLastModifiedTime(target, timestamp.toInstant())
} catch (e: IOException) {
e.printStackTrace()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
package me.zhanghai.android.files.provider.ftp

import android.os.Parcelable
import java.time.Instant
import java8.nio.file.attribute.FileTime
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.WriteWith
import me.zhanghai.android.files.compat.toInstantCompat
import me.zhanghai.android.files.provider.common.AbstractBasicFileAttributes
import me.zhanghai.android.files.provider.common.BasicFileType
import me.zhanghai.android.files.provider.common.FileTimeParceler
import org.apache.commons.net.ftp.FTPFile
import org.threeten.bp.Instant

@Parcelize
internal data class FtpFileAttributes(
Expand All @@ -27,7 +26,7 @@ internal data class FtpFileAttributes(
) : AbstractBasicFileAttributes() {
companion object {
fun from(file: FTPFile, path: FtpPath): FtpFileAttributes {
val lastModifiedTime = FileTime.from(file.timestamp?.toInstantCompat() ?: Instant.EPOCH)
val lastModifiedTime = FileTime.from(file.timestamp?.toInstant() ?: Instant.EPOCH)
val lastAccessTime = lastModifiedTime
val creationTime = lastModifiedTime
val type = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

package me.zhanghai.android.files.provider.ftp.client

import java8.nio.file.Path as Java8Path
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.time.Instant
import java.time.ZoneOffset
import java.time.chrono.IsoChronology
import java.time.format.DateTimeFormatter
import java.util.Collections
import java.util.Locale
import java.util.WeakHashMap
import java8.nio.channels.SeekableByteChannel
import me.zhanghai.android.files.provider.common.DelegateInputStream
import me.zhanghai.android.files.provider.common.DelegateOutputStream
Expand All @@ -17,17 +28,6 @@ import org.apache.commons.net.ftp.FTPCmd
import org.apache.commons.net.ftp.FTPFile
import org.apache.commons.net.ftp.FTPReply
import org.apache.commons.net.ftp.FTPSClient
import org.threeten.bp.Instant
import org.threeten.bp.ZoneOffset
import org.threeten.bp.chrono.IsoChronology
import org.threeten.bp.format.DateTimeFormatter
import java.io.IOException
import java.io.InputStream
import java.io.OutputStream
import java.util.Collections
import java.util.Locale
import java.util.WeakHashMap
import java8.nio.file.Path as Java8Path

object Client {
private val TIMESTAMP_FORMATTER =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package me.zhanghai.android.files.provider.linux

import android.os.Parcelable
import java.time.Instant
import java8.nio.file.attribute.FileTime
import kotlinx.parcelize.Parcelize
import kotlinx.parcelize.WriteWith
Expand All @@ -18,7 +19,6 @@ import me.zhanghai.android.files.provider.common.PosixFileType
import me.zhanghai.android.files.provider.common.PosixGroup
import me.zhanghai.android.files.provider.common.PosixUser
import me.zhanghai.android.files.provider.linux.syscall.StructStat
import org.threeten.bp.Instant

@Parcelize
internal class LinuxFileAttributes(
Expand Down
Loading

0 comments on commit 2e1a4db

Please sign in to comment.