Skip to content

Commit

Permalink
Refactor UI: Credentials dialog
Browse files Browse the repository at this point in the history
  Gutted UI setup for swipe views
  and implemented a email/pass dialog
  UI is still a bit of a mess.

  ADDED: email pass dialog
  ADDED: swipe views w/ header
  FIXED: request email/pass from user
  DELED: most of the previous UI
  • Loading branch information
3jb committed Sep 22, 2012
1 parent a1ab9da commit 3b7e206
Show file tree
Hide file tree
Showing 9 changed files with 249 additions and 163 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bin/
gen/
libs/
7 changes: 1 addition & 6 deletions res/layout/main.xml → res/layout/cred_req.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:background="@color/white"
android:gravity="center_horizontal|center_vertical"
>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello udacity"
/>
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
Expand Down
27 changes: 27 additions & 0 deletions res/layout/udacity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">


<LinearLayout android:orientation="horizontal"
android:gravity="center" android:measureWithLargestChild="true"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_weight="0">
<TextView
style="@style/CodeFont"
android:text="@string/status_start"
/>
</LinearLayout>

<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1">
</android.support.v4.view.ViewPager>

</LinearLayout>
2 changes: 1 addition & 1 deletion res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
<color name="white">#fff</color>
<color name="red">#f00</color>
<color name="green">#0f0</color>
<color name="light_gray">#aaa</color>
<color name="light_gray">#ffa0a0a0</color>
</resources>
36 changes: 19 additions & 17 deletions src/com/appittome/udacity/client/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ protected JSONObject getJSONCredentials() {
public void checkCredentials() {
new LoadWithCredentialsTask().execute(url);
}
public void fetchNewCookie() {
new FetchNewCookieTask().execute(url);
}
private boolean loggedInto(String page) {
return page.contains("Sign Out");
}
Expand All @@ -59,7 +62,7 @@ protected String doInBackground(URL... urls){
@Override
protected void onPostExecute(String result) {
if(!loggedInto(result)){
new FetchNewCookieTask().execute(url);
fetchNewCookie();
} else {
//TODO possible nasty loop here…
showMessage("Logged In");
Expand All @@ -70,41 +73,40 @@ protected void onPostExecute(String result) {

private class FetchNewCookieTask extends AsyncTask<URL, Integer, String>
{
public static final String MISSING_CREDENTIALS = "001";
@Override
protected String doInBackground(URL... urls){
String retVal = "";
try{
retVal = sendJSON(getJSONCredentials(), new URL(urls[0], AJAX_SPEC) );
} catch (IOException e) {
retVal = "Unable to retreive webpage. URL may be invalid";
} finally {
return retVal;
} catch (NullPointerException e){
retVal = MISSING_CREDENTIALS;
}
return retVal;
//}
}
@Override
protected void onPostExecute(String result) {
try {
showMessage("result::" + result);
JSONObject JSONResp = new JSONObject(result);
if (!result.equals(MISSING_CREDENTIALS)){
try {
String reply = JSONResp.getString("win");
//showMessage(reply);
if( reply.compareTo("loaded cookie") == 0 ) {
try {
new LoadWithCredentialsTask().execute(new URL("http://192.168.1.11:3000"));
} catch (MalformedURLException e) {
Log.w("AuthenticateTask", e);
JSONObject JSONResp = new JSONObject(result);
try {
String reply = JSONResp.getString("win");
//showMessage(reply);
if( reply.compareTo("loaded cookie") == 0 ) {
checkCredentials();
}
} catch (JSONException e) {
showMessage(JSONResp.toString(2));
}
} catch (JSONException e) {
showMessage(JSONResp.toString(2));
showMessage("Invalid JSON returned::" + e);
}
} catch (JSONException e) {
showMessage("Invalid JSON returned::" + e);
}
}
}

//---CONNECTION TYPES---//
private String grabPage(URL url) throws IOException
{
Expand Down
23 changes: 18 additions & 5 deletions src/com/appittome/udacity/client/SignInCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class SignInCredentials {
private static final String METHOD = "account.sign-in";
private static final String VERSION = "dacity-45";

public class NullCredentialsException extends NullPointerException {
public NullCredentialsException(String msg) {
super(msg);
}
}

public SignInCredentials() {
this(null,null);
}
Expand All @@ -34,14 +40,18 @@ public void setCsrf_token(String csrf_token) {
this.csrf_token = csrf_token;
}
//public attributes
public String getEmail(){
public String getEmail() throws NullCredentialsException {
if (this.email == null)
throw new NullCredentialsException("email");
return this.email;
}
}
public int getPasswordLength() {
return this.password.length();
}
//private attributes
protected String getPassword(){
protected String getPassword() throws NullCredentialsException {
if (this.email == null)
throw new NullCredentialsException("email");
return this.password;
}
protected String getCsrf_token() {
Expand All @@ -51,7 +61,7 @@ protected String getCsrf_token() {
public JSONObject toJSON() {
JSONObject retObj = new JSONObject();
JSONObject data = new JSONObject();

Log.w("SignInCredentials.toJSON", "begin assembling JSON…");
try {
//User relavant attibutes
data.put("email", getEmail());
Expand All @@ -62,7 +72,10 @@ public JSONObject toJSON() {
retObj.put("version", VERSION);
retObj.put("csrf_token", getCsrf_token());
} catch (JSONException e) {
Log.w("collectForSubmission()", e);
Log.w("SignInCredentials.toJSON()", e);
} catch (NullCredentialsException e) {
Log.w("SignInCredentials.toJSON()", e);
throw new NullCredentialsException("Cannot Construct Credentials");
}
return retObj;
}
Expand Down
114 changes: 0 additions & 114 deletions src/com/appittome/udacity/client/UdaUserInterface.java

This file was deleted.

Loading

0 comments on commit 3b7e206

Please sign in to comment.