forked from Tribler/trustchain-superapp
-
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.
Add a vote tracker to the app that can be used as a basis for maintai…
…ning votes. (#23)
- Loading branch information
Showing
3 changed files
with
47 additions
and
1 deletion.
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
19 changes: 19 additions & 0 deletions
19
freedomOfComputing/src/main/java/nl/tudelft/trustchain/foc/community/FOCVote.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,19 @@ | ||
package nl.tudelft.trustchain.foc.community | ||
|
||
import nl.tudelft.ipv8.messaging.Deserializable | ||
|
||
data class FOCVote(val memberId: String) : nl.tudelft.ipv8.messaging.Serializable { | ||
override fun serialize(): ByteArray { | ||
return memberId.toByteArray() | ||
} | ||
|
||
companion object Deserializer : Deserializable<FOCMessage> { | ||
override fun deserialize( | ||
buffer: ByteArray, | ||
offset: Int | ||
): Pair<FOCMessage, Int> { | ||
val toReturn = buffer.toString(Charsets.UTF_8) | ||
return Pair(FOCMessage(toReturn), buffer.size) | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
freedomOfComputing/src/main/java/nl/tudelft/trustchain/foc/community/FOCVoteTracker.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,23 @@ | ||
package nl.tudelft.trustchain.foc.community | ||
|
||
import android.util.Log | ||
|
||
class FOCVoteTracker { | ||
// Stores the votes for all apks | ||
private val voteMap: MutableMap<String, Set<FOCVote>> = mutableMapOf() | ||
get() = field | ||
|
||
/** | ||
* Gets called on pause (or shutdown) of the app to persist state | ||
*/ | ||
fun storeState() { | ||
Log.w("vote-tracker", "storestate") | ||
} | ||
|
||
/** | ||
* Gets called on start up to load the state from disk | ||
*/ | ||
fun loadState() { | ||
Log.w("vote-tracker", "load state") | ||
} | ||
} |