Skip to content

Commit

Permalink
update UI
Browse files Browse the repository at this point in the history
  • Loading branch information
iMeiji committed Jun 2, 2017
1 parent e2f09e2 commit 3d206e9
Show file tree
Hide file tree
Showing 30 changed files with 144 additions and 155 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ android {
release {
// Properties props = new Properties()
// props.load(new FileInputStream(file("/sign/sign.properties")))
// 变量在 Travis CI 后台设置好
keyAlias System.getenv("KEY_ALIAS")
keyPassword System.getenv("KEY_PASSWORD")
storeFile file("../KeyStore.jks")
storePassword System.getenv("STORE_PASSWORD")
}
debug {
// 部分第三方SDK要绑定签名, 故使用 release 的签名, 方便测试
// 使用 try catch 是防止 Travis CI 打包失败
try {
Properties props = new Properties()
props.load(new FileInputStream(file("/sign/sign.properties")))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.meiji.toutiao.adapter.news.joke;
package com.meiji.toutiao.adapter.joke;

import android.content.Context;
import android.graphics.PorterDuff;
Expand All @@ -14,6 +14,7 @@

import com.meiji.toutiao.R;
import com.meiji.toutiao.bean.joke.JokeCommentBean;
import com.meiji.toutiao.bean.joke.JokeContentBean;
import com.meiji.toutiao.interfaces.IOnItemClickListener;
import com.meiji.toutiao.utils.ImageLoader;
import com.meiji.toutiao.utils.SettingsUtil;
Expand All @@ -28,9 +29,12 @@

public class JokeCommentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private static final int TYPE_NORMAL = 0;
private static final int TYPE_FOOTER = 1;
private static final int TYPE_HEADER = 0;
private static final int TYPE_NORMAL = 1;
private static final int TYPE_FOOTER = 2;

private List<JokeCommentBean.DataBean.RecentCommentsBean> list;
private JokeContentBean.DataBean.GroupBean bean;
private Context context;
private IOnItemClickListener onItemClickListener;

Expand All @@ -50,8 +54,15 @@ public void setOnItemClickListener(IOnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}

public void setBean(JokeContentBean.DataBean.GroupBean bean) {
this.bean = bean;
}

@Override
public int getItemViewType(int position) {
if (position == 0) {
return TYPE_HEADER;
}
if (position == list.size()) {
return TYPE_FOOTER;
}
Expand All @@ -60,6 +71,10 @@ public int getItemViewType(int position) {

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HEADER) {
View view = LayoutInflater.from(context).inflate(R.layout.item_news_joke, parent, false);
return new JokeHeaderViewHolder(view, onItemClickListener);
}
if (viewType == TYPE_NORMAL) {
View view = LayoutInflater.from(context).inflate(R.layout.item_news_joke_comment, parent, false);
return new JokeCommentViewHolder(view, onItemClickListener);
Expand Down Expand Up @@ -89,6 +104,26 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
jokeViewHolder.tv_text.setText(tv_text);
jokeViewHolder.tv_likes.setText(tv_likes);
}

if (holder instanceof JokeHeaderViewHolder) {
JokeHeaderViewHolder viewHolder = (JokeHeaderViewHolder) holder;


String avatar_url = bean.getUser().getAvatar_url();
String name = bean.getUser().getName();
String text = bean.getText();
String digg_count = bean.getDigg_count() + "";
String bury_count = bean.getBury_count() + "";
String comment_count = bean.getComment_count() + "评论";

ImageLoader.loadCenterCrop(context, avatar_url, viewHolder.iv_avatar, R.color.viewBackground);
viewHolder.tv_username.setText(name);
viewHolder.tv_text.setText(text);
viewHolder.tv_digg_count.setText(digg_count);
viewHolder.tv_bury_count.setText(bury_count);
viewHolder.tv_comment_count.setText(comment_count);

}
}

@Override
Expand Down Expand Up @@ -140,4 +175,33 @@ private class FooterViewHolder extends RecyclerView.ViewHolder {
}
}

private class JokeHeaderViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

private CircleImageView iv_avatar;
private TextView tv_username;
private TextView tv_text;
private TextView tv_digg_count;
private TextView tv_bury_count;
private TextView tv_comment_count;
private IOnItemClickListener onItemClickListener;

JokeHeaderViewHolder(View itemView, IOnItemClickListener onItemClickListener) {
super(itemView);
this.iv_avatar = (CircleImageView) itemView.findViewById(R.id.iv_avatar);
this.tv_username = (TextView) itemView.findViewById(R.id.tv_username);
this.tv_text = (TextView) itemView.findViewById(R.id.tv_text);
this.tv_digg_count = (TextView) itemView.findViewById(R.id.tv_digg_count);
this.tv_bury_count = (TextView) itemView.findViewById(R.id.tv_bury_count);
this.tv_comment_count = (TextView) itemView.findViewById(R.id.tv_comment_count);
this.onItemClickListener = onItemClickListener;
itemView.setOnClickListener(this);
}

@Override
public void onClick(View view) {
if (onItemClickListener != null) {
onItemClickListener.onClick(view, getLayoutPosition());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.meiji.toutiao.adapter.news.joke;
package com.meiji.toutiao.adapter.joke;

import android.content.Context;
import android.graphics.PorterDuff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public int getItemViewType(int position) {
if (position == list.size()) {
return TYPE_FOOTER;
}
if (list.get(position).getImage_list().size() < 1) {
return TYPE_NOIMAGE;
}
// if (list.get(position).getImage_list().size() < 1) {
// return TYPE_NOIMAGE;
// }
return TYPE_NORMAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void setComments(List<?> comments) {
}

public static class GroupBean implements Parcelable {

public static final Creator<GroupBean> CREATOR = new Creator<GroupBean>() {
@Override
public GroupBean createFromParcel(Parcel in) {
Expand Down Expand Up @@ -234,6 +235,7 @@ protected GroupBean(Parcel in) {
has_comments = in.readInt();
user_bury = in.readInt();
status_desc = in.readString();
user = in.readParcelable(UserBean.class.getClassLoader());
user_digg = in.readInt();
online_time = in.readInt();
category_name = in.readString();
Expand Down Expand Up @@ -271,6 +273,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(has_comments);
dest.writeInt(user_bury);
dest.writeString(status_desc);
dest.writeParcelable(user, flags);
dest.writeInt(user_digg);
dest.writeInt(online_time);
dest.writeString(category_name);
Expand Down Expand Up @@ -570,7 +573,18 @@ public void setCategory_id(int category_id) {
this.category_id = category_id;
}

public static class UserBean {
public static class UserBean implements Parcelable {
public static final Creator<UserBean> CREATOR = new Creator<UserBean>() {
@Override
public UserBean createFromParcel(Parcel in) {
return new UserBean(in);
}

@Override
public UserBean[] newArray(int size) {
return new UserBean[size];
}
};
/**
* is_following : false
* avatar_url : http://p3.pstatp.com/thumb/123200136e8a76748b9f
Expand All @@ -585,6 +599,28 @@ public static class UserBean {
private String name;
private boolean user_verified;

protected UserBean(Parcel in) {
is_following = in.readByte() != 0;
avatar_url = in.readString();
user_id = in.readLong();
name = in.readString();
user_verified = in.readByte() != 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (is_following ? 1 : 0));
dest.writeString(avatar_url);
dest.writeLong(user_id);
dest.writeString(name);
dest.writeByte((byte) (user_verified ? 1 : 0));
}

@Override
public int describeContents() {
return 0;
}

public boolean isIs_following() {
return is_following;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.os.Bundle;
import android.os.Parcelable;
import android.support.design.widget.BottomSheetDialog;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.util.DiffUtil;
Expand All @@ -18,11 +17,10 @@
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.meiji.toutiao.R;
import com.meiji.toutiao.adapter.DiffCallback;
import com.meiji.toutiao.adapter.news.joke.JokeCommentAdapter;
import com.meiji.toutiao.adapter.joke.JokeCommentAdapter;
import com.meiji.toutiao.bean.joke.JokeCommentBean;
import com.meiji.toutiao.bean.joke.JokeContentBean;
import com.meiji.toutiao.interfaces.IOnItemClickListener;
Expand All @@ -42,14 +40,11 @@ public class JokeCommentFragment extends BaseFragment<IJokeComment.Presenter> im
private String jokeCommentCount;
private String jokeText;
private boolean canLoading;

private TextView tv_content;
private RecyclerView recycler_view;
private SwipeRefreshLayout refresh_layout;
private JokeCommentAdapter adapter;

private IJokeComment.Presenter presenter;
private CollapsingToolbarLayout collapsing_toolbar;

public static JokeCommentFragment newInstance(Parcelable data) {
Bundle args = new Bundle();
Expand All @@ -63,7 +58,6 @@ public static JokeCommentFragment newInstance(Parcelable data) {
protected void initViews(View view) {
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
initToolBar(toolbar, true, "");
tv_content = (TextView) view.findViewById(R.id.tv_content);

recycler_view = (RecyclerView) view.findViewById(R.id.recycler_view);
recycler_view.setHasFixedSize(true);
Expand All @@ -79,8 +73,6 @@ public void onClick(View view) {
recycler_view.smoothScrollToPosition(0);
}
});
collapsing_toolbar = (CollapsingToolbarLayout) view.findViewById(R.id.collapsing_toolbar);
collapsing_toolbar.setBackgroundColor(SettingsUtil.getInstance().getColor());

adapter = new JokeCommentAdapter(getActivity());
recycler_view.setAdapter(adapter);
Expand All @@ -96,7 +88,7 @@ public void onClick(View view, int position) {

@Override
protected int attachLayoutId() {
return R.layout.fragment_news_joke_comment;
return R.layout.fragment_list_toolbar;
}

@Override
Expand All @@ -105,8 +97,8 @@ protected void initData() {
JokeContentBean.DataBean.GroupBean bean = bundle.getParcelable(TAG);
jokeId = bean.getId() + "";
jokeCommentCount = bean.getComment_count() + "";
adapter.setBean(bean);
jokeText = bean.getText();
tv_content.setText(jokeText);
onLoadData();
}

Expand All @@ -126,12 +118,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
.putExtra(Intent.EXTRA_TEXT, jokeText);
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_to)));
break;
case R.id.action_comment_copy:
ClipboardManager copy = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("text", jokeText);
copy.setPrimaryClip(clipData);
Snackbar.make(refresh_layout, R.string.copied_to_clipboard, Snackbar.LENGTH_SHORT).show();
break;
}
return super.onOptionsItemSelected(item);
}
Expand Down Expand Up @@ -172,7 +158,12 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
}

private void showCopyDialog(final int position) {
final String content = presenter.doGetCopyContent(position);
final String content;
if (position == 0) {
content = jokeText;
} else {
content = presenter.doGetCopyContent(position);
}

final BottomSheetDialog dialog = new BottomSheetDialog(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.item_comment_action_sheet, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import com.meiji.toutiao.R;
import com.meiji.toutiao.adapter.DiffCallback;
import com.meiji.toutiao.adapter.news.joke.JokeContentAdapter;
import com.meiji.toutiao.adapter.joke.JokeContentAdapter;
import com.meiji.toutiao.bean.joke.JokeContentBean;
import com.meiji.toutiao.interfaces.IOnItemClickListener;
import com.meiji.toutiao.module.base.LazyLoadFragment;
Expand All @@ -35,7 +35,7 @@ public static JokeContentView newInstance() {

@Override
protected int attachLayoutId() {
return R.layout.fragment_base_main;
return R.layout.fragment_list;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static NewsArticleView newInstance(String categoryId) {

@Override
protected int attachLayoutId() {
return R.layout.fragment_base_main;
return R.layout.fragment_list;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static MultiNewsArticleView newInstance(String categoryId) {

@Override
protected int attachLayoutId() {
return R.layout.fragment_base_main;
return R.layout.fragment_list;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static PhotoArticleView newInstance(String categoryId) {

@Override
protected int attachLayoutId() {
return R.layout.fragment_base_main;
return R.layout.fragment_list;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static SearchFragment newInstance(String query) {

@Override
protected int attachLayoutId() {
return R.layout.fragment_search;
return R.layout.fragment_list_toolbar;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static VideoArticleView newInstance(String categoryId) {

@Override
protected int attachLayoutId() {
return R.layout.fragment_base_main;
return R.layout.fragment_list;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void onLoadData() {

@Override
protected int attachLayoutId() {
return R.layout.fragment_base_main;
return R.layout.fragment_list;
}

@Override
Expand Down
Loading

0 comments on commit 3d206e9

Please sign in to comment.