diff --git a/build.gradle b/build.gradle index 6dfc56a9..bacbcd9e 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ ext { ext.buildScriptsDir = "$rootDir/BuildScripts" versions = [ compileSdk : 28, + multidex : '2.0.1', appcompat : '1.0.2', androidx : '1.0.0', material : '1.0.0', @@ -41,6 +42,7 @@ ext { location : '16.0.0', coreKtx : '1.0.1', yandex_mapkit: '3.4.0', - google_maps : '16.1.0' + google_maps : '16.1.0', + danlew_joda : '2.10.3' ] } diff --git a/navigation/build.gradle b/navigation/build.gradle index d5129173..78ae5fad 100644 --- a/navigation/build.gradle +++ b/navigation/build.gradle @@ -19,15 +19,15 @@ dependencies { api project(":utils") api project(":logging") - api 'androidx.multidex:multidex:2.0.1' + api "androidx.multidex:multidex:$versions.multidex" - api 'net.danlew:android.joda:2.10.2' + api "net.danlew:android.joda:$versions.danlew_joda" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "androidx.appcompat:appcompat:$versions.appcompat" - implementation("com.crashlytics.sdk.android:crashlytics:$versions.crashlytics@aar") { + implementation("com.crashlytics.sdk.android:crashlytics:$versions.crashlytics") { transitive = true } } diff --git a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/TouchinApp.java b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/TouchinApp.java deleted file mode 100644 index 49f40475..00000000 --- a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/TouchinApp.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (c) 2016 Touch Instinct - * - * This file is part of RoboSwag library. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -package ru.touchin.roboswag.components.navigation; - -import android.app.Application; -import android.content.Context; -import android.os.StrictMode; -import android.util.Log; - -import com.crashlytics.android.Crashlytics; - -import net.danlew.android.joda.JodaTimeAndroid; - -import java.util.ArrayList; -import java.util.List; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.multidex.MultiDex; -import io.fabric.sdk.android.Fabric; -import ru.touchin.roboswag.core.log.ConsoleLogProcessor; -import ru.touchin.roboswag.core.log.Lc; -import ru.touchin.roboswag.core.log.LcGroup; -import ru.touchin.roboswag.core.log.LcLevel; -import ru.touchin.roboswag.core.log.LogProcessor; -import ru.touchin.roboswag.core.utils.ShouldNotHappenException; -import ru.touchin.templates.ApiModel; - -/** - * Created by Gavriil Sitnikov on 10/03/16. - * Base class of application to extends for Touch Instinct related projects. - */ -public abstract class TouchinApp extends Application { - - @Override - protected void attachBaseContext(@NonNull final Context base) { - super.attachBaseContext(base); - MultiDex.install(base); - } - - @Override - public void onCreate() { - super.onCreate(); - JodaTimeAndroid.init(this); - if (BuildConfig.DEBUG) { - enableStrictMode(); - Lc.initialize(new ConsoleLogProcessor(LcLevel.VERBOSE), true); - LcGroup.UI_LIFECYCLE.disable(); - } else { - try { - final Crashlytics crashlytics = new Crashlytics(); - Fabric.with(this, crashlytics); - Fabric.getLogger().setLogLevel(Log.ERROR); - Lc.initialize(new CrashlyticsLogProcessor(crashlytics), false); - } catch (final NoClassDefFoundError error) { - Lc.initialize(new ConsoleLogProcessor(LcLevel.INFO), false); - Lc.e("Crashlytics initialization error! Did you forget to add\n" - + "compile('com.crashlytics.sdk.android:crashlytics:+@aar') {\n" - + " transitive = true;\n" - + "}\n" - + "to your build.gradle?", error); - } - } - } - - private void enableStrictMode() { - StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() - .detectAll() - .permitDiskReads() - .permitDiskWrites() - .penaltyLog() - .build()); - StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() - .detectAll() - .penaltyLog() - .build()); - } - - private static class CrashlyticsLogProcessor extends LogProcessor { - - @NonNull - private final Crashlytics crashlytics; - - public CrashlyticsLogProcessor(@NonNull final Crashlytics crashlytics) { - super(LcLevel.INFO); - this.crashlytics = crashlytics; - } - - @Override - public void processLogMessage(@NonNull final LcGroup group, - @NonNull final LcLevel level, - @NonNull final String tag, - @NonNull final String message, - @Nullable final Throwable throwable) { - if (group == LcGroup.UI_LIFECYCLE) { - crashlytics.core.log(level.getPriority(), tag, message); - } else if (!level.lessThan(LcLevel.ASSERT) - || (group == ApiModel.API_VALIDATION_LC_GROUP && level == LcLevel.ERROR)) { - Log.e(tag, message); - if (throwable != null) { - crashlytics.core.log(level.getPriority(), tag, message); - crashlytics.core.logException(throwable); - } else { - final ShouldNotHappenException exceptionToLog = new ShouldNotHappenException(tag + ':' + message); - reduceStackTrace(exceptionToLog); - crashlytics.core.logException(exceptionToLog); - } - } - } - - private void reduceStackTrace(@NonNull final Throwable throwable) { - final StackTraceElement[] stackTrace = throwable.getStackTrace(); - final List reducedStackTraceList = new ArrayList<>(); - for (int i = stackTrace.length - 1; i >= 0; i--) { - final StackTraceElement stackTraceElement = stackTrace[i]; - if (stackTraceElement.getClassName().contains(getClass().getSimpleName()) - || stackTraceElement.getClassName().contains(LcGroup.class.getName()) - || stackTraceElement.getClassName().contains(Lc.class.getName())) { - break; - } - reducedStackTraceList.add(0, stackTraceElement); - } - StackTraceElement[] reducedStackTrace = new StackTraceElement[reducedStackTraceList.size()]; - reducedStackTrace = reducedStackTraceList.toArray(reducedStackTrace); - throwable.setStackTrace(reducedStackTrace); - } - - } - -} diff --git a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/TouchinApp.kt b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/TouchinApp.kt new file mode 100644 index 00000000..b5bc16a2 --- /dev/null +++ b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/TouchinApp.kt @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2019 Touch Instinct + * + * This file is part of RoboSwag library. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package ru.touchin.roboswag.components.navigation + +import android.app.Application +import android.content.Context +import android.os.StrictMode +import android.util.Log +import androidx.multidex.MultiDex +import com.crashlytics.android.Crashlytics +import io.fabric.sdk.android.Fabric +import net.danlew.android.joda.JodaTimeAndroid +import ru.touchin.roboswag.core.log.ConsoleLogProcessor +import ru.touchin.roboswag.core.log.CrashlyticsLogProcessor +import ru.touchin.roboswag.core.log.Lc +import ru.touchin.roboswag.core.log.LcGroup +import ru.touchin.roboswag.core.log.LcLevel + +/** + * Base class of application to extends for Touch Instinct related projects. + */ +abstract class TouchinApp : Application() { + + companion object { + private const val CRASHLYTICS_INITIALIZATION_ERROR = "Crashlytics initialization error! Did you forget to add\n" + + "compile('com.crashlytics.sdk.android:crashlytics:+') {\n" + + " transitive = true;\n" + + "}\n" + + "to your build.gradle?" + } + + override fun attachBaseContext(base: Context) { + super.attachBaseContext(base) + MultiDex.install(base) + } + + override fun onCreate() { + super.onCreate() + JodaTimeAndroid.init(this) + enableStrictMode() + initCrashlytics() + } + + private fun enableStrictMode() { + if (BuildConfig.DEBUG) { + StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder() + .detectAll() + .permitDiskReads() + .permitDiskWrites() + .penaltyLog() + .build()) + StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder() + .detectAll() + .penaltyLog() + .build()) + } + } + + private fun initCrashlytics() { + if (BuildConfig.DEBUG) { + Lc.initialize(ConsoleLogProcessor(LcLevel.VERBOSE), true) + LcGroup.UI_LIFECYCLE.disable() + } else { + try { + val crashlytics = Crashlytics() + Fabric.with(this, crashlytics) + Fabric.getLogger().logLevel = Log.ERROR + Lc.initialize(CrashlyticsLogProcessor(crashlytics), false) + } catch (error: NoClassDefFoundError) { + Lc.initialize(ConsoleLogProcessor(LcLevel.INFO), false) + Lc.e(CRASHLYTICS_INITIALIZATION_ERROR, error) + } + } + } + +} diff --git a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/activities/OnBackPressedListener.java b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/activities/OnBackPressedListener.java deleted file mode 100644 index de5d3183..00000000 --- a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/activities/OnBackPressedListener.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.touchin.roboswag.components.navigation.activities; - -public interface OnBackPressedListener { - - boolean onBackPressed(); - -} diff --git a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/activities/OnBackPressedListener.kt b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/activities/OnBackPressedListener.kt new file mode 100644 index 00000000..f10d79d6 --- /dev/null +++ b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/activities/OnBackPressedListener.kt @@ -0,0 +1,7 @@ +package ru.touchin.roboswag.components.navigation.activities + +interface OnBackPressedListener { + + fun onBackPressed(): Boolean + +} diff --git a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/keyboard_resizeable/KeyboardResizeableViewController.kt b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/keyboard_resizeable/KeyboardResizeableViewController.kt index 85a4e78c..ac63a0f7 100644 --- a/navigation/src/main/java/ru/touchin/roboswag/components/navigation/keyboard_resizeable/KeyboardResizeableViewController.kt +++ b/navigation/src/main/java/ru/touchin/roboswag/components/navigation/keyboard_resizeable/KeyboardResizeableViewController.kt @@ -25,13 +25,15 @@ abstract class KeyboardResizeableViewController { + crashlytics.core.log(level.priority, tag, message) + } + !level.lessThan(LcLevel.ASSERT) && level == LcLevel.ERROR -> { + Log.e(tag, message) + if (throwable != null) { + crashlytics.core.log(level.priority, tag, message) + crashlytics.core.logException(throwable) + } else { + val exceptionToLog = ShouldNotHappenException("$tag:$message") + reduceStackTrace(exceptionToLog) + crashlytics.core.logException(exceptionToLog) + } + } + } + } + + private fun reduceStackTrace(throwable: Throwable) { + val stackTrace = throwable.stackTrace + val reducedStackTraceList = arrayListOf() + for (i in stackTrace.indices.reversed()) { + val stackTraceElement = stackTrace[i] + if (stackTraceElement.className.contains(javaClass.simpleName) + || stackTraceElement.className.contains(LcGroup::class.java.name) + || stackTraceElement.className.contains(Lc::class.java.name)) { + break + } + reducedStackTraceList.add(0, stackTraceElement) + } + throwable.stackTrace = reducedStackTraceList.toTypedArray() + } + +}