Improved clone screen and added preliminary support for custom ports, fix #14

This commit is contained in:
knuthy 2014-10-01 23:20:51 +02:00
parent ff3c3f94d1
commit 34999c2bd5
3 changed files with 92 additions and 10 deletions

View file

@ -9,6 +9,7 @@ import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.InputType;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@ -48,6 +49,10 @@ import org.eclipse.jgit.util.FS;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
// TODO move the messages to strings.xml
@ -147,6 +152,7 @@ public class GitHandler extends Activity {
EditText server_port = ((EditText) findViewById(R.id.server_port));
EditText server_path = ((EditText) findViewById(R.id.server_path));
EditText server_user = ((EditText) findViewById(R.id.server_user));
final EditText server_uri = ((EditText)findViewById(R.id.clone_uri));
View.OnKeyListener updateListener = new View.OnKeyListener() {
@Override
@ -165,6 +171,15 @@ public class GitHandler extends Activity {
server_port.setOnKeyListener(updateListener);
server_user.setOnKeyListener(updateListener);
server_path.setOnKeyListener(updateListener);
server_uri.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
splitURI();
return false;
}
});
break;
case REQUEST_PULL:
authenticateAndRun("pullOperation");
@ -178,7 +193,8 @@ public class GitHandler extends Activity {
}
public void updateURI() {
/** Fills in the server_uri field with the information coming from other fields */
private void updateURI() {
EditText uri = (EditText) findViewById(R.id.clone_uri);
EditText server_url = ((EditText) findViewById(R.id.server_url));
EditText server_port = ((EditText) findViewById(R.id.server_port));
@ -190,13 +206,53 @@ public class GitHandler extends Activity {
server_user.getText()
+ "@" +
server_url.getText().toString().trim()
+ ":" +
server_path.getText();
+ ":";
if (server_port.getText().toString().equals("22")) {
hostname += server_path.getText().toString();
} else {
TextView warn_url = (TextView) findViewById(R.id.warn_url);
if (!server_path.getText().toString().matches("/.*")) {
warn_url.setText(R.string.warn_malformed_url_port);
warn_url.setVisibility(View.VISIBLE);
} else {
warn_url.setVisibility(View.GONE);
}
hostname += server_port.getText().toString() + server_path.getText().toString();
}
if (!hostname.equals("@:")) uri.setText(hostname);
}
}
/** Splits the information in server_uri into the other fields */
private void splitURI() {
EditText server_uri = (EditText) findViewById(R.id.clone_uri);
EditText server_url = ((EditText) findViewById(R.id.server_url));
EditText server_port = ((EditText) findViewById(R.id.server_port));
EditText server_path = ((EditText) findViewById(R.id.server_path));
EditText server_user = ((EditText) findViewById(R.id.server_user));
String uri = server_uri.getText().toString();
Pattern pattern = Pattern.compile("(.+)@([\\w\\d\\.]+):([\\d]+)*(.*)");
Matcher matcher = pattern.matcher(uri);
if (matcher.find()) {
int count = matcher.groupCount();
Log.i("GIT", ">> " + count);
if (count > 1) {
server_user.setText(matcher.group(1));
server_url.setText(matcher.group(2));
}
if (count == 3) {
server_path.setText(matcher.group(3));
server_port.setText("22");
}
if (count == 4) {
server_port.setText(matcher.group(3));
server_path.setText(matcher.group(4));
}
}
}
@Override
public void onResume() {
super.onResume();

View file

@ -137,6 +137,13 @@
android:layout_alignParentEnd="true"/>
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/red_rectangle"
android:textColor="@android:color/white"
android:visibility="gone"
android:id="@+id/warn_url"/>
<TextView
android:layout_width="fill_parent"
@ -156,21 +163,37 @@
android:layout_height="wrap_content"
android:inputType="textWebEmailAddress"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connection_mode"
android:id="@+id/label_connection_mode"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/connection_mode"
android:layout_column="1"
android:layout_row="2"/>
android:layout_toEndOf="@+id/label_connection_mode"
android:layout_toRightOf="@+id/label_connection_mode" />
</RelativeLayout>
<Button
android:id="@+id/clone_button"
android:text="Clone!"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="cloneRepository"
android:layout_column="1"
android:layout_row="4"/>
android:onClick="cloneRepository"/>
</LinearLayout>

View file

@ -30,6 +30,9 @@
<string name="server_user_hint">git_username</string>
<string name="server_resulting_url">Resulting URL</string>
<string name="connection_mode">Authentication Mode</string>
<string name="warn_malformed_url_port">When using custom ports, provide an absolute path (starts with "/")</string>
<!-- PGP Handler -->
<string name="title_activity_pgp_handler">PgpHandler</string>