1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Add device dialog: Implement refresh button and help (fixes #310) (#311)

* Add drawable ic_refresh_black_24

* Add device: Add refresh button to dialog

* Add device dialog: Implement refresh button (fixes #310)

Always show "No devices discovered label" and refresh button if no device ID had been entered yet.

* Update model/Options for SyncthingNative 1.0.1

* Add ConfigRouter#getOptions

* Add ConfigXml#getOptions

* Update README.md

* Add string: local_discovery_disabled

* Add device dialog: Show notice if local discovery is disabled

and explain how to enable it.

* Add device dialog: Show helpful text if no devices were discovered locally

* Updated de translation
This commit is contained in:
Catfriend1 2019-02-09 18:26:54 +01:00 committed by GitHub
parent e5a033a64d
commit 7bd253ab0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 42 additions and 18 deletions

View file

@ -14,7 +14,6 @@ import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -34,6 +33,7 @@ import com.nutomic.syncthingandroid.R;
import com.nutomic.syncthingandroid.model.Connections; import com.nutomic.syncthingandroid.model.Connections;
import com.nutomic.syncthingandroid.model.Device; import com.nutomic.syncthingandroid.model.Device;
import com.nutomic.syncthingandroid.model.DiscoveredDevice; import com.nutomic.syncthingandroid.model.DiscoveredDevice;
import com.nutomic.syncthingandroid.model.Options;
import com.nutomic.syncthingandroid.service.Constants; import com.nutomic.syncthingandroid.service.Constants;
import com.nutomic.syncthingandroid.service.RestApi; import com.nutomic.syncthingandroid.service.RestApi;
import com.nutomic.syncthingandroid.service.SyncthingService; import com.nutomic.syncthingandroid.service.SyncthingService;
@ -54,7 +54,6 @@ import javax.inject.Inject;
import static android.support.v4.view.MarginLayoutParamsCompat.setMarginEnd; import static android.support.v4.view.MarginLayoutParamsCompat.setMarginEnd;
import static android.support.v4.view.MarginLayoutParamsCompat.setMarginStart; import static android.support.v4.view.MarginLayoutParamsCompat.setMarginStart;
import static android.text.TextUtils.isEmpty; import static android.text.TextUtils.isEmpty;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN; import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
import static android.view.Gravity.CENTER_VERTICAL; import static android.view.Gravity.CENTER_VERTICAL;
@ -293,6 +292,11 @@ public class DeviceActivity extends SyncthingActivity {
if (restApi != null) { if (restApi != null) {
restApi.getConnections(this::onReceiveConnections); restApi.getConnections(this::onReceiveConnections);
if (mIsCreateMode) { if (mIsCreateMode) {
mDiscoveredDevicesTitle.setOnClickListener(view -> {
if (restApi != null) {
asyncQueryDiscoveredDevices(restApi);
}
});
asyncQueryDiscoveredDevices(restApi); asyncQueryDiscoveredDevices(restApi);
} }
} }
@ -659,18 +663,30 @@ public class DeviceActivity extends SyncthingActivity {
return; return;
} }
/**
* If "mEditDeviceId" already contains content, don't show local discovery results.
* This also suppresses the results being shown a second time after the user chose a
* deviceId from the list and rotated the screen.
*/
mDiscoveredDevicesTitle.setVisibility(TextUtils.isEmpty(mEditDeviceId.getText()) ? View.VISIBLE : View.GONE);
mDiscoveredDevicesContainer.setVisibility(TextUtils.isEmpty(mEditDeviceId.getText()) ? View.VISIBLE : View.GONE);
mDiscoveredDevicesContainer.removeAllViews(); mDiscoveredDevicesContainer.removeAllViews();
if (discoveredDevices.size() == 0) { if (discoveredDevices.size() == 0) {
// No discovered devices. // No discovered devices. Determine if local discovery is enabled.
int height = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics()); Options options = mConfig.getOptions(null);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT, height); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
int dividerInset = getResources().getDimensionPixelOffset(R.dimen.material_divider_inset); int dividerInset = getResources().getDimensionPixelOffset(R.dimen.material_divider_inset);
int contentInset = getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material); int contentInset = getResources().getDimensionPixelOffset(R.dimen.abc_action_bar_content_inset_material);
setMarginStart(params, dividerInset); setMarginStart(params, dividerInset);
setMarginEnd(params, contentInset); setMarginEnd(params, contentInset);
TextView emptyView = new TextView(mDiscoveredDevicesContainer.getContext()); TextView emptyView = new TextView(mDiscoveredDevicesContainer.getContext());
emptyView.setGravity(CENTER_VERTICAL); emptyView.setGravity(CENTER_VERTICAL);
emptyView.setText(R.string.discovered_device_list_empty); if (options.localAnnounceEnabled) {
emptyView.setText(getString(R.string.discovered_device_list_empty, getString(R.string.url_syncthing_homepage)));
} else {
emptyView.setText(R.string.local_discovery_disabled);
}
mDiscoveredDevicesContainer.addView(emptyView, params); mDiscoveredDevicesContainer.addView(emptyView, params);
return; return;
} }
@ -682,8 +698,8 @@ public class DeviceActivity extends SyncthingActivity {
DiscoveredDevice discoveredDevice = discoveredDevices.get(deviceId); DiscoveredDevice discoveredDevice = discoveredDevices.get(deviceId);
if (discoveredDevice != null && discoveredDevice.addresses != null) { if (discoveredDevice != null && discoveredDevice.addresses != null) {
readableAddresses = TextUtils.join(", ", discoveredDevice.addresses); readableAddresses = TextUtils.join(", ", discoveredDevice.addresses);
// Log.v(TAG, "onReceiveDiscoveredDevices: deviceID = '" + deviceId + "' has addresses '" + readableAddresses + "'");
} }
// Log.v(TAG, "onReceiveDiscoveredDevices: deviceID = '" + deviceId + "' has addresses '" + readableAddresses + "'");
String caption = deviceId + (TextUtils.isEmpty(readableAddresses) ? "" : " (" + readableAddresses + ")"); String caption = deviceId + (TextUtils.isEmpty(readableAddresses) ? "" : " (" + readableAddresses + ")");
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
inflater.inflate(R.layout.item_discovered_device_form, mDiscoveredDevicesContainer); inflater.inflate(R.layout.item_discovered_device_form, mDiscoveredDevicesContainer);
@ -694,14 +710,6 @@ public class DeviceActivity extends SyncthingActivity {
deviceIdView.setOnClickListener(v -> onDeviceIdViewClick(v)); deviceIdView.setOnClickListener(v -> onDeviceIdViewClick(v));
} }
} }
/**
* If "mEditDeviceId" already contains content, don't show local discovery results.
* This also suppresses the results being shown a second time after the user chose a
* deviceId from the list and rotated the screen.
*/
mDiscoveredDevicesTitle.setVisibility(TextUtils.isEmpty(mEditDeviceId.getText()) ? View.VISIBLE : View.GONE);
mDiscoveredDevicesContainer.setVisibility(TextUtils.isEmpty(mEditDeviceId.getText()) ? View.VISIBLE : View.GONE);
} }
/** /**

Binary file not shown.

After

Width:  |  Height:  |  Size: 362 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 481 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

View file

@ -61,9 +61,14 @@
android:id="@+id/discoveredDevicesTitle" android:id="@+id/discoveredDevicesTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/abc_action_bar_content_inset_material"
android:layout_marginRight="@dimen/abc_action_bar_content_inset_material"
android:clickable="true"
android:drawableLeft="@drawable/ic_device_hub_black_24dp_active" android:drawableLeft="@drawable/ic_device_hub_black_24dp_active"
android:drawableStart="@drawable/ic_device_hub_black_24dp_active" android:drawableStart="@drawable/ic_device_hub_black_24dp_active"
android:focusable="false" android:drawableEnd="@drawable/ic_refresh_black_24"
android:drawableRight="@drawable/ic_refresh_black_24"
android:focusable="true"
android:text="@string/discovered_devices_title" android:text="@string/discovered_devices_title"
android:visibility="gone" /> android:visibility="gone" />

View file

@ -261,7 +261,10 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="discovered_devices_title">Gefundene Geräte - Tippe zur Auswahl</string> <string name="discovered_devices_title">Gefundene Geräte - Tippe zur Auswahl</string>
<!-- Status text --> <!-- Status text -->
<string name="discovered_device_list_empty">Die lokale Geräteerkennung hat im lokalen Netzwerk keine Geräte gefunden.</string> <string name="discovered_device_list_empty">Die lokale Geräteerkennung hat im lokalen Netzwerk keine Geräte gefunden. Starte dieses App auf einem zweiten Telefon. Installationsdateien für Computer stehen unter %1$s zur Verfügung.</string>
<!-- Status text -->
<string name="local_discovery_disabled">Du hast die lokale Geräteerkennung unter \'Einstellungen\' > \'Syncthing-Optionen\' > \'Lokale Gerätesuche\' deaktiviert. Aktiviere sie, um im lokalen Netzwerk nach Geräten zu suchen.</string>
<!-- Setting title --> <!-- Setting title -->
<string name="name">Name</string> <string name="name">Name</string>

View file

@ -264,7 +264,10 @@ Please report any problems you encounter via Github.</string>
<string name="discovered_devices_title">Discovered devices - Tap to select</string> <string name="discovered_devices_title">Discovered devices - Tap to select</string>
<!-- Status text --> <!-- Status text -->
<string name="discovered_device_list_empty">Local discovery didn\'t find any devices on the local network.</string> <string name="discovered_device_list_empty">Local discovery didn\'t find any devices on the local network. Run this app on a second phone. Installation files for computers are available at: %1$s</string>
<!-- Status text -->
<string name="local_discovery_disabled">You have disabled local discovery in \'Settings\' > \'Syncthing Options\' > \'Local Discovery\'. Enable it to search for devices on the local network.</string>
<!-- Setting title --> <!-- Setting title -->
<string name="name">Name</string> <string name="name">Name</string>
@ -604,8 +607,13 @@ Please report any problems you encounter via Github.</string>
<!-- URL of the issue tracker --> <!-- URL of the issue tracker -->
<string name="issue_tracker_url" translatable="false">https://github.com/Catfriend1/syncthing-android/issues</string> <string name="issue_tracker_url" translatable="false">https://github.com/Catfriend1/syncthing-android/issues</string>
<!-- URL of the GitHub wiki -->
<string name="wiki_url" translatable="false">https://github.com/Catfriend1/syncthing-android/wiki</string> <string name="wiki_url" translatable="false">https://github.com/Catfriend1/syncthing-android/wiki</string>
<!-- URL of the Syncthing project homepage -->
<string name="url_syncthing_homepage" translatable="false">https://syncthing.net</string>
<!-- Menu item to donate --> <!-- Menu item to donate -->
<!-- Title of the preference showing upstream version name --> <!-- Title of the preference showing upstream version name -->