Share configuration
This commit is contained in:
@@ -227,6 +227,16 @@
|
||||
|
||||
</provider>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.cache"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/cache_paths"/>
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.FileProvider
|
||||
import com.tbruyelle.rxpermissions.RxPermissions
|
||||
import com.tencent.mmkv.MMKV
|
||||
import com.v2ray.ang.AppConfig
|
||||
@@ -33,7 +34,31 @@ class AboutActivity : BaseActivity() {
|
||||
|
||||
binding.tvBackupSummary.text = this.getString(R.string.summary_configuration_backup, extDir)
|
||||
binding.layoutBackup.setOnClickListener {
|
||||
backupMMKV()
|
||||
val ret = backupConfiguration(extDir.absolutePath)
|
||||
if (ret.first) {
|
||||
toast(R.string.toast_success)
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
}
|
||||
}
|
||||
|
||||
binding.layoutShare.setOnClickListener {
|
||||
val ret = backupConfiguration(cacheDir.absolutePath)
|
||||
if (ret.first) {
|
||||
startActivity(
|
||||
Intent.createChooser(
|
||||
Intent(Intent.ACTION_SEND).setType("application/zip")
|
||||
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
.putExtra(
|
||||
Intent.EXTRA_STREAM, FileProvider.getUriForFile(
|
||||
this, BuildConfig.APPLICATION_ID + ".cache", File(ret.second)
|
||||
)
|
||||
), getString(R.string.title_configuration_share)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
}
|
||||
}
|
||||
|
||||
binding.layoutRestore.setOnClickListener {
|
||||
@@ -77,40 +102,36 @@ class AboutActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
fun backupMMKV() {
|
||||
fun backupConfiguration(outputZipFilePos: String): Pair<Boolean, String> {
|
||||
val dateFormated = SimpleDateFormat(
|
||||
"yyyy-MM-dd-HH-mm-ss",
|
||||
Locale.getDefault()
|
||||
).format(System.currentTimeMillis())
|
||||
val folderName = "${getString(R.string.app_name)}_${dateFormated}"
|
||||
val backupDir = this.cacheDir.absolutePath + "/$folderName"
|
||||
val outputZipFilePath = extDir.absolutePath + "/$folderName.zip"
|
||||
val outputZipFilePath = "$outputZipFilePos/$folderName.zip"
|
||||
|
||||
val count = MMKV.backupAllToDirectory(backupDir)
|
||||
if (count <= 0) {
|
||||
toast(R.string.toast_failure)
|
||||
return Pair(false, "")
|
||||
}
|
||||
|
||||
if (ZipUtil.zipFromFolder(backupDir, outputZipFilePath)) {
|
||||
toast(R.string.toast_success)
|
||||
return Pair(true, outputZipFilePath)
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
return Pair(false, "")
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreMMKV(zipFile: File) {
|
||||
fun restoreConfiguration(zipFile: File): Boolean {
|
||||
val backupDir = this.cacheDir.absolutePath + "/${System.currentTimeMillis()}"
|
||||
|
||||
if (!ZipUtil.unzipToFolder(zipFile, backupDir)) {
|
||||
toast(R.string.toast_failure)
|
||||
return false
|
||||
}
|
||||
|
||||
val count = MMKV.restoreAllFromDirectory(backupDir)
|
||||
if (count > 0) {
|
||||
toast(R.string.toast_success)
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
}
|
||||
return count > 0
|
||||
}
|
||||
|
||||
private fun showFileChooser() {
|
||||
@@ -138,8 +159,11 @@ class AboutActivity : BaseActivity() {
|
||||
input?.copyTo(fileOut)
|
||||
}
|
||||
}
|
||||
|
||||
restoreMMKV(targetFile)
|
||||
if (restoreConfiguration(targetFile)) {
|
||||
toast(R.string.toast_success)
|
||||
} else {
|
||||
toast(R.string.toast_failure)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
@@ -51,6 +51,30 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_share"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/server_height"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?attr/selectableItemBackground"
|
||||
android:gravity="center|start"
|
||||
android:orientation="horizontal"
|
||||
android:padding="16dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="@dimen/png_height"
|
||||
android:layout_height="@dimen/png_height"
|
||||
app:srcCompat="@drawable/ic_share_24dp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="16dp"
|
||||
android:text="@string/title_configuration_share"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Subhead" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_restore"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -183,6 +183,7 @@
|
||||
<string name="title_configuration_backup">إعدادات النسخ الاحتياطي</string>
|
||||
<string name="summary_configuration_backup">مكان التخزين: [%s]، سيتم مسح النسخة الاحتياطية بعد إلغاء تثبيت التطبيق أو مسح مساحة التخزين</string>
|
||||
<string name="title_configuration_restore">استعادة الاعدادات</string>
|
||||
<string name="title_configuration_share">Share configuration</string>
|
||||
<string name="title_pref_promotion">ترقية</string>
|
||||
|
||||
<string name="summary_pref_promotion">ترقية، انقر للحصول على التفاصيل (يمكن إزالة التبرع)</string>
|
||||
|
||||
@@ -177,6 +177,7 @@
|
||||
<string name="title_configuration_backup">Backup configuration</string>
|
||||
<string name="summary_configuration_backup">Storage location: [%s], The backup will be cleared after uninstalling the app or clearing the storage</string>
|
||||
<string name="title_configuration_restore">Restore configuration</string>
|
||||
<string name="title_configuration_share">Share configuration</string>
|
||||
<string name="title_pref_promotion">تبلیغات</string>
|
||||
<string name="summary_pref_promotion">تبلیغات، برای جزئیات بیشتر کلیک کنید (کمک مالی کنید تا حذف شود)</string>
|
||||
|
||||
|
||||
@@ -179,6 +179,7 @@
|
||||
<string name="title_configuration_backup">Резервирование</string>
|
||||
<string name="summary_configuration_backup">Путь: [%s]. Резервная копия будет стёрта при удалении приложения или очистке хранилища.</string>
|
||||
<string name="title_configuration_restore">Восстановление</string>
|
||||
<string name="title_configuration_share">Share configuration</string>
|
||||
|
||||
<string name="title_pref_promotion">Содействие</string>
|
||||
<string name="summary_pref_promotion">Содействие, нажмите для получения подробной информации (пожертвование может быть удалено)</string>
|
||||
|
||||
@@ -179,6 +179,7 @@
|
||||
<string name="title_configuration_backup">Backup configuration</string>
|
||||
<string name="summary_configuration_backup">Storage location: [%s], The backup will be cleared after uninstalling the app or clearing the storage</string>
|
||||
<string name="title_configuration_restore">Restore configuration</string>
|
||||
<string name="title_configuration_share">Share configuration</string>
|
||||
<string name="title_pref_promotion">Quảng bá server</string>
|
||||
<string name="summary_pref_promotion">Quảng cáo, nhấn để biết thêm (Ủng hộ có thể được gỡ bỏ)</string>
|
||||
|
||||
|
||||
@@ -177,6 +177,7 @@
|
||||
<string name="title_configuration_backup">备份配置</string>
|
||||
<string name="summary_configuration_backup">存储位置: [%s], 卸载App或清除存储后备份将被清除</string>
|
||||
<string name="title_configuration_restore">还原配置</string>
|
||||
<string name="title_configuration_share">分享配置</string>
|
||||
|
||||
<string name="title_pref_promotion">推广</string>
|
||||
<string name="summary_pref_promotion">一些推广,点击查看详情(捐赠可去除)</string>
|
||||
|
||||
@@ -177,6 +177,7 @@
|
||||
<string name="title_configuration_backup">備份配置</string>
|
||||
<string name="summary_configuration_backup">儲存位置: [%s], 卸載App或清除儲存後備份將被清除</string>
|
||||
<string name="title_configuration_restore">還原配置</string>
|
||||
<string name="title_configuration_share">分享配置</string>
|
||||
|
||||
<string name="title_pref_promotion">推廣</string>
|
||||
<string name="summary_pref_promotion">一些推廣,輕觸以檢視 (捐贈可去除)</string>
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
<string name="title_configuration_backup">Backup configuration</string>
|
||||
<string name="summary_configuration_backup">Storage location: [%s], The backup will be cleared after uninstalling the app or clearing the storage</string>
|
||||
<string name="title_configuration_restore">Restore configuration</string>
|
||||
<string name="title_configuration_share">Share configuration</string>
|
||||
|
||||
<string name="title_pref_promotion">Promotion</string>
|
||||
<string name="summary_pref_promotion">Promotion,click for details(Donation can be removed)</string>
|
||||
|
||||
4
V2rayNG/app/src/main/res/xml/cache_paths.xml
Normal file
4
V2rayNG/app/src/main/res/xml/cache_paths.xml
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths>
|
||||
<cache-path name="cache" path="/"/>
|
||||
</paths>
|
||||
Reference in New Issue
Block a user