use Android view bindings

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2020-12-04 14:54:28 +01:00
parent 9cf14f7e94
commit 9a03dc199d
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B

View file

@ -20,14 +20,9 @@
package com.owncloud.android.ui.fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
@ -35,6 +30,8 @@ import com.google.gson.Gson;
import com.nextcloud.client.account.User;
import com.nextcloud.client.device.DeviceInfo;
import com.owncloud.android.R;
import com.owncloud.android.databinding.FileListActionsBottomSheetCreatorBinding;
import com.owncloud.android.databinding.FileListActionsBottomSheetFragmentBinding;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.FileMenuFilter;
@ -45,44 +42,11 @@ import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ThemeUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
/**
* FAB menu {@link android.app.Dialog} styled as a bottom sheet for main actions.
*/
public class OCFileListBottomSheetDialog extends BottomSheetDialog {
@BindView(R.id.menu_icon_upload_files)
public ImageView iconUploadFiles;
@BindView(R.id.menu_icon_upload_from_app)
public ImageView iconUploadFromApp;
@BindView(R.id.menu_icon_direct_camera_upload)
public ImageView iconDirectCameraUpload;
@BindView(R.id.menu_icon_mkdir)
public ImageView iconMakeDir;
@BindView(R.id.add_to_cloud)
public TextView headline;
@BindView(R.id.templates)
public View templates;
@BindView(R.id.creators)
public LinearLayout creators;
@BindView(R.id.creators_container)
public LinearLayout creatorsContainer;
@BindView(R.id.menu_direct_camera_upload)
public View cameraView;
@BindView(R.id.menu_create_rich_workspace)
public View createRichWorkspace;
private Unbinder unbinder;
private FileListActionsBottomSheetFragmentBinding binding;
private OCFileListBottomSheetActions actions;
private FileActivity fileActivity;
private DeviceInfo deviceInfo;
@ -106,21 +70,20 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final View view = getLayoutInflater().inflate(R.layout.file_list_actions_bottom_sheet_fragment, null);
setContentView(view);
binding = FileListActionsBottomSheetFragmentBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
if (getWindow() != null) {
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
unbinder = ButterKnife.bind(this, view);
int primaryColor = ThemeUtils.primaryColor(getContext(), true);
ThemeUtils.tintDrawable(iconUploadFiles.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(iconUploadFromApp.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(iconDirectCameraUpload.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(iconMakeDir.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(binding.menuIconUploadFiles.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(binding.menuIconUploadFromApp.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(binding.menuIconDirectCameraUpload.getDrawable(), primaryColor);
ThemeUtils.tintDrawable(binding.menuIconMkdir.getDrawable(), primaryColor);
headline.setText(getContext().getResources().getString(R.string.add_to_cloud,
binding.addToCloud.setText(getContext().getResources().getString(R.string.add_to_cloud,
ThemeUtils.getDefaultDisplayNameForRootFolder(getContext())));
OCCapability capability = fileActivity.getCapabilities();
@ -129,7 +92,7 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
capability.getRichDocumentsDirectEditing().isTrue() &&
capability.getRichDocumentsTemplatesAvailable().isTrue() &&
!file.isEncrypted()) {
templates.setVisibility(View.VISIBLE);
binding.templates.setVisibility(View.VISIBLE);
}
String json = new ArbitraryDataProvider(getContext().getContentResolver())
@ -140,19 +103,19 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class);
if (!directEditing.getCreators().isEmpty()) {
creatorsContainer.setVisibility(View.VISIBLE);
binding.creatorsContainer.setVisibility(View.VISIBLE);
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FileListActionsBottomSheetCreatorBinding creatorViewBinding =
FileListActionsBottomSheetCreatorBinding.inflate(getLayoutInflater());
for (Creator creator : directEditing.getCreators().values()) {
View creatorView = vi.inflate(R.layout.file_list_actions_bottom_sheet_creator, null);
((TextView) creatorView.findViewById(R.id.creator_name)).setText(
View creatorView = creatorViewBinding.getRoot();
creatorViewBinding.creatorName.setText(
String.format(fileActivity.getString(R.string.editor_placeholder),
fileActivity.getString(R.string.create_new),
creator.getName()));
ImageView thumbnail = creatorView.findViewById(R.id.creator_thumbnail);
thumbnail.setImageDrawable(MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
creatorViewBinding.creatorThumbnail.setImageDrawable(MimeTypeUtil.getFileTypeIcon(creator.getMimetype(),
creator.getExtension(),
user,
getContext()));
@ -162,13 +125,13 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
dismiss();
});
creators.addView(creatorView);
binding.creators.addView(creatorView);
}
}
}
if (!deviceInfo.hasCamera(getContext())) {
cameraView.setVisibility(View.GONE);
binding.menuDirectCameraUpload.setVisibility(View.GONE);
}
// create rich workspace
@ -181,68 +144,66 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
// == null: disabled on server side -> hide button
// != "": info set -> hide button
if (file.getRichWorkspace() == null || !"".equals(file.getRichWorkspace())) {
createRichWorkspace.setVisibility(View.GONE);
binding.menuCreateRichWorkspace.setVisibility(View.GONE);
} else {
createRichWorkspace.setVisibility(View.VISIBLE);
binding.menuCreateRichWorkspace.setVisibility(View.VISIBLE);
}
} else {
createRichWorkspace.setVisibility(View.GONE);
binding.menuCreateRichWorkspace.setVisibility(View.GONE);
}
createRichWorkspace.setOnClickListener(v -> {
actions.createRichWorkspace();
dismiss();
});
setupClickListener();
setOnShowListener(d ->
BottomSheetBehavior.from((View) view.getParent()).setPeekHeight(view.getMeasuredHeight())
);
}
@OnClick(R.id.menu_mkdir)
public void createFolder() {
actions.createFolder();
dismiss();
private void setupClickListener() {
binding.menuCreateRichWorkspace.setOnClickListener(v -> {
actions.createRichWorkspace();
dismiss();
});
binding.menuIconMkdir.setOnClickListener(v -> {
actions.createFolder();
dismiss();
});
binding.menuUploadFromApp.setOnClickListener(v -> {
actions.uploadFromApp();
dismiss();
});
binding.menuDirectCameraUpload.setOnClickListener(v -> {
actions.directCameraUpload();
dismiss();
});
binding.menuUploadFiles.setOnClickListener(v -> {
actions.uploadFiles();
dismiss();
});
binding.menuNewDocument.setOnClickListener(v -> {
actions.newDocument();
dismiss();
});
binding.menuNewSpreadsheet.setOnClickListener(v -> {
actions.newSpreadsheet();
dismiss();
});
binding.menuNewPresentation.setOnClickListener(v -> {
actions.newPresentation();
dismiss();
});
}
@OnClick(R.id.menu_upload_from_app)
public void uploadFromApp() {
actions.uploadFromApp();
dismiss();
}
@OnClick(R.id.menu_direct_camera_upload)
public void directCameraUpload() {
actions.directCameraUpload();
dismiss();
}
@OnClick(R.id.menu_upload_files)
public void uploadFiles() {
actions.uploadFiles();
dismiss();
}
@OnClick(R.id.menu_new_document)
public void newDocument() {
actions.newDocument();
dismiss();
}
@OnClick(R.id.menu_new_spreadsheet)
public void newSpreadsheet() {
actions.newSpreadsheet();
dismiss();
}
@OnClick(R.id.menu_new_presentation)
public void newPresentation() {
actions.newPresentation();
dismiss();
}
@Override
protected void onStop() {
super.onStop();
unbinder.unbind();
binding = null;
}
}