2025-12-17 15:38:00 +08:00
|
|
|
|
package com.example.livestreaming;
|
|
|
|
|
|
|
2025-12-23 12:39:14 +08:00
|
|
|
|
import android.Manifest;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
import android.content.Intent;
|
2025-12-18 17:33:36 +08:00
|
|
|
|
import android.content.ClipData;
|
|
|
|
|
|
import android.content.ClipboardManager;
|
2025-12-22 16:31:46 +08:00
|
|
|
|
import android.graphics.drawable.Drawable;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
import android.os.Bundle;
|
2025-12-19 15:11:49 +08:00
|
|
|
|
import android.net.Uri;
|
2025-12-18 14:20:41 +08:00
|
|
|
|
import android.text.TextUtils;
|
2025-12-18 17:33:36 +08:00
|
|
|
|
import android.view.View;
|
2025-12-18 14:20:41 +08:00
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
import android.widget.Toast;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
|
import androidx.activity.result.ActivityResultLauncher;
|
|
|
|
|
|
import androidx.activity.result.contract.ActivityResultContracts;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
import androidx.appcompat.app.AppCompatActivity;
|
2025-12-23 15:37:37 +08:00
|
|
|
|
import androidx.core.content.FileProvider;
|
2025-12-18 14:20:41 +08:00
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
|
2025-12-18 14:20:41 +08:00
|
|
|
|
import com.bumptech.glide.Glide;
|
2025-12-23 12:39:14 +08:00
|
|
|
|
import com.example.livestreaming.BuildConfig;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
import com.example.livestreaming.databinding.ActivityProfileBinding;
|
2025-12-23 12:39:14 +08:00
|
|
|
|
import com.example.livestreaming.ShareUtils;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
2025-12-23 12:39:14 +08:00
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
2025-12-17 15:38:00 +08:00
|
|
|
|
|
2025-12-23 12:39:14 +08:00
|
|
|
|
import java.io.File;
|
2025-12-22 16:31:46 +08:00
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
|
import java.text.ParseException;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
2025-12-17 15:38:00 +08:00
|
|
|
|
public class ProfileActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
|
|
|
|
private ActivityProfileBinding binding;
|
|
|
|
|
|
|
2025-12-18 14:20:41 +08:00
|
|
|
|
private static final String PREFS_NAME = "profile_prefs";
|
|
|
|
|
|
private static final String KEY_NAME = "profile_name";
|
|
|
|
|
|
private static final String KEY_BIO = "profile_bio";
|
|
|
|
|
|
private static final String KEY_LEVEL = "profile_level";
|
|
|
|
|
|
private static final String KEY_FANS_BADGE = "profile_fans_badge";
|
|
|
|
|
|
private static final String KEY_BADGE = "profile_badge";
|
|
|
|
|
|
private static final String KEY_AVATAR_RES = "profile_avatar_res";
|
|
|
|
|
|
private static final String KEY_AVATAR_URI = "profile_avatar_uri";
|
|
|
|
|
|
private static final String KEY_BIRTHDAY = "profile_birthday";
|
|
|
|
|
|
private static final String KEY_GENDER = "profile_gender";
|
|
|
|
|
|
private static final String KEY_LOCATION = "profile_location";
|
|
|
|
|
|
|
2025-12-19 10:50:13 +08:00
|
|
|
|
private static final String BIO_HINT_TEXT = "填写个人签名更容易获得关注,点击此处添加";
|
2025-12-22 16:31:46 +08:00
|
|
|
|
|
|
|
|
|
|
private ActivityResultLauncher<Intent> editProfileLauncher;
|
2025-12-19 10:50:13 +08:00
|
|
|
|
|
2025-12-17 15:38:00 +08:00
|
|
|
|
public static void start(Context context) {
|
|
|
|
|
|
Intent intent = new Intent(context, ProfileActivity.class);
|
|
|
|
|
|
context.startActivity(intent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
binding = ActivityProfileBinding.inflate(getLayoutInflater());
|
|
|
|
|
|
setContentView(binding.getRoot());
|
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
|
// 注册编辑资料页面的结果监听
|
|
|
|
|
|
editProfileLauncher = registerForActivityResult(
|
|
|
|
|
|
new ActivityResultContracts.StartActivityForResult(),
|
|
|
|
|
|
result -> {
|
|
|
|
|
|
// 当从EditProfileActivity返回时,立即刷新所有数据
|
|
|
|
|
|
loadProfileFromPrefs();
|
|
|
|
|
|
loadAndDisplayTags();
|
|
|
|
|
|
loadProfileInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-12-18 14:20:41 +08:00
|
|
|
|
loadProfileFromPrefs();
|
2025-12-22 16:31:46 +08:00
|
|
|
|
loadAndDisplayTags();
|
|
|
|
|
|
loadProfileInfo();
|
2025-12-18 14:20:41 +08:00
|
|
|
|
setupEditableAreas();
|
2025-12-22 16:31:46 +08:00
|
|
|
|
setupAvatarClick();
|
2025-12-18 14:20:41 +08:00
|
|
|
|
setupNavigationClicks();
|
2025-12-18 17:33:36 +08:00
|
|
|
|
setupProfileTabs();
|
2025-12-18 14:20:41 +08:00
|
|
|
|
|
2025-12-17 15:38:00 +08:00
|
|
|
|
BottomNavigationView bottomNavigation = binding.bottomNavInclude.bottomNavigation;
|
|
|
|
|
|
bottomNavigation.setSelectedItemId(R.id.nav_profile);
|
2025-12-22 16:31:46 +08:00
|
|
|
|
|
|
|
|
|
|
// 更新未读消息徽章
|
|
|
|
|
|
UnreadMessageManager.updateBadge(bottomNavigation);
|
|
|
|
|
|
|
2025-12-17 15:38:00 +08:00
|
|
|
|
bottomNavigation.setOnItemSelectedListener(item -> {
|
|
|
|
|
|
int id = item.getItemId();
|
|
|
|
|
|
if (id == R.id.nav_home) {
|
|
|
|
|
|
startActivity(new Intent(this, MainActivity.class));
|
|
|
|
|
|
finish();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (id == R.id.nav_friends) {
|
|
|
|
|
|
startActivity(new Intent(this, FishPondActivity.class));
|
|
|
|
|
|
finish();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (id == R.id.nav_wish_tree) {
|
|
|
|
|
|
WishTreeActivity.start(this);
|
|
|
|
|
|
finish();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (id == R.id.nav_messages) {
|
|
|
|
|
|
MessagesActivity.start(this);
|
|
|
|
|
|
finish();
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 14:20:41 +08:00
|
|
|
|
private void loadProfileFromPrefs() {
|
2025-12-23 15:37:37 +08:00
|
|
|
|
// TODO: 接入后端接口 - 获取用户资料
|
|
|
|
|
|
// 接口路径: GET /api/users/{userId}/profile
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(路径参数,当前用户从token中获取)
|
|
|
|
|
|
// 返回数据格式: ApiResponse<UserProfile>
|
|
|
|
|
|
// UserProfile对象应包含: id, name, avatarUrl, bio, level, badge, birthday, gender, location,
|
|
|
|
|
|
// followingCount, fansCount, likesCount等字段
|
|
|
|
|
|
// 首次加载时从接口获取,后续可从本地缓存读取
|
2025-12-18 14:20:41 +08:00
|
|
|
|
String n = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_NAME, null);
|
|
|
|
|
|
if (!TextUtils.isEmpty(n)) binding.name.setText(n);
|
|
|
|
|
|
|
|
|
|
|
|
String bio = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_BIO, null);
|
2025-12-19 10:50:13 +08:00
|
|
|
|
if (!TextUtils.isEmpty(bio) && !BIO_HINT_TEXT.equals(bio)) {
|
2025-12-18 14:20:41 +08:00
|
|
|
|
binding.bioText.setText(bio);
|
|
|
|
|
|
binding.bioText.setTextColor(0xFF111111);
|
2025-12-19 10:50:13 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
binding.bioText.setText(BIO_HINT_TEXT);
|
|
|
|
|
|
binding.bioText.setTextColor(0xFF999999);
|
2025-12-18 14:20:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String avatarUri = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_AVATAR_URI, null);
|
|
|
|
|
|
if (!TextUtils.isEmpty(avatarUri)) {
|
2025-12-23 15:37:37 +08:00
|
|
|
|
Uri uri = Uri.parse(avatarUri);
|
|
|
|
|
|
// 如果是 file:// 协议,尝试转换为 FileProvider URI
|
|
|
|
|
|
if ("file".equals(uri.getScheme())) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
java.io.File file = new java.io.File(uri.getPath());
|
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
|
uri = FileProvider.getUriForFile(
|
|
|
|
|
|
this,
|
|
|
|
|
|
getPackageName() + ".fileprovider",
|
|
|
|
|
|
file
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
// 如果转换失败,使用原始 URI
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-19 15:11:49 +08:00
|
|
|
|
Glide.with(this)
|
2025-12-23 15:37:37 +08:00
|
|
|
|
.load(uri)
|
2025-12-19 15:11:49 +08:00
|
|
|
|
.circleCrop()
|
|
|
|
|
|
.error(R.drawable.ic_account_circle_24)
|
2025-12-23 15:37:37 +08:00
|
|
|
|
.placeholder(R.drawable.ic_account_circle_24)
|
2025-12-19 15:11:49 +08:00
|
|
|
|
.into(binding.avatar);
|
2025-12-18 14:20:41 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
int avatarRes = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getInt(KEY_AVATAR_RES, 0);
|
|
|
|
|
|
if (avatarRes != 0) {
|
2025-12-19 15:11:49 +08:00
|
|
|
|
Glide.with(this)
|
|
|
|
|
|
.load(avatarRes)
|
|
|
|
|
|
.circleCrop()
|
|
|
|
|
|
.error(R.drawable.ic_account_circle_24)
|
|
|
|
|
|
.into(binding.avatar);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.avatar.setImageResource(R.drawable.ic_account_circle_24);
|
2025-12-18 14:20:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 等级/称号/徽章:保持固定显示(例如“月亮/星耀/至尊”),不从本地缓存覆盖。
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void setupEditableAreas() {
|
2025-12-23 15:37:37 +08:00
|
|
|
|
// TODO: 接入后端接口 - 更新用户资料
|
|
|
|
|
|
// 接口路径: PUT /api/users/{userId}/profile
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(路径参数,从token中获取)
|
|
|
|
|
|
// - name (可选): 昵称
|
|
|
|
|
|
// - bio (可选): 个人签名
|
|
|
|
|
|
// - avatarUrl (可选): 头像URL
|
|
|
|
|
|
// - birthday (可选): 生日
|
|
|
|
|
|
// - gender (可选): 性别
|
|
|
|
|
|
// - location (可选): 所在地
|
|
|
|
|
|
// 返回数据格式: ApiResponse<UserProfile>
|
|
|
|
|
|
// 更新成功后,同步更新本地缓存和界面显示
|
2025-12-18 14:20:41 +08:00
|
|
|
|
binding.name.setOnClickListener(v -> showEditDialog("编辑昵称", binding.name.getText() != null ? binding.name.getText().toString() : "", text -> {
|
|
|
|
|
|
binding.name.setText(text);
|
|
|
|
|
|
getSharedPreferences(PREFS_NAME, MODE_PRIVATE).edit().putString(KEY_NAME, text).apply();
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
2025-12-19 10:50:13 +08:00
|
|
|
|
binding.bioText.setOnClickListener(v -> {
|
|
|
|
|
|
String current = binding.bioText.getText() != null ? binding.bioText.getText().toString() : "";
|
|
|
|
|
|
String initial = BIO_HINT_TEXT.equals(current) ? "" : current;
|
|
|
|
|
|
showEditDialog("编辑签名", initial, text -> {
|
|
|
|
|
|
if (TextUtils.isEmpty(text) || BIO_HINT_TEXT.equals(text)) {
|
|
|
|
|
|
binding.bioText.setText(BIO_HINT_TEXT);
|
|
|
|
|
|
binding.bioText.setTextColor(0xFF999999);
|
|
|
|
|
|
getSharedPreferences(PREFS_NAME, MODE_PRIVATE).edit().remove(KEY_BIO).apply();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.bioText.setText(text);
|
|
|
|
|
|
binding.bioText.setTextColor(0xFF111111);
|
|
|
|
|
|
getSharedPreferences(PREFS_NAME, MODE_PRIVATE).edit().putString(KEY_BIO, text).apply();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2025-12-18 14:20:41 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
|
private void setupAvatarClick() {
|
|
|
|
|
|
binding.avatar.setOnClickListener(v -> {
|
2025-12-22 16:31:46 +08:00
|
|
|
|
AvatarViewerDialog dialog = AvatarViewerDialog.create(this);
|
|
|
|
|
|
|
|
|
|
|
|
// 优先从SharedPreferences读取最新的头像信息(因为ImageView可能还在加载中)
|
|
|
|
|
|
String avatarUri = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_AVATAR_URI, null);
|
|
|
|
|
|
int avatarRes = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getInt(KEY_AVATAR_RES, 0);
|
|
|
|
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(avatarUri)) {
|
|
|
|
|
|
// 使用URI加载,确保能正确显示
|
|
|
|
|
|
dialog.setAvatarUri(Uri.parse(avatarUri));
|
|
|
|
|
|
} else if (avatarRes != 0) {
|
|
|
|
|
|
dialog.setAvatarResId(avatarRes);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 如果都没有,尝试从ImageView获取Drawable
|
|
|
|
|
|
Drawable drawable = binding.avatar.getDrawable();
|
|
|
|
|
|
if (drawable != null) {
|
|
|
|
|
|
dialog.setAvatarDrawable(drawable);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
dialog.setAvatarResId(R.drawable.ic_account_circle_24);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
dialog.show();
|
2025-12-23 12:39:14 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 14:20:41 +08:00
|
|
|
|
private void setupNavigationClicks() {
|
2025-12-18 17:33:36 +08:00
|
|
|
|
binding.topActionSearch.setOnClickListener(v -> TabPlaceholderActivity.start(this, "定位/发现"));
|
2025-12-23 18:09:56 +08:00
|
|
|
|
binding.topActionClock.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,观看历史需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "查看观看历史需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
WatchHistoryActivity.start(this);
|
|
|
|
|
|
});
|
2025-12-18 14:20:41 +08:00
|
|
|
|
binding.topActionMore.setOnClickListener(v -> TabPlaceholderActivity.start(this, "更多"));
|
|
|
|
|
|
|
2025-12-18 17:33:36 +08:00
|
|
|
|
binding.copyIdBtn.setOnClickListener(v -> {
|
|
|
|
|
|
String idText = binding.idLine.getText() != null ? binding.idLine.getText().toString() : "";
|
|
|
|
|
|
if (TextUtils.isEmpty(idText)) return;
|
|
|
|
|
|
String digits = idText.replaceAll("\\D+", "");
|
|
|
|
|
|
if (TextUtils.isEmpty(digits)) return;
|
|
|
|
|
|
ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
|
|
|
|
|
if (cm != null) {
|
|
|
|
|
|
cm.setPrimaryClip(ClipData.newPlainText("id", digits));
|
|
|
|
|
|
Toast.makeText(this, "已复制:" + digits, Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-23 15:37:37 +08:00
|
|
|
|
// TODO: 接入后端接口 - 获取关注/粉丝/获赞数量
|
|
|
|
|
|
// 接口路径: GET /api/users/{userId}/stats
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(路径参数)
|
|
|
|
|
|
// 返回数据格式: ApiResponse<{followingCount: number, fansCount: number, likesCount: number}>
|
|
|
|
|
|
// 在ProfileActivity加载时调用,更新关注、粉丝、获赞数量显示
|
2025-12-23 18:09:56 +08:00
|
|
|
|
binding.following.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,查看关注列表需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "查看关注列表需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
FollowingListActivity.start(this);
|
|
|
|
|
|
});
|
|
|
|
|
|
binding.followers.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,查看粉丝列表需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "查看粉丝列表需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
FansListActivity.start(this);
|
|
|
|
|
|
});
|
|
|
|
|
|
binding.likes.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,查看获赞列表需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "查看获赞列表需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
LikesListActivity.start(this);
|
|
|
|
|
|
});
|
2025-12-18 14:20:41 +08:00
|
|
|
|
|
|
|
|
|
|
binding.action1.setOnClickListener(v -> TabPlaceholderActivity.start(this, "公园勋章"));
|
2025-12-23 18:09:56 +08:00
|
|
|
|
binding.action2.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,观看历史需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "查看观看历史需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
WatchHistoryActivity.start(this);
|
|
|
|
|
|
});
|
2025-12-18 14:20:41 +08:00
|
|
|
|
binding.action3.setOnClickListener(v -> startActivity(new Intent(this, MyFriendsActivity.class)));
|
|
|
|
|
|
|
2025-12-22 16:31:46 +08:00
|
|
|
|
binding.editProfile.setOnClickListener(v -> {
|
2025-12-23 18:09:56 +08:00
|
|
|
|
// 检查登录状态,编辑资料需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "编辑资料需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-12-22 16:31:46 +08:00
|
|
|
|
Intent intent = new Intent(this, EditProfileActivity.class);
|
|
|
|
|
|
editProfileLauncher.launch(intent);
|
|
|
|
|
|
});
|
2025-12-23 18:09:56 +08:00
|
|
|
|
binding.shareHome.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,分享个人主页需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "分享个人主页需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
showShareProfileDialog();
|
|
|
|
|
|
});
|
2025-12-18 14:20:41 +08:00
|
|
|
|
binding.addFriendBtn.setOnClickListener(v -> TabPlaceholderActivity.start(this, "加好友"));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 17:33:36 +08:00
|
|
|
|
private void setupProfileTabs() {
|
|
|
|
|
|
showTab(0);
|
|
|
|
|
|
|
|
|
|
|
|
binding.profileTabs.addOnTabSelectedListener(new com.google.android.material.tabs.TabLayout.OnTabSelectedListener() {
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onTabSelected(com.google.android.material.tabs.TabLayout.Tab tab) {
|
|
|
|
|
|
if (tab == null) return;
|
|
|
|
|
|
showTab(tab.getPosition());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onTabUnselected(com.google.android.material.tabs.TabLayout.Tab tab) {
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public void onTabReselected(com.google.android.material.tabs.TabLayout.Tab tab) {
|
|
|
|
|
|
if (tab == null) return;
|
|
|
|
|
|
showTab(tab.getPosition());
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-23 18:09:56 +08:00
|
|
|
|
// TODO: 接入后端接口 - 发布作品
|
|
|
|
|
|
// 接口路径: POST /api/works
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(从token中获取)
|
|
|
|
|
|
// - title: 作品标题
|
|
|
|
|
|
// - description: 作品描述(可选)
|
|
|
|
|
|
// - coverUrl: 封面图片URL(必填,需要先上传图片)
|
|
|
|
|
|
// - videoUrl (可选): 视频URL(如果是视频作品)
|
|
|
|
|
|
// - images (可选): 图片URL列表(如果是图片作品)
|
|
|
|
|
|
// 返回数据格式: ApiResponse<WorkItem>
|
|
|
|
|
|
// WorkItem对象应包含: id, title, coverUrl, likeCount, viewCount, publishTime等字段
|
|
|
|
|
|
// 发布成功后,刷新作品列表显示
|
|
|
|
|
|
binding.worksPublishBtn.setOnClickListener(v -> {
|
|
|
|
|
|
// 检查登录状态,发布作品需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "发布作品需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Toast.makeText(this, "发布功能待接入", Toast.LENGTH_SHORT).show();
|
|
|
|
|
|
});
|
2025-12-18 17:33:36 +08:00
|
|
|
|
binding.likedGoBrowseBtn.setOnClickListener(v -> startActivity(new Intent(this, MainActivity.class)));
|
|
|
|
|
|
binding.favGoBrowseBtn.setOnClickListener(v -> startActivity(new Intent(this, MainActivity.class)));
|
2025-12-22 16:31:46 +08:00
|
|
|
|
binding.profileEditFromTab.setOnClickListener(v -> {
|
2025-12-23 18:09:56 +08:00
|
|
|
|
// 检查登录状态,编辑资料需要登录
|
|
|
|
|
|
if (!AuthHelper.requireLogin(this, "编辑资料需要登录")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-12-22 16:31:46 +08:00
|
|
|
|
Intent intent = new Intent(this, EditProfileActivity.class);
|
|
|
|
|
|
editProfileLauncher.launch(intent);
|
|
|
|
|
|
});
|
2025-12-18 17:33:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showTab(int index) {
|
2025-12-23 18:09:56 +08:00
|
|
|
|
// TODO: 接入后端接口 - 获取用户作品列表
|
|
|
|
|
|
// 接口路径: GET /api/users/{userId}/works
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(从token中获取)
|
|
|
|
|
|
// - page (可选): 页码
|
|
|
|
|
|
// - pageSize (可选): 每页数量
|
|
|
|
|
|
// 返回数据格式: ApiResponse<List<WorkItem>>
|
|
|
|
|
|
// WorkItem对象应包含: id, title, coverUrl, likeCount, viewCount, publishTime等字段
|
|
|
|
|
|
// TODO: 接入后端接口 - 获取用户收藏列表
|
|
|
|
|
|
// 接口路径: GET /api/users/{userId}/favorites
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(从token中获取)
|
|
|
|
|
|
// - page (可选): 页码
|
|
|
|
|
|
// - pageSize (可选): 每页数量
|
|
|
|
|
|
// 返回数据格式: ApiResponse<List<WorkItem>>
|
|
|
|
|
|
// TODO: 接入后端接口 - 获取用户赞过的作品列表
|
|
|
|
|
|
// 接口路径: GET /api/users/{userId}/liked
|
|
|
|
|
|
// 请求参数:
|
|
|
|
|
|
// - userId: 用户ID(从token中获取)
|
|
|
|
|
|
// - page (可选): 页码
|
|
|
|
|
|
// - pageSize (可选): 每页数量
|
|
|
|
|
|
// 返回数据格式: ApiResponse<List<WorkItem>>
|
2025-12-22 16:31:46 +08:00
|
|
|
|
// 标签页顺序:0-作品, 1-收藏, 2-赞过
|
2025-12-18 17:33:36 +08:00
|
|
|
|
binding.tabWorks.setVisibility(index == 0 ? View.VISIBLE : View.GONE);
|
2025-12-22 16:31:46 +08:00
|
|
|
|
binding.tabFavorites.setVisibility(index == 1 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
binding.tabLiked.setVisibility(index == 2 ? View.VISIBLE : View.GONE);
|
|
|
|
|
|
// "资料"标签页已移除
|
2025-12-18 17:33:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-18 14:20:41 +08:00
|
|
|
|
private interface OnTextSaved {
|
|
|
|
|
|
void onSaved(String text);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showEditDialog(String title, String initialValue, OnTextSaved onSaved) {
|
|
|
|
|
|
EditText editText = new EditText(this);
|
|
|
|
|
|
editText.setText(initialValue != null ? initialValue : "");
|
|
|
|
|
|
editText.setSelection(editText.getText() != null ? editText.getText().length() : 0);
|
2025-12-19 10:50:13 +08:00
|
|
|
|
editText.setTextColor(0xFF111111);
|
|
|
|
|
|
editText.setHintTextColor(0xFF999999);
|
|
|
|
|
|
if ("编辑签名".equals(title)) {
|
|
|
|
|
|
editText.setHint(BIO_HINT_TEXT);
|
|
|
|
|
|
}
|
2025-12-18 14:20:41 +08:00
|
|
|
|
int pad = (int) (16 * getResources().getDisplayMetrics().density);
|
|
|
|
|
|
editText.setPadding(pad, pad, pad, pad);
|
|
|
|
|
|
|
|
|
|
|
|
new AlertDialog.Builder(this)
|
|
|
|
|
|
.setTitle(title)
|
|
|
|
|
|
.setView(editText)
|
|
|
|
|
|
.setNegativeButton("取消", null)
|
|
|
|
|
|
.setPositiveButton("保存", (d, w) -> {
|
|
|
|
|
|
String t = editText.getText() != null ? editText.getText().toString().trim() : "";
|
|
|
|
|
|
if (onSaved != null) onSaved.onSaved(t);
|
|
|
|
|
|
})
|
|
|
|
|
|
.show();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-17 15:38:00 +08:00
|
|
|
|
@Override
|
|
|
|
|
|
protected void onResume() {
|
|
|
|
|
|
super.onResume();
|
|
|
|
|
|
if (binding != null) {
|
2025-12-18 14:20:41 +08:00
|
|
|
|
loadProfileFromPrefs();
|
2025-12-22 16:31:46 +08:00
|
|
|
|
loadAndDisplayTags();
|
|
|
|
|
|
loadProfileInfo();
|
|
|
|
|
|
BottomNavigationView bottomNav = binding.bottomNavInclude.bottomNavigation;
|
|
|
|
|
|
bottomNav.setSelectedItemId(R.id.nav_profile);
|
|
|
|
|
|
// 更新未读消息徽章
|
|
|
|
|
|
UnreadMessageManager.updateBadge(bottomNav);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void loadAndDisplayTags() {
|
|
|
|
|
|
String location = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_LOCATION, "");
|
|
|
|
|
|
String gender = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_GENDER, "");
|
|
|
|
|
|
String birthday = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_BIRTHDAY, "");
|
|
|
|
|
|
|
|
|
|
|
|
// 设置所在地标签 - 支持"省份-城市"格式
|
|
|
|
|
|
if (!TextUtils.isEmpty(location)) {
|
|
|
|
|
|
// 将"省份-城市"格式转换为"省份·城市"显示
|
|
|
|
|
|
String displayLocation = location.replace("-", "·");
|
|
|
|
|
|
binding.tagLocation.setText("IP:" + displayLocation);
|
|
|
|
|
|
binding.tagLocation.setVisibility(View.VISIBLE);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagLocation.setText("IP:广西");
|
|
|
|
|
|
binding.tagLocation.setVisibility(View.VISIBLE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 设置性别标签
|
|
|
|
|
|
if (!TextUtils.isEmpty(gender)) {
|
|
|
|
|
|
if (gender.contains("男")) {
|
|
|
|
|
|
binding.tagGender.setText("男");
|
|
|
|
|
|
} else if (gender.contains("女")) {
|
|
|
|
|
|
binding.tagGender.setText("女");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagGender.setText("H");
|
|
|
|
|
|
}
|
|
|
|
|
|
binding.tagGender.setVisibility(View.VISIBLE);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagGender.setText("H");
|
|
|
|
|
|
binding.tagGender.setVisibility(View.VISIBLE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 计算并设置年龄标签
|
|
|
|
|
|
if (!TextUtils.isEmpty(birthday)) {
|
|
|
|
|
|
int age = calculateAge(birthday);
|
|
|
|
|
|
if (age > 0) {
|
|
|
|
|
|
binding.tagAge.setText(age + "岁");
|
|
|
|
|
|
binding.tagAge.setVisibility(View.VISIBLE);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagAge.setVisibility(View.GONE);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagAge.setVisibility(View.GONE);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 计算并设置星座标签
|
|
|
|
|
|
if (!TextUtils.isEmpty(birthday)) {
|
|
|
|
|
|
String constellation = calculateConstellation(birthday);
|
|
|
|
|
|
if (!TextUtils.isEmpty(constellation)) {
|
|
|
|
|
|
binding.tagConstellation.setText(constellation);
|
|
|
|
|
|
binding.tagConstellation.setVisibility(View.VISIBLE);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagConstellation.setVisibility(View.GONE);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
binding.tagConstellation.setVisibility(View.GONE);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void loadProfileInfo() {
|
|
|
|
|
|
String name = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_NAME, "爱你");
|
|
|
|
|
|
String location = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_LOCATION, "广西");
|
|
|
|
|
|
String bio = getSharedPreferences(PREFS_NAME, MODE_PRIVATE).getString(KEY_BIO, null);
|
|
|
|
|
|
|
|
|
|
|
|
if (binding.profileInfoLine1 != null) {
|
|
|
|
|
|
binding.profileInfoLine1.setText("昵称:" + name);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (binding.profileInfoLine2 != null) {
|
|
|
|
|
|
String locationText = !TextUtils.isEmpty(location) ? location : "广西";
|
|
|
|
|
|
binding.profileInfoLine2.setText("地区:" + locationText);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (binding.profileInfoLine3 != null) {
|
|
|
|
|
|
String bioText = (!TextUtils.isEmpty(bio) && !BIO_HINT_TEXT.equals(bio)) ? bio : "填写个人签名更容易获得关注";
|
|
|
|
|
|
binding.profileInfoLine3.setText("签名:" + bioText);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int calculateAge(String birthdayStr) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
|
|
|
|
|
Date birthDate = sdf.parse(birthdayStr);
|
|
|
|
|
|
if (birthDate == null) return 0;
|
|
|
|
|
|
|
|
|
|
|
|
Calendar birth = Calendar.getInstance();
|
|
|
|
|
|
birth.setTime(birthDate);
|
|
|
|
|
|
Calendar now = Calendar.getInstance();
|
|
|
|
|
|
|
|
|
|
|
|
int age = now.get(Calendar.YEAR) - birth.get(Calendar.YEAR);
|
|
|
|
|
|
if (now.get(Calendar.DAY_OF_YEAR) < birth.get(Calendar.DAY_OF_YEAR)) {
|
|
|
|
|
|
age--;
|
|
|
|
|
|
}
|
|
|
|
|
|
return age;
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String calculateConstellation(String birthdayStr) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
|
|
|
|
|
|
Date birthDate = sdf.parse(birthdayStr);
|
|
|
|
|
|
if (birthDate == null) return "";
|
|
|
|
|
|
|
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
|
cal.setTime(birthDate);
|
|
|
|
|
|
int month = cal.get(Calendar.MONTH) + 1; // Calendar.MONTH 从0开始
|
|
|
|
|
|
int day = cal.get(Calendar.DAY_OF_MONTH);
|
|
|
|
|
|
|
|
|
|
|
|
// 星座计算
|
|
|
|
|
|
if ((month == 3 && day >= 21) || (month == 4 && day <= 19)) {
|
|
|
|
|
|
return "白羊座";
|
|
|
|
|
|
} else if ((month == 4 && day >= 20) || (month == 5 && day <= 20)) {
|
|
|
|
|
|
return "金牛座";
|
|
|
|
|
|
} else if ((month == 5 && day >= 21) || (month == 6 && day <= 21)) {
|
|
|
|
|
|
return "双子座";
|
|
|
|
|
|
} else if ((month == 6 && day >= 22) || (month == 7 && day <= 22)) {
|
|
|
|
|
|
return "巨蟹座";
|
|
|
|
|
|
} else if ((month == 7 && day >= 23) || (month == 8 && day <= 22)) {
|
|
|
|
|
|
return "狮子座";
|
|
|
|
|
|
} else if ((month == 8 && day >= 23) || (month == 9 && day <= 22)) {
|
|
|
|
|
|
return "处女座";
|
|
|
|
|
|
} else if ((month == 9 && day >= 23) || (month == 10 && day <= 23)) {
|
|
|
|
|
|
return "天秤座";
|
|
|
|
|
|
} else if ((month == 10 && day >= 24) || (month == 11 && day <= 22)) {
|
|
|
|
|
|
return "天蝎座";
|
|
|
|
|
|
} else if ((month == 11 && day >= 23) || (month == 12 && day <= 21)) {
|
|
|
|
|
|
return "射手座";
|
|
|
|
|
|
} else if ((month == 12 && day >= 22) || (month == 1 && day <= 19)) {
|
|
|
|
|
|
return "摩羯座";
|
|
|
|
|
|
} else if ((month == 1 && day >= 20) || (month == 2 && day <= 18)) {
|
|
|
|
|
|
return "水瓶座";
|
|
|
|
|
|
} else if ((month == 2 && day >= 19) || (month == 3 && day <= 20)) {
|
|
|
|
|
|
return "双鱼座";
|
|
|
|
|
|
}
|
|
|
|
|
|
return "";
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
return "";
|
2025-12-17 15:38:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-12-23 12:39:14 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 显示分享个人主页对话框
|
|
|
|
|
|
*/
|
|
|
|
|
|
private void showShareProfileDialog() {
|
|
|
|
|
|
// 获取用户ID
|
|
|
|
|
|
String idText = binding.idLine.getText() != null ? binding.idLine.getText().toString() : "";
|
|
|
|
|
|
String digits = !TextUtils.isEmpty(idText) ? idText.replaceAll("\\D+", "") : "";
|
|
|
|
|
|
if (TextUtils.isEmpty(digits)) {
|
|
|
|
|
|
digits = "24187196"; // 默认ID
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 直接生成分享链接
|
|
|
|
|
|
String shareLink = ShareUtils.generateProfileShareLink(digits);
|
|
|
|
|
|
ShareUtils.shareLink(this, shareLink, "个人主页", "来看看我的主页吧");
|
|
|
|
|
|
}
|
2025-12-17 15:38:00 +08:00
|
|
|
|
}
|