-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new FrescoVitoComponents class that FrescoVitoProvider delegate…
…s to Differential Revision: D54695897 fbshipit-source-id: 260aa5f076328dece2307436c3d0b143cb150f97
- Loading branch information
1 parent
9208572
commit 2b854a6
Showing
5 changed files
with
90 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...ovider/src/main/java/com/facebook/fresco/vito/provider/components/FrescoVitoComponents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.fresco.vito.provider.components | ||
|
||
import com.facebook.common.logging.FLog | ||
import com.facebook.fresco.vito.core.FrescoController2 | ||
import com.facebook.fresco.vito.core.FrescoVitoConfig | ||
import com.facebook.fresco.vito.core.FrescoVitoPrefetcher | ||
import com.facebook.fresco.vito.core.VitoImagePipeline | ||
import java.lang.RuntimeException | ||
|
||
object FrescoVitoComponents { | ||
|
||
private var _implementation: Implementation? = null | ||
|
||
@JvmStatic | ||
@Synchronized | ||
fun getController(): FrescoController2 = getImplementation().getController() | ||
|
||
@JvmStatic | ||
@Synchronized | ||
fun getPrefetcher(): FrescoVitoPrefetcher = getImplementation().getPrefetcher() | ||
|
||
@JvmStatic | ||
@Synchronized | ||
fun getImagePipeline(): VitoImagePipeline = getImplementation().getImagePipeline() | ||
|
||
@JvmStatic @Synchronized fun getConfig(): FrescoVitoConfig = getImplementation().getConfig() | ||
|
||
/** | ||
* Reset the implementation. This will remove any implementation currently set up and has to be | ||
* used with caution. | ||
*/ | ||
@JvmStatic | ||
@Synchronized | ||
fun resetImplementation() { | ||
_implementation = null | ||
} | ||
|
||
@JvmStatic @Synchronized fun hasBeenInitialized(): Boolean = _implementation != null | ||
|
||
// We do not allow to re-initialize Vito directly. | ||
// You can use #resetImplementation() if you must manually tear down Vito. | ||
@JvmStatic | ||
@Synchronized | ||
fun getImplementation(): Implementation { | ||
return _implementation ?: throw RuntimeException("Fresco context provider must be set") | ||
} | ||
|
||
@JvmStatic | ||
@Synchronized | ||
fun setImplementation(implementation: Implementation) { | ||
// We do not allow to re-initialize Vito directly. | ||
// You can use #resetImplementation() if you must manually tear down Vito. | ||
if (_implementation != null) { | ||
FLog.e( | ||
"FrescoVitoProvider", | ||
"Fresco Vito already initialized! Vito must be initialized only once.") | ||
} | ||
_implementation = implementation | ||
} | ||
|
||
interface Implementation { | ||
fun getController(): FrescoController2 | ||
|
||
fun getPrefetcher(): FrescoVitoPrefetcher | ||
|
||
fun getImagePipeline(): VitoImagePipeline | ||
|
||
fun getConfig(): FrescoVitoConfig | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters