Code cleanup

This commit is contained in:
Sayed Owais Ali
2023-09-27 13:47:03 +05:30
parent ccc1632e7c
commit 6cce57fdf2
8 changed files with 157 additions and 265 deletions

View File

@@ -1,5 +1,4 @@
apply plugin: "com.android.application"
apply plugin: "com.google.gms.google-services"
apply plugin: "com.google.firebase.crashlytics"
import com.android.build.OutputFile
import org.apache.tools.ant.taskdefs.condition.Os
@@ -280,7 +279,7 @@ android {
buildConfigField 'String', 'FLAVOR', '"fieldAgentsProd"'
buildConfigField 'String', 'BUILD_FLAVOR', '"prod"'
buildConfigField 'String', 'APP_NAME', '"COSMOS"'
buildConfigField 'String', 'API_KEY', '"qa"'
buildConfigField 'String', 'API_KEY', '"tOScvaFFqRd0tKF2d8jnJu6oY6eSwtLA"'
}
callingAgentsQA {
applicationId "com.avapp"
@@ -296,7 +295,7 @@ android {
buildConfigField 'String', 'FLAVOR', '"callingAgentsProd"'
buildConfigField 'String', 'BUILD_FLAVOR', '"prod"'
buildConfigField 'String', 'APP_NAME', '"COSMOS"'
buildConfigField 'String', 'API_KEY', '"qa"'
buildConfigField 'String', 'API_KEY', '"tOScvaFFqRd0tKF2d8jnJu6oY6eSwtLA"'
}
}
}
@@ -308,14 +307,10 @@ dependencies {
implementation 'com.navi.medici:alfred:navi_v1.0.0-20230921.100900-52'
implementation(platform("com.google.firebase:firebase-bom:32.2.3"))
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+" // From node_modules
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"
implementation("com.google.firebase:firebase-config-ktx")
implementation("com.google.firebase:firebase-analytics-ktx")
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
exclude group:'com.facebook.fbjni'

View File

@@ -1,39 +1,40 @@
{
"project_info": {
"project_number": "60755663443",
"project_id": "address-verification-app",
"storage_bucket": "address-verification-app.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:60755663443:android:988149d3da3c00d38584a6",
"android_client_info": {
"package_name": "com.avapp"
}
},
"oauth_client": [
{
"client_id": "60755663443-40k0fbrbbqv4ci4hrjlbrphab5fj387b.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyA70_d2M2ke-Mu0OHGZ6iZilBbD6A-_z0c"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "60755663443-40k0fbrbbqv4ci4hrjlbrphab5fj387b.apps.googleusercontent.com",
"client_type": 3
}
]
}
"project_info": {
"project_number": "60755663443",
"project_id": "address-verification-app",
"storage_bucket": "address-verification-app.appspot.com",
"firebase_url": "https://address-verification-app-default-rtdb.firebaseio.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:60755663443:android:4a948ee9d0b4e3098584a6",
"android_client_info": {
"package_name": "com.avapp"
}
},
"oauth_client": [
{
"client_id": "60755663443-40k0fbrbbqv4ci4hrjlbrphab5fj387b.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyA70_d2M2ke-Mu0OHGZ6iZilBbD6A-_z0c"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "60755663443-40k0fbrbbqv4ci4hrjlbrphab5fj387b.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
],
"configuration_version": "1"
}
}
],
"configuration_version": "1"
}

View File

@@ -6,30 +6,68 @@ import com.facebook.react.ReactRootView;
import com.navi.alfred.AlfredManager;
import com.navi.alfred.utils.UtilsKt;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
private static int appInForegroundCounter = 0;
private boolean cruiseApiCalled = false;
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "AVAPP";
}
// https://github.com/software-mansion/react-native-screens#android
@Override
protected String getMainComponentName() {
return "AVAPP";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(null);
}
// https://github.com/software-mansion/react-native-screens#android
/**
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
* (Paper).
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new MainActivityDelegate(this, getMainComponentName());
}
public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}
@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
@Override
protected boolean isConcurrentRootEnabled() {
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
}
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
AlfredManager.INSTANCE.handleTouchEvent(ev, "Cosmos", "Cosmos");
AlfredManager.INSTANCE.handleTouchEvent(ev, BuildConfig.APP_NAME, BuildConfig.APP_NAME);
return super.dispatchTouchEvent(ev);
}
@@ -48,7 +86,7 @@ public class MainActivity extends ReactActivity {
cruiseApiCalled = true;
if (AlfredManager.config != null && AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
try {
AlfredManager.INSTANCE.startRecording(this, this.getWindow().getDecorView().getRootView(), "cosmos", "cosmos", null);
AlfredManager.INSTANCE.startRecording(this, this.getWindow().getDecorView().getRootView(), BuildConfig.APP_NAME, BuildConfig.APP_NAME, null);
} catch (Exception e) {
UtilsKt.log(e);
}
@@ -59,7 +97,7 @@ public class MainActivity extends ReactActivity {
else {
if (AlfredManager.config != null && AlfredManager.config.getAlfredStatus() && AlfredManager.config.getEnableRecordingStatus()) {
try {
AlfredManager.INSTANCE.startRecording(this, this.getWindow().getDecorView().getRootView(), "cosmos", "cosmos", null);
AlfredManager.INSTANCE.startRecording(this, this.getWindow().getDecorView().getRootView(), BuildConfig.APP_NAME, BuildConfig.APP_NAME, null);
} catch (Exception e) {
UtilsKt.log(e);
}
@@ -80,39 +118,6 @@ public class MainActivity extends ReactActivity {
}
}
/**
* Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
* you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
* (Paper).
*/
@Override
protected ReactActivityDelegate createReactActivityDelegate() {
return new MainActivityDelegate(this, getMainComponentName());
}
public static class MainActivityDelegate extends ReactActivityDelegate {
public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
super(activity, mainComponentName);
}
@Override
protected ReactRootView createRootView() {
ReactRootView reactRootView = new ReactRootView(getContext());
// If you opted-in for the New Architecture, we enable the Fabric Renderer.
reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
return reactRootView;
}
@Override
protected boolean isConcurrentRootEnabled() {
// If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
// More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
}
}
public static Boolean isAppInForeground() {
return appInForegroundCounter >= 1;
}

View File

@@ -3,6 +3,7 @@ package com.avapp;
import static com.avapp.utils.Constants.APP_IN_FOREGROUND;
import static com.avapp.utils.Constants.LINE_NUMBER;
import static com.avapp.utils.Constants.METHOD_NAME;
import static com.avapp.utils.Constants.STACK_TRACE;
import static com.google.firebase.analytics.FirebaseAnalytics.Param.SCREEN_NAME;
import android.app.Application;
@@ -15,18 +16,14 @@ import com.facebook.react.ReactPackage;
import com.facebook.react.config.ReactFeatureFlags;
import com.facebook.soloader.SoLoader;
import com.avapp.newarchitecture.MainApplicationReactNativeHost;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;
import com.github.anrwatchdog.ANRWatchDog;
import com.microsoft.codepush.react.CodePush;
import com.navi.alfred.AlfredConfig;
import com.navi.alfred.AlfredManager;
import android.database.CursorWindow;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -36,49 +33,52 @@ import java.util.Map;
public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
private final ReactNativeHost mReactNativeHost =
new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
packages.add(new DeviceUtilsModulePackage());
return packages;
return packages;
}
@Override
protected String getJSMainModuleName() {
return "index";
return "index";
}
@Override
protected String getJSBundleFile() {
return CodePush.getJSBundleFile();
return CodePush.getJSBundleFile();
}
};
};
private final ReactNativeHost mNewArchitectureNativeHost = new MainApplicationReactNativeHost(this);
private final ReactNativeHost mNewArchitectureNativeHost =
new MainApplicationReactNativeHost(this);
@Override
public ReactNativeHost getReactNativeHost() {
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
return mNewArchitectureNativeHost;
} else {
return mReactNativeHost;
}
@Override
public ReactNativeHost getReactNativeHost() {
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
return mNewArchitectureNativeHost;
} else {
return mReactNativeHost;
}
}
@Override
public void onCreate() {
super.onCreate();
// If you opted-in for the New Architecture, we enable the TurboModule system
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
@Override
public void onCreate() {
super.onCreate();
// If you opted-in for the New Architecture, we enable the TurboModule system
ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
SoLoader.init(this, /* native exopackage */ false);
initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
AlfredConfig alfredConfig = new AlfredConfig(BuildConfig.APP_NAME, String.valueOf(BuildConfig.VERSION_CODE), BuildConfig.VERSION_NAME, BuildConfig.BUILD_FLAVOR, BuildConfig.API_KEY);
AlfredManager.INSTANCE.init(alfredConfig, getApplicationContext());
@@ -87,7 +87,6 @@ public class MainApplication extends Application implements ReactApplication {
if (error.getCause().getStackTrace().length == 0) {
return;
}
Map<String, String> anrEventProperties = new HashMap<>();
anrEventProperties.put(SCREEN_NAME, BuildConfig.APP_NAME);
anrEventProperties.put(METHOD_NAME, error.getCause().getStackTrace()[0].getMethodName());
@@ -95,7 +94,7 @@ public class MainApplication extends Application implements ReactApplication {
anrEventProperties.put(APP_IN_FOREGROUND, MainActivity.isAppInForeground().toString());
if (AlfredManager.config.getAlfredStatus() && AlfredManager.config.getAnrEnableStatus()) {
anrEventProperties.put("STACK_TRACE", error.getCause().getStackTrace()[0].toString());
anrEventProperties.put(STACK_TRACE, error.getCause().getStackTrace()[0].toString());
View anrView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.anr_screen, null);
AlfredManager.INSTANCE.measureInflatedView(anrView);
AlfredManager.INSTANCE.handleAnrEvent(anrEventProperties, anrView, SCREEN_NAME);
@@ -114,7 +113,7 @@ public class MainApplication extends Application implements ReactApplication {
}
try {
Map<String, String> crashEventProperties = new HashMap<>();
crashEventProperties.put(SCREEN_NAME, "Cosmos");
crashEventProperties.put(SCREEN_NAME, BuildConfig.APP_NAME);
crashEventProperties.put(METHOD_NAME, exception.getStackTrace()[0].getMethodName());
crashEventProperties.put(LINE_NUMBER, String.valueOf(exception.getStackTrace()[0].getLineNumber()));
crashEventProperties.put(APP_IN_FOREGROUND, MainActivity.isAppInForeground().toString());
@@ -122,58 +121,59 @@ public class MainApplication extends Application implements ReactApplication {
if ((AlfredManager.config.getAlfredStatus() && AlfredManager.config.getCrashEnableStatus())) {
StackTraceElement stackTraceElement = exception.getStackTrace()[0];
if (stackTraceElement != null) {
crashEventProperties.put("STACK_TRACE", stackTraceElement.toString());
crashEventProperties.put(STACK_TRACE, stackTraceElement.toString());
}
View crashView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.crash_screen, null);
AlfredManager.INSTANCE.measureInflatedView(crashView);
AlfredManager.INSTANCE.handleCrashEvent(crashEventProperties, crashView.getRootView(), "Cosmos");
AlfredManager.INSTANCE.handleCrashEvent(crashEventProperties, crashView.getRootView(), BuildConfig.APP_NAME);
}
} finally {
if (defaultHandler != null) {
defaultHandler.uncaughtException(thread, exception);
}
}
});
// https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 20 * 1024 * 1024); //20MB
} catch (Exception e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}
// https://github.com/rt2zz/redux-persist/issues/284#issuecomment-1011214066
try {
Field field = CursorWindow.class.getDeclaredField("sCursorWindowSize");
field.setAccessible(true);
field.set(null, 20 * 1024 * 1024); //20MB
} catch (Exception e) {
if (BuildConfig.DEBUG) {
e.printStackTrace();
}
}
}
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/**
* Loads Flipper in React Native templates. Call this in the onCreate method with something like
* initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
*
* @param context
* @param reactInstanceManager
*/
private static void initializeFlipper(
Context context, ReactInstanceManager reactInstanceManager) {
if (BuildConfig.DEBUG) {
try {
/*
We use reflection here to pick up the class that initializes Flipper,
since Flipper library is not available in release mode
*/
Class<?> aClass = Class.forName("com.avapp.ReactNativeFlipper");
aClass.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class).invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
Class<?> aClass = Class.forName("com.avapp.ReactNativeFlipper");
aClass
.getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
.invoke(null, context, reactInstanceManager);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}
}

View File

@@ -5,4 +5,5 @@ public class Constants {
public static final String METHOD_NAME = "method_name";
public static final String LINE_NUMBER = "line_number";
public static final String APP_IN_FOREGROUND = "app_in_foreground";
public static final String STACK_TRACE = "STACK_TRACE";
}

View File

@@ -1,75 +0,0 @@
package com.avapp.utils;
import com.avapp.BuildConfig;
import com.avapp.R;
import com.google.firebase.remoteconfig.FirebaseRemoteConfig;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigValue;
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings;
public class FirebaseRemoteConfigHelper {
private static FirebaseRemoteConfig remoteConfig;
private static final long CONFIG_SYNC_INTERVAL = 60 * 60;
public static final String DISABLE_ALFRED_LOGS = "DISABLE_ALFRED_LOGS";
public static void init() {
remoteConfig = getFirebaseRemoteConfig();
}
private static FirebaseRemoteConfig getFirebaseRemoteConfig() {
FirebaseRemoteConfig remoteConfig = FirebaseRemoteConfig.getInstance();
FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder().setMinimumFetchIntervalInSeconds(BuildConfig.DEBUG ? 0 : CONFIG_SYNC_INTERVAL).build();
remoteConfig.setConfigSettingsAsync(configSettings);
remoteConfig.setDefaultsAsync(R.xml.default_remote_config);
remoteConfig.fetchAndActivate().addOnCompleteListener(task -> {
});
return remoteConfig;
}
private static FirebaseRemoteConfigValue getRawValue(String key) {
try {
FirebaseRemoteConfigValue rawValue = remoteConfig.getValue(key);
return rawValue.getSource() == FirebaseRemoteConfig.VALUE_SOURCE_STATIC ? null : rawValue;
} catch (Exception e) {
return null;
}
}
public static Boolean getRawBoolean(String key) {
FirebaseRemoteConfigValue rawValue = getRawValue(key);
return rawValue != null ? rawValue.asBoolean() : null;
}
public static String getString(String key) {
try {
return remoteConfig.getString(key);
} catch (Exception e) {
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_STRING;
}
}
public static boolean getBoolean(String key) {
try {
return remoteConfig.getBoolean(key);
} catch (Exception e) {
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_BOOLEAN;
}
}
public static double getDouble(String key) {
try {
return remoteConfig.getDouble(key);
} catch (Exception e) {
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_DOUBLE;
}
}
public static long getLong(String key) {
try {
return remoteConfig.getLong(key);
} catch (Exception e) {
return FirebaseRemoteConfig.DEFAULT_VALUE_FOR_LONG;
}
}
}

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/tv_sww"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/something_went_wrong"
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~
~ * Copyright © 2019-2023 by Navi Technologies Limited
~ * All rights reserved. Strictly confidential
~
-->
<defaultsMap>
<entry>
<key>ALFRED_ENABLED</key>
<value>true</value>
</entry>
</defaultsMap>