Commit f06d8257 authored by Mygod's avatar Mygod

Clear all profiles only on import success

parent 3cb6b630
...@@ -290,10 +290,11 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti ...@@ -290,10 +290,11 @@ class MainPreferenceFragment : LeanbackPreferenceFragment(), ShadowsocksConnecti
if (resultCode != Activity.RESULT_OK) return if (resultCode != Activity.RESULT_OK) return
val profiles = ProfileManager.getAllProfiles()?.associateBy { it.formattedAddress } val profiles = ProfileManager.getAllProfiles()?.associateBy { it.formattedAddress }
val feature = profiles?.values?.singleOrNull { it.id == DataStore.profileId } val feature = profiles?.values?.singleOrNull { it.id == DataStore.profileId }
ProfileManager.clear() val lazyClear = lazy { ProfileManager.clear() }
for (uri in data!!.datas) try { for (uri in data!!.datas) try {
Profile.parseJson(activity.contentResolver.openInputStream(uri)!!.bufferedReader().readText(), Profile.parseJson(activity.contentResolver.openInputStream(uri)!!.bufferedReader().readText(),
feature) { feature) {
lazyClear.value
// if two profiles has the same address, treat them as the same profile and copy stats over // if two profiles has the same address, treat them as the same profile and copy stats over
profiles?.get(it.formattedAddress)?.apply { profiles?.get(it.formattedAddress)?.apply {
it.tx = tx it.tx = tx
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment