-
Notifications
You must be signed in to change notification settings - Fork 33
Fix for Fragment having constructor with parameters. #986
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6e9847c
Fix for Fragment having constructor with parameters.
franco-zalamena-iterable d79cbc1
Using WARNING istead of ERROR level for deprecated IterableEmbeddedVi…
franco-zalamena-iterable 2c98252
ChangeLog with unreleased section back
franco-zalamena-iterable 28fa367
Better wording for fragment embedded view javadoc deprecated constructor
franco-zalamena-iterable File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
123 changes: 123 additions & 0 deletions
123
...pi-ui/src/main/java/com/iterable/iterableapi/ui/embedded/IterableEmbeddedViewArguments.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| package com.iterable.iterableapi.ui.embedded | ||
|
|
||
| import android.os.Bundle | ||
| import com.iterable.iterableapi.IterableEmbeddedMessage | ||
| import com.iterable.iterableapi.IterableLogger | ||
| import org.json.JSONException | ||
| import org.json.JSONObject | ||
|
|
||
| internal object IterableEmbeddedViewArguments { | ||
|
|
||
| private const val TAG = "IterableEmbeddedViewArgs" | ||
|
|
||
| // Argument keys | ||
| private const val KEY_VIEW_TYPE = "view_type" | ||
| private const val KEY_MESSAGE_JSON = "message_json" | ||
| private const val KEY_BG_COLOR = "bg_color" | ||
| private const val KEY_BORDER_COLOR = "border_color" | ||
| private const val KEY_BORDER_WIDTH = "border_width" | ||
| private const val KEY_BORDER_RADIUS = "border_radius" | ||
| private const val KEY_PRIMARY_BTN_BG = "primary_btn_bg" | ||
| private const val KEY_PRIMARY_BTN_TEXT = "primary_btn_text" | ||
| private const val KEY_SECONDARY_BTN_BG = "secondary_btn_bg" | ||
| private const val KEY_SECONDARY_BTN_TEXT = "secondary_btn_text" | ||
| private const val KEY_TITLE_COLOR = "title_color" | ||
| private const val KEY_BODY_COLOR = "body_color" | ||
|
|
||
| fun toBundle( | ||
| viewType: IterableEmbeddedViewType, | ||
| message: IterableEmbeddedMessage, | ||
| config: IterableEmbeddedViewConfig? | ||
| ): Bundle { | ||
| return Bundle().apply { | ||
| putString(KEY_VIEW_TYPE, viewType.name) | ||
| putString(KEY_MESSAGE_JSON, IterableEmbeddedMessage.toJSONObject(message).toString()) | ||
| putConfig(config) | ||
| } | ||
| } | ||
|
|
||
| fun getViewType(arguments: Bundle): IterableEmbeddedViewType { | ||
| val viewTypeName = arguments.getString(KEY_VIEW_TYPE) | ||
| return viewTypeName?.let { | ||
| try { | ||
| IterableEmbeddedViewType.valueOf(it) | ||
| } catch (e: IllegalArgumentException) { | ||
| IterableLogger.e(TAG, "Invalid view type: $it, defaulting to BANNER") | ||
| IterableEmbeddedViewType.BANNER | ||
| } | ||
| } ?: IterableEmbeddedViewType.BANNER | ||
| } | ||
|
|
||
| fun getMessage(arguments: Bundle): IterableEmbeddedMessage { | ||
| val messageJsonString = arguments.getString(KEY_MESSAGE_JSON) | ||
| return if (messageJsonString != null) { | ||
| try { | ||
| val messageJson = JSONObject(messageJsonString) | ||
| IterableEmbeddedMessage.fromJSONObject(messageJson) | ||
| } catch (e: JSONException) { | ||
| IterableLogger.e(TAG, "Failed to parse message JSON", e) | ||
| throw IllegalStateException( | ||
| "IterableEmbeddedView failed to restore message from saved state. Use newInstance() factory method to create this fragment." | ||
| ) | ||
| } | ||
| } else { | ||
| throw IllegalStateException( | ||
| "IterableEmbeddedView requires a message argument. Use newInstance() factory method to create this fragment." | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| fun getConfig(arguments: Bundle): IterableEmbeddedViewConfig? { | ||
| // Check if any config properties exist | ||
| val hasConfig = arguments.containsKey(KEY_BG_COLOR) || | ||
| arguments.containsKey(KEY_BORDER_COLOR) || | ||
| arguments.containsKey(KEY_BORDER_WIDTH) || | ||
| arguments.containsKey(KEY_BORDER_RADIUS) || | ||
| arguments.containsKey(KEY_PRIMARY_BTN_BG) || | ||
| arguments.containsKey(KEY_PRIMARY_BTN_TEXT) || | ||
| arguments.containsKey(KEY_SECONDARY_BTN_BG) || | ||
| arguments.containsKey(KEY_SECONDARY_BTN_TEXT) || | ||
| arguments.containsKey(KEY_TITLE_COLOR) || | ||
| arguments.containsKey(KEY_BODY_COLOR) | ||
|
|
||
| return if (hasConfig) { | ||
| IterableEmbeddedViewConfig( | ||
| backgroundColor = arguments.getIntOrNull(KEY_BG_COLOR), | ||
| borderColor = arguments.getIntOrNull(KEY_BORDER_COLOR), | ||
| borderWidth = arguments.getIntOrNull(KEY_BORDER_WIDTH), | ||
| borderCornerRadius = arguments.getFloatOrNull(KEY_BORDER_RADIUS), | ||
| primaryBtnBackgroundColor = arguments.getIntOrNull(KEY_PRIMARY_BTN_BG), | ||
| primaryBtnTextColor = arguments.getIntOrNull(KEY_PRIMARY_BTN_TEXT), | ||
| secondaryBtnBackgroundColor = arguments.getIntOrNull(KEY_SECONDARY_BTN_BG), | ||
| secondaryBtnTextColor = arguments.getIntOrNull(KEY_SECONDARY_BTN_TEXT), | ||
| titleTextColor = arguments.getIntOrNull(KEY_TITLE_COLOR), | ||
| bodyTextColor = arguments.getIntOrNull(KEY_BODY_COLOR) | ||
| ) | ||
| } else { | ||
| null | ||
| } | ||
| } | ||
|
|
||
| private fun Bundle.putConfig(config: IterableEmbeddedViewConfig?) { | ||
| config?.let { cfg -> | ||
| cfg.backgroundColor?.let { putInt(KEY_BG_COLOR, it) } | ||
| cfg.borderColor?.let { putInt(KEY_BORDER_COLOR, it) } | ||
| cfg.borderWidth?.let { putInt(KEY_BORDER_WIDTH, it) } | ||
| cfg.borderCornerRadius?.let { putFloat(KEY_BORDER_RADIUS, it) } | ||
| cfg.primaryBtnBackgroundColor?.let { putInt(KEY_PRIMARY_BTN_BG, it) } | ||
| cfg.primaryBtnTextColor?.let { putInt(KEY_PRIMARY_BTN_TEXT, it) } | ||
| cfg.secondaryBtnBackgroundColor?.let { putInt(KEY_SECONDARY_BTN_BG, it) } | ||
| cfg.secondaryBtnTextColor?.let { putInt(KEY_SECONDARY_BTN_TEXT, it) } | ||
| cfg.titleTextColor?.let { putInt(KEY_TITLE_COLOR, it) } | ||
| cfg.bodyTextColor?.let { putInt(KEY_BODY_COLOR, it) } | ||
| } | ||
| } | ||
|
|
||
| private fun Bundle.getIntOrNull(key: String): Int? { | ||
| return if (containsKey(key)) getInt(key) else null | ||
| } | ||
|
|
||
| private fun Bundle.getFloatOrNull(key: String): Float? { | ||
| return if (containsKey(key)) getFloat(key) else null | ||
| } | ||
| } |
2 changes: 0 additions & 2 deletions
2
...leapi-ui/src/main/java/com/iterable/iterableapi/ui/embedded/IterableEmbeddedViewConfig.kt
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow a dedicated class for arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that was a lot of variables and it really clustered the fragment, let me know if it is ok