diff --git a/app/build.gradle b/app/build.gradle index e70186e1..862dbb91 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -8,8 +8,8 @@ android { applicationId "me.yluo.ruisiapp" minSdkVersion 23 targetSdkVersion 29 - versionCode 38 - versionName '2.9.8' + versionCode 40 + versionName '2.9.8.2' } compileOptions { diff --git a/app/src/main/java/me/yluo/ruisiapp/activity/FragementActivity.java b/app/src/main/java/me/yluo/ruisiapp/activity/FragementActivity.java index d67f62dd..69b3e974 100644 --- a/app/src/main/java/me/yluo/ruisiapp/activity/FragementActivity.java +++ b/app/src/main/java/me/yluo/ruisiapp/activity/FragementActivity.java @@ -10,6 +10,7 @@ import me.yluo.ruisiapp.R; import me.yluo.ruisiapp.fragment.FrageHistory; +import me.yluo.ruisiapp.fragment.FrageMyBlog; import me.yluo.ruisiapp.fragment.FrageMyStar; import me.yluo.ruisiapp.fragment.FrageMyTopic; import me.yluo.ruisiapp.model.FrageType; @@ -47,8 +48,15 @@ protected void onCreate(Bundle savedInstanceState) { case FrageType.HISTORY: to = new FrageHistory(); break; - default: + case FrageType.BLOG: + to = new FrageMyBlog(); + args = new Bundle(); + args.putString("username", b.getString("username")); + args.putInt("uid", b.getInt("uid", 0)); + to.setArguments(args); break; + default: + throw new IllegalArgumentException("unknown type : " + b.getInt("TYPE")); } getSupportFragmentManager().beginTransaction().replace(R.id.container, to).commit(); } diff --git a/app/src/main/java/me/yluo/ruisiapp/activity/PostActivity.java b/app/src/main/java/me/yluo/ruisiapp/activity/PostActivity.java index b9803562..bde43d90 100644 --- a/app/src/main/java/me/yluo/ruisiapp/activity/PostActivity.java +++ b/app/src/main/java/me/yluo/ruisiapp/activity/PostActivity.java @@ -330,8 +330,13 @@ private void setupReplyView(SingleArticleData data) { input.setSelection(input.getText().length()); input.setTag(d); - commentHeaderView.setText("回复 " + d.index + " " + d.username + ":" - + d.textContent.substring(0, Math.min(20, d.textContent.length()))); + + if (d.type == SingleType.CONTENT || d.type == SingleType.COMMENT) { + commentHeaderView.setText("回复 " + d.index + " " + d.username + ":" + + d.textContent.substring(0, Math.min(20, d.textContent.length()))); + } else { + commentHeaderView.setText("回复 楼主 " + (isGetTitle ? title : "")); + } commentHeaderView.setVisibility(View.VISIBLE); } @@ -414,7 +419,6 @@ public void onListItemClick(View v, final int position) { // i.putExtra("islz", single.uid == datas.get(0).uid); // i.putExtra("data", single); // startActivityForResult(i, 20); - showReplyView(true, single); } break; diff --git a/app/src/main/java/me/yluo/ruisiapp/activity/PostsActivity.java b/app/src/main/java/me/yluo/ruisiapp/activity/PostsActivity.java index a0a711dd..cd2a433b 100644 --- a/app/src/main/java/me/yluo/ruisiapp/activity/PostsActivity.java +++ b/app/src/main/java/me/yluo/ruisiapp/activity/PostsActivity.java @@ -137,7 +137,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { mRecyclerView.setAdapter(adapter); myDB = new MyDB(this); datas.clear(); - btnRefresh.setOnClickListener(v -> refresh()); + btnRefresh.setOnClickListener(v -> refreshBtnCLick()); init(); //子类实现获取数据 getData(); @@ -185,6 +185,17 @@ public void onShow() { }); } + private void refreshBtnCLick() { + int offset = mRecyclerView.computeVerticalScrollOffset(); + if (offset == 0) { + refresh(); + } else if (offset > DimenUtils.getScreenHeight() * 4) { + mRecyclerView.scrollToPosition(0); + } else { + mRecyclerView.smoothScrollToPosition(0); + } + } + private void refresh() { btnRefresh.hide(); refreshLayout.setRefreshing(true); diff --git a/app/src/main/java/me/yluo/ruisiapp/activity/UserDetailActivity.java b/app/src/main/java/me/yluo/ruisiapp/activity/UserDetailActivity.java index 0b2317d4..1b96c502 100644 --- a/app/src/main/java/me/yluo/ruisiapp/activity/UserDetailActivity.java +++ b/app/src/main/java/me/yluo/ruisiapp/activity/UserDetailActivity.java @@ -140,6 +140,15 @@ protected void onCreate(Bundle savedInstanceState) { intent.putExtra("uid", uid); } + UserDetailActivity.this.startActivity(intent); + } else if (position == 1 && App.isLogin(UserDetailActivity.this)) { + Intent intent = new Intent(UserDetailActivity.this, FragementActivity.class); + intent.putExtra("TYPE", FrageType.BLOG); + intent.putExtra("username", username); + if (uid > 0) { + intent.putExtra("uid", uid); + } + UserDetailActivity.this.startActivity(intent); } }); @@ -300,6 +309,10 @@ protected Void doInBackground(String... params) { datas.add(new SimpleListData("帖子", null, "")); } + if (App.isLogin(UserDetailActivity.this)) { + datas.add(new SimpleListData("日志", null, "")); + } + for (Element tmp : lists) { String value = tmp.select("span").text(); tmp.select("span").remove(); diff --git a/app/src/main/java/me/yluo/ruisiapp/adapter/MyBlogListAdapter.java b/app/src/main/java/me/yluo/ruisiapp/adapter/MyBlogListAdapter.java new file mode 100644 index 00000000..46929672 --- /dev/null +++ b/app/src/main/java/me/yluo/ruisiapp/adapter/MyBlogListAdapter.java @@ -0,0 +1,88 @@ +package me.yluo.ruisiapp.adapter; + +import android.app.Activity; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +import me.yluo.ruisiapp.R; +import me.yluo.ruisiapp.listener.ListItemClickListener; +import me.yluo.ruisiapp.model.BlogData; + +/** + * @author yang + */ +public class MyBlogListAdapter extends BaseAdapter { + + private List datas = new ArrayList<>(); + private final Activity activity; + private ListItemClickListener clickListener; + + public MyBlogListAdapter(Activity activity, List datas) { + this.datas = datas; + this.activity = activity; + } + + public void setClickListener(ListItemClickListener clickListener) { + this.clickListener = clickListener; + } + + @Override + protected int getDataCount() { + return datas.size(); + } + + @Override + protected int getItemType(int pos) { + return 0; + } + + + @Override + protected BaseViewHolder getItemViewHolder(ViewGroup parent, int viewType) { + return new MyPostsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_my_blog_list, parent, false)); + } + + + private class MyPostsViewHolder extends BaseViewHolder { + protected TextView title, content, postTime, viewCount, replyCount; + + MyPostsViewHolder(View itemView) { + super(itemView); + title = itemView.findViewById(R.id.title); + content = itemView.findViewById(R.id.content); + postTime = itemView.findViewById(R.id.post_time); + viewCount = itemView.findViewById(R.id.view_count); + replyCount = itemView.findViewById(R.id.reply_count); + + + itemView.findViewById(R.id.item_root).setOnClickListener(v -> { + if (clickListener != null) { + clickListener.onListItemClick(v, getAdapterPosition()); + } else { + itemClick(); + } + }); + } + + @Override + void setData(int position) { + BlogData data = datas.get(position); + title.setText(data.getTitle()); + content.setText(data.getContent()); + postTime.setText("\uf017 " + data.getPostTime()); + viewCount.setText("\uf06e " + data.getViewCount()); + replyCount.setText("\uf0e6 " + data.getReplyCount()); + } + + void itemClick() { + BlogData d = datas.get(getAdapterPosition()); + Integer blogId = d.getId(); + //BlogActivity.open(activity, d); + } + } +} diff --git a/app/src/main/java/me/yluo/ruisiapp/fragment/FragSetting.java b/app/src/main/java/me/yluo/ruisiapp/fragment/FragSetting.java index 3f5a76b9..168c2b4d 100644 --- a/app/src/main/java/me/yluo/ruisiapp/fragment/FragSetting.java +++ b/app/src/main/java/me/yluo/ruisiapp/fragment/FragSetting.java @@ -10,7 +10,6 @@ import androidx.appcompat.app.AlertDialog; import androidx.preference.EditTextPreference; -import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; @@ -34,8 +33,6 @@ public class FragSetting extends PreferenceFragmentCompat //小尾巴string private EditTextPreference settingUserTail; - //论坛地址 - private ListPreference settingForumsUrl; private SharedPreferences sharedPreferences; private Preference clearCache; @@ -46,14 +43,11 @@ public void onCreate(final Bundle savedInstanceState) { addPreferencesFromResource(R.xml.setting); settingUserTail = findPreference("setting_user_tail"); - settingForumsUrl = findPreference("setting_forums_url"); clearCache = findPreference("clean_cache"); sharedPreferences = getPreferenceScreen().getSharedPreferences(); boolean b = sharedPreferences.getBoolean("setting_show_tail", false); settingUserTail.setEnabled(b); settingUserTail.setSummary(sharedPreferences.getString("setting_user_tail", "无小尾巴")); - settingForumsUrl.setSummary(App.IS_SCHOOL_NET ? "当前网络校园网,点击切换" : "当前网络校外网,点击切换"); - settingForumsUrl.setValue(App.IS_SCHOOL_NET ? "1" : "2"); sharedPreferences.registerOnSharedPreferenceChangeListener(this); PackageManager manager; @@ -151,22 +145,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { switch (key) { - case "settingForumsUrl": - switch (sharedPreferences.getString("setting_forums_url", "2")) { - case "1": - settingForumsUrl.setSummary("当前网络校园网,点击切换"); - Toast.makeText(getActivity(), "切换到校园网!", Toast.LENGTH_SHORT).show(); - App.IS_SCHOOL_NET = true; - break; - case "2": - settingForumsUrl.setSummary("当前网络校外网,点击切换"); - Toast.makeText(getActivity(), "切换到外网!", Toast.LENGTH_SHORT).show(); - App.IS_SCHOOL_NET = false; - break; - default: - break; - } - break; case "setting_show_tail": boolean b = sharedPreferences.getBoolean("setting_show_tail", false); settingUserTail.setEnabled(b); diff --git a/app/src/main/java/me/yluo/ruisiapp/fragment/FrageMyBlog.java b/app/src/main/java/me/yluo/ruisiapp/fragment/FrageMyBlog.java new file mode 100644 index 00000000..773cb3e5 --- /dev/null +++ b/app/src/main/java/me/yluo/ruisiapp/fragment/FrageMyBlog.java @@ -0,0 +1,181 @@ +package me.yluo.ruisiapp.fragment; + +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.util.ArrayList; +import java.util.List; + +import me.yluo.ruisiapp.App; +import me.yluo.ruisiapp.R; +import me.yluo.ruisiapp.adapter.BaseAdapter; +import me.yluo.ruisiapp.adapter.MyBlogListAdapter; +import me.yluo.ruisiapp.listener.LoadMoreListener; +import me.yluo.ruisiapp.model.BlogData; +import me.yluo.ruisiapp.myhttp.HttpUtil; +import me.yluo.ruisiapp.myhttp.ResponseHandler; +import me.yluo.ruisiapp.utils.GetId; +import me.yluo.ruisiapp.widget.MyListDivider; + +/** + * Created by yang on 21-4-10. + * 我的日志 + * TODO 子分类tab + */ +public class FrageMyBlog extends BaseFragment implements LoadMoreListener.OnLoadMoreListener { + + private List datas; + private MyBlogListAdapter adapter; + private int currentPage = 1; + private boolean isEnableLoadMore = true; + private boolean isHaveMore = true; + private String title = ""; + + private String url; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + super.onCreateView(inflater, container, savedInstanceState); + Bundle bundle = getArguments();//从activity传过来的Bundle + int uid = 0; + if (bundle != null) { + uid = bundle.getInt("uid", 0); + String username = bundle.getString("username", "我的"); + if (uid == 0) { + title = "我的日志"; + } else { + title = username + "的日志"; + } + } + initToolbar(true, title); + RecyclerView recyclerView = mRootView.findViewById(R.id.recycler_view); + //recyclerView.setHasFixedSize(true); + SwipeRefreshLayout refreshLayout = mRootView.findViewById(R.id.refresh_layout); + refreshLayout.setEnabled(false); + String myUid = App.getUid(getActivity()); + + url = "home.php?mod=space&uid=" + (uid > 0 ? uid : myUid) + "&do=blog&view=me"; + datas = new ArrayList<>(); + adapter = new MyBlogListAdapter(getActivity(), datas); + + LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); + recyclerView.addItemDecoration(new MyListDivider(getActivity(), MyListDivider.VERTICAL)); + recyclerView.addOnScrollListener(new LoadMoreListener(layoutManager, this, 8)); + recyclerView.setLayoutManager(layoutManager); + recyclerView.setAdapter(adapter); + refresh(); + return mRootView; + } + + @Override + protected int getLayoutId() { + return R.layout.list_toolbar; + } + + + @Override + public void onLoadMore() { + if (isEnableLoadMore && isHaveMore) { + currentPage++; + getWebDatas(); + adapter.changeLoadMoreState(BaseAdapter.STATE_LOADING); + isEnableLoadMore = false; + } + } + + private void refresh() { + datas.clear(); + adapter.notifyDataSetChanged(); + getWebDatas(); + } + + + private void getWebDatas() { + String newurl = url + "&page=" + currentPage; + HttpUtil.get(newurl, new ResponseHandler() { + @Override + public void onSuccess(byte[] response) { + String res = new String(response); + new GetUserBlogs().execute(res); + } + + @Override + public void onFailure(Throwable e) { + e.printStackTrace(); + adapter.changeLoadMoreState(BaseAdapter.STATE_LOAD_FAIL); + } + }); + } + + + //获得主题 + private class GetUserBlogs extends AsyncTask> { + @Override + protected List doInBackground(String... strings) { + String res = strings[0]; + Log.i("=====", res); + List temp = new ArrayList<>(); + Elements lists = Jsoup.parse(res).select(".xld").select("dl.bbda"); + for (Element tmp : lists) { + Element title = tmp.select("dt.xs2").select("a[href*=do=blog]").last(); + if (title == null) { + continue; + } + + String titleText = title.text(); + Integer id = Integer.parseInt(GetId.getId("&id=", title.attr("href"))); + String content = tmp.select("dd[id^=blog_article]").text(); + + temp.add(new BlogData(id, titleText, content, "author", "2020", "1", "2")); + } + + if (temp.size() % 10 != 0) { + isHaveMore = false; + } + return temp; + } + + @Override + protected void onPostExecute(List aVoid) { + if (datas.size() == 0 && aVoid.size() == 0) { + adapter.setPlaceHolderText("暂无日志"); + } + onLoadCompete(aVoid); + } + + } + + //加载完成 + private void onLoadCompete(List d) { + if (isHaveMore && d.size() > 0) { + adapter.changeLoadMoreState(BaseAdapter.STATE_LOADING); + } else { + adapter.changeLoadMoreState(BaseAdapter.STATE_LOAD_NOTHING); + } + + if (d.size() > 0) { + int i = datas.size(); + datas.addAll(d); + if (i == 0) { + adapter.notifyDataSetChanged(); + } else { + adapter.notifyItemRangeInserted(i, d.size()); + } + } else if (datas.size() == 0) { + adapter.notifyDataSetChanged(); + } + isEnableLoadMore = true; + } +} diff --git a/app/src/main/java/me/yluo/ruisiapp/fragment/FragmentMy.java b/app/src/main/java/me/yluo/ruisiapp/fragment/FragmentMy.java index 5489be90..da976183 100644 --- a/app/src/main/java/me/yluo/ruisiapp/fragment/FragmentMy.java +++ b/app/src/main/java/me/yluo/ruisiapp/fragment/FragmentMy.java @@ -50,7 +50,7 @@ public class FragmentMy extends BaseLazyFragment implements View.OnClickListener private boolean isLoginLast = false; private final int[] icons = new int[]{ - R.drawable.ic_autorenew_black_24dp, + R.drawable.ic_baseline_calendar_today_24, R.drawable.ic_palette_black_24dp, R.drawable.ic_settings_24dp, R.drawable.ic_info_24dp, diff --git a/app/src/main/java/me/yluo/ruisiapp/listener/LoadMoreListener.java b/app/src/main/java/me/yluo/ruisiapp/listener/LoadMoreListener.java index b9258e46..e2f199ee 100644 --- a/app/src/main/java/me/yluo/ruisiapp/listener/LoadMoreListener.java +++ b/app/src/main/java/me/yluo/ruisiapp/listener/LoadMoreListener.java @@ -18,9 +18,10 @@ public LoadMoreListener(@NonNull LinearLayoutManager linearLayoutManager, @NonNu } @Override - public void onScrollStateChanged(RecyclerView recyclerView, int newState) { + public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) { //-1最后 -2 倒数第二 - if (linearLayoutManager.findLastVisibleItemPosition() > limit && linearLayoutManager.findLastVisibleItemPosition() == linearLayoutManager.getItemCount() - 1) { + int lastVisiblePosition = linearLayoutManager.findLastVisibleItemPosition(); + if (lastVisiblePosition > limit && lastVisiblePosition == linearLayoutManager.getItemCount() - 1) { onLoadMoreListener.onLoadMore(); } } diff --git a/app/src/main/java/me/yluo/ruisiapp/model/BlogData.java b/app/src/main/java/me/yluo/ruisiapp/model/BlogData.java new file mode 100644 index 00000000..98de5341 --- /dev/null +++ b/app/src/main/java/me/yluo/ruisiapp/model/BlogData.java @@ -0,0 +1,84 @@ +package me.yluo.ruisiapp.model; + +public class BlogData { + + private Integer id; + + private String title; + + private String content; + + private String author; + + private String postTime; + + private String viewCount; + + private String replyCount; + + public BlogData(Integer id, String title, String content, String author, String postTime, String viewCount, String replyCount) { + this.id = id; + this.title = title; + this.content = content; + this.author = author; + this.postTime = postTime; + this.viewCount = viewCount; + this.replyCount = replyCount; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getPostTime() { + return postTime; + } + + public void setPostTime(String postTime) { + this.postTime = postTime; + } + + public String getViewCount() { + return viewCount; + } + + public void setViewCount(String viewCount) { + this.viewCount = viewCount; + } + + public String getReplyCount() { + return replyCount; + } + + public void setReplyCount(String replyCount) { + this.replyCount = replyCount; + } +} diff --git a/app/src/main/java/me/yluo/ruisiapp/model/FrageType.java b/app/src/main/java/me/yluo/ruisiapp/model/FrageType.java index f68bc315..3ec43e6a 100644 --- a/app/src/main/java/me/yluo/ruisiapp/model/FrageType.java +++ b/app/src/main/java/me/yluo/ruisiapp/model/FrageType.java @@ -15,4 +15,5 @@ public class FrageType { public static final int HISTORY = 6; public static final int HELP = 7; public static final int TOPIC = 8; + public static final int BLOG = 9; } diff --git a/app/src/main/res/drawable/ic_baseline_calendar_today_24.xml b/app/src/main/res/drawable/ic_baseline_calendar_today_24.xml new file mode 100644 index 00000000..1cf969c7 --- /dev/null +++ b/app/src/main/res/drawable/ic_baseline_calendar_today_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/app/src/main/res/layout/item_my_blog_list.xml b/app/src/main/res/layout/item_my_blog_list.xml new file mode 100644 index 00000000..480896f0 --- /dev/null +++ b/app/src/main/res/layout/item_my_blog_list.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 4c56cfc0..857e193f 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -1,14 +1,5 @@ - - 内网,校园网环境可使用 - 外网,校园网,外网下使用 - - - 1 - 2 - - 1号 2号 diff --git a/app/src/main/res/xml/setting.xml b/app/src/main/res/xml/setting.xml index 95bdd85f..d5a60217 100644 --- a/app/src/main/res/xml/setting.xml +++ b/app/src/main/res/xml/setting.xml @@ -1,12 +1,5 @@ - -