- Now Crystal can make file backups
This commit is contained in:
parent
db7ba760bd
commit
ef18863c7c
4 changed files with 48 additions and 15 deletions
|
@ -4,6 +4,8 @@
|
|||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:name=".application.CrystalApplication"
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package cy.agorise.crystalwallet.fragments;
|
||||
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.arch.lifecycle.Observer;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
@ -21,6 +24,8 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import cy.agorise.crystalwallet.R;
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.models.GeneralSetting;
|
||||
import cy.agorise.crystalwallet.requestmanagers.CreateBackupRequest;
|
||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequest;
|
||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequestListener;
|
||||
|
@ -78,26 +83,38 @@ public class BackupsSettingsFragment extends Fragment{
|
|||
|
||||
@OnClick(R.id.btnBinFile)
|
||||
public void makeBackupFile(){
|
||||
if (Environment.getExternalStorageState() == Environment.MEDIA_MOUNTED) {
|
||||
|
||||
final CreateBackupRequest backupFileRequest = new CreateBackupRequest(getContext());
|
||||
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
||||
|
||||
backupFileRequest.setListener(new FileServiceRequestListener() {
|
||||
LiveData<GeneralSetting> generalSettingLD = CrystalDatabase.getAppDatabase(getContext()).generalSettingDao().getByName(GeneralSetting.SETTING_PASSWORD);
|
||||
|
||||
generalSettingLD.observe(this, new Observer<GeneralSetting>() {
|
||||
@Override
|
||||
public void onCarryOut() {
|
||||
if (backupFileRequest.getStatus() == CreateBackupRequest.StatusCode.SUCCEEDED){
|
||||
Toast toast = Toast.makeText(
|
||||
getContext(), "Backup done! File: "+backupFileRequest.getFilePath(), Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
} else if (backupFileRequest.getStatus() == CreateBackupRequest.StatusCode.FAILED){
|
||||
Toast toast = Toast.makeText(
|
||||
getContext(), "An error ocurred while making the backup!", Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
public void onChanged(@Nullable GeneralSetting generalSetting) {
|
||||
String password = "";
|
||||
if (generalSetting != null) {
|
||||
password = generalSetting.getValue();
|
||||
}
|
||||
|
||||
final CreateBackupRequest backupFileRequest = new CreateBackupRequest(getContext(), password);
|
||||
|
||||
backupFileRequest.setListener(new FileServiceRequestListener() {
|
||||
@Override
|
||||
public void onCarryOut() {
|
||||
if (backupFileRequest.getStatus() == CreateBackupRequest.StatusCode.SUCCEEDED){
|
||||
Toast toast = Toast.makeText(
|
||||
getContext(), "Backup done! File: "+backupFileRequest.getFilePath(), Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
} else if (backupFileRequest.getStatus() == CreateBackupRequest.StatusCode.FAILED){
|
||||
Toast toast = Toast.makeText(
|
||||
getContext(), "An error ocurred while making the backup!", Toast.LENGTH_LONG);
|
||||
toast.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
FileServiceRequests.getInstance().addRequest(backupFileRequest);
|
||||
}
|
||||
});
|
||||
|
||||
FileServiceRequests.getInstance().addRequest(backupFileRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,6 +100,11 @@ public class FileBackupManager implements FileServiceRequestsListener {
|
|||
String folder = Environment.getExternalStorageDirectory() + File.separator + "Crystal"; //TODO make constant
|
||||
String path = folder + File.separator + fileName + dateHourString +".bin";
|
||||
|
||||
File folderFile = new File(folder);
|
||||
if (!folderFile.exists()) {
|
||||
folderFile.mkdir();
|
||||
}
|
||||
|
||||
boolean success = saveBinFile(path,content,request);
|
||||
if(success) {
|
||||
request.setFilePath(path);
|
||||
|
|
|
@ -15,6 +15,7 @@ import android.util.Log;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cy.agorise.crystalwallet.manager.FileBackupManager;
|
||||
import cy.agorise.crystalwallet.requestmanagers.CryptoNetInfoRequests;
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.enums.CryptoNet;
|
||||
|
@ -26,6 +27,8 @@ import cy.agorise.crystalwallet.models.CryptoNetAccount;
|
|||
import cy.agorise.crystalwallet.models.GeneralSetting;
|
||||
import cy.agorise.crystalwallet.models.GrapheneAccount;
|
||||
import cy.agorise.crystalwallet.models.GrapheneAccountInfo;
|
||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequest;
|
||||
import cy.agorise.crystalwallet.requestmanagers.FileServiceRequests;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 3/10/2017.
|
||||
|
@ -42,6 +45,8 @@ public class CrystalWalletService extends LifecycleService {
|
|||
private boolean keepLoadingAccountTransactions;
|
||||
private boolean keepLoadingEquivalences;
|
||||
private CryptoNetInfoRequests cryptoNetInfoRequests;
|
||||
private FileBackupManager fileBackupManager;
|
||||
private FileServiceRequests fileServiceRequests;
|
||||
|
||||
// Handler that receives messages from the thread
|
||||
private final class ServiceHandler extends Handler {
|
||||
|
@ -160,11 +165,15 @@ public class CrystalWalletService extends LifecycleService {
|
|||
super.onCreate();
|
||||
//Creates a instance for the cryptoNetInfoRequest and the managers
|
||||
this.cryptoNetInfoRequests = CryptoNetInfoRequests.getInstance();
|
||||
this.fileServiceRequests = FileServiceRequests.getInstance();
|
||||
this.bitsharesAccountManager = new BitsharesAccountManager();
|
||||
this.fileBackupManager = new FileBackupManager();
|
||||
|
||||
//Add the managers as listeners of the CryptoNetInfoRequest so
|
||||
//they can carry out the info requests from the ui
|
||||
this.cryptoNetInfoRequests.addListener(this.bitsharesAccountManager);
|
||||
|
||||
this.fileServiceRequests.addListener(this.fileBackupManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue