Skip to content

Instantly share code, notes, and snippets.

@Xiryl
Xiryl / ViewModel.kt
Created February 11, 2023 13:06
driveapimedium-github-5
for (file in files) {
val gfile = com.google.api.services.drive.model.File()
val fileContent = FileContent("your_mime", file)
gfile.name = file.name
val parents: MutableList<String> = ArrayList(1)
parents.add("folder_id") // Here you need to get the parent folder id
gfile.parents = parents
@Xiryl
Xiryl / ViewModel.kt
Last active March 6, 2023 15:56
driveapimedium-github-4
viewModelScope.launch(Dispatchers.IO) {
// Define a Folder
val gFolder = com.google.api.services.drive.model.File()
// Set file name and MIME
gFolder.name = "My Cool Folder Name"
gFolder.mimeType = "application/vnd.google-apps.folder"
// You can also specify where to create the new Google folder
// passing a parent Folder Id
val parents: MutableList<String> = ArrayList(1)
@Xiryl
Xiryl / DriveInstance.kt
Created February 11, 2023 12:57
driveapimedium-github-3
GoogleSignIn.getLastSignedInAccount(context)?.let { googleAccount ->
// get credentials
val credential = GoogleAccountCredential.usingOAuth2(
context, listOf(DriveScopes.DRIVE, DriveScopes.DRIVE_FILE)
)
credential.selectedAccount = googleAccount.account!!
// get Drive Instance
val drive = Drive
@Xiryl
Xiryl / Helpers.kt
Created February 11, 2023 12:50
driveapimedium-github-2
fun getGoogleSignInClient(context: Context): GoogleSignInClient {
val signInOptions = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(Scope(DriveScopes.DRIVE_FILE), Scope(DriveScopes.DRIVE))
.build()
return GoogleSignIn.getClient(context, signInOptions)
}
@Xiryl
Xiryl / YourUi.kt
Created February 11, 2023 11:02
driveapimedium-github-2
Button(
onClick = {
startForResult.launch(getGoogleSignInClient(ctx).signInIntent)
},
modifier = Modifier()
) {
Text(text = "Sign in with Google")
}
@Xiryl
Xiryl / Activity.kt
Created February 11, 2023 10:58
driveapimedium-github-1
val startForResult = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
if (result.resultCode == Activity.RESULT_OK) {
val intent = result.data
if (result.data != null) {
val task: Task<GoogleSignInAccount> =
GoogleSignIn.getSignedInAccountFromIntent(intent)
/**
* handle [task] result
*/
@Xiryl
Xiryl / build.gradle
Created February 11, 2023 10:42
driveapimedium-github
// ...
// coroutines
// Guava
implementation "com.google.guava:guava:24.1-jre"
// Guava fix
implementation "com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava"
//Drive
implementation('com.google.api-client:google-api-client-android:1.23.0') {
function createHomeCard() {
const imgLogoUri = "http://your.home.page.image.link";
const imgLogo = CardService.newImage()
.setImageUrl(imgLogoUri)
.setAltText("Digit-Atoms");
const footer = CardService.newFixedFooter().setPrimaryButton(
CardService.newTextButton()
.setTextButtonStyle(CardService.TextButtonStyle.FILLED)
@Xiryl
Xiryl / code.gs
Created January 5, 2022 16:18
addon -3
const txtInsertId =
CardService.newTextParagraph().setText("<b>Bold text</b><br/> -Can you read this?");
const textInput = CardService.newTextInput()
.setFieldName("txt_input_id_to_process")
.setTitle("Write something here...");
const ico = CardService.newIconImage().setIconUrl(
"ico link"
);
/**
* Callback for rendering the homepage card.
* @return The card to show to the user.
*/
function onHomepage(e) {
return createHomeCard();
}
/**
* Build the home card