Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ insert_final_newline = true
end_of_line = lf

# ktlint
disabled_rules=no-wildcard-imports,import-ordering,max-line-length
[*.{kt,kts}]
ktlint_no-wildcard-imports = disabled
33 changes: 19 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.7.10'
ext.ktlint_version = '0.44.0'
ext.kotlin_version = '1.8.10'
ext.ktlint_version = '0.48.2'
ext.coroutines_version = '1.6.4'
ext.ktlint_gradle_version = '11.0.0'
// https://github.com/cashapp/sqldelight/issues/1574
ext.sqldelight_version = '1.5.2'
ext.ktlint_gradle_version = '11.3.1'
ext.sqldelight_version = '1.5.5'
ext.nav_version = "2.5.3"
ext.fragment_version = "1.5.4"
ext.lifecycle_version = "2.5.1"
ext.dokka_version = "0.10.1"
ext.fragment_version = "1.5.5"
ext.lifecycle_version = "2.6.0"
ext.dokka_version = "1.8.10"
repositories {
google()
mavenCentral()
Expand All @@ -23,34 +24,38 @@ buildscript {
classpath "org.jlleitschuh.gradle:ktlint-gradle:$ktlint_gradle_version"
classpath "com.squareup.sqldelight:gradle-plugin:$sqldelight_version"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

plugins {
id("org.jetbrains.dokka") version "$dokka_version"
}

allprojects {

repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}

// Temp fix for issue https://github.com/mockk/mockk/issues/281
configurations.all {
configurations.configureEach {
resolutionStrategy {
force("org.objenesis:objenesis:2.6")
}
}
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
tasks.withType(KotlinCompile).configureEach {
kotlinOptions.freeCompilerArgs += [
"-opt-in=kotlin.Experimental,kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.RequiresOptIn"
"-opt-in=kotlin.ExperimentalUnsignedTypes,kotlin.RequiresOptIn",
]
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
}
45 changes: 21 additions & 24 deletions demo-android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdkVersion 33
compileSdk 33

defaultConfig {
applicationId "nl.tudelft.ipv8.demo"
Expand All @@ -22,16 +25,10 @@ android {
}
}

// To inline the bytecode built with JVM target 1.8 into
// bytecode that is being built with JVM target 1.6. (e.g. navArgs)
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_11.toString()
allWarningsAsErrors = true
}

viewBinding {
enabled = true
Expand All @@ -53,24 +50,23 @@ dependencies {
implementation project(':ipv8-android')

// AndroidX
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.recyclerview:recyclerview:1.1.0"
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "androidx.recyclerview:recyclerview:1.3.0"
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.fragment:fragment-ktx:$fragment_version"
implementation "androidx.preference:preference:1.1.0"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
implementation "androidx.preference:preference-ktx:1.2.0"
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"

// Material
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.google.android.material:material:1.8.0'

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
Expand All @@ -79,17 +75,18 @@ dependencies {
implementation 'io.github.microutils:kotlin-logging:1.7.7'
implementation 'com.github.tony19:logback-android:2.0.0'

implementation 'com.github.MattSkala:recyclerview-itemadapter:0.4'
implementation 'com.github.MattSkala:recyclerview-itemadapter:0.5'

// Testing
testImplementation 'junit:junit:4.12'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
tasks.withType(KotlinCompile).configureEach {
kotlinOptions.freeCompilerArgs += [
"-opt-in=kotlin.Experimental,kotlin.ExperimentalUnsignedTypes",
"-opt-in=kotlin.RequiresOptIn"
"-opt-in=kotlin.ExperimentalUnsignedTypes,kotlin.RequiresOptIn",
]
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
kotlinOptions.allWarningsAsErrors = true
}
1 change: 1 addition & 0 deletions demo-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<application
android:name="nl.tudelft.trustchain.demo.DemoApplication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@ import android.widget.LinearLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import com.mattskala.itemadapter.ItemAdapter
import kotlinx.android.synthetic.main.fragment_peers.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import nl.tudelft.ipv8.android.IPv8Android
import nl.tudelft.trustchain.demo.DemoCommunity
import nl.tudelft.trustchain.demo.R
import nl.tudelft.trustchain.demo.databinding.FragmentPeersBinding
import nl.tudelft.trustchain.demo.ui.peers.AddressItem
import nl.tudelft.trustchain.demo.ui.peers.AddressItemRenderer
import nl.tudelft.trustchain.demo.ui.peers.PeerItem
import nl.tudelft.trustchain.demo.ui.peers.PeerItemRenderer

class DemoActivity : AppCompatActivity() {
private val adapter = ItemAdapter()
private lateinit var binding: FragmentPeersBinding


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.fragment_peers)
binding = FragmentPeersBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)

adapter.registerRenderer(PeerItemRenderer {
// NOOP
Expand All @@ -36,60 +43,62 @@ class DemoActivity : AppCompatActivity() {
// NOOP
})

recyclerView.adapter = adapter
recyclerView.layoutManager = LinearLayoutManager(this)
recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))
binding.recyclerView.adapter = adapter
binding.recyclerView.layoutManager = LinearLayoutManager(this)
binding.recyclerView.addItemDecoration(DividerItemDecoration(this, LinearLayout.VERTICAL))

loadNetworkInfo()
}

private fun loadNetworkInfo() {
lifecycleScope.launchWhenStarted {
while (isActive) {
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()

val discoveredAddresses = demoCommunity.network
.getWalkableAddresses(demoCommunity.serviceId)

val discoveredBluetoothAddresses = demoCommunity.network
.getNewBluetoothPeerCandidates()
.map { it.address }

val peerItems = peers.map {
PeerItem(
it
)
}

val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address,
null,
contacted
)
}

val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address,
null,
null
)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
while (isActive) {
val demoCommunity = IPv8Android.getInstance().getOverlay<DemoCommunity>()!!
val peers = demoCommunity.getPeers()

val discoveredAddresses = demoCommunity.network
.getWalkableAddresses(demoCommunity.serviceId)

val discoveredBluetoothAddresses = demoCommunity.network
.getNewBluetoothPeerCandidates()
.map { it.address }

val peerItems = peers.map {
PeerItem(
it
)
}

val addressItems = discoveredAddresses.map { address ->
val contacted = demoCommunity.discoveredAddressesContacted[address]
AddressItem(
address,
null,
contacted
)
}

val bluetoothAddressItems = discoveredBluetoothAddresses.map { address ->
AddressItem(
address,
null,
null
)
}

val items = peerItems + bluetoothAddressItems + addressItems

adapter.updateItems(items)
binding.txtCommunityName.text = demoCommunity.javaClass.simpleName
binding.txtPeerCount.text = getString(R.string.peers, peers.size)
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
binding.txtPeerCount.setTextColor(textColor)
binding.imgEmpty.isVisible = items.isEmpty()

delay(1000)
}

val items = peerItems + bluetoothAddressItems + addressItems

adapter.updateItems(items)
txtCommunityName.text = demoCommunity.javaClass.simpleName
txtPeerCount.text = "${peers.size} peers"
val textColorResId = if (peers.isNotEmpty()) R.color.green else R.color.red
val textColor = ResourcesCompat.getColor(resources, textColorResId, null)
txtPeerCount.setTextColor(textColor)
imgEmpty.isVisible = items.isEmpty()

delay(1000)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
package nl.tudelft.trustchain.demo.ui.peers

import android.annotation.SuppressLint
import android.view.View
import androidx.core.view.isVisible
import com.mattskala.itemadapter.ItemLayoutRenderer
import kotlinx.android.synthetic.main.item_peer.view.*
import nl.tudelft.trustchain.demo.R
import com.mattskala.itemadapter.BindingItemRenderer
import nl.tudelft.trustchain.demo.databinding.ItemPeerBinding
import java.util.*
import kotlin.math.roundToInt

class AddressItemRenderer(
private val onItemClick: (AddressItem) -> Unit
) : ItemLayoutRenderer<AddressItem, View>(
AddressItem::class.java) {
@SuppressLint("SetTextI18n")
override fun bindView(item: AddressItem, view: View) = with(view) {
txtPeerId.text = "?"
txtAddress.text = item.address.toString()
) : BindingItemRenderer<AddressItem, ItemPeerBinding>(
AddressItem::class.java,
ItemPeerBinding::inflate
) {
override fun bindView(item: AddressItem, binding: ItemPeerBinding) {
binding.txtPeerId.text = "?"
binding.txtAddress.text = item.address.toString()
val lastRequest = item.contacted
val lastResponse = item.discovered
txtBluetoothAddress.isVisible = false
binding.txtBluetoothAddress.isVisible = false

txtLastSent.text = if (lastRequest != null)
binding.txtLastSent.text = if (lastRequest != null)
"" + ((Date().time - lastRequest.time) / 1000.0).roundToInt() + " s" else "?"

txtLastReceived.text = if (lastResponse != null)
binding.txtLastReceived.text = if (lastResponse != null)
"" + ((Date().time - lastResponse.time) / 1000.0).roundToInt() + " s" else "?"

txtAvgPing.text = "? ms"
binding.txtAvgPing.text = "? ms"

setOnClickListener {
binding.root.setOnClickListener {
onItemClick(item)
}
}

override fun getLayoutResourceId(): Int {
return R.layout.item_peer
}
}
Loading