Skip to content

Commit 5b5e1d1

Browse files
committedOct 29, 2023
Show service class name if service label is empty
Also, avoid IndexOutOfBounds if service label is shorter than 3 chars. + update to androidx.recyclerview:recyclerview:1.3.2
1 parent 3e5c518 commit 5b5e1d1

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed
 

‎app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies {
99
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22'
1010
implementation 'androidx.appcompat:appcompat:1.6.1'
1111
implementation 'androidx.preference:preference-ktx:1.2.1'
12-
implementation 'androidx.recyclerview:recyclerview:1.3.1'
12+
implementation 'androidx.recyclerview:recyclerview:1.3.2'
1313
// implementation 'androidx.activity:activity:1.4.0'
1414
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
1515
implementation 'com.google.android.material:material:1.10.0'
@@ -27,8 +27,8 @@ android {
2727
applicationId 'ee.ioc.phon.android.speak'
2828
minSdkVersion 24
2929
targetSdkVersion 34
30-
versionCode 1910
31-
versionName '1.9.10'
30+
versionCode 1912
31+
versionName '1.9.12'
3232
vectorDrawables.useSupportLibrary = true
3333
// Keep only en and et resources
3434
resourceConfigurations += ['en', 'et']

‎app/src/main/java/ee/ioc/phon/android/speak/adapter/ComboButtonsAdapter.kt

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ class ComboButtonsAdapter(
5252
holder.mView.paintFlags = 0
5353
holder.mView.isClickable = true
5454
}
55-
var label = combo.localeAsStr
56-
if (label.isEmpty() || label.equals("und")) {
57-
label = combo.service.substring(0, 3)
58-
}
59-
holder.mView.text = label
55+
holder.mView.text = combo.tinyLabel
6056
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
6157
holder.mView.tooltipText = combo.longLabel
6258
}

‎app/src/main/java/ee/ioc/phon/android/speak/model/Combo.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Combo {
2121
private final ComponentName mComponentName;
2222
private final String mLocaleLongLabel;
2323
private final String mLocaleAsStr;
24+
private final String mTinyLabel;
2425
private final String mShortLabel;
2526
private final String mLongLabel;
2627
private boolean mIsSelected;
@@ -31,18 +32,22 @@ public Combo(Context context, String id) {
3132
mId = id;
3233
mComponentName = pair.first;
3334
mLocaleAsStr = pair.second;
34-
mServiceLabel = RecognitionServiceManager.getServiceLabel(context, mComponentName);
35+
String serviceLabel = RecognitionServiceManager.getServiceLabel(context, mComponentName);
36+
// Present the service by its short class name, if it does not have a label.
37+
mServiceLabel = serviceLabel.isEmpty() ? mComponentName.getShortClassName() : serviceLabel;
3538
if (mLocaleAsStr.isEmpty() || "und".equals(mLocaleAsStr)) {
3639
mLocaleLongLabel = "";
3740
mAsString = String.format(context.getString(R.string.labelComboListItemWithoutLocale), mServiceLabel);
3841
mShortLabel = mServiceLabel;
3942
mLongLabel = mServiceLabel;
43+
mTinyLabel = mServiceLabel.length() < 3 ? mServiceLabel : mServiceLabel.substring(0, 3);
4044
} else {
4145
mLocaleLongLabel = RecognitionServiceManager.makeLangLabel(mLocaleAsStr);
4246
mAsString = String.format(context.getString(R.string.labelComboListItem), mServiceLabel, mLocaleLongLabel);
4347
String mFormatLabelComboItem = context.getString(R.string.labelComboItem);
4448
mShortLabel = String.format(mFormatLabelComboItem, mServiceLabel, mLocaleAsStr);
4549
mLongLabel = String.format(mFormatLabelComboItem, mServiceLabel, mLocaleLongLabel);
50+
mTinyLabel = mLocaleAsStr;
4651
}
4752
}
4853

@@ -66,6 +71,10 @@ public String getLanguage() {
6671
return mLocaleLongLabel;
6772
}
6873

74+
public String getTinyLabel() {
75+
return mTinyLabel;
76+
}
77+
6978
public String getShortLabel() {
7079
return mShortLabel;
7180
}

‎app/src/main/java/ee/ioc/phon/android/speak/model/RecService.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public RecService(Context context, String id) {
2828
Pair<ComponentName, String> pair = RecognitionServiceManager.unflattenFromString(id);
2929
mComponentName = pair.first;
3030

31-
mLabel = RecognitionServiceManager.getServiceLabel(context, mComponentName);
31+
String label = RecognitionServiceManager.getServiceLabel(context, mComponentName);
32+
// Present the service by its short class name, if it does not have a label.
33+
mLabel = label.isEmpty() ? mComponentName.getShortClassName() : label;
3234
ServiceInfo si = RecognitionServiceManager.getServiceInfo(context, mComponentName);
3335
int resId = si.descriptionRes;
3436
if (resId != 0) {

0 commit comments

Comments
 (0)
Failed to load comments.