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

More Android TV DPAD fixes (fixes #226) (fixes #228) (fixes #230) (fixes #231) (fixes #232) (fixes #233) (#229)

* Fix focus when editing folder (fixes #226)

* Don't show qr code scan button on TV (fixes #230)

* FolderActivity: Prevent accidential scroll by DPAD

* Make DPAD available in Custom Sync Conditions dialog (fixes #231)

* EnhancedEditText: Reformat code

* Remove blank

* DeviceActivity: Move code, set initial focus

* FolderActivity: Fix focus problems on phones with keyboard input (fixes #233)

* DeviceActivity: Set custom sync dialog focus from code (fixes #233)

* DeviceActivity: Use setOnClickListener instead of implementing View.OnClickListener

* fragment_folder: focusableInTouchMode => focusable

* Edit device dialog: Show copy device ID row or edit, scan device row

* Fix unused, outdated refs

* Constants: Static implies final

* Remove double semicolon

* Remove double semicolon

* Remove unused imports

* Remove unnecessary return in void func

* Fix javadoc errors (fixes #234)

* Fix typos

* Fix focus problem on TV/device edit dialog

* Fix create folder dialog focus on TV (fixes #228)
This commit is contained in:
Catfriend1 2019-01-19 11:49:41 +01:00 committed by GitHub
parent 495c3e9eb6
commit 89212bc956
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 151 additions and 112 deletions

View file

@ -6,10 +6,8 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SwitchCompat;
import android.text.Editable;
@ -57,7 +55,6 @@ import static com.nutomic.syncthingandroid.util.Compression.METADATA;
*/
public class DeviceActivity extends SyncthingActivity
implements
View.OnClickListener,
SyncthingService.OnServiceStateChangeListener {
public static final String EXTRA_NOTIFICATION_ID =
@ -79,34 +76,21 @@ public class DeviceActivity extends SyncthingActivity
private ConfigRouter mConfig;
private Device mDevice;
private View mIdContainer;
private EditText mIdView;
private EditText mEditDeviceId;
private View mShowDeviceIdContainer;
private EditText mShowDeviceId;
private View mQrButton;
private EditText mNameView;
private EditText mAddressesView;
private TextView mCurrentAddressView;
private TextView mCompressionValueView;
private SwitchCompat mIntroducerView;
private SwitchCompat mDevicePaused;
private SwitchCompat mCustomSyncConditionsSwitch;
private TextView mCustomSyncConditionsDescription;
private TextView mCustomSyncConditionsDialog;
private TextView mSyncthingVersionView;
private View mCompressionContainer;
private TextView mCompressionValueView;
private SwitchCompat mIntroducerView;
private SwitchCompat mDevicePaused;
private SwitchCompat mCustomSyncConditionsSwitch;
private TextView mCustomSyncConditionsDescription;
private TextView mCustomSyncConditionsDialog;
private TextView mSyncthingVersionView;
@Inject
SharedPreferences mPreferences;
@ -179,6 +163,7 @@ public class DeviceActivity extends SyncthingActivity
break;
case R.id.customSyncConditionsSwitch:
mCustomSyncConditionsDescription.setEnabled(isChecked);
mCustomSyncConditionsDialog.setFocusable(isChecked);
mCustomSyncConditionsDialog.setEnabled(isChecked);
// This is needed to display the "discard changes dialog".
mDeviceNeedsToUpdate = true;
@ -198,8 +183,9 @@ public class DeviceActivity extends SyncthingActivity
mIsCreateMode = getIntent().getBooleanExtra(EXTRA_IS_CREATE, false);
setTitle(mIsCreateMode ? R.string.add_device : R.string.edit_device);
mIdContainer = findViewById(R.id.idContainer);
mIdView = findViewById(R.id.id);
mEditDeviceId = findViewById(R.id.editDeviceId);
mShowDeviceIdContainer = findViewById(R.id.showDeviceIdContainer);
mShowDeviceId = findViewById(R.id.showDeviceId);
mQrButton = findViewById(R.id.qrButton);
mNameView = findViewById(R.id.name);
mAddressesView = findViewById(R.id.addresses);
@ -213,9 +199,13 @@ public class DeviceActivity extends SyncthingActivity
mCustomSyncConditionsDialog = findViewById(R.id.customSyncConditionsDialog);
mSyncthingVersionView = findViewById(R.id.syncthingVersion);
mQrButton.setOnClickListener(this);
if (Util.isRunningOnTV(this)) {
mQrButton.setVisibility(View.GONE);
}
mQrButton.setOnClickListener(view -> onQrButtonClick());
mShowDeviceIdContainer.setOnClickListener(view -> onCopyDeviceIdClick());
mCompressionContainer.setOnClickListener(view -> onCompressionContainerClick());
mCustomSyncConditionsDialog.setOnClickListener(view -> onCustomSyncConditionsDialogClick());
mCompressionContainer.setOnClickListener(this);
if (savedInstanceState != null){
if (mDevice == null) {
@ -223,26 +213,18 @@ public class DeviceActivity extends SyncthingActivity
}
restoreDialogStates(savedInstanceState);
}
findViewById(R.id.editDeviceIdContainer).setVisibility(mIsCreateMode ? View.VISIBLE : View.GONE);
mShowDeviceIdContainer.setVisibility(!mIsCreateMode ? View.VISIBLE : View.GONE);
if (mIsCreateMode) {
if (mDevice == null) {
if (mDevice == null) {
initDevice();
}
mEditDeviceId.requestFocus();
} else {
getWindow().setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN);
mNameView.requestFocus();
}
else {
prepareEditMode();
}
}
/**
* Invoked after user clicked on the {@link #mCustomSyncConditionsDialog} label.
*/
private void onCustomSyncConditionsDialogClick() {
startActivityForResult(
SyncConditionsActivity.createIntent(
this, Constants.PREF_OBJECT_PREFIX_DEVICE + mDevice.deviceID, mDevice.name
),
0
);
}
private void restoreDialogStates(Bundle savedInstanceState) {
@ -327,7 +309,7 @@ public class DeviceActivity extends SyncthingActivity
syncthingService.getNotificationHandler().cancelConsentNotification(getIntent().getIntExtra(EXTRA_NOTIFICATION_ID, 0));
syncthingService.unregisterOnServiceStateChangeListener(DeviceActivity.this);
}
mIdView.removeTextChangedListener(mIdTextWatcher);
mEditDeviceId.removeTextChangedListener(mIdTextWatcher);
mNameView.removeTextChangedListener(mNameTextWatcher);
mAddressesView.removeTextChangedListener(mAddressesTextWatcher);
}
@ -376,7 +358,7 @@ public class DeviceActivity extends SyncthingActivity
}
private void updateViewsAndSetListeners() {
mIdView.removeTextChangedListener(mIdTextWatcher);
mEditDeviceId.removeTextChangedListener(mIdTextWatcher);
mNameView.removeTextChangedListener(mNameTextWatcher);
mAddressesView.removeTextChangedListener(mAddressesTextWatcher);
mIntroducerView.setOnCheckedChangeListener(null);
@ -384,7 +366,8 @@ public class DeviceActivity extends SyncthingActivity
mCustomSyncConditionsSwitch.setOnCheckedChangeListener(null);
// Update views
mIdView.setText(mDevice.deviceID);
mEditDeviceId.setText(mDevice.deviceID);
mShowDeviceId.setText(mDevice.deviceID);
mNameView.setText(mDevice.name);
mAddressesView.setText(displayableAddresses());
mCompressionValueView.setText(Compression.fromValue(this, mDevice.compression).getTitle(this));
@ -402,10 +385,11 @@ public class DeviceActivity extends SyncthingActivity
}
mCustomSyncConditionsSwitch.setEnabled(!mIsCreateMode);
mCustomSyncConditionsDescription.setEnabled(mCustomSyncConditionsSwitch.isChecked());
mCustomSyncConditionsDialog.setFocusable(mCustomSyncConditionsSwitch.isChecked());
mCustomSyncConditionsDialog.setEnabled(mCustomSyncConditionsSwitch.isChecked());
// Keep state updated
mIdView.addTextChangedListener(mIdTextWatcher);
mEditDeviceId.addTextChangedListener(mIdTextWatcher);
mNameView.addTextChangedListener(mNameTextWatcher);
mAddressesView.addTextChangedListener(mAddressesTextWatcher);
mIntroducerView.setOnCheckedChangeListener(mCheckedListener);
@ -489,7 +473,7 @@ public class DeviceActivity extends SyncthingActivity
IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
if (scanResult != null) {
mDevice.deviceID = scanResult.getContents();
mIdView.setText(mDevice.deviceID);
mEditDeviceId.setText(mDevice.deviceID);
}
}
@ -507,17 +491,6 @@ public class DeviceActivity extends SyncthingActivity
mDevice.introducedBy = "";
}
private void prepareEditMode() {
getWindow().setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Drawable dr = ContextCompat.getDrawable(this, R.drawable.ic_content_copy_black_24dp);
mIdView.setCompoundDrawablesWithIntrinsicBounds(null, null, dr, null);
mIdView.setEnabled(false);
mQrButton.setVisibility(View.GONE);
mIdContainer.setOnClickListener(this);
}
/**
* Sends the updated device info if in edit mode.
* Preconditions: mDeviceNeedsToUpdate == true
@ -580,16 +553,29 @@ public class DeviceActivity extends SyncthingActivity
return TextUtils.join(", ", list);
}
@Override
public void onClick(View v) {
if (v.equals(mCompressionContainer)) {
showCompressionDialog();
} else if (v.equals(mQrButton)){
IntentIntegrator integrator = new IntentIntegrator(DeviceActivity.this);
integrator.initiateScan();
} else if (v.equals(mIdContainer)) {
Util.copyDeviceId(this, mDevice.deviceID);
}
private void onCompressionContainerClick() {
showCompressionDialog();
}
/**
* Invoked after user clicked on the {@link #mCustomSyncConditionsDialog} label.
*/
private void onCustomSyncConditionsDialogClick() {
startActivityForResult(
SyncConditionsActivity.createIntent(
this, Constants.PREF_OBJECT_PREFIX_DEVICE + mDevice.deviceID, mDevice.name
),
0
);
}
private void onCopyDeviceIdClick() {
Util.copyDeviceId(this, mDevice.deviceID);
}
private void onQrButtonClick() {
IntentIntegrator integrator = new IntentIntegrator(DeviceActivity.this);
integrator.initiateScan();
}
private void showCompressionDialog(){
@ -615,15 +601,11 @@ public class DeviceActivity extends SyncthingActivity
}
private void showDiscardDialog(){
mDiscardDialog = createDiscardDialog();
mDiscardDialog.show();
}
private Dialog createDiscardDialog() {
return new android.app.AlertDialog.Builder(this)
mDiscardDialog = new android.app.AlertDialog.Builder(this)
.setMessage(R.string.dialog_discard_changes)
.setPositiveButton(android.R.string.ok, (dialog, which) -> finish())
.setNegativeButton(android.R.string.cancel, null)
.create();
mDiscardDialog.show();
}
}

View file

@ -161,6 +161,7 @@ public class FolderActivity extends SyncthingActivity
break;
case R.id.customSyncConditionsSwitch:
mCustomSyncConditionsDescription.setEnabled(isChecked);
mCustomSyncConditionsDialog.setFocusable(isChecked);
mCustomSyncConditionsDialog.setEnabled(isChecked);
// This is needed to display the "discard changes dialog".
mFolderNeedsToUpdate = true;
@ -228,19 +229,20 @@ public class FolderActivity extends SyncthingActivity
if (mFolder == null) {
initFolder();
}
// Open keyboard on label view in edit mode.
mLabelView.requestFocus();
mEditIgnoreListTitle.setEnabled(false);
mEditIgnoreListContent.setEnabled(false);
}
else {
// Prepare edit mode.
mIdView.clearFocus();
mIdView.setFocusable(false);
mIdView.setEnabled(false);
mPathView.setFocusable(false);
mPathView.setEnabled(false);
}
// Open keyboard on label view in edit mode.
mLabelView.requestFocus();
if (savedInstanceState != null) {
if (savedInstanceState.getBoolean(IS_SHOWING_DELETE_DIALOG)) {
showDeleteDialog();
@ -494,6 +496,7 @@ public class FolderActivity extends SyncthingActivity
}
mCustomSyncConditionsSwitch.setEnabled(!mIsCreateMode);
mCustomSyncConditionsDescription.setEnabled(mCustomSyncConditionsSwitch.isChecked());
mCustomSyncConditionsDialog.setFocusable(mCustomSyncConditionsSwitch.isChecked());
mCustomSyncConditionsDialog.setEnabled(mCustomSyncConditionsSwitch.isChecked());
// Populate devicesList.

View file

@ -17,8 +17,7 @@
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:showDividers="middle"
android:focusableInTouchMode="true">
android:showDividers="middle">
<!-- Static Sync Condition Title -->
<LinearLayout

View file

@ -21,15 +21,16 @@
android:paddingTop="8dp"
android:showDividers="middle">
<!-- Option 1: Input or edit device ID -->
<LinearLayout
android:id="@+id/idContainer"
android:id="@+id/editDeviceIdContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="horizontal">
<com.nutomic.syncthingandroid.views.EnhancedEditText
android:id="@+id/id"
android:id="@+id/editDeviceId"
style="@style/Widget.Syncthing.TextView.Label.Details.Field"
android:layout_width="0dp"
android:layout_height="wrap_content"
@ -39,7 +40,8 @@
android:hint="@string/device_id"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions|textMultiLine"
android:nextFocusForward="@+id/name" />
android:focusable="true"
android:nextFocusDown="@+id/name" />
<ImageView
android:id="@+id/qrButton"
@ -51,8 +53,46 @@
android:layout_marginRight="@dimen/abc_action_bar_content_inset_material"
android:contentDescription="@string/scan_qr_code_description"
android:src="@drawable/ic_qrcode_black_24dp_active" />
</LinearLayout>
<!-- Option 2: Show or copy device ID -->
<LinearLayout
android:id="@+id/showDeviceIdContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="horizontal"
android:focusable="true"
android:nextFocusDown="@+id/name" >
<com.nutomic.syncthingandroid.views.EnhancedEditText
android:id="@+id/showDeviceId"
style="@style/Widget.Syncthing.TextView.Label.Details.Field"
android:enabled="false"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="@drawable/ic_cellphone_black_24dp"
android:drawableStart="@drawable/ic_cellphone_black_24dp"
android:hint="@string/device_id"
android:imeOptions="actionNext"
android:inputType="textNoSuggestions|textMultiLine" />
<ImageView
android:id="@+id/copyDeviceIdIcon"
style="?actionButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/abc_action_bar_content_inset_material"
android:layout_marginRight="@dimen/abc_action_bar_content_inset_material"
android:contentDescription="@string/scan_qr_code_description"
android:src="@drawable/ic_content_copy_black_24dp" />
</LinearLayout>
<!-- Device Name -->
<EditText
android:id="@+id/name"
style="@style/Widget.Syncthing.TextView.Label.Details.Field"
@ -65,6 +105,7 @@
android:inputType="textCapWords"
android:importantForAutofill="no" />
<!-- Device Addresses-->
<EditText
android:id="@+id/addresses"
style="@style/Widget.Syncthing.TextView.Label.Details.Field"
@ -82,7 +123,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="horizontal">
android:orientation="horizontal"
android:focusable="true">
<TextView
style="@style/Widget.Syncthing.TextView.Label.Details"
@ -161,7 +203,6 @@
android:layout_marginStart="56dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:text="@string/custom_sync_conditions_dialog"/>
<TextView

View file

@ -19,8 +19,7 @@
android:orientation="vertical"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:showDividers="middle"
android:focusableInTouchMode="true">
android:showDividers="middle">
<EditText
android:id="@+id/label"
@ -62,13 +61,15 @@
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_device_hub_black_24dp_active"
android:drawableStart="@drawable/ic_device_hub_black_24dp_active"
android:focusable="false"
android:text="@string/devices" />
<LinearLayout
android:id="@+id/devicesContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:focusable="false">
</LinearLayout>
<LinearLayout
@ -77,7 +78,8 @@
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="vertical"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:focusable="true">
<TextView
style="@style/Widget.Syncthing.TextView.Label.Details"
@ -185,7 +187,6 @@
android:layout_marginStart="56dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:text="@string/custom_sync_conditions_dialog"/>
<TextView
@ -207,7 +208,8 @@
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="vertical"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:focusable="true">
<TextView
style="@style/Widget.Syncthing.TextView.Label.Details"
@ -245,7 +247,8 @@
android:layout_height="wrap_content"
android:background="?selectableItemBackground"
android:orientation="vertical"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:focusable="true">
<TextView
style="@style/Widget.Syncthing.TextView.Label.Details"
@ -278,26 +281,37 @@
</LinearLayout>
<!-- variableSizeBlocks -->
<android.support.v7.widget.SwitchCompat
android:id="@+id/variableSizeBlocks"
style="@style/Widget.Syncthing.TextView.Label.Details"
<LinearLayout
android:id="@+id/variableSizeBlocksContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:drawableLeft="@drawable/ic_developer_board_black_24dp"
android:drawableStart="@drawable/ic_developer_board_black_24dp"
android:text="@string/folder_variable_size_blocks_caption" />
android:background="?selectableItemBackground"
android:orientation="vertical"
android:gravity="center_vertical"
android:focusable="true">
<TextView
android:id="@+id/variableSizeBlocksDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:layout_marginTop="-20dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:text="@string/folder_variable_size_blocks_description"
android:focusable="false"/>
<android.support.v7.widget.SwitchCompat
android:id="@+id/variableSizeBlocks"
style="@style/Widget.Syncthing.TextView.Label.Details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false"
android:drawableLeft="@drawable/ic_developer_board_black_24dp"
android:drawableStart="@drawable/ic_developer_board_black_24dp"
android:text="@string/folder_variable_size_blocks_caption" />
<TextView
android:id="@+id/variableSizeBlocksDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:layout_marginTop="-20dp"
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
android:text="@string/folder_variable_size_blocks_description"
android:focusable="false"/>
</LinearLayout>
<LinearLayout
android:id="@+id/editIgnoresContainer"