Revise share-offline screen wording; always show connected peers counter

This commit is contained in:
Daniel Lublin
2021-08-10 11:46:25 +02:00
parent ebaa3271dd
commit 4eb5c2ac10
6 changed files with 48 additions and 32 deletions

View File

@@ -9,6 +9,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
@@ -43,6 +44,7 @@ public abstract class AbstractTabsFragment extends Fragment {
protected Button stopButton;
protected Button connectedButton;
protected TextView connectedView;
@Override
public void onAttach(Context context) {
@@ -85,6 +87,9 @@ public abstract class AbstractTabsFragment extends Fragment {
finishAfterTransition(requireActivity());
});
connectedButton = view.findViewById(R.id.connectedButton);
connectedView = view.findViewById(R.id.connectedView);
viewModel.getPeersConnectedEvent()
.observe(getViewLifecycleOwner(), this::onPeerConnected);
}
@Override
@@ -126,4 +131,13 @@ public abstract class AbstractTabsFragment extends Fragment {
}
}
private void onPeerConnected(int peers) {
if (peers == 0) {
connectedView.setText(R.string.hotspot_no_peers_connected);
} else {
connectedView.setText(getResources().getQuantityString(
R.plurals.hotspot_peers_connected, peers, peers));
}
}
}

View File

@@ -2,11 +2,9 @@ package org.briarproject.briar.android.hotspot;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
import org.briarproject.bramble.api.nullsafety.MethodsNotNullByDefault;
import org.briarproject.bramble.api.nullsafety.ParametersNotNullByDefault;
import org.briarproject.briar.R;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
@@ -23,8 +21,6 @@ public class HotspotFragment extends AbstractTabsFragment {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
connectedButton.setOnClickListener(v -> showNextFragment());
viewModel.getPeerConnectedEvent().observeEvent(getViewLifecycleOwner(),
this::onPeerConnected);
}
@Override
@@ -37,12 +33,6 @@ public class HotspotFragment extends AbstractTabsFragment {
return QrHotspotFragment.newInstance(true);
}
private void onPeerConnected(boolean connected) {
if (!connected) return;
Toast.makeText(requireContext(), R.string.hotspot_peer_connected,
Toast.LENGTH_LONG).show();
}
private void showNextFragment() {
Fragment f = new WebsiteFragment();
String tag = WebsiteFragment.TAG;

View File

@@ -66,7 +66,7 @@ class HotspotManager {
void onHotspotStarted(NetworkConfig networkConfig);
@UiThread
void onDeviceConnected();
void onPeersUpdated(int peers);
@UiThread
void onHotspotError(String error);
@@ -377,12 +377,11 @@ class HotspotManager {
private void requestGroupInfoForConnection() {
LOG.info("requestGroupInfo for connection");
GroupInfoListener groupListener = group -> {
if (group == null || group.getClientList().isEmpty()) {
handler.postDelayed(this::requestGroupInfoForConnection,
RETRY_DELAY_MILLIS);
} else {
listener.onDeviceConnected();
if (group != null) {
listener.onPeersUpdated(group.getClientList().size());
}
handler.postDelayed(this::requestGroupInfoForConnection,
RETRY_DELAY_MILLIS);
};
try {
if (channel == null) return;

View File

@@ -63,8 +63,8 @@ class HotspotViewModel extends DbViewModel
private final MutableLiveData<HotspotState> state =
new MutableLiveData<>();
private final MutableLiveEvent<Boolean> peerConnected =
new MutableLiveEvent<>();
private final MutableLiveData<Integer> peersConnected =
new MutableLiveData<>();
private final MutableLiveEvent<Uri> savedApkToUri =
new MutableLiveEvent<>();
@@ -137,8 +137,8 @@ class HotspotViewModel extends DbViewModel
@UiThread
@Override
public void onDeviceConnected() {
peerConnected.setEvent(true);
public void onPeersUpdated(int peers) {
peersConnected.setValue(peers);
}
@Override
@@ -213,8 +213,8 @@ class HotspotViewModel extends DbViewModel
return state;
}
LiveEvent<Boolean> getPeerConnectedEvent() {
return peerConnected;
LiveData<Integer> getPeersConnectedEvent() {
return peersConnected;
}
LiveEvent<Uri> getSavedApkToUri() {

View File

@@ -6,9 +6,10 @@
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/connectedButton"
app:layout_constraintBottom_toTopOf="@+id/connectedView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
@@ -51,14 +52,22 @@
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="@+id/connectedButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tabLayout" />
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<TextView
android:id="@+id/connectedView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:gravity="center"
android:text="@string/hotspot_no_peers_connected"
app:layout_constraintTop_toBottomOf="@+id/coordinatorLayout"
app:layout_constraintBottom_toTopOf="@+id/connectedButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="@+id/connectedButton"
style="@style/BriarButton"

View File

@@ -693,7 +693,7 @@
<string name="transports_help_text">Briar can connect to your contacts via the Internet, Wi-Fi or Bluetooth.\n\nAll Internet connections go through the Tor network for privacy.\n\nIf a contact can be reached by multiple methods, Briar uses them in parallel.</string>
<!-- Share app offline -->
<string name="hotspot_title">Share Briar offline</string>
<string name="hotspot_title">Share this app offline</string>
<string name="hotspot_intro">Share this app with someone nearby without Internet connection by using your phone\'s Wi-Fi.
\n\nYour phone will start a Wi-Fi hotspot. People nearby can connect to the hotspot and download the Briar app from your phone.</string>
<string name="hotspot_button_start_sharing">Start hotspot</string>
@@ -715,10 +715,14 @@
<!-- Wi-Fi setup -->
<!-- The %s placeholder will be replaced with the translation of 'hotspot_scanning_a_qr_code' -->
<string name="hotspot_manual_wifi">Your phone is providing a Wi-Fi hotspot. People who want to download Briar can connect to the hotspot by entering the details below or %s. When they have connected to the hotspot, press \'Next\'.</string>
<string name="hotspot_manual_wifi_ssid">Network name (SSID)</string>
<string name="hotspot_manual_wifi">Your phone is providing a Wi-Fi hotspot. People who want to download Briar can connect to the hotspot by adding it in their device\'s Wi-Fi settings using the details below or by %s. When they have connected to the hotspot, press \'Next\'.</string>
<string name="hotspot_manual_wifi_ssid">Network name</string>
<string name="hotspot_qr_wifi">Your phone is providing a Wi-Fi hotspot. People who want to download Briar can connect to the hotspot by scanning this QR code. When they have connected to the hotspot, press \'Next\'.</string>
<string name="hotspot_peer_connected">Successfully connected</string>
<string name="hotspot_no_peers_connected">No devices connected</string>
<plurals name="hotspot_peers_connected">
<item quantity="one">%s device connected</item>
<item quantity="other">%s devices connected</item>
</plurals>
<!-- Download link -->
<!-- The %s placeholder will be replaced with the translation of 'hotspot_scanning_a_qr_code' -->