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;
import android.app.Activity;
import android.app.Dialog;
import android.content.ComponentName;
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.ViewGroup.LayoutParams.WRAP_CONTENT;
import static com.nutomic.syncthingandroid.service.Constants.ENABLE_TEST_DATA;
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");
public static final int DEVICE_ADD_CODE = 401;
private ConfigRouter mConfig;
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
public void onCreate(Bundle savedInstanceState) {
mConfig = new ConfigRouter(DeviceActivity.this);
@ -250,6 +261,7 @@ public class DeviceActivity extends SyncthingActivity {
}
if (mDevice == null) {
Log.w(TAG, "Device not found in API update, maybe it was deleted?");
setResult(Activity.RESULT_CANCELED);
finish();
return;
}
@ -454,6 +466,7 @@ public class DeviceActivity extends SyncthingActivity {
.setPositiveButton(android.R.string.yes, (dialogInterface, i) -> {
mConfig.removeDevice(getApi(), mDevice.deviceID);
mDeviceNeedsToUpdate = false;
setResult(Activity.RESULT_OK);
finish();
})
.setNegativeButton(android.R.string.no, null)
@ -520,6 +533,7 @@ public class DeviceActivity extends SyncthingActivity {
if (mIsCreateMode) {
Log.v(TAG, "onSave: Adding device with ID = \'" + mDevice.deviceID + "\'");
mConfig.addDevice(getApi(), mDevice);
setResult(Activity.RESULT_OK);
finish();
return;
}
@ -527,6 +541,7 @@ public class DeviceActivity extends SyncthingActivity {
// Edit mode.
if (!mDeviceNeedsToUpdate) {
// We've got nothing to save.
setResult(Activity.RESULT_CANCELED);
finish();
return;
}
@ -543,6 +558,7 @@ public class DeviceActivity extends SyncthingActivity {
// Update device using RestApi or ConfigXml.
mConfig.updateDevice(getApi(), mDevice);
setResult(Activity.RESULT_OK);
finish();
return;
}
@ -645,7 +661,10 @@ public class DeviceActivity extends SyncthingActivity {
private void showDiscardDialog(){
mDiscardDialog = new android.app.AlertDialog.Builder(this)
.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)
.create();
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.
*/
@ -582,6 +589,8 @@ public class FolderActivity extends SyncthingActivity {
mFolder.order = data.getStringExtra(PullOrderDialogActivity.EXTRA_RESULT_PULL_ORDER);
updatePullOrderDescription();
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.setText(R.string.devices_list_empty);
mDevicesContainer.addView(emptyView, params);
mDevicesContainer.setOnClickListener(view -> showAddDeviceDialog());
}
private void addDeviceViewAndSetListener(Device device, LayoutInflater inflater) {

View file

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

View file

@ -131,7 +131,7 @@ Bitte melden Sie auftretende Probleme via GitHub.</string>
<string name="devices_fragment_title">Geräte</string>
<!-- 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 -->
<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>
<!-- 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 -->
<string name="device_up_to_date">Up to Date</string>