From 972122457143b6b7705f5da3a3e71df1e768ab9c Mon Sep 17 00:00:00 2001 From: wolpi Date: Sat, 13 Apr 2024 18:21:20 +0200 Subject: [PATCH] showing fallback text when no network interface is available and thus no QR code can be shown --- primitiveFTPd/res/layout/qr.xml | 10 +++++++++ primitiveFTPd/res/values/strings.xml | 3 ++- .../src/org/primftpd/ui/QrFragment.java | 21 ++++++++++++------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/primitiveFTPd/res/layout/qr.xml b/primitiveFTPd/res/layout/qr.xml index b6b7ad66..1ecb004e 100644 --- a/primitiveFTPd/res/layout/qr.xml +++ b/primitiveFTPd/res/layout/qr.xml @@ -26,6 +26,16 @@ android:layout_marginStart="25dp" android:contentDescription="@null" /> + + diff --git a/primitiveFTPd/res/values/strings.xml b/primitiveFTPd/res/values/strings.xml index 1840ff62..5da31f3e 100644 --- a/primitiveFTPd/res/values/strings.xml +++ b/primitiveFTPd/res/values/strings.xml @@ -164,6 +164,7 @@ Keys Fingerprints Clean Space About + no network interfaces, no IP addresses, no QR code FTP and SFTP FTP only @@ -184,4 +185,4 @@ 1 2 - \ No newline at end of file + diff --git a/primitiveFTPd/src/org/primftpd/ui/QrFragment.java b/primitiveFTPd/src/org/primftpd/ui/QrFragment.java index e3e3e47e..6492c62b 100644 --- a/primitiveFTPd/src/org/primftpd/ui/QrFragment.java +++ b/primitiveFTPd/src/org/primftpd/ui/QrFragment.java @@ -11,6 +11,7 @@ import android.widget.ImageView; import android.widget.RadioButton; import android.widget.RadioGroup; +import android.widget.TextView; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; @@ -32,6 +33,7 @@ import java.util.List; import java.util.Map; +import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; public class QrFragment extends Fragment implements RecreateLogger { @@ -42,9 +44,10 @@ public class QrFragment extends Fragment implements RecreateLogger { private ImageView qrImage; private int width; private int height; + private TextView fallbackTextView; @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); @@ -53,6 +56,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, urlsParent = view.findViewById(R.id.qrUrlsParent); qrImage = view.findViewById(R.id.qrImage); + fallbackTextView = view.findViewById(R.id.qrFallbackTextView); width = (int) (getResources().getDisplayMetrics().widthPixels * 0.9); height = getResources().getDisplayMetrics().heightPixels / 2; @@ -81,6 +85,12 @@ public void onResume() { List urls = new ArrayList<>(); + if (ipAddressTexts.isEmpty()) { + fallbackTextView.setVisibility(View.VISIBLE); + } else { + fallbackTextView.setVisibility(View.GONE); + } + for (String ipAddressText : ipAddressTexts) { boolean ipv6 = ipAddressProvider.isIpv6(ipAddressText); if (!ipv6 && !showIpv4) { @@ -113,12 +123,9 @@ public void onResume() { radioButton.setText(url); radioGroup.addView(radioButton); final QrFragment fragment = this; - radioButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Bitmap qr = fragment.generateQr(url, darkMode); - fragment.qrImage.setImageBitmap(qr); - } + radioButton.setOnClickListener(v -> { + Bitmap qr = fragment.generateQr(url, darkMode); + fragment.qrImage.setImageBitmap(qr); }); } urlsParent.addView(radioGroup);