Skip to content

Commit

Permalink
fix no bbs found bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kidozh committed May 17, 2020
1 parent bd9fb22 commit d2e86ce
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 37 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/kidozh/discuzhub/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ private void bindForumData(){
localBBSViewModel.getBBSInformation().observe(this, new Observer<List<bbsInformation>>() {
@Override
public void onChanged(List<bbsInformation> bbsInformations) {
Log.d(TAG,"bbs information changed!");
Log.d(TAG,"bbs information changed! " +bbsInformations+" "+ bbsInformations.size());
adapter.setBbsInformationList(bbsInformations);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new forumSwipeToDeleteCallback(adapter));
itemTouchHelper.attachToRecyclerView(mForumInfoRecyclerview);
if(adapter.getBbsInformationList()==null || adapter.getBbsInformationList().size()==0){
if(bbsInformations ==null || bbsInformations.size()==0){
emptyView.setVisibility(View.VISIBLE);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ public void onClick(View view) {
public void addTypeChipToChipGroup(String typeId, String name){
choiceChipInfoList.add(new ChoiceChipInfo(bbsURLUtils.FILTER_TYPE_ID,name,typeId));
Chip chip = (Chip) getLayoutInflater().inflate(R.layout.layout_chip_choice,mForumThreadTypeChipGroup,false);
chip.setText(name);
Spanned threadSpanned = Html.fromHtml(name);
SpannableString threadSpannableString = new SpannableString(threadSpanned);
chip.setText(threadSpannableString);
chip.setClickable(true);
mForumThreadTypeChipGroup.addView(chip);
ChoiceResList.add(chip.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ private void initThreadStatus(){
threadDetailViewModel.threadStatusMutableLiveData.setValue(threadStatus);
}

private boolean checkWithPerm(int status, int perm){
return (status & perm) != 0;
}

private void configureSmileyLayout(){
handler = new EmotionInputHandler(mCommentEditText, (enable, s) -> {

Expand All @@ -210,7 +214,7 @@ private void bindViewModel(){
@Override
public void onChanged(forumUserBriefInfo userBriefInfo) {
Log.d(TAG,"User info "+userBriefInfo);
if(userBriefInfo == null){
if(userBriefInfo == null || userBriefInfo.auth == null){
mCommentConstraintLayout.setVisibility(View.GONE);
}
else{
Expand Down Expand Up @@ -405,9 +409,6 @@ public void onChanged(bbsParseUtils.DetailedThreadInfo detailedThreadInfo) {
);
}




// need another
if(!detailedThreadInfo.highlight.equals("0")){
threadPropertyList.add(
Expand Down Expand Up @@ -458,6 +459,36 @@ public void onChanged(bbsParseUtils.DetailedThreadInfo detailedThreadInfo) {
);
}

int status = detailedThreadInfo.status;
// check with perm
final int STATUS_CACHE_THREAD_LOCATION = 1, STATUS_ONLY_SEE_BY_POSTER = 2,
STATUS_REWARD_LOTTO = 4, STATUS_DESCEND_REPLY = 8, STATUS_EXIST_ICON = 16,
STATUS_NOTIFY_AUTHOR = 32;
if(checkWithPerm(status,STATUS_CACHE_THREAD_LOCATION)){
threadPropertyList.add(
new bbsThreadNotificationAdapter.threadNotification(R.drawable.ic_cache_thread_location_24px,
getString(R.string.thread_cache_location),getColor(R.color.colorMidnightblue))
);
}
if(checkWithPerm(status,STATUS_ONLY_SEE_BY_POSTER)){
threadPropertyList.add(
new bbsThreadNotificationAdapter.threadNotification(R.drawable.ic_reply_only_see_by_poster_24px,
getString(R.string.thread_reply_only_see_by_poster),getColor(R.color.colorNephritis))
);
}
if(checkWithPerm(status,STATUS_REWARD_LOTTO)){
threadPropertyList.add(
new bbsThreadNotificationAdapter.threadNotification(R.drawable.ic_thread_reward_lotto_24px,
getString(R.string.thread_reward_lotto),getColor(R.color.colorSunflower))
);
}
if(checkWithPerm(status,STATUS_NOTIFY_AUTHOR)){
threadPropertyList.add(
new bbsThreadNotificationAdapter.threadNotification(R.drawable.ic_thread_notify_author_24px,
getString(R.string.thread_notify_author),getColor(R.color.colorPrimaryDark))
);
}



notificationAdapter.setThreadNotificationList(threadNotificationList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public class showPersonalInfoActivity extends AppCompatActivity implements userF
bbsInformation curBBS;
forumUserBriefInfo curUser;
forumUserBriefInfo userBriefInfo;
private String userId;
private int userId;
OkHttpClient client;
String friendNum, threadNum, postsNum;
String username;
Expand Down Expand Up @@ -165,8 +165,8 @@ void configurePMBtn(){
personalInfoPMBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bbsParseUtils.privateMessage privateM = new bbsParseUtils.privateMessage(Integer.parseInt(userId),
false,"",Integer.parseInt(userId),1,1,
bbsParseUtils.privateMessage privateM = new bbsParseUtils.privateMessage(userId,
false,"",userId,1,1,
username,"",username,""
);
Intent intent = new Intent(getApplicationContext(), bbsPrivateMessageDetailActivity.class);
Expand All @@ -182,15 +182,15 @@ public void onClick(View v) {
void configureActionBar(){

getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setSubtitle(userId);
getSupportActionBar().setSubtitle(String.valueOf(userId));
}

private void getIntentInfo(){
Intent intent = getIntent();
curBBS = (bbsInformation) intent.getSerializableExtra(bbsConstUtils.PASS_BBS_ENTITY_KEY);
curUser = (forumUserBriefInfo) intent.getSerializableExtra(bbsConstUtils.PASS_BBS_USER_KEY);
userBriefInfo = (forumUserBriefInfo) intent.getSerializableExtra(bbsConstUtils.PASS_BBS_USER_KEY);
userId = intent.getStringExtra("UID");
userId = intent.getIntExtra("UID",0);
if(curBBS == null){
finishAfterTransition();
}
Expand All @@ -203,7 +203,7 @@ private void getIntentInfo(){
getSupportActionBar().setTitle(curBBS.site_name);
}
client = networkUtils.getPreferredClientWithCookieJarByUser(this,userBriefInfo);
if(userId !=null && userBriefInfo!=null && userId.equals(String.valueOf(userBriefInfo.uid))){
if(userBriefInfo!=null && userId == Integer.parseInt(userBriefInfo.uid)){
personalInfoFollowBtn.setVisibility(View.GONE);
personalInfoPMBtn.setVisibility(View.GONE);
}
Expand All @@ -221,7 +221,7 @@ void setIconAndTextView(String inputtedString, ImageView iconView, TextView text
}

void getUserInfo(){
String apiStr = bbsURLUtils.getProfileApiUrlByUid(Integer.parseInt(userId));
String apiStr = bbsURLUtils.getProfileApiUrlByUid(userId);
Request request = new Request.Builder()
.url(apiStr)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ public static userFriendFragment newInstance(String uid) {
return fragment;
}

public static userFriendFragment newInstance(int uid) {
userFriendFragment fragment = new userFriendFragment();
Bundle args = new Bundle();
args.putString(UID,String.valueOf(uid));
fragment.setArguments(args);
return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public bbsForumThreadAdapter.bbsForumThreadViewHolder onCreateViewHolder(@NonNul
@Override
public void onBindViewHolder(@NonNull bbsForumThreadAdapter.bbsForumThreadViewHolder holder, int position) {
ThreadInfo threadInfo = threadInfoList.get(position);
holder.mThreadPublisher.setText(threadInfo.author);

holder.mContent.setVisibility(View.GONE);
Spanned sp = Html.fromHtml(threadInfo.subject);
SpannableString spannableString = new SpannableString(sp);
Expand Down Expand Up @@ -150,11 +150,24 @@ public void onBindViewHolder(@NonNull bbsForumThreadAdapter.bbsForumThreadViewHo
holder.mThreadType.setText(String.format("%s",position+1));
}
else {
holder.mThreadType.setText(threadType.get(String.valueOf(threadInfo.typeId)));
// provided by label
String type = threadType.get(String.valueOf(threadInfo.typeId));
Log.d(TAG, "Get thread type "+type);
if(type !=null){
Spanned threadSpanned = Html.fromHtml(type);
SpannableString threadSpannableString = new SpannableString(threadSpanned);
holder.mThreadType.setText(threadSpannableString);
}
else {
holder.mThreadType.setText(String.format("%s",position+1));
}

}

holder.mThreadType.setBackgroundColor(mContext.getColor(R.color.colorPrimary));
}

holder.mThreadPublisher.setText(threadInfo.author);
int avatar_num = position % 16;

int avatarResource = mContext.getResources().getIdentifier(String.format("avatar_%s",avatar_num+1),"drawable",mContext.getPackageName());
Expand Down Expand Up @@ -243,6 +256,9 @@ public void onBindViewHolder(@NonNull bbsForumThreadAdapter.bbsForumThreadViewHo
holder.mReplyRecyclerview.setAdapter(adapter);
holder.mReplyRecyclerview.setNestedScrollingEnabled(false);
}
else {

}

holder.mCardview.setOnClickListener(new View.OnClickListener(){

Expand Down Expand Up @@ -271,13 +287,8 @@ public void onClick(View v) {
Intent intent = new Intent(mContext, showPersonalInfoActivity.class);
intent.putExtra(bbsConstUtils.PASS_BBS_ENTITY_KEY,bbsInfo);
intent.putExtra(bbsConstUtils.PASS_BBS_USER_KEY,curUser);

intent.putExtra("UID",threadInfo.authorId);

// ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(
// mContext, Pair.create(holder.mAvatarImageview, "user_info_avatar")
// );

ActivityOptions options = ActivityOptions
.makeSceneTransitionAnimation((Activity) mContext, holder.mAvatarImageview, "user_info_avatar");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onBindViewHolder(@NonNull bbsThreadPropertiesAdapter.bbsThreadProper
holder.itemThreadTypeTextview.setText(notification.typeString);
holder.itemThreadTypeTextview.setTextColor(notification.highlightColorRes);
holder.itemThreadTypeCardview.setBackgroundColor(notification.highlightColorRes);
holder.itemThreadTypeCardview.getBackground().setAlpha(20);
holder.itemThreadTypeCardview.getBackground().setAlpha(25);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ public List<bbsInformation> getBbsInformationList() {
@NonNull
@Override
public forumInformationAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
Log.d(TAG,"BBS info "+bbsInformationList);
if(bbsInformationList!=null && bbsInformationList.size()!=0){
return new ViewHolder(LayoutInflater.from(context).inflate(R.layout.item_forum_information,parent,false));
}
else {
return new EmptyViewHolder(LayoutInflater.from(context).inflate(R.layout.item_forum_information,parent,false));
return new EmptyViewHolder(LayoutInflater.from(context).inflate(R.layout.content_empty_bbs_information,parent,false));
}

}
Expand All @@ -90,8 +91,8 @@ public void setBbsInformationList(List<bbsInformation> bbsInformationList) {

@Override
public void onBindViewHolder(@NonNull forumInformationAdapter.ViewHolder holder, int position) {
if(bbsInformationList!=null && bbsInformationList.size()!=0){

if(bbsInformationList == null || bbsInformationList.size() == 0){
return;
}
bbsInformation forumInfo = bbsInformationList.get(position);

Expand Down Expand Up @@ -266,7 +267,7 @@ public void onClick(DialogInterface dialog, int which) {

@Override
public int getItemCount() {
if (bbsInformationList == null){
if (bbsInformationList == null || bbsInformationList.size() == 0){
return 0;
}
else {
Expand Down Expand Up @@ -303,10 +304,6 @@ public void undoDelete(bbsInformation deletedForumInfo, int position) {
bbsInformationList.add(position,deletedForumInfo);
notifyDataSetChanged();
new MainActivity.addNewForumInformationTask(deletedForumInfo, context).execute();

// mListItems.add(mRecentlyDeletedItemPosition,
// mRecentlyDeletedItem);
// notifyItemInserted(mRecentlyDeletedItemPosition);
}

static class ViewHolder extends RecyclerView.ViewHolder{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
Expand Down Expand Up @@ -86,7 +87,9 @@ public static class SubForumInfo implements Serializable{
public static class ThreadTypeInfo implements Serializable{
@JsonFormat(shape = JsonFormat.Shape.STRING)
@JsonDeserialize(using = OneZeroBooleanJsonDeserializer.class)
public boolean required, listable, prefix;
@JsonInclude(JsonInclude.Include.NON_NULL)
public boolean required = false, listable = false;
public String prefix;
@JsonProperty("types")
@JsonDeserialize(using = ForumThreadTypeDeserializer.class)
public Map<String, String> idNameMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ public static String getDefaultAvatarUrlByUid(String uid){
return UC_SERVER_URL+String.format("/avatar.php?uid=%s",uid);
}

public static String getDefaultAvatarUrlByUid(int uid){
return UC_SERVER_URL+String.format("/avatar.php?uid=%s",uid);
}

// public static String getLoginUrl(){
// return BASE_URL + "/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1";
// //return "https://bbs.nwpu.edu.cn/member.php?mod=logging&action=login&loginsubmit=yes&infloat=yes&lssubmit=yes&inajax=1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void onFailure(Call call, IOException e) {

@Override
public void onResponse(Call call, Response response) throws IOException {
isLoading.postValue(false);

if(response.isSuccessful() && response.body()!=null){
String s = response.body().string();
int totalThreadSize = 0;
Expand Down Expand Up @@ -215,6 +215,7 @@ public void onResponse(Call call, Response response) throws IOException {
threadStatusMutableLiveData.postValue(threadStatus);
}
}
isLoading.postValue(false);
}
});
}
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_cache_thread_location_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/colorMidnightblue" android:pathData="M17,3L5,3c-1.11,0 -2,0.9 -2,2v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2L21,7l-4,-4zM19,19L5,19L5,5h11.17L19,7.83L19,19zM12,12c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3zM6,6h9v4L6,10z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/colorNephritis" android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2L8.9,8L8.9,6zM18,20L6,20L6,10h12v10zM13,11h-2v3L8,14v2h3v3h2v-3h3v-2h-3z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_thread_notify_author_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/colorPrimaryDark" android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.9,2 2,2zM18,16v-5c0,-3.07 -1.63,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.64,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2zM16,17L8,17v-6c0,-2.48 1.51,-4.5 4,-4.5s4,2.02 4,4.5v6zM7.58,4.08L6.15,2.65C3.75,4.48 2.17,7.3 2.03,10.5h2c0.15,-2.65 1.51,-4.97 3.55,-6.42zM19.97,10.5h2c-0.15,-3.2 -1.73,-6.02 -4.12,-7.85l-1.42,1.43c2.02,1.45 3.39,3.77 3.54,6.42z"/>
</vector>
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/ic_thread_reward_lotto_24px.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@color/colorSunflower" android:pathData="M20,6h-2.18c0.11,-0.31 0.18,-0.65 0.18,-1 0,-1.66 -1.34,-3 -3,-3 -1.05,0 -1.96,0.54 -2.5,1.35l-0.5,0.67 -0.5,-0.68C10.96,2.54 10.05,2 9,2 7.34,2 6,3.34 6,5c0,0.35 0.07,0.69 0.18,1L4,6c-1.11,0 -1.99,0.89 -1.99,2L2,19c0,1.11 0.89,2 2,2h16c1.11,0 2,-0.89 2,-2L22,8c0,-1.11 -0.89,-2 -2,-2zM15,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM9,4c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM20,19L4,19v-2h16v2zM20,14L4,14L4,8h5.08L7,10.83 8.62,12 12,7.4l3.38,4.6L17,10.83 14.92,8L20,8v6z"/>
</vector>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="5"
tools:itemCount="0"
tools:listitem="@layout/item_forum_information">

</androidx.recyclerview.widget.RecyclerView>

<include
android:id="@+id/forum_information_emptyview"
layout="@layout/content_empty_bbs_information"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="@+id/forum_information_recyclerview"
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/item_bbs_thread_type.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

<ImageView
android:id="@+id/item_bbs_thread_type_avatar"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -38,7 +38,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:lines="2"
android:singleLine="true"
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down
Loading

0 comments on commit d2e86ce

Please sign in to comment.