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

Update Dependencies #98

Merged
merged 1 commit into from
Oct 4, 2023
Merged
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
25 changes: 11 additions & 14 deletions ChatExample/app/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -21,6 +18,10 @@ android {
}
}

buildFeatures {
viewBinding true
}

compileOptions {
targetCompatibility = "8"
sourceCompatibility = "8"
Expand All @@ -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'
}
Binary file removed ChatExample/app/libs/JavaPhoenixClient-0.7.0.jar
Binary file not shown.
Binary file added ChatExample/app/libs/JavaPhoenixClient-1.1.5.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion ChatExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 ->
Expand All @@ -67,7 +67,7 @@ class MainActivity : AppCompatActivity() {
}


connect_button.setOnClickListener {
binding.connectButton.setOnClickListener {
if (socket.isConnected) {
this.disconnectAndLeave()
} else {
Expand All @@ -76,7 +76,7 @@ class MainActivity : AppCompatActivity() {
}
}

send_button.setOnClickListener { sendMessage() }
binding.sendButton.setOnClickListener { sendMessage() }
}

private fun sendMessage() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MessagesAdapter.ViewHolder>() {

Expand All @@ -17,8 +18,8 @@ class MessagesAdapter : RecyclerView.Adapter<MessagesAdapter.ViewHolder>() {


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
Expand All @@ -27,8 +28,8 @@ class MessagesAdapter : RecyclerView.Adapter<MessagesAdapter.ViewHolder>() {
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
}

}
6 changes: 2 additions & 4 deletions ChatExample/build.gradle
Original file line number Diff line number Diff line change
@@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions ChatExample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
5 changes: 3 additions & 2 deletions src/main/kotlin/org/phoenixframework/Defaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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()
}
}