Skip to content

Commit

Permalink
Feature/sdk 3780/exoplayer migration (#621)
Browse files Browse the repository at this point in the history
* Chore: Formatting

* Chore: Code refactoring

- code cleanup and conditions simplified

* Feat: Exoplayer code extraction from fragment

- removed exoplay and styledplayerview instance in other handle
- the handle provides methods which will be extracted in interface

* Chore: Formatting and cleanup

* Feat: Extraction of exoplayer from MediaPlayerRV + optimisation

- removed all exoplayer imports
- optimised the code to fold methods
- removed recundant checks
- rect is reused
- stop and release methods called appropriately
- todo in activity

* Feat: Fields optimised

- fields made final where possible
- optimised the context getting and usage, removed cached field

* Feat: Removed exoplayer deps from CTInboxBaseMessageViewHolder

- the class does not contain any player/surface handling code anymore
- deletes the code to ExoplayerHandle.kt class where which we use as a holder to migrate to the media3

* Chore: Used lambda

* Chore: Used lambda

* Chore: Rename methods.

* Feat: Kotliny syntax

- force unwrap avoided

* Feat: static initialiser

- removed static block and made static field inline.

* Chore: Doc for class

* Chore: Class level doc

* Feat: Removed force unwraps

- removes force unwraps so that there are no NPEs

* Feat: Methods extracted

* Feat: Extracts video supported flag

- is video supported is computed statically by checking class.forname
- moved method to correct package

* Chore: Removed force unwraps.

- removed forceful unwraps and used null safe operator.

* Chore: Removed redundant method.

* Feat: Orientation from context

- did not use static filed from activity.

* Feat: Minor fixup.

- removed unref method

* Feat: Fixed problematic player assignment

- fixes val name clashing

* Feat: Removed companion object

- possible to use field in holder.

* Feat: SDK-3780 : Media handle

- adds media handle which uses media3 components instead of exoplayer
- adds a different handle class which has similar func to exo handle
- runtime can find the correct handle based on user and attach

* Feat: Unstable api annotation

* Chore: removes redundant import

* Feat: Redundant ?.let call

* Feat: SDK-3780: Extraction of video handle interface

- allows use of both impls of media3 as well as exoplayer2
- checks need to be added on runtime to chekc available lib and use appropriate handle

* Feat(SDK-3780): Adds runtime check method for media3

* Feat(SDK-3780): Methods to check media3 exoplayer

- adds method to check media3 exoplayer which is new lib

* Rename .java to .kt

* Feat(SDK-3780): Converts MediaPlayerRecyclerView to kotlin

- changes to kotlin class from java
- force unwraps removed
- change method signature which is more optimised for kotlin code

* Feat(SDK-3780): Removed redundant ovrrride

* Feat(SDK-3780): Runtime check for video lib

- uses media3 if possible
- exoplayer is deprecated but we do not force migration

* Chore(SDK-3780): Compilation errors fixed

- changes interface signature so corrected the impl

* Feat(SDK-3780): Video library check

- uses media3 if available
- used exoplayer in other cases

* Feat(SDK-3780): Video library check -> Interstitial inapp

- uses media3 if available
- used exoplayer in other cases

* Chore(SDK-3780): optimise find view call

* Chore(SDK-3780): annotate with unstable+static access correctness

* Chore(SDK-3780): unused anno removed

* Feat(SDK-3780): CTInAppNativeInterstitialFragment code cleanup

- broken down view method into smaller chunks
- makes the fragment readable

* Task(SDK-3894): Optimise and fix view add/remove

- corrects behaviour of add/remove views which are used to steam
- optimises add/remove on lifecycle events
- optimises view creation for surfaceview and close button
- reuses same views in dialog and activity
- methods cleanup and renaming

* Task(SDK-3894): crash fix for full screen switch

- fixes video view removal/add crash. dialog is reused and video container need not be attached again.

* Task(SDK-3894): layout params fixed

- moves full screen and normal view layout params in handles
- sets them correctly as needed

* Task(SDK-3894): Fixes init of mediaplayer

- corrects initialisation after removal

* Chore(SDK-3894): code simplified

* Feat(SDK-3780): removes progress bar correctly

- posts so that lifecycle scroll is settled and view is removed.

* Feat(SDK-3780): Pr comments addressed.

* Feat(SDK-3780): Changes build.gradle

- adds new media library instead of deprecated exoplayer2
  • Loading branch information
CTLalit authored Jul 9, 2024
1 parent 0fe651e commit b59b817
Show file tree
Hide file tree
Showing 22 changed files with 1,335 additions and 659 deletions.
4 changes: 4 additions & 0 deletions clevertap-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ android {

dependencies {
compileOnly(libs.firebase.messaging)

// For Media
compileOnly(libs.bundles.exoplayer)
compileOnly(libs.glide)
compileOnly(libs.bundles.media3)

//for notification
compileOnly(libs.androidx.core.core)
compileOnly(libs.androidx.viewpager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.clevertap.android.sdk.task.Task;
import com.clevertap.android.sdk.variables.CTVariables;
import com.clevertap.android.sdk.variables.callbacks.FetchVariablesCallback;
import com.clevertap.android.sdk.video.VideoLibChecker;

import java.util.concurrent.Callable;
import org.json.JSONArray;

Expand Down Expand Up @@ -195,11 +197,16 @@ private void _initializeInbox() {
return;
}
if (deviceInfo.getDeviceID() != null) {
setCTInboxController(new CTInboxController(config, deviceInfo.getDeviceID(),
baseDatabaseManager.loadDBAdapter(context),
ctLockManager,
callbackManager,
Utils.haveVideoPlayerSupport));
setCTInboxController(
new CTInboxController(
config,
deviceInfo.getDeviceID(),
baseDatabaseManager.loadDBAdapter(context),
ctLockManager,
callbackManager,
VideoLibChecker.haveVideoPlayerSupport
)
);
callbackManager._notifyInboxInitialized();
} else {
config.getLogger().info("CRITICAL : No device ID found!");
Expand Down
34 changes: 0 additions & 34 deletions clevertap-core/src/main/java/com/clevertap/android/sdk/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@

public final class Utils {

public static boolean haveVideoPlayerSupport;

public static boolean containsIgnoreCase(Collection<String> collection, String key) {
if (collection == null || key == null) {
return false;
Expand Down Expand Up @@ -428,34 +426,6 @@ static Bitmap drawableToBitmap(@NonNull Drawable drawable)
return bitmap;
}

/**
* Method to check whether app has ExoPlayer dependencies
*
* @return boolean - true/false depending on app's availability of ExoPlayer dependencies
*/
private static boolean checkForExoPlayer() {
boolean exoPlayerPresent = false;
Class className = null;
try {
className = Class.forName("com.google.android.exoplayer2.ExoPlayer");
className = Class.forName("com.google.android.exoplayer2.source.hls.HlsMediaSource");
className = Class.forName("com.google.android.exoplayer2.ui.StyledPlayerView");

Logger.d("ExoPlayer is present");
exoPlayerPresent = true;
} catch (Throwable t) {
Logger.d("ExoPlayer library files are missing!!!");
Logger.d(
"Please add ExoPlayer dependencies to render InApp or Inbox messages playing video. For more information checkout CleverTap documentation.");
if (className != null) {
Logger.d("ExoPlayer classes not found " + className.getName());
} else {
Logger.d("ExoPlayer classes not found");
}
}
return exoPlayerPresent;
}

private static @NonNull DownloadedBitmap getAppIcon(final Context context) throws NullPointerException {
// Try to get the app logo first
try {
Expand Down Expand Up @@ -507,10 +477,6 @@ public static void navigateToAndroidSettingsForNotifications(Context context) {
context.startActivity(intent);
}

static {
haveVideoPlayerSupport = checkForExoPlayer();
}

@WorkerThread
public static boolean isMainProcess(Context context, String mainProcessName) {

Expand Down

This file was deleted.

Loading

0 comments on commit b59b817

Please sign in to comment.