diff --git a/app/src/main/java/de/buttercookie/simbadroid/MainActivity.java b/app/src/main/java/de/buttercookie/simbadroid/MainActivity.java index 67c49e0..902eb10 100644 --- a/app/src/main/java/de/buttercookie/simbadroid/MainActivity.java +++ b/app/src/main/java/de/buttercookie/simbadroid/MainActivity.java @@ -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; @@ -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); }); } @@ -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,