From 89e24ef6f000461acb16c3292dc8f4c1bdd4b359 Mon Sep 17 00:00:00 2001 From: ynmlzdwsp <2727940448@qq.com> Date: Sat, 23 Sep 2023 10:20:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../023468cfdd0b71d4098903b9070e364658e2fbcf | 22 ++++++------ .../4529b3a97b0f3b19b895aa06f23bed63ff38a312 | 36 +++++++++---------- .../d187f1271655c3d91661a39fe6de395b6a9f290a | 8 ++--- .../f1226eeacd46c914d51f3d1a6d6f27377490d2a4 | 26 +++++++------- .idea/sonarlint/issuestore/index.pb | 22 +++++++++++- .idea/sonarlint/securityhotspotstore/index.pb | 22 +++++++++++- .../net/micode/notes/gtask/data/Task.java | 36 +++++++++++++++++++ .../notes/gtask/remote/GTaskASyncTask.java | 17 +++++++++ .../notes/gtask/remote/GTaskClient.java | 7 ++++ .../notes/gtask/remote/GTaskManager.java | 4 +++ 10 files changed, 152 insertions(+), 48 deletions(-) diff --git a/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf b/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf index fb72d00..1047716 100644 --- a/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf +++ b/.idea/sonarlint/issuestore/0/2/023468cfdd0b71d4098903b9070e364658e2fbcf @@ -1,21 +1,21 @@ -> -java:S1604t"(Make this anonymous inner class a lambda(î +? +java:S1604"(Make this anonymous inner class a lambda(î V java:S125"").(各 +| +java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(各8Ы1 a java:S2184t"FCast one of the operands of this multiplication operation to a "long".(⣛ T java:S1874L"9Remove this use of "DefaultHttpClient"; it is deprecated.(믥 H -java:S1874"2Remove this use of "HttpParams"; it is deprecated.(ŋE +java:S1874"2Remove this use of "HttpParams"; it is deprecated.(ŋE M -java:S1874"7Remove this use of "BasicHttpParams"; it is deprecated.(ŋE +java:S1874"7Remove this use of "BasicHttpParams"; it is deprecated.(ŋE X -java:S1874"").(81 +| +java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(81 +| +java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").(81 +9 +java:S2386."Make this member "protected".(u81 u -java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").( -u -java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").( -u -java:S2293"YReplace the type specification in this constructor call with the diamond operator ("<>").( -2 -java:S2386."Make this member "protected".(u -n -java:S3776"RRefactor this method to reduce its Cognitive Complexity from 91 to the 15 allowed.( -h -java:S3776"RRefactor this method to reduce its Cognitive Complexity from 32 to the 15 allowed.( - -java:S6541"A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 116 to 64, Complexity from 51 to 14, Nesting Level from 6 to 2, Number of Variables from 23 to 6.( \ No newline at end of file +java:S3776"RRefactor this method to reduce its Cognitive Complexity from 91 to the 15 allowed.(81 +o +java:S3776"RRefactor this method to reduce its Cognitive Complexity from 32 to the 15 allowed.(81 + +java:S6541"A "Brain Method" was detected. Refactor it to reduce at least one of the following metrics: LOC from 116 to 64, Complexity from 51 to 14, Nesting Level from 6 to 2, Number of Variables from 23 to 6.(81 \ No newline at end of file diff --git a/.idea/sonarlint/issuestore/index.pb b/.idea/sonarlint/issuestore/index.pb index 0cf0abf..5177437 100644 --- a/.idea/sonarlint/issuestore/index.pb +++ b/.idea/sonarlint/issuestore/index.pb @@ -148,4 +148,24 @@ p k ;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 j -:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 \ No newline at end of file +:app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 +g +7app/src/main/java/net/micode/notes/gtask/data/Node.java,3\a\3aac5305cb73bfbdeb8078cd264d04323fa80e92 +j +:app/src/main/java/net/micode/notes/gtask/data/SqlData.java,9\3\934a4e2abf19d28a53f6aeb1dcd99248c44b6892 +j +:app/src/main/java/net/micode/notes/gtask/data/SqlNote.java,f\1\f1226eeacd46c914d51f3d1a6d6f27377490d2a4 +g +7app/src/main/java/net/micode/notes/gtask/data/Task.java,d\1\d187f1271655c3d91661a39fe6de395b6a9f290a +k +;app/src/main/java/net/micode/notes/gtask/data/TaskList.java,e\0\e094aec5c3e1b6f44539adff3114f5a1ad603ddc +~ +Napp/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java,5\f\5f6162ca79fcea353b280c5dc84973a9c37d2c74 + +Oapp/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java,0\f\0f0f0549145d0e2bfb972ba1ed2e2c38bfd6d1b1 +s +Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf +p +@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312 +q +Aapp/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java,a\b\ab153b0256bc5f6c194e188cec0b8e327e347a90 \ No newline at end of file diff --git a/.idea/sonarlint/securityhotspotstore/index.pb b/.idea/sonarlint/securityhotspotstore/index.pb index c2cf1ae..84ad721 100644 --- a/.idea/sonarlint/securityhotspotstore/index.pb +++ b/.idea/sonarlint/securityhotspotstore/index.pb @@ -148,4 +148,24 @@ p j :app/src/main/java/net/micode/notes/data/NotesProvider.java,6\a\6a65e747031f27aef20597b4181148a9fbf963d5 k -;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 \ No newline at end of file +;app/src/main/java/net/micode/notes/gtask/data/MetaData.java,c\1\c182d0c9c237ea8a46a92ccaae9bb5c751923a88 +g +7app/src/main/java/net/micode/notes/gtask/data/Node.java,3\a\3aac5305cb73bfbdeb8078cd264d04323fa80e92 +j +:app/src/main/java/net/micode/notes/gtask/data/SqlData.java,9\3\934a4e2abf19d28a53f6aeb1dcd99248c44b6892 +j +:app/src/main/java/net/micode/notes/gtask/data/SqlNote.java,f\1\f1226eeacd46c914d51f3d1a6d6f27377490d2a4 +g +7app/src/main/java/net/micode/notes/gtask/data/Task.java,d\1\d187f1271655c3d91661a39fe6de395b6a9f290a +k +;app/src/main/java/net/micode/notes/gtask/data/TaskList.java,e\0\e094aec5c3e1b6f44539adff3114f5a1ad603ddc +~ +Napp/src/main/java/net/micode/notes/gtask/exception/ActionFailureException.java,5\f\5f6162ca79fcea353b280c5dc84973a9c37d2c74 + +Oapp/src/main/java/net/micode/notes/gtask/exception/NetworkFailureException.java,0\f\0f0f0549145d0e2bfb972ba1ed2e2c38bfd6d1b1 +p +@app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java,4\5\4529b3a97b0f3b19b895aa06f23bed63ff38a312 +s +Capp/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java,0\2\023468cfdd0b71d4098903b9070e364658e2fbcf +q +Aapp/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java,a\b\ab153b0256bc5f6c194e188cec0b8e327e347a90 \ No newline at end of file diff --git a/app/src/main/java/net/micode/notes/gtask/data/Task.java b/app/src/main/java/net/micode/notes/gtask/data/Task.java index 6a19454..7f7258c 100644 --- a/app/src/main/java/net/micode/notes/gtask/data/Task.java +++ b/app/src/main/java/net/micode/notes/gtask/data/Task.java @@ -54,6 +54,11 @@ public class Task extends Node { mMetaInfo = null; } + /** + * 生成创建任务的JSON数据 + * @param actionId + * @return + */ public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); @@ -103,6 +108,12 @@ public class Task extends Node { return js; } + + /** + * 生成更新任务的JSON数据 + * @param actionId + * @return + */ public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); @@ -135,6 +146,10 @@ public class Task extends Node { return js; } + /** + * 从远程服务器的JSON数据中设置任务的内容 + * @param js + */ public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try { @@ -175,6 +190,10 @@ public class Task extends Node { } } + /** + * 从本地JSON数据中设置任务的内容 + * @param js + */ public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE) || !js.has(GTaskStringUtils.META_HEAD_DATA)) { @@ -204,6 +223,10 @@ public class Task extends Node { } } + /** + * 将任务的内容转换为本地的JSON数据 + * @return + */ public JSONObject getLocalJSONFromContent() { String name = getName(); try { @@ -247,6 +270,10 @@ public class Task extends Node { } } + /** + * 设置任务的元数据信息 + * @param metaData + */ public void setMetaInfo(MetaData metaData) { if (metaData != null && metaData.getNotes() != null) { try { @@ -258,6 +285,11 @@ public class Task extends Node { } } + /** + * 获取同步操作的动作 + * @param c + * @return + */ public int getSyncAction(Cursor c) { try { JSONObject noteInfo = null; @@ -311,6 +343,10 @@ public class Task extends Node { return SYNC_ACTION_ERROR; } + /** + *判断任务是否值得保存 + * @return + */ public boolean isWorthSaving() { return mMetaInfo != null || (getName() != null && getName().trim().length() > 0) || (getNotes() != null && getNotes().trim().length() > 0); diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java b/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java index 56c8e5e..d6b382d 100644 --- a/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java +++ b/app/src/main/java/net/micode/notes/gtask/remote/GTaskASyncTask.java @@ -29,6 +29,9 @@ import net.micode.notes.ui.NotesListActivity; import net.micode.notes.ui.NotesPreferenceActivity; +/** + * 执行后台异步任务 + */ public class GTaskASyncTask extends AsyncTask { private static int GTASK_SYNC_NOTIFICATION_ID = 5234235; @@ -57,6 +60,10 @@ public class GTaskASyncTask extends AsyncTask { mTaskManager.cancelSync(); } + /** + * 发布进度信息 + * @param message + */ public void publishProgess(String message) { publishProgress(new String[] { message @@ -83,6 +90,11 @@ public class GTaskASyncTask extends AsyncTask { mNotifiManager.notify(GTASK_SYNC_NOTIFICATION_ID, notification); } + /** + * 在后台线程中执行的任务 + * @param unused + * @return + */ @Override protected Integer doInBackground(Void... unused) { publishProgess(mContext.getString(R.string.sync_progress_login, NotesPreferenceActivity @@ -90,6 +102,7 @@ public class GTaskASyncTask extends AsyncTask { return mTaskManager.sync(mContext, this); } + @Override protected void onProgressUpdate(String... progress) { showNotification(R.string.ticker_syncing, progress[0]); @@ -98,6 +111,10 @@ public class GTaskASyncTask extends AsyncTask { } } + /** + * 根据任务的结果显示相应的通知 + * @param result + */ @Override protected void onPostExecute(Integer result) { if (result == GTaskManager.STATE_SUCCESS) { diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java b/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java index 0ee5dc8..217cbfb 100644 --- a/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java +++ b/app/src/main/java/net/micode/notes/gtask/remote/GTaskClient.java @@ -114,10 +114,13 @@ public class GTaskClient { // 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 @@ -130,13 +133,16 @@ public class GTaskClient { return true; } + //更新最新登录时间为当前时间 mLastLoginTime = System.currentTimeMillis(); + //调用loginGoogleAccount方法进行Google账户登录,并获取认证令牌。 String authToken = loginGoogleAccount(activity, false); if (authToken == null) { Log.e(TAG, "login google account failed"); return false; } + //如果不是以 "gmail.com" 或 "googlemail.com" 结尾的自定义域名账户,则构建登录URL,并使用tryToLoginGtask方法尝试登录 // login with custom domain if necessary if (!(mAccount.name.toLowerCase().endsWith("gmail.com") || mAccount.name.toLowerCase() .endsWith("googlemail.com"))) { @@ -152,6 +158,7 @@ public class GTaskClient { } } + //如果自定义域名登录失败,则使用Google官方的登录URL,并使用tryToLoginGtask方法尝试登录 // try to login with google official url if (!mLoggedin) { mGetUrl = GTASK_GET_URL; diff --git a/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java b/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java index d2b4082..0197168 100644 --- a/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java +++ b/app/src/main/java/net/micode/notes/gtask/remote/GTaskManager.java @@ -247,6 +247,10 @@ public class GTaskManager { } } + /** + * 将本地笔记与远程GTasks进行同步 + * @throws NetworkFailureException + */ private void syncContent() throws NetworkFailureException { int syncType; Cursor c = null;