Skip to content

Commit

Permalink
fix npe add blog support
Browse files Browse the repository at this point in the history
  • Loading branch information
freedom10086 committed Apr 13, 2021
1 parent 091e27f commit f06e6b3
Show file tree
Hide file tree
Showing 16 changed files with 490 additions and 48 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/me/yluo/ruisiapp/activity/PostActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
13 changes: 12 additions & 1 deletion app/src/main/java/me/yluo/ruisiapp/activity/PostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down Expand Up @@ -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();
Expand Down
88 changes: 88 additions & 0 deletions app/src/main/java/me/yluo/ruisiapp/adapter/MyBlogListAdapter.java
Original file line number Diff line number Diff line change
@@ -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<BlogData> datas = new ArrayList<>();
private final Activity activity;
private ListItemClickListener clickListener;

public MyBlogListAdapter(Activity activity, List<BlogData> 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);
}
}
}
22 changes: 0 additions & 22 deletions app/src/main/java/me/yluo/ruisiapp/fragment/FragSetting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -34,8 +33,6 @@ public class FragSetting extends PreferenceFragmentCompat

//小尾巴string
private EditTextPreference settingUserTail;
//论坛地址
private ListPreference settingForumsUrl;
private SharedPreferences sharedPreferences;
private Preference clearCache;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit f06e6b3

Please sign in to comment.