Merge pull request #7829 from nextcloud/fixCrashOnMultipleCreators

Fix crash when multiple editors are shown
This commit is contained in:
Tobias Kaminsky 2021-01-14 15:12:24 +01:00 committed by GitHub
commit ebdf716e11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 3 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View file

@ -30,13 +30,19 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.google.gson.Gson;
import com.nextcloud.client.account.RegisteredUser;
import com.nextcloud.client.account.Server;
import com.nextcloud.client.device.DeviceInfo;
import com.nextcloud.ui.ChooseAccountDialogFragment;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.Creator;
import com.owncloud.android.lib.common.DirectEditing;
import com.owncloud.android.lib.common.Editor;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.accounts.AccountUtils;
import com.owncloud.android.lib.resources.status.CapabilityBooleanType;
@ -45,6 +51,9 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.lib.resources.users.Status;
import com.owncloud.android.lib.resources.users.StatusType;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetActions;
import com.owncloud.android.ui.fragment.OCFileListBottomSheetDialog;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ScreenshotTest;
import org.junit.Rule;
@ -52,6 +61,7 @@ import org.junit.Test;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Objects;
import androidx.fragment.app.DialogFragment;
@ -223,6 +233,115 @@ public class DialogFragmentIT extends AbstractIT {
showDialog(sut);
}
@Test
@ScreenshotTest
public void testBottomSheet() {
if (Looper.myLooper() == null) {
Looper.prepare();
}
OCFileListBottomSheetActions action = new OCFileListBottomSheetActions() {
@Override
public void createFolder() {
}
@Override
public void uploadFromApp() {
}
@Override
public void uploadFiles() {
}
@Override
public void newDocument() {
}
@Override
public void newSpreadsheet() {
}
@Override
public void newPresentation() {
}
@Override
public void directCameraUpload() {
}
@Override
public void showTemplate(Creator creator) {
}
@Override
public void createRichWorkspace() {
}
};
DeviceInfo info = new DeviceInfo();
OCFile ocFile = new OCFile("/test.md");
Intent intent = new Intent(targetContext, FileDisplayActivity.class);
FileDisplayActivity fda = activityRule.launchActivity(intent);
// add direct editing info
DirectEditing directEditing = new DirectEditing();
directEditing.creators.put("1", new Creator("1",
"text",
"text file",
".md",
"application/octet-stream",
false));
directEditing.creators.put("2", new Creator("2",
"md",
"markdown file",
".md",
"application/octet-stream",
false));
directEditing.editors.put("text",
new Editor("1",
"Text",
new ArrayList<>(Collections.singletonList(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN)),
new ArrayList<>(),
false));
String json = new Gson().toJson(directEditing);
new ArbitraryDataProvider(targetContext.getContentResolver()).storeOrUpdateKeyValue(user.getAccountName(),
ArbitraryDataProvider.DIRECT_EDITING,
json);
// activate templates
OCCapability capability = fda.getCapabilities();
capability.setRichDocuments(CapabilityBooleanType.TRUE);
capability.setRichDocumentsDirectEditing(CapabilityBooleanType.TRUE);
capability.setRichDocumentsTemplatesAvailable(CapabilityBooleanType.TRUE);
OCFileListBottomSheetDialog sut = new OCFileListBottomSheetDialog(fda,
action,
info,
user,
ocFile);
fda.runOnUiThread(sut::show);
waitForIdleSync();
screenshot(sut.getWindow().getDecorView());
}
private FileDisplayActivity showDialog(DialogFragment dialog) {
Intent intent = new Intent(targetContext, FileDisplayActivity.class);
FileDisplayActivity sut = activityRule.launchActivity(intent);

View file

@ -104,11 +104,12 @@ public class OCFileListBottomSheetDialog extends BottomSheetDialog {
if (!directEditing.getCreators().isEmpty()) {
binding.creatorsContainer.setVisibility(View.VISIBLE);
FileListActionsBottomSheetCreatorBinding creatorViewBinding =
FileListActionsBottomSheetCreatorBinding.inflate(getLayoutInflater());
for (Creator creator : directEditing.getCreators().values()) {
FileListActionsBottomSheetCreatorBinding creatorViewBinding =
FileListActionsBottomSheetCreatorBinding.inflate(getLayoutInflater());
View creatorView = creatorViewBinding.getRoot();
creatorViewBinding.creatorName.setText(
String.format(fileActivity.getString(R.string.editor_placeholder),
fileActivity.getString(R.string.create_new),