From f29ba3b8eb8d89820f5453eb7ac5b5ce5899ab1c Mon Sep 17 00:00:00 2001 From: Jan Henning Date: Sun, 15 Dec 2024 16:36:52 +0100 Subject: [PATCH] Extract updateStatusText(), to match updateButtonState() method --- .../buttercookie/simbadroid/MainActivity.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) 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,