Skip to content
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

Open
wants to merge 61 commits into
base: feature/custom_inapp_templates
Choose a base branch
from

Conversation

piyush-kukadiya
Copy link
Contributor

  • 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

…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){
Copy link
Collaborator

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

Copy link
Contributor Author

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(
Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 24ae903

Comment on lines 77 to 80
val memoryAccessObjectList = listOf<MemoryAccessObject<*>>(
FileMemoryAccessObject(ctCaches), ImageMemoryAccessObject(ctCaches),
GifMemoryAccessObject(ctCaches)
)
Copy link
Collaborator

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>())
Copy link
Contributor

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?

return true
}
}
return false
}

fun cachedImage(cacheKey: String?): Bitmap? {
Copy link
Contributor

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? {
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Contributor Author

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).

Copy link
Contributor Author

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

Comment on lines 18 to 19
fun cleanupStaleImages(validUrls: List<String>)
fun cleanupStaleFiles(validUrls: List<String>)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cleanupStaleGifs seems missing, intentional?

Copy link
Contributor Author

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.

@Anush-Shand
Copy link
Contributor

Anush-Shand commented Jun 6, 2024

@piyush-kukadiya GifMemoryV1, ImageMemoryV1 and FileMemoryV2 have same implementation for same functions, can they have a default implementation in the base class itself?

@CTLalit CTLalit changed the base branch from feature/custom_inapp_templates to task/SDK-3814/user_attribute_triggering June 11, 2024 13:28
CTLalit and others added 3 commits June 11, 2024 18:59
… showInApp() to CTInAppNotification prepareForDisplay() for CustomTemplates, download all file arguments before presenting SDK-3876
Base automatically changed from task/SDK-3814/user_attribute_triggering to feature/custom_inapp_templates June 12, 2024 13:51
CTLalit and others added 14 commits June 12, 2024 19:22
- handles inapp custom code download in sync fashion
…rTap/clevertap-android-sdk into feature/file_type_support_comments
…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

if (bytes == null) {
// download fail
this.error = "some error";
Copy link
Contributor

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.

Copy link
Contributor

@vasct vasct left a 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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO

Copy link
Contributor

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) {
Copy link
Contributor

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
)
)/*
Copy link
Contributor

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
)

/*
Copy link
Contributor

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
)
)/*
Copy link
Contributor

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)
/*
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Ignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants