Skip to content

Commit

Permalink
Updates and crash fixes
Browse files Browse the repository at this point in the history
+ updated Gradle and dependencies
+ fixed FLAG_MUTABLE crash when using Bubbles API in Android 12+ devices
+ fixed TTS Check crash in DictionaryFragment
+ added try-catch for TTS items in TTS Adapter
+ fixed FloatingDialogView EditText crash
  • Loading branch information
AwaisKing committed Feb 17, 2022
1 parent 5e455fd commit 53fee88
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 34 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ android {
minSdk 19
targetSdk 31

versionCode 120
versionName '12.0'
versionCode 121
versionName '12.1'

multiDexEnabled true

vectorDrawables {
useSupportLibrary true
generatedDensities = []
//generatedDensities = []
}
}

buildFeatures { viewBinding true }

aaptOptions { additionalParameters '--no-version-vectors' }
//aaptOptions { additionalParameters '--no-version-vectors' }

compileOptions {
targetCompatibility JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -78,16 +78,16 @@ allprojects {

dependencies {
implementation('androidx.multidex:multidex:2.0.1@aar') { transitive true }
implementation('androidx.work:work-runtime:2.7.1@aar') { transitive true }
//implementation('androidx.work:work-runtime:2.7.1@aar') { transitive true }
implementation('androidx.recyclerview:recyclerview:1.3.0-alpha01@aar') { transitive true }
implementation('com.google.android.material:material:1.6.0-alpha01@aar') {
implementation('com.google.android.material:material:1.6.0-alpha02@aar') {
transitive true
exclude group: 'androidx.work', module: 'work-runtime'
//exclude group: 'androidx.work', module: 'work-runtime'
}

implementation('com.google.android.gms:play-services-ads:20.5.0') { exclude group: 'androidx.work', module: 'work-runtime' }

implementation('com.google.firebase:firebase-core:20.0.2') { exclude group: 'androidx.work', module: 'work-runtime' }
implementation('com.google.firebase:firebase-analytics:20.0.2') { exclude group: 'androidx.work', module: 'work-runtime' }
implementation('com.google.firebase:firebase-crashlytics:18.2.6') { exclude group: 'androidx.work', module: 'work-runtime' }
implementation('com.google.firebase:firebase-core:20.1.0') { exclude group: 'androidx.work', module: 'work-runtime' }
implementation('com.google.firebase:firebase-analytics:20.1.0') { exclude group: 'androidx.work', module: 'work-runtime' }
implementation('com.google.firebase:firebase-crashlytics:18.2.8') { exclude group: 'androidx.work', module: 'work-runtime' }
}
22 changes: 16 additions & 6 deletions app/src/main/java/awais/backworddictionary/DictionaryFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -84,9 +85,17 @@ public void onAttach(@NonNull final Context context) {
final Activity activity = getActivity();
this.activity = activity != null ? activity : (Activity) context;

if (Main.tts == null) startActivityForResult(new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA),
Main.TTS_DATA_CHECK_CODE);
// Main.tts = new TextToSpeech(this.activity.getApplicationContext(), Main::onTTSInit);
// check for tts before initializing it
if (Main.tts == null) {
try {
startActivityForResult(new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA),
Main.TTS_DATA_CHECK_CODE);
} catch (final Throwable e) {
// tts check activity not found
Toast.makeText(this.activity, R.string.tts_act_not_found, Toast.LENGTH_SHORT).show();
}
// Main.tts = new TextToSpeech(this.activity.getApplicationContext(), Main::onTTSInit);
}
}

@Override
Expand All @@ -108,14 +117,15 @@ public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable final
public void onViewCreated(@NonNull final View magicRootView, @Nullable final Bundle savedInstanceState) {
final Activity act = getActivity();
activity = act == null ? (Activity) getContext() : act;
final boolean actNotNull = activity != null;

dictionaryBinding.rvItems.addOnScrollListener(VIEWPAGER_SCROLL_HACK);

if (resources == null) resources = activity != null ? activity.getResources() : getResources();
final Resources.Theme theme = activity != null ? activity.getTheme() : null;
if (resources == null) resources = actNotNull ? activity.getResources() : getResources();
final Resources.Theme theme = actNotNull ? activity.getTheme() : null;
cardBackColor = ResourcesCompat.getColor(resources, R.color.cards_back_color, theme);

if (Utils.inputMethodManager == null && activity != null)
if (Utils.inputMethodManager == null && actNotNull)
Utils.inputMethodManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);

wordList.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,20 @@ public void onBindViewHolder(@NonNull final TTSViewHolder holder, final int posi
final Object tag = holder.ivIcon.getTag();
if (tag instanceof Drawable) drawable = (Drawable) tag;
else if (engineInfo.icon != 0) {
final String resourceName = resources.getResourceName(engineInfo.icon);
final String resourcePackageName = resources.getResourcePackageName(engineInfo.icon);
String resourceName, resourcePackageName;

// getResourceName crash fix
try {
resourceName = resources.getResourceName(engineInfo.icon);
} catch (final Exception e) {
resourceName = null;
}
try {
resourcePackageName = resources.getResourcePackageName(engineInfo.icon);
} catch (final Exception e) {
resourcePackageName = null;
}

if (!BuildConfig.APPLICATION_ID.equalsIgnoreCase(resourcePackageName)
&& (resourceName == null || !resourceName.contains("ic_launcher"))) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ public void done(final ArrayList<WordItem> items, @NonNull final String word) {
dialogBinding.btnClear.setVisibility(VISIBLE);
dialogBinding.btnSearch.setVisibility(VISIBLE);

dialogBinding.etSearchView.setSelection(word.length());
try {
dialogBinding.etSearchView.setSelection(word.length());
} catch (final Exception e) {
final CharSequence str = dialogBinding.etSearchView.getText();
if (!Utils.isEmpty(str)) dialogBinding.etSearchView.setSelection(str.length());
}

this.word = word;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -41,7 +42,6 @@ public final class BubbleHelper {
categorySet.add("awais.linkedwords.bubbles.SEARCH");
}

@RequiresApi(api = 14)
public static final String INTENT_EXTRA_BUBBLING = "awais.intent.BUBBLING";

public static final String LW_BUBBLES_CHANNEL_NAME = "Linked Words Bubbles";
Expand Down Expand Up @@ -91,11 +91,14 @@ public void setText(final String text) {
final Bundle extras = intent.getExtras();
if (extras != null) extras.clear();

int flags = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT;
// fix for Android S+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) flags |= PendingIntent.FLAG_MUTABLE;

this.pendingIntent = PendingIntent.getActivity(context, LW_REQUEST_BUBBLE,
intent.putExtra(INTENT_EXTRA_BUBBLING, true)
.putExtra(Intent.EXTRA_TEXT, text)
.setData(Uri.parse(text)),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
.setData(Uri.parse(text)), flags);
}

public void showBubble() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@ private static String getPackageNameToUse(final Context context) {
defaultBrowser = defaultViewHandlerInfo.activityInfo.packageName;

final ArrayList<String> customTabBrowsersList = new ArrayList<>(0);
final Intent serviceIntent = new Intent(ACTION_CUSTOM_TABS_CONNECTION)
.setAction(ACTION_CUSTOM_TABS_CONNECTION_ANDROID_X);

final List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
for (final ResolveInfo info : resolvedActivityList) {
final String packageName = info.activityInfo.packageName;
final Intent serviceIntent = new Intent(ACTION_CUSTOM_TABS_CONNECTION).setPackage(packageName);

serviceIntent.setPackage(packageName);
ResolveInfo resolveInfo = pm.resolveService(serviceIntent, 0);
if (resolveInfo == null) {
serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION_ANDROID_X);
resolveInfo = pm.resolveService(serviceIntent, 0);
}

if (resolveInfo == null) resolveInfo = pm.resolveService(serviceIntent, 0);
if (resolveInfo != null) customTabBrowsersList.add(packageName);
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/awais/clans/FloatingActionButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void updateBackground() {
setBackground(layerDrawable);
}

protected Drawable getIconDrawable() {
private Drawable getIconDrawable() {
return iconDrawable != null ? iconDrawable : new ColorDrawable(Color.TRANSPARENT);
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable-anydpi-v21/ic_arrow_down.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z" />
</vector>
15 changes: 15 additions & 0 deletions app/src/main/res/drawable-anydpi-v21/ic_arrow_up.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:pivotX="12"
android:pivotY="12"
android:rotation="180">
<path
android:fillColor="@android:color/white"
android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z" />
</group>
</vector>
Binary file removed app/src/main/res/drawable/hml.png
Binary file not shown.
Binary file removed app/src/main/res/drawable/hmp.png
Binary file not shown.
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingEnd="@dimen/options_padding_horizontal"
android:paddingRight="@dimen/options_padding_horizontal"
android:paddingBottom="@dimen/options_padding_bottom"
android:scaleType="centerInside"
android:tooltipText="@string/options"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/layout_floating_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
android:layout_width="@dimen/progress_width"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/progress_margin_end"
android:layout_marginRight="@dimen/progress_margin_end"
android:visibility="gone" />

<androidx.appcompat.widget.AppCompatImageView
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ buildscript {
repositories {
google()
mavenCentral()
maven { url 'https://maven.java.net/content/groups/public/' }
}

dependencies {
classpath 'com.google.gms:google-services:4.3.10'
classpath 'com.android.tools.build:gradle:7.1.0-beta05'
classpath 'com.android.tools.build:gradle:7.1.1'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.8.1'
}
}
Expand Down

0 comments on commit 53fee88

Please sign in to comment.