linked: work on github design

This commit is contained in:
Vincent Breitmoser
2015-09-01 07:09:53 +02:00
parent b52a0303ca
commit 3e55fca0e5
3 changed files with 102 additions and 57 deletions

View File

@@ -36,7 +36,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ViewAnimator;
import javax.net.ssl.HttpsURLConnection;
@@ -51,8 +50,7 @@ import org.sufficientlysecure.keychain.util.Log;
public class LinkedIdCreateGithubFragment extends Fragment {
ViewAnimator mProceedContainer;
EditText mGithubUsername, mGithubPassword;
ViewAnimator mButtonContainer;
StatusIndicator mStatus1, mStatus2, mStatus3;
@@ -64,10 +62,7 @@ public class LinkedIdCreateGithubFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.linked_create_github_fragment, container, false);
mProceedContainer = (ViewAnimator) view.findViewById(R.id.proceed_container);
mGithubUsername = (EditText) view.findViewById(R.id.username);
mGithubPassword = (EditText) view.findViewById(R.id.password);
mButtonContainer = (ViewAnimator) view.findViewById(R.id.button_container);
mStatus1 = (StatusIndicator) view.findViewById(R.id.linked_status_step1);
mStatus2 = (StatusIndicator) view.findViewById(R.id.linked_status_step2);
@@ -102,13 +97,25 @@ public class LinkedIdCreateGithubFragment extends Fragment {
protected JSONObject doInBackground(Void... dummy) {
try {
long timer = System.currentTimeMillis();
JSONObject params = new JSONObject();
params.put("client_id", "7a011b66275f244d3f21");
params.put("client_secret", "eaced8a6655719d8c6848396de97b3f5d7a89fec");
params.put("code", oAuthCode);
params.put("state", oAuthState);
return jsonHttpRequest("https://github.com/login/oauth/access_token", params, null);
JSONObject result = jsonHttpRequest("https://github.com/login/oauth/access_token", params, null);
// ux flow: this operation should take at last a second
timer = System.currentTimeMillis() -timer;
if (timer < 1000) try {
Thread.sleep(1000 -timer);
} catch (InterruptedException e) {
// never mind
}
return result;
} catch (IOException e) {
Log.e(Constants.TAG, "error in request", e);
@@ -143,10 +150,30 @@ public class LinkedIdCreateGithubFragment extends Fragment {
mStatus2.setDisplayedChild(0);
mStatus3.setDisplayedChild(0);
mProceedContainer.setDisplayedChild(1);
mButtonContainer.setDisplayedChild(1);
LinkedIdWizard wizard = (LinkedIdWizard) getActivity();
wizard.oAuthRequest("github.com/login/oauth/authorize", "7a011b66275f244d3f21", "gist");
new AsyncTask<Void,Void,Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
// never mind
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
LinkedIdWizard wizard = (LinkedIdWizard) getActivity();
if (wizard == null) {
return;
}
wizard.oAuthRequest("github.com/login/oauth/authorize", "7a011b66275f244d3f21", "gist");
}
}.execute();
}
@@ -159,6 +186,8 @@ public class LinkedIdCreateGithubFragment extends Fragment {
protected JSONObject doInBackground(Void... dummy) {
try {
long timer = System.currentTimeMillis();
JSONObject file = new JSONObject();
file.put("content", "hello!");
@@ -170,7 +199,17 @@ public class LinkedIdCreateGithubFragment extends Fragment {
params.put("description", "OpenKeychain API Tests");
params.put("files", files);
return jsonHttpRequest("https://api.github.com/gists", params, accessToken);
JSONObject result = jsonHttpRequest("https://api.github.com/gists", params, accessToken);
// ux flow: this operation should take at last a second
timer = System.currentTimeMillis() -timer;
if (timer < 1000) try {
Thread.sleep(1000 -timer);
} catch (InterruptedException e) {
// never mind
}
return result;
} catch (IOException e) {
Log.e(Constants.TAG, "error in request", e);

View File

@@ -4,6 +4,7 @@ package org.sufficientlysecure.keychain.ui.widget;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.animation.AnimationUtils;
import org.sufficientlysecure.keychain.R;
@@ -14,12 +15,16 @@ public class StatusIndicator extends ToolableViewAnimator {
super(context);
LayoutInflater.from(context).inflate(R.layout.status_indicator, this, true);
setInAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in));
setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out));
}
public StatusIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.status_indicator, this, true);
setInAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_in));
setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.fade_out));
}
}

View File

@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto">
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
@@ -29,54 +27,35 @@
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:text="This login data will be used to post a gist, verifying this account and key belongs to you!"
android:text="This operation links your key to your GitHub account."
style="?android:textAppearanceSmall"/>
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/proceed_container"
custom:initialView="1">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
style="?android:buttonBarButtonStyle"
android:drawableLeft="@drawable/ic_mode_edit_grey_24dp"
android:drawableStart="@drawable/ic_mode_edit_grey_24dp"
android:drawablePadding="12dp"
android:text="Post Gist &amp; Link Key"
android:id="@+id/button_send"
/>
android:orientation="vertical"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<org.sufficientlysecure.keychain.ui.widget.StatusIndicator
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/linked_status_step1"
android:layout_margin="4dp" />
<org.sufficientlysecure.keychain.ui.widget.StatusIndicator
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/linked_status_step1"
android:layout_margin="4dp">
</org.sufficientlysecure.keychain.ui.widget.StatusIndicator>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Login at GitHub…"
style="?android:textAppearanceMedium"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="Login at GitHub…"
style="?android:textAppearanceMedium"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
@@ -86,8 +65,7 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/linked_status_step2"
android:layout_margin="4dp">
</org.sufficientlysecure.keychain.ui.widget.StatusIndicator>
android:layout_margin="4dp" />
<TextView
android:layout_width="wrap_content"
@@ -107,8 +85,7 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/linked_status_step3"
android:layout_margin="4dp">
</org.sufficientlysecure.keychain.ui.widget.StatusIndicator>
android:layout_margin="4dp" />
<TextView
android:layout_width="wrap_content"
@@ -121,6 +98,30 @@
</LinearLayout>
<org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button_container"
android:outAnimation="@anim/fade_out">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
style="?android:buttonBarButtonStyle"
android:drawableLeft="@drawable/ic_person_add_grey_24dp"
android:drawableStart="@drawable/ic_person_add_grey_24dp"
android:drawablePadding="12dp"
android:text="Link to Github Account"
android:id="@+id/button_send"
/>
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</org.sufficientlysecure.keychain.ui.widget.ToolableViewAnimator>
</LinearLayout>