Skip to content

Commit

Permalink
Refactor sample. Change obsolete APIs, make jetpack friendly, update …
Browse files Browse the repository at this point in the history
…files
  • Loading branch information
isaidamier committed May 19, 2021
1 parent 09b1be3 commit d403693
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 34 deletions.
4 changes: 2 additions & 2 deletions BluetoothLeChat/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.fragment:fragment-ktx:1.3.3'
implementation 'androidx.activity:activity-ktx:1.3.0-alpha07'
implementation 'androidx.fragment:fragment-ktx:1.3.4'
implementation 'androidx.activity:activity-ktx:1.3.0-alpha08'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:Suppress("ObjectPropertyName")

package com.example.bluetoothlechat.bluetooth

import android.app.Application
Expand Down Expand Up @@ -305,7 +307,7 @@ object ChatServer {
super.onStartFailure(errorCode)
// Send error state to display
val errorMessage = "Advertise failed with error: $errorCode"
Log.d(TAG, "Advertising failed")
Log.d(TAG, errorMessage)
//_viewState.value = DeviceScanViewState.Error(errorMessage)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:id="@+id/connect_devices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="@dimen/std_margin"
android:text="@string/connect_device_prompt" />
</LinearLayout>

Expand All @@ -50,8 +50,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="16dp"
android:textSize="18sp" />
android:padding="@dimen/std_margin"
android:textSize="@dimen/txt_size_18" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/messages"
Expand All @@ -61,8 +61,11 @@

<EditText
android:id="@+id/message_text"
android:inputType="text"
android:hint="@string/enter_message"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:importantForAutofill="no" />

<Button
android:id="@+id/send_message"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingTop="16dp"
android:paddingTop="@dimen/std_margin"
android:text="@string/active_scan_message"
android:textSize="18sp" />
android:textSize="@dimen/txt_size_18" />
</LinearLayout>

<androidx.recyclerview.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
android:id="@+id/location_error_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="@dimen/std_margin"
android:layout_marginEnd="@dimen/std_margin"
android:text="@string/location_required_error"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand All @@ -35,7 +35,7 @@
android:id="@+id/grant_permission_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="@dimen/std_margin"
android:text="@string/grant_permission_prompt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
14 changes: 7 additions & 7 deletions BluetoothLeChat/app/src/main/res/layout/item_device.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
android:id="@+id/device_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="@dimen/std_margin"
android:layout_marginTop="@dimen/std_margin"
android:layout_marginEnd="@dimen/std_margin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -34,10 +34,10 @@
android:id="@+id/device_address"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:layout_marginStart="@dimen/std_margin"
android:layout_marginTop="@dimen/std_margin"
android:layout_marginEnd="@dimen/std_margin"
android:layout_marginBottom="@dimen/std_margin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
android:id="@+id/message_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="@dimen/std_margin"
android:layout_marginTop="@dimen/std_margin_half"
android:layout_marginEnd="@dimen/std_margin"
android:layout_marginBottom="@dimen/std_margin_half"
android:background="@color/local_message_background"
android:padding="8dp"
android:textColor="#000000"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
android:id="@+id/message_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="@dimen/std_margin"
android:layout_marginTop="@dimen/std_margin_half"
android:layout_marginEnd="@dimen/std_margin"
android:layout_marginBottom="@dimen/std_margin_half"
android:background="@color/remote_message_background"
android:padding="8dp"
android:textColor="#ffffff"
Expand Down
6 changes: 6 additions & 0 deletions BluetoothLeChat/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="std_margin">16dp</dimen>
<dimen name="txt_size_18">18sp</dimen>
<dimen name="std_margin_half">8dp</dimen>
</resources>
1 change: 1 addition & 0 deletions BluetoothLeChat/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
<string name="connect_device_prompt">Connect with nearby devices</string>
<string name="send_message_button">Send Message</string>
<string name="chatting_with_device">Chatting with %1$s</string>
<string name="enter_message">enter message</string>
</resources>
8 changes: 4 additions & 4 deletions BluetoothLeChat/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
ext.kotlin_version = "1.5.0"
repositories {
google()
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:4.2.0'
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 All @@ -31,7 +31,7 @@ buildscript {
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}

Expand Down
6 changes: 3 additions & 3 deletions BluetoothLeChat/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Sep 03 12:48:38 EDT 2020
#Wed May 19 13:24:30 EDT 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME

0 comments on commit d403693

Please sign in to comment.