Skip to content

Commit

Permalink
Set local path hint to remote repo name (#186)
Browse files Browse the repository at this point in the history
* Set local path hint to remote repo name
* Strip '.git' from repo URL
Signed-off-by: Dave Brown <[email protected]>
  • Loading branch information
bigdavedev authored and maks committed Jun 2, 2016
1 parent b374b41 commit 6a2e48d
Showing 1 changed file with 45 additions and 5 deletions.
50 changes: 45 additions & 5 deletions src/me/sheimi/sgit/dialogs/CloneDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,38 @@ public class CloneDialog extends SheimiDialogFragment implements
private RepoListActivity mActivity;
private Repo mRepo;

@Override
private class RemoteUrlFocusListener implements View.OnFocusChangeListener {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (!hasFocus) {
final String remoteUrl = mRemoteURL.getText().toString();
String localHint = stripUrlFromRepo(remoteUrl);
localHint = stripGitExtension(localHint);
if (!localHint.equals("")) {
mLocalPath.setHint(localHint);
}
}
}

private String stripUrlFromRepo(final String remoteUrl) {
final int lastSlash = remoteUrl.lastIndexOf("/");
if (lastSlash != -1) {
return remoteUrl.substring(lastSlash + 1);
}

return remoteUrl;
}

private String stripGitExtension(final String remoteUrl) {
final int extension = remoteUrl.indexOf(".git");
if (extension != -1) {
return remoteUrl.substring(0, extension);
}

return remoteUrl;
}
}

public Dialog onCreateDialog(Bundle savedInstanceState) {
super.onCreateDialog(savedInstanceState);
mActivity = (RepoListActivity) getActivity();
Expand All @@ -64,6 +95,8 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
mLocalPath.setText(Repo.TEST_LOCAL);
}

mRemoteURL.setOnFocusChangeListener(new RemoteUrlFocusListener());

// set button listener
builder.setTitle(R.string.title_clone_repo);
builder.setNegativeButton(R.string.label_cancel,
Expand Down Expand Up @@ -116,10 +149,12 @@ public void onClick(View view) {
return;
}
if (localPath.equals("")) {
showToastMessage(R.string.alert_localpath_required);
mLocalPath.setError(getString(R.string.alert_localpath_required));
mLocalPath.requestFocus();
return;
if (mLocalPath.getHint().equals(getString(R.string.dialog_clone_local_path_hint))) {
showToastMessage(R.string.alert_localpath_required);
mLocalPath.setError(getString(R.string.alert_localpath_required));
mLocalPath.requestFocus();
return;
}
}
if (localPath.contains("/")) {
showToastMessage(R.string.alert_localpath_format);
Expand All @@ -128,6 +163,11 @@ public void onClick(View view) {
return;
}

// If user is accepting the default path in the hint, we need to set localPath to
// the string in the hint, so that the following checks don't fail.
if (mLocalPath.getHint().toString() != getString(R.string.dialog_clone_local_path_hint)) {
localPath = mLocalPath.getHint().toString();
}
File file = Repo.getDir(localPath);
if (file.exists()) {
showToastMessage(R.string.alert_localpath_repo_exists);
Expand Down

0 comments on commit 6a2e48d

Please sign in to comment.