Skip to content

Commit

Permalink
showing fallback text when no network interface is available and thus…
Browse files Browse the repository at this point in the history
… no QR code can be shown
  • Loading branch information
wolpi committed Apr 13, 2024
1 parent 6f82144 commit 9721224
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
10 changes: 10 additions & 0 deletions primitiveFTPd/res/layout/qr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
android:layout_marginStart="25dp"
android:contentDescription="@null" />


<TextView
android:id="@+id/qrFallbackTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="@string/qrFallback"
android:focusable="false"
android:visibility="gone"
/>
</LinearLayout>

</ScrollView>
3 changes: 2 additions & 1 deletion primitiveFTPd/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
<string name="iconKeysFingerprints">Keys Fingerprints</string>
<string name="iconCleanSpace">Clean Space</string>
<string name="iconAbout">About</string>
<string name="qrFallback">no network interfaces, no IP addresses, no QR code</string>
<string-array name="prefWhichServerToStartNames">
<item>FTP and SFTP</item>
<item>FTP only</item>
Expand All @@ -184,4 +185,4 @@
<item>1</item>
<item>2</item>
</string-array>
</resources>
</resources>
21 changes: 14 additions & 7 deletions primitiveFTPd/src/org/primftpd/ui/QrFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -81,6 +85,12 @@ public void onResume() {

List<String> 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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9721224

Please sign in to comment.