mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 15:15:51 +03:00
use Android view bindings
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
9cf14f7e94
commit
9a03dc199d
1 changed files with 64 additions and 103 deletions
|
@ -20,14 +20,9 @@
|
||||||
|
|
||||||
package com.owncloud.android.ui.fragment;
|
package com.owncloud.android.ui.fragment;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
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.BottomSheetBehavior;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
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.account.User;
|
||||||
import com.nextcloud.client.device.DeviceInfo;
|
import com.nextcloud.client.device.DeviceInfo;
|
||||||
import com.owncloud.android.R;
|
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.ArbitraryDataProvider;
|
||||||
import com.owncloud.android.datamodel.OCFile;
|
import com.owncloud.android.datamodel.OCFile;
|
||||||
import com.owncloud.android.files.FileMenuFilter;
|
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.MimeTypeUtil;
|
||||||
import com.owncloud.android.utils.ThemeUtils;
|
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.
|
* FAB menu {@link android.app.Dialog} styled as a bottom sheet for main actions.
|
||||||
*/
|
*/
|
||||||
public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
||||||
@BindView(R.id.menu_icon_upload_files)
|
private FileListActionsBottomSheetFragmentBinding binding;
|
||||||
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 OCFileListBottomSheetActions actions;
|
private OCFileListBottomSheetActions actions;
|
||||||
private FileActivity fileActivity;
|
private FileActivity fileActivity;
|
||||||
private DeviceInfo deviceInfo;
|
private DeviceInfo deviceInfo;
|
||||||
|
@ -106,21 +70,20 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
final View view = getLayoutInflater().inflate(R.layout.file_list_actions_bottom_sheet_fragment, null);
|
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) {
|
if (getWindow() != null) {
|
||||||
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
unbinder = ButterKnife.bind(this, view);
|
|
||||||
|
|
||||||
int primaryColor = ThemeUtils.primaryColor(getContext(), true);
|
int primaryColor = ThemeUtils.primaryColor(getContext(), true);
|
||||||
ThemeUtils.tintDrawable(iconUploadFiles.getDrawable(), primaryColor);
|
ThemeUtils.tintDrawable(binding.menuIconUploadFiles.getDrawable(), primaryColor);
|
||||||
ThemeUtils.tintDrawable(iconUploadFromApp.getDrawable(), primaryColor);
|
ThemeUtils.tintDrawable(binding.menuIconUploadFromApp.getDrawable(), primaryColor);
|
||||||
ThemeUtils.tintDrawable(iconDirectCameraUpload.getDrawable(), primaryColor);
|
ThemeUtils.tintDrawable(binding.menuIconDirectCameraUpload.getDrawable(), primaryColor);
|
||||||
ThemeUtils.tintDrawable(iconMakeDir.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())));
|
ThemeUtils.getDefaultDisplayNameForRootFolder(getContext())));
|
||||||
|
|
||||||
OCCapability capability = fileActivity.getCapabilities();
|
OCCapability capability = fileActivity.getCapabilities();
|
||||||
|
@ -129,7 +92,7 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
||||||
capability.getRichDocumentsDirectEditing().isTrue() &&
|
capability.getRichDocumentsDirectEditing().isTrue() &&
|
||||||
capability.getRichDocumentsTemplatesAvailable().isTrue() &&
|
capability.getRichDocumentsTemplatesAvailable().isTrue() &&
|
||||||
!file.isEncrypted()) {
|
!file.isEncrypted()) {
|
||||||
templates.setVisibility(View.VISIBLE);
|
binding.templates.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
String json = new ArbitraryDataProvider(getContext().getContentResolver())
|
String json = new ArbitraryDataProvider(getContext().getContentResolver())
|
||||||
|
@ -140,19 +103,19 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
||||||
DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class);
|
DirectEditing directEditing = new Gson().fromJson(json, DirectEditing.class);
|
||||||
|
|
||||||
if (!directEditing.getCreators().isEmpty()) {
|
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()) {
|
for (Creator creator : directEditing.getCreators().values()) {
|
||||||
View creatorView = vi.inflate(R.layout.file_list_actions_bottom_sheet_creator, null);
|
View creatorView = creatorViewBinding.getRoot();
|
||||||
((TextView) creatorView.findViewById(R.id.creator_name)).setText(
|
creatorViewBinding.creatorName.setText(
|
||||||
String.format(fileActivity.getString(R.string.editor_placeholder),
|
String.format(fileActivity.getString(R.string.editor_placeholder),
|
||||||
fileActivity.getString(R.string.create_new),
|
fileActivity.getString(R.string.create_new),
|
||||||
creator.getName()));
|
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(),
|
creator.getExtension(),
|
||||||
user,
|
user,
|
||||||
getContext()));
|
getContext()));
|
||||||
|
@ -162,13 +125,13 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
||||||
dismiss();
|
dismiss();
|
||||||
});
|
});
|
||||||
|
|
||||||
creators.addView(creatorView);
|
binding.creators.addView(creatorView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!deviceInfo.hasCamera(getContext())) {
|
if (!deviceInfo.hasCamera(getContext())) {
|
||||||
cameraView.setVisibility(View.GONE);
|
binding.menuDirectCameraUpload.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// create rich workspace
|
// create rich workspace
|
||||||
|
@ -181,68 +144,66 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
|
||||||
// == null: disabled on server side -> hide button
|
// == null: disabled on server side -> hide button
|
||||||
// != "": info set -> hide button
|
// != "": info set -> hide button
|
||||||
if (file.getRichWorkspace() == null || !"".equals(file.getRichWorkspace())) {
|
if (file.getRichWorkspace() == null || !"".equals(file.getRichWorkspace())) {
|
||||||
createRichWorkspace.setVisibility(View.GONE);
|
binding.menuCreateRichWorkspace.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
createRichWorkspace.setVisibility(View.VISIBLE);
|
binding.menuCreateRichWorkspace.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
createRichWorkspace.setVisibility(View.GONE);
|
binding.menuCreateRichWorkspace.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
createRichWorkspace.setOnClickListener(v -> {
|
setupClickListener();
|
||||||
actions.createRichWorkspace();
|
|
||||||
dismiss();
|
|
||||||
});
|
|
||||||
|
|
||||||
setOnShowListener(d ->
|
setOnShowListener(d ->
|
||||||
BottomSheetBehavior.from((View) view.getParent()).setPeekHeight(view.getMeasuredHeight())
|
BottomSheetBehavior.from((View) view.getParent()).setPeekHeight(view.getMeasuredHeight())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick(R.id.menu_mkdir)
|
private void setupClickListener() {
|
||||||
public void createFolder() {
|
binding.menuCreateRichWorkspace.setOnClickListener(v -> {
|
||||||
actions.createFolder();
|
actions.createRichWorkspace();
|
||||||
dismiss();
|
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
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
unbinder.unbind();
|
binding = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue