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

Add folder dialog: "Tap to add device" if no devices are present (fixes #344) (#345)

* Add folder dialog: "Tap to add device" if no devices are present (fixes #344)

* Update string: devices_list_empty

* Add service/TestData

* activity_folder/layout: Make devicesContainer selectable from DPAD

* Imported de translation
This commit is contained in:
Catfriend1 2019-03-05 23:01:06 +01:00 committed by GitHub
parent 22a302d940
commit e1f85548fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 4 deletions

View file

@ -1,5 +1,6 @@
package com.nutomic.syncthingandroid.activities; package com.nutomic.syncthingandroid.activities;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
@ -60,6 +61,8 @@ import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HI
import static android.view.Gravity.CENTER_VERTICAL; import static android.view.Gravity.CENTER_VERTICAL;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.nutomic.syncthingandroid.service.Constants.ENABLE_TEST_DATA;
import static com.nutomic.syncthingandroid.util.Compression.METADATA; import static com.nutomic.syncthingandroid.util.Compression.METADATA;
/** /**
@ -83,6 +86,8 @@ public class DeviceActivity extends SyncthingActivity {
private static final List<String> DYNAMIC_ADDRESS = Collections.singletonList("dynamic"); private static final List<String> DYNAMIC_ADDRESS = Collections.singletonList("dynamic");
public static final int DEVICE_ADD_CODE = 401;
private ConfigRouter mConfig; private ConfigRouter mConfig;
private Device mDevice; private Device mDevice;
@ -184,6 +189,12 @@ public class DeviceActivity extends SyncthingActivity {
} }
}; };
public static Intent createIntent(Context context) {
Intent intent = new Intent(context, DeviceActivity.class);
intent.putExtra(EXTRA_IS_CREATE, true);
return intent;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
mConfig = new ConfigRouter(DeviceActivity.this); mConfig = new ConfigRouter(DeviceActivity.this);
@ -250,6 +261,7 @@ public class DeviceActivity extends SyncthingActivity {
} }
if (mDevice == null) { if (mDevice == null) {
Log.w(TAG, "Device not found in API update, maybe it was deleted?"); Log.w(TAG, "Device not found in API update, maybe it was deleted?");
setResult(Activity.RESULT_CANCELED);
finish(); finish();
return; return;
} }
@ -454,6 +466,7 @@ public class DeviceActivity extends SyncthingActivity {
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> { .setPositiveButton(android.R.string.yes, (dialogInterface, i) -> {
mConfig.removeDevice(getApi(), mDevice.deviceID); mConfig.removeDevice(getApi(), mDevice.deviceID);
mDeviceNeedsToUpdate = false; mDeviceNeedsToUpdate = false;
setResult(Activity.RESULT_OK);
finish(); finish();
}) })
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
@ -520,6 +533,7 @@ public class DeviceActivity extends SyncthingActivity {
if (mIsCreateMode) { if (mIsCreateMode) {
Log.v(TAG, "onSave: Adding device with ID = \'" + mDevice.deviceID + "\'"); Log.v(TAG, "onSave: Adding device with ID = \'" + mDevice.deviceID + "\'");
mConfig.addDevice(getApi(), mDevice); mConfig.addDevice(getApi(), mDevice);
setResult(Activity.RESULT_OK);
finish(); finish();
return; return;
} }
@ -527,6 +541,7 @@ public class DeviceActivity extends SyncthingActivity {
// Edit mode. // Edit mode.
if (!mDeviceNeedsToUpdate) { if (!mDeviceNeedsToUpdate) {
// We've got nothing to save. // We've got nothing to save.
setResult(Activity.RESULT_CANCELED);
finish(); finish();
return; return;
} }
@ -543,6 +558,7 @@ public class DeviceActivity extends SyncthingActivity {
// Update device using RestApi or ConfigXml. // Update device using RestApi or ConfigXml.
mConfig.updateDevice(getApi(), mDevice); mConfig.updateDevice(getApi(), mDevice);
setResult(Activity.RESULT_OK);
finish(); finish();
return; return;
} }
@ -645,7 +661,10 @@ public class DeviceActivity extends SyncthingActivity {
private void showDiscardDialog(){ private void showDiscardDialog(){
mDiscardDialog = new android.app.AlertDialog.Builder(this) mDiscardDialog = new android.app.AlertDialog.Builder(this)
.setMessage(R.string.dialog_discard_changes) .setMessage(R.string.dialog_discard_changes)
.setPositiveButton(android.R.string.ok, (dialog, which) -> finish()) .setPositiveButton(android.R.string.ok, (dialog, which) -> {
setResult(Activity.RESULT_CANCELED);
finish();
})
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(android.R.string.cancel, null)
.create(); .create();
mDiscardDialog.show(); mDiscardDialog.show();

View file

@ -325,6 +325,13 @@ public class FolderActivity extends SyncthingActivity {
} }
} }
/**
* Open dialog if the user clicked on empty device list view.
*/
private void showAddDeviceDialog() {
startActivityForResult(DeviceActivity.createIntent(this), DeviceActivity.DEVICE_ADD_CODE);
}
/** /**
* Invoked after user clicked on the {@link #mCustomSyncConditionsDialog} label. * Invoked after user clicked on the {@link #mCustomSyncConditionsDialog} label.
*/ */
@ -582,6 +589,8 @@ public class FolderActivity extends SyncthingActivity {
mFolder.order = data.getStringExtra(PullOrderDialogActivity.EXTRA_RESULT_PULL_ORDER); mFolder.order = data.getStringExtra(PullOrderDialogActivity.EXTRA_RESULT_PULL_ORDER);
updatePullOrderDescription(); updatePullOrderDescription();
mFolderNeedsToUpdate = true; mFolderNeedsToUpdate = true;
} else if (resultCode == Activity.RESULT_OK && requestCode == DeviceActivity.DEVICE_ADD_CODE) {
updateViewsAndSetListeners();
} }
} }
@ -678,6 +687,7 @@ public class FolderActivity extends SyncthingActivity {
emptyView.setGravity(CENTER_VERTICAL); emptyView.setGravity(CENTER_VERTICAL);
emptyView.setText(R.string.devices_list_empty); emptyView.setText(R.string.devices_list_empty);
mDevicesContainer.addView(emptyView, params); mDevicesContainer.addView(emptyView, params);
mDevicesContainer.setOnClickListener(view -> showAddDeviceDialog());
} }
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) { private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {

View file

@ -66,10 +66,11 @@
<LinearLayout <LinearLayout
android:id="@+id/devicesContainer" android:id="@+id/devicesContainer"
android:background="?selectableItemBackground"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:focusable="false"> android:focusable="true">
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -131,7 +131,7 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="devices_fragment_title">Geräte</string> <string name="devices_fragment_title">Geräte</string>
<!-- Shown if no devices exist --> <!-- Shown if no devices exist -->
<string name="devices_list_empty">Keine Geräte gefunden</string> <string name="devices_list_empty">Keine Geräte konfiguriert. Tippe zum Hinzufügen eines neuen Geräts.</string>
<!-- Indicates that a folder is fully synced to the local device --> <!-- Indicates that a folder is fully synced to the local device -->
<string name="device_up_to_date">Aktuell</string> <string name="device_up_to_date">Aktuell</string>

View file

@ -134,7 +134,7 @@ Please report any problems you encounter via Github.</string>
<string name="devices_fragment_title">Devices</string> <string name="devices_fragment_title">Devices</string>
<!-- Shown if no devices exist --> <!-- Shown if no devices exist -->
<string name="devices_list_empty">No devices found</string> <string name="devices_list_empty">No devices configured. Tap to add a new device.</string>
<!-- Indicates that a folder is fully synced to the local device --> <!-- Indicates that a folder is fully synced to the local device -->
<string name="device_up_to_date">Up to Date</string> <string name="device_up_to_date">Up to Date</string>