小细节修改

master
Toyga 3 years ago
parent c079278026
commit 1f8caa6bc4

@ -31,7 +31,7 @@ public class BaseActivity extends AppCompatActivity {
public static Owner owner;
//服务器链接
public static String SERVER_IP = "172.30.112.86";
public static String SERVER_IP = "172.30.87.197";
// 172.30.118.24 寝172.18.138.225
// static {

@ -260,11 +260,12 @@ public class BlogDetailActivity extends BaseActivity {
@Override
public void onResponse(Call call, Response response) throws IOException {
String jsonStr = response.body().string();
// Log.e("提交评论",jsonStr);
Gson gson = new Gson();
runOnUiThread(new Runnable() {
@Override
public void run() {
commentList.add(comment);
Comment comment1 = gson.fromJson(jsonStr, Comment.class);
commentList.add(comment1);
commentAdapter.setMCommentList(commentList);
recyclerView.setAdapter(commentAdapter);
comEditView.setText("");

@ -81,6 +81,7 @@ public class ChatActivity extends BaseActivity {
jsonMap.put("messageType","1");
jsonMap.put("content", content);
jsonMap.put("createTime", TimeUtil.timeToString(new Timestamp(message.getCreateTime())));
jsonMap.put("username", owner.getUsername());
addMsg(message,1);
edit_content.setText("");
wsClient.send(gson.toJson(jsonMap));

@ -6,6 +6,7 @@ import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;
@ -19,6 +20,7 @@ import java.util.List;
public class InfoActivity extends BaseActivity {
private List<Recnews> recNews=new ArrayList<>();
private int position;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -27,6 +29,7 @@ public class InfoActivity extends BaseActivity {
Intent intent=getIntent();
int infoType=intent.getIntExtra("info_type",4);
position = intent.getIntExtra("position", 0);
List<String> typeList = new ArrayList<String>();
@ -49,10 +52,7 @@ public class InfoActivity extends BaseActivity {
//获取Spinner控件的适配器
ArrayAdapter<String> adapter = (ArrayAdapter<String>) parent.getAdapter();
//tvResult.setText(adapter.getItem(position));
Toast.makeText(getBaseContext(),adapter.getItem(position),Toast.LENGTH_SHORT).show();
// str1=spinner.getSelectedItem().toString();
// Log.e("tag:","你选中的消息是:"+str1);
}
//没有选中时的处理
public void onNothingSelected(AdapterView<?> parent) {
@ -68,48 +68,20 @@ public class InfoActivity extends BaseActivity {
startActivity(i);
}
});
// initRecNews();
// RecyclerView recyclerView=(RecyclerView) findViewById(R.id.info_recyclerView);//显示recycleview
// LinearLayoutManager layoutManager=new LinearLayoutManager(this);
// recyclerView.setLayoutManager(layoutManager);
// InfoAdapter infoAdapter=new InfoAdapter(recNews);
// recyclerView.setAdapter(infoAdapter);
getSupportFragmentManager() //这里添加一个展示资讯的碎片
.beginTransaction()
.add(R.id.infoFragment,new InfoFragment()) // 此处的R.id.fragment_container是要盛放fragment的父容器
.add(R.id.infoFragment,new InfoFragment(position)) // 此处的R.id.fragment_container是要盛放fragment的父容器
.commit();
}
private void initRecNews(){
for(int i=0;i<2;i++){
Recnews news1=new Recnews(R.drawable.rec_news1,
"哪些人容易得白血病?得白血病的人往往有这种征兆...",
"白血病早期是会有一定症状的。比如持续发烧,一些急性白血病前期会出现持续发热,发热原因可能是由于感染……"
,102,"2021-11-6 09:19:54"
);
recNews.add(news1);
Recnews news2=new Recnews(R.drawable.rec_news2,
"抨击误区——白血病化疗那么痛苦,干脆不做化疗了?!",
" “白血病化疗病死率高!不治病还促进病情严重!”“白血病用化疗药很痛苦的,别治了……"
,100,"2021-12-6 03:19:54"
);
recNews.add(news2);
Recnews news3=new Recnews(R.drawable.rec_news3,
"小天使医典:儿童白血病康复指引",
"目前,医学界公认的儿童白血病的发病率为 4-6/10 万人。其中,新增儿童\n" +
"白血病患儿就占二分之一……"
,100,"2021-12-6 03:19:54"
);
recNews.add(news3);
Recnews news4=new Recnews(R.drawable.rec_news4,
"儿童急性B淋巴细胞白血病,除了传统疗法还有哪些前沿治疗方法呢?",
"急性淋巴细胞白血病ALL是儿童最常见的恶性肿瘤其中约85%为……"
,100,"2021-12-6 03:19:54"
);
recNews.add(news4);
}
LinearLayout search = findViewById(R.id.search_linear);
search.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(InfoActivity.this, NewsSearchActivity.class);
startActivity(intent);
}
});
}
}

@ -24,10 +24,15 @@ import com.google.gson.reflect.TypeToken;
import org.litepal.LitePal;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;
public class LoginActivity extends BaseActivity {
private EditText edit_username;
private EditText edit_pwd;
@ -96,9 +101,6 @@ public class LoginActivity extends BaseActivity {
Owner dbOwner=ownerDao.findOwnerByUsername(username);
if (dbOwner!=null){
owner = dbOwner;
// ownerInfoSaveToPref(); //记住密码方法
// 初始化WS链接
// System.out.println(owner);
initWebSocket(owner.getNetId());
Log.d("记录","开始获取未读信息");
getUnReadMsg();
@ -139,35 +141,13 @@ public class LoginActivity extends BaseActivity {
Map<String, String> jsonMap= gson.fromJson(jsonStr, new TypeToken <Map<String, String>>() {}.getType());
final String message=(String) jsonMap.get("message");
if (message.equals("success")){
//进行本地数据存储,本地数据库不存储密码防止泄露需要补全imageURL路径
// JSONObject data=(JSONObject) jsonMap.get("data");
// JSONObject netUser=(JSONObject) data.get("owner");
// JSONArray netFriends=(JSONArray) data.get("friends");
User user = gson.fromJson(jsonMap.get("user"), User.class);
//
Owner newOwner = new Owner();
newOwner.setUsername(user.getUsername());
newOwner.setPassword(user.getPassword());
newOwner.setNetId(user.getIduser());
// newOwner.setName(netUser.getString("name"));
// newOwner.setImageURL(SERVER_URL+netUser.getString("imagePath"));
ownerDao.insert(newOwner); //插入本地数据库
//
// if (netFriends!=null && netFriends.size()>0){
// for (int i=0;i<netFriends.size();i++){
// JSONObject netFriend=(JSONObject) netFriends.get(i);
// String name=netFriend.getString("name");
// String imageUrl=SERVER_URL+netFriend.getString("imagePath");
// String username=netFriend.getString("username");
// int netId=netFriend.getInteger("id");
// Friend newFriend=new Friend(netId,username,name,imageUrl,newOwner.getNetId());
// friendDao.insert(newFriend);
// }
// }
owner = newOwner;
// ownerInfoSaveToPref();
//初始化WS链接
initWebSocket(owner.getNetId());
getUnReadMsg();
}else{
@ -218,6 +198,7 @@ public class LoginActivity extends BaseActivity {
getNewFriendRequest(senderId);
Log.d("记录","sender:"+senderId+" receiver:"+receiverId);
}
recommend();//执行推荐请求
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
@ -225,6 +206,31 @@ public class LoginActivity extends BaseActivity {
}
});
}
private void recommend() {
new Thread(new Runnable() {
@Override
public void run() {
try {
String url = LoginActivity.SERVER_URL + "/main-servlet?action=recommend&username="+username;
OkHttpUtil.asyGet(url, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
}
});
}catch (Exception e){
e.printStackTrace();
}
}
}).start();
}
private void getNewFriendRequest(final int senderId) {
new Thread(new Runnable() {
@Override

@ -37,7 +37,7 @@ public class CommunityFragment extends Fragment implements ViewPager.OnPageChang
private static ViewPager viewPager; //内导航的碎片的容器
private RadioGroup rgChannel=null; // 内导航由单选按钮组构成
private HorizontalScrollView hvChannel=null; //单选按钮组可滚动动
private String[] channelList = {"全部","经验"
private String[] channelList = {"全部","推荐","经验"
,"康复","扫雷","问答"}; //默认的内导航栏目
private InvitationPageFragmentAdapter adapter; //viewPager 的适配器
private PopupWindow popupWindow;

@ -43,6 +43,7 @@ public class IndexFragment extends Fragment {
private List<News> newsLists = new ArrayList<News>();
private RecyclerView recyclerView;
private NewsAdapter adapter;
public IndexFragment() {
// Required empty public constructor
}
@ -57,12 +58,12 @@ public class IndexFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_index, container, false);
View view = inflater.inflate(R.layout.fragment_index, container, false);
initRecNews();//初始化精选资讯的数据源
recyclerView=(RecyclerView) view.findViewById(R.id.recommend_news);//获取推荐资讯的布局
LinearLayoutManager layoutManager=new LinearLayoutManager(this.getActivity());
recyclerView = (RecyclerView) view.findViewById(R.id.recommend_news);//获取推荐资讯的布局
LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity());
recyclerView.setLayoutManager(layoutManager);
//initRecNews();//初始化数据源
@ -78,97 +79,103 @@ public class IndexFragment extends Fragment {
}
private void initClick(View view){
LinearLayout searchLinear=view.findViewById(R.id.search_linear);
LinearLayout blogPostLinear=view.findViewById(R.id.blog_post_linear);
LinearLayout questionPostLinear=view.findViewById(R.id.question_post_linear);
LinearLayout clockLinear=view.findViewById(R.id.clock_linear);
LinearLayout companyLinear=view.findViewById(R.id.company);
LinearLayout tenLinear=view.findViewById(R.id.ten);
LinearLayout governmentLinear=view.findViewById(R.id.government);
LinearLayout charity=view.findViewById(R.id.charity);
LinearLayout all=view.findViewById(R.id.all);
private void initClick(View view) {
LinearLayout searchLinear = view.findViewById(R.id.search_linear);
LinearLayout blogPostLinear = view.findViewById(R.id.blog_post_linear);
LinearLayout questionPostLinear = view.findViewById(R.id.question_post_linear);
LinearLayout clockLinear = view.findViewById(R.id.clock_linear);
LinearLayout companyLinear = view.findViewById(R.id.company);
LinearLayout tenLinear = view.findViewById(R.id.ten);
LinearLayout governmentLinear = view.findViewById(R.id.government);
LinearLayout charity = view.findViewById(R.id.charity);
LinearLayout all = view.findViewById(R.id.all);
//首页搜索的跳转
searchLinear.setOnClickListener(new View.OnClickListener(){
searchLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), NewsSearchActivity.class);
Intent intent = new Intent(getContext(), NewsSearchActivity.class);
startActivity(intent);
}
});
blogPostLinear.setOnClickListener(new View.OnClickListener(){
blogPostLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), SendInvitationActivity.class);
Intent intent = new Intent(getContext(), SendInvitationActivity.class);
startActivity(intent);
}
});
questionPostLinear.setOnClickListener(new View.OnClickListener(){
questionPostLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), SendQuestionActivity.class);
Intent intent = new Intent(getContext(), SendQuestionActivity.class);
startActivity(intent);
}
});
clockLinear.setOnClickListener(new View.OnClickListener(){
clockLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), MdctRmdActivity.class);
Intent intent = new Intent(getContext(), MdctRmdActivity.class);
startActivity(intent);
}
});
companyLinear.setOnClickListener(new View.OnClickListener(){
companyLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), InfoActivity.class);
int data=0;
intent.putExtra("info_type",data);
startActivity(intent); }
Intent intent = new Intent(getContext(), InfoActivity.class);
int data = 0;
intent.putExtra("info_type", data);
intent.putExtra("position",1);
startActivity(intent);
}
});
tenLinear.setOnClickListener(new View.OnClickListener(){
tenLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), InfoActivity.class);
int data=1;
intent.putExtra("info_type",data);
startActivity(intent); }
Intent intent = new Intent(getContext(), InfoActivity.class);
int data = 1;
intent.putExtra("info_type", data);
intent.putExtra("position",2);
startActivity(intent);
}
});
governmentLinear.setOnClickListener(new View.OnClickListener(){
governmentLinear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), InfoActivity.class);
int data=2;
intent.putExtra("info_type",data);
startActivity(intent); }
Intent intent = new Intent(getContext(), InfoActivity.class);
int data = 2;
intent.putExtra("info_type", data);
intent.putExtra("position",3);
startActivity(intent);
}
});
charity.setOnClickListener(new View.OnClickListener(){
charity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), InfoActivity.class);
int data=3;
intent.putExtra("info_type",data);
startActivity(intent); }
Intent intent = new Intent(getContext(), InfoActivity.class);
int data = 3;
intent.putExtra("info_type", data);
intent.putExtra("position",4);
startActivity(intent);
}
});
all.setOnClickListener(new View.OnClickListener(){
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent=new Intent(getContext(), InfoActivity.class);
int data=4;
intent.putExtra("info_type",data);
Intent intent = new Intent(getContext(), InfoActivity.class);
int data = 4;
intent.putExtra("info_type", data);
intent.putExtra("position",0);
startActivity(intent);
}
});
@ -177,17 +184,17 @@ public class IndexFragment extends Fragment {
}
private void initRecNews(){ //需要将资讯的信息从数据库里取出来,然后根据浏览量降序排列
Map<String,String> paramMap = new HashMap<String,String>();
private void initRecNews() { //需要将资讯的信息从数据库里取出来,然后根据浏览量降序排列
Map<String, String> paramMap = new HashMap<String, String>();
getInfoRequest(paramMap);
}
private void getInfoRequest(final Map paramMap){//Info请求
new Thread(new Runnable(){ //新开一个线程
private void getInfoRequest(final Map paramMap) {//Info请求
new Thread(new Runnable() { //新开一个线程
@Override
public void run() {
try{
String url= BaseActivity.SERVER_URL+"/news-servlet?action=get-infoIndex";//这里对应Eclipse的Servlet的
try {
String url = BaseActivity.SERVER_URL + "/news-servlet?action=get-infoIndex";//这里对应Eclipse的Servlet的
OkHttpUtil.asyPost(url, paramMap, new Callback() { //异步post
@Override
public void onFailure(Call call, IOException e) {
@ -197,30 +204,31 @@ public class IndexFragment extends Fragment {
@Override
public void onResponse(Call call, Response response) throws IOException {
String jsonStr = response.body().string();//这里就调用InfoResponse响应
Log.e("首页Info的json",jsonStr);
Log.e("首页Info的json", jsonStr);
getInfoResponse(jsonStr);
}
});
}catch (Exception e){
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
private void getInfoResponse(final String jsonStr){//这里是info响应
getActivity().runOnUiThread(new Runnable(){ //新开一个线程
private void getInfoResponse(final String jsonStr) {//这里是info响应
getActivity().runOnUiThread(new Runnable() { //新开一个线程
@Override
public void run() {
Gson gson = new Gson(); // 使用 gson 库解析 JSON 数据
// 创建一个 TypeToken 的匿名子类对象,并调用对象的 getType()方法
Type listType = new TypeToken<List<News>>() {}.getType();
Type listType = new TypeToken<List<News>>() {
}.getType();
// 把获取到的信息集合存到 newsList 中
newsLists = gson.fromJson(jsonStr, listType);
Log.e("jsonStr",jsonStr);
Log.e("jsonStr", jsonStr);
Log.e("object", String.valueOf(newsLists));
Log.e("newsLists最后",String.valueOf(newsLists));
Log.e("newsLists最后", String.valueOf(newsLists));
newsLists = gson.fromJson(jsonStr, listType);
adapter.setRecnewsList(newsLists);//这里设置数据源
recyclerView.setAdapter(adapter);
@ -242,7 +250,7 @@ public class IndexFragment extends Fragment {
isPause = false;
//刷新页面的显示
//得到请求,然后刷新页面
Map<String,String> paramMap = new HashMap<String,String>();
Map<String, String> paramMap = new HashMap<String, String>();
getInfoRequest(paramMap);
adapter.setRecnewsList(newsLists);//这里设置数据源
recyclerView.setAdapter(adapter);//更新显示

@ -89,19 +89,6 @@ public class InfoChannelFragment extends Fragment {
view = inflater.inflate(R.layout.recyclerview,container,false);
// initAllNews();//所有new组
//全部,公司,红十字,政府,慈善
// comAdapter=new NewsAdapter();
// comAdapter.setRecnewsList(comNews);
//
// redAdapter=new NewsAdapter();
// redAdapter.setRecnewsList(redNews);
//
// govAdapter=new NewsAdapter();
// govAdapter.setRecnewsList(govNews);
//
// chaAdapter=new NewsAdapter();
// chaAdapter.setRecnewsList(chaNews);
if (infoCategoryTitleNum == 0) {//这里是全部的那个内导航
view = inflater.inflate(R.layout.recyclerview,container,false);

@ -32,9 +32,14 @@ public class InfoFragment extends Fragment implements ViewPager.OnPageChangeLis
static List<List<News>> resourceList=new ArrayList<>();
static List<News> newsList=new ArrayList<>();
private int position;
public InfoFragment() {
// Required empty public constructor
}
public InfoFragment(int position){
this.position = position;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
@ -43,11 +48,10 @@ public class InfoFragment extends Fragment implements ViewPager.OnPageChangeLis
view = inflater.inflate(R.layout.fragment_info, container, false);//显示碎片的布局
viewPager=(ViewPager)view.findViewById(R.id.vpNewsListInfo);//加了这,后面就闪退了
initViewPager(); //设置 ViewPager
rgChannel=(RadioGroup)view.findViewById(R.id.rgChannel20);
hvChannel=(HorizontalScrollView)view.findViewById(R.id.hvChannel20);
initTab(inflater);//初始化内导航标签
setTab(position);
rgChannel.setOnCheckedChangeListener( //单选按钮的监听事件
new RadioGroup.OnCheckedChangeListener() {
@Override
@ -69,7 +73,6 @@ public class InfoFragment extends Fragment implements ViewPager.OnPageChangeLis
RadioGroup.LayoutParams params = new
RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
RadioGroup.LayoutParams.WRAP_CONTENT);
rgChannel.addView(rb,params);
}
rgChannel.check(0);
@ -78,12 +81,11 @@ public class InfoFragment extends Fragment implements ViewPager.OnPageChangeLis
private void initViewPager() {
FragmentManager fragmentManager = super.getActivity().getSupportFragmentManager();
adapter=new InfoPageFragmentAdapter(fragmentManager, channelList);
//参数 channelList 将被适配器用来在动态切换碎片的时候实时创建碎片
// 设置 ViewPager 的适配器
// 设置 ViewPager 的适配器
viewPager.setAdapter(adapter);
viewPager.setOffscreenPageLimit(1); //viewpager是默认预加载下一页的界面的
// viewpager提供了一个设置预加载页面数量的方法,让ViewPager多缓存一个页面
viewPager.setCurrentItem(0); //设置显示第1个碎片
viewPager.setCurrentItem(position); //设置显示第1个碎片
viewPager.addOnPageChangeListener((ViewPager.OnPageChangeListener) this);//设置 ViewPager 的切换监听
}

@ -6,7 +6,6 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
@ -37,13 +36,10 @@ import okhttp3.Response;
public class InvitationChannelFragment extends Fragment {
private static final String ARG_CATEGORY_TITLE = "category_title";
private static final String ARG_CATEGORY_TITLE_NUM = "category_title_num";
public static List<List<Blog>> resourceList = new ArrayList<>();
private List<Question> allQuestion = new ArrayList<>();
private List<Blog> allBlog = new ArrayList<>();
private String invitationCategoryTitle = "Default";
private int invitationCategoryTitleNum = 0;
private TextView mTitleField;
static List<Blog> blogList = new ArrayList<>();
private List<Blog> blogLists = new ArrayList<>();
private List<Blog> expBlog = new ArrayList<>();
private List<Blog> badBlog = new ArrayList<>();
@ -58,12 +54,11 @@ public class InvitationChannelFragment extends Fragment {
private RecyclerView expRecyclerView;
private RecyclerView recRecyclerView;
private RecyclerView badRecyclerView;
private boolean isPause = false;
private final String[] channelList = {"全部", "经验"
, "康复", "扫雷", "问答"};
// int temp=0;
private BlogAdapter recommendAdapter = new BlogAdapter();
private List<Blog> recommendBlog = new ArrayList<>();
private RecyclerView recommendRecyclerView;
private boolean isPause = false;
public InvitationChannelFragment() {
// Required empty public constructor
}
@ -74,9 +69,6 @@ public class InvitationChannelFragment extends Fragment {
args.putString(ARG_CATEGORY_TITLE, invitationCategoryTitle);
args.putInt(ARG_CATEGORY_TITLE_NUM, pos);
fragment.setArguments(args);
// blogList=getBlogList();
// resourceList=getResourceList();
// Log.e("newInstance","newInstance");
return fragment;
}
@ -86,7 +78,6 @@ public class InvitationChannelFragment extends Fragment {
try {
invitationCategoryTitle = (String) getArguments().getString(ARG_CATEGORY_TITLE);
invitationCategoryTitleNum = getArguments().getInt(ARG_CATEGORY_TITLE_NUM);
// Log.e("onCreate","onCreate");
} catch (java.lang.NullPointerException e) {
System.out.println("TesFragment getArg error!");
}
@ -98,8 +89,6 @@ public class InvitationChannelFragment extends Fragment {
Bundle savedInstanceState) {
View view;
view = inflater.inflate(R.layout.recyclerview, container, false);
// initAllBlog();// 所有blog组
// initAllBlogList(); //第一栏:全部项
questionAdapter = new QuestionAdapter();
questionAdapter.setContext(getContext());
questionAdapter.setQuestionList(allQuestion);
@ -110,6 +99,9 @@ public class InvitationChannelFragment extends Fragment {
recAdapter = new BlogAdapter();
recAdapter.setRecnewsList(recBlog);
recommendAdapter = new BlogAdapter(recommendBlog);
if (invitationCategoryTitleNum == 0) {
view = inflater.inflate(R.layout.recyclerview, container, false);
allRecyclerView = (RecyclerView) view.findViewById(R.id.list_community);
@ -117,23 +109,16 @@ public class InvitationChannelFragment extends Fragment {
allRecyclerView.setLayoutManager(layoutManager);
BlogAdapter allAdapter = new BlogAdapter(allBlog);
allRecyclerView.setAdapter(allAdapter);
// initAllBlogList();
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"全部"});
getAllBlogListRequest(paramMap);
// allAdapter.notifyDataSetChanged();
} else if (invitationCategoryTitleNum == 4) {
} else if (invitationCategoryTitleNum == 5) {
questionRecyclerView = (RecyclerView) view.findViewById(R.id.list_community);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
questionRecyclerView.setLayoutManager(layoutManager);
questionRecyclerView.setAdapter(questionAdapter);
// Map<String, String[]> paramMap = new HashMap<>();
// paramMap.put("channelList", new String[]{"问答"});
getQuestionListRequest();
// Log.e("应该为4问答", String.valueOf(invitationCategoryTitleNum));
} else if (invitationCategoryTitleNum == 2) {
} else if (invitationCategoryTitleNum == 3) {
recRecyclerView = (RecyclerView) view.findViewById(R.id.list_community);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recRecyclerView.setLayoutManager(layoutManager);
@ -141,9 +126,7 @@ public class InvitationChannelFragment extends Fragment {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"康复"});
getRecInvitationRequest(paramMap);
// Log.e("应该为2康复", String.valueOf(invitationCategoryTitleNum));
// Log.e("应该为2康复数据",String.valueOf(recBlog));
} else if (invitationCategoryTitleNum == 3) {
} else if (invitationCategoryTitleNum == 4) {
badRecyclerView = (RecyclerView) view.findViewById(R.id.list_community);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
badRecyclerView.setLayoutManager(layoutManager);
@ -151,8 +134,7 @@ public class InvitationChannelFragment extends Fragment {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"扫雷"});
getBadListRequest(paramMap);
// Log.e("应该为3扫雷", String.valueOf(invitationCategoryTitleNum));
} else if (invitationCategoryTitleNum == 1) {
} else if (invitationCategoryTitleNum == 2) {
expRecyclerView = (RecyclerView) view.findViewById(R.id.list_community);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
expRecyclerView.setLayoutManager(layoutManager);
@ -160,17 +142,50 @@ public class InvitationChannelFragment extends Fragment {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"经验"});
getExpListRequest(paramMap);
} else if(invitationCategoryTitleNum == 1){
recommendRecyclerView = view.findViewById(R.id.list_community);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recommendRecyclerView.setLayoutManager(layoutManager);
recommendRecyclerView.setAdapter(recommendAdapter);
getRecommendBlog();
}
// temp=temp+1;
return view;
}
private void initAllBlogList() {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"全部"});
getAllBlogListRequest(paramMap);
getQuestionListRequest();
private void getRecommendBlog() {
new Thread(new Runnable() {
@Override
public void run() {
try {
String url = BaseActivity.SERVER_URL + "/blog-servlet?action=getRecommendBlog&iduser="+BaseActivity.owner.getNetId();
OkHttpUtil.asyGet(url, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String jsonStr = response.body().string();
Log.e("帖子推荐",jsonStr);
Gson gson = new Gson();
recommendBlog = gson.fromJson(jsonStr, new TypeToken<List<Blog>>(){}.getType());
getActivity().runOnUiThread(new Runnable(){
@Override
public void run() {
recommendAdapter = new BlogAdapter(recommendBlog);
recommendRecyclerView.setAdapter(recommendAdapter);
}
});
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
private void getQuestionListRequest() {
@ -284,46 +299,16 @@ public class InvitationChannelFragment extends Fragment {
Gson gson = new Gson();
Type listType = new TypeToken<List<List<Blog>>>() {
}.getType();
// Log.e("AllBlogList:jsonStr",jsonStr);
List<Blog> lists = gson.fromJson(jsonStr, listType);
// List<Blog> allBlogList=new ArrayList<>();
lists = (List<Blog>) lists.get(0);
allBlog = lists;
// Log.e("allBlog的数据",String.valueOf(lists));
BlogAdapter allAdapter = new BlogAdapter(allBlog);
allRecyclerView.setAdapter(allAdapter);
//
// if(allAdapter==null)
// Log.e("allAdapter","allAdapter is null");
// if(allRecyclerView==null)
// Log.e("allRecyclerView1","allRecyclerView1 is null");
// allRecyclerView= (RecyclerView) (getActivity().getLayoutInflater().inflate(R.layout.recyclerview, null)).findViewById(R.id.list_community);
// if(allRecyclerView==null)
// Log.e("allRecyclerView2","allRecyclerView2 is null");
// allRecyclerView.setAdapter(allAdapter);
//// InvitationChannelFragment.allBlog=allBlogList;
}
});
}
private void initAllBlog() {
Map<String, String[]> paramMap_bad = new HashMap<String, String[]>();
Map<String, String[]> paramMap_rec = new HashMap<String, String[]>();
Map<String, String[]> paramMap_exp = new HashMap<String, String[]>();
Map<String, String[]> paramMap_all = new HashMap<String, String[]>();
Map<String, String[]> paramMap = new HashMap<String, String[]>();
// paramMap.put("channelList",java.util.Arrays.copyOf(channelList,1));
paramMap_rec.put("channelList", new String[]{"康复"});
paramMap_bad.put("channelList", new String[]{"扫雷"});
paramMap_exp.put("channelList", new String[]{"经验"});
getExpListRequest(paramMap_exp);
getBadListRequest(paramMap_bad);
getRecInvitationRequest(paramMap_rec);
}
private void getRecInvitationRequest(final Map paramMap) {
new Thread(new Runnable() {
@Override
@ -333,7 +318,6 @@ public class InvitationChannelFragment extends Fragment {
OkHttpUtil.asyPost(url, paramMap, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
@ -349,53 +333,21 @@ public class InvitationChannelFragment extends Fragment {
}).start();
}
private void getInvitationRequest(final Map paramMap, final Map paramMap_bad,
final Map paramMap_rec, final Map paramMap_exp) {
new Thread(new Runnable() {
@Override
public void run() {
try {
String url1 = BaseActivity.SERVER_URL + "/blog-servlet?action=get-invitation";
String url2 = BaseActivity.SERVER_URL + "/question-servlet?action=get-allQuestion";
// String jsonStr1= OkHttpUtil.synPost(url1, paramMap);换为异步
// String jsonStr2= OkHttpUtil.synPost(url2, null);换为异步
// String jsonStr_rec= OkHttpUtil.synPost(url1, paramMap_rec);
// String jsonStr_bad= OkHttpUtil.synPost(url1, paramMap_bad);
// String jsonStr_exp= OkHttpUtil.synPost(url1, paramMap_exp);
// Log.e("getInvitationRequest","getInvitationRequest");
// getInvitationResponse(jsonStr1);
// getQuestionResponse(jsonStr2);
// getRecInvitationResponse(jsonStr_rec);
// getBadInvitationResponse(jsonStr_bad);
// getExpInvitationResponse(jsonStr_exp);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
private void getBadInvitationResponse(final String jsonStr) {
getActivity().runOnUiThread(new Runnable() {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void run() {
// Log.e("jsonStr",jsonStr);
Gson gson = new Gson(); // 使用 gson 库解析 JSON 数据
// 创建一个 TypeToken 的匿名子类对象,并调用对象的 getType()方法
Type listType = new TypeToken<List<List<Blog>>>() {
}.getType();
// Log.e("jsonStr",jsonStr);
List<List<Blog>> lists = gson.fromJson(jsonStr, listType);
List<Blog> badBlogList = new ArrayList<>();
badBlogList = (List<Blog>) lists.get(0);
badBlog = badBlogList;
BlogAdapter badAdapter = new BlogAdapter();
badAdapter.setRecnewsList(badBlog);
badRecyclerView.setAdapter(badAdapter);
// Log.e("badBlog",String.valueOf(badBlogList));
}
});
@ -406,12 +358,9 @@ public class InvitationChannelFragment extends Fragment {
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void run() {
// Log.e("jsonStr",jsonStr);
Gson gson = new Gson(); // 使用 gson 库解析 JSON 数据
// 创建一个 TypeToken 的匿名子类对象,并调用对象的 getType()方法
Type listType = new TypeToken<List<List<Blog>>>() {
}.getType();
// Log.e("jsonStr",jsonStr);
List<List<Blog>> lists = gson.fromJson(jsonStr, listType);
List<Blog> recBlogList = new ArrayList<>();
@ -420,7 +369,6 @@ public class InvitationChannelFragment extends Fragment {
BlogAdapter recAdapter = new BlogAdapter();
recAdapter.setRecnewsList(recBlog);
recRecyclerView.setAdapter(recAdapter);
// Log.e("recBlog的数据",String.valueOf(recBlogList));
}
});
}
@ -432,16 +380,13 @@ public class InvitationChannelFragment extends Fragment {
public void run() {
Log.e("jsonStr", jsonStr);
Gson gson = new Gson(); // 使用 gson 库解析 JSON 数据
// 创建一个 TypeToken 的匿名子类对象,并调用对象的 getType()方法
Type listType = new TypeToken<List<List<Blog>>>() {
}.getType();
// Log.e("jsonStr",jsonStr);
List<List<Blog>> lists = gson.fromJson(jsonStr, listType);
List<Blog> expBlogList = new ArrayList<>();
expBlogList = (List<Blog>) lists.get(0);
expBlog = expBlogList;
// Log.e("expBlog的数据",String.valueOf(expBlogList));
BlogAdapter expAdapter = new BlogAdapter();
expAdapter.setRecnewsList(expBlog);
expRecyclerView.setAdapter(expAdapter);
@ -455,8 +400,6 @@ public class InvitationChannelFragment extends Fragment {
@Override
public void run() {
Gson gson = new Gson(); // 使用 gson 库解析 JSON 数据
// 创建一个 TypeToken 的匿名子类对象,并调用对象的 getType()方法
// Log.e("questionListStr",jsonStr);
Type listType = new TypeToken<List<Question>>() {
}.getType();
List<Question> questionList = gson.fromJson(jsonStr, listType);
@ -486,32 +429,36 @@ public class InvitationChannelFragment extends Fragment {
getAllBlogListRequest(paramMap);
BlogAdapter allAdapter = new BlogAdapter(allBlog);
allRecyclerView.setAdapter(allAdapter);
}else if(invitationCategoryTitleNum == 4) {
} else if (invitationCategoryTitleNum == 5) {
getQuestionListRequest();
QuestionAdapter questionAdapter = new QuestionAdapter(allQuestion, getContext());
questionAdapter.setContext(getContext());
questionRecyclerView.setAdapter(questionAdapter);
}else if(invitationCategoryTitleNum == 2) {
} else if (invitationCategoryTitleNum == 3) {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"康复"});
getRecInvitationRequest(paramMap);
BlogAdapter recAdapter = new BlogAdapter(recBlog);
recRecyclerView.setAdapter(recAdapter);
}else if(invitationCategoryTitleNum == 3) {
} else if (invitationCategoryTitleNum == 4) {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"扫雷"});
getBadListRequest(paramMap);
BlogAdapter badAdapter = new BlogAdapter(badBlog);
badRecyclerView.setAdapter(badAdapter);
}else if(invitationCategoryTitleNum == 1) {
} else if (invitationCategoryTitleNum == 2) {
Map<String, String[]> paramMap = new HashMap<String, String[]>();
paramMap = new HashMap<String, String[]>();
paramMap.put("channelList", new String[]{"经验"});
getExpListRequest(paramMap);
BlogAdapter expAdapter = new BlogAdapter(expBlog);
expRecyclerView.setAdapter(expAdapter);
}else if(invitationCategoryTitleNum == 1){
getRecommendBlog();
BlogAdapter recommendAdapter = new BlogAdapter();
recommendRecyclerView.setAdapter(recommendAdapter);
}
}

@ -8,11 +8,14 @@ import android.widget.Toast;
import androidx.annotation.RequiresApi;
import com.example.leudaemialikeme.Activity.BaseActivity;
import com.example.leudaemialikeme.Activity.ChatActivity;
import com.example.leudaemialikeme.Activity.MainActivity;
import com.example.leudaemialikeme.Controller.ActivityController;
import com.example.leudaemialikeme.Dao.FriendDao;
import com.example.leudaemialikeme.Fragment.MessageChannelFragment;
import com.example.leudaemialikeme.Fragment.MessageFragment;
import com.example.leudaemialikeme.Model.Friend;
import com.example.leudaemialikeme.Model.Message;
import com.example.leudaemialikeme.R;
import com.google.gson.Gson;
@ -38,6 +41,13 @@ public class WebSocketClient extends org.java_websocket.client.WebSocketClient {
public static final int MSG_IMAGE=2;
public static final int MSG_SYSTEM=3;
private MainActivity mainActivity;
private String content;
private int messageType;
private int receiverId;
private int senderId;
private long createTime;
private String username;
public WebSocketClient(URI serverURI){
@ -57,11 +67,12 @@ public class WebSocketClient extends org.java_websocket.client.WebSocketClient {
Log.d("WS",message+" onMessage()回调");
//提取消息
Map<String, String> jsonMap = gson.fromJson(message, new TypeToken<Map<String, String>>() {}.getType());
String content = jsonMap.get("content");
int messageType = Integer.parseInt(Objects.requireNonNull(jsonMap.get("messageType")));
int receiverId = Integer.parseInt(Objects.requireNonNull(jsonMap.get("receiverNetId")));
int senderId = Integer.parseInt(Objects.requireNonNull(jsonMap.get("senderNetId")));
long createTime = Timestamp.valueOf(jsonMap.get("createTime")).getTime();
content = jsonMap.get("content");
messageType = Integer.parseInt(Objects.requireNonNull(jsonMap.get("messageType")));
receiverId = Integer.parseInt(Objects.requireNonNull(jsonMap.get("receiverNetId")));
senderId = Integer.parseInt(Objects.requireNonNull(jsonMap.get("senderNetId")));
createTime = Timestamp.valueOf(jsonMap.get("createTime")).getTime();
username = jsonMap.get("username");
Message newMessage=new Message(senderId,receiverId,messageType, content, createTime);
Log.d("刷新","获取到对面发送的消息");
//获取当前活动对象
@ -128,13 +139,12 @@ public class WebSocketClient extends org.java_websocket.client.WebSocketClient {
currentActivity.runOnUiThread(new Runnable() {
@Override
public void run() {
FriendDao friendDao = new FriendDao();
if(friendDao.findByNetId(senderId, BaseActivity.owner.getNetId())==null){
Friend friend = new Friend(senderId, username, BaseActivity.owner.getNetId());
friendDao.insert(friend);
}
mainActivity = (MainActivity) currentActivity;
// FragmentManager fm = mainActivity.getSupportFragmentManager();
// Log.d("刷新","当前碎片管理:"+fm.toString());
// MessageChannelFragment mcf = (MessageChannelFragment) fm.findFragmentById(R.id.fragment_message_channel);
// Log.d("刷新","当前所在碎片:"+mcf);
// MessageChannelFragment msgcf = (MessageChannelFragment) mainActivity.getSupportFragmentManager().findFragmentById(R.id.fragment_message_channel);
// MessageChannelFragment mcf = new MessageChannelFragment();
MessageFragment mf = (MessageFragment) mainActivity.getFragment(2);
MessageChannelFragment mcf = mf.getAdapter().getMcf(0);
Log.d("当前碎片的名字滑动页:", mcf.getMessageCategoryTitle());

Loading…
Cancel
Save