Skip to content

Commit

Permalink
Modify Bangumi index interface UI and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
HotBitmapGG committed Oct 10, 2016
1 parent 08f6f2e commit 1526f0b
Show file tree
Hide file tree
Showing 29 changed files with 1,006 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.hotbitmapgg.ohmybilibili.R;
import com.hotbitmapgg.ohmybilibili.adapter.helper.AbsRecyclerViewAdapter;
import com.hotbitmapgg.ohmybilibili.entity.bangumi.BangumiIndex;
import com.hotbitmapgg.ohmybilibili.entity.bangumi.BangumiIndexTag;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -25,13 +24,13 @@
public class BangumiIndexAdapter extends AbsRecyclerViewAdapter
{

private List<BangumiIndex> bangumiIndexList = new ArrayList<>();
private List<BangumiIndexTag> bangumiIndexTags;

public BangumiIndexAdapter(RecyclerView recyclerView, List<BangumiIndex> bangumiIndexList)
public BangumiIndexAdapter(RecyclerView recyclerView, List<BangumiIndexTag> bangumiIndexTags)
{

super(recyclerView);
this.bangumiIndexList = bangumiIndexList;
this.bangumiIndexTags = bangumiIndexTags;
}

@Override
Expand All @@ -50,17 +49,17 @@ public void onBindViewHolder(ClickableViewHolder holder, int position)
if (holder instanceof ItemViewHolder)
{
ItemViewHolder itemViewHolder = (ItemViewHolder) holder;
BangumiIndex bangumiIndex = bangumiIndexList.get(position);
BangumiIndexTag bangumiIndexTag = bangumiIndexTags.get(position);

Glide.with(getContext())
.load(bangumiIndex.cover)
.load(bangumiIndexTag.getPic())
.centerCrop()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.bili_default_image_tv)
.dontAnimate()
.into(itemViewHolder.mImageView);

itemViewHolder.mTextView.setText(bangumiIndex.title);
itemViewHolder.mTextView.setText(bangumiIndexTag.getTitle());
}
super.onBindViewHolder(holder, position);
}
Expand All @@ -69,7 +68,7 @@ public void onBindViewHolder(ClickableViewHolder holder, int position)
public int getItemCount()
{

return bangumiIndexList.size();
return bangumiIndexTags.size();
}

public class ItemViewHolder extends AbsRecyclerViewAdapter.ClickableViewHolder
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.hotbitmapgg.ohmybilibili.entity.bangumi;

/**
* Created by hcc on 2016/10/10 19:57
* [email protected]
*/

public class BangumiIndexTag
{

private String pic;

private String title;

public String getPic()
{

return pic;
}

public void setPic(String pic)
{

this.pic = pic;
}

public String getTitle()
{

return title;
}

public void setTitle(String title)
{

this.title = title;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;

import com.hotbitmapgg.ohmybilibili.R;
import com.hotbitmapgg.ohmybilibili.adapter.BangumiIndexAdapter;
import com.hotbitmapgg.ohmybilibili.adapter.helper.HeaderViewRecyclerAdapter;
import com.hotbitmapgg.ohmybilibili.base.RxAppCompatBaseActivity;
import com.hotbitmapgg.ohmybilibili.entity.bangumi.BangumiIndex;
import com.hotbitmapgg.ohmybilibili.entity.bangumi.BangumiIndexTag;
import com.hotbitmapgg.ohmybilibili.network.RetrofitHelper;
import com.hotbitmapgg.ohmybilibili.widget.CircleProgressView;

Expand Down Expand Up @@ -41,11 +44,15 @@ public class BangumiIndexActivity extends RxAppCompatBaseActivity
@Bind(R.id.circle_progress)
CircleProgressView mCircleProgressView;

private String month = "4";
private List<BangumiIndexTag> bangumiIndexTags = new ArrayList<>();

private String year = "2016";
private HeaderViewRecyclerAdapter mHeaderViewRecyclerAdapter;

private List<BangumiIndex> bangumiIndexList = new ArrayList<>();
private GridLayoutManager mGridLayoutManager;

private List<BangumiIndex.ResultBean.CategoriesBean> categories;

private List<BangumiIndex.ResultBean.RecommendCategoryBean> recommendCategory;


@Override
Expand All @@ -59,12 +66,31 @@ public int getLayoutId()
public void initViews(Bundle savedInstanceState)
{

mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new GridLayoutManager(BangumiIndexActivity.this, 3));

getBangumiIndex();
}

private void initRecyclerView()
{

mRecyclerView.setHasFixedSize(true);
mGridLayoutManager = new GridLayoutManager(BangumiIndexActivity.this, 3);
mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup()
{

@Override
public int getSpanSize(int position)
{

return (0 == position) ? mGridLayoutManager.getSpanCount() : 1;
}
});
mRecyclerView.setLayoutManager(mGridLayoutManager);
BangumiIndexAdapter mAdapter = new BangumiIndexAdapter(mRecyclerView, bangumiIndexTags);
mHeaderViewRecyclerAdapter = new HeaderViewRecyclerAdapter(mAdapter);
createHeadLayout();
mRecyclerView.setAdapter(mHeaderViewRecyclerAdapter);
}

@Override
public void initToolBar()
{
Expand All @@ -90,21 +116,18 @@ public void getBangumiIndex()
{

RetrofitHelper.getBangumiIndexApi()
.getBangumiIndex(year, month)
.getBangumiIndex()
.compose(this.bindToLifecycle())
.doOnSubscribe(this::showProgressBar)
.subscribeOn(Schedulers.io())
.delay(2000, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(bangumiIndices -> {
.subscribe(bangumiIndex -> {

if (bangumiIndices != null)
{
bangumiIndexList.addAll(bangumiIndices);
finishTask();
}
categories = bangumiIndex.getResult().getCategories();
recommendCategory = bangumiIndex.getResult().getRecommendCategory();
finishTask();
}, throwable -> {

hideProgressBar();
});
}
Expand All @@ -127,8 +150,38 @@ private void hideProgressBar()
private void finishTask()
{

BangumiIndexAdapter mAdapter = new BangumiIndexAdapter(mRecyclerView, bangumiIndexList);
mRecyclerView.setAdapter(mAdapter);
mergerIndexTags();
initRecyclerView();
hideProgressBar();
}

private void mergerIndexTags()
{

BangumiIndexTag bangumiIndexTag;
for (int i = 0, size = categories.size(); i < size; i++)
{
BangumiIndex.ResultBean.CategoriesBean.CategoryBean category = categories.get(i).getCategory();
bangumiIndexTag = new BangumiIndexTag();
bangumiIndexTag.setPic(category.getCover());
bangumiIndexTag.setTitle(category.getTag_name());
bangumiIndexTags.add(bangumiIndexTag);
}

for (int i = 0, size = recommendCategory.size(); i < size; i++)
{
BangumiIndex.ResultBean.RecommendCategoryBean recommendCategoryBean = recommendCategory.get(i);
bangumiIndexTag = new BangumiIndexTag();
bangumiIndexTag.setPic(recommendCategoryBean.getCover());
bangumiIndexTag.setTitle(recommendCategoryBean.getTag_name());
bangumiIndexTags.add(bangumiIndexTag);
}
}

private void createHeadLayout()
{

View headView = LayoutInflater.from(this).inflate(R.layout.layout_bangumi_index_head, mRecyclerView, false);
mHeaderViewRecyclerAdapter.addHeaderView(headView);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static BangumiIndexService getBangumiIndexApi()
{

Retrofit retrofit = new Retrofit.Builder()
.baseUrl(MAIN_BASE_URL)
.baseUrl(BANGUMI_BASE_URL)
.client(mOkHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import com.hotbitmapgg.ohmybilibili.entity.bangumi.BangumiIndex;

import java.util.List;

import retrofit2.http.GET;
import retrofit2.http.Path;
import rx.Observable;

/**
* Created by hcc on 16/8/4 12:03
* [email protected]
* <p/>
* 番剧索引数据请求
* <p>
* http://bangumi.bilibili.com/api/app_index_page?actionKey=appkey&appkey=27eb53fc9058f8c3&build=2310&device=phone&platform=ios&sign=55c99772ca87ed4720201d2f0429d9c2&ts=1466676873
*/
public interface BangumiIndexService
{

@GET("index/bangumi/{year}-{month}.json")
Observable<List<BangumiIndex>> getBangumiIndex(@Path("year") String year, @Path("month") String month);
@GET("api/app_index_page?actionKey=appkey&appkey=27eb53fc9058f8c3&build=2310&device=phone&platform=ios&sign=55c99772ca87ed4720201d2f0429d9c2&ts=1466676873")
Observable<BangumiIndex> getBangumiIndex();
}
Binary file added app/src/main/res/drawable-hdpi/ic_bangumi_index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_bangumi_rank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_bangumi_index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_bangumi_rank.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/bangumi_index_green_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="3dp" />

<solid android:color="@color/bangumi_index_green_bg" />

</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/bangumi_index_yellow_bg.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">

<corners android:radius="3dp" />

<solid android:color="@color/bangumi_index_yellow_bg" />

</shape>
8 changes: 4 additions & 4 deletions app/src/main/res/layout/item_bangumi_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_general_margin"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="@dimen/default_tiny_padding">
android:orientation="vertical">


<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/white"
android:foreground="?attr/selectableItemBackground"
app:cardBackgroundColor="@color/card_view_background"
app:cardCornerRadius="@dimen/card_corner_radius"
app:cardElevation="@dimen/card_elevation">

Expand All @@ -30,7 +31,6 @@
android:ellipsize="end"
android:maxWidth="@dimen/bangumi_index_image_size"
android:padding="@dimen/default_tiny_padding"
android:singleLine="true"
android:textColor="@color/font_normal"
android:textSize="@dimen/default_small_text_size" />

Expand Down
59 changes: 59 additions & 0 deletions app/src/main/res/layout/layout_bangumi_index_head.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/default_general_margin"
android:orientation="horizontal">


<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_default_height"
android:layout_weight="1"
android:background="@drawable/bangumi_index_green_bg"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_bangumi_index" />


<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_tiny_padding"
android:src="@drawable/ic_bangumi_index_text" />

</LinearLayout>


<Space
android:layout_width="@dimen/default_general_margin"
android:layout_height="wrap_content" />


<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/action_bar_default_height"
android:layout_weight="1"
android:background="@drawable/bangumi_index_yellow_bg"
android:gravity="center"
android:orientation="horizontal">

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_bangumi_rank" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_general_margin"
android:src="@drawable/ic_bangumi_rank_text" />

</LinearLayout>


</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values-hdpi/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<dimen name="home_recommend_foot_bangumi_layout_height">40dp</dimen>

<!--bangumi index size-->
<dimen name="bangumi_index_image_size">100dp</dimen>
<dimen name="bangumi_index_image_size">120dp</dimen>

<!--bangumi recomend size-->
<dimen name="bangumi_recommend_image_height">140dp</dimen>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-xhdpi/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<dimen name="home_recommend_foot_bangumi_layout_height">40dp</dimen>

<!--bangumi index size-->
<dimen name="bangumi_index_image_size">100dp</dimen>
<dimen name="bangumi_index_image_size">120dp</dimen>

<!--bangumi recomend size-->
<dimen name="bangumi_recommend_image_height">140dp</dimen>
Expand Down
Loading

0 comments on commit 1526f0b

Please sign in to comment.