|
|
|
@ -60,14 +60,7 @@ import java.util.zip.GZIPInputStream;
|
|
|
|
|
import java.util.zip.Inflater;
|
|
|
|
|
import java.util.zip.InflaterInputStream;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Package: net.micode.notes.gtask.remote
|
|
|
|
|
* @ClassName: GTaskClient
|
|
|
|
|
* @Description: 实现GTASK的登录操作,进行GTASK任务的创建,创建任务列表,从网络上获取任务和任务列表的内容
|
|
|
|
|
* @Author: WuShuxian
|
|
|
|
|
* @CreateDate: 2023/12/24 20:55
|
|
|
|
|
* @Version: 1.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public class GTaskClient {
|
|
|
|
|
private static final String TAG = GTaskClient.class.getSimpleName();
|
|
|
|
|
|
|
|
|
@ -97,12 +90,6 @@ public class GTaskClient {
|
|
|
|
|
|
|
|
|
|
private JSONArray mUpdateArray;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method GTaskClient
|
|
|
|
|
* @description: 构造函数
|
|
|
|
|
* @date: 2023/12/24 20:56
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
*/
|
|
|
|
|
private GTaskClient() {
|
|
|
|
|
mHttpClient = null;
|
|
|
|
|
mGetUrl = GTASK_GET_URL;
|
|
|
|
@ -121,40 +108,35 @@ public class GTaskClient {
|
|
|
|
|
}
|
|
|
|
|
return mInstance;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method login
|
|
|
|
|
* @description: 用来实现登录操作,有两种登录方式,使用用户自己的URL登录或者使用谷歌官方的URL登录
|
|
|
|
|
* @date: 2023/12/24 21:15
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: activity
|
|
|
|
|
* @return: boolean
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public boolean login(Activity activity) {
|
|
|
|
|
//判断距离最后一次登录操作是否超过5分钟
|
|
|
|
|
// we suppose that the cookie would expire after 5 minutes
|
|
|
|
|
// then we need to re-login
|
|
|
|
|
final long interval = 1000 * 60 * 5;
|
|
|
|
|
if (mLastLoginTime + interval < System.currentTimeMillis()) {
|
|
|
|
|
mLoggedin = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 重新登陆操作
|
|
|
|
|
// need to re-login after account switch
|
|
|
|
|
if (mLoggedin
|
|
|
|
|
&& !TextUtils.equals(getSyncAccount().name, NotesPreferenceActivity
|
|
|
|
|
.getSyncAccountName(activity))) {
|
|
|
|
|
mLoggedin = false;
|
|
|
|
|
}
|
|
|
|
|
//如果没超过时间,则不需要重新登录
|
|
|
|
|
|
|
|
|
|
if (mLoggedin) {
|
|
|
|
|
Log.d(TAG, "already logged in");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mLastLoginTime = System.currentTimeMillis();//更新最后登录时间为系统当前的时间
|
|
|
|
|
String authToken = loginGoogleAccount(activity, false);//判断是否登录到谷歌账户
|
|
|
|
|
mLastLoginTime = System.currentTimeMillis();
|
|
|
|
|
String authToken = loginGoogleAccount(activity, false);
|
|
|
|
|
if (authToken == null) {
|
|
|
|
|
Log.e(TAG, "login google account failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// login with custom domain if necessary
|
|
|
|
|
if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase()
|
|
|
|
|
.endsWith("googlemail.com"))) {
|
|
|
|
|
StringBuilder url = new StringBuilder(GTASK_URL).append("a/");
|
|
|
|
@ -168,7 +150,8 @@ public class GTaskClient {
|
|
|
|
|
mLoggedin = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//如果用户账户无法登录,则使用谷歌官方的URI进行登录
|
|
|
|
|
|
|
|
|
|
// try to login with google official url
|
|
|
|
|
if (!mLoggedin) {
|
|
|
|
|
mGetUrl = GTASK_GET_URL;
|
|
|
|
|
mPostUrl = GTASK_POST_URL;
|
|
|
|
@ -180,14 +163,7 @@ public class GTaskClient {
|
|
|
|
|
mLoggedin = true;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method loginGoogleAccount
|
|
|
|
|
* @description: 具体实现登录谷歌账户的方法
|
|
|
|
|
* @date: 2023/12/24 23:07
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: activity
|
|
|
|
|
* @return: String
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private String loginGoogleAccount(Activity activity, boolean invalidateToken) {
|
|
|
|
|
String authToken;
|
|
|
|
|
AccountManager accountManager = AccountManager.get(activity);
|
|
|
|
@ -200,7 +176,6 @@ public class GTaskClient {
|
|
|
|
|
|
|
|
|
|
String accountName = NotesPreferenceActivity.getSyncAccountName(activity);
|
|
|
|
|
Account account = null;
|
|
|
|
|
//遍历获得的accounts信息,寻找已经记录过的账户信息
|
|
|
|
|
for (Account a : accounts) {
|
|
|
|
|
if (a.name.equals(accountName)) {
|
|
|
|
|
account = a;
|
|
|
|
@ -214,7 +189,7 @@ public class GTaskClient {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取令牌
|
|
|
|
|
// get the token now
|
|
|
|
|
AccountManagerFuture<Bundle> accountManagerFuture = accountManager.getAuthToken(account,
|
|
|
|
|
"goanna_mobile", null, activity, null, null);
|
|
|
|
|
try {
|
|
|
|
@ -231,16 +206,11 @@ public class GTaskClient {
|
|
|
|
|
|
|
|
|
|
return authToken;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method tryToLoginGtask
|
|
|
|
|
* @description: 尝试登陆Gtask,这只是一个预先判断令牌是否是有效以及是否能登上GTask的方法,而不是具体实现登陆的方法
|
|
|
|
|
* @date: 2023/12/24 21:01
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param:
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private boolean tryToLoginGtask(Activity activity, String authToken) {
|
|
|
|
|
if (!loginGtask(authToken)) {
|
|
|
|
|
// maybe the auth token is out of date, now let's invalidate the
|
|
|
|
|
// token and try again
|
|
|
|
|
authToken = loginGoogleAccount(activity, true);
|
|
|
|
|
if (authToken == null) {
|
|
|
|
|
Log.e(TAG, "login google account failed");
|
|
|
|
@ -254,33 +224,26 @@ public class GTaskClient {
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method loginGtask
|
|
|
|
|
* @description: 具体实现登录操作
|
|
|
|
|
* @date: 2023/12/24 21:05
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param:
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private boolean loginGtask(String authToken) {
|
|
|
|
|
int timeoutConnection = 10000;
|
|
|
|
|
int timeoutSocket = 15000; //socket是一种通信连接实现数据的交换的端口
|
|
|
|
|
HttpParams httpParameters = new BasicHttpParams(); //实例化一个新的HTTP参数类
|
|
|
|
|
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);//设置连接超时时间
|
|
|
|
|
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);//设置设置端口超时时间
|
|
|
|
|
int timeoutSocket = 15000;
|
|
|
|
|
HttpParams httpParameters = new BasicHttpParams();
|
|
|
|
|
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
|
|
|
|
|
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
|
|
|
|
|
mHttpClient = new DefaultHttpClient(httpParameters);
|
|
|
|
|
BasicCookieStore localBasicCookieStore = new BasicCookieStore();
|
|
|
|
|
mHttpClient.setCookieStore(localBasicCookieStore);
|
|
|
|
|
HttpProtocolParams.setUseExpectContinue(mHttpClient.getParams(), false);
|
|
|
|
|
|
|
|
|
|
//登录操作
|
|
|
|
|
// login gtask
|
|
|
|
|
try {
|
|
|
|
|
String loginUrl = mGetUrl + "?auth=" + authToken;//设置登录的URL
|
|
|
|
|
HttpGet httpGet = new HttpGet(loginUrl);//通过登录的uri实例化网页上资源的查找
|
|
|
|
|
String loginUrl = mGetUrl + "?auth=" + authToken;
|
|
|
|
|
HttpGet httpGet = new HttpGet(loginUrl);
|
|
|
|
|
HttpResponse response = null;
|
|
|
|
|
response = mHttpClient.execute(httpGet);
|
|
|
|
|
|
|
|
|
|
//获取CookieStore里存放的cookie,如果存有“GTL”,则cookie有效
|
|
|
|
|
// get the cookie now
|
|
|
|
|
List<Cookie> cookies = mHttpClient.getCookieStore().getCookies();
|
|
|
|
|
boolean hasAuthCookie = false;
|
|
|
|
|
for (Cookie cookie : cookies) {
|
|
|
|
@ -292,7 +255,7 @@ public class GTaskClient {
|
|
|
|
|
Log.w(TAG, "it seems that there is no auth cookie");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取client的内容
|
|
|
|
|
// get the client version
|
|
|
|
|
String resString = getResponseContent(response.getEntity());
|
|
|
|
|
String jsBegin = "_setup(";
|
|
|
|
|
String jsEnd = ")}</script>";
|
|
|
|
@ -309,6 +272,7 @@ public class GTaskClient {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
return false;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
// simply catch all exceptions
|
|
|
|
|
Log.e(TAG, "httpget gtask_url failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -319,24 +283,14 @@ public class GTaskClient {
|
|
|
|
|
private int getActionId() {
|
|
|
|
|
return mActionId++;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method createHttpPost
|
|
|
|
|
* @description: 实例化创建一个用于向网络传输数据的对象
|
|
|
|
|
* @date: 2023/12/24 23:13
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private HttpPost createHttpPost() {
|
|
|
|
|
HttpPost httpPost = new HttpPost(mPostUrl);
|
|
|
|
|
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
|
|
|
|
|
httpPost.setHeader("AT", "1");
|
|
|
|
|
return httpPost;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method getResponseContent
|
|
|
|
|
* @description: 通过URL获取响应后返回的数据,也就是网络上的数据和资源
|
|
|
|
|
* @date: 2023/12/24 21:06
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private String getResponseContent(HttpEntity entity) throws IOException {
|
|
|
|
|
String contentEncoding = null;
|
|
|
|
|
if (entity.getContentEncoding() != null) {
|
|
|
|
@ -368,20 +322,13 @@ public class GTaskClient {
|
|
|
|
|
input.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method postRequest
|
|
|
|
|
* @description: 通过Json发送请求
|
|
|
|
|
* @date: 2023/12/24 21:07
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: js
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
private JSONObject postRequest(JSONObject js) throws NetworkFailureException {
|
|
|
|
|
if (!mLoggedin) {
|
|
|
|
|
Log.e(TAG, "please login first");
|
|
|
|
|
throw new ActionFailureException("not logged in");
|
|
|
|
|
}
|
|
|
|
|
//实例化一个httpPost的对象用来向服务器传输数据,在这里就是发送请求,而请求的内容在js里
|
|
|
|
|
|
|
|
|
|
HttpPost httpPost = createHttpPost();
|
|
|
|
|
try {
|
|
|
|
|
LinkedList<BasicNameValuePair> list = new LinkedList<BasicNameValuePair>();
|
|
|
|
@ -389,8 +336,9 @@ public class GTaskClient {
|
|
|
|
|
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, "UTF-8");
|
|
|
|
|
httpPost.setEntity(entity);
|
|
|
|
|
|
|
|
|
|
// execute the post
|
|
|
|
|
HttpResponse response = mHttpClient.execute(httpPost);
|
|
|
|
|
String jsString = getResponseContent(response.getEntity());//得到返回的数据和资源
|
|
|
|
|
String jsString = getResponseContent(response.getEntity());
|
|
|
|
|
return new JSONObject(jsString);
|
|
|
|
|
|
|
|
|
|
} catch (ClientProtocolException e) {
|
|
|
|
@ -411,25 +359,21 @@ public class GTaskClient {
|
|
|
|
|
throw new ActionFailureException("error occurs when posting request");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method createTask
|
|
|
|
|
* @description: 创建单个任务
|
|
|
|
|
* @date: 2023/12/24 21:08
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: task
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public void createTask(Task task) throws NetworkFailureException {
|
|
|
|
|
commitUpdate();
|
|
|
|
|
try {
|
|
|
|
|
JSONObject jsPost = new JSONObject();
|
|
|
|
|
JSONArray actionList = new JSONArray();
|
|
|
|
|
|
|
|
|
|
// action_list
|
|
|
|
|
actionList.put(task.getCreateAction(getActionId()));
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
|
|
|
|
|
|
|
|
|
|
// client_version
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
|
|
|
|
|
|
|
|
|
|
// post
|
|
|
|
|
JSONObject jsResponse = postRequest(jsPost);
|
|
|
|
|
JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(
|
|
|
|
|
GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
|
|
|
|
@ -441,29 +385,25 @@ public class GTaskClient {
|
|
|
|
|
throw new ActionFailureException("create task: handing jsonobject failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method createTaskList
|
|
|
|
|
* @description: 建一个任务列表,与createTask几乎一样,区别就是最后设置的是tasklist的gid
|
|
|
|
|
* @date: 2023/12/24 21:09
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: tasklist
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public void createTaskList(TaskList tasklist) throws NetworkFailureException {
|
|
|
|
|
commitUpdate();
|
|
|
|
|
try {
|
|
|
|
|
JSONObject jsPost = new JSONObject();
|
|
|
|
|
JSONArray actionList = new JSONArray();
|
|
|
|
|
|
|
|
|
|
// action_list
|
|
|
|
|
actionList.put(tasklist.getCreateAction(getActionId()));
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
|
|
|
|
|
|
|
|
|
|
// client version
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
|
|
|
|
|
|
|
|
|
|
JSONObject jsResponse = postRequest(jsPost);//得到任务的返回信息
|
|
|
|
|
// post
|
|
|
|
|
JSONObject jsResponse = postRequest(jsPost);
|
|
|
|
|
JSONObject jsResult = (JSONObject) jsResponse.getJSONArray(
|
|
|
|
|
GTaskStringUtils.GTASK_JSON_RESULTS).get(0);
|
|
|
|
|
tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID));//设置task的new_id
|
|
|
|
|
tasklist.setGid(jsResult.getString(GTaskStringUtils.GTASK_JSON_NEW_ID));
|
|
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
@ -477,8 +417,10 @@ public class GTaskClient {
|
|
|
|
|
try {
|
|
|
|
|
JSONObject jsPost = new JSONObject();
|
|
|
|
|
|
|
|
|
|
// action_list
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, mUpdateArray);
|
|
|
|
|
|
|
|
|
|
// client_version
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
|
|
|
|
|
|
|
|
|
|
postRequest(jsPost);
|
|
|
|
@ -490,17 +432,11 @@ public class GTaskClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method addUpdateNode
|
|
|
|
|
* @description: 添加更新的事项
|
|
|
|
|
* @date: 2023/12/24 23:19
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: node
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public void addUpdateNode(Node node) throws NetworkFailureException {
|
|
|
|
|
if (node != null) {
|
|
|
|
|
//设置更新(同步)项目数量上限:10
|
|
|
|
|
// too many update items may result in an error
|
|
|
|
|
// set max to 10 items
|
|
|
|
|
if (mUpdateArray != null && mUpdateArray.length() > 10) {
|
|
|
|
|
commitUpdate();
|
|
|
|
|
}
|
|
|
|
@ -510,14 +446,7 @@ public class GTaskClient {
|
|
|
|
|
mUpdateArray.put(node.getUpdateAction(getActionId()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method moveTask
|
|
|
|
|
* @description: 移动task,比如讲task移动到不同的task列表中去
|
|
|
|
|
* @date: 2023/12/24 23:19
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: task、preParent、curParent
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public void moveTask(Task task, TaskList preParent, TaskList curParent)
|
|
|
|
|
throws NetworkFailureException {
|
|
|
|
|
commitUpdate();
|
|
|
|
@ -526,22 +455,26 @@ public class GTaskClient {
|
|
|
|
|
JSONArray actionList = new JSONArray();
|
|
|
|
|
JSONObject action = new JSONObject();
|
|
|
|
|
|
|
|
|
|
// 动作序列
|
|
|
|
|
// action_list
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
|
|
|
|
|
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_MOVE);
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId());
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_ID, task.getGid());
|
|
|
|
|
if (preParent == curParent && task.getPriorSibling() != null) {
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling());//设置优先级ID,只有当移动是发生在文件中
|
|
|
|
|
// put prioring_sibing_id only if moving within the tasklist and
|
|
|
|
|
// it is not the first one
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_PRIOR_SIBLING_ID, task.getPriorSibling());
|
|
|
|
|
}
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_SOURCE_LIST, preParent.getGid());
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_DEST_PARENT, curParent.getGid());
|
|
|
|
|
if (preParent != curParent) {
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid());//仅当在任务列表之间移动时才放入dest_list
|
|
|
|
|
// put the dest_list only if moving between tasklists
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_DEST_LIST, curParent.getGid());
|
|
|
|
|
}
|
|
|
|
|
actionList.put(action);
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);//将ACTION_LIST加入到jsPost中
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
|
|
|
|
|
|
|
|
|
|
// client_version
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
|
|
|
|
|
|
|
|
|
|
postRequest(jsPost);
|
|
|
|
@ -552,27 +485,22 @@ public class GTaskClient {
|
|
|
|
|
throw new ActionFailureException("move task: handing jsonobject failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method deleteNode
|
|
|
|
|
* @description: 删除操作节点
|
|
|
|
|
* @date: 2023/12/24 23:22
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: node
|
|
|
|
|
* @return: void
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public void deleteNode(Node node) throws NetworkFailureException {
|
|
|
|
|
commitUpdate();
|
|
|
|
|
try {
|
|
|
|
|
JSONObject jsPost = new JSONObject();
|
|
|
|
|
JSONArray actionList = new JSONArray();
|
|
|
|
|
|
|
|
|
|
// action_list
|
|
|
|
|
node.setDeleted(true);
|
|
|
|
|
actionList.put(node.getUpdateAction(getActionId()));//获取删除操作的ID,加入actionLiast
|
|
|
|
|
actionList.put(node.getUpdateAction(getActionId()));
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
|
|
|
|
|
|
|
|
|
|
// client_version
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
|
|
|
|
|
|
|
|
|
|
postRequest(jsPost);//使用postRequest发送删除后的结果
|
|
|
|
|
postRequest(jsPost);
|
|
|
|
|
mUpdateArray = null;
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
@ -580,14 +508,7 @@ public class GTaskClient {
|
|
|
|
|
throw new ActionFailureException("delete node: handing jsonobject failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method getTaskLists
|
|
|
|
|
* @description: 获取任务列表
|
|
|
|
|
* @date: 2023/12/24 23:24
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: void
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public JSONArray getTaskLists() throws NetworkFailureException {
|
|
|
|
|
if (!mLoggedin) {
|
|
|
|
|
Log.e(TAG, "please login first");
|
|
|
|
@ -599,8 +520,8 @@ public class GTaskClient {
|
|
|
|
|
HttpResponse response = null;
|
|
|
|
|
response = mHttpClient.execute(httpGet);
|
|
|
|
|
|
|
|
|
|
// 获取任务列表,把筛选出的字符串放入jsString
|
|
|
|
|
String resString = getResponseContent(response.getEntity());//从网上获取数据
|
|
|
|
|
// get the task list
|
|
|
|
|
String resString = getResponseContent(response.getEntity());
|
|
|
|
|
String jsBegin = "_setup(";
|
|
|
|
|
String jsEnd = ")}</script>";
|
|
|
|
|
int begin = resString.indexOf(jsBegin);
|
|
|
|
@ -625,14 +546,7 @@ public class GTaskClient {
|
|
|
|
|
throw new ActionFailureException("get task lists: handing jasonobject failed");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @method getTaskList
|
|
|
|
|
* @description: 通过传入的TASKList的gid,从网络上获取相应属于这个任务列表的任务
|
|
|
|
|
* @date: 2023/12/24 23:28
|
|
|
|
|
* @author: WuShuxian
|
|
|
|
|
* @param: listGid
|
|
|
|
|
* @return:
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public JSONArray getTaskList(String listGid) throws NetworkFailureException {
|
|
|
|
|
commitUpdate();
|
|
|
|
|
try {
|
|
|
|
@ -640,6 +554,7 @@ public class GTaskClient {
|
|
|
|
|
JSONArray actionList = new JSONArray();
|
|
|
|
|
JSONObject action = new JSONObject();
|
|
|
|
|
|
|
|
|
|
// action_list
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE,
|
|
|
|
|
GTaskStringUtils.GTASK_JSON_ACTION_TYPE_GETALL);
|
|
|
|
|
action.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, getActionId());
|
|
|
|
@ -648,6 +563,7 @@ public class GTaskClient {
|
|
|
|
|
actionList.put(action);
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_ACTION_LIST, actionList);
|
|
|
|
|
|
|
|
|
|
// client_version
|
|
|
|
|
jsPost.put(GTaskStringUtils.GTASK_JSON_CLIENT_VERSION, mClientVersion);
|
|
|
|
|
|
|
|
|
|
JSONObject jsResponse = postRequest(jsPost);
|
|
|
|
|