From 7401366ac9b2221cb40005b5454c0e069b0fa393 Mon Sep 17 00:00:00 2001
From: Hans-Christoph Steiner <hans@eds.org>
Date: Wed, 7 May 2014 22:03:35 -0400
Subject: [PATCH] quick improvement of LocalRepoActivity layout

This is meant to try to make the on/off state of the webserver that serves
the local repo more apparent.
---
 res/layout/local_repo_activity.xml            | 35 ++++++++++++++++---
 res/values/strings.xml                        |  3 ++
 .../fdroid/views/LocalRepoActivity.java       | 30 +++++++++-------
 3 files changed, 51 insertions(+), 17 deletions(-)

diff --git a/res/layout/local_repo_activity.xml b/res/layout/local_repo_activity.xml
index 81ba324ca..17908b176 100644
--- a/res/layout/local_repo_activity.xml
+++ b/res/layout/local_repo_activity.xml
@@ -4,23 +4,50 @@
     android:layout_height="fill_parent"
     android:orientation="vertical" >
 
-    <ToggleButton
+    <Button
+        android:id="@+id/enable_wifi"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:text="@string/enable_wifi" />
+
+    <CheckBox
         android:id="@+id/repoSwitch"
         android:layout_width="match_parent"
-        android:layout_height="wrap_content" />
+        android:layout_height="wrap_content"
+        android:gravity="center"
+        android:padding="15dp"
+        android:text="@string/touch_to_turn_on_local_repo" />
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <TextView
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:text="@string/sharing_uri" />
+
+        <TextView
+            android:id="@+id/sharing_uri"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_marginLeft="15dp"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:textStyle="bold"
+            android:typeface="monospace" />
+    </LinearLayout>
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content" >
 
         <TextView
-            android:id="@+id/wifiNetwork"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:text="@string/wifi_network" />
 
         <TextView
-            android:id="@+id/wifiNetworkName"
+            android:id="@+id/wifi_network"
             android:layout_width="wrap_content"
             android:layout_height="match_parent"
             android:layout_marginLeft="15dp"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ae4f18a66..86fae6b4a 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -156,6 +156,8 @@
 	<string name="local_repo_running">Your local FDroid repo is accessible.</string>
 	<string name="setup_repo">Setup Local Repo</string>
 	<string name="touch_to_configure_local_repo">Touch to setup your local repo.</string>
+	<string name="touch_to_turn_on_local_repo">Touch to turn on your local repo.</string>
+	<string name="touch_to_turn_off_local_repo">Touch to turn off your local repo.</string>
 	<string name="updating">Updating&#8230;</string>
 	<string name="update_repo">Update Repo</string>
 	<string name="deleting_repo">Deleting current repo&#8230;</string>
@@ -168,6 +170,7 @@
 	<string name="icon">icon</string>
 	<string name="fingerprint">Fingerprint:</string>
 	<string name="wifi_network">WiFi Network:</string>
+	<string name="sharing_uri">Sharing URL:</string>
 	<string name="enable_wifi">Enable WiFi</string>
 	<string name="enabling_wifi">Enabling WiFi&#8230;</string>
 	<string name="same_wifi_instructions">To connect to other people\'s devices, make sure both devices are on the same WiFi network.  Then either type the URL above into F-Droid, or scan this QR Code:</string>
diff --git a/src/org/fdroid/fdroid/views/LocalRepoActivity.java b/src/org/fdroid/fdroid/views/LocalRepoActivity.java
index b54904154..d71d30129 100644
--- a/src/org/fdroid/fdroid/views/LocalRepoActivity.java
+++ b/src/org/fdroid/fdroid/views/LocalRepoActivity.java
@@ -19,9 +19,7 @@ import android.support.v4.content.LocalBroadcastManager;
 import android.text.TextUtils;
 import android.util.Log;
 import android.view.*;
-import android.widget.TextView;
-import android.widget.Toast;
-import android.widget.ToggleButton;
+import android.widget.*;
 
 import org.fdroid.fdroid.*;
 import org.fdroid.fdroid.net.WifiStateChangeService;
@@ -33,7 +31,8 @@ public class LocalRepoActivity extends Activity {
     private ProgressDialog repoProgress;
 
     private WifiManager wifiManager;
-    private ToggleButton repoSwitch;
+    private Button enableWifiButton;
+    private CheckBox repoSwitch;
 
     private int SET_IP_ADDRESS = 7345;
     private int UPDATE_REPO = 7346;
@@ -45,7 +44,8 @@ public class LocalRepoActivity extends Activity {
         ((FDroidApp) getApplication()).applyTheme(this);
         setContentView(R.layout.local_repo_activity);
 
-        repoSwitch = (ToggleButton) findViewById(R.id.repoSwitch);
+        enableWifiButton = (Button) findViewById(R.id.enable_wifi);
+        repoSwitch = (CheckBox) findViewById(R.id.repoSwitch);
         wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
     }
 
@@ -80,14 +80,17 @@ public class LocalRepoActivity extends Activity {
         if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
             setUIFromWifi();
             wireRepoSwitchToWebServer();
+            repoSwitch.setVisibility(View.VISIBLE);
+            enableWifiButton.setVisibility(View.GONE);
         } else {
             repoSwitch.setChecked(false);
-            repoSwitch.setText(R.string.enable_wifi);
-            repoSwitch.setTextOn(getString(R.string.enabling_wifi));
-            repoSwitch.setTextOff(getString(R.string.enable_wifi));
-            repoSwitch.setOnClickListener(new View.OnClickListener() {
+            repoSwitch.setVisibility(View.GONE);
+            enableWifiButton.setVisibility(View.VISIBLE);
+            enableWifiButton.setText(R.string.enable_wifi);
+            enableWifiButton.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
+                    enableWifiButton.setText(R.string.enabling_wifi);
                     wifiManager.setWifiEnabled(true);
                     /*
                      * Once the wifi is connected to a network, then
@@ -161,8 +164,10 @@ public class LocalRepoActivity extends Activity {
             public void onClick(View v) {
                 if (repoSwitch.isChecked()) {
                     FDroidApp.startLocalRepoService(LocalRepoActivity.this);
+                    repoSwitch.setText(R.string.local_repo_running);
                 } else {
                     FDroidApp.stopLocalRepoService(LocalRepoActivity.this);
+                    repoSwitch.setText(R.string.touch_to_turn_on_local_repo);
                 }
             }
         });
@@ -174,9 +179,8 @@ public class LocalRepoActivity extends Activity {
             return;
         // the fingerprint is not useful on the button label
         String buttonLabel = FDroidApp.repo.address.replaceAll("\\?.*$", "");
-        repoSwitch.setText(buttonLabel);
-        repoSwitch.setTextOn(buttonLabel);
-        repoSwitch.setTextOff(buttonLabel);
+        TextView sharingUriTextView = (TextView) findViewById(R.id.sharing_uri);
+        sharingUriTextView.setText(buttonLabel);
         /*
          * Set URL to UPPER for compact QR Code, FDroid will translate it back.
          * Remove the SSID from the query string since SSIDs are case-sensitive.
@@ -192,7 +196,7 @@ public class LocalRepoActivity extends Activity {
         if (Build.VERSION.SDK_INT >= 8) // zxing requires >= 8
             new QrGenAsyncTask(this, R.id.repoQrCode).execute(qrUriString);
 
-        TextView wifiNetworkNameTextView = (TextView) findViewById(R.id.wifiNetworkName);
+        TextView wifiNetworkNameTextView = (TextView) findViewById(R.id.wifi_network);
         wifiNetworkNameTextView.setText(FDroidApp.ssid);
 
         TextView fingerprintTextView = (TextView) findViewById(R.id.fingerprint);