verify that the server information is set before pulling/pushing

This commit is contained in:
knuthy 2014-08-10 17:03:23 +01:00
parent cd28c358a4
commit c3c3acda2c

View file

@ -26,6 +26,7 @@ import android.widget.TextView;
import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.utils.PasswordRepository; import com.zeapo.pwdstore.utils.PasswordRepository;
import org.eclipse.jgit.api.CloneCommand; import org.eclipse.jgit.api.CloneCommand;
@ -407,6 +408,30 @@ public class GitHandler extends Activity {
} }
public void pullOperation(UsernamePasswordCredentialsProvider provider) { public void pullOperation(UsernamePasswordCredentialsProvider provider) {
if (settings.getString("git_remote_username", "user").isEmpty() ||
settings.getString("git_remote_server", "server.com").isEmpty() ||
settings.getString("git_remote_location", "path/to/repository").isEmpty() )
new AlertDialog.Builder(this)
.setMessage("You have to set the information about the server before synchronizing with the server")
.setPositiveButton("On my way!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(activity, UserPreference.class);
startActivityForResult(intent, REQUEST_PULL);
}
})
.setNegativeButton("Nah... later", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// do nothing :(
setResult(RESULT_OK);
finish();
}
})
.show();
else
new GitAsyncTask(activity, true).execute(new Git(PasswordRepository.getRepository(new File(""))) new GitAsyncTask(activity, true).execute(new Git(PasswordRepository.getRepository(new File("")))
.pull() .pull()
.setRebase(true) .setRebase(true)
@ -415,6 +440,29 @@ public class GitHandler extends Activity {
public void pushOperation(UsernamePasswordCredentialsProvider provider) { public void pushOperation(UsernamePasswordCredentialsProvider provider) {
if (settings.getString("git_remote_username", "user").isEmpty() ||
settings.getString("git_remote_server", "server.com").isEmpty() ||
settings.getString("git_remote_location", "path/to/repository").isEmpty() )
new AlertDialog.Builder(this)
.setMessage("You have to set the information about the server before synchronizing with the server")
.setPositiveButton("On my way!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(activity, UserPreference.class);
startActivityForResult(intent, REQUEST_PUSH);
}
})
.setNegativeButton("Nah... later", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// do nothing :(
setResult(RESULT_OK);
finish();
}
})
.show();
else
new GitAsyncTask(activity, true).execute(new Git(PasswordRepository.getRepository(new File(""))) new GitAsyncTask(activity, true).execute(new Git(PasswordRepository.getRepository(new File("")))
.push() .push()
.setCredentialsProvider(provider)); .setCredentialsProvider(provider));
@ -482,4 +530,26 @@ public class GitHandler extends Activity {
} }
} }
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (resultCode == RESULT_CANCELED) {
setResult(RESULT_CANCELED);
finish();
return;
}
if (resultCode == RESULT_OK) {
switch (requestCode) {
case REQUEST_PULL:
authenticateAndRun("pullOperation");
break;
case REQUEST_PUSH:
authenticateAndRun("pushOperation");
break;
}
}
}
} }