Skip to content

Commit

Permalink
detail page ,something bad
Browse files Browse the repository at this point in the history
  • Loading branch information
Harlber committed Jul 30, 2015
1 parent 0d4d19c commit 1524bae
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 153 deletions.
57 changes: 27 additions & 30 deletions MDBilibili/app/src/main/java/me/qixingchen/mdbilibili/AppUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,36 @@
public class AppUtils {
public static void setTextWithLinks(TextView textView, String htmlText) {
setHtmlText(textView, htmlText);
textView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();

TextView widget = (TextView) v;
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();

x += widget.getScrollX();
y += widget.getScrollY();

Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);

ClickableSpan[] link = Spannable.Factory.getInstance()
.newSpannable(widget.getText())
.getSpans(off, off, ClickableSpan.class);

if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
}
return true;
textView.setOnTouchListener((v, event) -> {
int action = event.getAction();
if (action == MotionEvent.ACTION_UP ||
action == MotionEvent.ACTION_DOWN) {
int x = (int) event.getX();
int y = (int) event.getY();

TextView widget = (TextView) v;
x -= widget.getTotalPaddingLeft();
y -= widget.getTotalPaddingTop();

x += widget.getScrollX();
y += widget.getScrollY();

Layout layout = widget.getLayout();
int line = layout.getLineForVertical(y);
int off = layout.getOffsetForHorizontal(line, x);

ClickableSpan[] link = Spannable.Factory.getInstance()
.newSpannable(widget.getText())
.getSpans(off, off, ClickableSpan.class);

if (link.length != 0) {
if (action == MotionEvent.ACTION_UP) {
link[0].onClick(widget);
}
return true;
}
return false;
}
return false;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,48 @@
*/
public class CardAdapter extends RecyclerView.Adapter<BilibiliCardViewHolder> {

private Recommend recommend;
private ImageLoader mImageLoader;
private Context mContext;
private Recommend recommend;
private ImageLoader mImageLoader;
private Context mContext;

public CardAdapter(Recommend recommend, Context context) {
this.recommend = recommend;
mContext = context;
mImageLoader = GetVolley.getmInstance(mContext).getImageLoader();
}
public CardAdapter(Recommend recommend, Context context) {
this.recommend = recommend;
mContext = context;
mImageLoader = GetVolley.getmInstance(mContext).getImageLoader();
}

@Override
public BilibiliCardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.dast_bilibili_card_item, parent, false);
BilibiliCardViewHolder vh = new BilibiliCardViewHolder(v);
return vh;
}
@Override
public BilibiliCardViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.dast_bilibili_card_item, parent, false);
BilibiliCardViewHolder vh = new BilibiliCardViewHolder(v);
return vh;
}

@Override
public void onBindViewHolder(BilibiliCardViewHolder holder, final int position) {
holder.textView.setText(recommend.getLists().get(position).getTitle());
holder.imageView.setImageUrl(recommend.getLists().get(position).getPic(), mImageLoader);
holder.rootView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(BilibiliApplication.getApplication(),BilibiliDetail.class);
String url = String.valueOf(recommend.getLists().get(position).getPic());
String title = String.valueOf(recommend.getLists().get(position).getTitle());
String aid = String.valueOf(recommend.getLists().get(position).getAid());
intent.putExtra("IMG_URL", url);
intent.putExtra("TITLE", title);
intent.putExtra("AID", aid);
mContext.startActivity(intent);
}
});
}
@Override
public void onBindViewHolder(BilibiliCardViewHolder holder, final int position) {
holder.textView.setText(recommend.getLists().get(position).getTitle());
holder.imageView.setImageUrl(recommend.getLists().get(position).getPic(), mImageLoader);
holder.rootView.setOnClickListener(v -> {
Intent intent = new Intent(BilibiliApplication.getApplication(), BilibiliDetail.class);
String url = String.valueOf(recommend.getLists().get(position).getPic());
String title = String.valueOf(recommend.getLists().get(position).getTitle());
String aid = String.valueOf(recommend.getLists().get(position).getAid());
intent.putExtra("IMG_URL", url);
intent.putExtra("TITLE", title);
intent.putExtra("AID", aid);
mContext.startActivity(intent);
});
}

@Override
public int getItemCount() {
return recommend == null ? 0 : recommend.getLists().size();
}
@Override
public int getItemCount() {
return recommend == null ? 0 : recommend.getLists().size();
}

//刷新数据
public void notifyDateChanged(Recommend recommend) {
this.recommend = recommend;
this.notifyDataSetChanged();
}
//刷新数据
public void notifyDateChanged(Recommend recommend) {
this.recommend = recommend;
this.notifyDataSetChanged();
}
}
101 changes: 23 additions & 78 deletions MDBilibili/app/src/main/res/layout/dast_bilibili_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<LinearLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
Expand All @@ -74,117 +74,62 @@
android:id="@+id/aidTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:padding="8dp"
android:textColor="@color/md_black"
android:textSize="@dimen/small_title_size"
tools:text="AV1048898" />

<TextView
android:id="@+id/PlayTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/aidTextView"
android:layout_marginLeft="8dp"
android:textSize="@dimen/normal_text_size"
tools:text="55558" />

<TextView
android:id="@+id/reviewTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/aidTextView"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@id/PlayTextView"
android:textSize="@dimen/normal_text_size"
tools:text="55558" />

<TextView
android:id="@+id/video_reviewTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reviewTextView"
android:layout_marginLeft="8dp"
android:textSize="@dimen/normal_text_size"
tools:text="55558" />

<TextView
android:id="@+id/favoritesTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/reviewTextView"
android:layout_marginLeft="16dp"
android:layout_toRightOf="@id/video_reviewTextView"
android:textSize="@dimen/normal_text_size"
tools:text="55558" />

<android.support.v7.widget.CardView
<android.support.v4.view.ViewPager
android:id="@+id/detail_viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">

<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="妮可Nico"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sampledate" />

</LinearLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">

<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="妮可Nico"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sampledate" />

</LinearLayout>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">

<LinearLayout
style="@style/Widget.CardContent"
android:layout_height="match_parent">
<android.support.v4.view.PagerTabStrip
android:id="@+id/PagerTab"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="妮可Nico"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sampledate" />

</LinearLayout>

</android.support.v7.widget.CardView>
android:layout_height="wrap_content"
android:layout_gravity="top"/>
</android.support.v4.view.ViewPager>

</LinearLayout>
</RelativeLayout>

</android.support.v4.widget.NestedScrollView>

Expand Down
2 changes: 1 addition & 1 deletion MDBilibili/app/src/main/res/values-xhdpi/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dimen name="activity_vertical_margin">0dp</dimen>
<dimen name="tool_bar_top_padding">0dp</dimen>
<dimen name="normal_text_size">16sp</dimen>
<dimen name="small_title_size">20sp</dimen>
<dimen name="small_title_size">22sp</dimen>

<dimen name="detail_backdrop_height">256dp</dimen>
<dimen name="card_margin">16dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion MDBilibili/app/src/main/res/values-xxhdpi/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dimen name="activity_vertical_margin">0dp</dimen>
<dimen name="tool_bar_top_padding">0dp</dimen>
<dimen name="normal_text_size">16sp</dimen>
<dimen name="small_title_size">20sp</dimen>
<dimen name="small_title_size">22sp</dimen>

<dimen name="detail_backdrop_height">256dp</dimen>
<dimen name="card_margin">16dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion MDBilibili/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<dimen name="activity_vertical_margin">0dp</dimen>
<dimen name="tool_bar_top_padding">0dp</dimen>
<dimen name="normal_text_size">16sp</dimen>
<dimen name="small_title_size">20sp</dimen>
<dimen name="small_title_size">22sp</dimen>

<dimen name="detail_backdrop_height">256dp</dimen>
<dimen name="card_margin">16dp</dimen>
Expand Down

0 comments on commit 1524bae

Please sign in to comment.