-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3110 from CruGlobal/trackChangedFields
GT-1796 Track which tools were added/removed as favorites
- Loading branch information
Showing
13 changed files
with
851 additions
and
18 deletions.
There are no files selected for viewing
668 changes: 668 additions & 0 deletions
668
library/db/room-schemas/org.cru.godtools.db.room.GodToolsRoomDatabase/15.json
Large diffs are not rendered by default.
Oops, something went wrong.
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
21 changes: 21 additions & 0 deletions
21
library/db/src/main/kotlin/org/cru/godtools/db/room/entity/partial/ToolFavorite.kt
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,21 @@ | ||
package org.cru.godtools.db.room.entity.partial | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Ignore | ||
import org.cru.godtools.model.ChangeTrackingModel | ||
import org.cru.godtools.model.Tool | ||
|
||
internal class ToolFavorite(val code: String) : ChangeTrackingModel { | ||
var isFavorite = false | ||
set(value) { | ||
if (field != value) markChanged(Tool.ATTR_IS_FAVORITE) | ||
field = value | ||
} | ||
|
||
// region ChangeTrackingModel | ||
@Ignore | ||
override var isTrackingChanges = false | ||
@ColumnInfo(name = "changedFields") | ||
override var changedFieldsStr = "" | ||
// endregion ChangeTrackingModel | ||
} |
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
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
21 changes: 21 additions & 0 deletions
21
library/model/src/main/kotlin/org/cru/godtools/model/ChangeTrackingModel.kt
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,21 @@ | ||
package org.cru.godtools.model | ||
|
||
interface ChangeTrackingModel { | ||
val changedFields get() = changedFieldsStr.splitToSequence(",").filter { it.isNotEmpty() }.distinct() | ||
|
||
var isTrackingChanges: Boolean | ||
var changedFieldsStr: String | ||
|
||
fun markChanged(field: String) { | ||
if (isTrackingChanges) changedFieldsStr = "$changedFieldsStr,$field" | ||
} | ||
} | ||
|
||
inline fun <T : ChangeTrackingModel> T.trackChanges(block: (T) -> Unit) { | ||
isTrackingChanges = true | ||
try { | ||
block(this) | ||
} finally { | ||
isTrackingChanges = false | ||
} | ||
} |
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