Skip to content

Commit

Permalink
fix customfield reset, adding a deep copy for asset
Browse files Browse the repository at this point in the history
  • Loading branch information
0xpr03 committed Jun 9, 2022
1 parent 85e6a09 commit 52f9c2e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ data class Asset(
/** Custom fields, key is the user visible name **/
var custom_fields: HashMap<String,CustomField>?
) : Parcelable {
// required such that originAsset and asset can't override each other
fun deepCopy(): Asset {
val asset = this.copy()
asset._cf_by_dbname = null
asset.custom_fields = HashMap()
val fields = custom_fields
if (fields != null) {
for (item in fields.iterator()) {
asset.custom_fields!!.put(item.key,item.value.copy())
}
}
return asset
}

private var _cf_by_dbname: HashMap<String,CustomField>? = null
/**
* Custom fields with access by their internal DB name
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package de.tu_darmstadt.seemoo.HardWhere.ui.editor.asset

import android.telecom.Call
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import de.tu_darmstadt.seemoo.HardWhere.Utils.Companion.logResponseVerbose
import de.tu_darmstadt.seemoo.HardWhere.data.APIInterface
Expand All @@ -17,7 +15,6 @@ import io.reactivex.schedulers.Schedulers
import org.acra.ACRA
import retrofit2.Callback
import retrofit2.Response
import java.lang.reflect.Field


class EditorViewModel : ViewModel() {
Expand Down Expand Up @@ -79,7 +76,7 @@ class EditorViewModel : ViewModel() {
fun setEditorAsset(asset: Asset) {
Log.d(this::class.java.name,"Setting editor asset & default")
assetMutable.value = asset
assetOriginMutable.value = assetMutable.value!!.copy()
assetOriginMutable.value = assetMutable.value!!.deepCopy()
}

/**
Expand Down

0 comments on commit 52f9c2e

Please sign in to comment.