|
|
|
|
@ -1895,6 +1895,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void reserveBookOnServer(final Book book) {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持预约功能,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final String userId = currentUserId;
|
|
|
|
|
if (userId == null) return;
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
@ -1956,6 +1962,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadReservationsAndShowDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持预约功能,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final String userId = currentUserId;
|
|
|
|
|
if (userId == null) return;
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
@ -2161,6 +2173,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadNotificationsAndShowDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持通知中心,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final String userId = currentUserId;
|
|
|
|
|
if (userId == null) return;
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
@ -2387,63 +2405,55 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
} finally {
|
|
|
|
|
if (conn != null) conn.disconnect();
|
|
|
|
|
}
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final EditText input = new EditText(MainActivity.this);
|
|
|
|
|
input.setHint("输入图书ID,用于添加或取消收藏");
|
|
|
|
|
private void removeFavoriteOnServer(final String bookId) {
|
|
|
|
|
final String userId = currentUserId;
|
|
|
|
|
if (userId == null) return;
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
|
|
|
|
|
builder.setTitle("我的收藏(本地)");
|
|
|
|
|
builder.setMessage(sb.length() > 0 ? sb.toString() : "暂无收藏");
|
|
|
|
|
builder.setView(input);
|
|
|
|
|
builder.setPositiveButton("添加收藏", new DialogInterface.OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
String bookId = input.getText().toString().trim();
|
|
|
|
|
if (!bookId.isEmpty()) {
|
|
|
|
|
addFavoriteLocal(bookId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNeutralButton("取消收藏", new DialogInterface.OnClickListener() {
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
String bookId = input.getText().toString().trim();
|
|
|
|
|
if (!bookId.isEmpty()) {
|
|
|
|
|
removeFavoriteLocal(bookId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton("关闭", null);
|
|
|
|
|
builder.show();
|
|
|
|
|
}
|
|
|
|
|
public void run() {
|
|
|
|
|
HttpURLConnection conn = null;
|
|
|
|
|
try {
|
|
|
|
|
URL url = new URL(baseUrl + "/api/favorites?userId=" + userId + "&bookId=" + bookId);
|
|
|
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
|
|
|
conn.setRequestMethod("DELETE");
|
|
|
|
|
conn.setConnectTimeout(5000);
|
|
|
|
|
conn.setReadTimeout(5000);
|
|
|
|
|
|
|
|
|
|
private void addFavoriteLocal(final String bookId) {
|
|
|
|
|
if (dataManager == null) {
|
|
|
|
|
Toast.makeText(MainActivity.this, "本地数据未初始化", Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (currentUserId == null) {
|
|
|
|
|
Toast.makeText(MainActivity.this, "请先登录", Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dataManager.addFavorite(currentUserId, bookId);
|
|
|
|
|
Toast.makeText(MainActivity.this, "收藏成功(本地)", Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
final JSONObject json = readJson(conn);
|
|
|
|
|
final boolean success = json.optBoolean("success", false);
|
|
|
|
|
final String message = json.optString("message", "");
|
|
|
|
|
|
|
|
|
|
private void removeFavoriteLocal(final String bookId) {
|
|
|
|
|
if (dataManager == null) {
|
|
|
|
|
Toast.makeText(MainActivity.this, "本地数据未初始化", Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (currentUserId == null) {
|
|
|
|
|
Toast.makeText(MainActivity.this, "请先登录", Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
dataManager.removeFavorite(currentUserId, bookId);
|
|
|
|
|
Toast.makeText(MainActivity.this, "取消收藏成功(本地)", Toast.LENGTH_SHORT).show();
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
message != null && !message.isEmpty() ? message : (success ? "取消收藏成功" : "取消收藏失败"),
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
final String err = e.getMessage();
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"取消收藏失败: " + err,
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
if (conn != null) conn.disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadNotesAndShowDialog() {
|
|
|
|
|
@ -2514,28 +2524,37 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
|
showDeleteNoteDialog();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
builder.setNegativeButton("关闭", null);
|
|
|
|
|
builder.show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} catch (final Exception e) {
|
|
|
|
|
final String err = e.getMessage();
|
|
|
|
|
runOnUiThread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
progressBar.setVisibility(View.GONE);
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"加载笔记失败: " + err,
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
} finally {
|
|
|
|
|
if (conn != null) conn.disconnect();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadNotesAndShowDialog() {
|
|
|
|
|
private void showAddNoteDialog() {
|
|
|
|
|
final String userId = currentUserId;
|
|
|
|
|
if (userId == null) return;
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
loadNotesAndShowDialogLocal();
|
|
|
|
|
if (userId == null) {
|
|
|
|
|
Toast.makeText(MainActivity.this, "请先登录", Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@Override
|
|
|
|
|
public void run() {
|
|
|
|
|
HttpURLConnection conn = null;
|
|
|
|
|
try {
|
|
|
|
|
URL url = new URL(baseUrl + "/api/notes?userId=" + userId);
|
|
|
|
|
conn = (HttpURLConnection) url.openConnection();
|
|
|
|
|
conn.setRequestMethod("GET");
|
|
|
|
|
conn.setConnectTimeout(5000);
|
|
|
|
|
conn.setReadTimeout(5000);
|
|
|
|
|
final LinearLayout layout = new LinearLayout(this);
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
layout.setPadding(50, 20, 50, 0);
|
|
|
|
|
|
|
|
|
|
@ -2726,6 +2745,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showCommentsBookIdInputDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持图书评论功能,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final EditText input = new EditText(this);
|
|
|
|
|
input.setHint("输入要查看的图书ID");
|
|
|
|
|
|
|
|
|
|
@ -2746,6 +2771,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadCommentsAndShowDialog(final String bookId) {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持图书评论功能,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@ -2866,6 +2897,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addCommentOnServer(final String userId, final String bookId, final String content, final int rating) {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持图书评论功能,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@ -2921,6 +2958,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadFeedbackAndShowDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持意见反馈列表,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final String userId = currentUserId;
|
|
|
|
|
if (userId == null) return;
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
@ -3055,6 +3098,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
private void submitFeedbackOnServer(final String userId, final String type,
|
|
|
|
|
final String title, final String content, final String contact) {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持意见反馈提交,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@ -3111,6 +3160,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadStatsAndShowDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持服务器统计概览,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@ -3187,6 +3242,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadAiAnalysisAndShowDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持服务器 AI 阅读分析,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@ -3240,6 +3301,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void loadSystemStatusAndShowDialog() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持服务器系统状态查询,请切换到网络模式使用。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
@ -3303,6 +3370,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showAiAssistant() {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式下请使用增强 AI 助手界面,或切换到网络模式使用服务器 AI。",
|
|
|
|
|
Toast.LENGTH_LONG).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
final LinearLayout layout = new LinearLayout(this);
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL);
|
|
|
|
|
layout.setPadding(50, 20, 50, 0);
|
|
|
|
|
@ -3334,6 +3407,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void callAiBackend(final String question) {
|
|
|
|
|
if (useLocalMode) {
|
|
|
|
|
Toast.makeText(MainActivity.this,
|
|
|
|
|
"本地模式暂不支持服务器 AI 助手,请切换到网络模式使用,或使用本地增强 AI 助手。",
|
|
|
|
|
Toast.LENGTH_SHORT).show();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
progressBar.setVisibility(View.VISIBLE);
|
|
|
|
|
|
|
|
|
|
new Thread(new Runnable() {
|
|
|
|
|
|