diff --git a/app/src/full/java/org/fdroid/fdroid/views/swap/JoinWifiView.java b/app/src/full/java/org/fdroid/fdroid/views/swap/JoinWifiView.java deleted file mode 100644 index ac8454e47..000000000 --- a/app/src/full/java/org/fdroid/fdroid/views/swap/JoinWifiView.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.fdroid.fdroid.views.swap; - -import android.annotation.TargetApi; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.wifi.WifiManager; -import android.support.v4.content.LocalBroadcastManager; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; -import org.fdroid.fdroid.FDroidApp; -import org.fdroid.fdroid.R; -import org.fdroid.fdroid.localrepo.SwapView; -import org.fdroid.fdroid.net.WifiStateChangeService; - -public class JoinWifiView extends SwapView { - - public JoinWifiView(Context context) { - super(context); - } - - public JoinWifiView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public JoinWifiView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @TargetApi(21) - public JoinWifiView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - openAvailableNetworks(); - } - }); - refreshWifiState(); - - LocalBroadcastManager.getInstance(getActivity()).registerReceiver( - onWifiStateChange, - new IntentFilter(WifiStateChangeService.BROADCAST) - ); - } - - /** - * Remove relevant listeners/receivers/etc so that they do not receive and process events - * when this view is not in use. - */ - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - - LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(onWifiStateChange); - } - - // TODO: Listen for "Connecting..." state and reflect that in the view too. - private void refreshWifiState() { - TextView descriptionView = (TextView) findViewById(R.id.text_description); - ImageView wifiIcon = (ImageView) findViewById(R.id.wifi_icon); - TextView ssidView = (TextView) findViewById(R.id.wifi_ssid); - TextView tapView = (TextView) findViewById(R.id.wifi_available_networks_prompt); - if (TextUtils.isEmpty(FDroidApp.bssid) && !TextUtils.isEmpty(FDroidApp.ipAddressString)) { - // empty bssid with an ipAddress means hotspot mode - descriptionView.setText(R.string.swap_join_this_hotspot); - wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.hotspot)); - ssidView.setText(R.string.swap_active_hotspot); - tapView.setText(R.string.swap_switch_to_wifi); - } else if (TextUtils.isEmpty(FDroidApp.ssid)) { - // not connected to or setup with any wifi network - descriptionView.setText(R.string.swap_join_same_wifi); - wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.wifi)); - ssidView.setText(R.string.swap_no_wifi_network); - tapView.setText(R.string.swap_view_available_networks); - } else { - // connected to a regular wifi network - descriptionView.setText(R.string.swap_join_same_wifi); - wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.wifi)); - ssidView.setText(FDroidApp.ssid); - tapView.setText(R.string.swap_view_available_networks); - } - } - - private void openAvailableNetworks() { - getActivity().startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); - } - - private final BroadcastReceiver onWifiStateChange = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - refreshWifiState(); - } - }; -} diff --git a/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 9b706905a..719bf0340 100644 --- a/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/app/src/full/java/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -912,6 +912,9 @@ public class SwapWorkflowActivity extends AppCompatActivity { String qrUriString = null; switch (currentView.getLayoutResId()) { + case R.layout.swap_join_wifi: + setUpJoinWifi(); + return; case R.layout.swap_send_fdroid: qrUriString = buttonLabel; break; @@ -961,6 +964,39 @@ public class SwapWorkflowActivity extends AppCompatActivity { } } + // TODO: Listen for "Connecting..." state and reflect that in the view too. + private void setUpJoinWifi() { + currentView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + startActivity(new Intent(WifiManager.ACTION_PICK_WIFI_NETWORK)); + } + }); + TextView descriptionView = container.findViewById(R.id.text_description); + ImageView wifiIcon = container.findViewById(R.id.wifi_icon); + TextView ssidView = container.findViewById(R.id.wifi_ssid); + TextView tapView = container.findViewById(R.id.wifi_available_networks_prompt); + if (TextUtils.isEmpty(FDroidApp.bssid) && !TextUtils.isEmpty(FDroidApp.ipAddressString)) { + // empty bssid with an ipAddress means hotspot mode + descriptionView.setText(R.string.swap_join_this_hotspot); + wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.hotspot)); + ssidView.setText(R.string.swap_active_hotspot); + tapView.setText(R.string.swap_switch_to_wifi); + } else if (TextUtils.isEmpty(FDroidApp.ssid)) { + // not connected to or setup with any wifi network + descriptionView.setText(R.string.swap_join_same_wifi); + wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.wifi)); + ssidView.setText(R.string.swap_no_wifi_network); + tapView.setText(R.string.swap_view_available_networks); + } else { + // connected to a regular wifi network + descriptionView.setText(R.string.swap_join_same_wifi); + wifiIcon.setImageDrawable(getResources().getDrawable(R.drawable.wifi)); + ssidView.setText(FDroidApp.ssid); + tapView.setText(R.string.swap_view_available_networks); + } + } + private void setUpUseBluetoothButton() { Button useBluetooth = findViewById(R.id.btn_use_bluetooth); if (useBluetooth != null) { diff --git a/app/src/full/res/layout/swap_join_wifi.xml b/app/src/full/res/layout/swap_join_wifi.xml index b1e1146cc..6cce7801b 100644 --- a/app/src/full/res/layout/swap_join_wifi.xml +++ b/app/src/full/res/layout/swap_join_wifi.xml @@ -1,6 +1,6 @@ - - \ No newline at end of file + \ No newline at end of file