support github resource (re)

This commit is contained in:
Vincent Breitmoser 2015-03-24 02:30:39 +01:00
parent 94dbeaeaf0
commit b25371fc1b
8 changed files with 594 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.StringRes;
import org.apache.http.client.methods.HttpGet;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.sufficientlysecure.keychain.Constants;
@ -20,6 +21,7 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.regex.Matcher;
@ -90,6 +92,15 @@ public class GithubResource extends LinkedCookieResource {
}
public static GithubResource searchInGithubStream(String screenName, String needle) {
// TODO implement
return null;
}
public static GithubResource create(URI uri) {
return create(new HashSet<String>(), new HashMap<String,String>(), uri);
}
public static GithubResource create(Set<String> flags, HashMap<String,String> params, URI uri) {
// no params or flags

View File

@ -0,0 +1,129 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.linked;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.util.Notify;
public class LinkedIdCreateGithubStep1Fragment extends Fragment {
LinkedIdWizard mLinkedIdWizard;
EditText mEditHandle;
public static LinkedIdCreateGithubStep1Fragment newInstance() {
LinkedIdCreateGithubStep1Fragment frag = new LinkedIdCreateGithubStep1Fragment();
Bundle args = new Bundle();
frag.setArguments(args);
return frag;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mLinkedIdWizard = (LinkedIdWizard) getActivity();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.linked_create_github_fragment_step1, container, false);
view.findViewById(R.id.next_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String handle = mEditHandle.getText().toString();
new AsyncTask<Void,Void,Boolean>() {
@Override
protected Boolean doInBackground(Void... params) {
return true; // return checkHandle(handle);
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result == null) {
Notify.showNotify(getActivity(),
"Connection error while checking username!", Notify.Style.ERROR);
return;
}
if (!result) {
Notify.showNotify(getActivity(),
"This handle does not exist on Github!", Notify.Style.ERROR);
return;
}
LinkedIdCreateGithubStep2Fragment frag =
LinkedIdCreateGithubStep2Fragment.newInstance(handle);
mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT);
}
}.execute();
}
});
view.findViewById(R.id.back_button).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mLinkedIdWizard.loadFragment(null, null, LinkedIdWizard.FRAG_ACTION_TO_LEFT);
}
});
mEditHandle = (EditText) view.findViewById(R.id.linked_create_github_handle);
mEditHandle.setText("Valodim");
return view;
}
private static Boolean checkHandle(String handle) {
try {
HttpURLConnection nection =
(HttpURLConnection) new URL("https://api.github.com/" + handle).openConnection();
nection.setRequestMethod("HEAD");
return nection.getResponseCode() == 200;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}

View File

@ -0,0 +1,111 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.linked;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.linked.LinkedCookieResource;
import org.sufficientlysecure.keychain.pgp.linked.resources.GithubResource;
public class LinkedIdCreateGithubStep2Fragment extends LinkedIdCreateFinalFragment {
public static final String ARG_HANDLE = "handle";
String mResourceHandle;
String mResourceString;
public static LinkedIdCreateGithubStep2Fragment newInstance
(String handle) {
LinkedIdCreateGithubStep2Fragment frag = new LinkedIdCreateGithubStep2Fragment();
Bundle args = new Bundle();
args.putString(ARG_HANDLE, handle);
frag.setArguments(args);
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mResourceString =
GithubResource.generate(getActivity(), mLinkedIdWizard.mFingerprint);
mResourceHandle = getArguments().getString(ARG_HANDLE);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
view.findViewById(R.id.button_send).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
proofSend();
}
});
view.findViewById(R.id.button_share).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
proofShare();
}
});
return view;
}
@Override
LinkedCookieResource getResource() {
return GithubResource.searchInGithubStream(mResourceHandle, mResourceString);
}
@Override
protected View newView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.linked_create_github_fragment_step2, container, false);
}
private void proofShare() {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, mResourceString);
sendIntent.setType("text/plain");
startActivity(sendIntent);
}
private void proofSend() {
Uri.Builder builder = Uri.parse("https://gist.github.com/").buildUpon();
builder.appendQueryParameter("text", mResourceString);
Uri uri = builder.build();
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
getActivity().startActivity(intent);
}
}

View File

@ -78,6 +78,18 @@ public class LinkedIdSelectFragment extends Fragment {
}
});
view.findViewById(R.id.linked_create_github_button)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinkedIdCreateGithubStep1Fragment frag =
LinkedIdCreateGithubStep1Fragment.newInstance();
mLinkedIdWizard.loadFragment(null, frag, LinkedIdWizard.FRAG_ACTION_TO_RIGHT);
}
});
return view;
}

View File

@ -0,0 +1,134 @@
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
android:layout_above="@+id/create_key_button_divider">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">
<LinearLayout
android:layout_marginTop="16dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/certify_key_action_certify_image"
android:layout_width="60dip"
android:layout_height="60dip"
android:padding="8dp"
android:src="@drawable/github"
android:layout_gravity="center_vertical" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_1_1" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_1_2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_1_3" />
<EditText
android:id="@+id/linked_create_github_handle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:layout_marginTop="16dp"
android:ems="10"
android:layout_gravity="center_horizontal"
android:hint="@string/linked_create_github_handle"/>
</LinearLayout>
</ScrollView>
<View
android:id="@+id/create_key_button_divider"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="?android:attr/listDivider"
android:layout_alignTop="@+id/create_key_buttons"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:id="@+id/create_key_buttons">
<TextView
android:id="@+id/back_button"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn_back"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAllCaps="true"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="@drawable/ic_chevron_left_grey_24dp"
android:drawablePadding="8dp"
android:clickable="true"
android:gravity="center_vertical"
android:layout_gravity="center_vertical" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="?android:attr/listDivider" />
<TextView
android:id="@+id/next_button"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn_next"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAllCaps="true"
style="?android:attr/borderlessButtonStyle"
android:drawableRight="@drawable/ic_chevron_right_grey_24dp"
android:drawablePadding="8dp"
android:gravity="center_vertical|right"
android:layout_gravity="center_vertical" />
</LinearLayout>
</RelativeLayout>

View File

@ -0,0 +1,152 @@
<?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">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="false"
android:layout_above="@+id/create_key_button_divider">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_2_1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_2_2" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
style="?android:buttonBarStyle">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
style="?android:buttonBarButtonStyle"
android:drawableLeft="@android:drawable/ic_menu_send"
android:drawableStart="@android:drawable/ic_menu_send"
android:text="Post Gist"
android:id="@+id/button_send"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
style="?android:buttonBarButtonStyle"
android:drawableLeft="@android:drawable/ic_menu_share"
android:drawableStart="@android:drawable/ic_menu_share"
android:text="Share"
android:id="@+id/button_share"
/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_2_3" />
<include layout="@layout/linked_create_verify" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/linked_create_github_2_4" />
</LinearLayout>
</ScrollView>
<View
android:id="@+id/create_key_button_divider"
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:background="?android:attr/listDivider"
android:layout_alignTop="@+id/create_key_buttons"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:id="@+id/create_key_buttons">
<TextView
android:id="@+id/back_button"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn_back"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAllCaps="true"
style="?android:attr/borderlessButtonStyle"
android:drawableLeft="@drawable/ic_chevron_left_grey_24dp"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:clickable="true"
android:layout_gravity="center_vertical" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:background="?android:attr/listDivider" />
<TextView
android:id="@+id/next_button"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/btn_finish"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAllCaps="true"
android:drawableRight="@drawable/ic_person_add_grey_24dp"
android:drawablePadding="8dp"
style="?android:attr/borderlessButtonStyle"
android:gravity="center_vertical|right"
android:layout_gravity="center_vertical" />
</LinearLayout>
</RelativeLayout>

View File

@ -148,6 +148,41 @@
android:layout_marginBottom="4dp"
android:background="?android:attr/listDivider" />
<LinearLayout
android:id="@+id/linked_create_github_button"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:clickable="true"
android:paddingRight="4dp"
android:background="?android:selectableItemBackground"
android:orientation="horizontal">
<!-- separate ImageView required for recoloring -->
<ImageView
android:layout_width="60dip"
android:layout_height="60dip"
android:padding="8dp"
android:src="@drawable/github"
android:layout_gravity="center"
/>
<TextView
android:paddingLeft="8dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_width="0dip"
android:layout_height="match_parent"
android:text="Github"
android:layout_weight="1"
android:gravity="center_vertical" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_marginBottom="4dp"
android:background="?android:attr/listDivider" />
</LinearLayout>
</ScrollView>

View File

@ -1287,7 +1287,7 @@
<string name="linked_create_https_2_4">"After successful verification, press the Finish button to add the Linked Identity to your keyring and finish the process."</string>
<string name="linked_create_twitter_1_1">"By creating a Linked Identity of this type, you can link your key to a Twitter account you control."</string>
<string name="linked_create_twitter_1_2">"To do this, you publish a specific Tweet on your timeline, then create a Linked Identity which links to this tweet."</string>
<string name="linked_create_twitter_1_2">"To do this, you publish a specific Tweet on your timeline, then create a Linked Identity which links to this Tweet."</string>
<string name="linked_create_twitter_1_3">"Please enter your Twitter screen name to proceed."</string>
<string name="linked_create_twitter_handle">Twitter Handle</string>
<string name="linked_create_twitter_2_1">"Click either button to tweet the message!"</string>
@ -1295,6 +1295,15 @@
<string name="linked_create_twitter_2_3">"Once your Tweet is published, click the Verify button to scan your timeline for it."</string>
<string name="linked_create_twitter_2_4">"After successful verification, press the Finish button to add the Linked Identity to your keyring and finish the process."</string>
<string name="linked_create_github_1_1">"By creating a Linked Identity of this type, you can link your key to a Github account you control."</string>
<string name="linked_create_github_1_2">"To do this, you publish a specific Gist on your timeline, then create a Linked Identity which links to this Gist."</string>
<string name="linked_create_github_1_3">"Please enter your Twitter screen name to proceed."</string>
<string name="linked_create_github_handle">Github Handle</string>
<string name="linked_create_github_2_1">"Click either button to post the gist!"</string>
<string name="linked_create_github_2_2">"You can edit the Gist before posting it, so long as the text inside the brackets is unmodified."</string>
<string name="linked_create_github_2_3">"Once your Gist is published, click the Verify button to scan your timeline for it."</string>
<string name="linked_create_github_2_4">"After successful verification, press the Finish button to add the Linked Identity to your keyring and finish the process."</string>
<string name="linked_create_dns_1_1">"By creating a Linked Identity of this type, you can link your key to a domain name you control."</string>
<string name="linked_create_dns_1_2">"To do this, you create a specific TXT record for the domain, then create a Linked Identity which links to this record."</string>
<!-- An Identity of this type is especially appropriate if your email address is at the same domain. -->