-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加备份与恢复
- Loading branch information
Showing
6 changed files
with
137 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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,76 @@ | ||
package cn.lyric.getter.tool | ||
|
||
import android.app.Activity | ||
import android.content.SharedPreferences | ||
import android.net.Uri | ||
import cn.xiaowine.xkt.AcTool.showToast | ||
import cn.xiaowine.xkt.Tool.isNotNull | ||
import org.json.JSONObject | ||
import java.io.BufferedReader | ||
import java.io.BufferedWriter | ||
import java.io.InputStreamReader | ||
import java.io.OutputStreamWriter | ||
|
||
|
||
object BackupTools { | ||
fun handleReadDocument(activity: Activity, sp: SharedPreferences, data: Uri) { | ||
val edit = sp.edit() | ||
try { | ||
activity.contentResolver.openInputStream(data)?.let { loadFile -> | ||
BufferedReader(InputStreamReader(loadFile)).apply { | ||
val sb = StringBuffer() | ||
var line = readLine() | ||
while (line.isNotNull()) { | ||
sb.append(line) | ||
line = readLine() | ||
} | ||
val read = sb.toString() | ||
JSONObject(read).apply { | ||
val key = keys() | ||
while (key.hasNext()) { | ||
val keys = key.next() | ||
when (val value = get(keys)) { | ||
is String -> { | ||
if (value.startsWith("Float:")) { | ||
edit.putFloat(keys, value.substring(value.indexOf("Float:")).toFloat() / 1000) | ||
} else { | ||
edit.putString(keys, value) | ||
} | ||
} | ||
|
||
is Boolean -> edit.putBoolean(keys, value) | ||
is Int -> edit.putInt(keys, value) | ||
} | ||
} | ||
} | ||
close() | ||
} | ||
} | ||
edit.apply() | ||
"load ok".showToast() | ||
} catch (e: Exception) { | ||
"load fail\n${e.message}".showToast() | ||
} | ||
} | ||
|
||
fun handleCreateDocument(activity: Activity, sp: SharedPreferences, data: Uri) { | ||
try { | ||
activity.contentResolver.openOutputStream(data)?.let { saveFile -> | ||
BufferedWriter(OutputStreamWriter(saveFile)).apply { | ||
write(JSONObject().also { | ||
for (entry: Map.Entry<String, *> in sp.all) { | ||
when (entry.value) { | ||
Float -> it.put(entry.key, "Float:" + (entry.value as Float * 1000).toInt().toString()) | ||
else -> it.put(entry.key, entry.value) | ||
} | ||
} | ||
}.toString()) | ||
close() | ||
} | ||
} | ||
"save ok".showToast() | ||
} catch (e: Exception) { | ||
"save fail\n${e.message}".showToast() | ||
} | ||
} | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[versions] | ||
agp = "8.1.0" | ||
agp = "8.1.1" | ||
kotlin = "1.9.0" | ||
|
||
[libraries] | ||
|
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Jan 25 15:10:00 CST 2022 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |