Skip to content

Commit451/Veyron

Repository files navigation

Veyron

Build Maven Central

Easily store and fetch JSON, Files, and Strings in Google Drive on Android.

Dependency

implementation("com.commit451.veyron:veyron:latest.version.here")

Compile with Java 17:

android {
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }
}

Usage

You will first need to do the setup for the Google Drive API. See the sample project for a complete example.

// when you have a valid Drive class:
val veyron = Veyron.Builder(drive)
    // optional configuration for Moshi, if you are saving classes instead of Strings/Files
    // .moshi(moshi)
    .build()

Create

lifecycleScope.launch {
    val dog = Dog()
    val saveRequest = SaveRequest.Document("dog.json", Dog::class.java, dog)
    val path = "info"

    runCatching {
        veyron.save(path, saveRequest)
    }.onSuccess {
        snackbar("Saved")
    }.onFailure {
        it.printStackTrace()
    }
}

Fetch

lifecycleScope.launch {
    val path = "info/dog.json"

    runCatching {
        veyron.document(path, Dog::class.java).result
    }.onSuccess { dog ->
        if (dog != null) {
            snackbar("Dog found")
        }
    }.onFailure {
        it.printStackTrace()
    }
}

Delete

lifecycleScope.launch {
    val path = "info/dog.json"

    runCatching {
        veyron.delete(path)
    }.onSuccess {
        snackbar("Dogs deleted")
    }.onFailure {
        it.printStackTrace()
    }
}

Other Operations

Other operations you can perform:

  • veyron.file(path)
  • veyron.files(path)
  • veyron.documents(path)
  • veyron.search(path, query)
  • veyron.string(path)
  • veyron.save(path, listOfSaveRequests())

Build Locally

./gradlew :veyron:build

Note

A few things to note about this library:

  • Assumes unique file and folder names. Unlike a normal file system, Google Drive allows you to create folders and files at the same level with the same name. We will always fetch/return the first result we find if there are duplicates.
  • It has dependencies. Please check them and understand what they do.
  • Each query is limited to 1,000 results, but we fetch all results. We do not currently support pagination or "infinite loading"

R8/Proguard

If you are using R8/Proguard, you will need to include the rules for Moshi and okio. Rules for the Google HTTP Client Library are included as rules for this library.

License

Copyright 2023 Commit 451

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

Easier Google Drive SDK Access on Android

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages