diff --git a/ChatExample/app/build.gradle b/ChatExample/app/build.gradle index 18dd1a7..6ddf2db 100644 --- a/ChatExample/app/build.gradle +++ b/ChatExample/app/build.gradle @@ -1,15 +1,12 @@ apply plugin: 'com.android.application' - apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' - android { - compileSdkVersion 30 + compileSdkVersion 33 defaultConfig { applicationId "com.github.dsrees.chatexample" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 33 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -21,6 +18,10 @@ android { } } + buildFeatures { + viewBinding true + } + compileOptions { targetCompatibility = "8" sourceCompatibility = "8" @@ -40,14 +41,10 @@ dependencies { // implementation 'com.github.dsrees:JavaPhoenixClient:0.3.4' - implementation "com.google.code.gson:gson:2.8.5" - implementation "com.squareup.okhttp3:okhttp:3.12.2" - - - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" - - implementation 'androidx.appcompat:appcompat:1.0.2' - implementation 'androidx.recyclerview:recyclerview:1.0.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation "com.google.code.gson:gson:2.10.1" + implementation "com.squareup.okhttp3:okhttp:4.11.0" + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'androidx.recyclerview:recyclerview:1.3.1' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' } diff --git a/ChatExample/app/libs/JavaPhoenixClient-0.7.0.jar b/ChatExample/app/libs/JavaPhoenixClient-0.7.0.jar deleted file mode 100644 index 6dbc437..0000000 Binary files a/ChatExample/app/libs/JavaPhoenixClient-0.7.0.jar and /dev/null differ diff --git a/ChatExample/app/libs/JavaPhoenixClient-1.1.5.jar b/ChatExample/app/libs/JavaPhoenixClient-1.1.5.jar new file mode 100644 index 0000000..dae2106 Binary files /dev/null and b/ChatExample/app/libs/JavaPhoenixClient-1.1.5.jar differ diff --git a/ChatExample/app/src/main/AndroidManifest.xml b/ChatExample/app/src/main/AndroidManifest.xml index 15f50d6..5ed4835 100644 --- a/ChatExample/app/src/main/AndroidManifest.xml +++ b/ChatExample/app/src/main/AndroidManifest.xml @@ -14,7 +14,9 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" tools:ignore="GoogleAppIndexingWarning"> - + diff --git a/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MainActivity.kt b/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MainActivity.kt index 6e225dd..9a4caa5 100644 --- a/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MainActivity.kt +++ b/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MainActivity.kt @@ -3,11 +3,8 @@ package com.github.dsrees.chatexample import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log -import android.widget.ArrayAdapter -import android.widget.Button -import android.widget.EditText import androidx.recyclerview.widget.LinearLayoutManager -import kotlinx.android.synthetic.main.activity_main.* +import com.github.dsrees.chatexample.databinding.ActivityMainBinding import org.phoenixframework.Channel import org.phoenixframework.Socket @@ -17,44 +14,47 @@ class MainActivity : AppCompatActivity() { const val TAG = "MainActivity" } + private lateinit var binding: ActivityMainBinding + private val messagesAdapter = MessagesAdapter() private val layoutManager = LinearLayoutManager(this) // Use when connecting to https://github.com/dwyl/phoenix-chat-example - // private val socket = Socket("https://phxchat.herokuapp.com/socket/websocket") - // private val topic = "room:lobby" + private val socket = Socket("https://phoenix-chat.fly.dev/socket/websocket") + private val topic = "room:lobby" // Use when connecting to local server - private val socket = Socket("ws://10.0.2.2:4000/socket/websocket") - private val topic = "rooms:lobby" + // private val socket = Socket("ws://10.0.2.2:4000/socket/websocket") + // private val topic = "rooms:lobby" private var lobbyChannel: Channel? = null private val username: String - get() = username_input.text.toString() + get() = binding.usernameInput.text.toString() private val message: String - get() = message_input.text.toString() + get() = binding.messageInput.text.toString() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) + this.binding = ActivityMainBinding.inflate(layoutInflater) + setContentView(binding.root) layoutManager.stackFromEnd = true - messages_recycler_view.layoutManager = layoutManager - messages_recycler_view.adapter = messagesAdapter + binding.messagesRecyclerView.layoutManager = layoutManager + binding.messagesRecyclerView.adapter = messagesAdapter socket.onOpen { this.addText("Socket Opened") - runOnUiThread { connect_button.text = "Disconnect" } + runOnUiThread { binding.connectButton.text = "Disconnect" } } socket.onClose { this.addText("Socket Closed") - runOnUiThread { connect_button.text = "Connect" } + runOnUiThread { binding.connectButton.text = "Connect" } } socket.onError { throwable, response -> @@ -67,7 +67,7 @@ class MainActivity : AppCompatActivity() { } - connect_button.setOnClickListener { + binding.connectButton.setOnClickListener { if (socket.isConnected) { this.disconnectAndLeave() } else { @@ -76,7 +76,7 @@ class MainActivity : AppCompatActivity() { } } - send_button.setOnClickListener { sendMessage() } + binding.sendButton.setOnClickListener { sendMessage() } } private fun sendMessage() { @@ -85,7 +85,7 @@ class MainActivity : AppCompatActivity() { ?.receive("ok") { Log.d(TAG, "success $it") } ?.receive("error") { Log.d(TAG, "error $it") } - message_input.text.clear() + binding.messageInput.text.clear() } private fun disconnectAndLeave() { @@ -132,9 +132,7 @@ class MainActivity : AppCompatActivity() { private fun addText(message: String) { runOnUiThread { this.messagesAdapter.add(message) - layoutManager.smoothScrollToPosition(messages_recycler_view, null, messagesAdapter.itemCount) + layoutManager.smoothScrollToPosition(binding.messagesRecyclerView, null, messagesAdapter.itemCount) } - } - } diff --git a/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MessagesAdapter.kt b/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MessagesAdapter.kt index e99b294..143df58 100644 --- a/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MessagesAdapter.kt +++ b/ChatExample/app/src/main/java/com/github/dsrees/chatexample/MessagesAdapter.kt @@ -5,6 +5,7 @@ import android.view.View import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView +import com.github.dsrees.chatexample.databinding.ItemMessageBinding class MessagesAdapter : RecyclerView.Adapter() { @@ -17,8 +18,8 @@ class MessagesAdapter : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { - val view = LayoutInflater.from(parent.context).inflate(R.layout.item_message, parent, false) - return ViewHolder(view) + val binding = ItemMessageBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return ViewHolder(binding) } override fun getItemCount(): Int = messages.size @@ -27,8 +28,8 @@ class MessagesAdapter : RecyclerView.Adapter() { holder.label.text = messages[position] } - inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val label: TextView = itemView.findViewById(R.id.item_message_label) + inner class ViewHolder(binding: ItemMessageBinding) : RecyclerView.ViewHolder(binding.root) { + val label: TextView = binding.itemMessageLabel } } \ No newline at end of file diff --git a/ChatExample/build.gradle b/ChatExample/build.gradle index 5ff4b70..08b070b 100644 --- a/ChatExample/build.gradle +++ b/ChatExample/build.gradle @@ -1,17 +1,15 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.8.0' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.4.1' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } diff --git a/ChatExample/gradle/wrapper/gradle-wrapper.properties b/ChatExample/gradle/wrapper/gradle-wrapper.properties index 3c4d55d..5fa6080 100644 --- a/ChatExample/gradle/wrapper/gradle-wrapper.properties +++ b/ChatExample/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue May 14 11:28:07 EDT 2019 +#Wed Oct 04 12:35:15 EDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/build.gradle b/build.gradle index 41118db..56ef6e9 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { plugins { id 'java' id 'jacoco' - id 'org.jetbrains.kotlin.jvm' version '1.3.31' + id 'org.jetbrains.kotlin.jvm' version '1.8.0' } ext { @@ -47,16 +47,16 @@ test { } dependencies { - compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - compile "com.google.code.gson:gson:2.8.5" - compile "com.squareup.okhttp3:okhttp:3.12.2" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" + implementation "com.google.code.gson:gson:2.10.1" + implementation "com.squareup.okhttp3:okhttp:4.11.0" testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1' - testCompile group: 'com.google.truth', name: 'truth', version: '1.1.3' - testCompile group: 'org.mockito', name: 'mockito-core', version: '4.0.0' - testCompile group: 'org.mockito.kotlin', name: 'mockito-kotlin', version: '4.0.0' + testImplementation group: 'com.google.truth', name: 'truth', version: '1.1.3' + testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.0.0' + testImplementation group: 'org.mockito.kotlin', name: 'mockito-kotlin', version: '4.0.0' } jacocoTestReport { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d663d77..aa98239 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Mar 18 20:34:38 EDT 2021 +#Wed Oct 04 12:21:20 EDT 2023 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip diff --git a/src/main/kotlin/org/phoenixframework/Defaults.kt b/src/main/kotlin/org/phoenixframework/Defaults.kt index e1b1aa8..5c43d3e 100644 --- a/src/main/kotlin/org/phoenixframework/Defaults.kt +++ b/src/main/kotlin/org/phoenixframework/Defaults.kt @@ -29,6 +29,7 @@ import com.google.gson.JsonObject import com.google.gson.JsonParser import com.google.gson.reflect.TypeToken import okhttp3.HttpUrl +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import org.phoenixframework.Defaults.gson import java.net.URL import javax.swing.text.html.HTML.Tag.P @@ -149,7 +150,7 @@ object Defaults { } // Add the VSN query parameter - var httpUrl = HttpUrl.parse(mutableUrl) + var httpUrl = mutableUrl.toHttpUrlOrNull() ?: throw IllegalArgumentException("invalid url: $endpoint") val httpBuilder = httpUrl.newBuilder() httpBuilder.addQueryParameter("vsn", vsn) @@ -162,6 +163,6 @@ object Defaults { } // Return the [URL] that will be used to establish a connection - return httpBuilder.build().url() + return httpBuilder.build().toUrl() } } \ No newline at end of file