Add non-interactive mode to sample app
Summary: This can be used in integration tests/headless to create some data to match against. Ideally, headless also will need some mechanism to be told to exit, but that's a separate issue. Reviewed By: jknoxville Differential Revision: D14387494 fbshipit-source-id: 88d7c27e342fb0b26251e6edf12e7b922d5144c0
This commit is contained in:
committed by
Facebook Github Bot
parent
b675d1c6b5
commit
69dd6e4fc1
@@ -0,0 +1,79 @@
|
|||||||
|
package com.facebook.flipper.sample;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
import com.facebook.flipper.android.AndroidFlipperClient;
|
||||||
|
import com.facebook.flipper.core.FlipperClient;
|
||||||
|
import com.facebook.flipper.plugins.example.ExampleFlipperPlugin;
|
||||||
|
import java.io.IOException;
|
||||||
|
import okhttp3.Call;
|
||||||
|
import okhttp3.Callback;
|
||||||
|
import okhttp3.FormBody;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
final class ExampleActions {
|
||||||
|
|
||||||
|
static void sendPostRequest() {
|
||||||
|
final RequestBody formBody =
|
||||||
|
new FormBody.Builder().add("app", "Flipper").add("remarks", "Its awesome").build();
|
||||||
|
|
||||||
|
final Request request =
|
||||||
|
new Request.Builder()
|
||||||
|
.url("https://demo9512366.mockable.io/SonarPost")
|
||||||
|
.post(formBody)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
FlipperSampleApplication.sOkHttpClient
|
||||||
|
.newCall(request)
|
||||||
|
.enqueue(
|
||||||
|
new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(final Call call, final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.d("Flipper", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(final Call call, final Response response) throws IOException {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
Log.d("Flipper", response.body().string());
|
||||||
|
} else {
|
||||||
|
Log.d("Flipper", "not successful");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sendGetRequest() {
|
||||||
|
final Request request =
|
||||||
|
new Request.Builder().url("https://api.github.com/repos/facebook/yoga").get().build();
|
||||||
|
FlipperSampleApplication.sOkHttpClient
|
||||||
|
.newCall(request)
|
||||||
|
.enqueue(
|
||||||
|
new Callback() {
|
||||||
|
@Override
|
||||||
|
public void onFailure(final Call call, final IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.d("Flipper", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(final Call call, final Response response) throws IOException {
|
||||||
|
if (response.isSuccessful()) {
|
||||||
|
Log.d("Flipper", response.body().string());
|
||||||
|
} else {
|
||||||
|
Log.d("Flipper", "not successful");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void sendNotification() {
|
||||||
|
final FlipperClient client = AndroidFlipperClient.getInstanceIfInitialized();
|
||||||
|
if (client != null) {
|
||||||
|
final ExampleFlipperPlugin plugin = client.getPluginByClass(ExampleFlipperPlugin.class);
|
||||||
|
plugin.triggerNotification();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,5 +28,12 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
final ExampleFlipperPlugin samplePlugin = client.getPluginByClass(ExampleFlipperPlugin.class);
|
final ExampleFlipperPlugin samplePlugin = client.getPluginByClass(ExampleFlipperPlugin.class);
|
||||||
samplePlugin.setActivity(this);
|
samplePlugin.setActivity(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getIntent().getBooleanExtra("NON_INTERACTIVE_RUN", false)) {
|
||||||
|
ExampleActions.sendGetRequest();
|
||||||
|
ExampleActions.sendPostRequest();
|
||||||
|
ExampleActions.sendNotification();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,9 @@
|
|||||||
package com.facebook.flipper.sample;
|
package com.facebook.flipper.sample;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
|
||||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||||
import com.facebook.drawee.interfaces.DraweeController;
|
import com.facebook.drawee.interfaces.DraweeController;
|
||||||
import com.facebook.flipper.android.AndroidFlipperClient;
|
|
||||||
import com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity;
|
import com.facebook.flipper.android.diagnostics.FlipperDiagnosticActivity;
|
||||||
import com.facebook.flipper.core.FlipperClient;
|
|
||||||
import com.facebook.flipper.core.FlipperPlugin;
|
|
||||||
import com.facebook.flipper.plugins.example.ExampleFlipperPlugin;
|
|
||||||
import com.facebook.litho.ClickEvent;
|
import com.facebook.litho.ClickEvent;
|
||||||
import com.facebook.litho.Column;
|
import com.facebook.litho.Column;
|
||||||
import com.facebook.litho.Component;
|
import com.facebook.litho.Component;
|
||||||
@@ -28,13 +23,6 @@ import com.facebook.litho.annotations.OnUpdateState;
|
|||||||
import com.facebook.litho.annotations.State;
|
import com.facebook.litho.annotations.State;
|
||||||
import com.facebook.litho.fresco.FrescoImage;
|
import com.facebook.litho.fresco.FrescoImage;
|
||||||
import com.facebook.litho.widget.Text;
|
import com.facebook.litho.widget.Text;
|
||||||
import java.io.IOException;
|
|
||||||
import okhttp3.Call;
|
|
||||||
import okhttp3.Callback;
|
|
||||||
import okhttp3.FormBody;
|
|
||||||
import okhttp3.Request;
|
|
||||||
import okhttp3.RequestBody;
|
|
||||||
import okhttp3.Response;
|
|
||||||
|
|
||||||
@LayoutSpec
|
@LayoutSpec
|
||||||
public class RootComponentSpec {
|
public class RootComponentSpec {
|
||||||
@@ -80,72 +68,17 @@ public class RootComponentSpec {
|
|||||||
|
|
||||||
@OnEvent(ClickEvent.class)
|
@OnEvent(ClickEvent.class)
|
||||||
static void hitGetRequest(final ComponentContext c) {
|
static void hitGetRequest(final ComponentContext c) {
|
||||||
|
ExampleActions.sendGetRequest();
|
||||||
final Request request =
|
|
||||||
new Request.Builder().url("https://api.github.com/repos/facebook/yoga").get().build();
|
|
||||||
FlipperSampleApplication.sOkHttpClient
|
|
||||||
.newCall(request)
|
|
||||||
.enqueue(
|
|
||||||
new Callback() {
|
|
||||||
@Override
|
|
||||||
public void onFailure(final Call call, final IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.d("Flipper", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(final Call call, final Response response) throws IOException {
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
Log.d("Flipper", response.body().string());
|
|
||||||
} else {
|
|
||||||
Log.d("Flipper", "not successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnEvent(ClickEvent.class)
|
@OnEvent(ClickEvent.class)
|
||||||
static void hitPostRequest(final ComponentContext c) {
|
static void hitPostRequest(final ComponentContext c) {
|
||||||
|
ExampleActions.sendPostRequest();
|
||||||
final RequestBody formBody =
|
|
||||||
new FormBody.Builder().add("app", "Flipper").add("remarks", "Its awesome").build();
|
|
||||||
|
|
||||||
final Request request =
|
|
||||||
new Request.Builder()
|
|
||||||
.url("https://demo9512366.mockable.io/SonarPost")
|
|
||||||
.post(formBody)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
FlipperSampleApplication.sOkHttpClient
|
|
||||||
.newCall(request)
|
|
||||||
.enqueue(
|
|
||||||
new Callback() {
|
|
||||||
@Override
|
|
||||||
public void onFailure(final Call call, final IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Log.d("Flipper", e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(final Call call, final Response response) throws IOException {
|
|
||||||
if (response.isSuccessful()) {
|
|
||||||
Log.d("Flipper", response.body().string());
|
|
||||||
} else {
|
|
||||||
Log.d("Flipper", "not successful");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnEvent(ClickEvent.class)
|
@OnEvent(ClickEvent.class)
|
||||||
static void triggerNotification(final ComponentContext c) {
|
static void triggerNotification(final ComponentContext c) {
|
||||||
FlipperClient client = AndroidFlipperClient.getInstanceIfInitialized();
|
ExampleActions.sendNotification();
|
||||||
if (client != null) {
|
|
||||||
FlipperPlugin plugin = client.getPlugin(ExampleFlipperPlugin.ID);
|
|
||||||
if (plugin instanceof ExampleFlipperPlugin) {
|
|
||||||
((ExampleFlipperPlugin) plugin).triggerNotification();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnEvent(ClickEvent.class)
|
@OnEvent(ClickEvent.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user