Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies, polish stuff, make FileCallback.onCompleted receive newly created FileCallback.Result and more #144

Closed
wants to merge 16 commits into from

Conversation

w2sv
Copy link

@w2sv w2sv commented Jul 7, 2024

I did lots of different things for which I really should have created separate PRs, sorry for that. To break it down:

  • I ran AndroidStudio code reformatting on the entire project
  • Put all the kotlin code in kotlin src dirs and moved the sample java files to a java src dir
  • Removed redundant stuff like empty proguard files, the ExampleUnitTest.kt, the unused kotlinx.coroutines.core and com.afollestad.material-dialogs (only com.afollestad.material-dialogs:files is needed) dependencies
  • I integrated a FileCallback.Result interface
sealed interface Result {
        @JvmInline
        value class MediaFile(val value: com.anggrayudi.storage.media.MediaFile) : Result

        @JvmInline
        value class DocumentFile(val value: androidx.documentfile.provider.DocumentFile) : Result

        companion object {
            internal fun get(value: Any): Result =
                when (value) {
                    is com.anggrayudi.storage.media.MediaFile -> MediaFile(value)
                    is androidx.documentfile.provider.DocumentFile -> DocumentFile(value)
                    else -> throw IllegalArgumentException("Result must be either of type ${com.anggrayudi.storage.media.MediaFile::class.java.name} or ${androidx.documentfile.provider.DocumentFile::class.java.name}")
                }
        }
    }

and made it the result type argument of the FileCallback class, to make users unambiguously aware of the onCompleted result type

  • Made compatible classes data classes to make them benefit from their inherent advantages
    • e.g. data class Report(val progress: Float, val bytesMoved: Long, val writeSpeed: Int)
  • Un-api'd internal dependencies of the storage module, as imo consuming modules shouldn't automatically inherit them. For instance, in the compose app I'm building and in which I'm using your library, I don't use fragments or the afollestad.material-dialogs module, so I really wouldn't want them to leak into my dependencies
  • Removed lots of redundant DEPRECATED suppressions
  • Refactored the VideoMediaDirectory, ImageMediaDirectory, AudioMediaDirectory classes into the following
sealed interface MediaDirectory {
    val folderName: String

    /**
     * Created on 06/09/20
     * @author Anggrayudi H
     */
    enum class Image(override val folderName: String) : MediaDirectory {
        PICTURES(Environment.DIRECTORY_PICTURES),
        DCIM(Environment.DIRECTORY_DCIM)
    }

    /**
     * Created on 06/09/20
     * @author Anggrayudi H
     */
    enum class Video(override val folderName: String) : MediaDirectory {
        MOVIES(Environment.DIRECTORY_MOVIES),
        DCIM(Environment.DIRECTORY_DCIM)
    }

    /**
     * Created on 06/09/20
     * @author Anggrayudi H
     */
    enum class Audio(override val folderName: String) : MediaDirectory {
        MUSIC(Environment.DIRECTORY_MUSIC),
        PODCASTS(Environment.DIRECTORY_PODCASTS),
        RINGTONES(Environment.DIRECTORY_RINGTONES),
        ALARMS(Environment.DIRECTORY_ALARMS),
        NOTIFICATIONS(Environment.DIRECTORY_NOTIFICATIONS)
    }
}

to provide a common interface, as well as a higher degree of class cohesion

  • Introduced a ScopeHoldingCallback interface like so
interface ScopeHoldingCallback {
    val uiScope: CoroutineScope

    fun postToUiScope(action: () -> Unit) {
        uiScope.postToUi(action)
    }
}

and made all callbacks holding a CoroutineScope inherit from it. In that wake, I replaced the I believe 103 invocations of callback.uiScope.postToUi with callback.postToUiScope

  • Set the compileSdkVersion of storage to 34 and removed the redundant targetSdkVersion, which has no effect on library modules
  • Updated various dependencies, most notably androidx.core:core-ktx to 1.9.0, kotlin to 2.0.0, agp to 8.3.2, gradle to 8.8
  • Fixed some build file deprecations
  • Fixed some documentation language mistakes
  • ...and some more slight code polishing

As I said, quite a lot of different things 😄

./gradlew build passed without any errors.

@w2sv
Copy link
Author

w2sv commented Jul 7, 2024

Damn, I just now saw #142 😅

@anggrayudi
Copy link
Owner

anggrayudi commented Jul 7, 2024

Hi @w2sv , thanks for raising this PR. I've reviewed your PR and you've done so much to improve the library quality. Unfortunately, I've planned to release v2.0.0 long time ago, and tested it multiple times to ensure its stability. So, I'll merge my PR first, then you can rebase your branch to the latest commits. I'll review your PR again once you've resolved the git conflicts. Thanks in advance.

@w2sv
Copy link
Author

w2sv commented Jul 7, 2024

Yes, sounds absolutely perfect, I'll do that. Great PR btw, the migration to flows is awesome!

@w2sv
Copy link
Author

w2sv commented Jul 8, 2024

Closing as I created an entirely now PR #145

@w2sv w2sv closed this Jul 8, 2024
@w2sv w2sv deleted the master branch September 8, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants