Skip to content

Commit

Permalink
Add a vote tracker to the app that can be used as a basis for maintai…
Browse files Browse the repository at this point in the history
…ning votes. (#23)
  • Loading branch information
JopSchaap authored Mar 6, 2024
1 parent f16c411 commit 4a3bc15
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.trustchain.foc.community.FOCCommunity
import nl.tudelft.trustchain.foc.community.FOCVoteTracker
import nl.tudelft.trustchain.foc.databinding.ActivityMainFocBinding
import nl.tudelft.trustchain.foc.util.ExtensionUtils.Companion.APK_DOT_EXTENSION
import nl.tudelft.trustchain.foc.util.ExtensionUtils.Companion.TORRENT_DOT_EXTENSION
Expand Down Expand Up @@ -63,7 +64,7 @@ open class MainActivityFOC : AppCompatActivity() {
private var bufferSize = 1024 * 5
private val s = SessionManager()
private var torrentAmount = 0

private val voteTracker: FOCVoteTracker = FOCVoteTracker()
private var appGossiper: AppGossiper? = null

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -106,6 +107,8 @@ open class MainActivityFOC : AppCompatActivity() {
} catch (e: Exception) {
printToast(e.toString())
}

voteTracker.loadState()
}

// TODO: Remove hacky fix.
Expand Down Expand Up @@ -155,6 +158,7 @@ open class MainActivityFOC : AppCompatActivity() {
override fun onPause() {
super.onPause()
appGossiper?.pause()
voteTracker.storeState()
}

private fun showAllFiles() {
Expand Down
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)
}
}
}
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")
}
}

0 comments on commit 4a3bc15

Please sign in to comment.