Skip to content

Commit

Permalink
Extract updateStatusText(), to match updateButtonState() method
Browse files Browse the repository at this point in the history
  • Loading branch information
buttercookie42 committed Dec 15, 2024
1 parent 633cc14 commit f29ba3b
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions app/src/main/java/de/buttercookie/simbadroid/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
Expand Down Expand Up @@ -73,20 +74,7 @@ protected void onCreate(Bundle savedInstanceState) {

SmbServiceStatusLiveData.get().observe(this, status -> {
updateButtonState(status);
if (!status.serviceRunning()) {
binding.serviceStatus.setText(R.string.status_server_off);
} else if (!status.serverRunning()) {
binding.serviceStatus.setText(R.string.message_server_waiting_wifi);
} else if (StringUtils.isBlank(status.mdnsAddress()) ||
StringUtils.isBlank(status.ipAddress())) {
binding.serviceStatus.setText(R.string.message_server_running);
} else {
binding.serviceStatus.setText(getStyledText(this,
R.string.status_server_running,
status.mdnsAddress(),
status.netBiosAddress(),
status.ipAddress()));
}
updateStatusText(status);
});
}

Expand Down Expand Up @@ -120,6 +108,25 @@ private void updateButtonState(SmbService.Status status) {
}
}

private void updateStatusText(SmbService.Status status) {
final TextView statusText = binding.serviceStatus;

if (!status.serviceRunning()) {
statusText.setText(R.string.status_server_off);
} else if (!status.serverRunning()) {
statusText.setText(R.string.message_server_waiting_wifi);
} else if (StringUtils.isBlank(status.mdnsAddress()) ||
StringUtils.isBlank(status.ipAddress())) {
statusText.setText(R.string.message_server_running);
} else {
statusText.setText(getStyledText(this,
R.string.status_server_running,
status.mdnsAddress(),
status.netBiosAddress(),
status.ipAddress()));
}
}

private void toggleSmbService() {
if (!mBound) {
Toast.makeText(this,
Expand Down

0 comments on commit f29ba3b

Please sign in to comment.