-
Notifications
You must be signed in to change notification settings - Fork 296
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from Countly/rc-api-turtledreams
[A/B API] Adding testFetchAllVariants
- Loading branch information
Showing
13 changed files
with
801 additions
and
12 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
105 changes: 105 additions & 0 deletions
105
app/src/main/java/ly/count/android/demo/ActivityExampleTests.java
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,105 @@ | ||
package ly.count.android.demo; | ||
|
||
import android.content.res.Configuration; | ||
import android.view.Gravity; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import java.util.Arrays; | ||
import java.util.Map; | ||
import ly.count.android.sdk.Countly; | ||
import ly.count.android.sdk.RequestResponse; | ||
import ly.count.android.sdk.RCVariantCallback; | ||
|
||
public class ActivityExampleTests extends AppCompatActivity { | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_example_tests); | ||
} | ||
|
||
// For fetching all variants with a button click | ||
public void onClickFetchAllVariants(View v) { | ||
Countly.sharedInstance().remoteConfig().testingFetchVariantInformation(new RCVariantCallback() { | ||
@Override | ||
public void callback(RequestResponse result, String error) { | ||
if (result == RequestResponse.SUCCESS) { | ||
Toast.makeText(getApplicationContext(), "Fetch finished", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// To get all variants from the storage and show them with a toast | ||
public void onClickVariantsPrintValues(View v) { | ||
Map<String, String[]> values = Countly.sharedInstance().remoteConfig().testingGetAllVariants(); | ||
if (values == null) { | ||
Countly.sharedInstance().L.w("No variants present"); | ||
return; | ||
} | ||
Countly.sharedInstance().L.d("Get all variants: " + values); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
sb.append("Stored Variant Values:\n"); | ||
for (Map.Entry<String, String[]> entry : values.entrySet()) { | ||
String key = entry.getKey(); | ||
String[] variants = entry.getValue(); | ||
sb.append(key).append(": ").append(Arrays.toString(variants)).append("\n"); | ||
} | ||
|
||
Toast t = Toast.makeText(getApplicationContext(), sb.toString(), Toast.LENGTH_LONG); | ||
t.setGravity(Gravity.BOTTOM, 0, 0); | ||
t.show(); | ||
} | ||
|
||
public void onClickEnrollVariant(View v) { | ||
Map<String, String[]> values = Countly.sharedInstance().remoteConfig().testingGetAllVariants(); | ||
if (values == null) { | ||
Countly.sharedInstance().L.w("No variants present"); | ||
return; | ||
} | ||
Countly.sharedInstance().L.d("Get all variants: [" + values.toString() + "]"); | ||
|
||
// Get the first key and variant | ||
String key = null; | ||
String variant = null; | ||
for (Map.Entry<String, String[]> entry : values.entrySet()) { | ||
key = entry.getKey(); | ||
variant = entry.getValue()[0]; // first variant | ||
break; // Get only the first key-value pair | ||
} | ||
|
||
Countly.sharedInstance().remoteConfig().testingEnrollIntoVariant(key, variant, new RCVariantCallback() { | ||
@Override | ||
public void callback(RequestResponse result, String error) { | ||
if (result == RequestResponse.SUCCESS) { | ||
Toast.makeText(getApplicationContext(), "Fetch finished", Toast.LENGTH_SHORT).show(); | ||
} else { | ||
Toast.makeText(getApplicationContext(), "Error: " + result, Toast.LENGTH_SHORT).show(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onStart() { | ||
super.onStart(); | ||
Countly.sharedInstance().onStart(this); | ||
} | ||
|
||
@Override | ||
public void onStop() { | ||
Countly.sharedInstance().onStop(); | ||
super.onStop(); | ||
} | ||
|
||
@Override | ||
public void onConfigurationChanged(Configuration newConfig) { | ||
super.onConfigurationChanged(newConfig); | ||
Countly.sharedInstance().onConfigurationChanged(newConfig); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ActivityExampleTests" | ||
> | ||
|
||
<LinearLayout | ||
android:layout_width="409dp" | ||
android:layout_height="729dp" | ||
android:gravity="center_vertical" | ||
android:orientation="vertical" | ||
android:padding="@dimen/activity_horizontal_margin" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
> | ||
<Button | ||
android:id="@+id/enroll_variant" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:onClick="onClickEnrollVariant" | ||
android:text="Enroll first variant" | ||
/> | ||
<Button | ||
android:id="@+id/get_all_variants" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:onClick="onClickVariantsPrintValues" | ||
android:text="get all variants" | ||
/> | ||
<Button | ||
android:id="@+id/fetch_ab_variants" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:onClick="onClickFetchAllVariants" | ||
android:text="Fetch All vARIANTS" | ||
/> | ||
</LinearLayout> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
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
Oops, something went wrong.