Skip to content

Commit 1fc44da

Browse files
author
Amir Tocker
committed
Rename CldAndroid to MediaManager
1 parent 54978c6 commit 1fc44da

File tree

14 files changed

+67
-67
lines changed

14 files changed

+67
-67
lines changed

lib/src/androidTest/java/com/cloudinary/android/AbstractTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class AbstractTest {
2323
@BeforeClass
2424
public synchronized static void initLibrary() {
2525
if (!initialized) {
26-
CldAndroid.init(InstrumentationRegistry.getTargetContext(), new SignatureProvider() {
26+
MediaManager.init(InstrumentationRegistry.getTargetContext(), new SignatureProvider() {
2727
@Override
2828
public Signature provideSignature(Map options) {
2929
return null;
@@ -34,7 +34,7 @@ public String getName() {
3434
return null;
3535
}
3636
});
37-
CldAndroid.get().getCloudinary().config.apiSecret = null;
37+
MediaManager.get().getCloudinary().config.apiSecret = null;
3838
initialized = true;
3939
}
4040
}

lib/src/main/java/com/cloudinary/android/AndroidJobStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected Result onRunJob(Params params) {
200200
wl.acquire();
201201
try {
202202
// call the generic processor:
203-
UploadStatus result = CldAndroid.get().processRequest(getContext(), new AndroidJobRequestParams(params.getExtras()));
203+
UploadStatus result = MediaManager.get().processRequest(getContext(), new AndroidJobRequestParams(params.getExtras()));
204204
return adaptResult(result);
205205
} finally {
206206
wl.release();

lib/src/main/java/com/cloudinary/android/DefaultCallbackDispatcher.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ public void wakeListenerServiceWithRequestStart(Context appContext, String reque
150150
// if the service is already 'awake' it will receive events via callback. If we send the intent the event will be received twice.
151151
if (listenerServiceClass != null && !isListenerServiceAlreadyRegistered) {
152152
appContext.startService(new Intent(appContext, listenerServiceClass)
153-
.setAction(CldAndroid.ACTION_REQUEST_STARTED)
154-
.putExtra(CldAndroid.INTENT_EXTRA_REQUEST_ID, requestId));
153+
.setAction(MediaManager.ACTION_REQUEST_STARTED)
154+
.putExtra(MediaManager.INTENT_EXTRA_REQUEST_ID, requestId));
155155
}
156156
}
157157

@@ -165,9 +165,9 @@ public void wakeListenerServiceWithRequestFinished(Context appContext, String re
165165
// if the service is already 'awake' it will receive events via callback. If we send the intent the event will be received twice.
166166
if (listenerServiceClass != null && !isListenerServiceAlreadyRegistered) {
167167
appContext.startService(new Intent(appContext, listenerServiceClass)
168-
.setAction(CldAndroid.ACTION_REQUEST_FINISHED)
169-
.putExtra(CldAndroid.INTENT_EXTRA_REQUEST_ID, requestId)
170-
.putExtra(CldAndroid.INTENT_EXTRA_REQUEST_RESULT_STATUS, uploadStatus));
168+
.setAction(MediaManager.ACTION_REQUEST_FINISHED)
169+
.putExtra(MediaManager.INTENT_EXTRA_REQUEST_ID, requestId)
170+
.putExtra(MediaManager.INTENT_EXTRA_REQUEST_RESULT_STATUS, uploadStatus));
171171
}
172172
}
173173

lib/src/main/java/com/cloudinary/android/DefaultRequestDispatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public final String dispatch(UploadRequest request) {
2626
// Requests will be started once there's more room
2727
int totalCount = strategy.getPendingImmediateJobsCount() + strategy.getRunningJobsCount();
2828

29-
if (!request.getTimeWindow().isImmediate() && totalCount >= CldAndroid.get().getGlobalUploadPolicy().getMaxConcurrentRequests()) {
29+
if (!request.getTimeWindow().isImmediate() && totalCount >= MediaManager.get().getGlobalUploadPolicy().getMaxConcurrentRequests()) {
3030
int minutes = 10 + rand.nextInt(10);
3131
request.defferByMinutes(minutes);
3232
Logger.d(TAG, String.format("Request %s deferred by %d minutes.", requestId, minutes));

lib/src/main/java/com/cloudinary/android/DefaultRequestProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public UploadStatus processRequest(Context context, RequestParams params) {
4949
final String requestId = params.getString("requestId", null);
5050
final String uri = params.getString("uri", null);
5151
final String optionsAsString = params.getString("options", null);
52-
final int maxErrorRetries = params.getInt("maxErrorRetries", CldAndroid.get().getGlobalUploadPolicy().getMaxErrorRetries());
52+
final int maxErrorRetries = params.getInt("maxErrorRetries", MediaManager.get().getGlobalUploadPolicy().getMaxErrorRetries());
5353
final int errorCount = params.getInt("errorCount", 0);
5454

5555
Logger.i(TAG, String.format("Processing Request %s.", requestId));
@@ -81,7 +81,7 @@ public UploadStatus processRequest(Context context, RequestParams params) {
8181
if (StringUtils.isNotBlank(uri)) {
8282
Payload payload = PayloadFactory.fromUri(uri);
8383
if (payload != null) {
84-
int maxConcurrentRequests = CldAndroid.get().getGlobalUploadPolicy().getMaxConcurrentRequests();
84+
int maxConcurrentRequests = MediaManager.get().getGlobalUploadPolicy().getMaxConcurrentRequests();
8585
int runningJobsCount = runningJobs.get();
8686
if (runningJobsCount < maxConcurrentRequests) {
8787
try {
@@ -177,8 +177,8 @@ private Map doProcess(final String requestId, Context appContext, Map<String, Ob
177177
}
178178

179179
// if there are no credentials and the request is NOT unsigned - activate the signature provider (if present).
180-
if (!CldAndroid.get().hasCredentials() && !TRUE.equals(options.get("unsigned"))) {
181-
SignatureProvider signatureProvider = CldAndroid.get().getSignatureProvider();
180+
if (!MediaManager.get().hasCredentials() && !TRUE.equals(options.get("unsigned"))) {
181+
SignatureProvider signatureProvider = MediaManager.get().getSignatureProvider();
182182
if (signatureProvider != null) {
183183
try {
184184
Signature signature = signatureProvider.provideSignature(options);
@@ -194,7 +194,7 @@ private Map doProcess(final String requestId, Context appContext, Map<String, Ob
194194
final ProcessorCallback processorCallback = new ProcessorCallback(actualTotalBytes, offset, callbackDispatcher, requestId);
195195

196196
try {
197-
return CldAndroid.get().getCloudinary().uploader().uploadLarge(preparedPayload, options, bufferSize, offset, uploadUniqueId, processorCallback);
197+
return MediaManager.get().getCloudinary().uploader().uploadLarge(preparedPayload, options, bufferSize, offset, uploadUniqueId, processorCallback);
198198
} finally {
199199
// save data into persisted request params to enable resuming later on
200200
params.putInt("original_buffer_size", bufferSize);

lib/src/main/java/com/cloudinary/android/CldAndroid.java renamed to lib/src/main/java/com/cloudinary/android/MediaManager.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@
2626
import java.util.Map;
2727

2828
/**
29-
* Main class used as entry point to any operation against Cloudinary. Use {@link CldAndroid#get()} to get an instance.
29+
* Main class used as entry point to any operation against Cloudinary. Use {@link MediaManager#get()} to get an instance.
3030
* Must be initialized before use, see {@link #init(Context, SignatureProvider, Map)}.
3131
*/
32-
public class CldAndroid {
32+
public class MediaManager {
3333

3434
public static final String INTENT_EXTRA_REQUEST_ID = "INTENT_EXTRA_REQUEST_ID";
3535
public static final String INTENT_EXTRA_REQUEST_RESULT_STATUS = "INTENT_EXTRA_REQUEST_RESULT_STATUS";
3636
public static final String ACTION_REQUEST_STARTED = "com.cloudinary.ACTION_REQUEST_STARTED";
3737
public static final String ACTION_REQUEST_FINISHED = "com.cloudinary.ACTION_REQUEST_FINISHED";
38-
private static final String TAG = CldAndroid.class.getSimpleName();
38+
private static final String TAG = MediaManager.class.getSimpleName();
3939

40-
private static CldAndroid _instance;
40+
private static MediaManager _instance;
4141

4242
private final com.cloudinary.Cloudinary cloudinary;
4343
private final RequestDispatcher requestDispatcher;
@@ -49,7 +49,7 @@ public class CldAndroid {
4949

5050
private GlobalUploadPolicy globalUploadPolicy = GlobalUploadPolicy.defaultPolicy();
5151

52-
private CldAndroid(@NonNull Context context, @Nullable SignatureProvider signatureProvider, @Nullable Map config) {
52+
private MediaManager(@NonNull Context context, @Nullable SignatureProvider signatureProvider, @Nullable Map config) {
5353
// use context to initialize components but DO NOT store it
5454
strategy = BackgroundStrategyProvider.provideStrategy();
5555
callbackDispatcher = new DefaultCallbackDispatcher(context);
@@ -97,7 +97,7 @@ public void onReschedule(String requestId, ErrorInfo error) {
9797
}
9898

9999
/**
100-
* Setup the library with the required parameters. A flavor of init() must be called once before CldAndroid can be used, preferably in an implementation of {@link Application#onCreate()}.
100+
* Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of {@link Application#onCreate()}.
101101
*
102102
* @param context Android context for initializations. Does not get cached.
103103
*/
@@ -106,7 +106,7 @@ public static void init(@NonNull Context context) {
106106
}
107107

108108
/**
109-
* Setup the library with the required parameters. A flavor of init() must be called once before CldAndroid can be used, preferably in an implementation of {@link Application#onCreate()}.
109+
* Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of {@link Application#onCreate()}.
110110
*
111111
* @param context Android context for initializations. Does not get cached.
112112
* @param config Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
@@ -116,7 +116,7 @@ public static void init(@NonNull Context context, @Nullable Map config) {
116116
}
117117

118118
/**
119-
* Setup the library with the required parameters. A flavor of init() must be called once before CldAndroid can be used, preferably in an implementation of {@link Application#onCreate()}.
119+
* Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of {@link Application#onCreate()}.
120120
*
121121
* @param context Android context for initializations. Does not get cached.
122122
* @param config Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
@@ -131,7 +131,7 @@ public static void init(@NonNull Context context, @Nullable Configuration config
131131
}
132132

133133
/**
134-
* Setup the library with the required parameters. A flavor of init() must be called once before CldAndroid can be used, preferably in an implementation of {@link Application#onCreate()}.
134+
* Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of {@link Application#onCreate()}.
135135
*
136136
* @param context Android context for initializations. Does not get cached.
137137
* @param signatureProvider A signature provider. Needed if using signed uploads.
@@ -141,30 +141,30 @@ public static void init(@NonNull Context context, @Nullable SignatureProvider si
141141
}
142142

143143
/**
144-
* Setup the library with the required parameters. A flavor of init() must be called once before CldAndroid can be used, preferably in an implementation of {@link Application#onCreate()}.
144+
* Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of {@link Application#onCreate()}.
145145
*
146146
* @param context Android context for initializations. Does not get cached.
147147
* @param provider A signature provider. Needed if using signed uploads.
148148
* @param config Cloudinary configuration parameters. If not supplied a cloudinary-url metadata must exist in the manifest.
149149
*/
150150
public static void init(@NonNull Context context, @Nullable SignatureProvider provider, @Nullable Map config) {
151-
synchronized (CldAndroid.class) {
151+
synchronized (MediaManager.class) {
152152
//noinspection ConstantConditions
153153
if (context == null) {
154154
throw new IllegalArgumentException("context cannot be null.");
155155
}
156156

157157

158158
if (_instance == null) {
159-
_instance = new CldAndroid(context, provider, config);
159+
_instance = new MediaManager(context, provider, config);
160160
} else {
161-
throw new IllegalStateException("CldAndroid is already initialized");
161+
throw new IllegalStateException("MediaManager is already initialized");
162162
}
163163
}
164164
}
165165

166166
/**
167-
* Setup the library with the required parameters. A flavor of init() must be called once before CldAndroid can be used, preferably in an implementation of {@link Application#onCreate()}.
167+
* Setup the library with the required parameters. A flavor of init() must be called once before MediaManager can be used, preferably in an implementation of {@link Application#onCreate()}.
168168
*
169169
* @param context Android context for initializations. Does not get cached.
170170
* @param provider A signature provider. Needed if using signed uploads.
@@ -181,9 +181,9 @@ public static void init(@NonNull Context context, @Nullable SignatureProvider pr
181181
/**
182182
* Entry point for any operation against Cloudinary
183183
*
184-
* @return An instance of the CldAndroid class to run operations against cloudinary.
184+
* @return An instance of the MediaManager class to run operations against cloudinary.
185185
*/
186-
public static CldAndroid get() {
186+
public static MediaManager get() {
187187
if (_instance == null) {
188188
throw new IllegalStateException("Must call init() before accessing Cloudinary.");
189189
}
@@ -192,7 +192,7 @@ public static CldAndroid get() {
192192
}
193193

194194
/**
195-
* Set the log level. In order to affect initialization logging this can be set before calling {@link CldAndroid#init(Context)}.
195+
* Set the log level. In order to affect initialization logging this can be set before calling {@link MediaManager#init(Context)}.
196196
*
197197
* @param logLevel The log level to set, see {@link LogLevel}.
198198
*/

lib/src/main/java/com/cloudinary/android/UploadRequest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
/**
1818
* A request to upload a single {@link Payload} to Cloudinary. Note: Once calling {@link #dispatch()} the request is sealed and any
1919
* attempt to modify it will produce an {@link IllegalStateException}. If there's a need to change a request after dispatching,
20-
* it needs to be cancelled ({@link CldAndroid#cancelRequest(String)}) and a new request should be dispatched in it's place.
20+
* it needs to be cancelled ({@link MediaManager#cancelRequest(String)}) and a new request should be dispatched in it's place.
2121
* @param <T> The payload type this request will upload
2222
*/
2323
public class UploadRequest<T extends Payload> {
2424
private final UploadContext<T> uploadContext;
2525
private final String requestId = UUID.randomUUID().toString();
2626
private final Object optionsLockObject = new Object();
2727
private boolean dispatched = false;
28-
private UploadPolicy uploadPolicy = CldAndroid.get().getGlobalUploadPolicy();
28+
private UploadPolicy uploadPolicy = MediaManager.get().getGlobalUploadPolicy();
2929
private TimeWindow timeWindow = TimeWindow.getDefault();
3030
private UploadCallback callback;
3131
private Map<String, Object> options;
@@ -126,7 +126,7 @@ public synchronized String dispatch() {
126126
throw new InvalidParamsException("Parameters must be serializable", e);
127127
}
128128

129-
CldAndroid.get().registerCallback(requestId, callback);
129+
MediaManager.get().registerCallback(requestId, callback);
130130
uploadContext.getDispatcher().dispatch(this);
131131

132132
return requestId;
@@ -210,13 +210,13 @@ public void onProgress(String requestId, long bytes, long totalBytes) {
210210
@Override
211211
public void onSuccess(String requestId, Map resultData) {
212212
callback.onSuccess(requestId, resultData);
213-
CldAndroid.get().unregisterCallback(this);
213+
MediaManager.get().unregisterCallback(this);
214214
}
215215

216216
@Override
217217
public void onError(String requestId, ErrorInfo error) {
218218
callback.onError(requestId, error);
219-
CldAndroid.get().unregisterCallback(this);
219+
MediaManager.get().unregisterCallback(this);
220220
}
221221

222222
@Override

lib/src/main/java/com/cloudinary/android/callback/ListenerService.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import android.app.Service;
44
import android.content.Intent;
55

6-
import com.cloudinary.android.CldAndroid;
6+
import com.cloudinary.android.MediaManager;
77
import com.cloudinary.utils.StringUtils;
88

99
/**
@@ -24,20 +24,20 @@ public abstract class ListenerService extends Service implements UploadCallback{
2424
@Override
2525
public void onCreate() {
2626
super.onCreate();
27-
CldAndroid.get().registerCallback(this);
27+
MediaManager.get().registerCallback(this);
2828
}
2929

3030
@Override
3131
public int onStartCommand(Intent intent, int flags, int startId) {
3232
if (intent != null) {
33-
final String requestId = intent.getStringExtra(CldAndroid.INTENT_EXTRA_REQUEST_ID);
33+
final String requestId = intent.getStringExtra(MediaManager.INTENT_EXTRA_REQUEST_ID);
3434

3535
if (StringUtils.isNotBlank(requestId)) {
36-
if (CldAndroid.ACTION_REQUEST_STARTED.equals(intent.getAction())){
36+
if (MediaManager.ACTION_REQUEST_STARTED.equals(intent.getAction())){
3737
onStart(requestId);
38-
} else if (CldAndroid.ACTION_REQUEST_FINISHED.equals(intent.getAction())){
39-
UploadStatus result = (UploadStatus) intent.getSerializableExtra(CldAndroid.INTENT_EXTRA_REQUEST_RESULT_STATUS);
40-
UploadResult uploadResult = CldAndroid.get().popPendingResult(requestId);
38+
} else if (MediaManager.ACTION_REQUEST_FINISHED.equals(intent.getAction())){
39+
UploadStatus result = (UploadStatus) intent.getSerializableExtra(MediaManager.INTENT_EXTRA_REQUEST_RESULT_STATUS);
40+
UploadResult uploadResult = MediaManager.get().popPendingResult(requestId);
4141

4242
// ACTION_REQUEST_FINISHED means either success or failure:
4343
if (result == UploadStatus.FAILURE) {
@@ -55,6 +55,6 @@ public int onStartCommand(Intent intent, int flags, int startId) {
5555
@Override
5656
public void onDestroy() {
5757
super.onDestroy();
58-
CldAndroid.get().unregisterCallback(this);
58+
MediaManager.get().unregisterCallback(this);
5959
}
6060
}

lib/src/main/java/com/cloudinary/android/signed/SignatureProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
import android.content.Context;
44

5-
import com.cloudinary.android.CldAndroid;
5+
import com.cloudinary.android.MediaManager;
66
import com.cloudinary.android.UploadRequest;
77

88
import java.util.Map;
99

1010
/**
11-
* Provide an implementation of this class to {@link CldAndroid#init(Context, SignatureProvider, Map)} to enable signed uploads.
11+
* Provide an implementation of this class to {@link MediaManager#init(Context, SignatureProvider, Map)} to enable signed uploads.
1212
* Note: If an api key and secret are provided to the library this interface is not required.
1313
*/
1414
public interface SignatureProvider {

0 commit comments

Comments
 (0)