This file contains hidden or 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
fun Context.setDefaultRCFromFile() : Boolean = | |
File(filesDir, LOCAL_RC_JSON).takeIf { it.exists() }?.let {file-> | |
val defaultRC = mutableMapOf<String, Any>() | |
gson.fromJson(file.inputStream().convertLocalJsonToString(), RCModel::class.java)?.let { rcModel -> | |
defaultRC[RemoteConfigConstants.RC_JSON_PARAM_NAME] = file.inputStream().convertLocalJsonToString() | |
remoteConfigManager.updateRc(rcModel) | |
remoteConfigManager.updateFetchState(true, currentDateTimestamp) | |
} | |
app?.firebaseRemoteConfig?.setDefaults(defaultRC) | |
file.inputStream().close() |
This file contains hidden or 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
fetchAndActivate().addOnCompleteListener { task -> | |
task.isSuccessful.takeIf { it }?.apply { | |
context.saveFile(getString(RemoteConfigConstants.RC_JSON_PARAM_NAME).toByteArray(), | |
LOCAL_RC_JSON) | |
} | |
} |
This file contains hidden or 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
/** | |
* Context extension function which will save the file into the device local storage. | |
* @param data - content of the file. | |
* @param fileName - name of the final file. | |
*/ | |
fun Context.saveFile(data: ByteArray, fileName: String) = | |
openFileOutput(fileName, Context.MODE_PRIVATE)?.apply { | |
write(data) | |
close() | |
} |
This file contains hidden or 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
class RemoteConfigFunctions(private val gson: Gson, private val context: Context, | |
private val app: App?, | |
private val remoteConfigManager: RemoteConfigManager) { | |
companion object { | |
private const val TAG = "RemoteConfigFunctions:" | |
private const val RECEIVER_TAG = "FCM Receiver:" | |
} | |
/** |
This file contains hidden or 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
class RemoteConfigConstants { | |
companion object { | |
const val DEFAULT_LOCAL_RC_JSON = "RemoteConfig.json" | |
const val LOCAL_RC_JSON = "DeviceRemoteConfig.json" | |
const val RC_JSON_PARAM_NAME = "config_json" | |
const val RC_EXTRA_BACK_NOTIFICATION = "rc_extra_back_notification" | |
} | |
} |
This file contains hidden or 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
override fun handleRcUpdate(isItServiceUpdate: Boolean, | |
isFeatureOnBoardingVisible: Boolean) { | |
super.handleRcUpdate(isItServiceUpdate, isFeatureOnBoardingVisible) | |
when { | |
isItServiceUpdate -> updateUrls() | |
isFeatureOnBoardingVisible -> | |
navigateToOnBoardingMenu(true) | |
} | |
} |
This file contains hidden or 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
abstract class BaseActivity : AppCompatActivity() { | |
companion object { | |
private const val TAG = "BaseActivity:" | |
private const val RECEIVER_TAG = "BaseActivity-Receiver:" | |
} | |
private val localBroadcastManager: LocalBroadcastManager by lazy { | |
LocalBroadcastManager.getInstance(this) | |
} |
This file contains hidden or 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
class FCMService : FirebaseMessagingService() { | |
companion object { | |
private const val TAG = "FCMService" | |
private const val RECEIVER_TAG = "Receiver:" | |
const val IN_AP_EX_STR_TITLE = "in_ap_ex_str_title" | |
const val IN_AP_EX_STR_BODY = "in_ap_ex_str_body" | |
} | |
@SuppressLint("TimberArgCount") |
This file contains hidden or 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
/** | |
* App extension function, which return reference on RemoteConfigFunctions. | |
* @return reference on RemoteConfigFunctions. | |
*/ | |
fun App.getRCF() = RemoteConfigFunctions(gson, this, this, remoteConfigManager) |
This file contains hidden or 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
override fun onCreate() { | |
super.onCreate() | |
initFirebase() | |
this.getRCF().setDefaultRC() | |
} | |
private fun initFirebase() { | |
FirebaseApp.initializeApp(this) | |
firebaseRemoteConfig = FirebaseRemoteConfig.getInstance() | |
val configSettings = FirebaseRemoteConfigSettings.Builder() | |
.setFetchTimeoutInSeconds(0) |