Skip to content
Snippets Groups Projects
Commit 56c7ef02 authored by akwizgran's avatar akwizgran
Browse files

Show test phase in UI.

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