Skip to content

Commit

Permalink
Show service class name if service label is empty
Browse files Browse the repository at this point in the history
Also, avoid IndexOutOfBounds if service label is shorter than 3 chars.

+ update to androidx.recyclerview:recyclerview:1.3.2
  • Loading branch information
Kaljurand committed Oct 29, 2023
1 parent 3e5c518 commit 5b5e1d1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Expand Up @@ -9,7 +9,7 @@ dependencies {
implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.8.22'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
// implementation 'androidx.activity:activity:1.4.0'
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'com.google.android.material:material:1.10.0'
Expand All @@ -27,8 +27,8 @@ android {
applicationId 'ee.ioc.phon.android.speak'
minSdkVersion 24
targetSdkVersion 34
versionCode 1910
versionName '1.9.10'
versionCode 1912
versionName '1.9.12'
vectorDrawables.useSupportLibrary = true
// Keep only en and et resources
resourceConfigurations += ['en', 'et']
Expand Down
Expand Up @@ -52,11 +52,7 @@ class ComboButtonsAdapter(
holder.mView.paintFlags = 0
holder.mView.isClickable = true
}
var label = combo.localeAsStr
if (label.isEmpty() || label.equals("und")) {
label = combo.service.substring(0, 3)
}
holder.mView.text = label
holder.mView.text = combo.tinyLabel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
holder.mView.tooltipText = combo.longLabel
}
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/ee/ioc/phon/android/speak/model/Combo.java
Expand Up @@ -21,6 +21,7 @@ public class Combo {
private final ComponentName mComponentName;
private final String mLocaleLongLabel;
private final String mLocaleAsStr;
private final String mTinyLabel;
private final String mShortLabel;
private final String mLongLabel;
private boolean mIsSelected;
Expand All @@ -31,18 +32,22 @@ public Combo(Context context, String id) {
mId = id;
mComponentName = pair.first;
mLocaleAsStr = pair.second;
mServiceLabel = RecognitionServiceManager.getServiceLabel(context, mComponentName);
String serviceLabel = RecognitionServiceManager.getServiceLabel(context, mComponentName);
// Present the service by its short class name, if it does not have a label.
mServiceLabel = serviceLabel.isEmpty() ? mComponentName.getShortClassName() : serviceLabel;
if (mLocaleAsStr.isEmpty() || "und".equals(mLocaleAsStr)) {
mLocaleLongLabel = "";
mAsString = String.format(context.getString(R.string.labelComboListItemWithoutLocale), mServiceLabel);
mShortLabel = mServiceLabel;
mLongLabel = mServiceLabel;
mTinyLabel = mServiceLabel.length() < 3 ? mServiceLabel : mServiceLabel.substring(0, 3);
} else {
mLocaleLongLabel = RecognitionServiceManager.makeLangLabel(mLocaleAsStr);
mAsString = String.format(context.getString(R.string.labelComboListItem), mServiceLabel, mLocaleLongLabel);
String mFormatLabelComboItem = context.getString(R.string.labelComboItem);
mShortLabel = String.format(mFormatLabelComboItem, mServiceLabel, mLocaleAsStr);
mLongLabel = String.format(mFormatLabelComboItem, mServiceLabel, mLocaleLongLabel);
mTinyLabel = mLocaleAsStr;
}
}

Expand All @@ -66,6 +71,10 @@ public String getLanguage() {
return mLocaleLongLabel;
}

public String getTinyLabel() {
return mTinyLabel;
}

public String getShortLabel() {
return mShortLabel;
}
Expand Down
Expand Up @@ -28,7 +28,9 @@ public RecService(Context context, String id) {
Pair<ComponentName, String> pair = RecognitionServiceManager.unflattenFromString(id);
mComponentName = pair.first;

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

0 comments on commit 5b5e1d1

Please sign in to comment.