Skip to content

Commit

Permalink
refactor: comm
Browse files Browse the repository at this point in the history
  • Loading branch information
arifBurakDemiray committed Nov 1, 2024
1 parent 2fbc9f8 commit df97478
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
20 changes: 15 additions & 5 deletions sdk/src/main/java/ly/count/android/sdk/ModuleFeedback.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,22 @@ public void run() {
webViewClient.listener = new WebViewUrlListener() {
@Override
public boolean onUrl(String url, WebView webView) {
if (url.equals("https://countly_action_event/?cly_widget_command&close=1")) {
if (devCallback != null) {
devCallback.onFinished(null);
if (!url.startsWith(Utils.COMM_URL)) {
return false;
}

Map<String, String> params = Utils.splitIntoParams(url, L);
String widgetCommand = params.get("cly_widget_command");

if ("1".equals(widgetCommand)) {
String close = params.get("close");
if ("1".equals(close)) {
if (devCallback != null) {
devCallback.onFinished(null);
}
alert.cancel();
return true;
}
alert.cancel();
return true;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public class TransparentActivity extends Activity {
static final String CONFIGURATION_LANDSCAPE = "Landscape";
static final String CONFIGURATION_PORTRAIT = "Portrait";
static final String ORIENTATION = "orientation";
private static final String URL_START = "https://countly_action_event";
int currentOrientation = 0;
TransparentActivityConfig configLandscape = null;
TransparentActivityConfig configPortrait = null;
Expand Down Expand Up @@ -64,14 +63,14 @@ protected void onCreate(Bundle savedInstanceState) {
int height = config.height;

configLandscape.listeners.add((url, webView) -> {
if (url.startsWith(URL_START)) {
if (url.startsWith(Utils.COMM_URL)) {
return contentUrlAction(url, configLandscape, webView);
}
return false;
});

configPortrait.listeners.add((url, webView) -> {
if (url.startsWith(URL_START)) {
if (url.startsWith(Utils.COMM_URL)) {
return contentUrlAction(url, configPortrait, webView);
}
return false;
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/main/java/ly/count/android/sdk/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
import static android.content.Context.UI_MODE_SERVICE;

public class Utils {
/**
* This is a communication url between web views and the SDK
*/
protected static final String COMM_URL = "https://countly_action_event";
private static final ExecutorService bg = Executors.newSingleThreadExecutor();

public static Future<?> runInBackground(Runnable runnable) {
Expand Down

0 comments on commit df97478

Please sign in to comment.