Skip to content

Commit

Permalink
#84 Project maintenance (#87)
Browse files Browse the repository at this point in the history
AGP 8.0.0
Kotlin 1.8.10
Java 17
JVM 17
  • Loading branch information
zello-eugene authored May 2, 2023
1 parent 12b772c commit 128201b
Show file tree
Hide file tree
Showing 38 changed files with 580 additions and 628 deletions.
15 changes: 10 additions & 5 deletions zello-sdk-sample-contacts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath "com.android.tools.build:gradle:7.2.2"
classpath "com.android.tools.build:gradle:8.0.0"
}
}

Expand All @@ -18,13 +18,18 @@ apply plugin: "com.android.application"

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(17))
}
}

android {
compileSdkVersion 33
buildToolsVersion "33.0.0"
namespace "com.zello.sdk.sample.contacts"

buildFeatures {
buildConfig true
}

defaultConfig {
applicationId "com.zello.sdk.sample.contacts"
Expand All @@ -42,12 +47,12 @@ android {
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
}

dependencies {
implementation files("libs/zello-sdk.aar")
implementation "androidx.appcompat:appcompat:1.5.0"
implementation "androidx.appcompat:appcompat:1.6.1"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Nov 18 16:18:15 CST 2020
#Mon May 01 15:52:58 CDT 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
Binary file modified zello-sdk-sample-contacts/libs/zello-sdk.aar
Binary file not shown.
5 changes: 1 addition & 4 deletions zello-sdk-sample-contacts/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.zello.sdk.sample.contacts">
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="false"
android:fullBackupContent="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
package com.zello.sdk.sample.contacts;

import android.os.Parcelable;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.zello.sdk.AppState;
import com.zello.sdk.BluetoothAccessoryState;
import com.zello.sdk.BluetoothAccessoryType;
import com.zello.sdk.Tab;
import com.zello.sdk.Zello;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class ContactsActivity extends AppCompatActivity implements com.zello.sdk.Events {

private ListView _contactsListView;
private TextView _statusTextView;
private TextView _selectedContactTextView;

private com.zello.sdk.AppState _appState = new com.zello.sdk.AppState();
private final AppState _appState = new AppState();

//region Lifecycle Methods

Expand All @@ -36,22 +38,21 @@ protected void onCreate(Bundle savedInstanceState) {
_statusTextView = findViewById(R.id.statusTextView);
_selectedContactTextView = findViewById(R.id.selectedContactTextView);

Zello zello = Zello.getInstance();
// Automatically choose the app to connect to in the following order of preference: com.loudtalks, net.loudtalks, com.pttsdk
// Alternatively, connect to a preferred app by supplying a package name, for example: Zello.getInstance().configure("net.loudtalks", this)
Zello.getInstance().configure(this);
zello.configure(this);
zello.subscribeToEvents(this);

// Contact list pick handler
_contactsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ListAdapter adapter = (ListAdapter) _contactsListView.getAdapter();
if (adapter == null) {
return;
}
com.zello.sdk.Contact contact = (com.zello.sdk.Contact) adapter.getItem(position);
if (contact != null) {
Zello.getInstance().setSelectedContact(contact);
}
_contactsListView.setOnItemClickListener((parent, view, position, id) -> {
ListAdapter adapter = (ListAdapter) _contactsListView.getAdapter();
if (adapter == null) {
return;
}
com.zello.sdk.Contact contact = (com.zello.sdk.Contact) adapter.getItem(position);
if (contact != null) {
Zello.getInstance().setSelectedContact(contact);
}
});

Expand All @@ -61,8 +62,9 @@ public void onItemClick(AdapterView<?> parent, View view, int position, long id)
@Override
protected void onDestroy() {
super.onDestroy();
Zello.getInstance().unsubscribeFromEvents(this);
Zello.getInstance().unconfigure();
Zello zello = Zello.getInstance();
zello.unsubscribeFromEvents(this);
zello.unconfigure();
}

@Override
Expand Down Expand Up @@ -90,26 +92,24 @@ public boolean onPrepareOptionsMenu(Menu menu) {
return true;
}

@SuppressWarnings("SwitchStatementWithTooFewBranches")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_select_contact: {
// Activity title; optional
String title = getString(R.string.select_contact_title);
// Set of displayed tabs; required; any combination of RECENTS, USERS and CHANNELS
com.zello.sdk.Tab[] tabs = new com.zello.sdk.Tab[]{com.zello.sdk.Tab.RECENTS, com.zello.sdk.Tab.USERS, com.zello.sdk.Tab.CHANNELS};
// Initially active tab; optional; can be RECENTS, USERS or CHANNELS
com.zello.sdk.Tab tab = Tab.RECENTS;
// Visual theme; optional; can be DARK or LIGHT
com.zello.sdk.Theme theme = com.zello.sdk.Theme.DARK;

// Since Zello was initialized in the Activity, pass in this as Activity parameter
Zello.getInstance().selectContact(title, tabs, tab, theme, this);
break;
}
int id = item.getItemId();
if (id == R.id.menu_select_contact) {
// Activity title; optional
String title = getString(R.string.select_contact_title);
// Set of displayed tabs; required; any combination of RECENTS, USERS and CHANNELS
com.zello.sdk.Tab[] tabs = new com.zello.sdk.Tab[]{com.zello.sdk.Tab.RECENTS, com.zello.sdk.Tab.USERS, com.zello.sdk.Tab.CHANNELS};
// Initially active tab; optional; can be RECENTS, USERS or CHANNELS
com.zello.sdk.Tab tab = Tab.RECENTS;
// Visual theme; optional; can be DARK or LIGHT
com.zello.sdk.Theme theme = com.zello.sdk.Theme.DARK;

// Since Zello was initialized in the Activity, pass in this as Activity parameter
Zello.getInstance().selectContact(title, tabs, tab, theme, this);
return true;
}
return true;
return super.onOptionsItemSelected(item);
}

//endregion
Expand Down Expand Up @@ -161,7 +161,7 @@ public void onContactsChanged() {
}

@Override
public void onLastContactsTabChanged(Tab tab) {
public void onLastContactsTabChanged(@NonNull Tab tab) {
}

@Override
Expand Down Expand Up @@ -192,7 +192,12 @@ public void onMicrophonePermissionNotGranted() {
}

@Override
public void onBluetoothAccessoryStateChanged(BluetoothAccessoryType bluetoothAccessoryType, BluetoothAccessoryState bluetoothAccessoryState, String s, String s1) {
public void onBluetoothAccessoryStateChanged(
@NonNull BluetoothAccessoryType bluetoothAccessoryType,
@NonNull BluetoothAccessoryState bluetoothAccessoryState,
@Nullable String name,
@Nullable String description
) {
}

//endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,32 @@ public static void configureView(View view, Contact contact) {
Context context = view.getContext();

switch (type) {
case USER:
case GATEWAY: {
case USER, GATEWAY -> {
// User or radio gateway
String message = contact.getStatusMessage(); // User-defined status message
statusText = message == null || message.length() == 0 ? statusToText(context, status) : message;
break;
}
case CHANNEL: {
case CHANNEL -> {
if (status == ContactStatus.AVAILABLE) {
String countText = NumberFormat.getInstance().format(contact.getUsersCount());
statusText = context.getString(R.string.status_channel_users_count).replace("%count%", countText);
} else {
statusText = statusToText(context, status);
}
break;
}
case GROUP: {
case GROUP -> {
String countText = NumberFormat.getInstance().format(contact.getUsersTotal());
String totalText = NumberFormat.getInstance().format(contact.getUsersTotal());
statusText = view.getContext().getString(R.string.status_group_users_count).replace("%count%", countText).replace("%total%", totalText);
break;
}
case CONVERSATION: {
case CONVERSATION -> {
if (status == ContactStatus.AVAILABLE) {
String countText = NumberFormat.getInstance().format(contact.getUsersCount());
String totalText = NumberFormat.getInstance().format(contact.getUsersTotal());
statusText = view.getContext().getString(R.string.status_group_users_count).replace("%count%", countText).replace("%total%", totalText);
} else {
statusText = statusToText(context, status);
}
break;
}
}

Expand All @@ -162,71 +157,53 @@ public int getItemViewType(int position) {
}

private static String statusToText(Context context, ContactStatus status) {
int id = R.string.status_offline;
int id;
switch (status) {
case STANDBY:
id = R.string.status_standby;
break;
case AVAILABLE:
id = R.string.status_online;
break;
case BUSY:
id = R.string.status_busy;
break;
case CONNECTING:
id = R.string.status_connecting;
break;
default:
case STANDBY -> id = R.string.status_standby;
case AVAILABLE -> id = R.string.status_online;
case BUSY -> id = R.string.status_busy;
case CONNECTING -> id = R.string.status_connecting;
default -> id = R.string.status_offline;
}
return context.getString(id);
}

@SuppressWarnings("SwitchStatementWithTooFewBranches")
private static int statusToDrawableId(ContactStatus status, ContactType type) {
switch (type) {
case USER: {
case USER -> {
// User
switch (status) {
case STANDBY:
return R.drawable.user_standby;
case AVAILABLE:
return R.drawable.user_online;
case BUSY:
return R.drawable.user_busy;
default:
return R.drawable.user_offline;
}
return switch (status) {
case STANDBY -> R.drawable.user_standby;
case AVAILABLE -> R.drawable.user_online;
case BUSY -> R.drawable.user_busy;
default -> R.drawable.user_offline;
};
}
case CHANNEL: {
case CHANNEL -> {
// Channel
switch (status) {
case AVAILABLE:
return R.drawable.channel_online;
default:
return R.drawable.channel_offline;
}
return switch (status) {
case AVAILABLE -> R.drawable.channel_online;
default -> R.drawable.channel_offline;
};
}
case GATEWAY: {
case GATEWAY -> {
// Radio gateway
return R.drawable.gateway_online;
}
case GROUP: {
case GROUP -> {
// Group
switch (status) {
case AVAILABLE:
return R.drawable.group_online;
default:
return R.drawable.channel_offline;
}
return switch (status) {
case AVAILABLE -> R.drawable.group_online;
default -> R.drawable.channel_offline;
};
}
case CONVERSATION: {
case CONVERSATION -> {
// Channel
switch (status) {
case AVAILABLE:
return R.drawable.conversation_online;
default:
return R.drawable.conversation_offline;
}
return switch (status) {
case AVAILABLE -> R.drawable.conversation_online;
default -> R.drawable.conversation_offline;
};
}
}
return R.drawable.user_offline;
Expand Down
Loading

0 comments on commit 128201b

Please sign in to comment.