Skip to content

Commit

Permalink
make single image flow work
Browse files Browse the repository at this point in the history
  • Loading branch information
BrtqKr committed Mar 4, 2024
1 parent 53b28b5 commit 0ffe479
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.expensify.chat

import android.content.Context
import android.util.Log
import com.expensify.chat.intentHandler.IntentHandlerConstants
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.Callback
import com.facebook.react.bridge.ReactApplicationContext
Expand All @@ -12,20 +15,18 @@ class ShareActionHandlerModule(reactContext: ReactApplicationContext) : ReactCon
@ReactMethod
fun processFiles(callback: Callback) {
try {
//Perform your operation here. For instance, load your files

val fileArray: ArrayList<String> = ArrayList()
// Add your files to "fileArray"
val sharedPreferences = reactApplicationContext.getSharedPreferences(IntentHandlerConstants.preferencesFile, Context.MODE_PRIVATE)
val fileSet = sharedPreferences.getStringSet(IntentHandlerConstants.fileArrayProperty, setOf())
val fileArray: ArrayList<String> = ArrayList(fileSet)

val resultArray = Arguments.createArray()
for (file in fileArray) {
resultArray.pushString(file)
}

//invoke the callback with your loaded files
callback.invoke(null, resultArray)

callback.invoke(resultArray)
} catch (exception: Exception) {
Log.e("ImageIntentHandler", exception.toString())
callback.invoke(exception.toString(), null)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ object ImageUtils {
val imageFile: File = createImageFile(context)
saveImageFromMediaProviderUri(uri, imageFile, context)
resultingPath = imageFile.absolutePath
Log.i("ImageIntentHandler", "save image$resultingPath")

} catch (ex: IOException) {
Log.e(tag, "Couldn't save image from intent", ex)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import android.util.Log
import com.expensify.chat.image.ImageUtils.copyUriToStorage


object IntentHandlerConstants {
const val preferencesFile = "shareActionHandler"
const val fileArrayProperty = "filePaths"
}


class ImageIntentHandler(private val context: Context) : AbstractIntentHandler() {
override fun handle(intent: Intent?): Boolean {
override fun handle(intent: Intent?): Boolean {
Log.i("ImageIntentHandler", "Handle intent" + intent.toString())
if (intent == null) {
return false
Expand Down Expand Up @@ -37,15 +43,21 @@ class ImageIntentHandler(private val context: Context) : AbstractIntentHandler()

private fun handleSingleImageIntent(intent: Intent, context: Context) {
(intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM))?.let { imageUri ->

Log.i("ImageIntentHandler", "handleSingleImageIntent$imageUri")
// Update UI to reflect image being shared
if (imageUri == null) {
return
}

val resultingImagePaths = ArrayList<String>()
val fileArrayList: ArrayList<String> = ArrayList()
val resultingPath: String? = copyUriToStorage(imageUri, context)
if (resultingPath != null) {
resultingImagePaths.add(resultingPath)
fileArrayList.add(resultingPath)
val sharedPreferences = context.getSharedPreferences(IntentHandlerConstants.preferencesFile, Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
editor.putStringSet(IntentHandlerConstants.fileArrayProperty, fileArrayList.toSet())
editor.apply()
}
}
}
Expand Down
59 changes: 24 additions & 35 deletions src/pages/share/ShareRootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Navigation from '@navigation/Navigation';
import OnyxTabNavigator, {TopTab} from '@navigation/OnyxTabNavigator';
import MoneyRequestParticipantsSelector from '@pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector';
import CONST from '@src/CONST';
// import ShareActionHandlerModule from '@src/modules/ShareActionHandlerModule';
import ShareActionHandlerModule from '@src/modules/ShareActionHandlerModule';
import ONYXKEYS from '@src/ONYXKEYS';

Check failure on line 19 in src/pages/share/ShareRootPage.tsx

View workflow job for this annotation

GitHub Actions / lint

'ONYXKEYS' is defined but never used
import ROUTES from '@src/ROUTES';
import type {Report} from '@src/types/onyx';
Expand All @@ -37,41 +37,29 @@ function ShareRootPage({selectedTab, iou}: ShareRootPageProps) {
const selectedReportID = useRef(optimisticReportID);
const appState = useRef(AppState.currentState);

// const handleAppStateChange = (nextAppState: AppStateStatus) => {
// if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
// console.log('PROCESSED FILES ATTEMPT');
const handleAppStateChange = (nextAppState: AppStateStatus) => {
if (appState.current.match(/inactive|background/) && nextAppState === 'active') {
console.log('PROCESSED FILES ATTEMPT');

Check failure on line 42 in src/pages/share/ShareRootPage.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

// ShareActionHandlerModule.processFiles((processedFiles) => {
// // eslint-disable-next-line no-console
// console.log('PROCESSED FILES ', processedFiles);
// });
// }
ShareActionHandlerModule.processFiles((processedFiles) => {
// eslint-disable-next-line no-console
console.log('PROCESSED FILES ', processedFiles);
});
}
console.log('AppState', nextAppState);

Check failure on line 49 in src/pages/share/ShareRootPage.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

// appState.current = nextAppState;
// // eslint-disable-next-line no-console
// console.log('AppState', appState.current);
// };

// const handleAppStateFocus = (nextAppState: AppStateStatus) => {
// console.log('PROCESSED FILES ATTEMPT');

// ShareActionHandlerModule.processFiles((processedFiles) => {
// // eslint-disable-next-line no-console
// console.log('PROCESSED FILES ', processedFiles);
// });

// appState.current = nextAppState;
// // eslint-disable-next-line no-console
// console.log('AppState', appState.current);
// };
appState.current = nextAppState;
// eslint-disable-next-line no-console
console.log('AppState', appState.current);
};

// useEffect(() => {
// const changeSubscription = Platform.OS === 'ios' ? AppState.addEventListener('change', handleAppStateChange) : AppState.addEventListener('focus', handleAppStateFocus);
useEffect(() => {
const changeSubscription = AppState.addEventListener('change', handleAppStateChange);

// return () => {
// changeSubscription.remove();
// };
// }, []);
return () => {
changeSubscription.remove();
};
}, []);

const navigateBack = () => {
Navigation.dismissModal();
Expand All @@ -80,12 +68,13 @@ function ShareRootPage({selectedTab, iou}: ShareRootPageProps) {
const goToNextStep = useCallback(() => {
// const nextStepIOUType = numberOfParticipants.current === 1 ? CONST.IOU.TYPE.REQUEST : CONST.IOU.TYPE.SPLIT;
const nextStepIOUType = CONST.IOU.TYPE.REQUEST;
IOU.startMoneyRequest_temporaryForRefactor(optimisticReportID, false, CONST.IOU.REQUEST_TYPE.SCAN);
// IOU.startMoneyRequest_temporaryForRefactor(optimisticReportID, false, CONST.IOU.REQUEST_TYPE.SCAN);
IOU.setMoneyRequestTag(transactionID, '');
IOU.resetMoneyRequestCategory_temporaryForRefactor(transactionID);
// IOU.resetMoneyRequestCategory_temporaryForRefactor(transactionID);
Navigation.navigate(ROUTES.SHARE_SCAN_CONFIRM.getRoute(nextStepIOUType, transactionID, selectedReportID.current || optimisticReportID));
}, [transactionID, optimisticReportID]);

console.log('share root page');

Check failure on line 77 in src/pages/share/ShareRootPage.tsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down Expand Up @@ -145,4 +134,4 @@ function ShareRootPage({selectedTab, iou}: ShareRootPageProps) {
);
}

ShareRootPage.displayName = 'ShareRootPage';
export default ShareRootPage;

0 comments on commit 0ffe479

Please sign in to comment.