Skip to content

Commit

Permalink
Disable the button when no Wifi is available
Browse files Browse the repository at this point in the history
  • Loading branch information
buttercookie42 committed Dec 15, 2024
1 parent db8fca3 commit 633cc14
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.widget.Toast;
Expand Down Expand Up @@ -60,6 +61,9 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.toggleService.setOnClickListener(v -> toggleSmbService());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
binding.toggleService.setAllowClickWhenDisabled(true);
}

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
Expand Down Expand Up @@ -108,9 +112,11 @@ private void updateButtonState(SmbService.Status status) {
if (status.serviceRunning()) {
button.setText(R.string.button_stop_server);
button.setIcon(AppCompatResources.getDrawable(this, R.drawable.ic_stop));
button.setEnabled(true);
} else {
button.setText(R.string.button_start_server);
button.setIcon(AppCompatResources.getDrawable(this, R.drawable.ic_start));
button.setEnabled(mBound && mService.isWifiAvailable());
}
}

Expand Down

0 comments on commit 633cc14

Please sign in to comment.