support github resource (re)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user