Skip to content

Commit f0eb4d3

Browse files
authored
Merge pull request #576 from shuzijun/gradle
fix bugs
2 parents f9388c9 + 2c804f3 commit f0eb4d3

14 files changed

+152
-26
lines changed

src/main/java/com/shuzijun/leetcode/plugin/manager/CodeManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static void RunCodeCode(String titleSlug, Project project) {
148148
} else if (response.getStatusCode() == 429) {
149149
MessageUtils.getInstance(project).showWarnMsg("", "Please wait for the result.");
150150
} else {
151-
LogUtils.LOG.error("RuncodeCode failure " + response == null ? "" : response.getBody());
151+
LogUtils.LOG.error("RuncodeCode failure " + response.getBody());
152152
MessageUtils.getInstance(project).showWarnMsg("", PropertiesUtils.getInfo("request.failed"));
153153
}
154154
} catch (Exception i) {

src/main/java/com/shuzijun/leetcode/plugin/manager/QuestionManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,17 @@ public static Question pick(Project project, PageInfo<?> pageInfo) {
295295
}
296296

297297
public static User getUser() {
298-
HttpResponse response = Graphql.builder().cn(URLUtils.isCn()).operationName("userStatus").request();
298+
HttpResponse response = Graphql.builder().cn(URLUtils.isCn()).operationName("userStatus","globalData").request();
299299
if (response.getStatusCode() == 200) {
300300
JSONObject userObject = JSONObject.parseObject(response.getBody()).getJSONObject("data").getJSONObject("userStatus");
301301
User user = new User();
302302
user.setPremium(userObject.getBoolean("isPremium"));
303303
user.setUsername(userObject.getString("username"));
304+
if (userObject.containsValue("userSlug")){
305+
user.setUserSlug(userObject.getString("userSlug"));
306+
}else {
307+
user.setUserSlug(user.getUsername());
308+
}
304309
user.setSignedIn(userObject.getBoolean("isSignedIn"));
305310
user.setVerified(userObject.getBoolean("isVerified"));
306311
user.setPhoneVerified(userObject.getBoolean("isPhoneVerified"));

src/main/java/com/shuzijun/leetcode/plugin/manager/SessionManager.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import com.alibaba.fastjson.JSONArray;
55
import com.alibaba.fastjson.JSONObject;
66
import com.intellij.openapi.project.Project;
7+
import com.shuzijun.leetcode.plugin.model.Graphql;
78
import com.shuzijun.leetcode.plugin.model.HttpRequest;
89
import com.shuzijun.leetcode.plugin.model.Session;
910
import com.shuzijun.leetcode.plugin.utils.*;
11+
import com.shuzijun.leetcode.plugin.window.WindowFactory;
1012

1113
import java.util.ArrayList;
1214
import java.util.List;
@@ -37,6 +39,39 @@ public static List<Session> getSession(Project project, boolean cache) {
3739
defSession.setEasy(jsonObject.getJSONObject("solvedPerDifficulty").getInteger("Easy"));
3840
defSession.setMedium(jsonObject.getJSONObject("solvedPerDifficulty").getInteger("Medium"));
3941
defSession.setHard(jsonObject.getJSONObject("solvedPerDifficulty").getInteger("Hard"));
42+
if (URLUtils.isCn()){
43+
HttpResponse sessionHttpResponse = Graphql.builder().cn(URLUtils.isCn()).operationName("userSessionProgress")
44+
.variables("userSlug", WindowFactory.getDataContext(project).getData(DataKeys.LEETCODE_PROJECTS_TABS).getUser().getUserSlug())
45+
.cacheParam(defSession.getName())
46+
.cache(cache)
47+
.request();
48+
if (sessionHttpResponse.getStatusCode() == 200){
49+
JSONObject questionProgressObject = JSON.parseObject(sessionHttpResponse.getBody()).getJSONObject("data").getJSONObject("userProfileUserQuestionProgress");
50+
JSONArray numAcceptedQuestions = questionProgressObject.getJSONArray("numAcceptedQuestions");
51+
for (int i = 0; i < numAcceptedQuestions.size(); i++) {
52+
JSONObject acceptedQuestions = numAcceptedQuestions.getJSONObject(i);
53+
if ("EASY".equals(acceptedQuestions.getString("difficulty"))){
54+
defSession.setEasy(acceptedQuestions.getInteger("count"));
55+
}else if ("MEDIUM".equals(acceptedQuestions.getString("difficulty"))){
56+
defSession.setMedium(acceptedQuestions.getInteger("count"));
57+
}else if ("HARD".equals(acceptedQuestions.getString("difficulty"))){
58+
defSession.setHard(acceptedQuestions.getInteger("count"));
59+
}
60+
}
61+
Integer attempted = 0;
62+
JSONArray numFailedQuestions = questionProgressObject.getJSONArray("numFailedQuestions");
63+
for (int i = 0; i < numFailedQuestions.size(); i++) {
64+
attempted = attempted + numFailedQuestions.getJSONObject(i).getInteger("count");
65+
}
66+
defSession.setAttempted(attempted);
67+
defSession.setSolvedTotal(defSession.getEasy()+defSession.getMedium()+defSession.getHard());
68+
defSession.setUnsolved(defSession.getQuestionTotal() - defSession.getSolvedTotal());
69+
70+
}
71+
}
72+
73+
74+
4075
sessionList.add(defSession);
4176

4277
JSONArray jsonArray = jsonObject.getJSONArray("sessionList");

src/main/java/com/shuzijun/leetcode/plugin/manager/ViewManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static void loadAllServiceData(NavigatorAction navigatorAction, Project p
116116
}
117117
}
118118
if (status) {
119-
if ("TRIED".equalsIgnoreCase(filters.getStatus()) && !questionView.getStatusSign().equalsIgnoreCase("")) {
119+
if ("TRIED".equalsIgnoreCase(filters.getStatus()) && !questionView.getStatusSign().equalsIgnoreCase("?")) {
120120
continue;
121121
} else if ("AC".equalsIgnoreCase(filters.getStatus()) && !questionView.getStatusSign().equalsIgnoreCase("✔")) {
122122
continue;

src/main/java/com/shuzijun/leetcode/plugin/model/QuestionView.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ public void setFrontendQuestionId(String frontendQuestionId) {
109109
}
110110

111111
public void setAcceptance(Double acceptance) {
112+
if (acceptance != null && acceptance.doubleValue() > 1) {
113+
acceptance = acceptance / 100;
114+
}
112115
this.acceptance = acceptance;
113116
}
114117

@@ -117,6 +120,9 @@ public Double getAcceptance() {
117120
}
118121

119122
public Double getFrequency() {
123+
if (frequency != null && frequency.doubleValue() > 1) {
124+
frequency = frequency / 100;
125+
}
120126
return frequency;
121127
}
122128

@@ -127,17 +133,17 @@ public void setFrequency(Double frequency) {
127133
public String getStatusSign() {
128134

129135
if ("notac".equalsIgnoreCase(status) || "TRIED".equalsIgnoreCase(status)) {
130-
return "";
136+
return "?";
131137
} else if ("ac".equalsIgnoreCase(status)) {
132138
return "✔";
133139
} else if ("lock".equalsIgnoreCase(status)) {
134140
return "$";
135141
} else if ("day".equalsIgnoreCase(status)) {
136142
return "D";
137143
} else if (level != null) {
138-
return " ";
144+
return " ";
139145
}
140-
return " ";
146+
return " ";
141147
}
142148

143149
public String getCategory() {

src/main/java/com/shuzijun/leetcode/plugin/model/User.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public class User {
99

1010
private String username;
1111

12+
13+
private String userSlug;
14+
1215
private boolean isPremium;
1316

1417
private boolean isSignedIn = Boolean.FALSE;
@@ -25,6 +28,14 @@ public void setUsername(String username) {
2528
this.username = username;
2629
}
2730

31+
public String getUserSlug() {
32+
return userSlug;
33+
}
34+
35+
public void setUserSlug(String userSlug) {
36+
this.userSlug = userSlug;
37+
}
38+
2839
public boolean isPremium() {
2940
return isPremium;
3041
}

src/main/java/com/shuzijun/leetcode/plugin/utils/URLUtils.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.shuzijun.leetcode.plugin.utils;
22

3+
import com.shuzijun.leetcode.plugin.model.Config;
34
import com.shuzijun.leetcode.plugin.setting.PersistentConfig;
45
import org.apache.commons.lang.StringUtils;
56

@@ -29,7 +30,11 @@ public class URLUtils {
2930
private static String leetcodeRandomOneQuestion = "/problems/random-one-question/all";
3031

3132
public static String getLeetcodeHost() {
32-
String host = PersistentConfig.getInstance().getConfig().getUrl();
33+
Config config = PersistentConfig.getInstance().getInitConfig();
34+
if (config == null) {
35+
return leetcode;
36+
}
37+
String host = config.getUrl();
3338
if (StringUtils.isBlank(host)) {
3439
return leetcode;
3540
}

src/main/java/com/shuzijun/leetcode/plugin/window/login/HttpLogin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static boolean ajaxLogin(Config config, NavigatorAction navigatorAction,
7878
} else {
7979
HttpRequestUtils.resetHttpclient();
8080
MessageUtils.getInstance(project).showInfoMsg("info", PropertiesUtils.getInfo("login.unknown"));
81-
SentryUtils.submitErrorReport(null, String.format("login.unknown:\nStatusCode:%s\nbody:%s", response.getStatusCode(), body));
81+
//SentryUtils.submitErrorReport(null, String.format("login.unknown:\nStatusCode:%s\nbody:%s", response.getStatusCode(), body));
8282
return Boolean.FALSE;
8383
}
8484
} else if (response.getStatusCode() == 400) {
@@ -93,7 +93,7 @@ public static boolean ajaxLogin(Config config, NavigatorAction navigatorAction,
9393
} else {
9494
HttpRequestUtils.resetHttpclient();
9595
MessageUtils.getInstance(project).showInfoMsg("info", PropertiesUtils.getInfo("login.unknown"));
96-
SentryUtils.submitErrorReport(null, String.format("login.unknown:\nStatusCode:%s\nbody:%s", response.getStatusCode(), body));
96+
//SentryUtils.submitErrorReport(null, String.format("login.unknown:\nStatusCode:%s\nbody:%s", response.getStatusCode(), body));
9797
return Boolean.FALSE;
9898
}
9999
} catch (Exception e) {

src/main/java/com/shuzijun/leetcode/plugin/window/navigator/AllNavigatorTable.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ protected MyJBTable<QuestionView> createMyTable(MyTableModel<QuestionView> myTab
8282
MyJBTable<QuestionView> myJBTable = new MyJBTable(myTableModel) {
8383
@Override
8484
protected void prepareRenderer(Component component, Object value, int row, int column) {
85+
if (component instanceof JLabel) {
86+
if (column == 0 || column == 2) {
87+
((JLabel) component).setHorizontalAlignment(SwingConstants.CENTER);
88+
} else {
89+
((JLabel) component).setHorizontalAlignment(SwingConstants.LEADING);
90+
}
91+
}
8592
if (column == 2) {
8693
if (value != null) {
8794
if (value.toString().equals("Easy")) {
@@ -147,8 +154,8 @@ public boolean compareSlug(QuestionView myData, String titleSlug) {
147154
}
148155

149156
protected void setColumnWidth(MyJBTable myJBTable) {
150-
myJBTable.getColumnModel().getColumn(0).setMaxWidth(20);
151-
myJBTable.getColumnModel().getColumn(2).setMaxWidth(60);
157+
myJBTable.getColumnModel().getColumn(0).setMaxWidth(30);
158+
myJBTable.getColumnModel().getColumn(2).setMaxWidth(70);
152159
}
153160

154161
}

src/main/java/com/shuzijun/leetcode/plugin/window/navigator/NavigatorTable.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.shuzijun.leetcode.plugin.model.PageInfo;
88
import com.shuzijun.leetcode.plugin.model.Question;
99
import com.shuzijun.leetcode.plugin.model.QuestionView;
10-
import com.shuzijun.leetcode.plugin.utils.URLUtils;
1110
import com.shuzijun.leetcode.plugin.window.NavigatorTableData;
1211
import icons.LeetCodeEditorIcons;
1312

@@ -103,6 +102,14 @@ protected MyJBTable<QuestionView> createMyTable(MyTableModel<QuestionView> myTab
103102
MyJBTable<QuestionView> myJBTable = new MyJBTable(myTableModel) {
104103
@Override
105104
protected void prepareRenderer(Component component, Object value, int row, int column) {
105+
106+
if (component instanceof JLabel) {
107+
if (column == 0 || column == 2 || column == 3 || column == 4) {
108+
((JLabel) component).setHorizontalAlignment(SwingConstants.CENTER);
109+
} else {
110+
((JLabel) component).setHorizontalAlignment(SwingConstants.LEADING);
111+
}
112+
}
106113
if (column == 3) {
107114
if (value != null) {
108115
if (value.toString().equals("Easy")) {
@@ -173,10 +180,10 @@ public boolean compareSlug(QuestionView myData, String titleSlug) {
173180
}
174181

175182
protected void setColumnWidth(MyJBTable myJBTable) {
176-
myJBTable.getColumnModel().getColumn(0).setMaxWidth(20);
177-
myJBTable.getColumnModel().getColumn(2).setMaxWidth(50);
178-
myJBTable.getColumnModel().getColumn(3).setMaxWidth(60);
179-
myJBTable.getColumnModel().getColumn(4).setMaxWidth(50);
183+
myJBTable.getColumnModel().getColumn(0).setMaxWidth(30);
184+
myJBTable.getColumnModel().getColumn(2).setMaxWidth(60);
185+
myJBTable.getColumnModel().getColumn(3).setMaxWidth(70);
186+
myJBTable.getColumnModel().getColumn(4).setMaxWidth(60);
180187
}
181188

182189
}

src/main/java/com/shuzijun/leetcode/plugin/window/navigator/TopNavigatorTable.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ protected MyJBTable<CodeTopQuestionView> createMyTable(MyTableModel<CodeTopQuest
100100
MyJBTable<CodeTopQuestionView> myJBTable = new MyJBTable(myTableModel) {
101101
@Override
102102
protected void prepareRenderer(Component component, Object value, int row, int column) {
103+
if (component instanceof JLabel) {
104+
if (column == 0 || column == 2 || column == 3 || column == 4) {
105+
((JLabel) component).setHorizontalAlignment(SwingConstants.CENTER);
106+
} else {
107+
((JLabel) component).setHorizontalAlignment(SwingConstants.LEADING);
108+
}
109+
}
103110
if (column == 2) {
104111
if (value != null) {
105112
if (value.toString().equals("Easy")) {
@@ -175,10 +182,11 @@ public boolean compareSlug(CodeTopQuestionView myData, String titleSlug) {
175182

176183
@Override
177184
protected void setColumnWidth(MyJBTable myJBTable) {
178-
myJBTable.getColumnModel().getColumn(0).setMaxWidth(20);
179-
myJBTable.getColumnModel().getColumn(2).setMaxWidth(60);
180-
myJBTable.getColumnModel().getColumn(3).setMaxWidth(80);
181-
myJBTable.getColumnModel().getColumn(4).setMaxWidth(50);
185+
myJBTable.getColumnModel().getColumn(0).setMaxWidth(30);
186+
myJBTable.getColumnModel().getColumn(2).setMaxWidth(70);
187+
myJBTable.getColumnModel().getColumn(3).setMinWidth(100);
188+
myJBTable.getColumnModel().getColumn(3).setMaxWidth(120);
189+
myJBTable.getColumnModel().getColumn(4).setMaxWidth(60);
182190
}
183191

184192

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
query userSessionProgress($userSlug: String!) {
2+
userProfileUserQuestionSubmitStats(userSlug: $userSlug) {
3+
acSubmissionNum {
4+
difficulty
5+
count
6+
}
7+
totalSubmissionNum {
8+
difficulty
9+
count
10+
}
11+
}
12+
userProfileUserQuestionProgress(userSlug: $userSlug) {
13+
numAcceptedQuestions {
14+
difficulty
15+
count
16+
}
17+
numFailedQuestions {
18+
difficulty
19+
count
20+
}
21+
numUntouchedQuestions {
22+
difficulty
23+
count
24+
}
25+
}
26+
}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1-
query userStatus {
1+
query globalData {
22
userStatus {
3+
userId
34
isSignedIn
5+
isMockUser
46
isPremium
7+
isVerified
58
username
69
avatar
710
isAdmin
811
isSuperuser
12+
permissions
913
isTranslator
10-
isVerified
14+
activeSessionId
15+
notificationStatus {
16+
lastModified
17+
numUnread
18+
}
1119
}
1220
}
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
query userStatus {
1+
query globalData {
22
userStatus {
33
isSignedIn
44
isPremium
55
username
6+
realName
67
avatar
8+
userSlug
79
isAdmin
8-
isSuperuser
10+
useTranslation
11+
premiumExpiredAt
912
isTranslator
10-
isVerified
13+
isSuperuser
1114
isPhoneVerified
15+
isVerified
16+
}
17+
jobsMyCompany {
18+
nameSlug
1219
}
13-
}
20+
commonNojPermissionTypes
21+
}

0 commit comments

Comments
 (0)