Skip to content

Commit e97e3cc

Browse files
authored
Merge pull request #36 from standardsats/backup-improvement
Select backup location and stop creating new file each time
2 parents 6a1bca5 + d5c4868 commit e97e3cc

38 files changed

Lines changed: 334 additions & 252 deletions

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ android {
1717
targetSdkVersion 33
1818
minSdkVersion 21
1919

20-
versionName '4.3.0'
21-
versionCode 102
20+
versionName '4.4.0'
21+
versionCode 103
2222
}
2323

2424
dexOptions {

app/src/debug/res/drawable/ic_launcher_foreground.xml

Lines changed: 0 additions & 26 deletions
This file was deleted.
-31.6 KB
Binary file not shown.
Lines changed: 48 additions & 0 deletions
Loading

app/src/main/ic_launcher-web.png

-33.7 KB
Binary file not shown.

app/src/main/ic_launcher-web.svg

Lines changed: 98 additions & 0 deletions
Loading

app/src/main/java/com/btcontract/walletfiat/SettingsActivity.scala

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.btcontract.walletfiat
22

3+
import android.app.Activity
34
import android.content.Intent
45
import android.os.{Build, Bundle}
56
import android.view.{View, ViewGroup}
@@ -55,9 +56,11 @@ class SettingsActivity extends BaseCheckActivity with HasTypicalChainFee with Ch
5556
private[this] val CHOICE_FIAT_DENOMINATION_TAG = "choiceFiatDenominationTag"
5657
private[this] val CHOICE_BTC_DENOMINATON_TAG = "choiceBtcDenominationTag"
5758
private[this] val units = List(SatDenomination, BtcDenomination)
59+
private[this] final val DIRECTORY_REQUEST_CODE = 113
5860

5961
override def onResume: Unit = {
6062
storeLocalBackup.updateView
63+
backupLocation.updateView
6164
chainWallets.updateView
6265
electrum.updateView
6366
setFiat.updateView
@@ -94,7 +97,7 @@ class SettingsActivity extends BaseCheckActivity with HasTypicalChainFee with Ch
9497
val backupAllowed = LocalBackup.isAllowed(context = WalletApp.app)
9598
if (backupAllowed && LNParams.cm.all.nonEmpty) WalletApp.backupSaveWorker.replaceWork(false)
9699
val title = if (backupAllowed) settings_backup_enabled else settings_backup_disabled
97-
val info = if (backupAllowed) settings_backup_where else settings_backup_how
100+
val info = settings_backup_info
98101
settingsTitle.setText(title)
99102
settingsInfo.setText(info)
100103
}
@@ -106,6 +109,48 @@ class SettingsActivity extends BaseCheckActivity with HasTypicalChainFee with Ch
106109
}
107110
}
108111

112+
lazy private[this] val backupLocation = new SettingsHolder(me) {
113+
setVis(isVisible = false, settingsCheck)
114+
115+
def updateView: Unit = {
116+
val customLocation = WalletApp.customBackupLocation
117+
val info: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
118+
customLocation match {
119+
case Some(path) => path.getPath
120+
case None => me getString settings_backup_where
121+
}
122+
} else me getString settings_backup_location_too_old
123+
settingsTitle.setText(settings_backup_location)
124+
settingsInfo.setText(info)
125+
}
126+
127+
view setOnClickListener onButtonTap {
128+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
129+
val i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
130+
i.addCategory(Intent.CATEGORY_DEFAULT)
131+
i.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
132+
i.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION)
133+
startActivityForResult(Intent.createChooser(i, me getString settings_choose_directory), DIRECTORY_REQUEST_CODE)
134+
}
135+
}
136+
}
137+
138+
override def onActivityResult(requestCode: Int, resultCode: Int, resultData: Intent): Unit =
139+
if (requestCode == DIRECTORY_REQUEST_CODE && resultCode == Activity.RESULT_OK && resultData != null) {
140+
def saveDirectory(directory: String) = WalletApp.app.prefs.edit.putString(WalletApp.CUSTOM_BACKUP_LOCATION, directory)
141+
WalletApp.customBackupLocation match {
142+
case Some(uri) => {
143+
getContentResolver.releasePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
144+
}
145+
case _ => ()
146+
}
147+
val uri = resultData.getData
148+
getContentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
149+
saveDirectory(uri.toString).commit
150+
backupLocation.updateView
151+
WalletApp.backupSaveWorker.replaceWork(true)
152+
}
153+
109154
lazy private[this] val chainWallets: SettingsHolder = new SettingsHolder(me) {
110155
setVisMany(false -> settingsCheck, false -> settingsInfo)
111156
settingsTitle.setText(settings_chain_wallets)
@@ -320,6 +365,7 @@ class SettingsActivity extends BaseCheckActivity with HasTypicalChainFee with Ch
320365

321366
settingsContainer.addView(settingsPageitle.view)
322367
settingsContainer.addView(storeLocalBackup.view)
368+
settingsContainer.addView(backupLocation.view)
323369
settingsContainer.addView(chainWallets.view)
324370
settingsContainer.addView(addHardware.view)
325371
settingsContainer.addView(electrum.view)

0 commit comments

Comments
 (0)