Skip to content

Commit

Permalink
Added google drive icons, some minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Harrison committed Jul 2, 2022
1 parent c54f227 commit 522b581
Show file tree
Hide file tree
Showing 21 changed files with 28 additions and 77 deletions.
5 changes: 4 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ android {
kotlinOptions {
jvmTarget = 11
}

packagingOptions {
resources {
excludes += ['META-INF/DEPENDENCIES', 'plugin.properties']
Expand All @@ -103,6 +102,10 @@ android {
checkDependencies true
disable 'MissingTranslation', 'MissingQuantity', 'ImpliedQuantity', 'InvalidPackage'
}
lint {
disable 'MissingTranslation', 'MissingQuantity', 'ImpliedQuantity', 'InvalidPackage'
}

}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ public Drive getDriveService(GoogleSignInAccount googleAccount) {
}

public Drive getDriveService() {
if (mDriveService != null) return mDriveService;
return getDriveService(getGoogleAccount());
}

Expand Down Expand Up @@ -249,7 +248,7 @@ public VersionedRook download(Uri repoUri, String fileName, java.io.File localFi
if (e.getMessage() != null) {
throw new IOException("Failed downloading Google Drive file " + uri + ": " + e.getMessage());
} else {
throw new IOException("Failed downloading Google Drive file " + uri + ": " + e.toString());
throw new IOException("Failed downloading Google Drive file " + uri + ": " + e);
}
} finally {
out.close();
Expand Down Expand Up @@ -303,7 +302,7 @@ public VersionedRook upload(java.io.File file, Uri repoUri, String fileName) thr
if (e.getMessage() != null) {
throw new IOException("Failed overwriting " + filePath + " on Google Drive: " + e.getMessage());
} else {
throw new IOException("Failed overwriting " + filePath + " on Google Drive: " + e.toString());
throw new IOException("Failed overwriting " + filePath + " on Google Drive: " + e);
}
}

Expand Down Expand Up @@ -337,7 +336,7 @@ public void delete(String path) throws IOException {
if (e.getMessage() != null) {
throw new IOException("Failed deleting " + path + " on Google Drive: " + e.getMessage());
} else {
throw new IOException("Failed deleting " + path + " on Google Drive: " + e.toString());
throw new IOException("Failed deleting " + path + " on Google Drive: " + e);
}
}
}
Expand Down Expand Up @@ -374,7 +373,7 @@ public VersionedRook move(Uri repoUri, Uri from, Uri to) throws IOException {
if (e.getMessage() != null) { // TODO: Move this throwing to utils
throw new IOException("Failed moving " + from + " to " + to + ": " + e.getMessage(), e);
} else {
throw new IOException("Failed moving " + from + " to " + to + ": " + e.toString(), e);
throw new IOException("Failed moving " + from + " to " + to + ": " + e, e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ import com.orgzly.android.util.UriUtils
import com.orgzly.databinding.ActivityRepoGoogleDriveBinding
import javax.inject.Inject

import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.Scope;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.Scope
import com.google.android.gms.tasks.Task
import com.google.android.gms.tasks.OnCompleteListener

import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.DriveScopes

import androidx.annotation.NonNull;
import androidx.annotation.NonNull

import android.util.Log;
import android.util.Log

class GoogleDriveRepoActivity : CommonActivity() {
private lateinit var binding: ActivityRepoGoogleDriveBinding
Expand Down Expand Up @@ -152,7 +152,7 @@ class GoogleDriveRepoActivity : CommonActivity() {
{
GoogleSignIn.getSignedInAccountFromIntent(result)
.addOnSuccessListener { googleAccount ->
Log.d(TAG, "Signed in as " + googleAccount.getEmail())
Log.d(TAG, "Signed in as " + googleAccount.email)
// Use the authenticated account to sign in to the Drive service.
client.setDriveService(googleAccount)
showSnackbar(R.string.message_google_drive_linked)
Expand All @@ -161,48 +161,6 @@ class GoogleDriveRepoActivity : CommonActivity() {
}
}

// Token stuff is handled by Google sign-in
// private fun editAccessToken() {
// @SuppressLint("InflateParams")
// val view = layoutInflater.inflate(R.layout.dialog_simple_one_liner, null, false)
//
// val editView = view.findViewById<EditText>(R.id.dialog_input).apply {
// setSelectAllOnFocus(true)
//
// setHint(R.string.access_token)
//
// client.token?.let {
// setText(it)
// }
// }
//
// alertDialog = AlertDialog.Builder(this)
// .setView(view)
// .setTitle(R.string.access_token)
// .setPositiveButton(R.string.set) { _, _ ->
// editView.text.toString().let { value ->
// if (TextUtils.isEmpty(value)) {
// client.unlink(this)
// } else {
// client.setToken(value)
// }
// }
// updateGoogleDriveLinkUnlinkButton()
// }
// .setNeutralButton(R.string.clear) { _, _ ->
// client.unlink(this)
// updateGoogleDriveLinkUnlinkButton()
// }
// .setNegativeButton(R.string.cancel) { _, _ -> }
// .create().apply {
// setOnShowListener {
// ActivityUtils.openSoftKeyboard(this@GoogleDriveRepoActivity, editView)
// }
//
// show()
// }
// }

public override fun onResume() {
super.onResume()

Expand Down Expand Up @@ -296,33 +254,18 @@ class GoogleDriveRepoActivity : CommonActivity() {
}
}

// /**
// * Complete Google Drive linking.
// * After starting Google Drive authentication, user will return to activity.
// * We need to finish the process of authentication.
// */
// private fun googleDriveCompleteAuthentication() {
// if (!isGoogleDriveLinked()) {
// if (client.finishAuthentication()) {
// showSnackbar(R.string.message_google_drive_linked)
// }
// } else {
// showSnackbar(R.string.message_google_drive_linked)
// }
// }

private fun updateGoogleDriveLinkUnlinkButton() {
if (BuildConfig.LOG_DEBUG) LogUtils.d(TAG)

val resources = styledAttributes(R.styleable.Icons) { typedArray ->
if (isGoogleDriveLinked()) {
Pair(
getString(R.string.repo_google_drive_button_linked),
typedArray.getResourceId(R.styleable.Icons_oic_dropbox_linked, 0))
typedArray.getResourceId(R.styleable.Icons_oic_google_drive_linked, 0))
} else {
Pair(
getString(R.string.repo_google_drive_button_not_linked),
typedArray.getResourceId(R.styleable.Icons_oic_dropbox_not_linked, 0))
typedArray.getResourceId(R.styleable.Icons_oic_google_drive_not_linked, 0))
}
}

Expand All @@ -345,7 +288,7 @@ class GoogleDriveRepoActivity : CommonActivity() {

private fun unlinkGoogleDrive() {
gsiClient.revokeAccess()
.addOnCompleteListener(this, OnCompleteListener<Void>() {
.addOnCompleteListener(this, OnCompleteListener<Void> {
fun onComplete(@NonNull task:Task<Void>) {
Log.d(TAG, "Signed out")
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_repo_google_drive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
android:id="@+id/activity_repo_google_drive_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="?attr/oic_dropbox_not_linked"
android:src="?attr/oic_google_drive_not_linked"
android:contentDescription="@string/google_drive" />

<Button
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@

<attr name="oic_dropbox_linked" format="reference"/>
<attr name="oic_dropbox_not_linked" format="reference"/>
<attr name="oic_google_drive_linked" format="reference"/>
<attr name="oic_google_drive_not_linked" format="reference"/>
<attr name="oic_git_48dp" format="reference"/>
<attr name="oic_new_above_24dp" format="reference"/>
<attr name="oic_new_below_24dp" format="reference"/>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@
<item name="ic_widgets_24dp">@drawable/ic_widgets_black_24dp</item>

<item name="oic_dropbox_linked">@drawable/cic_dropbox_blue_48px</item>
<item name="oic_google_drive_linked">@drawable/cic_google_drive_color</item>
<item name="oic_git_48dp">@drawable/cic_git_black_48dp</item>
<item name="oic_dropbox_not_linked">@drawable/cic_dropbox_black_48px</item>
<item name="oic_google_drive_not_linked">@drawable/cic_google_drive_black</item>
<item name="oic_new_above_24dp">@drawable/cic_new_above_black_24dp</item>
<item name="oic_new_below_24dp">@drawable/cic_new_below_black_24dp</item>
<item name="oic_new_under_24dp">@drawable/cic_new_under_black_24dp</item>
Expand Down Expand Up @@ -270,8 +272,10 @@
<item name="ic_widgets_24dp">@drawable/ic_widgets_white_24dp</item>

<item name="oic_dropbox_linked">@drawable/cic_dropbox_blue_48px</item>
<item name="oic_google_drive_linked">@drawable/cic_google_drive_color</item>
<item name="oic_git_48dp">@drawable/cic_git_white_48dp</item>
<item name="oic_dropbox_not_linked">@drawable/cic_dropbox_white_48px</item>
<item name="oic_google_drive_not_linked">@drawable/cic_google_drive_white</item>
<item name="oic_new_above_24dp">@drawable/cic_new_above_white_24dp</item>
<item name="oic_new_below_24dp">@drawable/cic_new_below_white_24dp</item>
<item name="oic_new_under_24dp">@drawable/cic_new_under_white_24dp</item>
Expand Down

0 comments on commit 522b581

Please sign in to comment.