-
Notifications
You must be signed in to change notification settings - Fork 38
[SDK-500] Follow the system light/dark theme in HTML in-app messages #1084
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
Open
franco-zalamena-iterable
wants to merge
4
commits into
master
Choose a base branch
from
feature/SDK-500-inapp-daynight-theme
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
82b3668
[SDK-500] Follow the system light/dark theme in HTML in-app messages
franco-zalamena-iterable c34ff01
[SDK-500] Support custom in-app color schemes
franco-zalamena-iterable ee342eb
[SDK-500] Scope color scheme attributes to API 29
franco-zalamena-iterable d2991fb
Merge remote-tracking branch 'origin/master' into feature/SDK-500-ina…
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
21 changes: 21 additions & 0 deletions
21
iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppColorScheme.java
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,21 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| /** | ||
| * Controls the color scheme reported to HTML in-app messages. | ||
| */ | ||
| public enum IterableInAppColorScheme { | ||
| /** | ||
| * Follow the host activity's Android UI mode. | ||
| */ | ||
| AUTOMATIC, | ||
|
|
||
| /** | ||
| * Report a light color scheme to in-app message HTML. | ||
| */ | ||
| LIGHT, | ||
|
|
||
| /** | ||
| * Report a dark color scheme to in-app message HTML. | ||
| */ | ||
| DARK | ||
| } |
17 changes: 17 additions & 0 deletions
17
iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppColorSchemeProvider.java
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,17 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
|
|
||
| /** | ||
| * Supplies the color scheme to use when an HTML in-app message is created. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface IterableInAppColorSchemeProvider { | ||
| /** | ||
| * Returns the current color scheme for HTML in-app messages. | ||
| * | ||
| * @return the color scheme to use | ||
| */ | ||
| @NonNull | ||
| IterableInAppColorScheme getInAppColorScheme(); | ||
| } |
60 changes: 60 additions & 0 deletions
60
iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppColorSchemeResolver.java
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,60 @@ | ||
| package com.iterable.iterableapi; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
|
|
||
| final class IterableInAppColorSchemeResolver { | ||
| private static final String TAG = "IterableInAppColorScheme"; | ||
|
|
||
| private IterableInAppColorSchemeResolver() { | ||
| } | ||
|
|
||
| @NonNull | ||
| static IterableInAppColorScheme resolve() { | ||
| IterableConfig config = IterableApi.sharedInstance == null | ||
| ? null | ||
| : IterableApi.sharedInstance.config; | ||
| if (config == null) { | ||
| return IterableInAppColorScheme.AUTOMATIC; | ||
| } | ||
|
|
||
| IterableInAppColorSchemeProvider provider = config.inAppColorSchemeProvider; | ||
| if (provider == null) { | ||
| return config.inAppColorScheme; | ||
| } | ||
|
|
||
| try { | ||
| IterableInAppColorScheme colorScheme = provider.getInAppColorScheme(); | ||
| if (colorScheme != null) { | ||
| return colorScheme; | ||
| } | ||
| IterableLogger.e(TAG, "Color scheme provider returned null; using AUTOMATIC"); | ||
| } catch (Exception e) { | ||
| IterableLogger.e(TAG, "Color scheme provider failed; using AUTOMATIC", e); | ||
| } | ||
| return IterableInAppColorScheme.AUTOMATIC; | ||
| } | ||
|
|
||
| static int resolveDialogTheme() { | ||
| switch (resolve()) { | ||
| case LIGHT: | ||
| return R.style.Iterable_InAppDialog_Light; | ||
| case DARK: | ||
| return R.style.Iterable_InAppDialog_Dark; | ||
| case AUTOMATIC: | ||
| default: | ||
| return R.style.Iterable_InAppDialog; | ||
| } | ||
| } | ||
|
|
||
| static int resolveFragmentTheme() { | ||
| switch (resolve()) { | ||
| case LIGHT: | ||
| return R.style.Iterable_InAppFragment_Light; | ||
| case DARK: | ||
| return R.style.Iterable_InAppFragment_Dark; | ||
| case AUTOMATIC: | ||
| default: | ||
| return R.style.Iterable_InAppFragment; | ||
| } | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
|
|
||
| <style name="Iterable.InAppDialog.Light"> | ||
| <item name="android:isLightTheme">true</item> | ||
| </style> | ||
|
|
||
| <style name="Iterable.InAppDialog.Dark"> | ||
| <item name="android:isLightTheme">false</item> | ||
| </style> | ||
|
|
||
| <style name="Iterable.InAppFragment.Light"> | ||
| <item name="android:isLightTheme">true</item> | ||
| </style> | ||
|
|
||
| <style name="Iterable.InAppFragment.Dark"> | ||
| <item name="android:isLightTheme">false</item> | ||
| </style> | ||
| </resources> |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.