-
Notifications
You must be signed in to change notification settings - Fork 2
Google Drive Backup #3
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
Open
RafaRuiz
wants to merge
5
commits into
develop
Choose a base branch
from
feature/google_drive_backup
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/minima/android/MinimaApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.minima.android; | ||
|
|
||
| import android.app.Application; | ||
|
|
||
| import com.minima.android.dependencies.backupSync.recurring.BackupRecurringAlarmManager; | ||
|
|
||
| public class MinimaApplication extends Application { | ||
| @Override | ||
| public void onCreate() { | ||
| super.onCreate(); | ||
| BackupRecurringAlarmManager.setAlarm(this); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/minima/android/dependencies/backupSync/BackupSyncProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.minima.android.dependencies.backupSync; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.Intent; | ||
|
|
||
| import androidx.activity.result.ActivityResultLauncher; | ||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
|
|
||
| import com.minima.android.dependencies.backupSync.model.BackupUserStateCallback; | ||
| import com.minima.android.dependencies.backupSync.providers.drive.GoogleDriveProvider; | ||
|
|
||
| public abstract class BackupSyncProvider { | ||
| /** | ||
| * @param context Context of the application (resources wise) | ||
| * @param oAuth2ResultLauncher [ActivityResultLauncher] that will handle the | ||
| * result back when logged in. | ||
| */ | ||
| public abstract void auth(Context context, @NonNull ActivityResultLauncher<Intent> oAuth2ResultLauncher); | ||
|
|
||
| /** | ||
| * @param context Context of the application (resources wise) | ||
| * @return user's state and possible info depending on the provider injected | ||
| */ | ||
| public abstract void getUserState(Context context, BackupUserStateCallback backupUserStateCallback); | ||
|
|
||
| /** | ||
| * @param context Context of the application (resources wise) | ||
| * @param fileToUpload File from the file system to upload. | ||
| * @param retryResultLauncher [ActivityResultLauncher] that will handle the | ||
| * and launch in case the user needs to do any | ||
| * further operation. | ||
| * <p> | ||
| * Example: when the user denies the access of this | ||
| * app to Google Drive once accepted before. | ||
| * <p> | ||
| * This parameter can be null, which means that it | ||
| * won't try to retry any OAuth2 further action that | ||
| * can be need, and it's usually null when we can to | ||
| * do a silent upload. | ||
| */ | ||
| public abstract void uploadBackup(Context context, java.io.File fileToUpload, @Nullable ActivityResultLauncher<Intent> retryResultLauncher); | ||
|
|
||
| /** | ||
| * @param context Context of the application (resources wise) | ||
| * @param fileToUpload File from the file system to upload. | ||
| */ | ||
| public void uploadBackup(Context context, java.io.File fileToUpload) { | ||
| uploadBackup(context, fileToUpload, null); | ||
| } | ||
|
|
||
| // Providers | ||
| public static BackupSyncProvider getGoogleDriveProvider(Context context) { | ||
| return GoogleDriveProvider.getInstance(context); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
app/src/main/java/com/minima/android/dependencies/backupSync/minima/MinimaBackupUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package com.minima.android.dependencies.backupSync.minima; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a file I wrote, but I moved it from another location |
||
|
|
||
| import android.content.Context; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
|
|
||
| import com.minima.android.service.MinimaService; | ||
|
|
||
| import org.minima.Minima; | ||
| import org.minima.utils.MinimaLogger; | ||
|
|
||
| import java.io.File; | ||
|
|
||
| public class MinimaBackupUtils { | ||
| @Nullable | ||
| public static File createBackup(Context context) { | ||
| final Minima minima = MinimaService.minima; | ||
| if (minima != null) { | ||
| //Where are we going to store the file | ||
| String filename = "minima-backup.gz.bak"; | ||
| File backup = new File(context.getFilesDir(), filename); | ||
| if (backup.exists()) { | ||
| backup.delete(); | ||
| } | ||
|
|
||
| //First run a command On Minima.. | ||
| String result = minima.runMinimaCMD("backup file:" + backup.getAbsolutePath()); | ||
|
|
||
| //Now share this.. | ||
| MinimaLogger.log("Backup : " + result); | ||
|
|
||
| if (backup.exists()) { | ||
| return backup; | ||
| } else { | ||
| return null; | ||
| } | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| } | ||
5 changes: 5 additions & 0 deletions
5
...c/main/java/com/minima/android/dependencies/backupSync/model/BackupUserStateCallback.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.minima.android.dependencies.backupSync.model; | ||
|
|
||
| public interface BackupUserStateCallback { | ||
| void onUserState(BackupUserStateModel backupUserStateModel); | ||
| } |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/minima/android/dependencies/backupSync/model/BackupUserStateModel.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.minima.android.dependencies.backupSync.model; | ||
|
|
||
| public abstract class BackupUserStateModel { | ||
| } | ||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has been moved. It was existing before.