style: 修改entity层

1.将entity更名为model
2.将所有model层java代码使用kotlin编写
This commit is contained in:
糕小菜 2024-10-16 14:04:40 +08:00
parent 85e9a4c487
commit 17ddb633b6
21 changed files with 162 additions and 211 deletions

View File

@ -1,68 +0,0 @@
package com.kaixed.kchat.entity.search;
import androidx.annotation.NonNull;
/**
* @Author: kaixed
* @Date: 2024/8/13 14:23
* @Description: TODO
*/
public class SearchItem {
private String avatarUrl;
private String name;
private String content;
private boolean hasMore;
private String type;
public SearchItem() {
}
public SearchItem(String avatarUrl, String name, String content, boolean hasMore, String type) {
this.avatarUrl = avatarUrl;
this.name = name;
this.content = content;
this.hasMore = hasMore;
this.type = type;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public boolean isHasMore() {
return hasMore;
}
public void setHasMore(boolean hasMore) {
this.hasMore = hasMore;
}
}

View File

@ -1,48 +0,0 @@
package com.kaixed.kchat.entity.user;
import androidx.annotation.NonNull;
/**
* @Author: kaixed
* @Date: 2024/6/1 20:31
* @Description: TODO
*/
public class User {
private String nickname;
private String avatarUrl;
private String username;
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getAvatarUrl() {
return avatarUrl;
}
public void setAvatarUrl(String avatarUrl) {
this.avatarUrl = avatarUrl;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@NonNull
@Override
public String toString() {
return "User{" +
"nickname='" + nickname + '\'' +
", avatarUrl='" + avatarUrl + '\'' +
", username='" + username + '\'' +
'}';
}
}

View File

@ -1,58 +0,0 @@
package com.kaixed.kchat.entity.user;
import java.util.List;
/**
* @Author: kaixed
* @Date: 2024/6/13 12:43
* @Description: TODO
*/
public class UserList {
private String code;
private String msg;
private Data data;
public static class Data{
private List<User> userLists;
public List<User> getUserLists() {
return userLists;
}
public void setUserLists(List<User> userLists) {
this.userLists = userLists;
}
@Override
public String toString() {
return "Data{" +
"userLists=" + userLists +
'}';
}
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public Data getData() {
return data;
}
public void setData(Data data) {
this.data = data;
}
}

View File

@ -0,0 +1,12 @@
package com.kaixed.kchat.model
/**
* @Author: kaixed
* @Date: 2024/10/16 13:36
* @Description: TODO
*/
data class HomeItem(
val name: String,
val more: Boolean,
val img: Int,
)

View File

@ -0,0 +1,14 @@
package com.kaixed.kchat.model.friend
/**
* @Author: kaixed
* @Date: 2024/10/14 14:30
* @Description: TODO
*/
data class FriendItem(
val username: String,
val avatarUrl: String,
val nickname: String,
val remark: String,
val signature: String,
)

View File

@ -0,0 +1,9 @@
package com.kaixed.kchat.model.login
data class Data(
val avatarUrl: String,
val nickname: String,
val signature: String,
val status: Any,
val username: String,
)

View File

@ -0,0 +1,15 @@
package com.kaixed.kchat.model.search
/**
* @Author: kaixed
* @Date: 2024/10/16 13:32
* @Description: TODO
*/
data class SearchItem(
val avatarUrl: String,
val name: String,
val content: String,
val hasMore: Boolean,
val type: String,
)

View File

@ -0,0 +1,12 @@
package com.kaixed.kchat.model.setting
/**
* @Author: kaixed
* @Date: 2024/10/9 20:35
* @Description: TODO
*/
data class FunctionItem(
val itemName: String,
val remark: String,
)

View File

@ -0,0 +1,11 @@
package com.kaixed.kchat.model.setting
/**
* @Author: kaixed
* @Date: 2024/10/9 20:33
* @Description: TODO
*/
data class NormalItem(
val name: String,
val group: String,
)

View File

@ -0,0 +1,10 @@
package com.kaixed.kchat.model.user
/**
* @Author: kaixed
* @Date: 2024/10/16 13:35
* @Description: TODO
*/
data class Data(
val userLists: List<User>,
)

View File

@ -0,0 +1,12 @@
package com.kaixed.kchat.model.user
/**
* @Author: kaixed
* @Date: 2024/10/16 13:33
* @Description: TODO
*/
data class User(
var nickname: String,
val avatarUrl: String,
val username: String,
)

View File

@ -0,0 +1,12 @@
package com.kaixed.kchat.model.user
/**
* @Author: kaixed
* @Date: 2024/10/16 13:34
* @Description: TODO
*/
data class UserList(
val code: String,
val msg: String,
val data: Data,
)

View File

@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.kaixed.kchat.entity.login.Login;
import com.kaixed.kchat.model.login.Login;
import com.kaixed.kchat.network.NetworkRequest;
import java.io.IOException;

View File

@ -7,7 +7,7 @@ import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import com.google.gson.Gson;
import com.kaixed.kchat.entity.user.UserList;
import com.kaixed.kchat.model.user.UserList;
import com.kaixed.kchat.network.NetworkRequest;
import java.io.IOException;

View File

@ -6,7 +6,6 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@ -15,22 +14,19 @@ import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.kaixed.kchat.KChatApplication;
import com.kaixed.kchat.R;
import com.kaixed.kchat.database.ObjectBox;
import com.kaixed.kchat.database.entity.ChatLists;
import com.kaixed.kchat.database.entity.ChatLists_;
import com.kaixed.kchat.database.entity.Messages;
import com.kaixed.kchat.databinding.ActivityMainBinding;
import com.kaixed.kchat.entity.HomeItem;
import com.kaixed.kchat.model.HomeItem;
import com.kaixed.kchat.service.WebSocketService;
import com.kaixed.kchat.view.adapter.ChatListAdapter;
import com.kaixed.kchat.view.adapter.MyGridAdapter;
@ -280,6 +276,10 @@ public class MainActivity extends AppCompatActivity implements OnChatListItemCli
Intent intent = new Intent(MainActivity.this, AddFriendsActivity.class);
startActivity(intent);
break;
case 6:
Intent intent1 = new Intent(MainActivity.this, FriendListActivity.class);
startActivity(intent1);
break;
default:
finish();
break;
@ -295,7 +295,7 @@ public class MainActivity extends AppCompatActivity implements OnChatListItemCli
items.add(new HomeItem("夜间模式", true, R.drawable.ic_night));
items.add(new HomeItem("好友动态", false, R.drawable.ic_qzone));
items.add(new HomeItem("扫一扫", false, R.drawable.ic_scan));
items.add(new HomeItem("打卡", false, R.drawable.ic_clock_in));
items.add(new HomeItem("通讯录", true, R.drawable.ic_clock_in));
items.add(new HomeItem("关闭应用", false, R.drawable.ic_exit));
}

View File

@ -13,12 +13,13 @@ import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.kaixed.kchat.databinding.ActivitySearchBinding;
import com.kaixed.kchat.entity.search.SearchItem;
import com.kaixed.kchat.model.search.SearchItem;
import com.kaixed.kchat.view.adapter.SearchResultAdapter;
import java.util.ArrayList;
import java.util.List;
public class SearchActivity extends AppCompatActivity {
private ActivitySearchBinding binding;
@ -30,10 +31,40 @@ public class SearchActivity extends AppCompatActivity {
binding = ActivitySearchBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
binding.tvCancel.setOnClickListener(v -> {
finish();
setOnClickListener();
setupRecycleView();
binding.etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
setupViewVisibility(s.length());
}
});
}
private void setupViewVisibility(int length) {
binding.rvSearchResult.setVisibility(length > 0 ? View.VISIBLE : View.INVISIBLE);
binding.tvPageSetting.setVisibility(length > 0 ? View.INVISIBLE : View.VISIBLE);
}
private void setupRecycleView() {
binding.rvSearchResult.setEdgeEffectFactory(new RecyclerView.EdgeEffectFactory() {
@NonNull
@Override
@ -57,31 +88,18 @@ public class SearchActivity extends AppCompatActivity {
}
});
binding.etSearch.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
binding.rvSearchResult.setVisibility(s.length() > 0 ? View.VISIBLE : View.INVISIBLE);
binding.tvPageSetting.setVisibility(s.length() > 0 ? View.INVISIBLE : View.VISIBLE);
}
});
SearchResultAdapter searchResultAdapter = getSearchResultAdapter();
binding.rvSearchResult.setAdapter(searchResultAdapter);
LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
binding.rvSearchResult.setLayoutManager(layoutManager);
}
private void setOnClickListener() {
binding.tvCancel.setOnClickListener(v -> {
finish();
});
}
private static @NonNull SearchResultAdapter getSearchResultAdapter() {
SearchItem contactItem = new SearchItem("sa", "kaixed", "as", false, "联系人");
SearchItem chatHistoryItem = new SearchItem("sa", "kaixed", "as", false, "群聊");

View File

@ -9,7 +9,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.kaixed.kchat.R;
import com.kaixed.kchat.entity.HomeItem;
import com.kaixed.kchat.model.HomeItem;
import java.util.List;
@ -53,7 +53,7 @@ public class MyGridAdapter extends BaseAdapter {
ImageView image = convertView.findViewById(R.id.imageview);
ImageView imageView = convertView.findViewById(R.id.iv_more);
if (item.isMore()) {
if (item.getMore()) {
imageView.setVisibility(View.VISIBLE);
} else {
imageView.setVisibility(View.GONE);

View File

@ -10,7 +10,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.kaixed.kchat.databinding.SearchRecycleItemContactsBinding;
import com.kaixed.kchat.databinding.SearchRecycleItemDetailsBinding;
import com.kaixed.kchat.entity.search.SearchItem;
import com.kaixed.kchat.model.search.SearchItem;
import java.util.List;
@ -52,7 +52,7 @@ public class SearchResultAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
DetailsViewHolder detailsViewHolder = (DetailsViewHolder) holder;
if (displayedItems.get(position) instanceof SearchItem item) {
detailsViewHolder.binding.tvName.setText((item.getName()));
if ((item.isHasMore())) {
if ((item.getHasMore())) {
detailsViewHolder.binding.tvHasMore.setText("更多" + item.getType());
detailsViewHolder.binding.rlHasMore.setVisibility(View.VISIBLE);
detailsViewHolder.binding.view.setVisibility(View.INVISIBLE);

View File

@ -9,7 +9,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.kaixed.kchat.R;
import com.kaixed.kchat.entity.user.User;
import com.kaixed.kchat.model.user.User;
import java.util.List;

View File

@ -3,7 +3,7 @@ package com.kaixed.kchat.viewmodel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.kaixed.kchat.entity.login.Login;
import com.kaixed.kchat.model.login.Login;
import com.kaixed.kchat.repository.LoginRepository;
/**

View File

@ -3,7 +3,7 @@ package com.kaixed.kchat.viewmodel;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
import com.kaixed.kchat.entity.user.UserList;
import com.kaixed.kchat.model.user.UserList;
import com.kaixed.kchat.repository.UserRepository;
/**