-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/file type support SDK-3856 SDK-3844 #619
base: feature/custom_inapp_templates
Are you sure you want to change the base?
Feature/file type support SDK-3856 SDK-3844 #619
Conversation
piyush-kukadiya
commented
Jun 5, 2024
- Adds implementation for file pre loading of any file type.
- Adds public API for clearing files from cache and disk
- Adds public API for returning absolute file path for given file url
- Adds public API to check if file for given url exists or not
…ogic with callback support SDK-3845
…c, types of files storage and add file cleanup logic SDK-3856
… in FilePreloaderCoroutine SDK-3856
… and replace existing FileResourcesRepo instance creation with factory SDK-3856
…es(bool) SDK-3869
…rl(String) SDK-3872
…l(String) SDK-3873
…rUrl(String) SDK-3872
… file preloading tests SDK-3856
…eContext, add getFile(name: String) method for retrieving file arguments SDK-3876
* @param url the non-null url for which to check the existence of the file. | ||
* @return true if a file exists for the specified url, false otherwise. | ||
*/ | ||
public boolean isFileExistsForUrl(@NonNull String url){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be renamed to checkFileForUrl
or doesFileExistForUrl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 49f583
private val inAppRemoteSource: InAppImageFetchApiContract = InAppImageFetchApi() | ||
) { | ||
|
||
private var ctCaches: CTCaches = CTCaches.instance( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
names to call args and formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 24ae903
val memoryAccessObjectList = listOf<MemoryAccessObject<*>>( | ||
FileMemoryAccessObject(ctCaches), ImageMemoryAccessObject(ctCaches), | ||
GifMemoryAccessObject(ctCaches) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we avoid the * wildcard?
class InAppResourceProviderTest { | ||
|
||
private val mockCache = Mockito.mock(CTCaches::class.java) | ||
private val mockBitmap = Mockito.mock(Bitmap::class.java) | ||
private val mockBitmapPair = Pair(Mockito.mock(Bitmap::class.java), mockk<File>()) | ||
private val mockBytesPair = Pair(Mockito.mock(ByteArray::class.java), mockk<File>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can only mockk be used instead of Mockito?
clevertap-core/src/main/java/com/clevertap/android/sdk/CleverTapAPI.java
Outdated
Show resolved
Hide resolved
clevertap-core/src/main/java/com/clevertap/android/sdk/CleverTapAPI.java
Outdated
Show resolved
Hide resolved
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
fun cachedImage(cacheKey: String?): Bitmap? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename to getCachedImage. Would be more readable?
return imageInMemory.get(key) | ||
} | ||
|
||
override fun fetchInMemoryAndTransform(key: String, transformTo: Int): Any? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have specific return types and not Any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transformTo: Int
can be an enum/sealed class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have specific return types and not
Any?
Right now return type Any produces 6 methods. Changing Any to specific return type will produce 18 methods(12 more).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transformTo: Int
can be an enum/sealed class?
fixed in 2bbb5f6
clevertap-core/src/main/java/com/clevertap/android/sdk/inapp/images/memory/ImageMemoryV1.kt
Outdated
Show resolved
Hide resolved
fun cleanupStaleImages(validUrls: List<String>) | ||
fun cleanupStaleFiles(validUrls: List<String>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanupStaleGifs seems missing, intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's intentional because cleanupStaleImages
clears both gif and images.
@piyush-kukadiya GifMemoryV1, ImageMemoryV1 and FileMemoryV2 have same implementation for same functions, can they have a default implementation in the base class itself? |
…, for CustomTemplates, download all file arguments before presenting SDK-3876
…er showInApp(), for CustomTemplates, download all file arguments before presenting SDK-3876
…doesFileExistForUrl() SDK-3872
…ve Logger SDK-3869
…ve Logger in doesFileExistForUrl SDK-3872
…ve Logger in getFilePathForUrl SDK-3873
…ore specific SDK-3856
…FilesAndCache caller and complete preloadFilesAndCache implementation SDK-3856
…on-image files SDK-3856
…feature/file_type_support
… showInApp() to CTInAppNotification prepareForDisplay() for CustomTemplates, download all file arguments before presenting SDK-3876
- handles inapp custom code download in sync fashion
…rTap/clevertap-android-sdk into feature/file_type_support_comments
…o fix build errors SDK-3856
…o remove duplicate code for cached related methods SDK-3856
…o remove duplicate code for api call related methods SDK-3856
…o remove duplicate code for saving call related methods SDK-3856
…o remove duplicate code for fetching call related methods SDK-3856
…o remove duplicate code for delete method SDK-3856
…o remove duplicate code for isFileCached method SDK-3856
…ents File type support refactoring
|
||
if (bytes == null) { | ||
// download fail | ||
this.error = "some error"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to discuss how to handle failed files with product. We could leave failed files as "null" and still display the in-app with no error.
Meanwhile could we change the error string to something more descriptive. "Failed to download file" or something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work overall. Why are so many tests commented-out ?
} else { | ||
impl.cleanupAllImages(); | ||
impl.cleanupStaleFiles(); // todo this also only clears expired ones. fixme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This todo should be addressed before release since this is the public API. We could also temporary remove the expiredOnly param from the function if it would be too much work to have clean up of all files.
@@ -179,7 +184,17 @@ sealed class CustomTemplateContext private constructor( | |||
return map | |||
} | |||
|
|||
//TODO CustomTemplates add getFile(name: String) method for retrieving file arguments | |||
// TODO CustomTemplates add getFile(name: String) method for retrieving file arguments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the //TODO
@@ -253,8 +268,8 @@ sealed class CustomTemplateContext private constructor( | |||
else -> overrides.getDouble(argument.name) | |||
} | |||
} | |||
//TODO CustomTemplates add FILE handling when implemented | |||
FILE -> null | |||
// TODO CustomTemplates add FILE handling when implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use this class and HttpBitmapOperaiton for also downloading bytes (files), I think we could rename those classes to reflect that they are used in a more generic way.
final LegacyInAppStore legacyInAppStore = storeRegistry.getLegacyInAppStore(); | ||
|
||
if (impressionStore == null || inAppStore == null || inAppAssetStore == null || legacyInAppStore == null) { | ||
if (impressionStore == null || inAppStore == null || inAppAssetStore == null || legacyInAppStore == null || fileStore == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only use inAppAssetStore, legacyInAppStore and fileStore to check if they are null and nowhere after that. Do we need them as variables ?
executor = executors | ||
) | ||
)/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
logger = logger, | ||
dispatchers = dispatchers | ||
) | ||
|
||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
logger = logger, | ||
executor = executors | ||
) | ||
)/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
|
||
private val inAppImageCleanupStrategy = mockk<InAppCleanupStrategy>(relaxed = true) | ||
private val preloaderStrategy = mockk<InAppImagePreloaderStrategy>(relaxed = true) | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
@Ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Ignore
…fore-display Fix copying of in-app before displaying of custom code template
Fix visual templates triggered as actions are not dismissed