mirror of
https://github.com/gsantner/dandelion
synced 2024-11-25 22:02:08 +01:00
Added first design of StatisticsFetchTask (currently not working/needed)
This commit is contained in:
parent
75106e2c12
commit
7c1510a272
3 changed files with 110 additions and 2 deletions
|
@ -25,6 +25,7 @@ import android.webkit.CookieManager;
|
||||||
|
|
||||||
import com.github.dfa.diaspora_android.App;
|
import com.github.dfa.diaspora_android.App;
|
||||||
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||||
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -45,10 +46,12 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
final App app;
|
final App app;
|
||||||
final Context context;
|
final Context context;
|
||||||
|
final DiasporaUrlHelper urls;
|
||||||
|
|
||||||
public ProfileFetchTask(final App app) {
|
public ProfileFetchTask(final App app) {
|
||||||
this.context = app.getApplicationContext();
|
this.context = app.getApplicationContext();
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
this.urls = new DiasporaUrlHelper(app.getSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,13 +59,13 @@ public class ProfileFetchTask extends AsyncTask<Void, Void, Void> {
|
||||||
protected Void doInBackground(Void... params) {
|
protected Void doInBackground(Void... params) {
|
||||||
String extractedProfileData = null;
|
String extractedProfileData = null;
|
||||||
final CookieManager cookieManager = app.getCookieManager();
|
final CookieManager cookieManager = app.getCookieManager();
|
||||||
String cookies = cookieManager.getCookie("https://" + app.getSettings().getPodDomain());
|
String cookies = cookieManager.getCookie(urls.getPodUrl());
|
||||||
Log.d(App.TAG, cookies);
|
Log.d(App.TAG, cookies);
|
||||||
|
|
||||||
HttpsURLConnection connection;
|
HttpsURLConnection connection;
|
||||||
InputStream inStream;
|
InputStream inStream;
|
||||||
try {
|
try {
|
||||||
URL url = new URL("https://" + app.getSettings().getPodDomain() + "/stream");
|
URL url = new URL(urls.getStreamUrl());
|
||||||
connection = NetCipher.getHttpsURLConnection(url);
|
connection = NetCipher.getHttpsURLConnection(url);
|
||||||
connection.setReadTimeout(10000);
|
connection.setReadTimeout(10000);
|
||||||
connection.setConnectTimeout(15000);
|
connection.setConnectTimeout(15000);
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
/*
|
||||||
|
This file is part of the Diaspora for Android.
|
||||||
|
|
||||||
|
Diaspora for Android 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.
|
||||||
|
|
||||||
|
Diaspora for Android 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 the Diaspora for Android.
|
||||||
|
|
||||||
|
If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.github.dfa.diaspora_android.task;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.webkit.CookieManager;
|
||||||
|
|
||||||
|
import com.github.dfa.diaspora_android.App;
|
||||||
|
import com.github.dfa.diaspora_android.data.PodUserProfile;
|
||||||
|
import com.github.dfa.diaspora_android.util.DiasporaUrlHelper;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
|
||||||
|
import info.guardianproject.netcipher.NetCipher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* AsyncTask to fetch a users profile
|
||||||
|
*/
|
||||||
|
public class StatisticsFetchTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
// Code for getting the profile async without any UI/WebView
|
||||||
|
// TODO: This is an early version,needs to be converted to Service
|
||||||
|
|
||||||
|
final App app;
|
||||||
|
final Context context;
|
||||||
|
final DiasporaUrlHelper urls;
|
||||||
|
|
||||||
|
public StatisticsFetchTask(final App app) {
|
||||||
|
this.context = app.getApplicationContext();
|
||||||
|
this.app = app;
|
||||||
|
this.urls = new DiasporaUrlHelper(app.getSettings());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground(Void... params) {
|
||||||
|
String extractedProfileData = null;
|
||||||
|
final CookieManager cookieManager = app.getCookieManager();
|
||||||
|
String cookies = cookieManager.getCookie(urls.getPodUrl());
|
||||||
|
|
||||||
|
HttpsURLConnection connection;
|
||||||
|
InputStream inStream;
|
||||||
|
try {
|
||||||
|
URL url = new URL(urls.getStatisticsUrl());
|
||||||
|
connection = NetCipher.getHttpsURLConnection(url);
|
||||||
|
connection.setReadTimeout(10000);
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
if (cookies != null) {
|
||||||
|
connection.setRequestProperty("Cookie", cookies);
|
||||||
|
}
|
||||||
|
connection.connect();
|
||||||
|
|
||||||
|
inStream = connection.getInputStream();
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(inStream));
|
||||||
|
String line;
|
||||||
|
while ((line = br.readLine()) != null) {
|
||||||
|
Log.d(App.TAG, "STATS: "+line);
|
||||||
|
}
|
||||||
|
|
||||||
|
try{
|
||||||
|
br.close();
|
||||||
|
inStream.close();
|
||||||
|
} catch (IOException e){/*Nothing*/}
|
||||||
|
|
||||||
|
connection.disconnect();
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,6 +48,7 @@ public class DiasporaUrlHelper {
|
||||||
public static final String SUBURL_SEARCH_PEOPLE = "/people.mobile?q=";
|
public static final String SUBURL_SEARCH_PEOPLE = "/people.mobile?q=";
|
||||||
public static final String SUBURL_FOLOWED_TAGS = "/followed_tags";
|
public static final String SUBURL_FOLOWED_TAGS = "/followed_tags";
|
||||||
public static final String SUBURL_ASPECTS = "/aspects";
|
public static final String SUBURL_ASPECTS = "/aspects";
|
||||||
|
public static final String SUBURL_STATISTICS = "/statistics";
|
||||||
public static final String URL_BLANK = "about:blank";
|
public static final String URL_BLANK = "about:blank";
|
||||||
|
|
||||||
public DiasporaUrlHelper(AppSettings settings) {
|
public DiasporaUrlHelper(AppSettings settings) {
|
||||||
|
@ -202,6 +203,14 @@ public class DiasporaUrlHelper {
|
||||||
return getPodUrl() + SUBURL_SEARCH_PEOPLE + query;
|
return getPodUrl() + SUBURL_SEARCH_PEOPLE + query;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a https url that points to the statistics page of the pod.
|
||||||
|
* @return https://(pod-domain.tld)/statistics
|
||||||
|
*/
|
||||||
|
public String getStatisticsUrl() {
|
||||||
|
return getPodUrl() + SUBURL_STATISTICS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the url of the blank WebView
|
* Returns the url of the blank WebView
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue