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,12 +77,7 @@ public class ConflictsResolveActivityIT extends AbstractIT {
ConflictsResolveActivity sut = activityRule.launchActivity(intent);
ConflictsResolveDialog.OnConflictDecisionMadeListener listener = decision -> {
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
ConflictsResolveDialog dialog = ConflictsResolveDialog.newInstance(existingFile,
newUpload,
UserAccountManagerImpl
.fromContext(targetContext)
@ -132,24 +128,23 @@ public class ConflictsResolveActivityIT extends AbstractIT {
};
ConflictsResolveDialog dialog = new ConflictsResolveDialog(listener,
existingFile,
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,16 +80,8 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
if (conflictUpload != null) {
localBehaviour = conflictUpload.getLocalAction();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(EXTRA_CONFLICT_UPLOAD, conflictUpload);
outState.putInt(EXTRA_LOCAL_BEHAVIOUR, localBehaviour);
}
listener = new OnConflictDecisionMadeListener() {
@Override
public void conflictDecisionMade(Decision decision) {
OCFile file = getFile();
@ -99,7 +92,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
break;
case KEEP_LOCAL: // Upload
FileUploader.uploadUpdateFile(
this,
getBaseContext(),
getAccount(),
file,
localBehaviour,
@ -112,7 +105,7 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
break;
case KEEP_BOTH: // Upload
FileUploader.uploadUpdateFile(
this,
getBaseContext(),
getAccount(),
file,
localBehaviour,
@ -124,9 +117,9 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
}
break;
case KEEP_SERVER: // Download
if (!this.shouldDeleteLocal()) {
if (!shouldDeleteLocal()) {
// Overwrite local file
Intent intent = new Intent(this, FileDownloader.class);
Intent intent = new Intent(getBaseContext(), FileDownloader.class);
intent.putExtra(FileDownloader.EXTRA_ACCOUNT, getAccount());
intent.putExtra(FileDownloader.EXTRA_FILE, file);
if (conflictUpload != null) {
@ -139,6 +132,21 @@ public class ConflictsResolveActivity extends FileActivity implements OnConflict
finish();
}
};
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(EXTRA_CONFLICT_UPLOAD, conflictUpload);
outState.putInt(EXTRA_LOCAL_BEHAVIOUR, localBehaviour);
}
@Override
public void conflictDecisionMade(Decision decision) {
listener.conflictDecisionMade(decision);
}
@Override
protected void onStart() {

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<>();