Commit 56c7ef02 authored by akwizgran's avatar akwizgran

Show test phase in UI.

parent b7f7084c
......@@ -20,13 +20,16 @@ import static org.briarproject.interferometer.MainViewModel.ConnectionState.DOWN
import static org.briarproject.interferometer.MainViewModel.ConnectionState.UPLOADING;
import static org.briarproject.interferometer.MainViewModel.StartResult.INVALID_ADDRESS;
import static org.briarproject.interferometer.MainViewModel.StartResult.NO_BLUETOOTH;
import static org.briarproject.interferometer.MainViewModel.TestPhase.BASELINE;
import static org.briarproject.interferometer.MainViewModel.TestPhase.BLUETOOTH;
import static org.briarproject.interferometer.MainViewModel.TestPhase.READY;
public class MainActivity extends AppCompatActivity {
private MainViewModel viewModel;
private EditText serverAddressEditText;
private TextView throughputTextView;
private Button testButton;
private TextView testPhaseTextView, throughputTextView;
private ConnectionState state = DISCONNECTED;
private long throughput = 0;
......@@ -35,30 +38,27 @@ public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewModel = new ViewModelProvider(this).get(MainViewModel.class);
serverAddressEditText = findViewById(R.id.server_address_edit_text);
testPhaseTextView = findViewById(R.id.test_phase_text_view);
throughputTextView = findViewById(R.id.throughput_text_view);
testButton = findViewById(R.id.test_button);
showThroughput(state, throughput);
Button testButton = findViewById(R.id.test_button);
viewModel.getTestPhase().observe(this, phase -> {
if (phase == READY) testButton.setText(R.string.start_test);
else testButton.setText(R.string.stop_test);
});
viewModel.getTestPhase().observe(this, this::showTestPhase);
viewModel.getConnectionState().observe(this, state -> {
this.state = state;
showThroughput(state, throughput);
showThroughput();
});
viewModel.getThroughput().observe(this, throughput -> {
this.throughput = throughput;
showThroughput(state, throughput);
showThroughput();
});
}
private void showThroughput(ConnectionState state, long throughput) {
private void showThroughput() {
if (state == DISCONNECTED) {
throughputTextView.setText(null);
} else if (state == DOWNLOADING) {
......@@ -68,6 +68,19 @@ public class MainActivity extends AppCompatActivity {
}
}
private void showTestPhase(TestPhase phase) {
if (phase == READY) {
testButton.setText(R.string.start_test);
testPhaseTextView.setText(null);
} else if (phase == BASELINE) {
testButton.setText(R.string.stop_test);
testPhaseTextView.setText(R.string.testing_baseline);
} else if (phase == BLUETOOTH) {
testButton.setText(R.string.stop_test);
testPhaseTextView.setText(R.string.testing_bluetooth);
}
}
public void onTestClick(View view) {
TestPhase phase = viewModel.getTestPhase().getValue();
if (phase == null || phase == READY) {
......
......@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:padding="32dp"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
......@@ -12,7 +12,6 @@
android:id="@+id/server_address_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="@string/server_address"
android:inputType="textUri"
android:text="@string/default_server_address"
......@@ -27,11 +26,16 @@
android:text="@string/start_test"
tools:ignore="ButtonStyle" />
<TextView
android:id="@+id/test_phase_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/throughput_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="" />
</LinearLayout>
\ No newline at end of file
......@@ -9,6 +9,9 @@
<string name="start_test">Start test</string>
<string name="stop_test">Stop test</string>
<string name="testing_baseline">Testing with Bluetooth disabled</string>
<string name="testing_bluetooth">Testing with Bluetooth enabled</string>
<string name="download_format">Download: %,d bytes/sec</string>
<string name="upload_format">Upload: %,d bytes/sec</string>
</resources>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment