From 8dccf8a5ba5c797e03b220a8cb308f6a69277155 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Wed, 29 Jul 2020 13:58:56 +0530 Subject: [PATCH 1/2] Updated to AndroidX --- app/build.gradle | 38 ++++----- .../socketio/androidchat/LoginActivity.java | 4 +- .../socketio/androidchat/MainActivity.java | 2 +- .../socketio/androidchat/MainFragment.java | 7 +- .../socketio/androidchat/MessageAdapter.java | 20 ++--- app/src/main/res/layout/fragment_main.xml | 74 +++++++++--------- build.gradle | 12 ++- gradle.properties | 2 + gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 78 ++++++++++--------- 10 files changed, 132 insertions(+), 109 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c6c1e10..6fc9409 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,37 +1,39 @@ apply plugin: 'com.android.application' - - android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 29 + buildToolsVersion "29.0.3" + defaultConfig { applicationId 'com.github.nkzawa.socketio.androidchat' - minSdkVersion 17 - targetSdkVersion 25 + minSdkVersion 21 + targetSdkVersion 29 versionCode 1 versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } - productFlavors { - } + } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.0.+' - compile 'com.android.support:recyclerview-v7:25.0.+' - compile ('io.socket:socket.io-client:0.8.3') { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.2.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + implementation ('io.socket:socket.io-client:1.0.0') { exclude group: 'org.json', module: 'json' } - - androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { - exclude group: 'com.android.support', module: 'support-annotations' - }) - testCompile 'junit:junit:4.12' + implementation 'androidx.recyclerview:recyclerview:1.1.0' } diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java index e3477c1..1edfa2d 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java @@ -1,6 +1,5 @@ package com.github.nkzawa.socketio.androidchat; -import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; @@ -11,6 +10,7 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; +import androidx.appcompat.app.AppCompatActivity; import io.socket.client.Socket; import io.socket.emitter.Emitter; import org.json.JSONException; @@ -20,7 +20,7 @@ /** * A login screen that offers login via username. */ -public class LoginActivity extends Activity { +public class LoginActivity extends AppCompatActivity { private EditText mUsernameView; diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java index a5e010c..3b90140 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainActivity.java @@ -1,7 +1,7 @@ package com.github.nkzawa.socketio.androidchat; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java index 4060468..7844657 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java @@ -5,9 +5,6 @@ import android.content.Intent; import android.os.Bundle; import android.os.Handler; -import android.support.v4.app.Fragment; -import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; @@ -25,6 +22,10 @@ import android.widget.TextView; import android.widget.Toast; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + import org.json.JSONException; import org.json.JSONObject; diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MessageAdapter.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MessageAdapter.java index 7521a39..8ba1b8b 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MessageAdapter.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MessageAdapter.java @@ -1,11 +1,11 @@ package com.github.nkzawa.socketio.androidchat; import android.content.Context; -import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; +import androidx.recyclerview.widget.RecyclerView; import java.util.List; @@ -24,15 +24,15 @@ public MessageAdapter(Context context, List messages) { public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { int layout = -1; switch (viewType) { - case Message.TYPE_MESSAGE: - layout = R.layout.item_message; - break; - case Message.TYPE_LOG: - layout = R.layout.item_log; - break; - case Message.TYPE_ACTION: - layout = R.layout.item_action; - break; + case Message.TYPE_MESSAGE: + layout = R.layout.item_message; + break; + case Message.TYPE_LOG: + layout = R.layout.item_log; + break; + case Message.TYPE_ACTION: + layout = R.layout.item_action; + break; } View v = LayoutInflater .from(parent.getContext()) diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml index c582a20..1761bbe 100644 --- a/app/src/main/res/layout/fragment_main.xml +++ b/app/src/main/res/layout/fragment_main.xml @@ -1,46 +1,46 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + tools:context=".MainFragment"> - + + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:paddingLeft="@dimen/activity_horizontal_margin" + android:paddingRight="@dimen/activity_horizontal_margin" + android:orientation="horizontal" + android:gravity="center_vertical"> + android:id="@+id/message_input" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:hint="@string/prompt_message" + android:imeActionId="@+id/send" + android:imeActionLabel="@string/action_send" + android:imeOptions="actionSend" + android:inputType="text" + android:maxLines="1" + android:singleLine="true"/> + android:id="@+id/send_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:src="@android:drawable/ic_menu_send" + android:contentDescription="@string/action_send"/> diff --git a/build.gradle b/build.gradle index 16f9930..1115535 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,15 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { + ext.kotlin_version = '1.3.71' repositories { + google() jcenter() + } dependencies { - classpath 'com.android.tools.build:gradle:2.3.0-beta4' + classpath 'com.android.tools.build:gradle:3.6.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 @@ -14,6 +18,12 @@ buildscript { allprojects { repositories { + google() jcenter() + } } + +task clean(type: Delete) { + delete rootProject.buildDir +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4e7c65d..081bb0a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,8 @@ # The setting is particularly useful for tweaking memory settings. # Default value: -Xmx10248m -XX:MaxPermSize=256m # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 +android.enableJetifier=true +android.useAndroidX=true org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2a61779..6771692 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Feb 20 09:34:25 PST 2017 +#Wed Jul 29 10:58:46 IST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip diff --git a/gradlew b/gradlew index 91a7e26..cccdd3d 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" From c75b5572c7e26443a70a8917cdf79d49ae127dfe Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 17 Aug 2020 22:56:47 +0530 Subject: [PATCH 2/2] Updated to AndroidX --- app/build.gradle | 2 +- .../github/nkzawa/socketio/androidchat/ChatApplication.java | 5 +++-- .../github/nkzawa/socketio/androidchat/LoginActivity.java | 4 ++-- .../github/nkzawa/socketio/androidchat/MainFragment.java | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 6fc9409..8acf445 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -32,7 +32,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' - implementation ('io.socket:socket.io-client:1.0.0') { + implementation ('io.socket:socket.io-client:0.8.3') { exclude group: 'org.json', module: 'json' } implementation 'androidx.recyclerview:recyclerview:1.1.0' diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/ChatApplication.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/ChatApplication.java index ea62589..2230e8e 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/ChatApplication.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/ChatApplication.java @@ -1,10 +1,10 @@ package com.github.nkzawa.socketio.androidchat; import android.app.Application; + import io.socket.client.IO; import io.socket.client.Socket; -import java.net.URISyntaxException; public class ChatApplication extends Application { @@ -12,7 +12,8 @@ public class ChatApplication extends Application { { try { mSocket = IO.socket(Constants.CHAT_SERVER_URL); - } catch (URISyntaxException e) { + } catch (Exception e) { + e.printStackTrace(); throw new RuntimeException(e); } } diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java index 1edfa2d..e3477c1 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/LoginActivity.java @@ -1,5 +1,6 @@ package com.github.nkzawa.socketio.androidchat; +import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.text.TextUtils; @@ -10,7 +11,6 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; -import androidx.appcompat.app.AppCompatActivity; import io.socket.client.Socket; import io.socket.emitter.Emitter; import org.json.JSONException; @@ -20,7 +20,7 @@ /** * A login screen that offers login via username. */ -public class LoginActivity extends AppCompatActivity { +public class LoginActivity extends Activity { private EditText mUsernameView; diff --git a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java index 7844657..f46c2fe 100644 --- a/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java +++ b/app/src/main/java/com/github/nkzawa/socketio/androidchat/MainFragment.java @@ -70,7 +70,7 @@ public MainFragment() { public void onAttach(Context context) { super.onAttach(context); mAdapter = new MessageAdapter(context, mMessages); - if (context instanceof Activity){ + if (context instanceof Activity) { //this.listener = (MainActivity) context; } } @@ -84,8 +84,8 @@ public void onCreate(Bundle savedInstanceState) { ChatApplication app = (ChatApplication) getActivity().getApplication(); mSocket = app.getSocket(); - mSocket.on(Socket.EVENT_CONNECT,onConnect); - mSocket.on(Socket.EVENT_DISCONNECT,onDisconnect); + mSocket.on(Socket.EVENT_CONNECT, onConnect); + mSocket.on(Socket.EVENT_DISCONNECT, onDisconnect); mSocket.on(Socket.EVENT_CONNECT_ERROR, onConnectError); mSocket.on(Socket.EVENT_CONNECT_TIMEOUT, onConnectError); mSocket.on("new message", onNewMessage);