Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-03-03 14:22:50 +01:00
parent 7ca6f304ed
commit 30ac72652e
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
3 changed files with 80 additions and 109 deletions

View file

@ -42,6 +42,7 @@ import org.junit.Test;
import java.io.File;
import java.io.IOException;
import androidx.fragment.app.DialogFragment;
import androidx.test.espresso.intent.rule.IntentsTestRule;
import static androidx.test.espresso.Espresso.onView;
@ -76,17 +77,12 @@ public class ConflictsResolveActivityIT extends AbstractIT {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
dialog.showDialog(sut);
getInstrumentation().waitForIdleSync();
@ -132,24 +128,23 @@ public class ConflictsResolveActivityIT extends AbstractIT {
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
dialog.showDialog(sut);
dialog.listener = listener;
getInstrumentation().waitForIdleSync();
Thread.sleep(10000);
Thread.sleep(2000);
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
}
@Test
public void cancel() {
public void cancel() throws InterruptedException {
returnCode = false;
OCUpload newUpload = new OCUpload(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt",
@ -168,21 +163,13 @@ public class ConflictsResolveActivityIT extends AbstractIT {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
sut.listener = decision -> {
assertEquals(decision, ConflictsResolveDialog.Decision.CANCEL);
returnCode = true;
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
dialog.showDialog(sut);
getInstrumentation().waitForIdleSync();
Thread.sleep(2000);
onView(withText("Cancel")).perform(click());
@ -209,24 +196,16 @@ public class ConflictsResolveActivityIT extends AbstractIT {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
sut.listener = decision -> {
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
returnCode = true;
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
dialog.showDialog(sut);
getInstrumentation().waitForIdleSync();
onView(withId(R.id.existing_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
onView(withText("OK")).perform(click());
@ -254,24 +233,16 @@ public class ConflictsResolveActivityIT extends AbstractIT {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
sut.listener = decision -> {
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
returnCode = true;
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
dialog.showDialog(sut);
getInstrumentation().waitForIdleSync();
onView(withId(R.id.new_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
onView(withText("OK")).perform(click());
@ -299,25 +270,17 @@ public class ConflictsResolveActivityIT extends AbstractIT {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
sut.listener = decision -> {
assertEquals(decision, ConflictsResolveDialog.Decision.KEEP_SERVER);
returnCode = true;
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
.getUser()
);
dialog.showDialog(sut);
getInstrumentation().waitForIdleSync();
onView(withId(R.id.existing_checkbox)).perform(click());
onView(withId(R.id.new_checkbox)).perform(click());
DialogFragment dialog = (DialogFragment) sut.getSupportFragmentManager().findFragmentByTag("conflictDialog");
Screenshot.snap(dialog.getDialog().getWindow().getDecorView()).record();
onView(withText("OK")).perform(click());

View file

@ -63,6 +63,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
private OCUpload conflictUpload;
private int localBehaviour = FileUploader.LOCAL_BEHAVIOUR_FORGET;
protected OnConflictDecisionMadeListener listener;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -79,6 +80,59 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
if (conflictUpload != null) {
localBehaviour = conflictUpload.getLocalAction();
}
listener = new OnConflictDecisionMadeListener() {
@Override
public void conflictDecisionMade(Decision decision) {
OCFile file = getFile();
switch (decision) {
case CANCEL:
// nothing to do
break;
case KEEP_LOCAL: // Upload
FileUploader.uploadUpdateFile(
getBaseContext(),
getAccount(),
file,
localBehaviour,
FileUploader.NameCollisionPolicy.OVERWRITE
);
if (conflictUpload != null) {
uploadsStorageManager.removeUpload(conflictUpload);
}
break;
case KEEP_BOTH: // Upload
FileUploader.uploadUpdateFile(
getBaseContext(),
getAccount(),
file,
localBehaviour,
FileUploader.NameCollisionPolicy.RENAME
);
if (conflictUpload != null) {
uploadsStorageManager.removeUpload(conflictUpload);
}
break;
case KEEP_SERVER: // Download
if (!shouldDeleteLocal()) {
// Overwrite local file
Intent intent = new Intent(getBaseContext(), FileDownloader.class);
intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
intent.putExtra(FileDownloader.EXTRA_FILE, file);
if (conflictUpload != null) {
intent.putExtra(FileDownloader.EXTRA_CONFLICT_UPLOAD, conflictUpload);
}
startService(intent);
}
break;
}
finish();
}
};
}
@Override
@ -91,53 +145,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
@Override
public void conflictDecisionMade(Decision decision) {
OCFile file = getFile();
switch (decision) {
case CANCEL:
// nothing to do
break;
case KEEP_LOCAL: // Upload
FileUploader.uploadUpdateFile(
this,
getAccount(),
file,
localBehaviour,
FileUploader.NameCollisionPolicy.OVERWRITE
);
if (conflictUpload != null) {
uploadsStorageManager.removeUpload(conflictUpload);
}
break;
case KEEP_BOTH: // Upload
FileUploader.uploadUpdateFile(
this,
getAccount(),
file,
localBehaviour,
FileUploader.NameCollisionPolicy.RENAME
);
if (conflictUpload != null) {
uploadsStorageManager.removeUpload(conflictUpload);
}
break;
case KEEP_SERVER: // Download
if (!this.shouldDeleteLocal()) {
// Overwrite local file
Intent intent = new Intent(this, FileDownloader.class);
intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
intent.putExtra(FileDownloader.EXTRA_FILE, file);
if (conflictUpload != null) {
intent.putExtra(FileDownloader.EXTRA_CONFLICT_UPLOAD, conflictUpload);
}
startService(intent);
}
break;
}
finish();
listener.conflictDecisionMade(decision);
}
@Override

View file

@ -64,7 +64,7 @@ public class ConflictsResolveDialog extends DialogFragment {
private OCFile existingFile;
private File newFile;
private OnConflictDecisionMadeListener listener;
public OnConflictDecisionMadeListener listener;
private User user;
private List<ThumbnailsCacheManager.ThumbnailGenerationTask> asyncTasks = new ArrayList<>();