From 086fc81423e4adeffba1f2cbd5cf351a52f407d9 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Fri, 18 Jun 2021 18:53:01 +0800
Subject: [PATCH 1/9] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=B8=96=E5=AD=90?=
=?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/src/main/AndroidManifest.xml | 1 +
.../moyv/schoolbbs/service/MainService.java | 43 +++-
.../service/PostsManagerService.java | 8 +
.../schoolbbs/service/UserInfoService.java | 1 -
.../ui/activity/ManagerActivity.java | 216 ++++++++++++++++++
.../schoolbbs/ui/adapter/DataAdapter.java | 182 +++++++++------
.../schoolbbs/ui/adapter/ManagerAdapter.java | 71 ++++++
.../schoolbbs/ui/fragment/HomeFragment.java | 5 +
.../schoolbbs/ui/fragment/MeFragment.java | 21 ++
.../main/res/layout/activity_post_manager.xml | 19 ++
.../res/layout/activity_post_manager_item.xml | 123 ++++++++++
.../main/res/layout/fragment_main_item.xml | 41 ++--
app/src/main/res/values/colors.xml | 21 ++
13 files changed, 661 insertions(+), 91 deletions(-)
create mode 100644 app/src/main/java/com/moyv/schoolbbs/service/PostsManagerService.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/adapter/ManagerAdapter.java
create mode 100644 app/src/main/res/layout/activity_post_manager.xml
create mode 100644 app/src/main/res/layout/activity_post_manager_item.xml
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 6cce6d9..34fb9de 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -32,6 +32,7 @@
+
\ No newline at end of file
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/MainService.java b/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
index 40f8861..2d53e8e 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
@@ -48,12 +48,52 @@ public class MainService {
try{
obj.put("star",star);
obj.put("end",end);
+ Log.e(TAG, "getPost: "+star );
+ Log.e(TAG, "getPost: "+end );
}catch (JSONException e){
Log.d(TAG, "getPost: json添加失败");
}
FormBody formBody=new FormBody.Builder()
- .add("account","5554")
+ .add("result",obj.toString())
+ .build();
+// 发送请求操作
+ Request request=new Request.Builder()
+ .post(formBody)
+ .url(url)
+ .build();
+ okHttpClient.newCall(request).enqueue(new Callback(){
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ System.out.println("mainService.getPost:获取main的响应对象失败");
+// 发送404到主页
+ handler.sendMessage(handler.obtainMessage(404));
+
+ }
+
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ System.out.println("mainService.getPost:拿到main的响应对象");
+ String responseData=response.body().string();
+ reModel =parseReModel(responseData);
+ handler.sendMessage(handler.obtainMessage(0, reModel));
+ }
+ });
+ }
+ public void getUserPosts(int account,int star,int end){
+ url=MAIN_URL;
+ OkHttpClient okHttpClient=createClient();
+// 请求体
+ JSONObject obj=new JSONObject();
+ try{
+ obj.put("star",star);
+ obj.put("end",end);
+ }catch (JSONException e){
+ Log.d(TAG, "getPost: json添加失败");
+ }
+
+ FormBody formBody=new FormBody.Builder()
+ .add("account",String.valueOf(account))
.add("result",obj.toString())
.build();
// 发送请求操作
@@ -80,6 +120,7 @@ public class MainService {
}
});
}
+
public void getCmt(int postId){
url="http://10.0.2.2:8080/bbs_servlet/main";
OkHttpClient okHttpClient=createClient();
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/PostsManagerService.java b/app/src/main/java/com/moyv/schoolbbs/service/PostsManagerService.java
new file mode 100644
index 0000000..d187668
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/service/PostsManagerService.java
@@ -0,0 +1,8 @@
+package com.moyv.schoolbbs.service;
+
+/**
+ * @author moyv
+ */
+public class PostsManagerService {
+
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/UserInfoService.java b/app/src/main/java/com/moyv/schoolbbs/service/UserInfoService.java
index a492810..b52b2a7 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/UserInfoService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/UserInfoService.java
@@ -30,7 +30,6 @@ public class UserInfoService {
// 请求体
FormBody formBody=new FormBody.Builder()
.add("account",String.valueOf(account))
- .add("token",TOKEN)
.build();
// 发送请求操作
Request request=new Request.Builder()
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
new file mode 100644
index 0000000..13bf9f8
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
@@ -0,0 +1,216 @@
+package com.moyv.schoolbbs.ui.activity;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import android.widget.Toast;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
+
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.bean.ReModel;
+import com.moyv.schoolbbs.pojo.Item;
+import com.moyv.schoolbbs.service.MainService;
+import com.moyv.schoolbbs.ui.adapter.DataAdapter;
+import com.moyv.schoolbbs.ui.config.UIHelper;
+import com.moyv.schoolbbs.ui.listener.EndlessRecyclerOnScrollListener;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static com.moyv.schoolbbs.base.Global.init;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
+import static com.moyv.schoolbbs.ui.adapter.DataAdapter.MANAGER;
+
+/**
+ * @author moyv
+ */
+public class ManagerActivity extends AppCompatActivity {
+ private RecyclerView recyclerView;
+ private static final int SUCCESS = 0;
+ private static final int FALL = 404;
+ private DataAdapter adapter;;
+ private FloatingActionButton btnFlt;
+ private SwipeRefreshLayout swiperefreshlayout;
+ private Context mContext;
+ private int start, end;
+ private List lists;
+ // 帖子总数
+ private int count;
+ @Override
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_post_manager);
+ start = 0;
+ end = 5;
+ mContext = this;
+
+ recyclerView =findViewById(R.id.manager_recycler_view);
+
+ init(mContext);
+
+ swiperefreshlayout =findViewById(R.id.swiperefreshlayout);
+
+ swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+ @Override
+ public void onRefresh() {
+ Log.d("zttjiangqq", "invoke onRefresh...");
+ start=0;
+ end=5;
+ new MainService(handler1).getUserPosts(ACCOUNT,start,end);
+ }
+ }
+
+ );
+ // 设置滑动监听器
+ recyclerView.addOnScrollListener(new EndlessRecyclerOnScrollListener() {
+ @Override
+ public void onLoadMore() {
+ adapter.setLoadState(adapter.LOADING);
+ if(endcount){
+ start=end+1;
+ end=count;
+ }else{
+ start=end+1;
+ end=start+4;
+ }
+
+ new MainService(handler2).getPost(start,end);
+ }else{
+ // 显示加载到底的提示
+ adapter.setLoadState(adapter.LOADING_END);
+ }
+
+
+ }
+ });
+ new MainService(handler).getUserPosts(ACCOUNT,start, end);
+// 加载帖子数据
+ UIHelper.showDialogForLoading(mContext, "初始化数据中");
+ }
+
+ // 数据初始化
+ Handler handler = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(Message msg) {
+ UIHelper.closeDialog(mContext);
+ List- items=new ArrayList<>();
+ switch (msg.what) {
+ case SUCCESS:
+ Toast.makeText(mContext, "成功获取数据", Toast.LENGTH_SHORT).show();
+ ReModel reModel=(ReModel) msg.obj;
+ lists = reModel.getMain();
+ count=reModel.getCount();
+ System.out.println(count);
+
+ for(ReModel.Main list:lists){
+ Item item=new Item();
+ item.setMain(list);
+ System.out.println(list.getUserInfo().getIntroduction());
+ List
urls=new ArrayList<>();
+ for(int i=0;i items=new ArrayList<>();
+ for(ReModel.Main list:lists){
+ Item item=new Item();
+ item.setMain(list);
+ List urls=new ArrayList<>();
+ for(int i=0;i addLists = reModel.getMain();
+ List- items=new ArrayList<>();
+ for(ReModel.Main list:addLists){
+ Item item=new Item();
+ item.setMain(list);
+ List
urls=new ArrayList<>();
+ for(int i=0;i {
public Context context;
- private List- postList;
+ private List
- postList;
private String commentStr;
private List
comments;
private List cmtName;
private int cmtCount;
- private List cbStars=new ArrayList<>();
+ private List cbStars = new ArrayList<>();
+ // type有两个值,区别主页显示和管理显示
+ public static int MAIN = 202;
+ public static int MANAGER = 303;
+ public int type;
+
// 普通布局
private final int TYPE_ITEM = 1;
@@ -68,26 +73,27 @@ public class DataAdapter extends RecyclerView.Adapter {
// 加载到底
public final int LOADING_END = 3;
-// 防止重复加载
+ // 防止重复加载
List positions = new ArrayList<>();
- public DataAdapter(Context context, List- postList){
- this.context=context;
- this.postList=postList;
+ public DataAdapter(Context context, List
- postList) {
+ this.context = context;
+ this.postList = postList;
}
+
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
// 为每个Item inflater出一个View
// 通过判断显示类型,来创建不同的View
- if(viewType==TYPE_ITEM){
- View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_main_item,parent,false);
+ if (viewType == TYPE_ITEM) {
+ View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_main_item, parent, false);
return new ViewHolder(view);
- }else if(viewType==TYPE_FOOTER){
+ } else if (viewType == TYPE_FOOTER) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.loading_more, parent, false);
return new FootViewHolder(view);
- }else {
+ } else {
return null;
}
@@ -95,31 +101,43 @@ public class DataAdapter extends RecyclerView.Adapter
{
@Override
public int getItemCount() {
- return postList.size()+1;
+ return postList.size() + 1;
}
-// 这个方法主要用于适配渲染数据到View中
+ // 这个方法主要用于适配渲染数据到View中
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
- if(holder instanceof ViewHolder){
+ if (holder instanceof ViewHolder) {
Log.d(TAG, "onBindViewHolder: ViewHolder");
- Log.d(TAG, "onBindViewHolder: position:"+position);
+ Log.d(TAG, "onBindViewHolder: position:" + position);
- ViewHolder recyclerViewHolder =(ViewHolder) holder;
- cmtCount=0;
+ ViewHolder recyclerViewHolder = (ViewHolder) holder;
+ cmtCount = 0;
String name = postList.get(position).getMain().getUserInfo().getName();
String introduction = postList.get(position).getMain().getUserInfo().getIntroduction() == null ? "" : postList.get(position).getMain().getUserInfo().getIntroduction();
String Date = postList.get(position).getMain().getPost().getProTimer();
- String content=postList.get(position).getMain().getPost().getPostContent();
+ String content = postList.get(position).getMain().getPost().getPostContent();
recyclerViewHolder.tvUser.setText(name);
recyclerViewHolder.tvIntro.setText(introduction);
- //显示发表时间
+
+// 判断是否有删除键
+ if (type == MANAGER) {
+ recyclerViewHolder.tvDelete.setVisibility(View.VISIBLE);
+ recyclerViewHolder.tvDelete.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ removeData(position);
+ }
+ });
+ }
+
+// 显示发表时间
recyclerViewHolder.tvDate.setText(Date);
// 帖子文字内容
- if(content.length()==0){
+ if (content.length() == 0) {
recyclerViewHolder.tvCnt.setVisibility(View.GONE);
- }else {
+ } else {
recyclerViewHolder.tvCnt.setVisibility(View.VISIBLE);
recyclerViewHolder.tvCnt.setText(content);
}
@@ -146,7 +164,7 @@ public class DataAdapter extends RecyclerView.Adapter {
@Override
public void onClick(View v) {
//判断是否登录
- if(LOGIN){
+ if (LOGIN) {
//取出评论
commentStr = recyclerViewHolder.etCmt.getText().toString().trim();
// 评论发布
@@ -184,8 +202,8 @@ public class DataAdapter extends RecyclerView.Adapter {
// 隐藏软键盘
KeyboardUtils.hideKeyboard(context);
}
- }else{
- Toast.makeText(context,"请先登录",Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(context, "请先登录", Toast.LENGTH_SHORT).show();
}
}
@@ -194,7 +212,7 @@ public class DataAdapter extends RecyclerView.Adapter {
cmtName = new ArrayList<>();
removeCmt(recyclerViewHolder.lyCmt);
for (Comment comment : comments) {
- addCmt(comment.getCmtName(),comment.getCommentContent(),recyclerViewHolder.lyCmt);
+ addCmt(comment.getCmtName(), comment.getCommentContent(), recyclerViewHolder.lyCmt);
}
@@ -203,15 +221,15 @@ public class DataAdapter extends RecyclerView.Adapter {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// 只有手动点击才会执行点赞事件
- if(!buttonView.isPressed()){
+ if (!buttonView.isPressed()) {
return;
}
// 判断是否已经登录
- if(LOGIN){
- Handler handler=new Handler(new Handler.Callback() {
+ if (LOGIN) {
+ Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
Log.d(TAG, "handleMessage: 点赞成功");
recyclerViewHolder.btnStar.setChecked(true);
@@ -222,15 +240,15 @@ public class DataAdapter extends RecyclerView.Adapter {
break;
case 302:
recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- Toast.makeText(context,"已经点过赞了",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "已经点过赞了", Toast.LENGTH_SHORT).show();
break;
case 404:
recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- Toast.makeText(context,"网络连接失败",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "网络连接失败", Toast.LENGTH_SHORT).show();
break;
case 500:
recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- Toast.makeText(context,"操作失败",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "操作失败", Toast.LENGTH_SHORT).show();
break;
default:
recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
@@ -239,12 +257,12 @@ public class DataAdapter extends RecyclerView.Adapter {
return false;
}
});
- if(isChecked){
- StarService starService=new StarService();
+ if (isChecked) {
+ StarService starService = new StarService();
// starService.pushStar(postList.get(position).getMain().getPost().getPostId(),handler,1);
Log.e(TAG, "onCheckedChanged: 点赞事件");
- }else{
- StarService starService=new StarService();
+ } else {
+ StarService starService = new StarService();
// starService.pushStar(postList.get(position).getMain().getPost().getPostId(),handler,-1);
Log.e(TAG, "onCheckedChanged: 取消点赞事件");
}
@@ -253,35 +271,35 @@ public class DataAdapter extends RecyclerView.Adapter {
}
});
- List stars=postList.get(position).getMain().getStars();
- int starCount=stars.size();
+ List stars = postList.get(position).getMain().getStars();
+ int starCount = stars.size();
System.out.println(starCount);
- String starInfo="";
- for(int i=0;i {
// 图片显示
GridLayoutManager layoutManager = new GridLayoutManager(context, 3);
- int imageCount =postList.get(position).getImagesUrls().size();
+ int imageCount = postList.get(position).getImagesUrls().size();
if (imageCount == 0) {
// 没有微博图片
recyclerViewHolder.rvImages.setVisibility(View.GONE);
@@ -304,7 +322,7 @@ public class DataAdapter extends RecyclerView.Adapter {
if (imageCount == 1) {
layoutManager.setSpanCount(1);
param.width = ViewGroup.LayoutParams.WRAP_CONTENT;
- param.width=ViewGroup.LayoutParams.WRAP_CONTENT;
+ param.width = ViewGroup.LayoutParams.WRAP_CONTENT;
} else if (imageCount == 4) {
layoutManager.setSpanCount(2);
// 两个图片宫格的宽度
@@ -316,16 +334,16 @@ public class DataAdapter extends RecyclerView.Adapter {
// 刷新图片显示
recyclerViewHolder.rvImages.setLayoutManager(layoutManager);
- ImagesAdapter adapter=new ImagesAdapter(context,postList.get(position).getImagesUrls());
+ ImagesAdapter adapter = new ImagesAdapter(context, postList.get(position).getImagesUrls());
recyclerViewHolder.rvImages.setAdapter(adapter);
}
//先判断是否添加过,否则可能会重复添加
if (!positions.contains(position)) {
positions.add(position);
}
- } else if(holder instanceof FootViewHolder){
+ } else if (holder instanceof FootViewHolder) {
Log.d(TAG, "onBindViewHolder: ViewHolder");
- Log.d(TAG, "onBindViewHolder: position:"+position);
+ Log.d(TAG, "onBindViewHolder: position:" + position);
FootViewHolder footViewHolder = (FootViewHolder) holder;
switch (loadState) {
case LOADING:
@@ -356,20 +374,21 @@ public class DataAdapter extends RecyclerView.Adapter {
}
-// 刷新数据
- public void refreshView(List- postList){
- cmtCount=0;
- this.postList=postList;
+ // 刷新数据
+ public void refreshView(List
- postList) {
+ cmtCount = 0;
+ this.postList = postList;
notifyDataSetChanged();
}
-// 添加数据
- public void addDatas(List
- items){
+ // 添加数据
+ public void addDatas(List
- items) {
int positionStart = postList.size();
postList.addAll(items);
int itemCount = postList.size() - positionStart;
notifyItemRangeInserted(positionStart + 1, itemCount);
}
+
//动态添加textview实现评论
private void addCmt(String userName, String string, LinearLayout linearLayout) {
TextView textView = new TextView(context);
@@ -378,10 +397,11 @@ public class DataAdapter extends RecyclerView.Adapter
{
linearLayout.addView(textView);
LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
layoutParams.setMargins(0, 0, 0, 20);
- layoutParams.width= ViewGroup.LayoutParams.MATCH_PARENT;
+ layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
textView.setLayoutParams(layoutParams);
}
-// 动态移出评论
+
+ // 动态移出评论
private void removeCmt(LinearLayout linearLayout) {
linearLayout.removeAllViews();
}
@@ -395,6 +415,7 @@ public class DataAdapter extends RecyclerView.Adapter {
return TYPE_ITEM;
}
}
+
/**
* 设置上拉加载状态
*
@@ -405,9 +426,19 @@ public class DataAdapter extends RecyclerView.Adapter {
notifyDataSetChanged();
}
- public class ViewHolder extends RecyclerView.ViewHolder{
+
+ // 删除指定postion
+// 删除数据
+ public void removeData(int position) {
+ postList.remove(position);
+ //删除动画
+ notifyItemRemoved(position);
+ notifyDataSetChanged();
+ }
+
+ public static class ViewHolder extends RecyclerView.ViewHolder {
public RecyclerView rvImages;
- public TextView tvUser, tvCnt, tvDate, tvCmt, tvIntro, tvStar,tvCmtName;
+ public TextView tvUser, tvCnt, tvDate, tvCmt, tvIntro, tvStar, tvCmtName;
public EditText etCmt;
public ImageView ivCmt;
public ImageView ivSend;
@@ -416,12 +447,13 @@ public class DataAdapter extends RecyclerView.Adapter {
public TabLayout tab;
public FloatingActionButton btnFlt;
public CheckBox btnStar;
+ public TextView tvDelete;
public ViewHolder(@NonNull View itemView) {
super(itemView);
- tvCnt=itemView.findViewById(R.id.tv_content);
- rvImages =itemView.findViewById(R.id.rv_post_images);
+ tvCnt = itemView.findViewById(R.id.tv_content);
+ rvImages = itemView.findViewById(R.id.rv_post_images);
tvUser = itemView.findViewById(R.id.tv_user);
tvDate = itemView.findViewById(R.id.tv_date);
tvCmt = itemView.findViewById(R.id.tv_cmt);
@@ -434,10 +466,12 @@ public class DataAdapter extends RecyclerView.Adapter {
tab = itemView.findViewById(R.id.bottom_tab_layout);
btnFlt = itemView.findViewById(R.id.btn_float);
btnStar = itemView.findViewById(R.id.btn_star);
- ivHead=itemView.findViewById(R.id.iv_head);
+ ivHead = itemView.findViewById(R.id.iv_head);
+ tvDelete = itemView.findViewById(R.id.tv_delete);
}
}
- public class FootViewHolder extends RecyclerView.ViewHolder {
+
+ public static class FootViewHolder extends RecyclerView.ViewHolder {
AVLoadingIndicatorView pbLoading;
TextView tvLoading;
@@ -445,9 +479,9 @@ public class DataAdapter extends RecyclerView.Adapter {
FootViewHolder(View itemView) {
super(itemView);
- pbLoading =itemView.findViewById(R.id.ld_more);
- tvLoading =itemView.findViewById(R.id.tv_loading);
- llEnd =itemView.findViewById(R.id.ll_end);
+ pbLoading = itemView.findViewById(R.id.ld_more);
+ tvLoading = itemView.findViewById(R.id.tv_loading);
+ llEnd = itemView.findViewById(R.id.ll_end);
}
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ManagerAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ManagerAdapter.java
new file mode 100644
index 0000000..35db0bd
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ManagerAdapter.java
@@ -0,0 +1,71 @@
+package com.moyv.schoolbbs.ui.adapter;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.getbase.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.tabs.TabLayout;
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.pojo.Item;
+import com.moyv.schoolbbs.ui.activity.ManagerActivity;
+
+import java.util.List;
+
+public class ManagerAdapter extends RecyclerView.Adapter{
+
+ public Context context;
+ private List- postList;
+
+ // 普通布局
+ private final int TYPE_ITEM = 1;
+ // 脚布局
+ private final int TYPE_FOOTER = 2;
+ // 当前加载状态,默认为加载完成
+ private int loadState = 2;
+ // 正在加载
+ public final int LOADING = 1;
+ // 加载完成
+ public final int LOADING_COMPLETE = 2;
+ // 加载到底
+ public final int LOADING_END = 3;
+
+ public ManagerAdapter(Context context, List
- postList){
+ this.context=context;
+ this.postList=postList;
+ }
+ @NonNull
+ @Override
+ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+ if(viewType==TYPE_ITEM){
+ View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_main_item,parent,false);
+ return new DataAdapter.ViewHolder(view);
+ }else if(viewType==TYPE_FOOTER){
+ View view = LayoutInflater.from(parent.getContext())
+ .inflate(R.layout.loading_more, parent, false);
+ return new DataAdapter.FootViewHolder(view);
+ }else {
+ return null;
+ }
+ }
+
+ @Override
+ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
+
+ }
+
+ @Override
+ public int getItemCount() {
+ return postList.size()+1;
+ }
+
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
index 7ad1b43..f648975 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
@@ -34,7 +34,11 @@ import java.util.List;
import static com.moyv.schoolbbs.base.Global.init;
import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
+import static com.moyv.schoolbbs.ui.adapter.DataAdapter.MAIN;
+/**
+ * @author moyv
+ */
public class HomeFragment extends Fragment {
@@ -165,6 +169,7 @@ public class HomeFragment extends Fragment {
// 显示帖子列表
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
adapter = new DataAdapter(mContext,items);
+ adapter.type=MAIN;
Log.i("TAG", "handleMessage: "+items.size());
recyclerView.setAdapter(adapter);
return false;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
index 6476baf..9334af7 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
@@ -42,6 +42,7 @@ import com.moyv.schoolbbs.config.AccountConstant;
import com.moyv.schoolbbs.service.ChangeService;
import com.moyv.schoolbbs.service.UserInfoService;
import com.moyv.schoolbbs.ui.activity.LoginActivity;
+import com.moyv.schoolbbs.ui.activity.ManagerActivity;
import com.moyv.schoolbbs.ui.view.MaskImageView;
import com.moyv.schoolbbs.ui.view.MeItemView;
@@ -49,6 +50,7 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
import static com.moyv.schoolbbs.config.URLConstant.HEAD_URL;
import static com.moyv.schoolbbs.util.AnalysisUtils.cleanLoginStatus;
@@ -70,6 +72,8 @@ public class MeFragment extends Fragment implements View.OnClickListener {
private MeItemView itemAccount;
private MeItemView itemIntroduction;
private AlertDialog changeDialog;
+ private TextView postManager;
+ private TextView starManager;
public static MeFragment newInstance(String title) {
Bundle arguments = new Bundle();
arguments.putString("TITLE", title);
@@ -92,6 +96,8 @@ public class MeFragment extends Fragment implements View.OnClickListener {
itemAccount=root.findViewById(R.id.me_item_account);
itemIntroduction=root.findViewById(R.id.me_item_introduction);
ivHead.setImageResource(R.drawable.login_head);
+ postManager=root.findViewById(R.id.me_tv_posts);
+ starManager=root.findViewById(R.id.me_tv_stars);
btnLogOut.setOnClickListener(this);
@@ -99,6 +105,9 @@ public class MeFragment extends Fragment implements View.OnClickListener {
itemName.setOnClickListener(this);
itemIntroduction.setOnClickListener(this);
+
+ postManager.setOnClickListener(this);
+ starManager.setOnClickListener(this);
return root;
}
@@ -183,6 +192,13 @@ public class MeFragment extends Fragment implements View.OnClickListener {
// dialog(3,"请输入要修改的密码");
show("修改密码点击事件");
break;
+ case R.id.me_tv_posts:
+ intentPostsManager(ManagerActivity.class);
+ show("帖子管理");
+ break;
+ case R.id.me_tv_stars:
+ show("点赞管理");
+ break;
default:
System.out.println("点击事件没有执行事件");
}
@@ -217,4 +233,9 @@ public class MeFragment extends Fragment implements View.OnClickListener {
}
});
+ public void intentPostsManager(Class intentClass){
+ Intent intent=new Intent(context, intentClass);
+ startActivity(intent);
+ }
+
}
diff --git a/app/src/main/res/layout/activity_post_manager.xml b/app/src/main/res/layout/activity_post_manager.xml
new file mode 100644
index 0000000..4f28ec0
--- /dev/null
+++ b/app/src/main/res/layout/activity_post_manager.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_post_manager_item.xml b/app/src/main/res/layout/activity_post_manager_item.xml
new file mode 100644
index 0000000..00ccc56
--- /dev/null
+++ b/app/src/main/res/layout/activity_post_manager_item.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_main_item.xml b/app/src/main/res/layout/fragment_main_item.xml
index 62a2cf3..ff309ac 100644
--- a/app/src/main/res/layout/fragment_main_item.xml
+++ b/app/src/main/res/layout/fragment_main_item.xml
@@ -52,8 +52,6 @@
android:textColor="@color/item_text_secondary"
android:textSize="14sp" />
-
-
+
+
+
+
-
-
+ android:layout_marginLeft="10dp">
-
+
#636563
#9C9A9C
+
+ #697A9F
+
+
+ #6274e2
+ #303F9F
+ #2d3a93
+ #ebebeb
+ #e8e8e8
+ #a6efefef
+ #858585
+ #ae858585
+ #ae282828
+ #19000000
+ #f8efe6
+ #f7e8d9
+ #38be55
+ #2da346
+ #e94f4f
+ #4e342e
+
\ No newline at end of file
--
Gitee
From 190a8b133b15a36b947e18f1576d0ab352f5c591 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Fri, 18 Jun 2021 20:42:23 +0800
Subject: [PATCH 2/9] =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=82=B9=E8=B5=9E?=
=?UTF-8?q?=E7=AE=A1=E7=90=86=E7=95=8C=E9=9D=A2=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/moyv/schoolbbs/service/MainService.java | 6 ++++--
.../moyv/schoolbbs/ui/activity/ManagerActivity.java | 10 ++++++++--
.../com/moyv/schoolbbs/ui/fragment/MeFragment.java | 10 +++++++---
3 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/MainService.java b/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
index 2d53e8e..3face2a 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
@@ -33,6 +33,8 @@ import static com.moyv.schoolbbs.util.JsonUtil.parseReModel;
* @author moyv
*/
public class MainService {
+ public static int USER_POSTS =123;
+ public static int STAR_POSTS=321;
private String url;
private ReModel reModel = null;
private Handler handler=null;
@@ -80,7 +82,7 @@ public class MainService {
}
});
}
- public void getUserPosts(int account,int star,int end){
+ public void getUserPosts(int account,int star,int end,int type){
url=MAIN_URL;
OkHttpClient okHttpClient=createClient();
// 请求体
@@ -95,6 +97,7 @@ public class MainService {
FormBody formBody=new FormBody.Builder()
.add("account",String.valueOf(account))
.add("result",obj.toString())
+ .add("type",String.valueOf(type))
.build();
// 发送请求操作
Request request=new Request.Builder()
@@ -120,7 +123,6 @@ public class MainService {
}
});
}
-
public void getCmt(int postId){
url="http://10.0.2.2:8080/bbs_servlet/main";
OkHttpClient okHttpClient=createClient();
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
index 13bf9f8..0f8f1ed 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
@@ -1,6 +1,7 @@
package com.moyv.schoolbbs.ui.activity;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -29,6 +30,7 @@ import java.util.List;
import static com.moyv.schoolbbs.base.Global.init;
import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
+import static com.moyv.schoolbbs.service.MainService.USER_POSTS;
import static com.moyv.schoolbbs.ui.adapter.DataAdapter.MANAGER;
/**
@@ -46,6 +48,8 @@ public class ManagerActivity extends AppCompatActivity {
private List lists;
// 帖子总数
private int count;
+
+ private int type;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -54,6 +58,8 @@ public class ManagerActivity extends AppCompatActivity {
end = 5;
mContext = this;
+ Intent intent=getIntent();
+ type=intent.getIntExtra("type",USER_POSTS);
recyclerView =findViewById(R.id.manager_recycler_view);
init(mContext);
@@ -66,7 +72,7 @@ public class ManagerActivity extends AppCompatActivity {
Log.d("zttjiangqq", "invoke onRefresh...");
start=0;
end=5;
- new MainService(handler1).getUserPosts(ACCOUNT,start,end);
+ new MainService(handler1).getUserPosts(ACCOUNT,start,end,type);
}
}
@@ -94,7 +100,7 @@ public class ManagerActivity extends AppCompatActivity {
}
});
- new MainService(handler).getUserPosts(ACCOUNT,start, end);
+ new MainService(handler).getUserPosts(ACCOUNT,start, end ,type);
// 加载帖子数据
UIHelper.showDialogForLoading(mContext, "初始化数据中");
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
index 9334af7..b68baea 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
@@ -53,6 +53,8 @@ import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
import static com.moyv.schoolbbs.config.URLConstant.HEAD_URL;
+import static com.moyv.schoolbbs.service.MainService.STAR_POSTS;
+import static com.moyv.schoolbbs.service.MainService.USER_POSTS;
import static com.moyv.schoolbbs.util.AnalysisUtils.cleanLoginStatus;
import static com.moyv.schoolbbs.util.AnalysisUtils.readLoginStatus;
import static com.moyv.schoolbbs.util.AnalysisUtils.readLoginUserName;
@@ -193,10 +195,11 @@ public class MeFragment extends Fragment implements View.OnClickListener {
show("修改密码点击事件");
break;
case R.id.me_tv_posts:
- intentPostsManager(ManagerActivity.class);
+ intentPostsManager(USER_POSTS);
show("帖子管理");
break;
case R.id.me_tv_stars:
+ intentPostsManager(STAR_POSTS);
show("点赞管理");
break;
default:
@@ -233,8 +236,9 @@ public class MeFragment extends Fragment implements View.OnClickListener {
}
});
- public void intentPostsManager(Class intentClass){
- Intent intent=new Intent(context, intentClass);
+ public void intentPostsManager(int type){
+ Intent intent=new Intent(context, ManagerActivity.class);
+ intent.putExtra("type",type);
startActivity(intent);
}
--
Gitee
From b5b68854d25aa7cafab825c610a842967162528f Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Fri, 18 Jun 2021 23:31:47 +0800
Subject: [PATCH 3/9] =?UTF-8?q?=E7=BB=86=E5=BE=AE=E6=94=B9=E5=8A=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../com/moyv/schoolbbs/ui/activity/RegisterActivity.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
index 70116df..fc362d8 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
@@ -1,5 +1,7 @@
package com.moyv.schoolbbs.ui.activity;
+import android.app.Activity;
+import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -28,11 +30,13 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
private EditText etPassword;
private EditText etAgainPsw;
private Button btnRegister;
+ private Context context;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
+ context=this;
intiView();
checkLegal();
}
@@ -57,7 +61,6 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
case R.id.register_btn_register:
String name=etName.getText().toString();
int account=Integer.parseInt(etAccount.getText().toString());
- System.out.println(account);
String password=etPassword.getText().toString();
String pswAgain=etAgainPsw.getText().toString();
if(!password.equals(pswAgain)){
@@ -67,6 +70,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
registerService.register(account,name,password,handler);
}
break;
+ default:
}
}
@@ -75,7 +79,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
public boolean handleMessage(@NonNull Message msg) {
switch (msg.what){
case 200:
- finish();
+ ((Activity)context).finish();
break;
default:
System.out.println("handler接收出错");
--
Gitee
From 7767b71ea2c970b4c9eadd47fe684de450bed4c9 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Sat, 19 Jun 2021 16:31:50 +0800
Subject: [PATCH 4/9] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=B8=96=E5=AD=90?=
=?UTF-8?q?=E5=B1=95=E7=A4=BA=E5=B8=83=E5=B1=80=E4=BF=AE=E6=94=B9=EF=BC=88?=
=?UTF-8?q?=E6=9C=AA=E5=AE=8C=E5=96=84=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/inspectionProfiles/Project_Default.xml | 36 ++++
.../main/java/com/moyv/schoolbbs/app/App.java | 25 +++
.../java/com/moyv/schoolbbs/pojo/Comment.java | 20 ++
.../schoolbbs/ui/adapter/DataAdapter.java | 25 ++-
.../schoolbbs/ui/adapter/ImagesAdapter.java | 2 +-
.../schoolbbs/ui/adapter/ManagerAdapter.java | 10 +-
.../ui/spannable/CircleMovementMethod.java | 127 ++++++++++++
.../schoolbbs/ui/spannable/ISpanClick.java | 6 +
.../ui/spannable/SpannableClickable.java | 40 ++++
.../moyv/schoolbbs/ui/view/CommentsView.java | 195 ++++++++++++++++++
.../schoolbbs/ui/view/ExpandTextView.java | 131 ++++++++++++
.../schoolbbs/ui/view/PraiseListView.java | 136 ++++++++++++
.../drawable-v24/comments_drawable_blue.xml | 11 +
.../res/drawable-v24/heart_drawable_blue.xml | 11 +
...t_main_item.xml => item_fragment_main.xml} | 93 +++++++--
..._item.xml => item_fragment_main_image.xml} | 0
.../main/res/layout/layout_expand_text.xml | 26 +++
.../mipmap-hdpi/im_distribute_comm_bg.9.png | Bin 0 -> 433 bytes
app/src/main/res/values/attrs.xml | 7 +
app/src/main/res/values/colors.xml | 12 +-
20 files changed, 875 insertions(+), 38 deletions(-)
create mode 100644 .idea/inspectionProfiles/Project_Default.xml
create mode 100644 app/src/main/java/com/moyv/schoolbbs/app/App.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/spannable/CircleMovementMethod.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/ExpandTextView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/PraiseListView.java
create mode 100644 app/src/main/res/drawable-v24/comments_drawable_blue.xml
create mode 100644 app/src/main/res/drawable-v24/heart_drawable_blue.xml
rename app/src/main/res/layout/{fragment_main_item.xml => item_fragment_main.xml} (65%)
rename app/src/main/res/layout/{fragment_main_image_item.xml => item_fragment_main_image.xml} (100%)
create mode 100644 app/src/main/res/layout/layout_expand_text.xml
create mode 100644 app/src/main/res/mipmap-hdpi/im_distribute_comm_bg.9.png
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 0000000..6560a98
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/moyv/schoolbbs/app/App.java b/app/src/main/java/com/moyv/schoolbbs/app/App.java
new file mode 100644
index 0000000..4a31dab
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/app/App.java
@@ -0,0 +1,25 @@
+package com.moyv.schoolbbs.app;
+
+import android.app.Application;
+import android.content.Context;
+
+/**
+ * @作者: njb
+ * @时间: 2019/7/22 11:07
+ * @描述:
+ */
+public class App extends Application {
+ //全局Context
+ private static Context sContext;
+
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ sContext = getApplicationContext();
+ }
+
+
+ public static Context getContext() {
+ return sContext;
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java b/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
index a35632e..0f81fc6 100644
--- a/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
@@ -1,6 +1,7 @@
package com.moyv.schoolbbs.pojo;
import com.google.gson.annotations.SerializedName;
+import com.moyv.schoolbbs.bean.UserInfo;
import java.sql.Timestamp;
import java.util.Date;
@@ -19,6 +20,25 @@ public class Comment {
@SerializedName("cmtName")
private String cmtName;
+ private UserInfo replyUser; // 回复人信息
+ private UserInfo commentsUser; // 评论人信息
+
+ public UserInfo getReplyUser() {
+ return replyUser;
+ }
+
+ public void setReplyUser(UserInfo replyUser) {
+ this.replyUser = replyUser;
+ }
+
+ public UserInfo getCommentsUser() {
+ return commentsUser;
+ }
+
+ public void setCommentsUser(UserInfo commentsUser) {
+ this.commentsUser = commentsUser;
+ }
+
public String getCmtName() {
return cmtName;
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
index c109b3a..71577ae 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
@@ -34,6 +34,9 @@ import com.moyv.schoolbbs.pojo.Item;
import com.moyv.schoolbbs.pojo.Star;
import com.moyv.schoolbbs.service.CmtService;
import com.moyv.schoolbbs.service.StarService;
+import com.moyv.schoolbbs.ui.view.CommentsView;
+import com.moyv.schoolbbs.ui.view.ExpandTextView;
+import com.moyv.schoolbbs.ui.view.PraiseListView;
import com.moyv.schoolbbs.util.KeyboardUtils;
import com.wang.avi.AVLoadingIndicatorView;
@@ -87,7 +90,7 @@ public class DataAdapter extends RecyclerView.Adapter {
// 为每个Item inflater出一个View
// 通过判断显示类型,来创建不同的View
if (viewType == TYPE_ITEM) {
- View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fragment_main_item, parent, false);
+ View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fragment_main, parent, false);
return new ViewHolder(view);
} else if (viewType == TYPE_FOOTER) {
View view = LayoutInflater.from(parent.getContext())
@@ -136,10 +139,13 @@ public class DataAdapter extends RecyclerView.Adapter {
recyclerViewHolder.tvDate.setText(Date);
// 帖子文字内容
if (content.length() == 0) {
- recyclerViewHolder.tvCnt.setVisibility(View.GONE);
+// recyclerViewHolder.tvCnt.setVisibility(View.GONE);
+ recyclerViewHolder.expandTextView.setVisibility(View.GONE);
} else {
- recyclerViewHolder.tvCnt.setVisibility(View.VISIBLE);
- recyclerViewHolder.tvCnt.setText(content);
+// recyclerViewHolder.tvCnt.setVisibility(View.VISIBLE);
+// recyclerViewHolder.tvCnt.setText(content);
+ recyclerViewHolder.expandTextView.setVisibility(View.VISIBLE);
+ recyclerViewHolder.expandTextView.setText(content);
}
@@ -292,7 +298,10 @@ public class DataAdapter extends RecyclerView.Adapter {
}
if (starCount == 0) {
recyclerViewHolder.tvStar.setText("");
+ recyclerViewHolder.rvLike.setVisibility(View.GONE);
} else {
+ recyclerViewHolder.rvLike.setVisibility(View.VISIBLE);
+ recyclerViewHolder.rvLike.setDatas(postList.get(position).getMain().getStars());
starInfo += "共计" + stars.size() + "个赞";
recyclerViewHolder.tvStar.setText(starInfo);
}
@@ -448,11 +457,13 @@ public class DataAdapter extends RecyclerView.Adapter {
public FloatingActionButton btnFlt;
public CheckBox btnStar;
public TextView tvDelete;
-
+ public ExpandTextView expandTextView;
+ public PraiseListView rvLike;
+ public CommentsView rvComment;
public ViewHolder(@NonNull View itemView) {
super(itemView);
- tvCnt = itemView.findViewById(R.id.tv_content);
+// tvCnt = itemView.findViewById(R.id.tv_content);
rvImages = itemView.findViewById(R.id.rv_post_images);
tvUser = itemView.findViewById(R.id.tv_user);
tvDate = itemView.findViewById(R.id.tv_date);
@@ -468,6 +479,8 @@ public class DataAdapter extends RecyclerView.Adapter {
btnStar = itemView.findViewById(R.id.btn_star);
ivHead = itemView.findViewById(R.id.iv_head);
tvDelete = itemView.findViewById(R.id.tv_delete);
+ expandTextView=itemView.findViewById(R.id.tv_content);
+ rvLike=itemView.findViewById(R.id.rv_like);
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
index 8a5fd3d..e540a02 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
@@ -40,7 +40,7 @@ public class ImagesAdapter extends RecyclerView.Adapter 0){
+ // 点击的是Span区域,不要把点击事件传递
+ setPassToTv(false);
+ Selection.setSelection(buffer,
+ buffer.getSpanStart(mClickLinks[0]),
+ buffer.getSpanEnd(mClickLinks[0]));
+ //设置点击区域的背景色
+ mBgSpan = new BackgroundColorSpan(clickableSpanBgClor);
+ buffer.setSpan(mBgSpan,
+ buffer.getSpanStart(mClickLinks[0]),
+ buffer.getSpanEnd(mClickLinks[0]),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }else{
+ setPassToTv(true);
+ // textview选中效果
+ widget.setBackgroundColor(textViewBgColor);
+ }
+
+ }else if(action == MotionEvent.ACTION_UP){
+ if(mClickLinks.length > 0){
+ mClickLinks[0].onClick(widget);
+ if(mBgSpan != null){//移除点击时设置的背景span
+ buffer.removeSpan(mBgSpan);
+ }
+ }else{
+
+ }
+ Selection.removeSelection(buffer);
+ widget.setBackgroundResource(R.color.transparent);
+ }else if(action == MotionEvent.ACTION_MOVE){
+ //这种情况不用做处理
+ }else{
+ if(mBgSpan != null){//移除点击时设置的背景span
+ buffer.removeSpan(mBgSpan);
+ }
+ widget.setBackgroundResource(R.color.transparent);
+ }
+ return Touch.onTouchEvent(widget, buffer, event);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java
new file mode 100644
index 0000000..adcbfdc
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java
@@ -0,0 +1,6 @@
+package com.moyv.schoolbbs.ui.spannable;
+
+
+public interface ISpanClick {
+ public void onClick(int position);
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java
new file mode 100644
index 0000000..7eb92c4
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java
@@ -0,0 +1,40 @@
+package com.moyv.schoolbbs.ui.spannable;
+
+import android.text.TextPaint;
+import android.text.style.ClickableSpan;
+import android.view.View;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.app.App;
+
+
+/**
+ * @作者: njb
+ * @时间: 2019/7/22 10:53
+ * @描述:
+ */
+public abstract class SpannableClickable extends ClickableSpan implements View.OnClickListener {
+
+ private int DEFAULT_COLOR_ID = R.color.color_8290AF;
+ /**
+ * text颜色
+ */
+ private int textColor ;
+
+ public SpannableClickable() {
+ this.textColor = App.getContext().getResources().getColor(DEFAULT_COLOR_ID);
+ }
+
+ public SpannableClickable(int textColor){
+ this.textColor = textColor;
+ }
+
+ @Override
+ public void updateDrawState(TextPaint ds) {
+ super.updateDrawState(ds);
+
+ ds.setColor(textColor);
+ ds.setUnderlineText(false);
+ ds.clearShadowLayer();
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java
new file mode 100644
index 0000000..f1f3556
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java
@@ -0,0 +1,195 @@
+package com.moyv.schoolbbs.ui.view;
+
+import android.content.Context;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.SpannableStringBuilder;
+import android.text.TextPaint;
+import android.text.TextUtils;
+import android.text.style.ClickableSpan;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.Nullable;
+
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.bean.UserInfo;
+import com.moyv.schoolbbs.pojo.Comment;
+import com.moyv.schoolbbs.ui.spannable.CircleMovementMethod;
+
+import java.util.List;
+
+/**
+ * @作者: njb
+ * @时间: 2019/7/22 19:04
+ * @描述: 评论列表
+ */
+public class CommentsView extends LinearLayout {
+ private Context mContext;
+ private List mDatas;
+ private onItemLongClickListener onItemLongClickListener;
+ private CommentListener onCommentListener;
+
+ public CommentsView(Context context) {
+ this(context, null);
+ }
+
+ public CommentsView(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public CommentsView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ setOrientation(VERTICAL);
+ this.mContext = context;
+ }
+
+ /**
+ * 设置评论列表信息
+ *
+ * @param list
+ */
+ public void setList(List list) {
+ mDatas = list;
+ }
+
+ public void setOnItemLongClickListener(onItemLongClickListener longClickListener) {
+ this.onItemLongClickListener = longClickListener;
+ }
+
+ public void setOnCommentListener(CommentListener onCommentListener) {
+ this.onCommentListener = onCommentListener;
+ }
+
+
+ public void notifyDataSetChanged() {
+ removeAllViews();
+ if (mDatas == null || mDatas.size() <= 0) {
+ return;
+ }
+ LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
+ layoutParams.setMargins(0, 10, 0, 10);
+ for (int i = 0; i < mDatas.size(); i++) {
+ View view = getView(i);
+ if (view == null) {
+ throw new NullPointerException("listview item layout is null, please check getView()...");
+ }
+ addView(view, i, layoutParams);
+ }
+ }
+
+ private View getView(final int position) {
+ final Comment item = mDatas.get(position);
+ UserInfo userBean = new UserInfo();
+ UserInfo replyUser;
+ if (!TextUtils.isEmpty(String.valueOf(item.getCommentAccount())) && !TextUtils.isEmpty(item.getCmtName())) {
+ userBean.setAccount(item.getCommentAccount());
+ userBean.setName(item.getCmtName());
+ item.setReplyUser(userBean);
+ }
+ replyUser = item.getReplyUser();
+ boolean hasReply = false; // 是否有回复
+ if (replyUser != null) {
+ hasReply = true;
+ }
+ TextView textView = new TextView(mContext);
+ textView.setTextSize(15);
+ textView.setTextColor(0xff686868);
+ SpannableStringBuilder builder = new SpannableStringBuilder();
+
+ UserInfo userComBean = new UserInfo();
+ if (String.valueOf(item.getCommentAccount()) != null && item.getCmtName() != null) {
+ userComBean.setAccount(item.getCommentAccount());
+ userComBean.setName(item.getCmtName());
+ item.setCommentsUser(userComBean);
+ }
+
+ UserInfo comUser = item.getCommentsUser();
+
+ String name = comUser.getName();
+ if (hasReply) {
+ builder.append(setClickableSpan(name, item.getCommentsUser()));
+ builder.append("回复");
+ builder.append(setClickableSpan(replyUser.getName(), item.getReplyUser()));
+ } else {
+ builder.append(setClickableSpan(name, item.getCommentsUser()));
+ }
+ builder.append(" : ");
+ builder.append(setClickableSpanContent(item.getCommentContent(), position, String.valueOf(userBean.getAccount()), item));
+ textView.setText(builder);
+ // 设置点击背景色
+ textView.setHighlightColor(getResources().getColor(android.R.color.transparent));
+ textView.setMovementMethod(new CircleMovementMethod(0xffcccccc, 0xffcccccc));
+
+
+ return textView;
+ }
+
+ /**
+ * 设置评论内容点击事件
+ *
+ * @param item
+ * @param position
+ * @return
+ */
+ public SpannableString setClickableSpanContent(final String item, final int position, String user_id, Comment bean) {
+ final SpannableString string = new SpannableString(item);
+ ClickableSpan span = new ClickableSpan() {
+ @Override
+ public void onClick(View widget) {
+ if (onCommentListener != null) {
+ onCommentListener.Comment(position, bean, user_id);
+ }
+ }
+
+ @Override
+ public void updateDrawState(TextPaint ds) {
+ super.updateDrawState(ds);
+ // 设置显示的内容文本颜色
+ ds.setColor(0xff686868);
+ ds.setUnderlineText(false);
+ }
+ };
+ string.setSpan(span, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ return string;
+ }
+
+ /**
+ * 设置评论用户名字点击事件
+ *
+ * @param item
+ * @param bean
+ * @return
+ */
+ public SpannableString setClickableSpan(final String item, final UserInfo bean) {
+ final SpannableString string = new SpannableString(item);
+ ClickableSpan span = new ClickableSpan() {
+ @Override
+ public void onClick(View widget) {
+ }
+
+ @Override
+ public void updateDrawState(TextPaint ds) {
+ super.updateDrawState(ds);
+ // 设置显示的用户名文本颜色
+ ds.setColor(getResources().getColor(R.color.c697A9F));
+ ds.setUnderlineText(false);
+ }
+ };
+
+ string.setSpan(span, 0, string.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ return string;
+ }
+
+
+ public interface onItemLongClickListener {
+ void onItemLongClick(int position, Comment bean);
+ }
+
+ public interface CommentListener {
+ void Comment(int position, Comment bean, String user_id);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/ExpandTextView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/ExpandTextView.java
new file mode 100644
index 0000000..23d1fd5
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/ExpandTextView.java
@@ -0,0 +1,131 @@
+package com.moyv.schoolbbs.ui.view;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.util.AttributeSet;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewTreeObserver;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.moyv.schoolbbs.R;
+
+/**
+ * @作者: njb
+ * @时间: 2019/7/22 10:53
+ * @描述: 自定义仿微信朋友圈显示全文与收起的TextView
+ */
+public class ExpandTextView extends LinearLayout {
+ public static final int DEFAULT_MAX_LINES = 3;//最大的行数
+ private TextView contentText;
+ private TextView textState;
+
+ private int showLines;
+
+ private ExpandStatusListener expandStatusListener;
+ private boolean isExpand;
+
+ public ExpandTextView(Context context) {
+ super(context);
+ initView();
+ }
+
+ public ExpandTextView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initAttrs(attrs);
+ initView();
+ }
+
+ public ExpandTextView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initAttrs(attrs);
+ initView();
+ }
+
+ private void initView() {
+ setOrientation(LinearLayout.VERTICAL);
+ LayoutInflater.from(getContext()).inflate(R.layout.layout_expand_text, this);
+ contentText = (TextView) findViewById(R.id.contentText);
+ if(showLines > 0){
+ contentText.setMaxLines(showLines);
+ }
+
+ textState = (TextView) findViewById(R.id.textState);
+ textState.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ String textStr = textState.getText().toString().trim();
+ if("全文".equals(textStr)){
+ contentText.setMaxLines(Integer.MAX_VALUE);
+ textState.setText("收起");
+ setExpand(true);
+ }else{
+ contentText.setMaxLines(showLines);
+ textState.setText("全文");
+ setExpand(false);
+ }
+ //通知外部状态已变更
+ if(expandStatusListener != null){
+ expandStatusListener.statusChange(isExpand());
+ }
+ }
+ });
+ }
+
+ private void initAttrs(AttributeSet attrs) {
+ TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ExpandTextView, 0, 0);
+ try {
+ showLines = typedArray.getInt(R.styleable.ExpandTextView_showLines, DEFAULT_MAX_LINES);
+ }finally {
+ typedArray.recycle();
+ }
+ }
+
+ public void setText(final CharSequence content){
+ contentText.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+
+ @Override
+ public boolean onPreDraw() {
+ // 避免重复监听
+ contentText.getViewTreeObserver().removeOnPreDrawListener(this);
+
+ int linCount = contentText.getLineCount();
+ if(linCount > showLines){
+
+ if(isExpand){
+ contentText.setMaxLines(Integer.MAX_VALUE);
+ textState.setText("收起");
+ }else{
+ contentText.setMaxLines(showLines);
+ textState.setText("全文");
+ }
+ textState.setVisibility(View.VISIBLE);
+ }else{
+ textState.setVisibility(View.GONE);
+ }
+ return true;
+ }
+
+
+ });
+ contentText.setText(content);
+ }
+
+ public void setExpand(boolean isExpand){
+ this.isExpand = isExpand;
+ }
+
+ public boolean isExpand(){
+ return this.isExpand;
+ }
+
+ public void setExpandStatusListener(ExpandStatusListener listener){
+ this.expandStatusListener = listener;
+ }
+
+ public static interface ExpandStatusListener{
+
+ void statusChange(boolean isExpand);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/PraiseListView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/PraiseListView.java
new file mode 100644
index 0000000..c33d49c
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/PraiseListView.java
@@ -0,0 +1,136 @@
+package com.moyv.schoolbbs.ui.view;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
+import android.text.Spannable;
+import android.text.SpannableString;
+import android.text.SpannableStringBuilder;
+import android.text.style.ImageSpan;
+import android.util.AttributeSet;
+import android.view.View;
+
+import androidx.annotation.NonNull;
+
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.pojo.Star;
+import com.moyv.schoolbbs.ui.spannable.CircleMovementMethod;
+import com.moyv.schoolbbs.ui.spannable.SpannableClickable;
+
+import java.util.List;
+
+/**
+ * @作者: njb
+ * @时间: 2019/7/22 19:04
+ * @描述: 点赞列表
+ */
+public class PraiseListView extends androidx.appcompat.widget.AppCompatTextView {
+
+ private int itemColor;
+ private int itemSelectorColor;
+ private List datas;
+ private OnItemClickListener onItemClickListener;
+
+ public OnItemClickListener getOnItemClickListener() {
+ return onItemClickListener;
+ }
+
+ public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
+ this.onItemClickListener = onItemClickListener;
+ }
+
+ public PraiseListView(Context context) {
+ super(context);
+ }
+
+ public PraiseListView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ initAttrs(attrs);
+ }
+
+ public PraiseListView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ initAttrs(attrs);
+ }
+
+ private void initAttrs(AttributeSet attrs) {
+ TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.PraiseListView, 0, 0);
+ try {
+ //textview的默认颜色
+ itemColor = typedArray.getColor(R.styleable.PraiseListView_item_color, getResources().getColor(R.color.c697A9F));
+ itemSelectorColor = typedArray.getColor(R.styleable.PraiseListView_item_selector_color, getResources().getColor(R.color.praise_item_selector_default));
+
+ } finally {
+ typedArray.recycle();
+ }
+ }
+
+ public List getDatas() {
+ return datas;
+ }
+
+ public void setDatas(List datas) {
+ this.datas = datas;
+ notifyDataSetChanged();
+ }
+
+
+ public void notifyDataSetChanged() {
+ SpannableStringBuilder builder = new SpannableStringBuilder();
+ if (datas != null && datas.size() > 0) {
+ //添加点赞图标
+ builder.append(setImageSpan());
+ Star item = null;
+ for (int i = 0; i < datas.size(); i++) {
+ item = datas.get(i);
+ if (item != null) {
+ builder.append(setClickableSpan(item.getName(), i));
+ if (i != datas.size() - 1) {
+ builder.append(",");
+ }
+ }
+ }
+ }
+
+ setText(builder);
+
+ setMovementMethod(new CircleMovementMethod(itemSelectorColor));
+ }
+
+
+ private SpannableString setImageSpan() {
+ String text = " ";
+ SpannableString imgSpanText = new SpannableString(text);
+ Drawable drawable = getContext().getResources().getDrawable(R.drawable.heart_drawable_blue);
+ drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
+ ImageSpan imageSpan = new ImageSpan(drawable);
+ imgSpanText.setSpan(imageSpan,0, 1, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
+ return imgSpanText;
+ }
+
+ @NonNull
+ private SpannableString setClickableSpan(String textStr, final int position) {
+ SpannableString subjectSpanText = new SpannableString(textStr);
+ subjectSpanText.setSpan(new SpannableClickable(itemColor) {
+ @Override
+ public void onClick(View widget) {
+ if (onItemClickListener != null) {
+ onItemClickListener.onClick(position);
+ }
+ }
+ }, 0, subjectSpanText.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ return subjectSpanText;
+ }
+
+ @Override
+ protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ }
+
+ public interface OnItemClickListener {
+ void onClick(int position);
+ }
+}
diff --git a/app/src/main/res/drawable-v24/comments_drawable_blue.xml b/app/src/main/res/drawable-v24/comments_drawable_blue.xml
new file mode 100644
index 0000000..8457e7d
--- /dev/null
+++ b/app/src/main/res/drawable-v24/comments_drawable_blue.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/heart_drawable_blue.xml b/app/src/main/res/drawable-v24/heart_drawable_blue.xml
new file mode 100644
index 0000000..63ca9bb
--- /dev/null
+++ b/app/src/main/res/drawable-v24/heart_drawable_blue.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_main_item.xml b/app/src/main/res/layout/item_fragment_main.xml
similarity index 65%
rename from app/src/main/res/layout/fragment_main_item.xml
rename to app/src/main/res/layout/item_fragment_main.xml
index ff309ac..25302bf 100644
--- a/app/src/main/res/layout/fragment_main_item.xml
+++ b/app/src/main/res/layout/item_fragment_main.xml
@@ -1,6 +1,7 @@
@@ -39,8 +40,8 @@
android:layout_height="wrap_content"
android:layout_marginRight="120dp"
android:text="用户名"
- android:textColor="@color/black"
- android:textSize="16sp" />
+ android:textColor="@color/c697A9F"
+ android:textSize="14sp" />
+ android:textColor="@color/c697A9F"
+ android:textSize="12sp" />
-
+
+
+
+
+
+
+
+
+
+
+
+ android:textColor="@color/black"
+ android:textSize="16sp"
+ android:ellipsize="end"/>
+
@@ -93,7 +104,7 @@
android:layout_marginLeft="10dp"
android:text="0000-00-00"
android:textColor="@color/item_text_secondary"
- android:textSize="14sp" />
+ android:textSize="12sp" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-hdpi/im_distribute_comm_bg.9.png b/app/src/main/res/mipmap-hdpi/im_distribute_comm_bg.9.png
new file mode 100644
index 0000000000000000000000000000000000000000..6d2eaf68586fbf3ae57937c3e04b167af7ae4151
GIT binary patch
literal 433
zcmeAS@N?(olHy`uVBq!ia0vp^Q9x|P!3HD^V*DZ)7#J%&T^vIyZoR#;-|Mgg!|{(R
zeu#g(|4#XbfL-hPhYzwj`ttOely+EHa4gzkQL-g?qQc3er(-8yS@__}XDwe2rKP^b
zAuqqP-#0apXPUln?enwWdYb?3>@fVCxW?agO~1`Eo=U~8t215A?w|bTDK9s3)Ww@949Ih6`sl!CF^iBg>si$vlYdO?R#Cz;vOO5nl1Kb9aGW0
+
+
+
+
+
+
+
//设置左侧图标
//左侧标题文字
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 2c73773..555a1df 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -3,25 +3,25 @@
#3F51B5
#303F9F
#FF4081
-
#FFBB86FC
#FF6200EE
#FF3700B3
#FF03DAC5
#FF018786
#FF000000
-
#FFFFFFFF
#e6e6e6
-
#00000000
#44000000
-
#636563
#9C9A9C
-
#697A9F
-
+ #697A9F
+ #232323
+ #8290AF
+ #cccccc
+ #cccccc
+ #8290AF
#6274e2
#303F9F
--
Gitee
From f54fae14e836c4c4a7fe5fd49793814c7c6b9c99 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Sat, 19 Jun 2021 23:43:54 +0800
Subject: [PATCH 5/9] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=AE=8C=E6=88=90?=
=?UTF-8?q?=E5=90=8E=E9=A1=B5=E9=9D=A2=E4=B8=8D=E8=B7=B3=E8=BD=AC=E9=97=AE?=
=?UTF-8?q?=E9=A2=98=E8=A7=A3=E5=86=B3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../schoolbbs/service/RegisterService.java | 11 ++-
.../schoolbbs/ui/activity/LoginActivity.java | 2 +
.../ui/activity/RegisterActivity.java | 69 +++++++++++++------
3 files changed, 55 insertions(+), 27 deletions(-)
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/RegisterService.java b/app/src/main/java/com/moyv/schoolbbs/service/RegisterService.java
index 28a9266..4e00568 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/RegisterService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/RegisterService.java
@@ -48,7 +48,7 @@ public class RegisterService {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
System.out.println("Register.register:连接服务器失败");
- show(getClass().getName()+"连接服务器失败");
+ handler.sendMessage(handler.obtainMessage(500));
}
@Override
@@ -64,20 +64,19 @@ public class RegisterService {
}
switch (result){
case 0:
- show("注册失败");
+ handler.sendMessage(handler.obtainMessage(500));
break;
case 1:
- show("注册成功");
handler.sendMessage(handler.obtainMessage(200));
break;
case 2:
- show("账号已存在");
+ handler.sendMessage(handler.obtainMessage(301));
break;
case 3:
- show("用户名已存在");
+ handler.sendMessage(handler.obtainMessage(302));
break;
default:
- show(getClass().getName()+"非法result");
+
}
}
});
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
index 36b0d28..1c551dc 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
@@ -57,6 +57,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
btnConfirm.setOnClickListener(this);
SharedPreferences sharedPreferences=getSharedPreferences("login",0);
int account=sharedPreferences.getInt("account",0);
+ Log.e(TAG, "initView: "+account );
etName.setText(account==0?"":String.valueOf(account));
if(sharedPreferences.getBoolean("rememberPsw",false)){
cbRm.setChecked(true);
@@ -72,6 +73,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
case R.id.login_btn_register:
Intent intent=new Intent(context,RegisterActivity.class);
startActivity(intent);
+ finish();
break;
default:
System.out.println("点击事件没有注册事件");
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
index fc362d8..f55343c 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
@@ -2,6 +2,8 @@ package com.moyv.schoolbbs.ui.activity;
import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -14,6 +16,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.config.AccountConstant;
import com.moyv.schoolbbs.service.RegisterService;
import static com.moyv.schoolbbs.util.ToastUtils.init;
@@ -31,58 +34,82 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
private EditText etAgainPsw;
private Button btnRegister;
private Context context;
+ private int account;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
- context=this;
+ context = this;
intiView();
checkLegal();
}
- public void intiView(){
+
+ public void intiView() {
init(this);
- etName =findViewById(R.id.register_et_name);
- etAccount =findViewById(R.id.register_et_account);
- etPassword =findViewById(R.id.register_et_password);
- etAgainPsw =findViewById(R.id.register_et_againPsw);
- btnRegister=findViewById(R.id.register_btn_register);
+ etName = findViewById(R.id.register_et_name);
+ etAccount = findViewById(R.id.register_et_account);
+ etPassword = findViewById(R.id.register_et_password);
+ etAgainPsw = findViewById(R.id.register_et_againPsw);
+ btnRegister = findViewById(R.id.register_btn_register);
btnRegister.setOnClickListener(this);
}
- public void checkLegal(){
+ public void checkLegal() {
// 验证输入合法性
}
+
@Override
public void onClick(View v) {
- switch (v.getId()){
+ switch (v.getId()) {
case R.id.register_btn_register:
- String name=etName.getText().toString();
- int account=Integer.parseInt(etAccount.getText().toString());
- String password=etPassword.getText().toString();
- String pswAgain=etAgainPsw.getText().toString();
- if(!password.equals(pswAgain)){
+ String name = etName.getText().toString();
+
+ account = Integer.parseInt(etAccount.getText().toString());
+ String password = etPassword.getText().toString();
+ String pswAgain = etAgainPsw.getText().toString();
+ if (!password.equals(pswAgain)) {
show("两次输入的密码不一样");
- }else{
- RegisterService registerService=new RegisterService();
- registerService.register(account,name,password,handler);
+ } else {
+ RegisterService registerService = new RegisterService();
+ registerService.register(account, name, password, handler);
}
break;
default:
}
}
- Handler handler=new Handler(new Handler.Callback() {
+ Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
- ((Activity)context).finish();
+ show("注册成功");
+ SharedPreferences sharedPreferences=getSharedPreferences("login",0);
+ SharedPreferences.Editor editor=sharedPreferences.edit();
+ editor.putInt("account",account);
+ editor.putBoolean("isLogin",true);
+ new AccountConstant(context);
+ Intent intent=new Intent(context,LoginActivity.class);
+ startActivity(intent);
+ finish();
+ break;
+ case 500:
+ show("注册失败");
+ break;
+ case 301:
+ show("账号已存在");
+ break;
+ case 302:
+ show("用户名已存在");
+ break;
+ case 404:
+ show(getClass().getName()+"连接服务器失败");
break;
default:
- System.out.println("handler接收出错");
+ show(getClass().getName()+"非法result");
}
return false;
}
--
Gitee
From 679859e4e318fee15c88167d0c5b3895ed87b496 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Tue, 22 Jun 2021 14:01:59 +0800
Subject: [PATCH 6/9] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=EF=BC=88=E8=AF=84=E8=AE=BA?=
=?UTF-8?q?=E6=97=B6=E8=BE=93=E5=85=A5=E6=A1=86=E8=A2=AB=E8=BE=93=E5=85=A5?=
=?UTF-8?q?=E6=B3=95=E9=A1=B6=E4=B8=8A=E5=8E=BB=E6=97=B6=E5=B8=83=E5=B1=80?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=E8=BF=98=E6=B2=A1=E6=9C=89=E8=A7=A3=E5=86=B3?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/inspectionProfiles/Project_Default.xml | 61 +++
.idea/smartfox_info.xml | 6 +
app/src/main/AndroidManifest.xml | 3 +-
.../schoolbbs/config/AccountConstant.java | 4 +
.../java/com/moyv/schoolbbs/pojo/Comment.java | 1 +
.../moyv/schoolbbs/pojo/HandlerPosition.java | 23 +
.../moyv/schoolbbs/service/CmtService.java | 31 +-
.../moyv/schoolbbs/service/StarService.java | 6 +-
.../ui/activity/ManagerActivity.java | 16 +-
.../schoolbbs/ui/adapter/DataAdapter.java | 457 +++++++++++-------
.../schoolbbs/ui/fragment/HomeFragment.java | 34 +-
.../moyv/schoolbbs/ui/view/CommentsView.java | 10 +-
.../schoolbbs/ui/view/LikePopupWindow.java | 92 ++++
.../view/OnPraiseOrCommentClickListener.java | 15 +
.../moyv/schoolbbs/util/KeyboardUtils.java | 127 +++++
.../main/res/anim/photo_dialog_in_anim.xml | 11 +
.../main/res/anim/photo_dialog_out_anim.xml | 12 +
app/src/main/res/anim/push_bottom_in.xml | 11 +
app/src/main/res/anim/push_bottom_out.xml | 11 +
.../res/drawable/comments_drawable_white.xml | 11 +
.../res/drawable/heart_drawable_white.xml | 11 +
.../selector_praise_or_comment_left_bg.xml | 15 +
.../selector_praise_or_comment_right_bg.xml | 15 +
app/src/main/res/drawable/shape_comment.xml | 24 +
.../main/res/drawable/shape_comment_bg.xml | 11 +
app/src/main/res/drawable/shape_remind.xml | 5 +
app/src/main/res/layout/dialog_like.xml | 59 +++
app/src/main/res/layout/fragment_main.xml | 45 ++
.../main/res/layout/item_fragment_main.xml | 134 ++---
app/src/main/res/values/themes.xml | 4 +
30 files changed, 1005 insertions(+), 260 deletions(-)
create mode 100644 .idea/smartfox_info.xml
create mode 100644 app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/LikePopupWindow.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/OnPraiseOrCommentClickListener.java
create mode 100644 app/src/main/res/anim/photo_dialog_in_anim.xml
create mode 100644 app/src/main/res/anim/photo_dialog_out_anim.xml
create mode 100644 app/src/main/res/anim/push_bottom_in.xml
create mode 100644 app/src/main/res/anim/push_bottom_out.xml
create mode 100644 app/src/main/res/drawable/comments_drawable_white.xml
create mode 100644 app/src/main/res/drawable/heart_drawable_white.xml
create mode 100644 app/src/main/res/drawable/selector_praise_or_comment_left_bg.xml
create mode 100644 app/src/main/res/drawable/selector_praise_or_comment_right_bg.xml
create mode 100644 app/src/main/res/drawable/shape_comment.xml
create mode 100644 app/src/main/res/drawable/shape_comment_bg.xml
create mode 100644 app/src/main/res/drawable/shape_remind.xml
create mode 100644 app/src/main/res/layout/dialog_like.xml
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 6560a98..fa99c1b 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -1,6 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -32,5 +92,6 @@
+
\ No newline at end of file
diff --git a/.idea/smartfox_info.xml b/.idea/smartfox_info.xml
new file mode 100644
index 0000000..1c2584f
--- /dev/null
+++ b/.idea/smartfox_info.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 0676b5f..11e5e63 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,7 +21,8 @@
+ android:windowSoftInputMode="adjustPan|stateHidden"
+ >
diff --git a/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java b/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
index 65bf59c..9f828df 100644
--- a/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
+++ b/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
@@ -10,12 +10,16 @@ public class AccountConstant {
public static boolean LOGIN;
public static int ACCOUNT;
public static String TOKEN;
+ public static String NAME;
+ public static String INTRODUCTION;
public AccountConstant(Context context){
SharedPreferences sharedPreferences=context.getSharedPreferences("login",0);
LOGIN=sharedPreferences.getBoolean("isLogin",false);
if(LOGIN){
ACCOUNT=sharedPreferences.getInt("account",0);
TOKEN=sharedPreferences.getString("token","");
+ NAME=sharedPreferences.getString("name","");
+ INTRODUCTION=sharedPreferences.getString("introduction","");
}
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java b/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
index 0f81fc6..c3e6328 100644
--- a/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
@@ -21,6 +21,7 @@ public class Comment {
private String cmtName;
private UserInfo replyUser; // 回复人信息
+
private UserInfo commentsUser; // 评论人信息
public UserInfo getReplyUser() {
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java b/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java
new file mode 100644
index 0000000..4b13e90
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java
@@ -0,0 +1,23 @@
+package com.moyv.schoolbbs.pojo;
+
+public class HandlerPosition {
+ private int position;
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+
+ public Object getObj() {
+ return obj;
+ }
+
+ public void setObj(Object obj) {
+ this.obj = obj;
+ }
+
+ private Object obj;
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java b/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
index f10ac98..6d0c324 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
@@ -4,6 +4,7 @@ import android.os.Handler;
import android.util.Log;
import com.moyv.schoolbbs.pojo.Comment;
+import com.moyv.schoolbbs.pojo.HandlerPosition;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
@@ -23,9 +24,10 @@ import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.CMT_URL;
import static com.moyv.schoolbbs.config.URLConstant.MAIN_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
+import static com.moyv.schoolbbs.util.JsonUtil.parseJson;
public class CmtService {
- public void pushCmt(Comment comment, Handler handler){
+ public void pushCmt(Comment comment, Handler handler,int position){
String url=CMT_URL;
OkHttpClient okHttpClient=createClient();
// 请求体
@@ -57,12 +59,29 @@ public class CmtService {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
String responseData=response.body().string();
- System.out.println(responseData);
- if(responseData.equals("1")){
- handler.sendMessage(handler.obtainMessage(0));
- }else{
- handler.sendMessage(handler.obtainMessage(505));
+ JSONObject object= null;
+ JSONObject objComment=null;
+ int result=0;
+ try {
+ object = new JSONObject(responseData);
+ result=object.getInt("result");
+ System.out.println(object);
+ if(result==1){
+
+ objComment=object.getJSONObject("comment");
+ System.out.println(objComment);
+ Comment comment1=parseJson(objComment.toString(),Comment.class);
+ HandlerPosition handlerPosition=new HandlerPosition();
+ handlerPosition.setObj(comment1);
+ handlerPosition.setPosition(position);
+ handler.sendMessage(handler.obtainMessage(0,handlerPosition));
+ }else{
+ handler.sendMessage(handler.obtainMessage(505));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
}
+
}
});
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/StarService.java b/app/src/main/java/com/moyv/schoolbbs/service/StarService.java
index 7b9c3e6..eab23ca 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/StarService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/StarService.java
@@ -28,7 +28,7 @@ import static com.moyv.schoolbbs.util.HttpUtil.createClient;
* @author moyv
*/
public class StarService {
- public void pushStar(int postId, Handler handler,int type){
+ public void pushStar(int postId, Handler handler,int type,int index){
String url=STAR_URL;
OkHttpClient okHttpClient=createClient();
// 请求体
@@ -68,9 +68,9 @@ public class StarService {
}
System.out.println(responseData);
if(1==result){
- handler.sendMessage(handler.obtainMessage(200));
+ handler.sendMessage(handler.obtainMessage(200,index));
}else if(2==result){
- handler.sendMessage(handler.obtainMessage(201));
+ handler.sendMessage(handler.obtainMessage(201,index));
}else if(3==result){
handler.sendMessage(handler.obtainMessage(302));
}else{
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
index 0f8f1ed..eee6b67 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
@@ -6,6 +6,9 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -16,6 +19,7 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.tabs.TabLayout;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.bean.ReModel;
import com.moyv.schoolbbs.pojo.Item;
@@ -50,6 +54,11 @@ public class ManagerActivity extends AppCompatActivity {
private int count;
private int type;
+
+ private LinearLayout llComment;
+ private EditText etComment1;
+ private TabLayout tabLayout;
+ private TextView tvSend;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -61,6 +70,11 @@ public class ManagerActivity extends AppCompatActivity {
Intent intent=getIntent();
type=intent.getIntExtra("type",USER_POSTS);
recyclerView =findViewById(R.id.manager_recycler_view);
+ llComment = findViewById(R.id.ll_comment);
+ etComment1=findViewById(R.id.et_comment);
+ tabLayout=findViewById(R.id.bottom_tab_layout);
+ tvSend=findViewById(R.id.tv_send_comment);
+
init(mContext);
@@ -141,7 +155,7 @@ public class ManagerActivity extends AppCompatActivity {
}
// 显示帖子列表
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
- adapter = new DataAdapter(mContext,items);
+ adapter = new DataAdapter(mContext,items,llComment, etComment1,tabLayout,tvSend);
adapter.type=MANAGER;
Log.i("TAG", "handleMessage: "+items.size());
recyclerView.setAdapter(adapter);
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
index 71577ae..ec29a6f 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
@@ -1,6 +1,9 @@
package com.moyv.schoolbbs.ui.adapter;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
@@ -15,6 +18,7 @@ import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
@@ -30,33 +34,45 @@ import com.google.android.material.tabs.TabLayout;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.base.Global;
import com.moyv.schoolbbs.pojo.Comment;
+import com.moyv.schoolbbs.pojo.HandlerPosition;
import com.moyv.schoolbbs.pojo.Item;
import com.moyv.schoolbbs.pojo.Star;
import com.moyv.schoolbbs.service.CmtService;
import com.moyv.schoolbbs.service.StarService;
+import com.moyv.schoolbbs.ui.activity.BottomTabLayoutActivity;
import com.moyv.schoolbbs.ui.view.CommentsView;
import com.moyv.schoolbbs.ui.view.ExpandTextView;
+import com.moyv.schoolbbs.ui.view.LikePopupWindow;
+import com.moyv.schoolbbs.ui.view.OnPraiseOrCommentClickListener;
import com.moyv.schoolbbs.ui.view.PraiseListView;
import com.moyv.schoolbbs.util.KeyboardUtils;
+import com.moyv.schoolbbs.util.ToastUtils;
import com.wang.avi.AVLoadingIndicatorView;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import static android.content.ContentValues.TAG;
import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.config.AccountConstant.NAME;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
+import static com.moyv.schoolbbs.util.ToastUtils.show;
public class DataAdapter extends RecyclerView.Adapter {
public Context context;
private List- postList;
+ //评论框
+ private EditText etComment;
+ private LinearLayout llComment;
+ private ViewHolder recyclerViewHolder;
+
+ private int isLike=0;
+ private TextView tvSend;
+
private String commentStr;
- private List
comments;
- private List cmtName;
- private int cmtCount;
- private List cbStars = new ArrayList<>();
// type有两个值,区别主页显示和管理显示
public static int MAIN = 202;
public static int MANAGER = 303;
@@ -79,9 +95,12 @@ public class DataAdapter extends RecyclerView.Adapter {
// 防止重复加载
List positions = new ArrayList<>();
- public DataAdapter(Context context, List- postList) {
+ public DataAdapter(Context context, List
- postList, LinearLayout llComment, EditText etComment, TabLayout tabLayout, TextView tvSend) {
this.context = context;
this.postList = postList;
+ this.etComment = etComment;
+ this.llComment = llComment;
+ this.tvSend = tvSend;
}
@NonNull
@@ -112,11 +131,8 @@ public class DataAdapter extends RecyclerView.Adapter
{
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolder) {
- Log.d(TAG, "onBindViewHolder: ViewHolder");
- Log.d(TAG, "onBindViewHolder: position:" + position);
-
- ViewHolder recyclerViewHolder = (ViewHolder) holder;
- cmtCount = 0;
+ recyclerViewHolder = (ViewHolder) holder;
+ isLike = postList.get(position).getMain().getStars().size();
String name = postList.get(position).getMain().getUserInfo().getName();
String introduction = postList.get(position).getMain().getUserInfo().getIntroduction() == null ? "" : postList.get(position).getMain().getUserInfo().getIntroduction();
String Date = postList.get(position).getMain().getPost().getProTimer();
@@ -124,8 +140,25 @@ public class DataAdapter extends RecyclerView.Adapter {
recyclerViewHolder.tvUser.setText(name);
recyclerViewHolder.tvIntro.setText(introduction);
-// 判断是否有删除键
+ recyclerViewHolder.ivEdit.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ //评论弹框
+ Log.e(TAG, "onClick: "+position );
+ showLikePopupWindow(v, position ,recyclerViewHolder);
+ tvSend.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ getComment(recyclerViewHolder, position);
+ }
+ });
+ }
+ });
+
+
+// 判断是否有删除键
if (type == MANAGER) {
+ recyclerViewHolder.ivEdit.setVisibility(View.GONE);
recyclerViewHolder.tvDelete.setVisibility(View.VISIBLE);
recyclerViewHolder.tvDelete.setOnClickListener(new View.OnClickListener() {
@Override
@@ -135,7 +168,7 @@ public class DataAdapter extends RecyclerView.Adapter {
});
}
-// 显示发表时间
+// 显示发表时间
recyclerViewHolder.tvDate.setText(Date);
// 帖子文字内容
if (content.length() == 0) {
@@ -148,165 +181,55 @@ public class DataAdapter extends RecyclerView.Adapter {
recyclerViewHolder.expandTextView.setText(content);
}
-
- //点击评论图标获取edittext焦点
- recyclerViewHolder.ivCmt.setOnClickListener(
- new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Log.e("onClick: ", "获取焦点");
- if (recyclerViewHolder.etCmt.isFocused()) {
- } else {
- recyclerViewHolder.etCmt.requestFocus();
- recyclerViewHolder.etCmt.setFocusableInTouchMode(true);
- InputMethodManager inputManager =
- (InputMethodManager) recyclerViewHolder.etCmt.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- inputManager.showSoftInput(recyclerViewHolder.etCmt, 0);
- }
- }
- });
-// 评论功能实现
- recyclerViewHolder.ivSend.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //判断是否登录
- if (LOGIN) {
- //取出评论
- commentStr = recyclerViewHolder.etCmt.getText().toString().trim();
- // 评论发布
- Handler handler1 = new Handler(new Handler.Callback() {
- @Override
- public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what) {
- case 0:
- Toast.makeText(context, "成功评论", Toast.LENGTH_SHORT).show();
- addCmt("me", commentStr, recyclerViewHolder.lyCmt);
- recyclerViewHolder.etCmt.setText("");
- break;
- case 404:
- Toast.makeText(context, "没有找到服务器", Toast.LENGTH_SHORT).show();
- break;
- case 505:
- Toast.makeText(context, "评论失败", Toast.LENGTH_SHORT).show();
- ;
- default:
- break;
- }
- return false;
- }
- });
- if (TextUtils.isEmpty(commentStr)) {
- Toast.makeText(context, "评论内容不能为空", Toast.LENGTH_SHORT).show();
- } else {
- Comment comment = new Comment();
- comment.setCommentContent(commentStr);
- comment.setCommentAccount(ACCOUNT);
- comment.setPostId(postList.get(position).getMain().getPost().getPostId());
- CmtService cmtService = new CmtService();
- cmtService.pushCmt(comment, handler1);
- recyclerViewHolder.etCmt.clearFocus();//失去焦点
-// 隐藏软键盘
- KeyboardUtils.hideKeyboard(context);
- }
- } else {
- Toast.makeText(context, "请先登录", Toast.LENGTH_SHORT).show();
- }
-
- }
- });
- comments = postList.get(position).getMain().getComments();
- cmtName = new ArrayList<>();
- removeCmt(recyclerViewHolder.lyCmt);
- for (Comment comment : comments) {
- addCmt(comment.getCmtName(), comment.getCommentContent(), recyclerViewHolder.lyCmt);
+ if ((postList.get(position).getMain().getStars() != null && postList.get(position).getMain().getStars().size() > 0) && (postList.get(position).getMain().getComments() != null && postList.get(position).getMain().getComments().size() > 0)) {
+ recyclerViewHolder.viewLike.setVisibility(View.VISIBLE);
+ } else {
+ recyclerViewHolder.viewLike.setVisibility(View.GONE);
}
+ if ((postList.get(position).getMain().getStars() != null && postList.get(position).getMain().getStars().size() > 0) || (postList.get(position).getMain().getComments() != null && postList.get(position).getMain().getComments().size() > 0)) {
+ recyclerViewHolder.llLike.setVisibility(View.VISIBLE);
+ if (postList.get(position).getMain().getStars() != null && postList.get(position).getMain().getStars().size() > 0) {
+ recyclerViewHolder.rvLike.setVisibility(View.VISIBLE);
+ recyclerViewHolder.rvLike.setDatas(postList.get(position).getMain().getStars());
+ } else {
+ recyclerViewHolder.rvLike.setVisibility(View.GONE);
+ }
-
-// 点赞功能实现
- recyclerViewHolder.btnStar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
-// 只有手动点击才会执行点赞事件
- if (!buttonView.isPressed()) {
- return;
- }
-// 判断是否已经登录
- if (LOGIN) {
- Handler handler = new Handler(new Handler.Callback() {
- @Override
- public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what) {
- case 200:
- Log.d(TAG, "handleMessage: 点赞成功");
- recyclerViewHolder.btnStar.setChecked(true);
- break;
- case 201:
- Log.d(TAG, "handleMessage: 取消点赞成功");
- recyclerViewHolder.btnStar.setChecked(false);
- break;
- case 302:
- recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- Toast.makeText(context, "已经点过赞了", Toast.LENGTH_SHORT).show();
- break;
- case 404:
- recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- Toast.makeText(context, "网络连接失败", Toast.LENGTH_SHORT).show();
- break;
- case 500:
- recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- Toast.makeText(context, "操作失败", Toast.LENGTH_SHORT).show();
- break;
- default:
- recyclerViewHolder.btnStar.setChecked(!recyclerViewHolder.btnStar.isChecked());
- System.out.println("返回错误");
- }
- return false;
- }
- });
- if (isChecked) {
- StarService starService = new StarService();
-// starService.pushStar(postList.get(position).getMain().getPost().getPostId(),handler,1);
- Log.e(TAG, "onCheckedChanged: 点赞事件");
+ if (postList.get(position).getMain().getComments() != null && postList.get(position).getMain().getComments().size() > 0) {
+ recyclerViewHolder.rvComment.setVisibility(View.VISIBLE);
+ recyclerViewHolder.rvComment.setList(postList.get(position).getMain().getComments());
+ recyclerViewHolder.rvComment.setOnCommentListener((posit, bean, user_id) -> {
+ etComment.setText("");
+ //如果当前用户id和评论用户id相同则删除
+ if (bean.getCommentsUser().getAccount()==ACCOUNT) {
+ showDeletePopWindow(recyclerViewHolder.rvComment, bean.getCommentId(), recyclerViewHolder.getLayoutPosition() - 1, posit);
+ llComment.setVisibility(View.GONE);
} else {
- StarService starService = new StarService();
-// starService.pushStar(postList.get(position).getMain().getPost().getPostId(),handler,-1);
- Log.e(TAG, "onCheckedChanged: 取消点赞事件");
+ //不相同回复
+ llComment.setVisibility(View.VISIBLE);
+ etComment.setHint("回复:" + bean.getCommentsUser().getName());
+ if (View.VISIBLE == llComment.getVisibility()) {
+ llComment.requestFocus();
+ //弹出键盘
+ KeyboardUtils.showSoftInput(etComment.getContext(), etComment);
+ } else if (View.GONE == llComment.getVisibility()) {
+ //隐藏键盘
+ KeyboardUtils.hideSoftInput(etComment.getContext(), etComment);
+ }
+// if (click != null) {
+// //由于真实项目中有头部所以position-1
+// click.Commend(recyclerViewHolder.getLayoutPosition(), bean);
+// }
}
- }
-
-
- }
- });
- List stars = postList.get(position).getMain().getStars();
- int starCount = stars.size();
- System.out.println(starCount);
- String starInfo = "";
- for (int i = 0; i < starCount; i++) {
- Star star = stars.get(i);
- String starName = star.getName();
-// 判断本机用户是否点赞
- int account = ACCOUNT;
- if (star.getStarAccount() == account) {
- starName = "你";
- recyclerViewHolder.btnStar.setChecked(true);
- Log.e(TAG, "onBindViewHolder: 执行了");
- }
- starInfo += starName;
- if (i != starCount - 1) {
- starInfo += "、";
+ });
+ recyclerViewHolder.rvComment.notifyDataSetChanged();
+ } else {
+ recyclerViewHolder.rvComment.setVisibility(View.GONE);
}
- }
- if (starCount == 0) {
- recyclerViewHolder.tvStar.setText("");
- recyclerViewHolder.rvLike.setVisibility(View.GONE);
} else {
- recyclerViewHolder.rvLike.setVisibility(View.VISIBLE);
- recyclerViewHolder.rvLike.setDatas(postList.get(position).getMain().getStars());
- starInfo += "共计" + stars.size() + "个赞";
- recyclerViewHolder.tvStar.setText(starInfo);
+ recyclerViewHolder.llLike.setVisibility(View.GONE);
}
-
// 头像显示
String headUrl = IMAGE_URL + "/head/" + postList.get(position).getMain().getPost().getPostAccount() + ".jpg";
Glide.with(context)
@@ -383,9 +306,21 @@ public class DataAdapter extends RecyclerView.Adapter {
}
+ private void showDeletePopWindow(View view, int id, int layoutPosition, int position) {
+// View contentView = getPopupWindowContentView(id, layoutPosition, position);
+// mPopupWindow = new PopupWindow(contentView,
+// ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
+// // 如果不设置PopupWindow的背景,有些版本就会出现一个问题:无论是点击外部区域还是Back键都无法dismiss弹框
+// mPopupWindow.setBackgroundDrawable(new ColorDrawable());
+// // 设置好参数之后再show
+// int[] windowPos = PopupWindowUtil.calculatePopWindowPos(view, contentView, x, y);
+// mPopupWindow.showAsDropDown(view, 0, -40, windowPos[1]);
+// mPopupWindow.setFocusable(true);
+// mPopupWindow.setOutsideTouchable(true);
+ }
+
// 刷新数据
public void refreshView(List- postList) {
- cmtCount = 0;
this.postList = postList;
notifyDataSetChanged();
}
@@ -435,6 +370,172 @@ public class DataAdapter extends RecyclerView.Adapter
{
notifyDataSetChanged();
}
+ /**
+ * 获取控件左上顶点Y坐标
+ *
+ * @param view
+ * @return
+ */
+ private int getCoordinateY(View view) {
+ int[] coordinate = new int[2];
+ view.getLocationOnScreen(coordinate);
+ return coordinate[1];
+ }
+
+ private void showLikePopupWindow(View view, int position,ViewHolder recyclerViewHolder) {
+ LikePopupWindow likePopupWindow=recyclerViewHolder.likePopupWindow;
+ List list = postList.get(position).getMain().getStars();
+ // 判断用户是否已经点赞
+ for (Star star : list) {
+ isLike = star.getName().equals(NAME) ? 1 : 0;
+ if (isLike == 1) {
+ break;
+ }
+ }
+ likePopupWindow.setTextView(isLike);
+ likePopupWindow.setOnPraiseOrCommentClickListener(new OnPraiseOrCommentClickListener() {
+ @Override
+ public void onPraiseClick(int position) {
+ //调用点赞接口
+ getLikeData(position);
+ likePopupWindow.dismiss();
+ }
+
+ @Override
+ public void onCommentClick(int position) {
+ llComment.setVisibility(View.VISIBLE);
+ etComment.requestFocus();
+ etComment.setHint("说点什么");
+ KeyboardUtils.showSoftInput(context);
+ likePopupWindow.dismiss();
+ etComment.setText("");
+ }
+
+ @Override
+ public void onClickFrendCircleTopBg() {
+
+ }
+
+ @Override
+ public void onDeleteItem(String id, int position) {
+
+ }
+
+ }).setTextView(isLike).setCurrentPosition(position);
+ if (likePopupWindow.isShowing()) {
+ likePopupWindow.dismiss();
+ } else {
+ likePopupWindow.showPopupWindow(view);
+ }
+ }
+
+ public void getLikeData(int postion) {
+ // 判断是否已经登录
+
+ if (LOGIN) {
+ Handler handler = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(@NonNull Message msg) {
+ switch (msg.what) {
+ case 200:
+ show("点赞成功");
+ Integer index=(Integer) msg.obj;
+ List stars=postList.get(index).getMain().getStars();
+ Star star=new Star();
+ star.setName(NAME);
+ stars.add(star);
+ notifyDataSetChanged();
+ break;
+ case 201:
+ Log.d(TAG, "handleMessage: 取消点赞成功");
+ show("取消点赞成功");
+ Integer index1=(Integer) msg.obj;
+ List stars1=postList.get(index1).getMain().getStars();
+ List likeListBeans1=new ArrayList<>();
+ Iterator it1 = stars1.iterator();
+ while (it1.hasNext()) {
+ Star info = (Star) it1.next();
+ if (String.valueOf(info.getName()).equals(String.valueOf(NAME))) {
+ it1.remove();
+ } else {
+ likeListBeans1.add(info);
+ }
+ }
+ postList.get(index1).getMain().setStars(likeListBeans1);
+ notifyDataSetChanged();
+ break;
+ case 302:
+ Toast.makeText(context, "已经点过赞了", Toast.LENGTH_SHORT).show();
+ break;
+ case 404:
+ Toast.makeText(context, "网络连接失败", Toast.LENGTH_SHORT).show();
+ break;
+ case 500:
+ Toast.makeText(context, "操作失败", Toast.LENGTH_SHORT).show();
+ break;
+ default:
+ System.out.println("返回错误");
+ }
+ return false;
+ }
+ });
+ StarService starService=new StarService();
+ starService.pushStar(postList.get(postion).getMain().getPost().getPostId(),handler,isLike,postion);
+ }
+
+ }
+
+ public void getComment(ViewHolder recyclerViewHolder, int position) {
+ //判断是否登录
+ if (LOGIN) {
+ //取出评论
+ commentStr = etComment.getText().toString().trim();
+ // 评论发布
+ Handler handler1 = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(@NonNull Message msg) {
+ switch (msg.what) {
+ case 0:
+ Toast.makeText(context, "成功评论", Toast.LENGTH_SHORT).show();
+ HandlerPosition handlerPosition=(HandlerPosition)msg.obj;
+ int index=handlerPosition.getPosition();
+ Comment comment=(Comment) handlerPosition.getObj();
+ comment.setCmtName(NAME);
+ postList.get(index).getMain().getComments().add(comment);
+// 打印返回的comment对象
+ Log.d(TAG, "handleMessage: "+comment.getCmtName());
+ notifyDataSetChanged();
+ break;
+ case 404:
+ Toast.makeText(context, "没有找到服务器", Toast.LENGTH_SHORT).show();
+ break;
+ case 505:
+ Toast.makeText(context, "评论失败", Toast.LENGTH_SHORT).show();
+ ;
+ default:
+ break;
+ }
+ return false;
+ }
+ });
+ if (TextUtils.isEmpty(commentStr)) {
+ Toast.makeText(context, "评论内容不能为空", Toast.LENGTH_SHORT).show();
+ } else {
+ Comment comment = new Comment();
+ comment.setCommentContent(commentStr);
+ comment.setCommentAccount(ACCOUNT);
+// 打印position
+ Log.d(TAG, "getComment: "+position);
+ comment.setPostId(postList.get(position).getMain().getPost().getPostId());
+ CmtService cmtService = new CmtService();
+ cmtService.pushCmt(comment, handler1,position);
+ }
+ } else {
+ Toast.makeText(context, "请先登录", Toast.LENGTH_SHORT).show();
+ }
+ KeyboardUtils.hideSoftInput((Activity) context);
+ llComment.setVisibility(View.GONE);
+ }
// 删除指定postion
// 删除数据
@@ -447,40 +548,38 @@ public class DataAdapter extends RecyclerView.Adapter {
public static class ViewHolder extends RecyclerView.ViewHolder {
public RecyclerView rvImages;
+ public View viewLike;
+ public LinearLayout llLike;
public TextView tvUser, tvCnt, tvDate, tvCmt, tvIntro, tvStar, tvCmtName;
- public EditText etCmt;
- public ImageView ivCmt;
- public ImageView ivSend;
public ImageView ivHead;
- public LinearLayout lyCmt;
public TabLayout tab;
public FloatingActionButton btnFlt;
- public CheckBox btnStar;
public TextView tvDelete;
public ExpandTextView expandTextView;
public PraiseListView rvLike;
public CommentsView rvComment;
+ public ImageView ivEdit;
+ public LikePopupWindow likePopupWindow;
public ViewHolder(@NonNull View itemView) {
super(itemView);
-// tvCnt = itemView.findViewById(R.id.tv_content);
rvImages = itemView.findViewById(R.id.rv_post_images);
tvUser = itemView.findViewById(R.id.tv_user);
tvDate = itemView.findViewById(R.id.tv_date);
tvCmt = itemView.findViewById(R.id.tv_cmt);
tvIntro = itemView.findViewById(R.id.tv_user_introduction);
- etCmt = itemView.findViewById(R.id.et_cmt);
- ivCmt = itemView.findViewById(R.id.iv_cmt);
- lyCmt = itemView.findViewById(R.id.layout_cmt);
- ivSend = itemView.findViewById(R.id.iv_send);
tvStar = itemView.findViewById(R.id.tv_star);
tab = itemView.findViewById(R.id.bottom_tab_layout);
btnFlt = itemView.findViewById(R.id.btn_float);
- btnStar = itemView.findViewById(R.id.btn_star);
ivHead = itemView.findViewById(R.id.iv_head);
tvDelete = itemView.findViewById(R.id.tv_delete);
- expandTextView=itemView.findViewById(R.id.tv_content);
- rvLike=itemView.findViewById(R.id.rv_like);
+ expandTextView = itemView.findViewById(R.id.tv_content);
+ rvLike = itemView.findViewById(R.id.rv_like);
+ viewLike = itemView.findViewById(R.id.view_like);
+ llLike = itemView.findViewById(R.id.ll_like_comment);
+ rvComment = itemView.findViewById(R.id.rv_comment);
+ ivEdit = itemView.findViewById(R.id.iv_edit);
+ likePopupWindow=new LikePopupWindow(itemView.getContext());
}
}
@@ -497,4 +596,8 @@ public class DataAdapter extends RecyclerView.Adapter {
llEnd = itemView.findViewById(R.id.ll_end);
}
}
+
+ public interface Click {
+ void Commend(int position, Comment bean);//回复评论
+ }
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
index f648975..c02b9a4 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
@@ -9,6 +9,9 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.EditText;
+import android.widget.LinearLayout;
+import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -19,8 +22,10 @@ import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.google.android.material.tabs.TabLayout;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.bean.ReModel;
+import com.moyv.schoolbbs.pojo.Comment;
import com.moyv.schoolbbs.pojo.Item;
import com.moyv.schoolbbs.service.MainService;
import com.moyv.schoolbbs.ui.activity.AddActivity;
@@ -39,7 +44,7 @@ import static com.moyv.schoolbbs.ui.adapter.DataAdapter.MAIN;
/**
* @author moyv
*/
-public class HomeFragment extends Fragment {
+public class HomeFragment extends Fragment implements DataAdapter.Click{
private static final int SUCCESS = 0;
@@ -54,6 +59,15 @@ public class HomeFragment extends Fragment {
// 帖子总数
private int count;
+ private LinearLayout llComment;
+ private EditText etComment1;
+ private TabLayout tabLayout;
+ private TextView tvSend;
+ private int to_user_id;
+ private String to_user_name;
+ private int circle_id;
+ private int commentPosition;
+
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@@ -66,6 +80,14 @@ public class HomeFragment extends Fragment {
btnFlt = root.findViewById(R.id.btn_float);
+ llComment=root.findViewById(R.id.ll_comment);
+
+ etComment1=root.findViewById(R.id.et_comment);
+
+ tvSend = root.findViewById(R.id.tv_send_comment);
+
+ tabLayout=root.findViewById(R.id.bottom_tab_layout);
+
init(mContext);
swiperefreshlayout = root.findViewById(R.id.swiperefreshlayout);
@@ -168,7 +190,7 @@ public class HomeFragment extends Fragment {
}
// 显示帖子列表
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
- adapter = new DataAdapter(mContext,items);
+ adapter = new DataAdapter(mContext,items,llComment, etComment1, tabLayout,tvSend);
adapter.type=MAIN;
Log.i("TAG", "handleMessage: "+items.size());
recyclerView.setAdapter(adapter);
@@ -243,4 +265,12 @@ public class HomeFragment extends Fragment {
return false;
}
});
+
+ @Override
+ public void Commend(int position, Comment bean) {
+ circle_id = bean.getPostId();
+ commentPosition = position;
+ to_user_name = bean.getCmtName();
+ to_user_id = bean.getCommentAccount();
+ }
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java
index f1f3556..5d70f70 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/CommentsView.java
@@ -92,9 +92,9 @@ public class CommentsView extends LinearLayout {
}
replyUser = item.getReplyUser();
boolean hasReply = false; // 是否有回复
- if (replyUser != null) {
- hasReply = true;
- }
+// if (replyUser != null) {
+// hasReply = true;
+// }
TextView textView = new TextView(mContext);
textView.setTextSize(15);
textView.setTextColor(0xff686868);
@@ -107,9 +107,9 @@ public class CommentsView extends LinearLayout {
item.setCommentsUser(userComBean);
}
- UserInfo comUser = item.getCommentsUser();
+// UserInfo comUser = item.getCommentsUser();
- String name = comUser.getName();
+ String name = item.getCmtName();
if (hasReply) {
builder.append(setClickableSpan(name, item.getCommentsUser()));
builder.append("回复");
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/LikePopupWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/LikePopupWindow.java
new file mode 100644
index 0000000..ee937a9
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/LikePopupWindow.java
@@ -0,0 +1,92 @@
+package com.moyv.schoolbbs.ui.view;
+
+import android.content.Context;
+import android.graphics.drawable.ColorDrawable;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.PopupWindow;
+import android.widget.TextView;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.base.Global;
+
+
+public class LikePopupWindow extends PopupWindow implements View.OnClickListener {
+ private Context mContext;
+
+ private OnPraiseOrCommentClickListener mOnPraiseOrCommentClickListener;
+
+ private int mPopupWindowHeight;
+ private int mPopupWindowWidth;
+ private int mCurrentPosition;
+ private TextView commentPopupText;
+
+ public LikePopupWindow(Context context) {
+ View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_like, null);
+ this.setContentView(contentView);
+ contentView.findViewById(R.id.ll_like).setOnClickListener(this);
+ contentView.findViewById(R.id.ll_comment).setOnClickListener(this);
+ //不设置宽高将无法显示popupWindow
+ this.mPopupWindowHeight = Global.dp2px(40);
+ this.mPopupWindowWidth = Global.dp2px(200);
+ this.setHeight(mPopupWindowHeight);
+ this.setWidth(mPopupWindowWidth);
+ // 设置SelectPicPopupWindow弹出窗体可点击
+ this.setFocusable(true);
+ this.setOutsideTouchable(true);
+ //弹出动画
+ this.setAnimationStyle(R.style.anim_push_bottom);
+ // 刷新状态
+ this.update();
+ // 实例化一个ColorDrawable颜色为半透明
+ ColorDrawable dw = new ColorDrawable(0x00000000);
+ this.setBackgroundDrawable(dw);
+ commentPopupText = contentView.findViewById(R.id.tv_like);
+ }
+
+ public LikePopupWindow setCurrentPosition(int currentPosition) {
+ mCurrentPosition = currentPosition;
+ return this;
+ }
+
+ public LikePopupWindow setTextView(int isLike) {
+ commentPopupText.setText(isLike == 0 ? "点赞" : "取消点赞");
+ return this;
+ }
+
+ public LikePopupWindow setOnPraiseOrCommentClickListener(OnPraiseOrCommentClickListener onPraiseOrCommentClickListener) {
+ mOnPraiseOrCommentClickListener = onPraiseOrCommentClickListener;
+ return this;
+ }
+
+ public void showPopupWindow(View anchor) {
+ if (anchor == null) {
+ return;
+ }
+ int[] location = new int[2];
+ anchor.getLocationOnScreen(location);
+ int xOffset = location[0] - mPopupWindowWidth - Global.dp2px(10);
+ int yOffset = location[1] + (anchor.getHeight() - mPopupWindowHeight) / 2;
+ showAtLocation(anchor, Gravity.NO_GRAVITY, xOffset, yOffset);
+ //showAsDropDown(anchor,0,0);
+ Log.e("location", xOffset + " -------------------" + yOffset);
+ }
+
+ @Override
+ public void onClick(View v) {
+ dismiss();
+ int i = v.getId();
+ if (i == R.id.ll_like) {
+ if (mOnPraiseOrCommentClickListener != null) {
+ mOnPraiseOrCommentClickListener.onPraiseClick(mCurrentPosition);
+ }
+
+ } else if (i == R.id.ll_comment) {
+ if (mOnPraiseOrCommentClickListener != null) {
+ mOnPraiseOrCommentClickListener.onCommentClick(mCurrentPosition);
+ }
+ }
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/OnPraiseOrCommentClickListener.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/OnPraiseOrCommentClickListener.java
new file mode 100644
index 0000000..0c5387b
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/OnPraiseOrCommentClickListener.java
@@ -0,0 +1,15 @@
+package com.moyv.schoolbbs.ui.view;
+
+/**
+ * @author zhaojin
+ * @date 2018/8/10
+ */
+public interface OnPraiseOrCommentClickListener {
+ void onPraiseClick(int position);
+
+ void onCommentClick(int position);
+
+ void onClickFrendCircleTopBg();
+
+ void onDeleteItem(String id, int position);
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/util/KeyboardUtils.java b/app/src/main/java/com/moyv/schoolbbs/util/KeyboardUtils.java
index b7db62a..244c9ad 100644
--- a/app/src/main/java/com/moyv/schoolbbs/util/KeyboardUtils.java
+++ b/app/src/main/java/com/moyv/schoolbbs/util/KeyboardUtils.java
@@ -3,6 +3,8 @@ package com.moyv.schoolbbs.util;
import android.app.Activity;
import android.content.Context;
+import android.graphics.Rect;
+import android.view.View;
import android.view.inputmethod.InputMethodManager;
/**
@@ -22,4 +24,129 @@ public class KeyboardUtils {
// 隐藏软键盘
imm.hideSoftInputFromWindow(((Activity)context).getWindow().getDecorView().getWindowToken(), 0);
}
+
+ Activity mContext;
+ /**
+ * 虚拟键盘高度
+ */
+ int virtualKeyboardHeight;
+ /**
+ * 屏幕高度
+ */
+ int screenHeight;
+ /**
+ * 屏幕6分之一的高度,作用是防止获取到虚拟键盘的高度
+ */
+ int screenHeight6;
+ View rootView;
+
+ public KeyboardUtils(Activity context) {
+ this.mContext = context;
+ /**
+ * 获取屏幕的高度,该方式的获取不包含虚拟键盘
+ */
+ screenHeight = mContext.getResources().getDisplayMetrics().heightPixels;
+ screenHeight6 = screenHeight / 6;
+ rootView = mContext.getWindow().getDecorView();
+ }
+
+ /**
+ * @param listener
+ */
+ public void setOnKeyboardChangeListener(final KeyboardChangeListener listener) {
+ //当键盘弹出隐藏的时候会 调用此方法。
+ rootView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
+ /**
+ * 回调该方法时rootView还未绘制,需要设置绘制完成监听
+ */
+ rootView.post(() -> {
+ Rect rect = new Rect();
+ /**
+ * 获取屏幕底部坐标
+ */
+ rootView.getWindowVisibleDisplayFrame(rect);
+ /**
+ * 获取键盘的高度
+ */
+ int heightDifference = screenHeight - rect.bottom;
+ if (heightDifference < screenHeight6) {
+ virtualKeyboardHeight = heightDifference;
+ if (listener != null) {
+ listener.onKeyboardHide();
+ }
+ } else {
+ if (listener != null) {
+ listener.onKeyboardShow(heightDifference - virtualKeyboardHeight);
+ }
+ }
+ });
+ });
+ }
+
+ /**
+ * 软键盘状态切换监听
+ */
+ public interface KeyboardChangeListener {
+ /**
+ * 键盘弹出
+ *
+ * @param keyboardHight 键盘高度
+ */
+ void onKeyboardShow(int keyboardHight);
+
+ /**
+ * 键盘隐藏
+ */
+ void onKeyboardHide();
+ }
+
+ /**
+ * 显示软键盘
+ *
+ * @param context 当前Activity
+ */
+ public static void showSoftInput(Context context) {
+ InputMethodManager inputMethodManager =
+ (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
+ }
+
+ /**
+ * 隐藏软键盘
+ *
+ * @param activity 当前Activity
+ */
+ public static void hideSoftInput(Activity activity) {
+ InputMethodManager inputMethodManager =
+ (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+ inputMethodManager.hideSoftInputFromWindow(
+ activity.getWindow().getDecorView().getWindowToken(), 0);
+ }
+
+ public static void showSoftInput(Context context, View view) {
+ InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
+ //imm.showSoftInput(view, InputMethodManager.SHOW_FORCED);
+ }
+
+ public static void hideSoftInput(Context context, View view) {
+ InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.hideSoftInputFromWindow(view.getWindowToken(), 0); //强制隐藏键盘
+ }
+
+ public static boolean isShowSoftInput(Context context) {
+ InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ //获取状态信息
+ return imm.isActive();//true 打开
+ }
+
+ /**
+ * 是否显示,显示则关闭,没显示则显示
+ *
+ * @param context
+ */
+ public static void isShow(Context context) {
+ InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
+ imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
+ }
}
\ No newline at end of file
diff --git a/app/src/main/res/anim/photo_dialog_in_anim.xml b/app/src/main/res/anim/photo_dialog_in_anim.xml
new file mode 100644
index 0000000..ba90eaf
--- /dev/null
+++ b/app/src/main/res/anim/photo_dialog_in_anim.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/photo_dialog_out_anim.xml b/app/src/main/res/anim/photo_dialog_out_anim.xml
new file mode 100644
index 0000000..86131c1
--- /dev/null
+++ b/app/src/main/res/anim/photo_dialog_out_anim.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/push_bottom_in.xml b/app/src/main/res/anim/push_bottom_in.xml
new file mode 100644
index 0000000..c1e8074
--- /dev/null
+++ b/app/src/main/res/anim/push_bottom_in.xml
@@ -0,0 +1,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/push_bottom_out.xml b/app/src/main/res/anim/push_bottom_out.xml
new file mode 100644
index 0000000..0e9a480
--- /dev/null
+++ b/app/src/main/res/anim/push_bottom_out.xml
@@ -0,0 +1,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/comments_drawable_white.xml b/app/src/main/res/drawable/comments_drawable_white.xml
new file mode 100644
index 0000000..176b619
--- /dev/null
+++ b/app/src/main/res/drawable/comments_drawable_white.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/heart_drawable_white.xml b/app/src/main/res/drawable/heart_drawable_white.xml
new file mode 100644
index 0000000..85f0b14
--- /dev/null
+++ b/app/src/main/res/drawable/heart_drawable_white.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_praise_or_comment_left_bg.xml b/app/src/main/res/drawable/selector_praise_or_comment_left_bg.xml
new file mode 100644
index 0000000..4a2f6f9
--- /dev/null
+++ b/app/src/main/res/drawable/selector_praise_or_comment_left_bg.xml
@@ -0,0 +1,15 @@
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/selector_praise_or_comment_right_bg.xml b/app/src/main/res/drawable/selector_praise_or_comment_right_bg.xml
new file mode 100644
index 0000000..04f2842
--- /dev/null
+++ b/app/src/main/res/drawable/selector_praise_or_comment_right_bg.xml
@@ -0,0 +1,15 @@
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_comment.xml b/app/src/main/res/drawable/shape_comment.xml
new file mode 100644
index 0000000..276e1df
--- /dev/null
+++ b/app/src/main/res/drawable/shape_comment.xml
@@ -0,0 +1,24 @@
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_comment_bg.xml b/app/src/main/res/drawable/shape_comment_bg.xml
new file mode 100644
index 0000000..ff16e40
--- /dev/null
+++ b/app/src/main/res/drawable/shape_comment_bg.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable/shape_remind.xml b/app/src/main/res/drawable/shape_remind.xml
new file mode 100644
index 0000000..721e50f
--- /dev/null
+++ b/app/src/main/res/drawable/shape_remind.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_like.xml b/app/src/main/res/layout/dialog_like.xml
new file mode 100644
index 0000000..947b5b6
--- /dev/null
+++ b/app/src/main/res/layout/dialog_like.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_main.xml b/app/src/main/res/layout/fragment_main.xml
index 1c1f00b..1b731cc 100644
--- a/app/src/main/res/layout/fragment_main.xml
+++ b/app/src/main/res/layout/fragment_main.xml
@@ -16,7 +16,52 @@
+
+
+
+
+
+ android:layout_marginLeft="10dp"
+ android:layout_marginBottom="10dp"
+ android:id="@+id/ll_like_comment"
+ android:visibility="gone">
-->
-
-
-
-
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
-
+
+
+
+
+
+
-
-
+
-
+
+
+
+
-
-
+
+
+
+
+
+
-
+
+
+
+
-
+
+
+
+
+
+
-
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 4bbfb8a..23a1a76 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -62,4 +62,8 @@
- @color/white
+
\ No newline at end of file
--
Gitee
From 3d200acb1f66e0b847b02fb24e3c819d228e73c0 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Wed, 23 Jun 2021 00:34:03 +0800
Subject: [PATCH 7/9] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90=EF=BC=88=E8=AF=84=E8=AE=BA?=
=?UTF-8?q?=E6=97=B6=E8=BE=93=E5=85=A5=E6=A1=86=E8=A2=AB=E8=BE=93=E5=85=A5?=
=?UTF-8?q?=E6=B3=95=E9=A1=B6=E4=B8=8A=E5=8E=BB=E6=97=B6=E5=B8=83=E5=B1=80?=
=?UTF-8?q?=E9=97=AE=E9=A2=98=E8=BF=98=E6=B2=A1=E6=9C=89=E8=A7=A3=E5=86=B3?=
=?UTF-8?q?=EF=BC=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/build.gradle | 6 +
app/src/main/AndroidManifest.xml | 13 +-
.../config/PictureSelectorConfig.java | 45 ++-
.../schoolbbs/service/PictureService.java | 139 ++++++++
.../schoolbbs/ui/activity/AddActivity.java | 82 ++---
.../ui/activity/BottomTabLayoutActivity.java | 78 ++++
.../schoolbbs/ui/activity/LoginActivity.java | 5 +-
.../ui/activity/ManagerActivity.java | 2 +-
.../schoolbbs/ui/adapter/DataAdapter.java | 19 -
.../schoolbbs/ui/config/MainConstant.java | 4 +-
.../schoolbbs/ui/fragment/HomeFragment.java | 2 +-
.../schoolbbs/ui/fragment/MeFragment.java | 196 ++++++++---
.../ui/view/popWindow/PopAlertDialog.java | 226 ++++++++++++
.../ui/view/popWindow/PopDownWindow.java | 260 ++++++++++++++
.../ui/view/popWindow/PopItemAction.java | 81 +++++
.../popWindow/PopSimpleAnimationListener.java | 20 ++
.../ui/view/popWindow/PopUpWindow.java | 221 ++++++++++++
.../ui/view/popWindow/PopViewInterface.java | 35 ++
.../ui/view/popWindow/PopWindow.java | 332 ++++++++++++++++++
.../ui/view/popWindow/PopWindowHelper.java | 112 ++++++
.../ui/view/popWindow/PopWindowInterface.java | 29 ++
.../ui/view/popWindow/view/PopAlertView.java | 146 ++++++++
.../ui/view/popWindow/view/PopDownView.java | 15 +
.../ui/view/popWindow/view/PopItemView.java | 52 +++
.../ui/view/popWindow/view/PopLineView.java | 24 ++
.../ui/view/popWindow/view/PopUpView.java | 161 +++++++++
.../moyv/schoolbbs/util/AnalysisUtils.java | 3 +
.../com/moyv/schoolbbs/util/UCropUtils.java | 71 ++++
.../{ui/config => util}/UIHelper.java | 2 +-
app/src/main/res/anim/anim/fade_in.xml | 7 +
app/src/main/res/anim/anim/fade_out.xml | 7 +
.../res/anim/anim/pop_action_sheet_enter.xml | 10 +
.../res/anim/anim/pop_action_sheet_exit.xml | 10 +
.../main/res/anim/anim/pop_alert_enter.xml | 14 +
app/src/main/res/anim/anim/pop_alert_exit.xml | 13 +
.../main/res/anim/anim/pop_alpha_enter.xml | 8 +
app/src/main/res/anim/anim/pop_alpha_exit.xml | 8 +
app/src/main/res/anim/fade_in.xml | 7 +
app/src/main/res/anim/fade_out.xml | 7 +
.../main/res/anim/pop_action_sheet_enter.xml | 10 +
.../main/res/anim/pop_action_sheet_exit.xml | 10 +
app/src/main/res/anim/pop_alert_enter.xml | 14 +
app/src/main/res/anim/pop_alert_exit.xml | 13 +
app/src/main/res/anim/pop_alpha_enter.xml | 8 +
app/src/main/res/anim/pop_alpha_exit.xml | 8 +
.../res/drawable-v24/pop_selector_bottom.xml | 10 +
.../res/drawable-v24/pop_selector_cancel.xml | 15 +
.../pop_selector_cancel_square.xml | 13 +
.../res/drawable-v24/pop_selector_center.xml | 9 +
.../res/drawable-v24/pop_selector_top.xml | 10 +
.../main/res/drawable-v24/pop_shape_bg.xml | 6 +
app/src/main/res/layout/fragment_me.xml | 19 +-
app/src/main/res/layout/pop_alert_dialog.xml | 29 ++
app/src/main/res/layout/pop_down_window.xml | 28 ++
app/src/main/res/layout/pop_up_window.xml | 32 ++
app/src/main/res/values-night/integers.xml | 3 +
app/src/main/res/values/colors.xml | 9 +
app/src/main/res/values/dimens.xml | 7 +
app/src/main/res/values/themes.xml | 21 ++
59 files changed, 2613 insertions(+), 133 deletions(-)
create mode 100644 app/src/main/java/com/moyv/schoolbbs/service/PictureService.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopSimpleAnimationListener.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowHelper.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowInterface.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopDownView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopLineView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java
create mode 100644 app/src/main/java/com/moyv/schoolbbs/util/UCropUtils.java
rename app/src/main/java/com/moyv/schoolbbs/{ui/config => util}/UIHelper.java (97%)
create mode 100644 app/src/main/res/anim/anim/fade_in.xml
create mode 100644 app/src/main/res/anim/anim/fade_out.xml
create mode 100644 app/src/main/res/anim/anim/pop_action_sheet_enter.xml
create mode 100644 app/src/main/res/anim/anim/pop_action_sheet_exit.xml
create mode 100644 app/src/main/res/anim/anim/pop_alert_enter.xml
create mode 100644 app/src/main/res/anim/anim/pop_alert_exit.xml
create mode 100644 app/src/main/res/anim/anim/pop_alpha_enter.xml
create mode 100644 app/src/main/res/anim/anim/pop_alpha_exit.xml
create mode 100644 app/src/main/res/anim/fade_in.xml
create mode 100644 app/src/main/res/anim/fade_out.xml
create mode 100644 app/src/main/res/anim/pop_action_sheet_enter.xml
create mode 100644 app/src/main/res/anim/pop_action_sheet_exit.xml
create mode 100644 app/src/main/res/anim/pop_alert_enter.xml
create mode 100644 app/src/main/res/anim/pop_alert_exit.xml
create mode 100644 app/src/main/res/anim/pop_alpha_enter.xml
create mode 100644 app/src/main/res/anim/pop_alpha_exit.xml
create mode 100644 app/src/main/res/drawable-v24/pop_selector_bottom.xml
create mode 100644 app/src/main/res/drawable-v24/pop_selector_cancel.xml
create mode 100644 app/src/main/res/drawable-v24/pop_selector_cancel_square.xml
create mode 100644 app/src/main/res/drawable-v24/pop_selector_center.xml
create mode 100644 app/src/main/res/drawable-v24/pop_selector_top.xml
create mode 100644 app/src/main/res/drawable-v24/pop_shape_bg.xml
create mode 100644 app/src/main/res/layout/pop_alert_dialog.xml
create mode 100644 app/src/main/res/layout/pop_down_window.xml
create mode 100644 app/src/main/res/layout/pop_up_window.xml
create mode 100644 app/src/main/res/values-night/integers.xml
diff --git a/app/build.gradle b/app/build.gradle
index 7a7236b..a3f5654 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -91,6 +91,12 @@ dependencies {
// 悬浮按钮
implementation 'com.getbase:floatingactionbutton:1.10.1'
+// EasyPermissions(负责处理运行时权限的处理)
+ implementation 'pub.devrel:easypermissions:2.0.0'
+
+// 图片裁剪库
+// implementation 'com.github.yalantis:ucrop:2.2.1'
+
testImplementation 'junit:junit:4+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'junit:junit:4.10'
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 11e5e63..618871c 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -2,13 +2,16 @@
-
+
-
+
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java b/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java
index fd7187d..3478d49 100644
--- a/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java
+++ b/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java
@@ -20,7 +20,7 @@ public class PictureSelectorConfig {
PictureSelector.create(activity)
.openGallery(PictureMimeType.ofAll())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
// .theme(R.style.picture.white.style)// 主题样式设置 具体参考 values/styles 用法:R.style.picture.white.style
- .maxSelectNum(1)// 最大图片选择数量
+ .maxSelectNum(9)// 最大图片选择数量
.minSelectNum(1)// 最小选择数量
.imageSpanCount(4)// 每行显示个数
.selectionMode(PictureConfig.MULTIPLE)// 多选 or 单选
@@ -44,4 +44,47 @@ public class PictureSelectorConfig {
.forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
}
+ public static void initMultiConfigCut(Activity activity, int maxTotal){
+ PictureSelector.create(activity)
+ .openGallery(PictureMimeType.ofAll())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
+// .theme(R.style.picture.white.style)// 主题样式设置 具体参考 values/styles 用法:R.style.picture.white.style
+ .maxSelectNum(1)// 最大图片选择数量
+ .minSelectNum(1)// 最小选择数量
+ .imageSpanCount(4)// 每行显示个数
+ .selectionMode(PictureConfig.SINGLE)// 多选 or 单选
+ .isPreviewImage(true)// 是否可预览图片
+ .isEnablePreviewAudio(false) // 是否可播放音频
+ .isCamera(false)// 是否显示拍照按钮
+ .isZoomAnim(true)// 图片列表点击 缩放效果 默认true
+ .isEnableCrop(true)// 是否裁剪
+ .isCompress(true)// 是否压缩
+ .synOrAsy(true)//同步true或异步false 压缩 默认同步
+ .withAspectRatio(1, 1)// 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
+ .hideBottomControls(true)// 是否显示uCrop工具栏,默认不显示
+ .isGif(false)// 是否显示gif图片
+ .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
+ .circleDimmedLayer(false)// 是否圆形裁剪
+ .showCropFrame(true)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
+ .showCropGrid(true)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
+ .minimumCompressSize(100)// 小于100kb的图片不压缩
+ .imageEngine(GlideEngine.createGlideEngine())
+ .forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
+ }
+
+ public static void initCamer(Activity activity){
+ PictureSelector.create(activity)
+ .openCamera(PictureMimeType.ofImage())
+ .isEnableCrop(true)// 是否裁剪
+ .isCompress(true)// 是否压缩
+ .synOrAsy(true)//同步true或异步false 压缩 默认同步
+ .withAspectRatio(1, 1)// 裁剪比例 如16:9 3:2 3:4 1:1 可自定义
+ .freeStyleCropEnabled(true)// 裁剪框是否可拖拽
+ .circleDimmedLayer(false)// 是否圆形裁剪
+ .showCropFrame(true)// 是否显示裁剪矩形边框 圆形裁剪时建议设为false
+ .showCropGrid(true)// 是否显示裁剪矩形网格 圆形裁剪时建议设为false
+ .minimumCompressSize(100)// 小于100kb的图片不压缩
+ .imageEngine(GlideEngine.createGlideEngine())
+ .forResult(PictureConfig.REQUEST_CAMERA);
+ }
+
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java b/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java
new file mode 100644
index 0000000..19830a0
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java
@@ -0,0 +1,139 @@
+package com.moyv.schoolbbs.service;
+
+import android.os.Handler;
+
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.MediaType;
+import okhttp3.MultipartBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+
+import static com.moyv.schoolbbs.config.URLConstant.UPLOAD_URL;
+import static com.moyv.schoolbbs.util.HttpUtil.createClient;
+
+public class PictureService {
+ public static int PIC_POST=202;
+ public static int PIC_HEAD=303;
+
+ private static final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
+ //图片上传
+ public static void uploading(List files,List fileName,int postId,Handler handler) {
+//图片上传接口地址
+ String url = UPLOAD_URL;
+ MultipartBody multipartBody=null;
+ MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
+ builder.addFormDataPart("type", String.valueOf(PIC_POST));
+ builder.addFormDataPart("postId", String.valueOf(postId));
+ for (int i = 0; i picUrls = new ArrayList<>();
+ List files=new ArrayList<>();
for (int i = 0; i < mPicList.size(); i++) {
String photo = mPicList.get(i);
+ File file=new File(photo);
+ files.add(file);
System.out.println(photo);
- uploading(photo, i);
+ String url=okPostId + "_" + i + ".jpg";
+ picUrls.add(url);
}
- handler.sendMessage(handler.obtainMessage(0));
+ uploading(files,picUrls,okPostId,handler1);
} else {
handler.sendMessage(handler.obtainMessage(404));
@@ -279,45 +281,27 @@ public class AddActivity extends AppCompatActivity {
}
});
}
-
- //图片上传
- public void uploading(String photo, int index) {
-//图片上传接口地址
- String url = UPLOAD_URL;
-//创建上传文件对象
- File file = new File(photo);
-//创建RequestBody封装参数
- RequestBody fileBody = RequestBody.create(MediaType.parse("image/jpeg"), file);
-//创建MultipartBody,给RequestBody进行设置
- MultipartBody multipartBody = new MultipartBody.Builder()
- .setType(MultipartBody.FORM)
- .addFormDataPart("postId", okPostId)
- .addFormDataPart("image", okPostId + "_" + index + ".jpg", fileBody)
- .build();
-//创建Request
- Request request = new Request.Builder()
- .url(url)
- .post(multipartBody)
- .build();
-//创建okhttp对象
- OkHttpClient okHttpClient = new OkHttpClient.Builder()
- .connectTimeout(10, TimeUnit.SECONDS)
- .readTimeout(10, TimeUnit.SECONDS)
- .writeTimeout(10, TimeUnit.SECONDS)
- .build();
-//上传完图片,得到服务器反馈数据
- okHttpClient.newCall(request).enqueue(new Callback() {
- @Override
- public void onFailure(Call call, IOException e) {
- Log.e("ff", "uploadMultiFile() e=" + e);
+ Handler handler1=new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(@NonNull Message msg) {
+ switch (msg.what){
+ case 200:
+ handler.sendMessage(handler.obtainMessage(0));
+ System.out.println("图片上传成功");
+ break;
+ case 301:
+ System.out.println("上传失败");
+ break;
+ case 404:
+ System.out.println("服务器出错");
+ break;
+ default:
}
+ return false;
+ }
+ });
+
- @Override
- public void onResponse(Call call, Response response) throws IOException {
- Log.i("ff", "uploadMultiFile() response=" + response.body().string());
- }
- });
- }
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
index 1da5fe2..4aa5322 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
@@ -1,22 +1,39 @@
package com.moyv.schoolbbs.ui.activity;
import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.util.Log;
+import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.tabs.TabLayout;
+import com.luck.picture.lib.PictureSelector;
+import com.luck.picture.lib.config.PictureConfig;
+import com.luck.picture.lib.entity.LocalMedia;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.config.AccountConstant;
import com.moyv.schoolbbs.ui.adapter.DataGenerator;
+import com.moyv.schoolbbs.util.UIHelper;
import com.moyv.schoolbbs.ui.fragment.HomeFragment;
+import java.util.List;
+
+import static android.content.ContentValues.TAG;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.service.PictureService.uploadHead;
import static com.moyv.schoolbbs.ui.adapter.DataGenerator.mTabTitle;
import static com.moyv.schoolbbs.util.ToastUtils.init;
+import static com.moyv.schoolbbs.util.ToastUtils.show;
+import static com.moyv.schoolbbs.util.UIHelper.closeDialog;
+import static com.moyv.schoolbbs.util.UIHelper.showDialogForLoading;
/**
* @author moyv
@@ -125,4 +142,65 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
transaction.commit();
}
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+// UCropUtils uCropUtils = new UCropUtils(context);
+ Log.e(TAG, "onActivityResult: 回调成功" );
+ switch (requestCode) {
+ //相册
+ case PictureConfig.CHOOSE_REQUEST:
+ if (resultCode == RESULT_OK) {
+// 系统相册调用
+// Uri sourceUri = data.getData();
+// uCropUtils.startUCrop(sourceUri);
+// 图片选择器调用
+ List imageUrl = PictureSelector.obtainMultipleResult(data);
+ upload(imageUrl);
+ } else {
+ show("头像选择失败");
+ }
+ break;
+ //照相
+ case PictureConfig.REQUEST_CAMERA:
+ if (resultCode == RESULT_OK) {
+ if (data != null) {
+// uCropUtils.startUCrop(imageUri);
+ // 结果回调
+ List result = PictureSelector.obtainMultipleResult(data);
+ upload(result);
+ } else {
+ show("拍照失败");
+ }
+ }
+ break;
+ }
+ }
+
+ public void upload(List result){
+ List imageUrl =result;
+ Handler handler1=new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(@NonNull Message msg) {
+ switch (msg.what){
+ case 200:
+ show("头像上传成功");
+// 刷新用户信息
+ closeDialog(context);
+ mFragmensts[2].onResume();
+ break;
+ case 301:
+ show("上传失败");
+ break;
+ case 404:
+ show("服务器出错");
+ break;
+ default:
+ }
+ return false;
+ }
+ });
+ showDialogForLoading(context,"头像上传中");
+ uploadHead(imageUrl.get(0).getCompressPath(),ACCOUNT,handler1);
+ }
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
index 1c551dc..ff776be 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
@@ -135,8 +135,11 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
editor.putBoolean("isLogin",true);
if(cbRm.isChecked()){
editor.putBoolean("rememberPsw",true);
- editor.putString("password",password);
+// editor.putString("password",password);
+ }else{
+ editor.putBoolean("rememberPsw",false);
}
+ editor.putString("password",password);
editor.commit();
new AssertionError(context);
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
index eee6b67..4119e1b 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
@@ -25,7 +25,7 @@ import com.moyv.schoolbbs.bean.ReModel;
import com.moyv.schoolbbs.pojo.Item;
import com.moyv.schoolbbs.service.MainService;
import com.moyv.schoolbbs.ui.adapter.DataAdapter;
-import com.moyv.schoolbbs.ui.config.UIHelper;
+import com.moyv.schoolbbs.util.UIHelper;
import com.moyv.schoolbbs.ui.listener.EndlessRecyclerOnScrollListener;
import java.util.ArrayList;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
index ec29a6f..0664745 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
@@ -172,11 +172,8 @@ public class DataAdapter extends RecyclerView.Adapter {
recyclerViewHolder.tvDate.setText(Date);
// 帖子文字内容
if (content.length() == 0) {
-// recyclerViewHolder.tvCnt.setVisibility(View.GONE);
recyclerViewHolder.expandTextView.setVisibility(View.GONE);
} else {
-// recyclerViewHolder.tvCnt.setVisibility(View.VISIBLE);
-// recyclerViewHolder.tvCnt.setText(content);
recyclerViewHolder.expandTextView.setVisibility(View.VISIBLE);
recyclerViewHolder.expandTextView.setText(content);
}
@@ -333,22 +330,6 @@ public class DataAdapter extends RecyclerView.Adapter {
notifyItemRangeInserted(positionStart + 1, itemCount);
}
- //动态添加textview实现评论
- private void addCmt(String userName, String string, LinearLayout linearLayout) {
- TextView textView = new TextView(context);
- textView.setText(userName + ": " + string);
- textView.setTextSize(15);
- linearLayout.addView(textView);
- LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) textView.getLayoutParams();
- layoutParams.setMargins(0, 0, 0, 20);
- layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
- textView.setLayoutParams(layoutParams);
- }
-
- // 动态移出评论
- private void removeCmt(LinearLayout linearLayout) {
- linearLayout.removeAllViews();
- }
@Override
public int getItemViewType(int position) {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/config/MainConstant.java b/app/src/main/java/com/moyv/schoolbbs/ui/config/MainConstant.java
index 338aa2b..53e3ae8 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/config/MainConstant.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/config/MainConstant.java
@@ -11,7 +11,7 @@ public class MainConstant {
* 图片路径
* 主页展示
* 添加页面展示
- * 最多上传5张图片
+ * 最多上传9张图片
* 请求码
* 查看大图页面的结果码
*/
@@ -21,7 +21,7 @@ public class MainConstant {
public static final String SHOW = "show";
public static final String MAIN_SHOW = "main_show";
public static final String ADD_SHOW = "add_show";
- public static final int MAX_SELECT_PIC_NUM = 6;
+ public static final int MAX_SELECT_PIC_NUM = 9;
public static final int REQUEST_CODE_MAIN = 10;
public static final int RESULT_CODE_VIEW_IMG = 11;
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
index c02b9a4..72385c8 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
@@ -30,7 +30,7 @@ import com.moyv.schoolbbs.pojo.Item;
import com.moyv.schoolbbs.service.MainService;
import com.moyv.schoolbbs.ui.activity.AddActivity;
import com.moyv.schoolbbs.ui.adapter.DataAdapter;
-import com.moyv.schoolbbs.ui.config.UIHelper;
+import com.moyv.schoolbbs.util.UIHelper;
import com.moyv.schoolbbs.ui.listener.EndlessRecyclerOnScrollListener;
import java.util.ArrayList;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
index b68baea..5c6eabb 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
@@ -7,13 +7,21 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.media.Image;
+import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Handler;
import android.os.Message;
+import android.os.StrictMode;
+import android.provider.MediaStore;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -36,25 +44,43 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
+import com.luck.picture.lib.PictureSelector;
+import com.luck.picture.lib.config.PictureConfig;
+import com.luck.picture.lib.entity.LocalMedia;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.bean.UserInfo;
import com.moyv.schoolbbs.config.AccountConstant;
+import com.moyv.schoolbbs.config.PictureSelectorConfig;
import com.moyv.schoolbbs.service.ChangeService;
import com.moyv.schoolbbs.service.UserInfoService;
import com.moyv.schoolbbs.ui.activity.LoginActivity;
import com.moyv.schoolbbs.ui.activity.ManagerActivity;
import com.moyv.schoolbbs.ui.view.MaskImageView;
import com.moyv.schoolbbs.ui.view.MeItemView;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+import com.moyv.schoolbbs.util.UCropUtils;
+import com.yalantis.ucrop.UCrop;
+import com.yalantis.ucrop.UCropActivity;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.List;
import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.CropCircleTransformation;
+import static android.app.Activity.RESULT_OK;
+import static android.content.ContentValues.TAG;
import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.config.PictureSelectorConfig.initCamer;
import static com.moyv.schoolbbs.config.URLConstant.HEAD_URL;
import static com.moyv.schoolbbs.service.MainService.STAR_POSTS;
import static com.moyv.schoolbbs.service.MainService.USER_POSTS;
+import static com.moyv.schoolbbs.service.PictureService.PIC_POST;
+import static com.moyv.schoolbbs.service.PictureService.uploading;
import static com.moyv.schoolbbs.util.AnalysisUtils.cleanLoginStatus;
import static com.moyv.schoolbbs.util.AnalysisUtils.readLoginStatus;
import static com.moyv.schoolbbs.util.AnalysisUtils.readLoginUserName;
@@ -76,6 +102,13 @@ public class MeFragment extends Fragment implements View.OnClickListener {
private AlertDialog changeDialog;
private TextView postManager;
private TextView starManager;
+
+ private final static String CROPIMAGEROOT = Environment.getExternalStorageDirectory() + "/myxmpp/";
+ public final static int REQUEST_PICTURE_CHOOSE = 1;
+ public final static int REQUEST_CAMERA_IMAGE = 2;
+ public static File mPictureFile;//照相产生的临时图片
+ private static Uri imageUri = null;//拍照后,照片的Uri
+
public static MeFragment newInstance(String title) {
Bundle arguments = new Bundle();
arguments.putString("TITLE", title);
@@ -88,55 +121,64 @@ public class MeFragment extends Fragment implements View.OnClickListener {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_me, container, false);
- this.context=root.getContext();
- ivHead=root.findViewById(R.id.h_head);
- ivBackground=root.findViewById(R.id.h_background);
- tvName=root.findViewById(R.id.user_name);
- btnLogin=root.findViewById(R.id.btn_login);
- btnLogOut=root.findViewById(R.id.btn_log_out);
- itemName=root.findViewById(R.id.me_item_name);
- itemAccount=root.findViewById(R.id.me_item_account);
- itemIntroduction=root.findViewById(R.id.me_item_introduction);
- ivHead.setImageResource(R.drawable.login_head);
- postManager=root.findViewById(R.id.me_tv_posts);
- starManager=root.findViewById(R.id.me_tv_stars);
+ this.context = root.getContext();
- btnLogOut.setOnClickListener(this);
+ //严格模式,解决7.0拍照问题
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+ StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
+ StrictMode.setVmPolicy(builder.build());
+ builder.detectFileUriExposure();
+ }
+ ivHead = root.findViewById(R.id.h_head);
+ ivBackground = root.findViewById(R.id.h_background);
+ tvName = root.findViewById(R.id.user_name);
+ btnLogin = root.findViewById(R.id.btn_login);
+ btnLogOut = root.findViewById(R.id.btn_log_out);
+ itemName = root.findViewById(R.id.me_item_name);
+ itemAccount = root.findViewById(R.id.me_item_account);
+ itemIntroduction = root.findViewById(R.id.me_item_introduction);
+ ivHead.setImageResource(R.drawable.login_head);
+ postManager = root.findViewById(R.id.me_tv_posts);
+ starManager = root.findViewById(R.id.me_tv_stars);
+ btnLogOut.setOnClickListener(this);
btnLogin.setOnClickListener(this);
-
itemName.setOnClickListener(this);
itemIntroduction.setOnClickListener(this);
-
postManager.setOnClickListener(this);
starManager.setOnClickListener(this);
+ ivHead.setOnClickListener(this);
return root;
}
@Override
public void onResume() {
super.onResume();
- SharedPreferences sharedPreferences=context.getSharedPreferences("login",0);
- if(readLoginStatus(context)){
+ SharedPreferences sharedPreferences = context.getSharedPreferences("login", 0);
+ if (readLoginStatus(context)) {
tvName.setVisibility(View.VISIBLE);
btnLogin.setVisibility(View.GONE);
- int account=sharedPreferences.getInt("account",0);
- Glide.with(context).load(HEAD_URL+account+".jpg")
+ int account = sharedPreferences.getInt("account", 0);
+ Glide.with(context).load(HEAD_URL + account + ".jpg")
//缓存
- .diskCacheStrategy(DiskCacheStrategy.RESOURCE)
+ .diskCacheStrategy(DiskCacheStrategy.NONE)
.apply(ivBackground.setGaussBlur())
//淡入淡出
.transition(DrawableTransitionOptions.withCrossFade())
.into(ivBackground);
- Glide.with(context).load(HEAD_URL+account+".jpg")
- .error( R.drawable.login_head)
- .apply(RequestOptions.bitmapTransform(new CircleCrop()))
+// RequestOptions options = new RequestOptions();
+// options.skipMemoryCache(true);//跳过内存缓存
+// options.diskCacheStrategy(DiskCacheStrategy.NONE);//不缓冲disk硬盘中
+
+ Glide.with(context).load(HEAD_URL + account + ".jpg")
+ .error(R.drawable.login_head)
+ .apply(RequestOptions.bitmapTransform(new CircleCrop()).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true))
.into(ivHead);
- UserInfoService userInfoService=new UserInfoService();
+ UserInfoService userInfoService = new UserInfoService();
new AccountConstant(context);
- userInfoService.getUserInfo(account,handler);
+ userInfoService.getUserInfo(account, handler);
itemAccount.setData(String.valueOf(account));
- }else {
+ } else {
// 退出登录操作
tvName.setVisibility(View.GONE);
btnLogin.setVisibility(View.VISIBLE);
@@ -148,17 +190,16 @@ public class MeFragment extends Fragment implements View.OnClickListener {
itemAccount.setData("");
itemIntroduction.setData("");
}
- Toast.makeText(context,"hello",Toast.LENGTH_SHORT).show();
}
-// 获取用户信息
- Handler handler=new Handler(new Handler.Callback() {
+ // 获取用户信息
+ Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
- UserInfo userInfo=(UserInfo)msg.obj;
+ UserInfo userInfo = (UserInfo) msg.obj;
tvName.setText(userInfo.getName());
itemName.setData(userInfo.getName());
itemIntroduction.setData(userInfo.getIntroduction());
@@ -172,23 +213,23 @@ public class MeFragment extends Fragment implements View.OnClickListener {
@Override
public void onClick(View v) {
- switch (v.getId()){
+ switch (v.getId()) {
case R.id.btn_login:
- Intent intent=new Intent(context, LoginActivity.class);
+ Intent intent = new Intent(context, LoginActivity.class);
startActivity(intent);
break;
case R.id.btn_log_out:
cleanLoginStatus(context);
new AccountConstant(context);
- if(!LOGIN){
+ if (!LOGIN) {
onResume();
}
break;
case R.id.me_item_name:
- dialog(1,"请输入要修改的名字");
+ dialog(1, "请输入要修改的名字");
break;
case R.id.me_item_introduction:
- dialog(2,"请输入要修改的简介");
+ dialog(2, "请输入要修改的简介");
break;
case R.id.me_item_change_psw:
// dialog(3,"请输入要修改的密码");
@@ -202,31 +243,34 @@ public class MeFragment extends Fragment implements View.OnClickListener {
intentPostsManager(STAR_POSTS);
show("点赞管理");
break;
+ case R.id.h_head:
+ showPopWindow();
default:
System.out.println("点击事件没有执行事件");
}
}
- public void dialog(int index,String hint){
+ public void dialog(int index, String hint) {
final EditText et = new EditText(context);
et.setHint(hint);
// et.setText(itemName.getData().getText().toString());
- changeDialog=new AlertDialog.Builder(context).setTitle("请输入消息")
+ changeDialog = new AlertDialog.Builder(context).setTitle("请输入消息")
.setIcon(android.R.drawable.sym_def_app_icon)
.setView(et)
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//按下确定键后的事件
- ChangeService changeService=new ChangeService();
- changeService.changeInfo(index,et.getText().toString(),handler1);
+ ChangeService changeService = new ChangeService();
+ changeService.changeInfo(index, et.getText().toString(), handler1);
}
- }).setNegativeButton("取消",null).show();
+ }).setNegativeButton("取消", null).show();
}
- Handler handler1=new Handler(new Handler.Callback() {
+
+ Handler handler1 = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
onResume();
break;
@@ -236,10 +280,70 @@ public class MeFragment extends Fragment implements View.OnClickListener {
}
});
- public void intentPostsManager(int type){
- Intent intent=new Intent(context, ManagerActivity.class);
- intent.putExtra("type",type);
+ public void intentPostsManager(int type) {
+ Intent intent = new Intent(context, ManagerActivity.class);
+ intent.putExtra("type", type);
startActivity(intent);
}
+
+
+
+
+ /**
+ * popwindow选择拍照还是选择图片
+ */
+ private void showPopWindow() {
+ PopWindow popWindow = new PopWindow.Builder((Activity) context)
+ .setStyle(PopWindow.PopWindowStyle.PopUp)
+ .addItemAction(new PopItemAction("选择照片", PopItemAction.PopItemStyle.Normal, new PopItemAction.OnClickListener() {
+ @Override
+ public void onClick() {
+// choosePhoto((Activity) context);
+// 调用图片选择器,最多可以选中一张
+ PictureSelectorConfig.initMultiConfigCut((Activity) context, 1);
+ }
+
+ }))
+ .addItemAction(new PopItemAction("拍照", PopItemAction.PopItemStyle.Warning, new PopItemAction.OnClickListener() {
+ @Override
+ public void onClick() {
+// openCamera((Activity) context);
+ initCamer((Activity) context);
+ }
+ }))
+ .addItemAction(new PopItemAction("取消", PopItemAction.PopItemStyle.Cancel))
+ .create();
+ popWindow.show();
+ }
+
+ /**
+ * 从相册选择图片
+ *
+ * @param activity
+ */
+ public static void choosePhoto(Activity activity) {
+ Intent intent = new Intent();
+ intent.setType("image/*");
+ intent.setAction(Intent.ACTION_PICK);
+ activity.startActivityForResult(intent, REQUEST_PICTURE_CHOOSE);
+ }
+
+ /**
+ * 打开相机拍照
+ *
+ * @param activity
+ * @return
+ */
+ public static void openCamera(Activity activity) {
+ mPictureFile = new File(CROPIMAGEROOT, "_" + System.currentTimeMillis() + ".jpg");
+ imageUri = Uri.fromFile(mPictureFile);
+ // 启动拍照,并保存到临时文件
+ Intent mIntent = new Intent();
+ mIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
+ mIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPictureFile));
+ mIntent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
+ activity.startActivityForResult(mIntent, REQUEST_CAMERA_IMAGE);
+ }
+
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java
new file mode 100644
index 0000000..ca9e7e9
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java
@@ -0,0 +1,226 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.util.DisplayMetrics;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.view.PopAlertView;
+
+
+
+public class PopAlertDialog extends Dialog implements PopWindowInterface, DialogInterface.OnShowListener, View.OnClickListener,
+ PopWindowInterface.OnStartShowListener, PopWindowInterface.OnStartDismissListener {
+
+ private FrameLayout mRootLayout;
+ private FrameLayout mContainLayout;
+ private PopAlertView mPopAlertDialog;
+ private LinearLayout mContentLayout;
+ private PopWindow mPopWindow;
+
+ private Animation mAlphaOpenAnimation;
+ private Animation mAlphaCloseAnimation;
+ private Animation mPopOpenAnimation;
+ private Animation mPopCloseAnimation;
+
+ private PopItemAction mCancelPopItemAction;
+ private boolean mIsDismissed = true;
+
+ private View mCustomView;
+
+ public PopAlertDialog(Activity activity, int titleResId, int messageResId, PopWindow popWindow) {
+ this(activity, titleResId == 0 ? null : activity.getString(titleResId), messageResId == 0 ? null : activity.getString(messageResId), popWindow);
+ }
+
+ public PopAlertDialog(Activity activity, CharSequence title, CharSequence message, PopWindow popWindow) {
+ super(activity, R.style.PopWindowStyle);
+ setContentView(R.layout.pop_alert_dialog);
+
+ getWindow().setWindowAnimations(R.style.PopWindowAnimation);
+ getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, getScreenHeight(activity) - getStatusBarHeight(activity));
+ setOnShowListener(this);
+ setCancelable(true);
+ setCanceledOnTouchOutside(true);
+ mPopWindow = popWindow;
+
+ initRootView();
+ initContentView(title, message);
+ initAnim();
+ }
+
+ private void initRootView() {
+ mRootLayout = (FrameLayout) findViewById(R.id.layout_root);
+ mRootLayout.setOnClickListener(this);
+ }
+
+ private void initContentView(CharSequence title, CharSequence message) {
+ mPopAlertDialog = (PopAlertView) findViewById(R.id.popAlertView);
+ mPopAlertDialog.setPopWindow(mPopWindow);
+ mPopAlertDialog.setTitleAndMessage(title, message);
+
+ mContentLayout = (LinearLayout) findViewById(R.id.layout_center);
+ mContainLayout = (FrameLayout) findViewById(R.id.layout_contain);
+ }
+
+ private void initAnim() {
+ mPopOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alert_enter);
+ mPopCloseAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alert_exit);
+ mPopCloseAnimation.setAnimationListener(new PopSimpleAnimationListener() {
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ if (mCustomView != null) {
+ mContentLayout.post(mDismissRunnable);
+ } else
+ mPopAlertDialog.post(mDismissRunnable);
+ }
+ });
+
+// mAlphaOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_enter);
+ mAlphaCloseAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_exit);
+ mAlphaCloseAnimation.setAnimationListener(new PopSimpleAnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ onStartDismiss(PopAlertDialog.this);
+ if (mCustomView != null) {
+ mContentLayout.startAnimation(mPopCloseAnimation);
+ } else
+ mPopAlertDialog.startAnimation(mPopCloseAnimation);
+ }
+ });
+ }
+
+ private Runnable mDismissRunnable = new Runnable() {
+ @Override
+ public void run() {
+ PopAlertDialog.super.dismiss();
+ }
+ };
+
+
+ @Override
+ public void onShow(DialogInterface dialog) {
+ if (mIsDismissed) {
+ mIsDismissed = false;
+ onStartShow(PopAlertDialog.this);
+ mRootLayout.startAnimation(mAlphaOpenAnimation);
+ if (mCustomView != null) {
+ mContentLayout.startAnimation(mPopOpenAnimation);
+ } else if (mPopAlertDialog.showAble()) {
+ mPopAlertDialog.refreshBackground();
+ mPopAlertDialog.startAnimation(mPopOpenAnimation);
+ } else {
+ throw new RuntimeException("必须至少添加一个PopItemView");
+ }
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.layout_root) {
+ onBackPressed();
+ }
+ }
+
+ @Override
+ public void cancel() {
+ super.cancel();
+ if (mCancelPopItemAction != null) {
+ mCancelPopItemAction.onClick();
+ }
+ }
+
+ @Override
+ public void dismiss() {
+ executeExitAnim();
+ }
+
+ private void executeExitAnim() {
+ if (!mIsDismissed) {
+ mIsDismissed = true;
+ mRootLayout.startAnimation(mAlphaCloseAnimation);
+ }
+ }
+
+
+ @Override
+ public void setView(View view) {
+ view.setClickable(true);
+ mCustomView = view;
+ mContentLayout.setVisibility(View.VISIBLE);
+ mPopAlertDialog.setVisibility(View.GONE);
+ mContentLayout.addView(mCustomView);
+ }
+
+ @Override
+ public void addContentView(View view) {
+ view.setClickable(true);
+ mPopAlertDialog.addContentView(view);
+ }
+
+ @Override
+ public void addItemAction(PopItemAction popItemAction) {
+ if (mCustomView != null) {
+ return;
+ }
+ mContentLayout.setVisibility(View.GONE);
+ mPopAlertDialog.setVisibility(View.VISIBLE);
+ mPopAlertDialog.addItemAction(popItemAction);
+ if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Cancel) {
+ setCancelable(true);
+ setCanceledOnTouchOutside(true);
+ mCancelPopItemAction = popItemAction;
+ }
+ }
+
+ @Override
+ public void setIsShowLine(boolean isShowLine) {
+ mPopAlertDialog.setIsShowLine(isShowLine);
+ }
+
+ @Override
+ public void setIsShowCircleBackground(boolean isShow) {
+ mPopAlertDialog.setIsShowCircleBackground(isShow);
+ if (!isShow) {
+ mPopAlertDialog.setBackgroundColor(getContext().getResources().getColor(R.color.pop_bg_content));
+ }
+ }
+
+ @Override
+ public void setPopWindowMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mContainLayout.getLayoutParams();
+ layoutParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ mContainLayout.setLayoutParams(layoutParams);
+ }
+
+ public static int getStatusBarHeight(Context context) {
+ Resources resources = context.getResources();
+ int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
+ return resources.getDimensionPixelSize(resourceId);
+ }
+
+ public static int getScreenHeight(Context context) {
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ DisplayMetrics dm = new DisplayMetrics();
+ windowManager.getDefaultDisplay().getMetrics(dm);
+ return dm.heightPixels;
+ }
+
+ @Override
+ public void onStartDismiss(PopWindowInterface popWindowInterface) {
+ mPopWindow.onStartDismiss(popWindowInterface);
+ }
+
+ @Override
+ public void onStartShow(PopWindowInterface popWindowInterface) {
+ mPopWindow.onStartShow(popWindowInterface);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java
new file mode 100644
index 0000000..c4c841a
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java
@@ -0,0 +1,260 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.app.Activity;
+import android.content.Context;
+import android.graphics.Rect;
+import android.os.Build;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.view.animation.TranslateAnimation;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.PopupWindow;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.view.PopDownView;
+
+import java.util.TimerTask;
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopDownWindow extends PopupWindow implements PopWindowInterface, View.OnClickListener,
+ PopWindowInterface.OnStartShowListener, PopWindowInterface.OnStartDismissListener {
+
+ private Activity mActivity;
+ private View mPopWindowLayout;
+ private FrameLayout mRootLayout;
+ private FrameLayout mContainLayout;
+ private PopDownView mPopDownView;
+ private LinearLayout mContentLayout;
+ private PopWindow mPopWindow;
+
+ private Animation mAlphaOpenAnimation;
+ private Animation mAlphaCloseAnimation;
+ private Animation mPopOpenAnimation;
+ private Animation mPopCloseAnimation;
+
+ private boolean mIsDismissed = true;
+
+ private View mCustomView;
+
+ public PopDownWindow(Activity activity, int titleResId, int messageResId, PopWindow popWindow) {
+ this(activity, titleResId == 0 ? null : activity.getString(titleResId), messageResId == 0 ? null : activity.getString(messageResId), popWindow);
+ }
+
+ public PopDownWindow(Activity activity, CharSequence title, CharSequence message, PopWindow popWindow) {
+ LayoutInflater inflater = (LayoutInflater) activity
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ mPopWindowLayout = inflater.inflate(R.layout.pop_down_window, null);
+ this.setContentView(mPopWindowLayout);
+ this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
+ this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
+ this.setFocusable(true);
+ this.setOutsideTouchable(true);
+ this.setAnimationStyle(R.style.PopDownWindow);
+
+ mActivity = activity;
+ mPopWindow = popWindow;
+
+ initRootView(mPopWindowLayout);
+ initContentView(mPopWindowLayout, title, message);
+ setListener();
+ initAnim();
+ }
+
+ private void initRootView(View view) {
+ mRootLayout = (FrameLayout) view.findViewById(R.id.layout_root);
+ mRootLayout.setOnClickListener(this);
+ }
+
+ private void initContentView(View view, CharSequence title, CharSequence message) {
+ mPopDownView = (PopDownView) view.findViewById(R.id.popDownView);
+ mPopDownView.setPopWindow(mPopWindow);
+ mPopDownView.setTitleAndMessage(title, message);
+
+ mContentLayout = (LinearLayout) view.findViewById(R.id.layout_top);
+ mContainLayout = (FrameLayout) view.findViewById(R.id.layout_contain);
+ }
+
+ private void setListener() {
+ mPopWindowLayout.setFocusable(true);
+ mPopWindowLayout.setFocusableInTouchMode(true);
+
+ mPopWindowLayout.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ public boolean onTouch(View v, MotionEvent event) {
+ dismiss();
+ return true;
+ }
+ });
+
+ mPopWindowLayout.setOnKeyListener(new View.OnKeyListener() {
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (keyCode == KeyEvent.KEYCODE_BACK) {
+ dismiss();
+ return true;
+ }
+ return false;
+ }
+ });
+ }
+
+ private void initAnim() {
+ mPopOpenAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation
+ .RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1, Animation.RELATIVE_TO_SELF, 0);
+ mPopOpenAnimation.setDuration(300);
+ mPopCloseAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
+ Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
+ mPopCloseAnimation.setDuration(300);
+ mPopCloseAnimation.setFillAfter(true);
+
+ mPopOpenAnimation.setAnimationListener(new PopSimpleAnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ mIsDismissed = false;
+ mRootLayout.startAnimation(mAlphaOpenAnimation);
+ }
+ });
+
+ mPopCloseAnimation.setAnimationListener(new PopSimpleAnimationListener() {
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ if (mCustomView != null) {
+ mContentLayout.post(mDismissRunnable);
+ } else
+ mPopDownView.post(mDismissRunnable);
+ }
+
+ @Override
+ public void onAnimationStart(Animation animation) {
+ mIsDismissed = true;
+ onStartDismiss(PopDownWindow.this);
+ mRootLayout.startAnimation(mAlphaCloseAnimation);
+ }
+ });
+
+ mAlphaOpenAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.pop_alpha_enter);
+ mAlphaCloseAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.pop_alpha_exit);
+ }
+
+ private Runnable mDismissRunnable = new Runnable() {
+ @Override
+ public void run() {
+ PopDownWindow.super.dismiss();
+ }
+ };
+
+ public void show(View view) {
+ if (mIsDismissed) {
+ onStartShow(PopDownWindow.this);
+ if (mCustomView != null) {
+ mContentLayout.startAnimation(mPopOpenAnimation);
+ } else if (mPopDownView.showAble()) {
+ mPopDownView.refreshBackground();
+ mPopDownView.startAnimation(mPopOpenAnimation);
+ } else {
+ throw new RuntimeException("必须至少添加一个PopItemView");
+ }
+
+ if (Build.VERSION.SDK_INT < 24) {
+ showAsDropDown(view);
+ } else {
+ Rect visibleFrame = new Rect();
+ view.getGlobalVisibleRect(visibleFrame);
+ int height = view.getResources().getDisplayMetrics().heightPixels - visibleFrame.bottom;
+ setHeight(height);
+ showAsDropDown(view, 0, 0);
+ }
+ }
+ }
+
+ @Override
+ public void dismiss() {
+ executeExitAnim();
+ }
+
+ private void executeExitAnim() {
+ if (!mIsDismissed) {
+ if (mCustomView != null) {
+ mContentLayout.startAnimation(mPopCloseAnimation);
+ } else
+ mPopDownView.startAnimation(mPopCloseAnimation);
+ }
+ }
+
+ @Override
+ public void addContentView(View view) {
+ view.setClickable(true);
+ mPopDownView.addContentView(view);
+ }
+
+ @Override
+ public void setView(View view) {
+ view.setClickable(true);
+ mCustomView = view;
+ mContentLayout.setVisibility(View.VISIBLE);
+ mPopDownView.setVisibility(View.GONE);
+ mContentLayout.addView(mCustomView);
+ }
+
+ @Override
+ public void addItemAction(PopItemAction popItemAction) {
+ if (mCustomView != null) {
+ return;
+ }
+ mContentLayout.setVisibility(View.GONE);
+ mPopDownView.setVisibility(View.VISIBLE);
+ mPopDownView.addItemAction(popItemAction);
+ }
+
+ @Override
+ public void setIsShowLine(boolean isShowLine) {
+ mPopDownView.setIsShowLine(isShowLine);
+ }
+
+ @Override
+ public void setIsShowCircleBackground(boolean isShow) {
+ mPopDownView.setIsShowCircleBackground(isShow);
+ if (!isShow) {
+ mPopDownView.setBackgroundColor(mActivity.getResources().getColor(R.color.pop_bg_content));
+ mPopDownView.post(new TimerTask() {
+ @Override
+ public void run() {
+ FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mPopDownView.getLayoutParams();
+ layoutParams.topMargin = 0;
+ }
+ });
+ }
+ }
+
+ @Override
+ public void setPopWindowMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mContainLayout.getLayoutParams();
+ layoutParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ mContainLayout.setLayoutParams(layoutParams);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.layout_root) {
+ dismiss();
+ }
+ }
+
+ @Override
+ public void onStartDismiss(PopWindowInterface popWindowInterface) {
+ mPopWindow.onStartDismiss(popWindowInterface);
+ }
+
+ @Override
+ public void onStartShow(PopWindowInterface popWindowInterface) {
+ mPopWindow.onStartShow(popWindowInterface);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java
new file mode 100644
index 0000000..5795309
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java
@@ -0,0 +1,81 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopItemAction {
+
+ private CharSequence mText;
+ private int mTextResId;
+ private PopItemStyle mPopItemStyle;
+ private OnClickListener mOnClickListener;
+
+ public PopItemAction(CharSequence text) {
+ this(text, PopItemStyle.Normal, null);
+ }
+
+ public PopItemAction(int textResId) {
+ this(textResId, PopItemStyle.Normal, null);
+ }
+
+ public PopItemAction(CharSequence text, OnClickListener listener) {
+ this(text, PopItemStyle.Normal, listener);
+ }
+
+ public PopItemAction(int textResId, OnClickListener listener) {
+ this(textResId, PopItemStyle.Normal, listener);
+ }
+
+
+ public PopItemAction(CharSequence text, PopItemStyle style) {
+ this(text, style, null);
+ }
+
+ public PopItemAction(int textResId, PopItemStyle style) {
+ this(textResId, style, null);
+ }
+
+ public PopItemAction(CharSequence text, PopItemStyle style, OnClickListener listener) {
+ mText = text;
+ mPopItemStyle = style;
+ mOnClickListener = listener;
+ }
+
+
+ public PopItemAction(int textResId, PopItemStyle style, OnClickListener listener) {
+ mTextResId = textResId;
+ mPopItemStyle = style;
+ mOnClickListener = listener;
+ }
+
+ public PopItemStyle getStyle() {
+ return mPopItemStyle;
+ }
+
+ public CharSequence getText() {
+ return mText;
+ }
+
+ public int getTextResId() {
+ return mTextResId;
+ }
+
+ public void setText(CharSequence text) {
+ this.mText = text;
+ }
+
+
+ public void onClick() {
+ if (mOnClickListener != null) {
+ mOnClickListener.onClick();
+ }
+ }
+
+ public interface OnClickListener {
+ void onClick();
+ }
+
+ public enum PopItemStyle {
+ Normal, Cancel, Warning
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopSimpleAnimationListener.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopSimpleAnimationListener.java
new file mode 100644
index 0000000..21c99f1
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopSimpleAnimationListener.java
@@ -0,0 +1,20 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.view.animation.Animation;
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopSimpleAnimationListener implements Animation.AnimationListener {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ }
+
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ }
+
+ @Override
+ public void onAnimationRepeat(Animation animation) {
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java
new file mode 100644
index 0000000..e033170
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java
@@ -0,0 +1,221 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.util.DisplayMetrics;
+import android.view.View;
+import android.view.WindowManager;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.view.PopUpView;
+
+
+public class PopUpWindow extends Dialog implements PopWindowInterface, DialogInterface.OnShowListener, View.OnClickListener,
+ PopWindowInterface.OnStartShowListener, PopWindowInterface.OnStartDismissListener {
+
+ private FrameLayout mRootLayout;
+ private FrameLayout mContainLayout;
+ private PopUpView mPopUpView;
+ private LinearLayout mContentLayout;
+ private PopWindow mPopWindow;
+
+ private Animation mAlphaOpenAnimation;
+ private Animation mAlphaCloseAnimation;
+ private Animation mPopOpenAnimation;
+ private Animation mPopCloseAnimation;
+
+ private PopItemAction mCancelPopItemAction;
+ private boolean mIsDismissed = true;
+
+ private View mCustomView;
+
+ public PopUpWindow(Activity activity, int titleResId, int messageResId, PopWindow popWindow) {
+ this(activity, titleResId == 0 ? null : activity.getString(titleResId), messageResId == 0 ? null : activity.getString(messageResId), popWindow);
+ }
+
+ public PopUpWindow(Activity activity, CharSequence title, CharSequence message, PopWindow popWindow) {
+ super(activity, R.style.PopWindowStyle);
+ setContentView(R.layout.pop_up_window);
+ getWindow().setWindowAnimations(R.style.PopWindowAnimation);
+ getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, getScreenHeight(activity) - getStatusBarHeight(activity));
+ setOnShowListener(this);
+ setCancelable(true);
+ setCanceledOnTouchOutside(true);
+ mPopWindow = popWindow;
+
+ initRootView();
+ initContentView(title, message);
+ initAnim();
+ }
+
+ private void initRootView() {
+ mRootLayout = (FrameLayout) findViewById(R.id.layout_root);
+ mRootLayout.setOnClickListener(this);
+ }
+
+ private void initContentView(CharSequence title, CharSequence message) {
+ mPopUpView = (PopUpView) findViewById(R.id.popUpView);
+ mPopUpView.setPopWindow(mPopWindow);
+ mPopUpView.setTitleAndMessage(title, message);
+
+ mContentLayout = (LinearLayout) findViewById(R.id.layout_bottom);
+ mContainLayout = (FrameLayout) findViewById(R.id.layout_contain);
+ }
+
+ private void initAnim() {
+ System.out.println(R.anim.pop_action_sheet_enter);
+ mPopOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_action_sheet_enter);
+ mPopCloseAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_action_sheet_exit);
+ mPopCloseAnimation.setAnimationListener(new PopSimpleAnimationListener() {
+ @Override
+ public void onAnimationEnd(Animation animation) {
+ if (mCustomView != null) {
+ mContentLayout.post(mDismissRunnable);
+ } else
+ mPopUpView.post(mDismissRunnable);
+ }
+ });
+
+ mAlphaOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_enter);
+ mAlphaCloseAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_exit);
+ mAlphaCloseAnimation.setAnimationListener(new PopSimpleAnimationListener() {
+ @Override
+ public void onAnimationStart(Animation animation) {
+ onStartDismiss(PopUpWindow.this);
+ if (mCustomView != null) {
+ mContentLayout.startAnimation(mPopCloseAnimation);
+ } else
+ mPopUpView.startAnimation(mPopCloseAnimation);
+ }
+ });
+ }
+
+ private Runnable mDismissRunnable = new Runnable() {
+ @Override
+ public void run() {
+ PopUpWindow.super.dismiss();
+ }
+ };
+
+
+ @Override
+ public void onShow(DialogInterface dialog) {
+ if (mIsDismissed) {
+ onStartShow(PopUpWindow.this);
+ mIsDismissed = false;
+ mRootLayout.startAnimation(mAlphaOpenAnimation);
+ if (mCustomView != null) {
+ mContentLayout.startAnimation(mPopOpenAnimation);
+ } else if (mPopUpView.showAble()) {
+ mPopUpView.refreshBackground();
+ mPopUpView.startAnimation(mPopOpenAnimation);
+ } else {
+ throw new RuntimeException("必须至少添加一个PopItemView");
+ }
+ }
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v.getId() == R.id.layout_root) {
+ onBackPressed();
+ }
+ }
+
+ @Override
+ public void cancel() {
+ super.cancel();
+ if (mCancelPopItemAction != null) {
+ mCancelPopItemAction.onClick();
+ }
+ }
+
+ @Override
+ public void dismiss() {
+ executeExitAnim();
+ }
+
+ private void executeExitAnim() {
+ if (!mIsDismissed) {
+ mIsDismissed = true;
+ mRootLayout.startAnimation(mAlphaCloseAnimation);
+ }
+ }
+
+ @Override
+ public void addContentView(View view) {
+ view.setClickable(true);
+ mPopUpView.addContentView(view);
+ }
+
+ @Override
+ public void setView(View view) {
+ view.setClickable(true);
+ mCustomView = view;
+ mContentLayout.setVisibility(View.VISIBLE);
+ mPopUpView.setVisibility(View.GONE);
+ mContentLayout.addView(mCustomView);
+ }
+
+ @Override
+ public void addItemAction(PopItemAction popItemAction) {
+ if (mCustomView != null) {
+ return;
+ }
+ mContentLayout.setVisibility(View.GONE);
+ mPopUpView.setVisibility(View.VISIBLE);
+ mPopUpView.addItemAction(popItemAction);
+ if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Cancel) {
+ setCancelable(true);
+ setCanceledOnTouchOutside(true);
+ mCancelPopItemAction = popItemAction;
+ }
+ }
+
+ @Override
+ public void setIsShowLine(boolean isShowLine) {
+ mPopUpView.setIsShowLine(isShowLine);
+ }
+
+ @Override
+ public void setIsShowCircleBackground(boolean isShow) {
+ mPopUpView.setIsShowCircleBackground(isShow);
+ }
+
+ @Override
+ public void setPopWindowMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mContainLayout.getLayoutParams();
+ layoutParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ mContainLayout.setLayoutParams(layoutParams);
+ }
+
+ public static int getStatusBarHeight(Context context) {
+ Resources resources = context.getResources();
+ int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
+ return resources.getDimensionPixelSize(resourceId);
+ }
+
+ public static int getScreenHeight(Context context) {
+ WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
+ DisplayMetrics dm = new DisplayMetrics();
+ windowManager.getDefaultDisplay().getMetrics(dm);
+ return dm.heightPixels;
+ }
+
+ @Override
+ public void onStartDismiss(PopWindowInterface popWindowInterface) {
+ mPopWindow.onStartDismiss(popWindowInterface);
+ }
+
+ @Override
+ public void onStartShow(PopWindowInterface popWindowInterface) {
+ mPopWindow.onStartShow(popWindowInterface);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java
new file mode 100644
index 0000000..b791ea3
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java
@@ -0,0 +1,35 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.view.View;
+
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public interface PopViewInterface {
+
+ void setTitleColor(int color);
+
+ void setTitleTextSize(int textSize);
+
+ void setMessageColor(int color);
+
+ void setMessageTextSize(int textSize);
+
+ void setTitleAndMessage(CharSequence title, CharSequence message);
+
+ void addContentView(View view);
+
+ void setPopWindow(PopWindow popWindow);
+
+ void addItemAction(PopItemAction popItemAction);
+
+ boolean showAble();
+
+ void refreshBackground();
+
+ void setIsShowLine(boolean isShowLine);
+
+ void setIsShowCircleBackground(boolean isShow);
+}
+
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java
new file mode 100644
index 0000000..5f96e40
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java
@@ -0,0 +1,332 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+
+
+import android.app.Activity;
+import android.view.View;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+
+
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopWindow implements PopWindowInterface,
+ PopWindowInterface.OnStartShowListener, PopWindowInterface.OnStartDismissListener {
+
+ private Activity mActivity;
+
+ private CharSequence mTitleText;
+ private CharSequence mMessageText;
+ private PopWindowStyle mStyle = PopWindowStyle.PopUp;
+ private View mCustomView;
+ private View mContentView;
+
+ private PopUpWindow mPopUpWindow;
+ private PopDownWindow mPopDownWindow;
+ private PopAlertDialog mPopAlertDialog;
+
+ private View mControlView = null;
+ private Animation mControlViewOpenAnimation;
+ private Animation mControlViewCloseAnimation;
+ private boolean mIsShowControlViewAnim;
+
+ public PopWindow(Activity activity, int titleResId, int messageResId, PopWindowStyle style) {
+ this(activity, titleResId == 0 ? null : activity.getString(titleResId), messageResId == 0 ? null : activity.getString(messageResId), style);
+ }
+
+ public PopWindow(Activity activity, CharSequence title, CharSequence message, PopWindowStyle style) {
+ mActivity = activity;
+ setTitle(title);
+ setMessage(message);
+ setStyle(style);
+ initPopWindow(activity, title, message);
+ }
+
+ public PopWindow(Activity activity) {
+ mActivity = activity;
+ initPopWindow(activity, null, null);
+ }
+
+ private void initPopWindow(Activity activity, CharSequence title, CharSequence message) {
+ if (mStyle == PopWindowStyle.PopUp) {
+ mPopUpWindow = new PopUpWindow(activity, title, message, this);
+ } else if (mStyle == PopWindowStyle.PopDown) {
+ mPopDownWindow = new PopDownWindow(activity, title, message, this);
+ } else if (mStyle == PopWindowStyle.PopAlert) {
+ mPopAlertDialog = new PopAlertDialog(activity, title, message, this);
+ }
+ }
+
+ public void setTitle(CharSequence title) {
+ mTitleText = title;
+ }
+
+ public void setMessage(CharSequence message) {
+ mMessageText = message;
+ }
+
+ public void setStyle(PopWindowStyle style) {
+ mStyle = style;
+ }
+
+ @Override
+ public void setView(View view) {
+ mCustomView = view;
+ if (view != null) {
+ if (mPopUpWindow != null) {
+ mPopUpWindow.setView(view);
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.setView(view);
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.setView(view);
+ }
+ }
+ }
+
+ @Override
+ public void addContentView(View view) {
+ mContentView = view;
+ if (mPopUpWindow != null) {
+ mPopUpWindow.addContentView(view);
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.addContentView(view);
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.addContentView(view);
+ }
+ }
+
+ @Override
+ public void setIsShowLine(boolean isShowLine) {
+ if (mPopUpWindow != null) {
+ mPopUpWindow.setIsShowLine(isShowLine);
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.setIsShowLine(isShowLine);
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.setIsShowLine(isShowLine);
+ }
+ }
+
+ @Override
+ public void setIsShowCircleBackground(boolean isShow) {
+ if (mPopUpWindow != null) {
+ mPopUpWindow.setIsShowCircleBackground(isShow);
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.setIsShowCircleBackground(isShow);
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.setIsShowCircleBackground(isShow);
+ }
+ }
+
+ @Override
+ public void setPopWindowMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ if (mPopUpWindow != null) {
+ mPopUpWindow.setPopWindowMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.setPopWindowMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.setPopWindowMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ }
+ }
+
+ @Override
+ public void onStartDismiss(PopWindowInterface popWindowInterface) {
+ if (mIsShowControlViewAnim) {
+ mControlView.startAnimation(mControlViewCloseAnimation);
+ }
+ }
+
+ @Override
+ public void onStartShow(PopWindowInterface popWindowInterface) {
+ if (mIsShowControlViewAnim) {
+ mControlView.startAnimation(mControlViewOpenAnimation);
+ }
+ }
+
+ /**
+ * 设置控制控件的动画
+ *
+ * @param view 控制控件
+ * @param openAnim 打开动画
+ * @param closeAnim 关闭动画
+ * @param isShowAnim 是否显示动画
+ */
+ public void setControlViewAnim(View view, Animation openAnim, Animation closeAnim, boolean isShowAnim) {
+ mControlView = view;
+ openAnim.setFillAfter(true);
+ closeAnim.setFillAfter(true);
+ mControlViewOpenAnimation = openAnim;
+ mControlViewCloseAnimation = closeAnim;
+ mIsShowControlViewAnim = isShowAnim;
+ }
+
+ /**
+ * @param view 控制控件
+ * @param openAnimId 打开动画id
+ * @param closeAnimId 关闭动画id
+ * @param isShowAnim 是否显示动画
+ */
+ public void setControlViewAnim(View view, int openAnimId, int closeAnimId, boolean isShowAnim) {
+ Animation openAnim = AnimationUtils.loadAnimation(mActivity, openAnimId);
+ Animation closeAnim = AnimationUtils.loadAnimation(mActivity, closeAnimId);
+ setControlViewAnim(view, openAnim, closeAnim, isShowAnim);
+ }
+
+ //构造器模式
+ public static class Builder {
+
+ private Activity activity;
+ private CharSequence title;
+ private CharSequence message;
+ private PopWindowStyle style = PopWindowStyle.PopUp;
+ private PopWindow popWindow;
+
+ public Builder(Activity activity) {
+ this.activity = activity;
+ }
+
+ public Builder setTitle(int titleResId) {
+ this.title = activity.getString(titleResId);
+ return this;
+ }
+
+ public Builder setTitle(CharSequence title) {
+ this.title = title;
+ return this;
+ }
+
+ public Builder setMessage(int messageResId) {
+ this.message = activity.getString(messageResId);
+ return this;
+ }
+
+ public Builder setMessage(CharSequence message) {
+ this.message = message;
+ return this;
+ }
+
+ public Builder setStyle(PopWindowStyle style) {
+ this.style = style;
+ return this;
+ }
+
+ public Builder setView(View view) {
+ create().setView(view);
+ return this;
+ }
+
+ public Builder addContentView(View view) {
+ create().addContentView(view);
+ return this;
+ }
+
+ public Builder setIsShowLine(boolean isShowLine) {
+ create().setIsShowLine(isShowLine);
+ return this;
+ }
+
+ public Builder setIsShowCircleBackground(boolean isShow) {
+ create().setIsShowCircleBackground(isShow);
+ return this;
+ }
+
+ public Builder addItemAction(PopItemAction popItemAction) {
+ create().addItemAction(popItemAction);
+ return this;
+ }
+
+ public Builder setPopWindowMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ create().setPopWindowMargins(leftMargin, topMargin, rightMargin, bottomMargin);
+ return this;
+ }
+
+ public Builder setControlViewAnim(View view, Animation openAnim, Animation closeAnim, boolean isShowAnim) {
+ create().setControlViewAnim(view, openAnim, closeAnim, isShowAnim);
+ return this;
+ }
+
+ public Builder setControlViewAnim(View view, int openAnimId, int closeAnimId, boolean isShowAnim) {
+ create().setControlViewAnim(view, openAnimId, closeAnimId, isShowAnim);
+ return this;
+ }
+
+ public PopWindow create() {
+ if (popWindow == null) {
+ popWindow = new PopWindow(activity, title, message, style);
+ }
+ return popWindow;
+ }
+
+ public PopWindow show(View view) {
+ create();
+ popWindow.show(view);
+ return popWindow;
+ }
+
+ public PopWindow show() {
+ return show(null);
+ }
+
+ }
+
+ public void show() {
+ show(null);
+ }
+
+ public void show(View view) {
+ if (mPopUpWindow != null) {
+ mPopUpWindow.show();
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.show(view);
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.show();
+ }
+ }
+
+ public void dismiss() {
+ if (mPopUpWindow != null) {
+ mPopUpWindow.dismiss();
+ }
+ if (mPopDownWindow != null) {
+ mPopDownWindow.dismiss();
+ }
+ if (mPopAlertDialog != null) {
+ mPopAlertDialog.dismiss();
+ }
+ }
+
+ @Override
+ public void addItemAction(PopItemAction popItemAction) {
+ if (popItemAction == null) {
+ return;
+ }
+ if (popItemAction.getTextResId() != 0) {
+ popItemAction.setText(mActivity.getString(popItemAction.getTextResId()));
+ }
+
+ if (mStyle == PopWindowStyle.PopUp) {
+ mPopUpWindow.addItemAction(popItemAction);
+ } else if (mStyle == PopWindowStyle.PopDown) {
+ mPopDownWindow.addItemAction(popItemAction);
+ } else if (mStyle == PopWindowStyle.PopAlert) {
+ mPopAlertDialog.addItemAction(popItemAction);
+ }
+ }
+
+ public enum PopWindowStyle {
+ PopUp, PopDown, PopAlert
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowHelper.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowHelper.java
new file mode 100644
index 0000000..3ccfbd5
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowHelper.java
@@ -0,0 +1,112 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.graphics.Typeface;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.TextUtils;
+import android.text.style.AbsoluteSizeSpan;
+import android.text.style.ForegroundColorSpan;
+import android.text.style.StyleSpan;
+import android.util.TypedValue;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.view.PopItemView;
+import com.moyv.schoolbbs.ui.view.popWindow.view.PopLineView;
+
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopWindowHelper {
+
+ public static void setTitleAndMessage(TextView titleTv, int titleColor, int titleTextSize, int messageColor, int messageTextSize, CharSequence title, CharSequence message) {
+ titleTv.setMinHeight(titleTextSize * 3);
+
+ if (!TextUtils.isEmpty(title) && TextUtils.isEmpty(message)) {
+ titleTv.setTextColor(titleColor);
+ titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleTextSize);
+ titleTv.getPaint().setFakeBoldText(true);
+ titleTv.setText(title);
+ } else if (TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
+ titleTv.setTextColor(messageColor);
+ titleTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, messageTextSize);
+ titleTv.setText(message);
+ } else if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
+ SpannableString titleSs = new SpannableString(title + "\n" + message);
+ titleSs.setSpan(new ForegroundColorSpan(titleColor), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ titleSs.setSpan(new AbsoluteSizeSpan(titleTextSize), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ titleSs.setSpan(new StyleSpan(Typeface.BOLD), 0, title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ titleSs.setSpan(new ForegroundColorSpan(messageColor), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ titleSs.setSpan(new AbsoluteSizeSpan(messageTextSize), title.length(), titleSs.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ titleTv.setText(titleSs);
+ titleTv.setLineSpacing(0.0f, 1.2f);
+ } else {
+ titleTv.setVisibility(View.GONE);
+ }
+ }
+
+ public static void refreshBackground(ViewGroup container, boolean isShowCircleBackground) {
+ if (container.getChildAt(0).getVisibility() == View.VISIBLE) {// 有标题的情况
+
+ if (container.getChildCount() >= 3) {
+ for (int i = 1; i < container.getChildCount(); i++) {
+ View child = container.getChildAt(i);
+ if (child instanceof PopItemView) {
+ if (isShowCircleBackground) {
+ if (i == container.getChildCount() - 1) {
+ child.setBackgroundResource(R.drawable.pop_selector_bottom);
+ } else {
+ child.setBackgroundResource(R.drawable.pop_selector_center);
+ }
+ } else {
+ child.setBackgroundResource(R.drawable.pop_selector_center);
+ }
+ }
+ }
+ }
+ } else {// 没有标题的情况
+ if (container.getChildCount() == 3) {
+ // 只有一个PopItemView的情况
+
+ // 移除第一条分割线
+ container.removeViewAt(1);
+
+ container.getChildAt(1).setBackgroundResource(R.drawable.pop_selector_cancel);
+ } else if (container.getChildCount() > 3) {
+ // 大于一个PopItemView的情况
+
+ // 移除第一条分割线
+ container.removeViewAt(1);
+
+ for (int i = 1; i < container.getChildCount(); i++) {
+ View child = container.getChildAt(i);
+ if (child instanceof PopItemView) {
+ if (isShowCircleBackground) {
+ if (i == 1) {
+ child.setBackgroundResource(R.drawable.pop_selector_top);
+ } else if (i == container.getChildCount() - 1) {
+ child.setBackgroundResource(R.drawable.pop_selector_bottom);
+ } else {
+ child.setBackgroundResource(R.drawable.pop_selector_center);
+ }
+ } else {
+ child.setBackgroundResource(R.drawable.pop_selector_center);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static boolean isLineView(View view) {
+ String tag = (String) view.getTag();
+ if (PopLineView.TAG_LINE_VIEW.equals(tag)) {
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowInterface.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowInterface.java
new file mode 100644
index 0000000..821609b
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindowInterface.java
@@ -0,0 +1,29 @@
+package com.moyv.schoolbbs.ui.view.popWindow;
+
+import android.view.View;
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public interface PopWindowInterface {
+
+ void setView(View view);
+
+ void addContentView(View view);
+
+ void addItemAction(PopItemAction popItemAction);
+
+ void setIsShowLine(boolean isShowLine);
+
+ void setIsShowCircleBackground(boolean isShow);
+
+ void setPopWindowMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin);
+
+ interface OnStartShowListener {
+ void onStartShow(PopWindowInterface popWindowInterface);
+ }
+
+ interface OnStartDismissListener {
+ void onStartDismiss(PopWindowInterface popWindowInterface);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java
new file mode 100644
index 0000000..e50cc8a
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java
@@ -0,0 +1,146 @@
+package com.moyv.schoolbbs.ui.view.popWindow.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopViewInterface;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindowHelper;
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopAlertView extends LinearLayout implements PopViewInterface {
+
+ private TextView mTitleTv;
+
+ private int mTitleColor;
+ private int mTitleTextSize;
+ private int mMessageColor;
+ private int mMessageTextSize;
+
+ private PopWindow mPopWindow;
+ private PopItemView mCancelItemView;
+ private View mContentView;
+
+ private boolean mIsFirstShow = true;
+ private boolean mIsShowLine = true;
+ private boolean mIsShowCircleBackground = true;
+
+ public PopAlertView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+
+ setOrientation(VERTICAL);
+ setBackgroundResource(R.drawable.pop_shape_bg);
+ mTitleTv = new TextView(context);
+ mTitleTv.setGravity(Gravity.CENTER);
+ mTitleTv.setBackgroundResource(android.R.color.transparent);
+ mTitleTv.setClickable(true);
+ int padding = getResources().getDimensionPixelOffset(R.dimen.pop_item_padding);
+ mTitleTv.setPadding(padding * 2, padding, padding * 2, padding);
+ addView(mTitleTv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
+
+ initTextAndMessage();
+ }
+
+ private void initTextAndMessage() {
+ mTitleColor = getResources().getColor(R.color.pop_action_sheet_title);
+ mTitleTextSize = getResources().getDimensionPixelOffset(R.dimen.pop_action_sheet_text_size_title);
+ mMessageColor = getResources().getColor(R.color.pop_action_sheet_message);
+ mMessageTextSize = getResources().getDimensionPixelOffset(R.dimen.pop_action_sheet_text_size_message);
+ }
+
+ @Override
+ public void setTitleColor(int color) {
+ mTitleColor = color;
+ }
+
+ @Override
+ public void setTitleTextSize(int textSize) {
+ mTitleTextSize = textSize;
+ }
+
+ @Override
+ public void setMessageColor(int color) {
+ mMessageColor = color;
+ }
+
+ @Override
+ public void setMessageTextSize(int textSize) {
+ mMessageTextSize = textSize;
+ }
+
+ @Override
+ public void setTitleAndMessage(CharSequence title, CharSequence message) {
+ PopWindowHelper.setTitleAndMessage(mTitleTv, mTitleColor, mTitleTextSize, mMessageColor, mMessageTextSize, title, message);
+ }
+
+ @Override
+ public void addContentView(View view) {
+ mContentView = view;
+ addLineView();
+ addView(mContentView);
+ }
+
+ @Override
+ public void setPopWindow(PopWindow popWindow) {
+ mPopWindow = popWindow;
+ }
+
+ @Override
+ public void addItemAction(PopItemAction popItemAction) {
+ PopItemView popItemView = new PopItemView(getContext(), popItemAction, mPopWindow);
+ if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Cancel) {
+ if (mCancelItemView == null) {
+ mCancelItemView = popItemView;
+ } else {
+ throw new RuntimeException("PopWindow 只能添加一个取消操作");
+ }
+ } else {
+ addLineView();
+ addView(popItemView);
+ }
+ }
+
+ @Override
+ public void setIsShowCircleBackground(boolean isShow) {
+ mIsShowCircleBackground = isShow;
+ }
+
+ @Override
+ public boolean showAble() {
+ return mCancelItemView != null || getChildCount() > 1;
+ }
+
+ @Override
+ public void refreshBackground() {
+ if (mIsFirstShow) {
+ mIsFirstShow = false;
+
+ if (mCancelItemView != null) {
+ addLineView();
+ addView(mCancelItemView);
+ }
+ PopWindowHelper.refreshBackground(this, mIsShowCircleBackground);
+ }
+ }
+
+ @Override
+ public void setIsShowLine(boolean isShowLine) {
+ mIsShowLine = isShowLine;
+ }
+
+ private void addLineView() {
+ int childCount = getChildCount();
+ if (mIsShowLine || childCount == 0) {//第一根始终都要添加,为了在最后refreshBackground时保证第一个是LineView
+ addView(new PopLineView(getContext()));
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopDownView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopDownView.java
new file mode 100644
index 0000000..ebfa6eb
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopDownView.java
@@ -0,0 +1,15 @@
+package com.moyv.schoolbbs.ui.view.popWindow.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopDownView extends PopAlertView {
+
+ public PopDownView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java
new file mode 100644
index 0000000..cd5edf6
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java
@@ -0,0 +1,52 @@
+package com.moyv.schoolbbs.ui.view.popWindow.view;
+
+
+import android.content.Context;
+import android.util.TypedValue;
+import android.view.Gravity;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+
+public class PopItemView extends androidx.appcompat.widget.AppCompatTextView implements View.OnClickListener {
+
+ private PopItemAction mPopItemAction;
+ private PopWindow mPopWindow;
+
+ public PopItemView(Context context, PopItemAction popItemAction, PopWindow windowController) {
+ super(context);
+ mPopItemAction = popItemAction;
+ mPopWindow = windowController;
+
+ int padding = getResources().getDimensionPixelOffset(R.dimen.pop_item_padding);
+ setPadding(padding, padding, padding, padding);
+ setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
+ if (popItemAction != null) {
+ if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Normal) {
+ setTextColor(getResources().getColor(R.color.pop_item_text_normal_color));
+ } else if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Cancel) {
+ setTextColor(getResources().getColor(R.color.pop_item_text_normal_color));
+ getPaint().setFakeBoldText(true);
+ } else if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Warning) {
+ setTextColor(getResources().getColor(R.color.pop_item_text_warning_color));
+ }
+ }
+ setGravity(Gravity.CENTER);
+ setClickable(true);
+ setOnClickListener(this);
+ setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelOffset(R.dimen.pop_item_text_size));
+ setText(popItemAction.getText());
+ }
+
+ @Override
+ public void onClick(View view) {
+ mPopItemAction.onClick();
+ mPopWindow.dismiss();
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopLineView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopLineView.java
new file mode 100644
index 0000000..949907f
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopLineView.java
@@ -0,0 +1,24 @@
+package com.moyv.schoolbbs.ui.view.popWindow.view;
+
+import android.content.Context;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+
+import com.moyv.schoolbbs.R;
+
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopLineView extends View {
+
+ public static final String TAG_LINE_VIEW = "tag_line_view";
+
+ public PopLineView(Context context) {
+ super(context);
+ setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelOffset(R.dimen.pop_line_height)));
+ setBackgroundResource(R.color.pop_item_bg_pressed);
+ setTag(TAG_LINE_VIEW);
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java
new file mode 100644
index 0000000..80154b1
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java
@@ -0,0 +1,161 @@
+package com.moyv.schoolbbs.ui.view.popWindow.view;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopViewInterface;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindowHelper;
+
+
+/**
+ * Created by HMY on 2016/9/10.
+ */
+public class PopUpView extends LinearLayout implements PopViewInterface {
+
+ private TextView mTitleTv;
+ private LinearLayout mContanierLl;
+
+ private int mTitleColor;
+ private int mTitleTextSize;
+ private int mMessageColor;
+ private int mMessageTextSize;
+
+ private PopWindow mPopWindow;
+ private PopItemView mCancelItemView;
+ private View mContentView;
+
+ private boolean mIsFirstShow = true;
+ private boolean mIsShowLine = true;
+ private boolean mIsShowCircleBackground = true;
+
+ public PopUpView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ setOrientation(VERTICAL);
+
+ mTitleTv = new TextView(context);
+ mTitleTv.setGravity(Gravity.CENTER);
+ mTitleTv.setBackgroundResource(android.R.color.transparent);
+ int padding = getResources().getDimensionPixelOffset(R.dimen.pop_item_padding);
+ mTitleTv.setPadding(padding * 2, padding, padding * 2, padding);
+ mTitleTv.setClickable(true);
+
+ mContanierLl = new LinearLayout(getContext());
+ mContanierLl.setOrientation(VERTICAL);
+ mContanierLl.setBackgroundResource(R.drawable.pop_shape_bg);
+ mContanierLl.addView(mTitleTv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
+
+ addView(mContanierLl, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
+
+ initTextAndMessage();
+ }
+
+ private void initTextAndMessage() {
+ mTitleColor = getResources().getColor(R.color.pop_action_sheet_title);
+ mTitleTextSize = getResources().getDimensionPixelOffset(R.dimen.pop_action_sheet_text_size_title);
+ mMessageColor = getResources().getColor(R.color.pop_action_sheet_message);
+ mMessageTextSize = getResources().getDimensionPixelOffset(R.dimen.pop_action_sheet_text_size_message);
+ }
+
+ @Override
+ public void setTitleColor(int color) {
+ mTitleColor = color;
+ }
+
+ @Override
+ public void setTitleTextSize(int textSize) {
+ mTitleTextSize = textSize;
+ }
+
+ @Override
+ public void setMessageColor(int color) {
+ mMessageColor = color;
+ }
+
+ @Override
+ public void setMessageTextSize(int textSize) {
+ mMessageTextSize = textSize;
+ }
+
+ @Override
+ public void setTitleAndMessage(CharSequence title, CharSequence message) {
+ PopWindowHelper.setTitleAndMessage(mTitleTv, mTitleColor, mTitleTextSize, mMessageColor, mMessageTextSize, title, message);
+ }
+
+ @Override
+ public void addContentView(View view) {
+ mContentView = view;
+ addLineView();
+ mContanierLl.addView(mContentView);
+ }
+
+ @Override
+ public void setPopWindow(PopWindow popWindow) {
+ mPopWindow = popWindow;
+ }
+
+ @Override
+ public void addItemAction(PopItemAction popItemAction) {
+ PopItemView popItemView = new PopItemView(getContext(), popItemAction, mPopWindow);
+ if (popItemAction.getStyle() == PopItemAction.PopItemStyle.Cancel) {
+ if (mCancelItemView == null) {
+ mCancelItemView = popItemView;
+ if (mIsShowCircleBackground) {
+ mCancelItemView.setBackgroundResource(R.drawable.pop_selector_cancel);
+ } else {
+ mCancelItemView.setBackgroundResource(R.drawable.pop_selector_cancel_square);
+ }
+ MarginLayoutParams params = (MarginLayoutParams) mCancelItemView.getLayoutParams();
+ params.topMargin = getResources().getDimensionPixelOffset(R.dimen.pop_item_padding);
+ addView(popItemView);
+ } else {
+ throw new RuntimeException("PopWindow 只能添加一个取消操作");
+ }
+ } else {
+ addLineView();
+ mContanierLl.addView(popItemView);
+ }
+ }
+
+ @Override
+ public boolean showAble() {
+ return mCancelItemView != null || mContanierLl.getChildCount() > 1;
+ }
+
+ @Override
+ public void refreshBackground() {
+ if (mIsFirstShow) {
+ mIsFirstShow = false;
+ PopWindowHelper.refreshBackground(mContanierLl, mIsShowCircleBackground);
+ }
+ }
+
+ @Override
+ public void setIsShowLine(boolean isShowLine) {
+ mIsShowLine = isShowLine;
+ }
+
+ @Override
+ public void setIsShowCircleBackground(boolean isShow) {
+ mIsShowCircleBackground = isShow;
+ if (!isShow) {
+ mContanierLl.setBackgroundColor(getContext().getResources().getColor(R.color.pop_bg_content));
+ if (mCancelItemView != null) {
+ mCancelItemView.setBackgroundResource(R.drawable.pop_selector_cancel);
+ }
+ }
+ }
+
+ private void addLineView() {
+ if (mIsShowLine || mContanierLl.getChildCount() == 0) {//第一根始终都要添加,为了在最后refreshBackground时保证第一个是LineView
+ mContanierLl.addView(new PopLineView(getContext()));
+ }
+ }
+
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/util/AnalysisUtils.java b/app/src/main/java/com/moyv/schoolbbs/util/AnalysisUtils.java
index c9928fe..33c626c 100644
--- a/app/src/main/java/com/moyv/schoolbbs/util/AnalysisUtils.java
+++ b/app/src/main/java/com/moyv/schoolbbs/util/AnalysisUtils.java
@@ -35,6 +35,9 @@ public class AnalysisUtils {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean("isLogin",false);
editor.putString("token","");
+// editor.putString("name","");
+// editor.putInt("account",0);
+// editor.putString("introduction","");
editor.commit();
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/util/UCropUtils.java b/app/src/main/java/com/moyv/schoolbbs/util/UCropUtils.java
new file mode 100644
index 0000000..72dc1e2
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/util/UCropUtils.java
@@ -0,0 +1,71 @@
+package com.moyv.schoolbbs.util;
+
+import android.content.Context;
+import android.graphics.Color;
+import android.net.Uri;
+import android.os.Environment;
+import android.widget.Toast;
+
+import androidx.appcompat.app.AppCompatActivity;
+
+import com.yalantis.ucrop.UCrop;
+import com.yalantis.ucrop.UCropActivity;
+
+import java.io.File;
+public class UCropUtils {
+ private Context context;
+
+ public UCropUtils(Context context){
+ this.context=context;
+ }
+ //图片裁剪的方法
+ public void startUCrop(Uri uri){
+ UCrop.Options options = new UCrop.Options();
+ //裁剪后图片保存在文件夹中
+ Uri destinationUri = Uri.fromFile(new File(context.getExternalCacheDir(), "ucrop.jpg"));
+ UCrop uCrop = UCrop.of(uri, destinationUri);//第一个参数是裁剪前的uri,第二个参数是裁剪后的uri
+ uCrop.withAspectRatio(1,1);//设置裁剪框的宽高比例
+ //下面参数分别是缩放,旋转,裁剪框的比例
+ options.setAllowedGestures(UCropActivity.ALL,UCropActivity.NONE,UCropActivity.ALL);
+ options.setToolbarTitle("移动和缩放");//设置标题栏文字
+ options.setCropGridStrokeWidth(2);//设置裁剪网格线的宽度(我这网格设置不显示,所以没效果)
+ options.setCropFrameStrokeWidth(10);//设置裁剪框的宽度
+ options.setMaxScaleMultiplier(3);//设置最大缩放比例
+ options.setHideBottomControls(true);//隐藏下边控制栏
+ options.setShowCropGrid(false); //设置是否显示裁剪网格
+ options.setShowCropFrame(false); //设置是否显示裁剪边框(true为方形边框)
+ options.setToolbarWidgetColor(Color.parseColor("#ffffff"));//标题字的颜色以及按钮颜色
+ options.setDimmedLayerColor(Color.parseColor("#AA000000"));//设置裁剪外颜色
+ options.setToolbarColor(Color.parseColor("#000000")); // 设置标题栏颜色
+ options.setStatusBarColor(Color.parseColor("#000000"));//设置状态栏颜色
+ options.setCropGridColor(Color.parseColor("#ffffff"));//设置裁剪网格的颜色
+ options.setCropFrameColor(Color.parseColor("#ffffff"));//设置裁剪框的颜色
+ uCrop.withOptions(options);
+ uCrop.start((AppCompatActivity) context);
+ }
+
+
+
+
+ //处理剪切失败的返回值
+ public void handleCropError(Throwable cropError) {
+ deleteTempPhotoFile();
+ if (cropError != null) {
+ Toast.makeText(context, cropError.getMessage(), Toast.LENGTH_LONG).show();
+ } else {
+ Toast.makeText(context, "无法剪切选择图片", Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ /**
+ * 删除拍照临时文件
+ */
+ private void deleteTempPhotoFile() {
+ File tempFile = new File(Environment.getExternalStorageDirectory() + File.separator + "output_iamge.jpg");
+ if (tempFile.exists() && tempFile.isFile()) {
+ tempFile.delete();
+ }
+ }
+
+
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/config/UIHelper.java b/app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java
similarity index 97%
rename from app/src/main/java/com/moyv/schoolbbs/ui/config/UIHelper.java
rename to app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java
index f43c4b3..b91acfa 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/config/UIHelper.java
+++ b/app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java
@@ -1,4 +1,4 @@
-package com.moyv.schoolbbs.ui.config;
+package com.moyv.schoolbbs.util;
import android.app.Dialog;
import android.content.Context;
diff --git a/app/src/main/res/anim/anim/fade_in.xml b/app/src/main/res/anim/anim/fade_in.xml
new file mode 100644
index 0000000..c8da556
--- /dev/null
+++ b/app/src/main/res/anim/anim/fade_in.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/anim/fade_out.xml b/app/src/main/res/anim/anim/fade_out.xml
new file mode 100644
index 0000000..2a8ebf8
--- /dev/null
+++ b/app/src/main/res/anim/anim/fade_out.xml
@@ -0,0 +1,7 @@
+
+
+
+
diff --git a/app/src/main/res/anim/anim/pop_action_sheet_enter.xml b/app/src/main/res/anim/anim/pop_action_sheet_enter.xml
new file mode 100644
index 0000000..259ef8d
--- /dev/null
+++ b/app/src/main/res/anim/anim/pop_action_sheet_enter.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/anim/pop_action_sheet_exit.xml b/app/src/main/res/anim/anim/pop_action_sheet_exit.xml
new file mode 100644
index 0000000..da81318
--- /dev/null
+++ b/app/src/main/res/anim/anim/pop_action_sheet_exit.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/anim/pop_alert_enter.xml b/app/src/main/res/anim/anim/pop_alert_enter.xml
new file mode 100644
index 0000000..1e8198b
--- /dev/null
+++ b/app/src/main/res/anim/anim/pop_alert_enter.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/anim/pop_alert_exit.xml b/app/src/main/res/anim/anim/pop_alert_exit.xml
new file mode 100644
index 0000000..498c0bb
--- /dev/null
+++ b/app/src/main/res/anim/anim/pop_alert_exit.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/anim/pop_alpha_enter.xml b/app/src/main/res/anim/anim/pop_alpha_enter.xml
new file mode 100644
index 0000000..18119a7
--- /dev/null
+++ b/app/src/main/res/anim/anim/pop_alpha_enter.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/anim/pop_alpha_exit.xml b/app/src/main/res/anim/anim/pop_alpha_exit.xml
new file mode 100644
index 0000000..ab9f3cf
--- /dev/null
+++ b/app/src/main/res/anim/anim/pop_alpha_exit.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/fade_in.xml b/app/src/main/res/anim/fade_in.xml
new file mode 100644
index 0000000..f2f73dc
--- /dev/null
+++ b/app/src/main/res/anim/fade_in.xml
@@ -0,0 +1,7 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/fade_out.xml b/app/src/main/res/anim/fade_out.xml
new file mode 100644
index 0000000..d76c109
--- /dev/null
+++ b/app/src/main/res/anim/fade_out.xml
@@ -0,0 +1,7 @@
+
+
+
+
diff --git a/app/src/main/res/anim/pop_action_sheet_enter.xml b/app/src/main/res/anim/pop_action_sheet_enter.xml
new file mode 100644
index 0000000..5cf295f
--- /dev/null
+++ b/app/src/main/res/anim/pop_action_sheet_enter.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/pop_action_sheet_exit.xml b/app/src/main/res/anim/pop_action_sheet_exit.xml
new file mode 100644
index 0000000..09043dd
--- /dev/null
+++ b/app/src/main/res/anim/pop_action_sheet_exit.xml
@@ -0,0 +1,10 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/pop_alert_enter.xml b/app/src/main/res/anim/pop_alert_enter.xml
new file mode 100644
index 0000000..d3b1ba7
--- /dev/null
+++ b/app/src/main/res/anim/pop_alert_enter.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/pop_alert_exit.xml b/app/src/main/res/anim/pop_alert_exit.xml
new file mode 100644
index 0000000..98d26d4
--- /dev/null
+++ b/app/src/main/res/anim/pop_alert_exit.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/pop_alpha_enter.xml b/app/src/main/res/anim/pop_alpha_enter.xml
new file mode 100644
index 0000000..21eaf56
--- /dev/null
+++ b/app/src/main/res/anim/pop_alpha_enter.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/anim/pop_alpha_exit.xml b/app/src/main/res/anim/pop_alpha_exit.xml
new file mode 100644
index 0000000..dae5f2c
--- /dev/null
+++ b/app/src/main/res/anim/pop_alpha_exit.xml
@@ -0,0 +1,8 @@
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/pop_selector_bottom.xml b/app/src/main/res/drawable-v24/pop_selector_bottom.xml
new file mode 100644
index 0000000..6d6b2fd
--- /dev/null
+++ b/app/src/main/res/drawable-v24/pop_selector_bottom.xml
@@ -0,0 +1,10 @@
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/pop_selector_cancel.xml b/app/src/main/res/drawable-v24/pop_selector_cancel.xml
new file mode 100644
index 0000000..480f55e
--- /dev/null
+++ b/app/src/main/res/drawable-v24/pop_selector_cancel.xml
@@ -0,0 +1,15 @@
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/pop_selector_cancel_square.xml b/app/src/main/res/drawable-v24/pop_selector_cancel_square.xml
new file mode 100644
index 0000000..6491dd2
--- /dev/null
+++ b/app/src/main/res/drawable-v24/pop_selector_cancel_square.xml
@@ -0,0 +1,13 @@
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/pop_selector_center.xml b/app/src/main/res/drawable-v24/pop_selector_center.xml
new file mode 100644
index 0000000..82970e3
--- /dev/null
+++ b/app/src/main/res/drawable-v24/pop_selector_center.xml
@@ -0,0 +1,9 @@
+
+
+ -
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/pop_selector_top.xml b/app/src/main/res/drawable-v24/pop_selector_top.xml
new file mode 100644
index 0000000..5ac544f
--- /dev/null
+++ b/app/src/main/res/drawable-v24/pop_selector_top.xml
@@ -0,0 +1,10 @@
+
+
+ -
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/drawable-v24/pop_shape_bg.xml b/app/src/main/res/drawable-v24/pop_shape_bg.xml
new file mode 100644
index 0000000..8e46966
--- /dev/null
+++ b/app/src/main/res/drawable-v24/pop_shape_bg.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_me.xml b/app/src/main/res/layout/fragment_me.xml
index 6ec3076..9df02da 100644
--- a/app/src/main/res/layout/fragment_me.xml
+++ b/app/src/main/res/layout/fragment_me.xml
@@ -90,6 +90,15 @@
android:layout_height="wrap_content"
android:orientation="vertical">
+
+
-
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/pop_down_window.xml b/app/src/main/res/layout/pop_down_window.xml
new file mode 100644
index 0000000..78821db
--- /dev/null
+++ b/app/src/main/res/layout/pop_down_window.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/pop_up_window.xml b/app/src/main/res/layout/pop_up_window.xml
new file mode 100644
index 0000000..3afe2df
--- /dev/null
+++ b/app/src/main/res/layout/pop_up_window.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-night/integers.xml b/app/src/main/res/values-night/integers.xml
new file mode 100644
index 0000000..55344e5
--- /dev/null
+++ b/app/src/main/res/values-night/integers.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index cb3cbb4..9022fc8 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -43,4 +43,13 @@
#e94f4f
#4e342e
+ #F9F9F9
+ #01000000
+ #70000000
+ #007AFF
+ #FF3B30
+ #EBEBEB
+ #4d4d4d
+ #8f8f8f
+
\ No newline at end of file
diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml
index e00c2dd..c3d856e 100644
--- a/app/src/main/res/values/dimens.xml
+++ b/app/src/main/res/values/dimens.xml
@@ -2,4 +2,11 @@
16dp
16dp
+
+ 10dp
+ 18sp
+ 1dp
+ 8dp
+ 16sp
+ 14sp
\ No newline at end of file
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 23a1a76..77c0458 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -66,4 +66,25 @@
- @anim/push_bottom_in
- @anim/push_bottom_out
+
+
+
+
+
+
\ No newline at end of file
--
Gitee
From 4706f9d0020f84ed78de039872993fa3cbd9031c Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Wed, 23 Jun 2021 18:01:58 +0800
Subject: [PATCH 8/9] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8F?=
=?UTF-8?q?=E5=8C=96=E4=B8=80=E4=B8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../main/java/com/moyv/schoolbbs/app/App.java | 11 +-
.../java/com/moyv/schoolbbs/base/Global.java | 38 ++--
.../java/com/moyv/schoolbbs/bean/ReModel.java | 12 +-
.../com/moyv/schoolbbs/bean/UserInfo.java | 4 +
.../config/PictureSelectorConfig.java | 19 +-
...ntConstant.java => SharedPreConstant.java} | 20 +-
.../moyv/schoolbbs/config/URLConstant.java | 11 +-
.../java/com/moyv/schoolbbs/pojo/Comment.java | 11 +-
.../moyv/schoolbbs/pojo/HandlerPosition.java | 3 +
.../java/com/moyv/schoolbbs/pojo/Item.java | 3 +
.../java/com/moyv/schoolbbs/pojo/Post.java | 3 +
.../moyv/schoolbbs/service/ChangeService.java | 54 +++---
.../moyv/schoolbbs/service/CmtService.java | 51 +++---
.../schoolbbs/service/DeletePostService.java | 65 +++++++
.../moyv/schoolbbs/service/LoginService.java | 47 +++--
.../moyv/schoolbbs/service/MainService.java | 146 +++++----------
.../schoolbbs/service/PictureService.java | 49 ++---
.../service/PostsManagerService.java | 8 -
.../schoolbbs/service/RegisterService.java | 38 ++--
.../moyv/schoolbbs/service/StarService.java | 49 +++--
.../schoolbbs/service/UserInfoService.java | 19 +-
.../schoolbbs/ui/activity/AddActivity.java | 24 ++-
.../ui/activity/BottomTabLayoutActivity.java | 57 +++---
.../schoolbbs/ui/activity/LoginActivity.java | 94 +++++-----
.../ui/activity/ManagerActivity.java | 106 +++++------
.../ui/activity/PlusImageActivity.java | 12 +-
.../ui/activity/RegisterActivity.java | 19 +-
.../schoolbbs/ui/adapter/DataAdapter.java | 171 +++++++++---------
.../schoolbbs/ui/adapter/DataGenerator.java | 4 +-
.../schoolbbs/ui/adapter/GridViewAdapter.java | 3 +
.../schoolbbs/ui/adapter/ImagesAdapter.java | 10 +-
.../schoolbbs/ui/adapter/ManagerAdapter.java | 63 -------
.../ui/adapter/ViewPagerAdapter.java | 3 +
.../schoolbbs/ui/config/CancelOrOkDialog.java | 3 +
.../moyv/schoolbbs/ui/config/GlideEngine.java | 3 +
.../schoolbbs/ui/fragment/HomeFragment.java | 98 +++++-----
.../schoolbbs/ui/fragment/MeFragment.java | 113 +++---------
.../ui/fragment/MessageFragment.java | 11 +-
.../EndlessRecyclerOnScrollListener.java | 3 +-
.../ui/spannable/CircleMovementMethod.java | 47 ++---
.../schoolbbs/ui/spannable/ISpanClick.java | 3 +
.../ui/spannable/SpannableClickable.java | 8 +-
.../ui/view/popWindow/PopAlertDialog.java | 15 +-
.../ui/view/popWindow/PopItemAction.java | 2 +-
.../ui/view/popWindow/PopViewInterface.java | 2 +
.../ui/view/popWindow/view/PopAlertView.java | 2 +-
.../ui/view/popWindow/view/PopItemView.java | 3 +-
.../ui/view/popWindow/view/PopUpView.java | 2 +-
.../popWindow/{ => window}/PopDownWindow.java | 9 +-
.../popWindow/{ => window}/PopUpWindow.java | 5 +-
.../popWindow/{ => window}/PopWindow.java | 5 +-
.../com/moyv/schoolbbs/util/FormatUtils.java | 36 ++++
.../com/moyv/schoolbbs/util/UIHelper.java | 1 -
app/src/main/res/layout/fragment_me.xml | 75 +++++---
.../main/res/layout/item_fragment_main.xml | 4 +-
55 files changed, 838 insertions(+), 839 deletions(-)
rename app/src/main/java/com/moyv/schoolbbs/config/{AccountConstant.java => SharedPreConstant.java} (35%)
create mode 100644 app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java
delete mode 100644 app/src/main/java/com/moyv/schoolbbs/service/PostsManagerService.java
delete mode 100644 app/src/main/java/com/moyv/schoolbbs/ui/adapter/ManagerAdapter.java
rename app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/{ => window}/PopDownWindow.java (95%)
rename app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/{ => window}/PopUpWindow.java (96%)
rename app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/{ => window}/PopWindow.java (97%)
diff --git a/app/src/main/java/com/moyv/schoolbbs/app/App.java b/app/src/main/java/com/moyv/schoolbbs/app/App.java
index 4a31dab..770f0f1 100644
--- a/app/src/main/java/com/moyv/schoolbbs/app/App.java
+++ b/app/src/main/java/com/moyv/schoolbbs/app/App.java
@@ -3,15 +3,16 @@ package com.moyv.schoolbbs.app;
import android.app.Application;
import android.content.Context;
+
/**
- * @作者: njb
- * @时间: 2019/7/22 11:07
- * @描述:
+ * @author moyv
*/
public class App extends Application {
- //全局Context
- private static Context sContext;
+ /**
+ * 全局Context
+ */
+ private static Context sContext;
@Override
public void onCreate() {
super.onCreate();
diff --git a/app/src/main/java/com/moyv/schoolbbs/base/Global.java b/app/src/main/java/com/moyv/schoolbbs/base/Global.java
index a70c492..b314236 100644
--- a/app/src/main/java/com/moyv/schoolbbs/base/Global.java
+++ b/app/src/main/java/com/moyv/schoolbbs/base/Global.java
@@ -3,7 +3,6 @@ package com.moyv.schoolbbs.base;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
-import android.os.Message;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.widget.Toast;
@@ -11,6 +10,10 @@ import android.widget.Toast;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
+/**
+ * @author moyv
+ * @描述 获取全局信息
+ */
public class Global {
private static Context context;
@@ -39,8 +42,14 @@ public class Global {
return (int) (dp * mDensity + 0.5f);
}
- public static void showToast(String msg) {
- Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
+ /**
+ * 获取宫格图片的宽高
+ */
+ public static int getGridWidth() {
+// 左边距: 10dp
+// 右边距: 10dp
+// 图片宫格的宽度 = (屏幕宽度-左边距-右边距) / 3
+ return (Global.mScreenWidth - Global.dp2px(10 + 10)) / 3;
}
/**
@@ -86,29 +95,6 @@ public class Global {
drawableName, "drawable", context.getPackageName());
}
-// Handler handler = new Handler(new Handler.Callback() {
-// @Override
-// public boolean handleMessage(@NonNull Message msg) {
-// Bitmap bitmap = (Bitmap) msg.obj;
-// createBitmap(bitmap, getGridWidth());
-// return false;
-// }
-// });
-//
-// public void Bitmap(String url) {
-// getPicture(url, handler);
-// }
-
- /**
- * 获取宫格图片的宽高
- */
- public static int getGridWidth() {
- // 左边距: 10dp
- // 右边距: 10dp
- // 图片宫格的宽度 = (屏幕宽度-左边距-右边距) / 3
- return (Global.mScreenWidth - Global.dp2px(10 + 10)) / 3;
- }
-
/**
* 根据一张原图生成一张指定宽高的图片
*
diff --git a/app/src/main/java/com/moyv/schoolbbs/bean/ReModel.java b/app/src/main/java/com/moyv/schoolbbs/bean/ReModel.java
index 8a6cd06..12c47a7 100644
--- a/app/src/main/java/com/moyv/schoolbbs/bean/ReModel.java
+++ b/app/src/main/java/com/moyv/schoolbbs/bean/ReModel.java
@@ -7,9 +7,15 @@ import com.moyv.schoolbbs.pojo.Star;
import java.util.List;
+/**
+ * @author moyv
+ * @描述 首页返回信息封装类
+ */
public class ReModel {
@SerializedName("main")
private List main;
+ @SerializedName("count")
+ private int count;
public List getMain() {
return main;
@@ -19,9 +25,6 @@ public class ReModel {
this.main = main;
}
- @SerializedName("count")
- private int count;
-
public int getCount() {
return count;
}
@@ -30,6 +33,9 @@ public class ReModel {
this.count = count;
}
+ /**
+ * 一个子布局信息封装
+ */
public static class Main {
@SerializedName("comments")
private List comments;
diff --git a/app/src/main/java/com/moyv/schoolbbs/bean/UserInfo.java b/app/src/main/java/com/moyv/schoolbbs/bean/UserInfo.java
index 3fa4d9f..a138b7f 100644
--- a/app/src/main/java/com/moyv/schoolbbs/bean/UserInfo.java
+++ b/app/src/main/java/com/moyv/schoolbbs/bean/UserInfo.java
@@ -2,6 +2,10 @@ package com.moyv.schoolbbs.bean;
import com.google.gson.annotations.SerializedName;
+/**
+ * @author moyv
+ * @描述 用户信息封装
+ */
public class UserInfo {
@SerializedName("head")
private String head;
diff --git a/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java b/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java
index 3478d49..dc34217 100644
--- a/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java
+++ b/app/src/main/java/com/moyv/schoolbbs/config/PictureSelectorConfig.java
@@ -8,11 +8,14 @@ import com.luck.picture.lib.config.PictureMimeType;
import com.moyv.schoolbbs.ui.config.GlideEngine;
+/**
+ * @author moyv
+ * @描述 PictureSelector框架的使用
+ */
public class PictureSelectorConfig {
/**
- * 初始化多图选择的配置
- *
+ * @描述 打开图片选择器,发表界面图片选择,初始化多图选择的配置
* @param activity
* @param maxTotal
*/
@@ -44,7 +47,11 @@ public class PictureSelectorConfig {
.forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
}
- public static void initMultiConfigCut(Activity activity, int maxTotal){
+ /**
+ * 打开图片选择器,实现裁剪,配置
+ * @param activity
+ */
+ public static void initMultiConfigCut(Activity activity) {
PictureSelector.create(activity)
.openGallery(PictureMimeType.ofAll())// 全部.PictureMimeType.ofAll()、图片.ofImage()、视频.ofVideo()、音频.ofAudio()
// .theme(R.style.picture.white.style)// 主题样式设置 具体参考 values/styles 用法:R.style.picture.white.style
@@ -71,7 +78,11 @@ public class PictureSelectorConfig {
.forResult(PictureConfig.CHOOSE_REQUEST);//结果回调onActivityResult code
}
- public static void initCamer(Activity activity){
+ /**
+ * @描述 头像上传打开相机,实现裁剪,配置
+ * @param activity
+ */
+ public static void initCamer(Activity activity) {
PictureSelector.create(activity)
.openCamera(PictureMimeType.ofImage())
.isEnableCrop(true)// 是否裁剪
diff --git a/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java b/app/src/main/java/com/moyv/schoolbbs/config/SharedPreConstant.java
similarity index 35%
rename from app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
rename to app/src/main/java/com/moyv/schoolbbs/config/SharedPreConstant.java
index 9f828df..9605419 100644
--- a/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
+++ b/app/src/main/java/com/moyv/schoolbbs/config/SharedPreConstant.java
@@ -5,21 +5,23 @@ import android.content.SharedPreferences;
/**
* @author moyv
+ * @描述 sharedPreferences文件的数据作为全局变量
*/
-public class AccountConstant {
+public class SharedPreConstant {
public static boolean LOGIN;
public static int ACCOUNT;
public static String TOKEN;
public static String NAME;
public static String INTRODUCTION;
- public AccountConstant(Context context){
- SharedPreferences sharedPreferences=context.getSharedPreferences("login",0);
- LOGIN=sharedPreferences.getBoolean("isLogin",false);
- if(LOGIN){
- ACCOUNT=sharedPreferences.getInt("account",0);
- TOKEN=sharedPreferences.getString("token","");
- NAME=sharedPreferences.getString("name","");
- INTRODUCTION=sharedPreferences.getString("introduction","");
+
+ public SharedPreConstant(Context context) {
+ SharedPreferences sharedPreferences = context.getSharedPreferences("login", 0);
+ LOGIN = sharedPreferences.getBoolean("isLogin", false);
+ if (LOGIN) {
+ ACCOUNT = sharedPreferences.getInt("account", 0);
+ TOKEN = sharedPreferences.getString("token", "");
+ NAME = sharedPreferences.getString("name", "");
+ INTRODUCTION = sharedPreferences.getString("introduction", "");
}
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/config/URLConstant.java b/app/src/main/java/com/moyv/schoolbbs/config/URLConstant.java
index 913f65b..7dd9e1d 100644
--- a/app/src/main/java/com/moyv/schoolbbs/config/URLConstant.java
+++ b/app/src/main/java/com/moyv/schoolbbs/config/URLConstant.java
@@ -1,9 +1,15 @@
package com.moyv.schoolbbs.config;
+/**
+ * @author moyv
+ */
public class URLConstant {
- public static final String HOST="http://192.168.0.101:8080/bbs_servlet";
+// tomcat位置
+// public static final String HOST="http://192.168.0.101:8080/bbs_servlet";
+// 服务器位置
// public static final String HOST="http://www.lyczs.xyz:8080/bbs_servlet";
-// public static final String HOST="http://192.168.43.224:8080/bbs_servlet";
+// 手机热点位置
+ public static final String HOST="http://192.168.43.224:8080/bbs_servlet";
public static final String MAIN_URL=HOST+"/main";
public static final String LOGIN_URL=HOST+"/login";
public static final String REGISTER_URL=HOST+"/register";
@@ -15,4 +21,5 @@ public class URLConstant {
public static final String CMT_URL=HOST+"/cmt";
public static final String STAR_URL=HOST+"/star";
public static final String CHANGE_URL=HOST+"/change";
+ public static final String DELETE_URL=HOST+"/deletePost";
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java b/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
index c3e6328..5752441 100644
--- a/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/Comment.java
@@ -6,6 +6,9 @@ import com.moyv.schoolbbs.bean.UserInfo;
import java.sql.Timestamp;
import java.util.Date;
+/**
+ * @author moyv
+ */
public class Comment {
@SerializedName("commentId")
private int commentId;
@@ -19,10 +22,10 @@ public class Comment {
private int postId;
@SerializedName("cmtName")
private String cmtName;
-
- private UserInfo replyUser; // 回复人信息
-
- private UserInfo commentsUser; // 评论人信息
+ // 回复人信息
+ private UserInfo replyUser;
+ // 评论人信息
+ private UserInfo commentsUser;
public UserInfo getReplyUser() {
return replyUser;
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java b/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java
index 4b13e90..fa0c1dc 100644
--- a/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/HandlerPosition.java
@@ -1,5 +1,8 @@
package com.moyv.schoolbbs.pojo;
+/**
+ * @author moyv
+ */
public class HandlerPosition {
private int position;
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/Item.java b/app/src/main/java/com/moyv/schoolbbs/pojo/Item.java
index 06b2408..492ff3e 100644
--- a/app/src/main/java/com/moyv/schoolbbs/pojo/Item.java
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/Item.java
@@ -6,6 +6,9 @@ import com.moyv.schoolbbs.bean.ReModel;
import java.util.List;
+/**
+ * @author moyv
+ */
public class Item {
private ReModel.Main main;
private List urls;
diff --git a/app/src/main/java/com/moyv/schoolbbs/pojo/Post.java b/app/src/main/java/com/moyv/schoolbbs/pojo/Post.java
index 6da7b03..a20dddc 100644
--- a/app/src/main/java/com/moyv/schoolbbs/pojo/Post.java
+++ b/app/src/main/java/com/moyv/schoolbbs/pojo/Post.java
@@ -7,6 +7,9 @@ import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;
+/**
+ * @author moyv
+ */
public class Post implements Serializable {
@SerializedName("postType")
private Integer postType;
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java b/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java
index 4739fcf..f01c4a5 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java
@@ -17,45 +17,45 @@ import okhttp3.Request;
import okhttp3.Response;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
+import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.CHANGE_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
import static com.moyv.schoolbbs.util.ToastUtils.show;
public class ChangeService {
- public void changeInfo(int index, String content,Handler handler){
- String url=CHANGE_URL;
- String params="";
- switch (index){
+ public void changeInfo(int index, String content, Handler handler) {
+ String url = CHANGE_URL;
+ String params = "";
+ switch (index) {
case 1:
// 用户名修改
- params="name";
+ params = "name";
break;
case 2:
// 用户简介修改
- params="introduction";
+ params = "introduction";
break;
case 3:
// 用户密码修改
- params="password";
+ params = "password";
break;
default:
}
- OkHttpClient okHttpClient=createClient();
- JSONObject obj=new JSONObject();
- try{
- obj.put("account",ACCOUNT);
- obj.put("params",params);
- obj.put("value",content);
- }catch (JSONException e){
+ OkHttpClient okHttpClient = createClient();
+ JSONObject obj = new JSONObject();
+ try {
+ obj.put("account", ACCOUNT);
+ obj.put("params", params);
+ obj.put("value", content);
+ } catch (JSONException e) {
Log.d(TAG, "getPost: json添加失败");
}
- FormBody formBody=new FormBody.Builder()
- .add("request",obj.toString())
- .add("token",TOKEN)
+ FormBody formBody = new FormBody.Builder()
+ .add("request", obj.toString())
+ .add("token", TOKEN)
.build();
- Request request=new Request.Builder()
+ Request request = new Request.Builder()
.post(formBody)
.url(url)
.build();
@@ -67,15 +67,15 @@ public class ChangeService {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
- String responseData=response.body().string();
- int result=0;
- try{
- JSONObject obj=new JSONObject(responseData);
- result=obj.getInt("result");
- }catch (JSONException e){
+ String responseData = response.body().string();
+ int result = 0;
+ try {
+ JSONObject obj = new JSONObject(responseData);
+ result = obj.getInt("result");
+ } catch (JSONException e) {
show("修改信息返回数据时解析失败");
}
- switch (result){
+ switch (result) {
case 0:
show("非法的token");
break;
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java b/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
index 6d0c324..f84c262 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
@@ -20,33 +20,32 @@ import okhttp3.Request;
import okhttp3.Response;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
+import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.CMT_URL;
-import static com.moyv.schoolbbs.config.URLConstant.MAIN_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
import static com.moyv.schoolbbs.util.JsonUtil.parseJson;
public class CmtService {
- public void pushCmt(Comment comment, Handler handler,int position){
- String url=CMT_URL;
- OkHttpClient okHttpClient=createClient();
+ public void pushCmt(Comment comment, Handler handler, int position) {
+ String url = CMT_URL;
+ OkHttpClient okHttpClient = createClient();
// 请求体
- JSONObject cmt=new JSONObject();
- try{
- cmt.put("postId",comment.getPostId());
- cmt.put("account",comment.getCommentAccount());
- cmt.put("content",comment.getCommentContent());
- }catch (JSONException e){
+ JSONObject cmt = new JSONObject();
+ try {
+ cmt.put("postId", comment.getPostId());
+ cmt.put("account", comment.getCommentAccount());
+ cmt.put("content", comment.getCommentContent());
+ } catch (JSONException e) {
Log.d(TAG, "pushCmt: json操作有问题");
}
- FormBody formBody=new FormBody.Builder()
- .add("comment",cmt.toString())
- .add("token",TOKEN)
+ FormBody formBody = new FormBody.Builder()
+ .add("comment", cmt.toString())
+ .add("token", TOKEN)
.build();
// 发送请求操作
- Request request=new Request.Builder()
+ Request request = new Request.Builder()
.post(formBody)
.url(url)
.build();
@@ -58,24 +57,24 @@ public class CmtService {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
- String responseData=response.body().string();
- JSONObject object= null;
- JSONObject objComment=null;
- int result=0;
+ String responseData = response.body().string();
+ JSONObject object = null;
+ JSONObject objComment = null;
+ int result = 0;
try {
object = new JSONObject(responseData);
- result=object.getInt("result");
+ result = object.getInt("result");
System.out.println(object);
- if(result==1){
+ if (result == 1) {
- objComment=object.getJSONObject("comment");
+ objComment = object.getJSONObject("comment");
System.out.println(objComment);
- Comment comment1=parseJson(objComment.toString(),Comment.class);
- HandlerPosition handlerPosition=new HandlerPosition();
+ Comment comment1 = parseJson(objComment.toString(), Comment.class);
+ HandlerPosition handlerPosition = new HandlerPosition();
handlerPosition.setObj(comment1);
handlerPosition.setPosition(position);
- handler.sendMessage(handler.obtainMessage(0,handlerPosition));
- }else{
+ handler.sendMessage(handler.obtainMessage(0, handlerPosition));
+ } else {
handler.sendMessage(handler.obtainMessage(505));
}
} catch (JSONException e) {
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java b/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java
new file mode 100644
index 0000000..35d1688
--- /dev/null
+++ b/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java
@@ -0,0 +1,65 @@
+package com.moyv.schoolbbs.service;
+
+
+import android.os.Handler;
+
+import org.jetbrains.annotations.NotNull;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.IOException;
+
+import okhttp3.Call;
+import okhttp3.Callback;
+import okhttp3.FormBody;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
+import static com.moyv.schoolbbs.config.URLConstant.DELETE_URL;
+import static com.moyv.schoolbbs.util.HttpUtil.createClient;
+
+public class DeletePostService {
+ public static void deletePost(int postId, Handler handler) {
+ String url = DELETE_URL;
+ OkHttpClient okHttpClient = createClient();
+ FormBody formBody = new FormBody.Builder()
+ .add("postId", String.valueOf(postId))
+ .add("token", TOKEN)
+ .build();
+// 发送请求操作
+ Request request = new Request.Builder()
+ .post(formBody)
+ .url(url)
+ .build();
+ okHttpClient.newCall(request).enqueue(new Callback() {
+ @Override
+ public void onFailure(@NotNull Call call, @NotNull IOException e) {
+ handler.sendMessage(handler.obtainMessage(505));
+ }
+
+ @Override
+ public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
+ String responseData = response.body().string();
+ System.out.println(responseData);
+ JSONObject object = null;
+ int result = 0;
+ try {
+ object = new JSONObject(responseData);
+ result = object.getInt("result");
+ System.out.println(object);
+ if (result == 1) {
+ handler.sendMessage(handler.obtainMessage(200));
+ } else {
+ handler.sendMessage(handler.obtainMessage(505));
+ }
+ } catch (JSONException e) {
+ e.printStackTrace();
+ handler.sendMessage(handler.obtainMessage(505));
+ }
+
+ }
+ });
+ }
+}
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/LoginService.java b/app/src/main/java/com/moyv/schoolbbs/service/LoginService.java
index 1b0bcbe..219ad38 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/LoginService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/LoginService.java
@@ -1,13 +1,9 @@
package com.moyv.schoolbbs.service;
import android.os.Handler;
-import android.os.Message;
import android.util.Log;
-import androidx.annotation.NonNull;
-
import com.moyv.schoolbbs.bean.LoginBean;
-import com.moyv.schoolbbs.util.JsonUtil;
import org.jetbrains.annotations.NotNull;
import org.json.JSONException;
@@ -23,7 +19,6 @@ import okhttp3.Request;
import okhttp3.Response;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.LOGIN_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
import static com.moyv.schoolbbs.util.JsonUtil.parseLoginBean;
@@ -33,24 +28,24 @@ import static com.moyv.schoolbbs.util.JsonUtil.parseLoginBean;
*/
public class LoginService {
- public void getLogin(int account,String password,Handler handler){
- String url=LOGIN_URL;
- OkHttpClient okHttpClient=createClient();
- JSONObject obj=new JSONObject();
- try{
- obj.put("account",account);
- obj.put("password",password);
- }catch (JSONException e){
+ public void getLogin(int account, String password, Handler handler) {
+ String url = LOGIN_URL;
+ OkHttpClient okHttpClient = createClient();
+ JSONObject obj = new JSONObject();
+ try {
+ obj.put("account", account);
+ obj.put("password", password);
+ } catch (JSONException e) {
Log.d(TAG, "getPost: json添加失败");
}
- FormBody formBody=new FormBody.Builder()
- .add("request",obj.toString())
+ FormBody formBody = new FormBody.Builder()
+ .add("request", obj.toString())
.build();
- Request request=new Request.Builder()
+ Request request = new Request.Builder()
.post(formBody)
.url(url)
.build();
- okHttpClient.newCall(request).enqueue(new Callback(){
+ okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
System.out.println("mainService.getPost:连接服务器失败");
@@ -60,28 +55,28 @@ public class LoginService {
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
System.out.println("mainService.getPost:连接服务器成功");
- String responseData=response.body().string();
+ String responseData = response.body().string();
System.out.println(responseData);
- int status=0;
+ int status = 0;
try {
- JSONObject jsonObject=new JSONObject(responseData);
- status=jsonObject.getInt("status");
+ JSONObject jsonObject = new JSONObject(responseData);
+ status = jsonObject.getInt("status");
} catch (JSONException e) {
e.printStackTrace();
}
- switch (status){
+ switch (status) {
case 0:
System.out.println("用户不存在,请先注册");
handler.sendMessage(handler.obtainMessage(300));
break;
case 1:
System.out.println("用户登录成功");
- LoginBean loginBean= parseLoginBean(responseData);
+ LoginBean loginBean = parseLoginBean(responseData);
System.out.println("数据解析完毕");
- if(loginBean==null){
+ if (loginBean == null) {
handler.sendMessage(handler.obtainMessage(500));
- }else{
- handler.sendMessage(handler.obtainMessage(200,loginBean));
+ } else {
+ handler.sendMessage(handler.obtainMessage(200, loginBean));
}
break;
case 2:
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/MainService.java b/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
index 3face2a..404e7c9 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/MainService.java
@@ -33,148 +33,102 @@ import static com.moyv.schoolbbs.util.JsonUtil.parseReModel;
* @author moyv
*/
public class MainService {
- public static int USER_POSTS =123;
- public static int STAR_POSTS=321;
+ public static int USER_POSTS = 123;
+ public static int STAR_POSTS = 321;
private String url;
private ReModel reModel = null;
- private Handler handler=null;
- public MainService(){}
- public MainService(Handler handler){
- this.handler=handler;
+ private Handler handler = null;
+
+ public MainService() {
+ }
+
+ public MainService(Handler handler) {
+ this.handler = handler;
}
- public void getPost(int star,int end) {
- url=MAIN_URL;
- OkHttpClient okHttpClient=createClient();
+
+ public void getPost(int star, int end) {
+ url = MAIN_URL;
+ System.out.println(url);
+ OkHttpClient okHttpClient = createClient();
// 请求体
- JSONObject obj=new JSONObject();
- try{
- obj.put("star",star);
- obj.put("end",end);
- Log.e(TAG, "getPost: "+star );
- Log.e(TAG, "getPost: "+end );
- }catch (JSONException e){
+ JSONObject obj = new JSONObject();
+ try {
+ obj.put("star", star);
+ obj.put("end", end);
+ Log.e(TAG, "getPost: " + star);
+ Log.e(TAG, "getPost: " + end);
+ } catch (JSONException e) {
Log.d(TAG, "getPost: json添加失败");
}
- FormBody formBody=new FormBody.Builder()
- .add("result",obj.toString())
+ FormBody formBody = new FormBody.Builder()
+ .add("result", obj.toString())
.build();
// 发送请求操作
- Request request=new Request.Builder()
+ Request request = new Request.Builder()
.post(formBody)
.url(url)
.build();
- okHttpClient.newCall(request).enqueue(new Callback(){
+ okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
System.out.println("mainService.getPost:获取main的响应对象失败");
// 发送404到主页
handler.sendMessage(handler.obtainMessage(404));
-
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
System.out.println("mainService.getPost:拿到main的响应对象");
- String responseData=response.body().string();
- reModel =parseReModel(responseData);
- handler.sendMessage(handler.obtainMessage(0, reModel));
+ String responseData = response.body().string();
+ reModel = parseReModel(responseData);
+ if (reModel == null) {
+ handler.sendMessage(handler.obtainMessage(404));
+ } else {
+ handler.sendMessage(handler.obtainMessage(0, reModel));
+ }
+
}
});
}
- public void getUserPosts(int account,int star,int end,int type){
- url=MAIN_URL;
- OkHttpClient okHttpClient=createClient();
+
+ public void getUserPosts(int account, int star, int end, int type) {
+ url = MAIN_URL;
+ OkHttpClient okHttpClient = createClient();
// 请求体
- JSONObject obj=new JSONObject();
- try{
- obj.put("star",star);
- obj.put("end",end);
- }catch (JSONException e){
+ JSONObject obj = new JSONObject();
+ try {
+ obj.put("star", star);
+ obj.put("end", end);
+ } catch (JSONException e) {
Log.d(TAG, "getPost: json添加失败");
}
- FormBody formBody=new FormBody.Builder()
- .add("account",String.valueOf(account))
- .add("result",obj.toString())
- .add("type",String.valueOf(type))
+ FormBody formBody = new FormBody.Builder()
+ .add("account", String.valueOf(account))
+ .add("result", obj.toString())
+ .add("type", String.valueOf(type))
.build();
// 发送请求操作
- Request request=new Request.Builder()
+ Request request = new Request.Builder()
.post(formBody)
.url(url)
.build();
- okHttpClient.newCall(request).enqueue(new Callback(){
+ okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(@NotNull Call call, @NotNull IOException e) {
System.out.println("mainService.getPost:获取main的响应对象失败");
// 发送404到主页
handler.sendMessage(handler.obtainMessage(404));
-
}
@Override
public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
System.out.println("mainService.getPost:拿到main的响应对象");
- String responseData=response.body().string();
- System.out.println(responseData);
- reModel =parseReModel(responseData);
+ String responseData = response.body().string();
+ reModel = parseReModel(responseData);
handler.sendMessage(handler.obtainMessage(0, reModel));
}
});
}
- public void getCmt(int postId){
- url="http://10.0.2.2:8080/bbs_servlet/main";
- OkHttpClient okHttpClient=createClient();
-// 请求体
- FormBody formBody=new FormBody.Builder()
- .add("account","5554")
- .build();
-// 发送请求操作
- Request request=new Request.Builder()
- .post(formBody)
- .url(url)
- .build();
- }
-
- public void getUserInfo(int account,String content,Handler handler1){
- url=USERINFO_URL;
- OkHttpClient okHttpClient=createClient();
-// 请求体
- FormBody formBody=new FormBody.Builder()
- .add("account",String.valueOf(account))
- .build();
-// 发送请求操作
- Request request=new Request.Builder()
- .post(formBody)
- .url(url)
- .build();
- okHttpClient.newCall(request).enqueue(new Callback() {
- @Override
- public void onFailure(@NotNull Call call, @NotNull IOException e) {
- System.out.println("mainService.getUserInfo:获取main的响应对象失败");
-// 发送404到主页
- handler1.sendMessage(handler1.obtainMessage(404));
- }
-
- @Override
- public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
- System.out.println("mainService.getPost:拿到main的响应对象");
- String responseData=response.body().string();
- parseJSONData1(responseData);
-// Message msg=new Message();
- System.out.println(userInfo.getName());
- Comment comment=new Comment();
- comment.setCmtName(userInfo.getName());
- comment.setCommentContent(content);
- handler1.sendMessage(handler1.obtainMessage(0,comment));
- }
- });
- }
-
- private UserInfo userInfo;
- public void parseJSONData1(String jsonData){
- Gson gson=new Gson();
- userInfo=gson.fromJson(jsonData, UserInfo.class);
- }
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java b/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java
index 19830a0..5d1ab4c 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/PictureService.java
@@ -23,26 +23,27 @@ import static com.moyv.schoolbbs.config.URLConstant.UPLOAD_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
public class PictureService {
- public static int PIC_POST=202;
- public static int PIC_HEAD=303;
+ public static int PIC_POST = 202;
+ public static int PIC_HEAD = 303;
private static final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
+
//图片上传
- public static void uploading(List files,List fileName,int postId,Handler handler) {
+ public static void uploading(List files, List fileName, int postId, Handler handler) {
//图片上传接口地址
String url = UPLOAD_URL;
- MultipartBody multipartBody=null;
+ MultipartBody multipartBody = null;
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
builder.addFormDataPart("type", String.valueOf(PIC_POST));
builder.addFormDataPart("postId", String.valueOf(postId));
- for (int i = 0; i picUrls = new ArrayList<>();
- List files=new ArrayList<>();
+ List files = new ArrayList<>();
for (int i = 0; i < mPicList.size(); i++) {
String photo = mPicList.get(i);
- File file=new File(photo);
+ File file = new File(photo);
files.add(file);
System.out.println(photo);
- String url=okPostId + "_" + i + ".jpg";
+ String url = okPostId + "_" + i + ".jpg";
picUrls.add(url);
}
- uploading(files,picUrls,okPostId,handler1);
+ uploading(files, picUrls, okPostId, handler1);
} else {
handler.sendMessage(handler.obtainMessage(404));
@@ -281,10 +280,11 @@ public class AddActivity extends AppCompatActivity {
}
});
}
- Handler handler1=new Handler(new Handler.Callback() {
+
+ Handler handler1 = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
handler.sendMessage(handler.obtainMessage(0));
System.out.println("图片上传成功");
@@ -302,6 +302,4 @@ public class AddActivity extends AppCompatActivity {
});
-
-
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
index 4aa5322..87e87f8 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
@@ -18,21 +18,21 @@ import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.moyv.schoolbbs.R;
-import com.moyv.schoolbbs.config.AccountConstant;
+import com.moyv.schoolbbs.config.SharedPreConstant;
import com.moyv.schoolbbs.ui.adapter.DataGenerator;
-import com.moyv.schoolbbs.util.UIHelper;
import com.moyv.schoolbbs.ui.fragment.HomeFragment;
import java.util.List;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.SharedPreConstant.LOGIN;
import static com.moyv.schoolbbs.service.PictureService.uploadHead;
import static com.moyv.schoolbbs.ui.adapter.DataGenerator.mTabTitle;
import static com.moyv.schoolbbs.util.ToastUtils.init;
import static com.moyv.schoolbbs.util.ToastUtils.show;
import static com.moyv.schoolbbs.util.UIHelper.closeDialog;
+import static com.moyv.schoolbbs.util.UIHelper.mLoadingDialog;
import static com.moyv.schoolbbs.util.UIHelper.showDialogForLoading;
/**
@@ -49,8 +49,8 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.bottom_tab_layout_ac);
mFragmensts = DataGenerator.getFragments("TabLayout Tab");
- context=this;
- new AccountConstant(context);
+ context = this;
+ new SharedPreConstant(context);
init(context);
initView();
@@ -87,8 +87,8 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
}
});
- if(LOGIN){
- mTabTitle[2]="我的";
+ if (LOGIN) {
+ mTabTitle[2] = "我的";
}
mTabLayout.addTab(mTabLayout.newTab().setIcon(getResources().getDrawable(R.drawable.tab_home_selector2)).setText(mTabTitle[0]));
mTabLayout.addTab(mTabLayout.newTab().setIcon(getResources().getDrawable(R.drawable.tab_message_selector)).setText(mTabTitle[1]));
@@ -98,8 +98,7 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
/**
* 页面切换
- */
-
+ */
private void onTabItemSelected(int position) {
Fragment fragment = null;
switch (position) {
@@ -109,12 +108,10 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
case 1:
fragment = mFragmensts[1];
break;
-
case 2:
fragment = mFragmensts[2];
break;
default:
- System.out.println("返回出错");
}
showFragment(fragment);
}
@@ -124,9 +121,7 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
* 显示fragment
*/
private void showFragment(Fragment fg) {
-
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
-
//如果之前没有添加过
if (!fg.isAdded()) {
transaction
@@ -140,13 +135,13 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
}
currentFragment = fg;
transaction.commit();
-
}
+
+
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
-// UCropUtils uCropUtils = new UCropUtils(context);
- Log.e(TAG, "onActivityResult: 回调成功" );
+ Log.e(TAG, "onActivityResult: 回调成功");
switch (requestCode) {
//相册
case PictureConfig.CHOOSE_REQUEST:
@@ -174,15 +169,16 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
}
}
break;
+ default:
}
}
- public void upload(List result){
- List imageUrl =result;
- Handler handler1=new Handler(new Handler.Callback() {
+ public void upload(List result) {
+ List imageUrl = result;
+ Handler handler1 = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
show("头像上传成功");
// 刷新用户信息
@@ -200,7 +196,22 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
return false;
}
});
- showDialogForLoading(context,"头像上传中");
- uploadHead(imageUrl.get(0).getCompressPath(),ACCOUNT,handler1);
+ showDialogForLoading(context, "头像上传中");
+ uploadHead(imageUrl.get(0).getCompressPath(), ACCOUNT, handler1);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+// 防止内存溢出
+ if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
+ mLoadingDialog.dismiss();
+ }
+// 标题更新
+ if (LOGIN) {
+ mTabTitle[2] = "我的";
+ } else {
+ mTabTitle[2] = "未登录";
+ }
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
index ff776be..39bd496 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
@@ -35,6 +35,7 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
private CheckBox cbRm;
private String password;
private TextView register;
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -45,33 +46,34 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
/**
* 初始化
*/
- public void initView(){
- context=this;
- etName=findViewById(R.id.et_username);
- etPsw=findViewById(R.id.et_password);
- btnConfirm=findViewById(R.id.btn_confirm);
- cbRm=findViewById(R.id.cb_rm);
- register=findViewById(R.id.login_btn_register);
+ public void initView() {
+ context = this;
+ etName = findViewById(R.id.et_username);
+ etPsw = findViewById(R.id.et_password);
+ btnConfirm = findViewById(R.id.btn_confirm);
+ cbRm = findViewById(R.id.cb_rm);
+ register = findViewById(R.id.login_btn_register);
register.setOnClickListener(this);
btnConfirm.setOnClickListener(this);
- SharedPreferences sharedPreferences=getSharedPreferences("login",0);
- int account=sharedPreferences.getInt("account",0);
- Log.e(TAG, "initView: "+account );
- etName.setText(account==0?"":String.valueOf(account));
- if(sharedPreferences.getBoolean("rememberPsw",false)){
+ SharedPreferences sharedPreferences = getSharedPreferences("login", 0);
+ int account = sharedPreferences.getInt("account", 0);
+ Log.e(TAG, "initView: " + account);
+ etName.setText(account == 0 ? "" : String.valueOf(account));
+ if (sharedPreferences.getBoolean("rememberPsw", false)) {
cbRm.setChecked(true);
- etPsw.setText(sharedPreferences.getString("password",""));
+ etPsw.setText(sharedPreferences.getString("password", ""));
}
}
+
@Override
public void onClick(View v) {
- switch (v.getId()){
+ switch (v.getId()) {
case R.id.btn_confirm:
send();
break;
case R.id.login_btn_register:
- Intent intent=new Intent(context,RegisterActivity.class);
+ Intent intent = new Intent(context, RegisterActivity.class);
startActivity(intent);
finish();
break;
@@ -79,39 +81,41 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
System.out.println("点击事件没有注册事件");
}
}
- public void send(){
- String userName=etName.getText().toString();
+
+ // 登录方法
+ public void send() {
+ String userName = etName.getText().toString();
password = etPsw.getText().toString();
- LoginService loginService=new LoginService();
- Handler handler=new Handler(new Handler.Callback() {
+ LoginService loginService = new LoginService();
+ Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
- switch (msg.what){
+ switch (msg.what) {
case 200:
- LoginBean loginBean=(LoginBean)msg.obj;
- Log.d(TAG, "onResponse: "+loginBean.getAccount());
- Log.d(TAG, "onResponse: "+loginBean.getName());
- Log.d(TAG, "onResponse: "+loginBean.getStatus());
- Log.d(TAG, "onResponse: "+loginBean.getIntroduction());
- Log.d(TAG, "onResponse: "+loginBean.getToken());
+ LoginBean loginBean = (LoginBean) msg.obj;
+ Log.d(TAG, "onResponse: " + loginBean.getAccount());
+ Log.d(TAG, "onResponse: " + loginBean.getName());
+ Log.d(TAG, "onResponse: " + loginBean.getStatus());
+ Log.d(TAG, "onResponse: " + loginBean.getIntroduction());
+ Log.d(TAG, "onResponse: " + loginBean.getToken());
save(loginBean);
- Toast.makeText(context,"登录成功",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "登录成功", Toast.LENGTH_SHORT).show();
finish();
break;
case 404:
- Toast.makeText(context,"没找到服务器",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "没找到服务器", Toast.LENGTH_SHORT).show();
break;
case 500:
- Toast.makeText(context,"返回错误数据",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "返回错误数据", Toast.LENGTH_SHORT).show();
break;
case 300:
etName.setText("");
etPsw.setText("");
- Toast.makeText(context,"用户不存在,请先注册",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "用户不存在,请先注册", Toast.LENGTH_SHORT).show();
break;
case 100:
etPsw.setText("");
- Toast.makeText(context,"密码错误",Toast.LENGTH_SHORT).show();
+ Toast.makeText(context, "密码错误", Toast.LENGTH_SHORT).show();
break;
default:
System.out.println("msg返回错误的编号");
@@ -119,27 +123,27 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
return false;
}
});
- loginService.getLogin(Integer.parseInt(userName),password,handler);
+ loginService.getLogin(Integer.parseInt(userName), password, handler);
}
/**
* 登录成功后保存token和账号信息
*/
- public void save(LoginBean loginBean){
- SharedPreferences sharedPreferences=getSharedPreferences("login",0);
- SharedPreferences.Editor editor=sharedPreferences.edit();
- editor.putInt("account",loginBean.getAccount());
- editor.putString("name",loginBean.getName());
- editor.putString("introduction",loginBean.getIntroduction());
- editor.putString("token",loginBean.getToken());
- editor.putBoolean("isLogin",true);
- if(cbRm.isChecked()){
- editor.putBoolean("rememberPsw",true);
+ public void save(LoginBean loginBean) {
+ SharedPreferences sharedPreferences = getSharedPreferences("login", 0);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putInt("account", loginBean.getAccount());
+ editor.putString("name", loginBean.getName());
+ editor.putString("introduction", loginBean.getIntroduction());
+ editor.putString("token", loginBean.getToken());
+ editor.putBoolean("isLogin", true);
+ if (cbRm.isChecked()) {
+ editor.putBoolean("rememberPsw", true);
// editor.putString("password",password);
- }else{
- editor.putBoolean("rememberPsw",false);
+ } else {
+ editor.putBoolean("rememberPsw", false);
}
- editor.putString("password",password);
+ editor.putString("password", password);
editor.commit();
new AssertionError(context);
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
index 4119e1b..777dae3 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
@@ -32,10 +32,11 @@ import java.util.ArrayList;
import java.util.List;
import static com.moyv.schoolbbs.base.Global.init;
-import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
import static com.moyv.schoolbbs.service.MainService.USER_POSTS;
-import static com.moyv.schoolbbs.ui.adapter.DataAdapter.MANAGER;
+import static com.moyv.schoolbbs.ui.adapter.DataAdapter.POSTMANAGER;
+import static com.moyv.schoolbbs.ui.adapter.DataAdapter.STARAMNAGER;
/**
* @author moyv
@@ -44,7 +45,8 @@ public class ManagerActivity extends AppCompatActivity {
private RecyclerView recyclerView;
private static final int SUCCESS = 0;
private static final int FALL = 404;
- private DataAdapter adapter;;
+ private DataAdapter adapter;
+ ;
private FloatingActionButton btnFlt;
private SwipeRefreshLayout swiperefreshlayout;
private Context mContext;
@@ -59,6 +61,7 @@ public class ManagerActivity extends AppCompatActivity {
private EditText etComment1;
private TabLayout tabLayout;
private TextView tvSend;
+
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -67,26 +70,26 @@ public class ManagerActivity extends AppCompatActivity {
end = 5;
mContext = this;
- Intent intent=getIntent();
- type=intent.getIntExtra("type",USER_POSTS);
- recyclerView =findViewById(R.id.manager_recycler_view);
+ Intent intent = getIntent();
+ type = intent.getIntExtra("type", USER_POSTS);
+ recyclerView = findViewById(R.id.manager_recycler_view);
llComment = findViewById(R.id.ll_comment);
- etComment1=findViewById(R.id.et_comment);
- tabLayout=findViewById(R.id.bottom_tab_layout);
- tvSend=findViewById(R.id.tv_send_comment);
+ etComment1 = findViewById(R.id.et_comment);
+ tabLayout = findViewById(R.id.bottom_tab_layout);
+ tvSend = findViewById(R.id.tv_send_comment);
init(mContext);
- swiperefreshlayout =findViewById(R.id.swiperefreshlayout);
+ swiperefreshlayout = findViewById(R.id.swiperefreshlayout);
swiperefreshlayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
Log.d("zttjiangqq", "invoke onRefresh...");
- start=0;
- end=5;
- new MainService(handler1).getUserPosts(ACCOUNT,start,end,type);
+ start = 0;
+ end = 5;
+ new MainService(handler1).getUserPosts(ACCOUNT, start, end, type);
}
}
@@ -96,17 +99,17 @@ public class ManagerActivity extends AppCompatActivity {
@Override
public void onLoadMore() {
adapter.setLoadState(adapter.LOADING);
- if(endcount){
- start=end+1;
- end=count;
- }else{
- start=end+1;
- end=start+4;
+ if (end < count) {
+ if (end + 5 > count) {
+ start = end + 1;
+ end = count;
+ } else {
+ start = end + 1;
+ end = start + 4;
}
- new MainService(handler2).getPost(start,end);
- }else{
+ new MainService(handler2).getPost(start, end);
+ } else {
// 显示加载到底的提示
adapter.setLoadState(adapter.LOADING_END);
}
@@ -114,7 +117,7 @@ public class ManagerActivity extends AppCompatActivity {
}
});
- new MainService(handler).getUserPosts(ACCOUNT,start, end ,type);
+ new MainService(handler).getUserPosts(ACCOUNT, start, end, type);
// 加载帖子数据
UIHelper.showDialogForLoading(mContext, "初始化数据中");
}
@@ -124,22 +127,22 @@ public class ManagerActivity extends AppCompatActivity {
@Override
public boolean handleMessage(Message msg) {
UIHelper.closeDialog(mContext);
- List- items=new ArrayList<>();
+ List
- items = new ArrayList<>();
switch (msg.what) {
case SUCCESS:
Toast.makeText(mContext, "成功获取数据", Toast.LENGTH_SHORT).show();
- ReModel reModel=(ReModel) msg.obj;
+ ReModel reModel = (ReModel) msg.obj;
lists = reModel.getMain();
- count=reModel.getCount();
+ count = reModel.getCount();
System.out.println(count);
- for(ReModel.Main list:lists){
- Item item=new Item();
+ for (ReModel.Main list : lists) {
+ Item item = new Item();
item.setMain(list);
System.out.println(list.getUserInfo().getIntroduction());
- List
urls=new ArrayList<>();
- for(int i=0;i urls = new ArrayList<>();
+ for (int i = 0; i < list.getPost().getPostType(); i++) {
+ String url = IMAGE_URL + "/" + list.getPost().getPostId() + "/" + list.getPost().getPostId() + "_" + i + ".jpg";
urls.add(url);
}
item.setImagesUrls(urls);
@@ -155,9 +158,9 @@ public class ManagerActivity extends AppCompatActivity {
}
// 显示帖子列表
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
- adapter = new DataAdapter(mContext,items,llComment, etComment1,tabLayout,tvSend);
- adapter.type=MANAGER;
- Log.i("TAG", "handleMessage: "+items.size());
+ adapter = new DataAdapter(mContext, items, llComment, etComment1, tvSend);
+ adapter.type = type == USER_POSTS ? POSTMANAGER : STARAMNAGER;
+ Log.i("TAG", "handleMessage: " + items.size());
recyclerView.setAdapter(adapter);
return false;
}
@@ -171,16 +174,16 @@ public class ManagerActivity extends AppCompatActivity {
switch (msg.what) {
case SUCCESS:
Toast.makeText(mContext, "成功获取数据", Toast.LENGTH_SHORT).show();
- ReModel reModel=(ReModel) msg.obj;
+ ReModel reModel = (ReModel) msg.obj;
lists = reModel.getMain();
- count=reModel.getCount();
- List- items=new ArrayList<>();
- for(ReModel.Main list:lists){
- Item item=new Item();
+ count = reModel.getCount();
+ List
- items = new ArrayList<>();
+ for (ReModel.Main list : lists) {
+ Item item = new Item();
item.setMain(list);
- List
urls=new ArrayList<>();
- for(int i=0;i urls = new ArrayList<>();
+ for (int i = 0; i < list.getPost().getPostType(); i++) {
+ String url = IMAGE_URL + "/" + list.getPost().getPostId() + "/" + list.getPost().getPostId() + "_" + i + ".jpg";
urls.add(url);
}
item.setImagesUrls(urls);
@@ -199,20 +202,20 @@ public class ManagerActivity extends AppCompatActivity {
});
// 数据添加
- Handler handler2=new Handler(new Handler.Callback() {
+ Handler handler2 = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
switch (msg.what) {
case SUCCESS:
- ReModel reModel=(ReModel) msg.obj;
+ ReModel reModel = (ReModel) msg.obj;
List addLists = reModel.getMain();
- List- items=new ArrayList<>();
- for(ReModel.Main list:addLists){
- Item item=new Item();
+ List
- items = new ArrayList<>();
+ for (ReModel.Main list : addLists) {
+ Item item = new Item();
item.setMain(list);
- List
urls=new ArrayList<>();
- for(int i=0;i urls = new ArrayList<>();
+ for (int i = 0; i < list.getPost().getPostType(); i++) {
+ String url = IMAGE_URL + "/" + list.getPost().getPostId() + "/" + list.getPost().getPostId() + "_" + i + ".jpg";
urls.add(url);
}
item.setImagesUrls(urls);
@@ -230,7 +233,4 @@ public class ManagerActivity extends AppCompatActivity {
return false;
}
});
-
-
-
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/PlusImageActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/PlusImageActivity.java
index 194a8f1..54a7beb 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/PlusImageActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/PlusImageActivity.java
@@ -52,7 +52,7 @@ public class PlusImageActivity extends AppCompatActivity implements ViewPager.On
getSupportActionBar().hide();
}
setContentView(R.layout.activity_plus_image);
- showType=getIntent().getStringExtra(SHOW);
+ showType = getIntent().getStringExtra(SHOW);
imgList = getIntent().getStringArrayListExtra(MainConstant.IMG_LIST);
mPosition = getIntent().getIntExtra(MainConstant.POSITION, 0);
initView();
@@ -61,11 +61,11 @@ public class PlusImageActivity extends AppCompatActivity implements ViewPager.On
private void initView() {
viewPager = (ViewPager) findViewById(R.id.viewPager);
positionTv = (TextView) findViewById(R.id.position_tv);
- ivBack=findViewById(R.id.back_iv);
- ivDelete=findViewById(R.id.delete_iv);
- if(showType.equals(MAIN_SHOW)){
+ ivBack = findViewById(R.id.back_iv);
+ ivDelete = findViewById(R.id.delete_iv);
+ if (showType.equals(MAIN_SHOW)) {
ivDelete.setVisibility(View.GONE);
- }else{
+ } else {
ivDelete.setOnClickListener(this);
}
ivBack.setOnClickListener(this);
@@ -87,7 +87,7 @@ public class PlusImageActivity extends AppCompatActivity implements ViewPager.On
public void ok() {
super.ok();
imgList.remove(mPosition); //从数据源移除删除的图片
- if(mPosition==1){
+ if (mPosition == 1) {
back();
}
setPosition();
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
index f55343c..a0ed253 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
@@ -1,6 +1,5 @@
package com.moyv.schoolbbs.ui.activity;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@@ -16,7 +15,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.moyv.schoolbbs.R;
-import com.moyv.schoolbbs.config.AccountConstant;
+import com.moyv.schoolbbs.config.SharedPreConstant;
import com.moyv.schoolbbs.service.RegisterService;
import static com.moyv.schoolbbs.util.ToastUtils.init;
@@ -87,12 +86,12 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
switch (msg.what) {
case 200:
show("注册成功");
- SharedPreferences sharedPreferences=getSharedPreferences("login",0);
- SharedPreferences.Editor editor=sharedPreferences.edit();
- editor.putInt("account",account);
- editor.putBoolean("isLogin",true);
- new AccountConstant(context);
- Intent intent=new Intent(context,LoginActivity.class);
+ SharedPreferences sharedPreferences = getSharedPreferences("login", 0);
+ SharedPreferences.Editor editor = sharedPreferences.edit();
+ editor.putInt("account", account);
+ editor.putBoolean("isLogin", true);
+ new SharedPreConstant(context);
+ Intent intent = new Intent(context, LoginActivity.class);
startActivity(intent);
finish();
break;
@@ -106,10 +105,10 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
show("用户名已存在");
break;
case 404:
- show(getClass().getName()+"连接服务器失败");
+ show(getClass().getName() + "连接服务器失败");
break;
default:
- show(getClass().getName()+"非法result");
+ show(getClass().getName() + "非法result");
}
return false;
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
index 0664745..f6d5fec 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
@@ -2,8 +2,6 @@ package com.moyv.schoolbbs.ui.adapter;
import android.app.Activity;
import android.content.Context;
-import android.content.Intent;
-import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
@@ -12,13 +10,9 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.CheckBox;
-import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
@@ -39,7 +33,7 @@ import com.moyv.schoolbbs.pojo.Item;
import com.moyv.schoolbbs.pojo.Star;
import com.moyv.schoolbbs.service.CmtService;
import com.moyv.schoolbbs.service.StarService;
-import com.moyv.schoolbbs.ui.activity.BottomTabLayoutActivity;
+import com.moyv.schoolbbs.ui.config.CancelOrOkDialog;
import com.moyv.schoolbbs.ui.view.CommentsView;
import com.moyv.schoolbbs.ui.view.ExpandTextView;
import com.moyv.schoolbbs.ui.view.LikePopupWindow;
@@ -49,16 +43,22 @@ import com.moyv.schoolbbs.util.KeyboardUtils;
import com.moyv.schoolbbs.util.ToastUtils;
import com.wang.avi.AVLoadingIndicatorView;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
-import static com.moyv.schoolbbs.config.AccountConstant.NAME;
+import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.SharedPreConstant.LOGIN;
+import static com.moyv.schoolbbs.config.SharedPreConstant.NAME;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
+import static com.moyv.schoolbbs.service.DeletePostService.deletePost;
+import static com.moyv.schoolbbs.util.FormatUtils.getFormatData;
import static com.moyv.schoolbbs.util.ToastUtils.show;
+import static com.moyv.schoolbbs.util.UIHelper.closeDialog;
public class DataAdapter extends RecyclerView.Adapter {
public Context context;
@@ -68,14 +68,15 @@ public class DataAdapter extends RecyclerView.Adapter {
private LinearLayout llComment;
private ViewHolder recyclerViewHolder;
- private int isLike=0;
+ private int isLike = 0;
private TextView tvSend;
private String commentStr;
// type有两个值,区别主页显示和管理显示
public static int MAIN = 202;
- public static int MANAGER = 303;
+ public static int POSTMANAGER = 303;
+ public static int STARAMNAGER = 404;
public int type;
@@ -95,7 +96,7 @@ public class DataAdapter extends RecyclerView.Adapter {
// 防止重复加载
List positions = new ArrayList<>();
- public DataAdapter(Context context, List- postList, LinearLayout llComment, EditText etComment, TabLayout tabLayout, TextView tvSend) {
+ public DataAdapter(Context context, List
- postList, LinearLayout llComment, EditText etComment, TextView tvSend) {
this.context = context;
this.postList = postList;
this.etComment = etComment;
@@ -144,8 +145,8 @@ public class DataAdapter extends RecyclerView.Adapter
{
@Override
public void onClick(View v) {
//评论弹框
- Log.e(TAG, "onClick: "+position );
- showLikePopupWindow(v, position ,recyclerViewHolder);
+ Log.e(TAG, "onClick: " + position);
+ showLikePopupWindow(v, position, recyclerViewHolder);
tvSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -157,9 +158,9 @@ public class DataAdapter extends RecyclerView.Adapter {
// 判断是否有删除键
- if (type == MANAGER) {
- recyclerViewHolder.ivEdit.setVisibility(View.GONE);
+ if (type != MAIN) {
recyclerViewHolder.tvDelete.setVisibility(View.VISIBLE);
+ recyclerViewHolder.ivEdit.setVisibility(View.GONE);
recyclerViewHolder.tvDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -169,7 +170,17 @@ public class DataAdapter extends RecyclerView.Adapter {
}
// 显示发表时间
- recyclerViewHolder.tvDate.setText(Date);
+ DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ java.util.Date date1 = null;
+ try {
+ date1 = fmt.parse(Date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ Long date = date1.getTime();
+ Long now = System.currentTimeMillis();
+ String formatData = getFormatData(date, now);
+ recyclerViewHolder.tvDate.setText(formatData);
// 帖子文字内容
if (content.length() == 0) {
recyclerViewHolder.expandTextView.setVisibility(View.GONE);
@@ -177,7 +188,7 @@ public class DataAdapter extends RecyclerView.Adapter {
recyclerViewHolder.expandTextView.setVisibility(View.VISIBLE);
recyclerViewHolder.expandTextView.setText(content);
}
-
+// 评论区显示判断
if ((postList.get(position).getMain().getStars() != null && postList.get(position).getMain().getStars().size() > 0) && (postList.get(position).getMain().getComments() != null && postList.get(position).getMain().getComments().size() > 0)) {
recyclerViewHolder.viewLike.setVisibility(View.VISIBLE);
} else {
@@ -196,28 +207,7 @@ public class DataAdapter extends RecyclerView.Adapter {
recyclerViewHolder.rvComment.setVisibility(View.VISIBLE);
recyclerViewHolder.rvComment.setList(postList.get(position).getMain().getComments());
recyclerViewHolder.rvComment.setOnCommentListener((posit, bean, user_id) -> {
- etComment.setText("");
- //如果当前用户id和评论用户id相同则删除
- if (bean.getCommentsUser().getAccount()==ACCOUNT) {
- showDeletePopWindow(recyclerViewHolder.rvComment, bean.getCommentId(), recyclerViewHolder.getLayoutPosition() - 1, posit);
- llComment.setVisibility(View.GONE);
- } else {
- //不相同回复
- llComment.setVisibility(View.VISIBLE);
- etComment.setHint("回复:" + bean.getCommentsUser().getName());
- if (View.VISIBLE == llComment.getVisibility()) {
- llComment.requestFocus();
- //弹出键盘
- KeyboardUtils.showSoftInput(etComment.getContext(), etComment);
- } else if (View.GONE == llComment.getVisibility()) {
- //隐藏键盘
- KeyboardUtils.hideSoftInput(etComment.getContext(), etComment);
- }
-// if (click != null) {
-// //由于真实项目中有头部所以position-1
-// click.Commend(recyclerViewHolder.getLayoutPosition(), bean);
-// }
- }
+ show("回复功能暂没实现");
});
recyclerViewHolder.rvComment.notifyDataSetChanged();
} else {
@@ -303,19 +293,6 @@ public class DataAdapter extends RecyclerView.Adapter {
}
- private void showDeletePopWindow(View view, int id, int layoutPosition, int position) {
-// View contentView = getPopupWindowContentView(id, layoutPosition, position);
-// mPopupWindow = new PopupWindow(contentView,
-// ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
-// // 如果不设置PopupWindow的背景,有些版本就会出现一个问题:无论是点击外部区域还是Back键都无法dismiss弹框
-// mPopupWindow.setBackgroundDrawable(new ColorDrawable());
-// // 设置好参数之后再show
-// int[] windowPos = PopupWindowUtil.calculatePopWindowPos(view, contentView, x, y);
-// mPopupWindow.showAsDropDown(view, 0, -40, windowPos[1]);
-// mPopupWindow.setFocusable(true);
-// mPopupWindow.setOutsideTouchable(true);
- }
-
// 刷新数据
public void refreshView(List- postList) {
this.postList = postList;
@@ -351,20 +328,9 @@ public class DataAdapter extends RecyclerView.Adapter
{
notifyDataSetChanged();
}
- /**
- * 获取控件左上顶点Y坐标
- *
- * @param view
- * @return
- */
- private int getCoordinateY(View view) {
- int[] coordinate = new int[2];
- view.getLocationOnScreen(coordinate);
- return coordinate[1];
- }
- private void showLikePopupWindow(View view, int position,ViewHolder recyclerViewHolder) {
- LikePopupWindow likePopupWindow=recyclerViewHolder.likePopupWindow;
+ private void showLikePopupWindow(View view, int position, ViewHolder recyclerViewHolder) {
+ LikePopupWindow likePopupWindow = recyclerViewHolder.likePopupWindow;
List list = postList.get(position).getMain().getStars();
// 判断用户是否已经点赞
for (Star star : list) {
@@ -420,9 +386,9 @@ public class DataAdapter extends RecyclerView.Adapter {
switch (msg.what) {
case 200:
show("点赞成功");
- Integer index=(Integer) msg.obj;
- List stars=postList.get(index).getMain().getStars();
- Star star=new Star();
+ Integer index = (Integer) msg.obj;
+ List stars = postList.get(index).getMain().getStars();
+ Star star = new Star();
star.setName(NAME);
stars.add(star);
notifyDataSetChanged();
@@ -430,9 +396,9 @@ public class DataAdapter extends RecyclerView.Adapter {
case 201:
Log.d(TAG, "handleMessage: 取消点赞成功");
show("取消点赞成功");
- Integer index1=(Integer) msg.obj;
- List stars1=postList.get(index1).getMain().getStars();
- List likeListBeans1=new ArrayList<>();
+ Integer index1 = (Integer) msg.obj;
+ List stars1 = postList.get(index1).getMain().getStars();
+ List likeListBeans1 = new ArrayList<>();
Iterator it1 = stars1.iterator();
while (it1.hasNext()) {
Star info = (Star) it1.next();
@@ -460,8 +426,8 @@ public class DataAdapter extends RecyclerView.Adapter {
return false;
}
});
- StarService starService=new StarService();
- starService.pushStar(postList.get(postion).getMain().getPost().getPostId(),handler,isLike,postion);
+ StarService starService = new StarService();
+ starService.pushStar(postList.get(postion).getMain().getPost().getPostId(), handler, isLike, postion);
}
}
@@ -478,13 +444,13 @@ public class DataAdapter extends RecyclerView.Adapter {
switch (msg.what) {
case 0:
Toast.makeText(context, "成功评论", Toast.LENGTH_SHORT).show();
- HandlerPosition handlerPosition=(HandlerPosition)msg.obj;
- int index=handlerPosition.getPosition();
- Comment comment=(Comment) handlerPosition.getObj();
+ HandlerPosition handlerPosition = (HandlerPosition) msg.obj;
+ int index = handlerPosition.getPosition();
+ Comment comment = (Comment) handlerPosition.getObj();
comment.setCmtName(NAME);
postList.get(index).getMain().getComments().add(comment);
// 打印返回的comment对象
- Log.d(TAG, "handleMessage: "+comment.getCmtName());
+ Log.d(TAG, "handleMessage: " + comment.getCmtName());
notifyDataSetChanged();
break;
case 404:
@@ -506,10 +472,10 @@ public class DataAdapter extends RecyclerView.Adapter {
comment.setCommentContent(commentStr);
comment.setCommentAccount(ACCOUNT);
// 打印position
- Log.d(TAG, "getComment: "+position);
+ Log.d(TAG, "getComment: " + position);
comment.setPostId(postList.get(position).getMain().getPost().getPostId());
CmtService cmtService = new CmtService();
- cmtService.pushCmt(comment, handler1,position);
+ cmtService.pushCmt(comment, handler1, position);
}
} else {
Toast.makeText(context, "请先登录", Toast.LENGTH_SHORT).show();
@@ -518,13 +484,42 @@ public class DataAdapter extends RecyclerView.Adapter {
llComment.setVisibility(View.GONE);
}
- // 删除指定postion
-// 删除数据
+ // 删除数据
public void removeData(int position) {
- postList.remove(position);
- //删除动画
- notifyItemRemoved(position);
- notifyDataSetChanged();
+ if (type == POSTMANAGER) {
+ CancelOrOkDialog dialog = new CancelOrOkDialog(context, "要删除确认删除?") {
+ @Override
+ public void ok() {
+ super.ok();
+ Handler handler = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(@NonNull Message msg) {
+ closeDialog(context);
+ switch (msg.what) {
+ case 200:
+ ToastUtils.show("删除成功");
+ postList.remove(position);
+ //删除动画
+ notifyItemRemoved(position);
+ notifyDataSetChanged();
+ break;
+ case 505:
+ ToastUtils.show("删除失败");
+ break;
+ default:
+ }
+ return false;
+ }
+ });
+ deletePost(postList.get(position).getMain().getPost().getPostId(), handler);
+ dismiss();
+ }
+ };
+ dialog.show();
+ } else {
+ show("暂时没有实现该功能");
+ }
+
}
public static class ViewHolder extends RecyclerView.ViewHolder {
@@ -560,7 +555,7 @@ public class DataAdapter extends RecyclerView.Adapter {
llLike = itemView.findViewById(R.id.ll_like_comment);
rvComment = itemView.findViewById(R.id.rv_comment);
ivEdit = itemView.findViewById(R.id.iv_edit);
- likePopupWindow=new LikePopupWindow(itemView.getContext());
+ likePopupWindow = new LikePopupWindow(itemView.getContext());
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataGenerator.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataGenerator.java
index a68716d..e207d67 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataGenerator.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataGenerator.java
@@ -39,9 +39,9 @@ public class DataGenerator {
*/
public static View getTabView(Context context, int position) {
View view = LayoutInflater.from(context).inflate(R.layout.home_tab_content, null);
- ImageView tabIcon =view.findViewById(R.id.tab_content_image);
+ ImageView tabIcon = view.findViewById(R.id.tab_content_image);
tabIcon.setImageResource(DataGenerator.mTabRes[position]);
- TextView tabText =view.findViewById(R.id.tab_content_text);
+ TextView tabText = view.findViewById(R.id.tab_content_text);
tabText.setText(mTabTitle[position]);
return view;
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/GridViewAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/GridViewAdapter.java
index 24a825c..96c219b 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/GridViewAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/GridViewAdapter.java
@@ -12,6 +12,9 @@ import com.moyv.schoolbbs.ui.config.MainConstant;
import java.util.List;
+/**
+ * @author moyv
+ */
public class GridViewAdapter extends android.widget.BaseAdapter {
private Context mContext;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
index e540a02..eaccae9 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
@@ -56,7 +56,7 @@ public class ImagesAdapter extends RecyclerView.Adapter) urls);
intent.putExtra(MainConstant.POSITION, position);
context.startActivity(intent);
@@ -79,10 +79,10 @@ public class ImagesAdapter extends RecyclerView.Adapter{
-
- public Context context;
- private List- postList;
-
- // 普通布局
- private final int TYPE_ITEM = 1;
- // 脚布局
- private final int TYPE_FOOTER = 2;
- // 当前加载状态,默认为加载完成
- private int loadState = 2;
- // 正在加载
- public final int LOADING = 1;
- // 加载完成
- public final int LOADING_COMPLETE = 2;
- // 加载到底
- public final int LOADING_END = 3;
-
- public ManagerAdapter(Context context, List
- postList){
- this.context=context;
- this.postList=postList;
- }
- @NonNull
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- if(viewType==TYPE_ITEM){
- View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_fragment_main,parent,false);
- return new DataAdapter.ViewHolder(view);
- }else if(viewType==TYPE_FOOTER){
- View view = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.loading_more, parent, false);
- return new DataAdapter.FootViewHolder(view);
- }else {
- return null;
- }
- }
-
- @Override
- public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
-
- }
-
- @Override
- public int getItemCount() {
- return postList.size()+1;
- }
-
-}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ViewPagerAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ViewPagerAdapter.java
index fc69784..a1f7db6 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ViewPagerAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ViewPagerAdapter.java
@@ -14,6 +14,9 @@ import com.moyv.schoolbbs.R;
import java.util.List;
+/**
+ * @author moyv
+ */
public class ViewPagerAdapter extends PagerAdapter {
private Context context;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/config/CancelOrOkDialog.java b/app/src/main/java/com/moyv/schoolbbs/ui/config/CancelOrOkDialog.java
index 42db663..ebbaec7 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/config/CancelOrOkDialog.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/config/CancelOrOkDialog.java
@@ -8,6 +8,9 @@ import android.widget.TextView;
import com.moyv.schoolbbs.R;
+/**
+ * @author moyv
+ */
public class CancelOrOkDialog extends Dialog {
public CancelOrOkDialog(Context context, String title) {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/config/GlideEngine.java b/app/src/main/java/com/moyv/schoolbbs/ui/config/GlideEngine.java
index eefc2b2..83833a4 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/config/GlideEngine.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/config/GlideEngine.java
@@ -24,6 +24,9 @@ import com.luck.picture.lib.widget.longimage.ImageViewState;
import com.luck.picture.lib.widget.longimage.SubsamplingScaleImageView;
import com.moyv.schoolbbs.R;
+/**
+ * @author moyv
+ */
public class GlideEngine implements ImageEngine {
/**
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
index 72385c8..79767ae 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/HomeFragment.java
@@ -37,26 +37,27 @@ import java.util.ArrayList;
import java.util.List;
import static com.moyv.schoolbbs.base.Global.init;
-import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.config.SharedPreConstant.LOGIN;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
import static com.moyv.schoolbbs.ui.adapter.DataAdapter.MAIN;
/**
* @author moyv
*/
-public class HomeFragment extends Fragment implements DataAdapter.Click{
+public class HomeFragment extends Fragment implements DataAdapter.Click {
private static final int SUCCESS = 0;
private static final int FALL = 404;
- private DataAdapter adapter;;
+ private DataAdapter adapter;
+ ;
private FloatingActionButton btnFlt;
private SwipeRefreshLayout swiperefreshlayout;
private Context mContext;
private int start, end;
private RecyclerView recyclerView;
private List
lists;
-// 帖子总数
+ // 帖子总数
private int count;
private LinearLayout llComment;
@@ -80,13 +81,13 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
btnFlt = root.findViewById(R.id.btn_float);
- llComment=root.findViewById(R.id.ll_comment);
+ llComment = root.findViewById(R.id.ll_comment);
- etComment1=root.findViewById(R.id.et_comment);
+ etComment1 = root.findViewById(R.id.et_comment);
tvSend = root.findViewById(R.id.tv_send_comment);
- tabLayout=root.findViewById(R.id.bottom_tab_layout);
+ tabLayout = root.findViewById(R.id.bottom_tab_layout);
init(mContext);
@@ -96,8 +97,8 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
@Override
public void onRefresh() {
Log.d("zttjiangqq", "invoke onRefresh...");
- start=0;
- end=5;
+ start = 0;
+ end = 5;
new MainService(handler1).getPost(start, end);
}
}
@@ -109,12 +110,12 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
@Override
public void onClick(View v) {
// 判断是否登录
- if(LOGIN){
+ if (LOGIN) {
Log.e("MainActivity", "onClick: 点击了跳转按钮");
Intent intent = new Intent(mContext, AddActivity.class);
startActivity(intent);
- }else{
- Toast.makeText(mContext,"请先登录",Toast.LENGTH_SHORT).show();
+ } else {
+ Toast.makeText(mContext, "请先登录", Toast.LENGTH_SHORT).show();
}
}
});
@@ -123,17 +124,17 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
@Override
public void onLoadMore() {
adapter.setLoadState(adapter.LOADING);
- if(endcount){
- start=end+1;
- end=count;
- }else{
- start=end+1;
- end=start+4;
+ if (end < count) {
+ if (end + 5 > count) {
+ start = end + 1;
+ end = count;
+ } else {
+ start = end + 1;
+ end = start + 4;
}
- new MainService(handler2).getPost(start,end);
- }else{
+ new MainService(handler2).getPost(start, end);
+ } else {
// 显示加载到底的提示
adapter.setLoadState(adapter.LOADING_END);
}
@@ -154,27 +155,28 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
fragment.setArguments(arguments);
return fragment;
}
+
// 数据初始化
Handler handler = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(Message msg) {
UIHelper.closeDialog(mContext);
- List- items=new ArrayList<>();
+ List
- items = new ArrayList<>();
switch (msg.what) {
case SUCCESS:
Toast.makeText(mContext, "成功获取数据", Toast.LENGTH_SHORT).show();
- ReModel reModel=(ReModel) msg.obj;
+ ReModel reModel = (ReModel) msg.obj;
lists = reModel.getMain();
- count=reModel.getCount();
+ count = reModel.getCount();
System.out.println(count);
- for(ReModel.Main list:lists){
- Item item=new Item();
+ for (ReModel.Main list : lists) {
+ Item item = new Item();
item.setMain(list);
System.out.println(list.getUserInfo().getIntroduction());
- List
urls=new ArrayList<>();
- for(int i=0;i urls = new ArrayList<>();
+ for (int i = 0; i < list.getPost().getPostType(); i++) {
+ String url = IMAGE_URL + "/" + list.getPost().getPostId() + "/" + list.getPost().getPostId() + "_" + i + ".jpg";
urls.add(url);
}
item.setImagesUrls(urls);
@@ -190,9 +192,9 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
}
// 显示帖子列表
recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
- adapter = new DataAdapter(mContext,items,llComment, etComment1, tabLayout,tvSend);
- adapter.type=MAIN;
- Log.i("TAG", "handleMessage: "+items.size());
+ adapter = new DataAdapter(mContext, items, llComment, etComment1, tvSend);
+ adapter.type = MAIN;
+ Log.i("TAG", "handleMessage: " + items.size());
recyclerView.setAdapter(adapter);
return false;
}
@@ -206,16 +208,16 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
switch (msg.what) {
case SUCCESS:
Toast.makeText(mContext, "成功获取数据", Toast.LENGTH_SHORT).show();
- ReModel reModel=(ReModel) msg.obj;
+ ReModel reModel = (ReModel) msg.obj;
lists = reModel.getMain();
- count=reModel.getCount();
- List- items=new ArrayList<>();
- for(ReModel.Main list:lists){
- Item item=new Item();
+ count = reModel.getCount();
+ List
- items = new ArrayList<>();
+ for (ReModel.Main list : lists) {
+ Item item = new Item();
item.setMain(list);
- List
urls=new ArrayList<>();
- for(int i=0;i urls = new ArrayList<>();
+ for (int i = 0; i < list.getPost().getPostType(); i++) {
+ String url = IMAGE_URL + "/" + list.getPost().getPostId() + "/" + list.getPost().getPostId() + "_" + i + ".jpg";
urls.add(url);
}
item.setImagesUrls(urls);
@@ -234,20 +236,20 @@ public class HomeFragment extends Fragment implements DataAdapter.Click{
});
// 数据添加
- Handler handler2=new Handler(new Handler.Callback() {
+ Handler handler2 = new Handler(new Handler.Callback() {
@Override
public boolean handleMessage(@NonNull Message msg) {
switch (msg.what) {
case SUCCESS:
- ReModel reModel=(ReModel) msg.obj;
+ ReModel reModel = (ReModel) msg.obj;
List addLists = reModel.getMain();
- List- items=new ArrayList<>();
- for(ReModel.Main list:addLists){
- Item item=new Item();
+ List
- items = new ArrayList<>();
+ for (ReModel.Main list : addLists) {
+ Item item = new Item();
item.setMain(list);
- List
urls=new ArrayList<>();
- for(int i=0;i urls = new ArrayList<>();
+ for (int i = 0; i < list.getPost().getPostType(); i++) {
+ String url = IMAGE_URL + "/" + list.getPost().getPostId() + "/" + list.getPost().getPostId() + "_" + i + ".jpg";
urls.add(url);
}
item.setImagesUrls(urls);
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
index 5c6eabb..bd831a9 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MeFragment.java
@@ -1,27 +1,16 @@
package com.moyv.schoolbbs.ui.fragment;
-import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.graphics.Bitmap;
-import android.graphics.BitmapFactory;
-import android.graphics.Color;
-import android.graphics.PorterDuff;
-import android.graphics.drawable.Drawable;
-import android.media.Image;
-import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
-import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
-import android.provider.MediaStore;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -29,27 +18,19 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
-import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.core.graphics.drawable.DrawableCompat;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
-import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;
-import com.bumptech.glide.request.target.SimpleTarget;
-import com.bumptech.glide.request.transition.Transition;
-import com.luck.picture.lib.PictureSelector;
-import com.luck.picture.lib.config.PictureConfig;
-import com.luck.picture.lib.entity.LocalMedia;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.bean.UserInfo;
-import com.moyv.schoolbbs.config.AccountConstant;
+import com.moyv.schoolbbs.config.SharedPreConstant;
import com.moyv.schoolbbs.config.PictureSelectorConfig;
import com.moyv.schoolbbs.service.ChangeService;
import com.moyv.schoolbbs.service.UserInfoService;
@@ -58,32 +39,15 @@ import com.moyv.schoolbbs.ui.activity.ManagerActivity;
import com.moyv.schoolbbs.ui.view.MaskImageView;
import com.moyv.schoolbbs.ui.view.MeItemView;
import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
-import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
-import com.moyv.schoolbbs.util.UCropUtils;
-import com.yalantis.ucrop.UCrop;
-import com.yalantis.ucrop.UCropActivity;
+import com.moyv.schoolbbs.ui.view.popWindow.window.PopWindow;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.util.List;
-
-import jp.wasabeef.glide.transformations.BlurTransformation;
-import jp.wasabeef.glide.transformations.CropCircleTransformation;
-
-import static android.app.Activity.RESULT_OK;
-import static android.content.ContentValues.TAG;
-import static com.bumptech.glide.request.RequestOptions.bitmapTransform;
-import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.config.SharedPreConstant.LOGIN;
import static com.moyv.schoolbbs.config.PictureSelectorConfig.initCamer;
import static com.moyv.schoolbbs.config.URLConstant.HEAD_URL;
import static com.moyv.schoolbbs.service.MainService.STAR_POSTS;
import static com.moyv.schoolbbs.service.MainService.USER_POSTS;
-import static com.moyv.schoolbbs.service.PictureService.PIC_POST;
-import static com.moyv.schoolbbs.service.PictureService.uploading;
import static com.moyv.schoolbbs.util.AnalysisUtils.cleanLoginStatus;
import static com.moyv.schoolbbs.util.AnalysisUtils.readLoginStatus;
-import static com.moyv.schoolbbs.util.AnalysisUtils.readLoginUserName;
import static com.moyv.schoolbbs.util.ToastUtils.show;
/**
@@ -99,15 +63,9 @@ public class MeFragment extends Fragment implements View.OnClickListener {
private MeItemView itemName;
private MeItemView itemAccount;
private MeItemView itemIntroduction;
- private AlertDialog changeDialog;
- private TextView postManager;
- private TextView starManager;
+ private MeItemView postManager;
+ private MeItemView starManager;
- private final static String CROPIMAGEROOT = Environment.getExternalStorageDirectory() + "/myxmpp/";
- public final static int REQUEST_PICTURE_CHOOSE = 1;
- public final static int REQUEST_CAMERA_IMAGE = 2;
- public static File mPictureFile;//照相产生的临时图片
- private static Uri imageUri = null;//拍照后,照片的Uri
public static MeFragment newInstance(String title) {
Bundle arguments = new Bundle();
@@ -161,6 +119,7 @@ public class MeFragment extends Fragment implements View.OnClickListener {
int account = sharedPreferences.getInt("account", 0);
Glide.with(context).load(HEAD_URL + account + ".jpg")
//缓存
+ .skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.apply(ivBackground.setGaussBlur())
//淡入淡出
@@ -172,10 +131,12 @@ public class MeFragment extends Fragment implements View.OnClickListener {
Glide.with(context).load(HEAD_URL + account + ".jpg")
.error(R.drawable.login_head)
- .apply(RequestOptions.bitmapTransform(new CircleCrop()).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true))
+ .skipMemoryCache(true)
+ .diskCacheStrategy(DiskCacheStrategy.NONE)
+ .apply(RequestOptions.bitmapTransform(new CircleCrop()))
.into(ivHead);
UserInfoService userInfoService = new UserInfoService();
- new AccountConstant(context);
+ new SharedPreConstant(context);
userInfoService.getUserInfo(account, handler);
itemAccount.setData(String.valueOf(account));
} else {
@@ -204,6 +165,10 @@ public class MeFragment extends Fragment implements View.OnClickListener {
itemName.setData(userInfo.getName());
itemIntroduction.setData(userInfo.getIntroduction());
break;
+ case 404:
+ show("登录失败,请重新登录");
+ cleanLoginStatus(context);
+ break;
default:
System.out.println("返回错误信息");
}
@@ -220,7 +185,7 @@ public class MeFragment extends Fragment implements View.OnClickListener {
break;
case R.id.btn_log_out:
cleanLoginStatus(context);
- new AccountConstant(context);
+ new SharedPreConstant(context);
if (!LOGIN) {
onResume();
}
@@ -231,10 +196,10 @@ public class MeFragment extends Fragment implements View.OnClickListener {
case R.id.me_item_introduction:
dialog(2, "请输入要修改的简介");
break;
- case R.id.me_item_change_psw:
-// dialog(3,"请输入要修改的密码");
- show("修改密码点击事件");
- break;
+// case R.id.me_item_change_psw:
+//// dialog(3,"请输入要修改的密码");
+// show("修改密码点击事件");
+// break;
case R.id.me_tv_posts:
intentPostsManager(USER_POSTS);
show("帖子管理");
@@ -245,6 +210,7 @@ public class MeFragment extends Fragment implements View.OnClickListener {
break;
case R.id.h_head:
showPopWindow();
+ break;
default:
System.out.println("点击事件没有执行事件");
}
@@ -253,7 +219,6 @@ public class MeFragment extends Fragment implements View.OnClickListener {
public void dialog(int index, String hint) {
final EditText et = new EditText(context);
et.setHint(hint);
-// et.setText(itemName.getData().getText().toString());
changeDialog = new AlertDialog.Builder(context).setTitle("请输入消息")
.setIcon(android.R.drawable.sym_def_app_icon)
.setView(et)
@@ -287,21 +252,18 @@ public class MeFragment extends Fragment implements View.OnClickListener {
}
-
-
-
/**
* popwindow选择拍照还是选择图片
+ * 弹出选项框
*/
private void showPopWindow() {
PopWindow popWindow = new PopWindow.Builder((Activity) context)
- .setStyle(PopWindow.PopWindowStyle.PopUp)
+// .setStyle(PopWindow.PopWindowStyle.PopUp)
.addItemAction(new PopItemAction("选择照片", PopItemAction.PopItemStyle.Normal, new PopItemAction.OnClickListener() {
@Override
public void onClick() {
-// choosePhoto((Activity) context);
// 调用图片选择器,最多可以选中一张
- PictureSelectorConfig.initMultiConfigCut((Activity) context, 1);
+ PictureSelectorConfig.initMultiConfigCut((Activity) context);
}
}))
@@ -317,33 +279,4 @@ public class MeFragment extends Fragment implements View.OnClickListener {
popWindow.show();
}
- /**
- * 从相册选择图片
- *
- * @param activity
- */
- public static void choosePhoto(Activity activity) {
- Intent intent = new Intent();
- intent.setType("image/*");
- intent.setAction(Intent.ACTION_PICK);
- activity.startActivityForResult(intent, REQUEST_PICTURE_CHOOSE);
- }
-
- /**
- * 打开相机拍照
- *
- * @param activity
- * @return
- */
- public static void openCamera(Activity activity) {
- mPictureFile = new File(CROPIMAGEROOT, "_" + System.currentTimeMillis() + ".jpg");
- imageUri = Uri.fromFile(mPictureFile);
- // 启动拍照,并保存到临时文件
- Intent mIntent = new Intent();
- mIntent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
- mIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mPictureFile));
- mIntent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
- activity.startActivityForResult(mIntent, REQUEST_CAMERA_IMAGE);
- }
-
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MessageFragment.java b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MessageFragment.java
index bfb7965..6f33a97 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MessageFragment.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/fragment/MessageFragment.java
@@ -19,6 +19,9 @@ import com.moyv.schoolbbs.util.AppUtils;
import com.stfalcon.chatkit.dialogs.DialogsList;
import com.stfalcon.chatkit.dialogs.DialogsListAdapter;
+/**
+ * @author moyv
+ */
public class MessageFragment extends Fragment {
private Context context;
private DialogsList dialogsList;
@@ -35,17 +38,17 @@ public class MessageFragment extends Fragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_message, container, false);
- context = root .getContext();
+ context = root.getContext();
- dialogsList=root.findViewById(R.id.dialogsList);
+ dialogsList = root.findViewById(R.id.dialogsList);
- DialogsListAdapter dialogsListAdapter=new DialogsListAdapter<>(R.layout.item_custom_dialog_view_holder,(imageView, url, payload) -> {
+ DialogsListAdapter dialogsListAdapter = new DialogsListAdapter<>(R.layout.item_custom_dialog_view_holder, (imageView, url, payload) -> {
Glide.with(context).load(url).into(imageView);
});
dialogsListAdapter.addItems(DialogsFixtures.getDialogs());//数据源
dialogsListAdapter.setOnDialogClickListener(dialog -> ChatActivity.open(context));
- dialogsListAdapter.setOnDialogLongClickListener(dialog -> AppUtils.showToast(context,dialog.getDialogName(),false));
+ dialogsListAdapter.setOnDialogLongClickListener(dialog -> AppUtils.showToast(context, dialog.getDialogName(), false));
dialogsList.setAdapter(dialogsListAdapter);
return root;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/listener/EndlessRecyclerOnScrollListener.java b/app/src/main/java/com/moyv/schoolbbs/ui/listener/EndlessRecyclerOnScrollListener.java
index de997ed..5a901fd 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/listener/EndlessRecyclerOnScrollListener.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/listener/EndlessRecyclerOnScrollListener.java
@@ -5,7 +5,8 @@ import androidx.recyclerview.widget.RecyclerView;
/**
* RecyclerView滑动监听
- * Created by yangle on 2017/10/12.
+ *
+ * @author moyv
*/
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/CircleMovementMethod.java b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/CircleMovementMethod.java
index 2bcc5b7..c1e2344 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/CircleMovementMethod.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/CircleMovementMethod.java
@@ -15,52 +15,55 @@ import com.moyv.schoolbbs.app.App;
/**
- * @作者: njb
- * @时间: 2019/7/22 10:53
+ * @author moyv
* @描述:
*/
public class CircleMovementMethod extends BaseMovementMethod {
public final String TAG = CircleMovementMethod.class.getSimpleName();
private final static int DEFAULT_COLOR_ID = R.color.transparent;
private final static int DEFAULT_CLICKABLEA_COLOR_ID = R.color.default_clickable_color;
- /**整个textView的背景色*/
+ /**
+ * 整个textView的背景色
+ */
private int textViewBgColor;
- /**点击部分文字时部分文字的背景色*/
+ /**
+ * 点击部分文字时部分文字的背景色
+ */
private int clickableSpanBgClor;
private BackgroundColorSpan mBgSpan;
private ClickableSpan[] mClickLinks;
private boolean isPassToTv = true;
+
/**
* true:响应textview的点击事件, false:响应设置的clickableSpan事件
*/
public boolean isPassToTv() {
return isPassToTv;
}
- private void setPassToTv(boolean isPassToTv){
+
+ private void setPassToTv(boolean isPassToTv) {
this.isPassToTv = isPassToTv;
}
- public CircleMovementMethod(){
+ public CircleMovementMethod() {
this.textViewBgColor = App.getContext().getResources().getColor(DEFAULT_COLOR_ID);
this.clickableSpanBgClor = App.getContext().getResources().getColor(DEFAULT_CLICKABLEA_COLOR_ID);
}
/**
- *
- * @param clickableSpanBgClor 点击选中部分时的背景色
+ * @param clickableSpanBgClor 点击选中部分时的背景色
*/
- public CircleMovementMethod(int clickableSpanBgClor){
+ public CircleMovementMethod(int clickableSpanBgClor) {
this.clickableSpanBgClor = clickableSpanBgClor;
// this.textViewBgColor = App.getContext().getResources().getColor(DEFAULT_COLOR_ID);
}
/**
- *
* @param clickableSpanBgClor 点击选中部分时的背景色
- * @param textViewBgColor 整个textView点击时的背景色
+ * @param textViewBgColor 整个textView点击时的背景色
*/
- public CircleMovementMethod(int clickableSpanBgClor, int textViewBgColor){
+ public CircleMovementMethod(int clickableSpanBgClor, int textViewBgColor) {
this.textViewBgColor = textViewBgColor;
this.clickableSpanBgClor = clickableSpanBgClor;
}
@@ -70,7 +73,7 @@ public class CircleMovementMethod extends BaseMovementMethod {
MotionEvent event) {
int action = event.getAction();
- if(action == MotionEvent.ACTION_DOWN){
+ if (action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();
@@ -85,7 +88,7 @@ public class CircleMovementMethod extends BaseMovementMethod {
int off = layout.getOffsetForHorizontal(line, x);
mClickLinks = buffer.getSpans(off, off, ClickableSpan.class);
- if(mClickLinks.length > 0){
+ if (mClickLinks.length > 0) {
// 点击的是Span区域,不要把点击事件传递
setPassToTv(false);
Selection.setSelection(buffer,
@@ -97,27 +100,27 @@ public class CircleMovementMethod extends BaseMovementMethod {
buffer.getSpanStart(mClickLinks[0]),
buffer.getSpanEnd(mClickLinks[0]),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- }else{
+ } else {
setPassToTv(true);
// textview选中效果
widget.setBackgroundColor(textViewBgColor);
}
- }else if(action == MotionEvent.ACTION_UP){
- if(mClickLinks.length > 0){
+ } else if (action == MotionEvent.ACTION_UP) {
+ if (mClickLinks.length > 0) {
mClickLinks[0].onClick(widget);
- if(mBgSpan != null){//移除点击时设置的背景span
+ if (mBgSpan != null) {//移除点击时设置的背景span
buffer.removeSpan(mBgSpan);
}
- }else{
+ } else {
}
Selection.removeSelection(buffer);
widget.setBackgroundResource(R.color.transparent);
- }else if(action == MotionEvent.ACTION_MOVE){
+ } else if (action == MotionEvent.ACTION_MOVE) {
//这种情况不用做处理
- }else{
- if(mBgSpan != null){//移除点击时设置的背景span
+ } else {
+ if (mBgSpan != null) {//移除点击时设置的背景span
buffer.removeSpan(mBgSpan);
}
widget.setBackgroundResource(R.color.transparent);
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java
index adcbfdc..076e096 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/ISpanClick.java
@@ -1,6 +1,9 @@
package com.moyv.schoolbbs.ui.spannable;
+/**
+ * @author moyv
+ */
public interface ISpanClick {
public void onClick(int position);
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java
index 7eb92c4..6249d1a 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/spannable/SpannableClickable.java
@@ -9,9 +9,7 @@ import com.moyv.schoolbbs.app.App;
/**
- * @作者: njb
- * @时间: 2019/7/22 10:53
- * @描述:
+ * @author moyv
*/
public abstract class SpannableClickable extends ClickableSpan implements View.OnClickListener {
@@ -19,13 +17,13 @@ public abstract class SpannableClickable extends ClickableSpan implements View.O
/**
* text颜色
*/
- private int textColor ;
+ private int textColor;
public SpannableClickable() {
this.textColor = App.getContext().getResources().getColor(DEFAULT_COLOR_ID);
}
- public SpannableClickable(int textColor){
+ public SpannableClickable(int textColor) {
this.textColor = textColor;
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java
index ca9e7e9..2381c18 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopAlertDialog.java
@@ -15,7 +15,7 @@ import android.widget.LinearLayout;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.ui.view.popWindow.view.PopAlertView;
-
+import com.moyv.schoolbbs.ui.view.popWindow.window.PopWindow;
public class PopAlertDialog extends Dialog implements PopWindowInterface, DialogInterface.OnShowListener, View.OnClickListener,
@@ -58,17 +58,17 @@ public class PopAlertDialog extends Dialog implements PopWindowInterface, Dialog
}
private void initRootView() {
- mRootLayout = (FrameLayout) findViewById(R.id.layout_root);
+ mRootLayout = findViewById(R.id.layout_root);
mRootLayout.setOnClickListener(this);
}
private void initContentView(CharSequence title, CharSequence message) {
- mPopAlertDialog = (PopAlertView) findViewById(R.id.popAlertView);
+ mPopAlertDialog = findViewById(R.id.popAlertView);
mPopAlertDialog.setPopWindow(mPopWindow);
mPopAlertDialog.setTitleAndMessage(title, message);
- mContentLayout = (LinearLayout) findViewById(R.id.layout_center);
- mContainLayout = (FrameLayout) findViewById(R.id.layout_contain);
+ mContentLayout =findViewById(R.id.layout_center);
+ mContainLayout =findViewById(R.id.layout_contain);
}
private void initAnim() {
@@ -84,7 +84,7 @@ public class PopAlertDialog extends Dialog implements PopWindowInterface, Dialog
}
});
-// mAlphaOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_enter);
+ mAlphaOpenAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_enter);
mAlphaCloseAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pop_alpha_exit);
mAlphaCloseAnimation.setAnimationListener(new PopSimpleAnimationListener() {
@Override
@@ -111,7 +111,7 @@ public class PopAlertDialog extends Dialog implements PopWindowInterface, Dialog
if (mIsDismissed) {
mIsDismissed = false;
onStartShow(PopAlertDialog.this);
- mRootLayout.startAnimation(mAlphaOpenAnimation);
+// mRootLayout.startAnimation(mAlphaOpenAnimation);
if (mCustomView != null) {
mContentLayout.startAnimation(mPopOpenAnimation);
} else if (mPopAlertDialog.showAble()) {
@@ -213,7 +213,6 @@ public class PopAlertDialog extends Dialog implements PopWindowInterface, Dialog
windowManager.getDefaultDisplay().getMetrics(dm);
return dm.heightPixels;
}
-
@Override
public void onStartDismiss(PopWindowInterface popWindowInterface) {
mPopWindow.onStartDismiss(popWindowInterface);
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java
index 5795309..587c976 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopItemAction.java
@@ -1,7 +1,7 @@
package com.moyv.schoolbbs.ui.view.popWindow;
/**
- * Created by HMY on 2016/9/10.
+ * @author moyv
*/
public class PopItemAction {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java
index b791ea3..91d5f22 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopViewInterface.java
@@ -2,6 +2,8 @@ package com.moyv.schoolbbs.ui.view.popWindow;
import android.view.View;
+import com.moyv.schoolbbs.ui.view.popWindow.window.PopWindow;
+
/**
* Created by HMY on 2016/9/10.
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java
index e50cc8a..1cca564 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopAlertView.java
@@ -10,7 +10,7 @@ import android.widget.TextView;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
import com.moyv.schoolbbs.ui.view.popWindow.PopViewInterface;
-import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+import com.moyv.schoolbbs.ui.view.popWindow.window.PopWindow;
import com.moyv.schoolbbs.ui.view.popWindow.PopWindowHelper;
/**
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java
index cd5edf6..2aad59c 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopItemView.java
@@ -7,12 +7,11 @@ import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
-import android.widget.TextView;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
-import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+import com.moyv.schoolbbs.ui.view.popWindow.window.PopWindow;
public class PopItemView extends androidx.appcompat.widget.AppCompatTextView implements View.OnClickListener {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java
index 80154b1..d9646a0 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/view/PopUpView.java
@@ -10,7 +10,7 @@ import android.widget.TextView;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
import com.moyv.schoolbbs.ui.view.popWindow.PopViewInterface;
-import com.moyv.schoolbbs.ui.view.popWindow.PopWindow;
+import com.moyv.schoolbbs.ui.view.popWindow.window.PopWindow;
import com.moyv.schoolbbs.ui.view.popWindow.PopWindowHelper;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopDownWindow.java
similarity index 95%
rename from app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java
rename to app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopDownWindow.java
index c4c841a..2eff8a4 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopDownWindow.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopDownWindow.java
@@ -1,4 +1,4 @@
-package com.moyv.schoolbbs.ui.view.popWindow;
+package com.moyv.schoolbbs.ui.view.popWindow.window;
import android.app.Activity;
import android.content.Context;
@@ -17,6 +17,9 @@ import android.widget.LinearLayout;
import android.widget.PopupWindow;
import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopSimpleAnimationListener;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindowInterface;
import com.moyv.schoolbbs.ui.view.popWindow.view.PopDownView;
import java.util.TimerTask;
@@ -140,8 +143,8 @@ public class PopDownWindow extends PopupWindow implements PopWindowInterface, Vi
}
});
- mAlphaOpenAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.pop_alpha_enter);
- mAlphaCloseAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.pop_alpha_exit);
+// mAlphaOpenAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.pop_alpha_enter);
+// mAlphaCloseAnimation = AnimationUtils.loadAnimation(mActivity, R.anim.pop_alpha_exit);
}
private Runnable mDismissRunnable = new Runnable() {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopUpWindow.java
similarity index 96%
rename from app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java
rename to app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopUpWindow.java
index e033170..7749f06 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopUpWindow.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopUpWindow.java
@@ -1,4 +1,4 @@
-package com.moyv.schoolbbs.ui.view.popWindow;
+package com.moyv.schoolbbs.ui.view.popWindow.window;
import android.app.Activity;
import android.app.Dialog;
@@ -14,6 +14,9 @@ import android.widget.FrameLayout;
import android.widget.LinearLayout;
import com.moyv.schoolbbs.R;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopSimpleAnimationListener;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindowInterface;
import com.moyv.schoolbbs.ui.view.popWindow.view.PopUpView;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopWindow.java
similarity index 97%
rename from app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java
rename to app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopWindow.java
index 5f96e40..36868d6 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/PopWindow.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/view/popWindow/window/PopWindow.java
@@ -1,4 +1,4 @@
-package com.moyv.schoolbbs.ui.view.popWindow;
+package com.moyv.schoolbbs.ui.view.popWindow.window;
@@ -7,6 +7,9 @@ import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
+import com.moyv.schoolbbs.ui.view.popWindow.PopAlertDialog;
+import com.moyv.schoolbbs.ui.view.popWindow.PopItemAction;
+import com.moyv.schoolbbs.ui.view.popWindow.PopWindowInterface;
/**
diff --git a/app/src/main/java/com/moyv/schoolbbs/util/FormatUtils.java b/app/src/main/java/com/moyv/schoolbbs/util/FormatUtils.java
index af0707a..84a46e8 100644
--- a/app/src/main/java/com/moyv/schoolbbs/util/FormatUtils.java
+++ b/app/src/main/java/com/moyv/schoolbbs/util/FormatUtils.java
@@ -1,13 +1,21 @@
package com.moyv.schoolbbs.util;
+import android.os.Build;
+
+import androidx.annotation.RequiresApi;
+
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
import java.util.TimeZone;
/*
* Created by troy379 on 06.04.17.
*/
public final class FormatUtils {
+ public static final long ONE_DAY_MILLIS = 24 * 60 * 60 * 1000;
+ public static final long ONE_HOUR_MILLIS = 60 * 60 * 1000;
+ public static final long ONE_MINUTE_MILLIS = 60 * 1000;
private FormatUtils() {
throw new AssertionError();
}
@@ -18,4 +26,32 @@ public final class FormatUtils {
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
return formatter.format(date);
}
+
+ public static String getFormatData(long start, long now){
+ String result="0000-00-00";
+ long timer=now-start;
+ if(timerONE_HOUR_MILLIS){
+ SimpleDateFormat formatDay = new SimpleDateFormat("HH小时前",
+ Locale.getDefault());
+ Date date = new Date(timer);
+ result=formatDay.format(date);
+ }else if(timerONE_MINUTE_MILLIS){
+ SimpleDateFormat formatDay = new SimpleDateFormat("mm分钟前",
+ Locale.getDefault());
+ Date date = new Date(timer);
+ result=formatDay.format(date);
+ }else if (timer0){
+ SimpleDateFormat formatDay = new SimpleDateFormat("mm分钟前",
+ Locale.getDefault());
+ Date date = new Date(timer);
+ result=formatDay.format(date);
+ }else if(timer>ONE_DAY_MILLIS){
+ int date= 0;
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
+ date = Math.toIntExact(timer / ONE_DAY_MILLIS);
+ }
+ result=date+"天前";
+ }
+ return result;
+ }
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java b/app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java
index b91acfa..74bdd98 100644
--- a/app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java
+++ b/app/src/main/java/com/moyv/schoolbbs/util/UIHelper.java
@@ -24,7 +24,6 @@ public class UIHelper {
mLoadingDialog.setCancelable(false);
mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
-
mLoadingDialog.show();
avLoadingIndicatorView.smoothToShow();
mLoadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
diff --git a/app/src/main/res/layout/fragment_me.xml b/app/src/main/res/layout/fragment_me.xml
index 9df02da..33e7e93 100644
--- a/app/src/main/res/layout/fragment_me.xml
+++ b/app/src/main/res/layout/fragment_me.xml
@@ -21,7 +21,7 @@
+ android:layout_height="200dp">
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -97,7 +97,8 @@
app:icon="@drawable/ic_me_account"
app:name="账号"
android:background="#fff"
- app:show_more="true"/>
+ app:show_more="true"
+ app:show_line="true"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--
Gitee
From c3959c2bf865a685475c3b3137008a906f1f4ce4 Mon Sep 17 00:00:00 2001
From: moyvch <3448497151@qq.com>
Date: Wed, 23 Jun 2021 19:59:48 +0800
Subject: [PATCH 9/9] =?UTF-8?q?=E5=B7=AE=E4=B8=8D=E5=A4=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
...dPreConstant.java => AccountConstant.java} | 4 +-
.../moyv/schoolbbs/service/ChangeService.java | 4 +-
.../moyv/schoolbbs/service/CmtService.java | 2 +-
.../schoolbbs/service/DeletePostService.java | 2 +-
.../moyv/schoolbbs/service/StarService.java | 2 +-
.../schoolbbs/ui/activity/AddActivity.java | 4 +-
.../ui/activity/BottomTabLayoutActivity.java | 14 +-
.../schoolbbs/ui/activity/LoginActivity.java | 3 +-
.../ui/activity/ManagerActivity.java | 2 +-
.../ui/activity/RegisterActivity.java | 4 +-
.../schoolbbs/ui/adapter/DataAdapter.java | 10 +-
.../schoolbbs/ui/adapter/ImagesAdapter.java | 5 +-
.../schoolbbs/ui/fragment/HomeFragment.java | 2 +-
.../schoolbbs/ui/fragment/MeFragment.java | 20 ++-
.../moyv/schoolbbs/util/GlideCacheUtil.java | 170 ++++++++++++++++++
.../res/layout/item_fragment_main_image.xml | 3 +-
16 files changed, 220 insertions(+), 31 deletions(-)
rename app/src/main/java/com/moyv/schoolbbs/config/{SharedPreConstant.java => AccountConstant.java} (90%)
create mode 100644 app/src/main/java/com/moyv/schoolbbs/util/GlideCacheUtil.java
diff --git a/app/src/main/java/com/moyv/schoolbbs/config/SharedPreConstant.java b/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
similarity index 90%
rename from app/src/main/java/com/moyv/schoolbbs/config/SharedPreConstant.java
rename to app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
index 9605419..7b9b944 100644
--- a/app/src/main/java/com/moyv/schoolbbs/config/SharedPreConstant.java
+++ b/app/src/main/java/com/moyv/schoolbbs/config/AccountConstant.java
@@ -7,14 +7,14 @@ import android.content.SharedPreferences;
* @author moyv
* @描述 sharedPreferences文件的数据作为全局变量
*/
-public class SharedPreConstant {
+public class AccountConstant {
public static boolean LOGIN;
public static int ACCOUNT;
public static String TOKEN;
public static String NAME;
public static String INTRODUCTION;
- public SharedPreConstant(Context context) {
+ public AccountConstant(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences("login", 0);
LOGIN = sharedPreferences.getBoolean("isLogin", false);
if (LOGIN) {
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java b/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java
index f01c4a5..7a5b053 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/ChangeService.java
@@ -17,8 +17,8 @@ import okhttp3.Request;
import okhttp3.Response;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.CHANGE_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
import static com.moyv.schoolbbs.util.ToastUtils.show;
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java b/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
index f84c262..2e5668c 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/CmtService.java
@@ -20,7 +20,7 @@ import okhttp3.Request;
import okhttp3.Response;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
+import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.CMT_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
import static com.moyv.schoolbbs.util.JsonUtil.parseJson;
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java b/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java
index 35d1688..efead30 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/DeletePostService.java
@@ -16,7 +16,7 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
-import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
+import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.DELETE_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
diff --git a/app/src/main/java/com/moyv/schoolbbs/service/StarService.java b/app/src/main/java/com/moyv/schoolbbs/service/StarService.java
index 42187ce..dcdc4a2 100644
--- a/app/src/main/java/com/moyv/schoolbbs/service/StarService.java
+++ b/app/src/main/java/com/moyv/schoolbbs/service/StarService.java
@@ -17,7 +17,7 @@ import okhttp3.Request;
import okhttp3.Response;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
+import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.STAR_URL;
import static com.moyv.schoolbbs.util.HttpUtil.createClient;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/AddActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/AddActivity.java
index b0e323b..4f0398a 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/AddActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/AddActivity.java
@@ -43,8 +43,8 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
-import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.SharedPreConstant.TOKEN;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.AccountConstant.TOKEN;
import static com.moyv.schoolbbs.config.URLConstant.RELPOST_URL;
import static com.moyv.schoolbbs.service.PictureService.uploading;
import static com.moyv.schoolbbs.ui.config.MainConstant.ADD_SHOW;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
index 87e87f8..9fb92b9 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/BottomTabLayoutActivity.java
@@ -18,15 +18,16 @@ import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.moyv.schoolbbs.R;
-import com.moyv.schoolbbs.config.SharedPreConstant;
+import com.moyv.schoolbbs.config.AccountConstant;
import com.moyv.schoolbbs.ui.adapter.DataGenerator;
import com.moyv.schoolbbs.ui.fragment.HomeFragment;
+import com.moyv.schoolbbs.util.GlideCacheUtil;
import java.util.List;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.SharedPreConstant.LOGIN;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
import static com.moyv.schoolbbs.service.PictureService.uploadHead;
import static com.moyv.schoolbbs.ui.adapter.DataGenerator.mTabTitle;
import static com.moyv.schoolbbs.util.ToastUtils.init;
@@ -39,6 +40,7 @@ import static com.moyv.schoolbbs.util.UIHelper.showDialogForLoading;
* @author moyv
*/
public class BottomTabLayoutActivity extends AppCompatActivity {
+ public static String HEAD_SIG="000000";
private TabLayout mTabLayout;
private Fragment[] mFragmensts;
private Fragment currentFragment;
@@ -50,7 +52,7 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
setContentView(R.layout.bottom_tab_layout_ac);
mFragmensts = DataGenerator.getFragments("TabLayout Tab");
context = this;
- new SharedPreConstant(context);
+ new AccountConstant(context);
init(context);
initView();
@@ -150,6 +152,10 @@ public class BottomTabLayoutActivity extends AppCompatActivity {
// Uri sourceUri = data.getData();
// uCropUtils.startUCrop(sourceUri);
// 图片选择器调用
+ GlideCacheUtil glideCacheUtil;
+ glideCacheUtil = GlideCacheUtil.getInstance();
+ glideCacheUtil.clearImageAllCache(context);
+// HEAD_SIG=String.valueOf(System.currentTimeMillis());
List imageUrl = PictureSelector.obtainMultipleResult(data);
upload(imageUrl);
} else {
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
index 39bd496..0313f5a 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/LoginActivity.java
@@ -20,6 +20,7 @@ import androidx.appcompat.app.AppCompatActivity;
import com.moyv.schoolbbs.R;
import com.moyv.schoolbbs.bean.LoginBean;
+import com.moyv.schoolbbs.config.AccountConstant;
import com.moyv.schoolbbs.service.LoginService;
import static android.content.ContentValues.TAG;
@@ -145,6 +146,6 @@ public class LoginActivity extends AppCompatActivity implements View.OnClickList
}
editor.putString("password", password);
editor.commit();
- new AssertionError(context);
+ new AccountConstant(context);
}
}
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
index 777dae3..fab7e42 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/ManagerActivity.java
@@ -32,7 +32,7 @@ import java.util.ArrayList;
import java.util.List;
import static com.moyv.schoolbbs.base.Global.init;
-import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
import static com.moyv.schoolbbs.service.MainService.USER_POSTS;
import static com.moyv.schoolbbs.ui.adapter.DataAdapter.POSTMANAGER;
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
index a0ed253..5bbd7ce 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/activity/RegisterActivity.java
@@ -15,7 +15,7 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.moyv.schoolbbs.R;
-import com.moyv.schoolbbs.config.SharedPreConstant;
+import com.moyv.schoolbbs.config.AccountConstant;
import com.moyv.schoolbbs.service.RegisterService;
import static com.moyv.schoolbbs.util.ToastUtils.init;
@@ -90,7 +90,7 @@ public class RegisterActivity extends AppCompatActivity implements View.OnClickL
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("account", account);
editor.putBoolean("isLogin", true);
- new SharedPreConstant(context);
+ new AccountConstant(context);
Intent intent = new Intent(context, LoginActivity.class);
startActivity(intent);
finish();
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
index f6d5fec..d75f959 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/DataAdapter.java
@@ -23,6 +23,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.getbase.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
import com.moyv.schoolbbs.R;
@@ -51,9 +52,9 @@ import java.util.Iterator;
import java.util.List;
import static android.content.ContentValues.TAG;
-import static com.moyv.schoolbbs.config.SharedPreConstant.ACCOUNT;
-import static com.moyv.schoolbbs.config.SharedPreConstant.LOGIN;
-import static com.moyv.schoolbbs.config.SharedPreConstant.NAME;
+import static com.moyv.schoolbbs.config.AccountConstant.ACCOUNT;
+import static com.moyv.schoolbbs.config.AccountConstant.LOGIN;
+import static com.moyv.schoolbbs.config.AccountConstant.NAME;
import static com.moyv.schoolbbs.config.URLConstant.IMAGE_URL;
import static com.moyv.schoolbbs.service.DeletePostService.deletePost;
import static com.moyv.schoolbbs.util.FormatUtils.getFormatData;
@@ -221,6 +222,9 @@ public class DataAdapter extends RecyclerView.Adapter {
String headUrl = IMAGE_URL + "/head/" + postList.get(position).getMain().getPost().getPostAccount() + ".jpg";
Glide.with(context)
.load(headUrl)
+ .skipMemoryCache(true)
+// .signature( new ObjectKey(HEAD_SIG))
+ .diskCacheStrategy(DiskCacheStrategy.NONE)
.placeholder(R.mipmap.ic_launcher)
.fallback(R.drawable.ic_launcher_background)
.into(recyclerViewHolder.ivHead);
diff --git a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
index eaccae9..0652955 100644
--- a/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
+++ b/app/src/main/java/com/moyv/schoolbbs/ui/adapter/ImagesAdapter.java
@@ -26,6 +26,7 @@ import static com.moyv.schoolbbs.ui.config.MainConstant.SHOW;
/**
* @author moyv
+ * @描述 网格图片适配器
*/
public class ImagesAdapter extends RecyclerView.Adapter {
public Context context;
@@ -77,8 +78,8 @@ public class ImagesAdapter extends RecyclerView.Adapter
+ android:layout_height="70dp"
+ android:padding="2dp">