mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-11-22 12:21:15 +00:00
Use view binding in more activities (#2052)
# Description Use view binding in more activities: * QRScannerActivity * ShareActivity * PullOrderDialogActivity Rename also a couple of xml layout files from `fragment_xyz` to `activity_xyz` as they are being used inside activities.
This commit is contained in:
parent
03f7b8ccef
commit
d415716256
5 changed files with 33 additions and 45 deletions
|
@ -5,10 +5,7 @@ import android.content.Intent;
|
|||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
|
||||
import com.nutomic.syncthingandroid.databinding.ActivityPullorderDialogBinding;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -19,6 +16,8 @@ public class PullOrderDialogActivity extends ThemedAppCompatActivity {
|
|||
|
||||
private String selectedType;
|
||||
|
||||
private ActivityPullorderDialogBinding binding;
|
||||
|
||||
private static final List<String> mTypes = Arrays.asList(
|
||||
"random",
|
||||
"alphabetic",
|
||||
|
@ -31,7 +30,8 @@ public class PullOrderDialogActivity extends ThemedAppCompatActivity {
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_pullorder_dialog);
|
||||
binding = ActivityPullorderDialogBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
if (savedInstanceState == null) {
|
||||
selectedType = getIntent().getStringExtra(EXTRA_PULL_ORDER);
|
||||
}
|
||||
|
@ -40,8 +40,7 @@ public class PullOrderDialogActivity extends ThemedAppCompatActivity {
|
|||
}
|
||||
|
||||
private void initiateFinishBtn() {
|
||||
Button finishBtn = findViewById(R.id.finish_btn);
|
||||
finishBtn.setOnClickListener(v -> {
|
||||
binding.finishBtn.setOnClickListener(v -> {
|
||||
saveConfiguration();
|
||||
finish();
|
||||
});
|
||||
|
@ -54,9 +53,8 @@ public class PullOrderDialogActivity extends ThemedAppCompatActivity {
|
|||
}
|
||||
|
||||
private void initiateSpinner() {
|
||||
Spinner pullOrderTypeSpinner = findViewById(R.id.pullOrderTypeSpinner);
|
||||
pullOrderTypeSpinner.setSelection(mTypes.indexOf(selectedType));
|
||||
pullOrderTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
binding.pullOrderTypeSpinner.setSelection(mTypes.indexOf(selectedType));
|
||||
binding.pullOrderTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (position != mTypes.indexOf(selectedType)) {
|
||||
|
|
|
@ -6,19 +6,15 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.google.zxing.ResultPoint;
|
||||
import com.journeyapps.barcodescanner.BarcodeCallback;
|
||||
import com.journeyapps.barcodescanner.BarcodeResult;
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.databinding.ActivityQrScannerBinding;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -33,17 +29,16 @@ public class QRScannerActivity extends ThemedAppCompatActivity implements Barcod
|
|||
|
||||
private final int RC_HANDLE_CAMERA_PERM = 888;
|
||||
|
||||
private DecoratedBarcodeView barcodeView;
|
||||
private ActivityQrScannerBinding binding;
|
||||
|
||||
// region === Activity Lifecycle ===
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.fragment_qr_scanner);
|
||||
binding = ActivityQrScannerBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
this.barcodeView = findViewById(R.id.bar_code_scanner_view);
|
||||
|
||||
findViewById(R.id.cancel_button).setOnClickListener(view -> {
|
||||
binding.cancelButton.setOnClickListener(view -> {
|
||||
finishScanning();
|
||||
});
|
||||
|
||||
|
@ -98,12 +93,12 @@ public class QRScannerActivity extends ThemedAppCompatActivity implements Barcod
|
|||
}
|
||||
|
||||
private void startScanner() {
|
||||
this.barcodeView.resume();
|
||||
this.barcodeView.decodeSingle(this);
|
||||
binding.barCodeScannerView.resume();
|
||||
binding.barCodeScannerView.decodeSingle(this);
|
||||
}
|
||||
|
||||
private void finishScanning() {
|
||||
this.barcodeView.pause();
|
||||
binding.barCodeScannerView.pause();
|
||||
finish();
|
||||
}
|
||||
// endregion
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.nutomic.syncthingandroid.activities;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
|
@ -15,14 +17,13 @@ import android.view.View;
|
|||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.nutomic.syncthingandroid.R;
|
||||
import com.nutomic.syncthingandroid.databinding.ActivityShareBinding;
|
||||
import com.nutomic.syncthingandroid.model.Folder;
|
||||
import com.nutomic.syncthingandroid.service.SyncthingService;
|
||||
import com.nutomic.syncthingandroid.util.Util;
|
||||
|
@ -39,8 +40,6 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
|
||||
|
||||
/**
|
||||
* Shares incoming files to syncthing folders.
|
||||
* <p>
|
||||
|
@ -59,6 +58,8 @@ public class ShareActivity extends StateDialogActivity
|
|||
|
||||
private Spinner mFoldersSpinner;
|
||||
|
||||
private ActivityShareBinding binding;
|
||||
|
||||
@Override
|
||||
public void onServiceStateChange(SyncthingService.State currentState) {
|
||||
if (currentState != SyncthingService.State.ACTIVE || getApi() == null)
|
||||
|
@ -81,9 +82,8 @@ public class ShareActivity extends StateDialogActivity
|
|||
this, android.R.layout.simple_spinner_item, folders);
|
||||
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
Spinner sItems = findViewById(R.id.folders);
|
||||
sItems.setAdapter(adapter);
|
||||
sItems.setSelection(folderIndex);
|
||||
binding.folders.setAdapter(adapter);
|
||||
binding.folders.setSelection(folderIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,18 +102,13 @@ public class ShareActivity extends StateDialogActivity
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_share);
|
||||
binding = ActivityShareBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
getWindow().setSoftInputMode(SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||
|
||||
registerOnServiceConnectedListener(this);
|
||||
|
||||
Button mShareButton = findViewById(R.id.share_button);
|
||||
Button mCancelButton = findViewById(R.id.cancel_button);
|
||||
Button browseButton = findViewById(R.id.browse_button);
|
||||
EditText mShareName = findViewById(R.id.name);
|
||||
TextView mShareTitle = findViewById(R.id.namesTitle);
|
||||
|
||||
mSubDirectoryTextView = findViewById(R.id.sub_directory_Textview);
|
||||
mFoldersSpinner = findViewById(R.id.folders);
|
||||
|
||||
|
@ -143,16 +138,16 @@ public class ShareActivity extends StateDialogActivity
|
|||
files.put(sourceUri, displayName);
|
||||
}
|
||||
|
||||
mShareName.setText(TextUtils.join("\n", files.values()));
|
||||
binding.name.setText(TextUtils.join("\n", files.values()));
|
||||
if (files.size() > 1) {
|
||||
mShareName.setFocusable(false);
|
||||
mShareName.setKeyListener(null);
|
||||
binding.name.setFocusable(false);
|
||||
binding.name.setKeyListener(null);
|
||||
}
|
||||
mShareTitle.setText(getResources().getQuantityString(R.plurals.file_name_title,
|
||||
binding.namesTitle.setText(getResources().getQuantityString(R.plurals.file_name_title,
|
||||
files.size() > 1 ? 2 : 1));
|
||||
mShareButton.setOnClickListener(view -> {
|
||||
binding.shareButton.setOnClickListener(view -> {
|
||||
if (files.size() == 1)
|
||||
files.entrySet().iterator().next().setValue(mShareName.getText().toString());
|
||||
files.entrySet().iterator().next().setValue(binding.name.getText().toString());
|
||||
Folder folder = (Folder) mFoldersSpinner.getSelectedItem();
|
||||
File directory = new File(folder.path, getSavedSubDirectory());
|
||||
CopyFilesTask mCopyFilesTask = new CopyFilesTask(this, files, folder, directory);
|
||||
|
@ -171,7 +166,7 @@ public class ShareActivity extends StateDialogActivity
|
|||
}
|
||||
});
|
||||
|
||||
browseButton.setOnClickListener(view -> {
|
||||
binding.browseButton.setOnClickListener(view -> {
|
||||
Folder folder = (Folder) mFoldersSpinner.getSelectedItem();
|
||||
File initialDirectory = new File(folder.path, getSavedSubDirectory());
|
||||
startActivityForResult(FolderPickerActivity.createIntent(getApplicationContext(),
|
||||
|
@ -179,7 +174,7 @@ public class ShareActivity extends StateDialogActivity
|
|||
FolderPickerActivity.DIRECTORY_REQUEST_CODE);
|
||||
});
|
||||
|
||||
mCancelButton.setOnClickListener(view -> finish());
|
||||
binding.cancelButton.setOnClickListener(view -> finish());
|
||||
mSubDirectoryTextView.setText(getSavedSubDirectory());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue