Skip to content

Commit

Permalink
优化主题功能,界面适配更多颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
luern0313 committed Sep 30, 2020
1 parent fcfb869 commit f872971
Show file tree
Hide file tree
Showing 106 changed files with 637 additions and 496 deletions.
20 changes: 11 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ android {
multiDexEnabled true
javaCompileOptions { annotationProcessorOptions { includeCompileClasspath = true } }
}
//compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_8
// targetCompatibility JavaVersion.VERSION_1_8
//}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
Expand All @@ -35,13 +35,13 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':Lson')

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.viewpager2:viewpager2:1.0.0'

Expand All @@ -61,4 +61,6 @@ dependencies {
implementation 'com.king.view:circleprogressview:1.1.1'
implementation 'org.projectlombok:lombok:1.16.18'
implementation 'javax.annotation:javax.annotation-api:1.2'

//implementation 'cn.luern0313.lson:Lson:0.3'
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.ArrayList;

import androidx.cardview.widget.CardView;
import androidx.core.graphics.ColorUtils;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import cn.luern0313.wristbilibili.R;
Expand Down Expand Up @@ -130,6 +129,15 @@ public ViewHolder getViewHolder(DynamicModel dynamicModel, View convertView, int
{
ViewHolder viewHolder;
ViewHolder vh = new ViewHolder();
if(dynamicModel instanceof DynamicModel.DynamicUnknownModel)
{
View view = mInflater.inflate(R.layout.widget_dynamic_unknown, null);
((LinearLayout) convertView.findViewById(viewId)).removeAllViewsInLayout();
((LinearLayout) convertView.findViewById(viewId)).addView(view);
viewHolder = vh.new ViewHolderUnknown(convertView, dynamicModel.getCardType());
convertView.setTag(viewHolder);
return viewHolder;
}
switch (dynamicModel.getCardType())
{
case 1:
Expand Down Expand Up @@ -231,7 +239,7 @@ public ViewHolder getViewHolder(DynamicModel dynamicModel, View convertView, int

public void handlerView(ViewHolder vh, DynamicModel dm, int position, boolean isShared, boolean isExpand)
{
if(dm.getCardType() == 1)
if(dm.getCardType() == 1 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
final ViewHolder.ViewHolderShare viewHolder = (ViewHolder.ViewHolderShare) vh;
final DynamicModel.DynamicShareModel dynamicModel = (DynamicModel.DynamicShareModel) dm;
Expand Down Expand Up @@ -267,7 +275,7 @@ public void onShrink(ExpandableTextView view)

viewHolder.share_share.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 2)
else if(dm.getCardType() == 2 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
final ViewHolder.ViewHolderAlbum viewHolder = (ViewHolder.ViewHolderAlbum) vh;
final DynamicModel.DynamicAlbumModel dynamicModel = (DynamicModel.DynamicAlbumModel) dm;
Expand Down Expand Up @@ -328,7 +336,7 @@ public void onClick(int position)

viewHolder.album_author.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 4)
else if(dm.getCardType() == 4 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderText viewHolder = (ViewHolder.ViewHolderText) vh;
final DynamicModel.DynamicTextModel dynamicModel = (DynamicModel.DynamicTextModel) dm;
Expand Down Expand Up @@ -370,7 +378,7 @@ public void onShrink(ExpandableTextView view)

viewHolder.text_author.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 8)
else if(dm.getCardType() == 8 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderVideo viewHolder = (ViewHolder.ViewHolderVideo) vh;
final DynamicModel.DynamicVideoModel dynamicModel = (DynamicModel.DynamicVideoModel) dm;
Expand Down Expand Up @@ -432,7 +440,7 @@ public void onShrink(ExpandableTextView view)

viewHolder.video_author_lay.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 64)
else if(dm.getCardType() == 64 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderArticle viewHolder = (ViewHolder.ViewHolderArticle) vh;
final DynamicModel.DynamicArticleModel dynamicModel = (DynamicModel.DynamicArticleModel) dm;
Expand Down Expand Up @@ -494,7 +502,7 @@ public void onShrink(ExpandableTextView view)

viewHolder.article_author_lay.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 512 || dm.getCardType() == 4098 || dm.getCardType() == 4099 || dm.getCardType() == 4101)
else if((dm.getCardType() == 512 || dm.getCardType() == 4098 || dm.getCardType() == 4099 || dm.getCardType() == 4101) && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderBangumi viewHolder = (ViewHolder.ViewHolderBangumi) vh;
DynamicModel.DynamicBangumiModel dynamicModel = (DynamicModel.DynamicBangumiModel) dm;
Expand All @@ -515,7 +523,7 @@ else if(dm.getCardType() == 512 || dm.getCardType() == 4098 || dm.getCardType()
BitmapDrawable a = setImageFormWeb(dynamicModel.getBangumiImg());
if(a != null) viewHolder.bangumi_img.setImageDrawable(a);
}
else if(dm.getCardType() == 2048)
else if(dm.getCardType() == 2048 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderUrl viewHolder = (ViewHolder.ViewHolderUrl) vh;
final DynamicModel.DynamicUrlModel dynamicModel = (DynamicModel.DynamicUrlModel) dm;
Expand Down Expand Up @@ -572,7 +580,7 @@ public void onShrink(ExpandableTextView view)
viewHolder.url_author.setOnClickListener(onViewClick(position, isShared));
viewHolder.url_url.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 4200)
else if(dm.getCardType() == 4200 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderLive viewHolder = (ViewHolder.ViewHolderLive) vh;
DynamicModel.DynamicLiveModel dynamicModel = (DynamicModel.DynamicLiveModel) dm;
Expand Down Expand Up @@ -618,7 +626,7 @@ else if(dm.getCardType() == 4200)

viewHolder.live_author_lay.setOnClickListener(onViewClick(position, isShared));
}
else if(dm.getCardType() == 4300)
else if(dm.getCardType() == 4300 && !(dm instanceof DynamicModel.DynamicUnknownModel))
{
ViewHolder.ViewHolderFavor viewHolder = (ViewHolder.ViewHolderFavor) vh;
DynamicModel.DynamicFavorModel dynamicModel = (DynamicModel.DynamicFavorModel) dm;
Expand Down Expand Up @@ -679,11 +687,9 @@ else if(dm.getCardAuthorOfficial() == 1)
}

if(dm.getCardAuthorVipStatus() == 1 && dm.getCardAuthorVipType() == 2)
vh.dynamic_author_name.setTextColor(ColorUtil.getColor(R.attr.colorAccent,
vh.dynamic_author_name.getContext()));
vh.dynamic_author_name.setTextColor(ColorUtil.getColor(R.attr.colorVip, vh.dynamic_author_name.getContext()));
else
vh.dynamic_author_name.setTextColor(ColorUtil.getColor(android.R.attr.textColor,
vh.dynamic_author_name.getContext()));
vh.dynamic_author_name.setTextColor(ColorUtil.getColor(android.R.attr.textColor, vh.dynamic_author_name.getContext()));

vh.dynamic_share_text.setText(dm.getCardShareNum());
vh.dynamic_reply_text.setText(dm.getCardReplyNum());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ public void onShrink(ExpandableTextView view)
if(replyModel.reply_reply_num > Math.min(replyModel.reply_reply_show.size(), 3))
{
if(!replyModel.reply_is_up_reply) viewHolder.reply_reply_show_show.setText(
Html.fromHtml("<font color=\"#3f51b5\">共" + DataProcessUtil.getView(replyModel.reply_reply_num) + "条回复 ></font>"));
Html.fromHtml("<font color=\"#188ad0\">共" + DataProcessUtil.getView(replyModel.reply_reply_num) + "条回复 ></font>"));
else viewHolder.reply_reply_show_show.setText(Html.fromHtml(
"UP主等人<font color=\"#3f51b5\">共" + DataProcessUtil.getView(replyModel.reply_reply_num) + "条回复 ></font>"));
"UP主等人<font color=\"#188ad0\">共" + DataProcessUtil.getView(replyModel.reply_reply_num) + "条回复 ></font>"));
viewHolder.reply_reply_show_show.setVisibility(View.VISIBLE);
}
else
Expand Down Expand Up @@ -274,7 +274,7 @@ public void onShrink(ExpandableTextView view)
else viewHolder.reply_dislike.setImageResource(R.drawable.icon_dislike);
if(replyModel.reply_owner_vip == 2)
{
viewHolder.reply_name.setTextColor(ColorUtil.getColor(R.attr.colorBigMember, listView.getContext()));
viewHolder.reply_name.setTextColor(ColorUtil.getColor(R.attr.colorVip, listView.getContext()));
viewHolder.reply_name.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -23,14 +24,16 @@ public class ThemeAdapter extends RecyclerView.Adapter<ThemeAdapter.ThemeViewHol
{
private Context ctx;
private LayoutInflater layoutInflater;
private RecyclerView recyclerView;

private ThemeAdapterListener themeAdapterListener;

public ThemeAdapter(Context ctx, LayoutInflater layoutInflater, ThemeAdapterListener themeAdapterListener)
public ThemeAdapter(Context ctx, LayoutInflater layoutInflater, ThemeAdapterListener themeAdapterListener, RecyclerView recyclerView)
{
this.ctx = ctx;
this.layoutInflater = layoutInflater;
this.themeAdapterListener = themeAdapterListener;
this.recyclerView = recyclerView;
}

@NonNull
Expand All @@ -44,27 +47,22 @@ public ThemeViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewTyp
public void onBindViewHolder(@NonNull final ThemeViewHolder holder, int position)
{
holder.checkView.setVisibility(ThemeUtil.getCurrentThemePos() == position ? View.VISIBLE : View.INVISIBLE);
holder.nameView.setText(ThemeUtil.themes[position].name);
holder.colorView.setCardBackgroundColor(ctx.getResources().getColor(ThemeUtil.themes[position].previewColor));
holder.nameView.setText(ThemeUtil.themes[position].getName());
holder.colorView.setCardBackgroundColor(ctx.getResources().getColor(ThemeUtil.themes[position].getPreviewColor()));
final int finalPos = position;

holder.itemView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
@ColorInt int prevBack = ColorUtil.getColor(android.R.attr.colorBackground, R.color.activityBG, ctx);
ThemeUtil.changeCurrentTheme(ThemeUtil.themes[finalPos]);
ThemeUtil.changeTheme(ctx, ThemeUtil.getCurrentTheme());
@ColorInt int[] colors = ColorUtil.getColors(
new int[]{R.attr.colorPrimary, android.R.attr.colorBackground, android.R.attr.textColor},
new int[]{ctx.getResources().getColor(R.color.colorPrimary),
ctx.getResources().getColor(R.color.activityBG),
ctx.getResources().getColor(R.color.gray_77)}, ctx);
int primary = colors[0];
int back = colors[1];
int fore = colors[2];
themeAdapterListener.onAnimate(((Activity) ctx).findViewById(R.id.theme_list), "backgroundColor", prevBack, back);
int primary = ColorUtil.getColor(R.attr.colorPrimary, ctx);
int back = ColorUtil.getColor(android.R.attr.colorBackground, ctx);
int fore = ColorUtil.getColor(android.R.attr.textColor, ctx);
themeAdapterListener.onChangeTheme((ViewGroup) ((Activity) ctx).findViewById(R.id.theme_root), primary, fore);
themeAdapterListener.onAnimate(recyclerView, "backgroundColor", ((ColorDrawable) recyclerView.getBackground()).getColor(), back);
notifyDataSetChanged();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import cn.luern0313.wristbilibili.R;
import cn.luern0313.wristbilibili.models.UserListPeopleModel;
import cn.luern0313.wristbilibili.util.ColorUtil;
import cn.luern0313.wristbilibili.util.ImageTaskUtil;
import cn.luern0313.wristbilibili.util.LruCacheUtil;
import de.hdodenhof.circleimageview.CircleImageView;
Expand Down Expand Up @@ -82,9 +83,9 @@ public View getView(final int position, View convertView, ViewGroup viewGroup)
viewHolder.img.setImageResource(R.drawable.img_default_head);
viewHolder.name.setText(userListPeopleModel.getName());
if(userListPeopleModel.getVip() == 2)
viewHolder.name.setTextColor(listView.getResources().getColor(R.color.mainColor));
viewHolder.name.setTextColor(ColorUtil.getColor(R.attr.colorVip, listView.getContext()));
else
viewHolder.name.setTextColor(listView.getResources().getColor(R.color.gray_44));
viewHolder.name.setTextColor(ColorUtil.getColor(R.attr.colorTitle, listView.getContext()));
String sign = userListPeopleModel.getVerifyName().equals("") ?
userListPeopleModel.getSign() : userListPeopleModel.getVerifyName();
if(!sign.equals(""))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package cn.luern0313.wristbilibili.api;


import java.io.IOException;
import java.util.ArrayList;

import cn.luern0313.lson.LsonArrayUtil;
import cn.luern0313.lson.LsonObjectUtil;
import cn.luern0313.lson.LsonParser;
import cn.luern0313.lson.LsonUtil;
import cn.luern0313.lson.element.LsonArray;
import cn.luern0313.lson.element.LsonObject;
import cn.luern0313.lson.json.LsonParser;
import cn.luern0313.wristbilibili.models.AnimationTimelineModel;
import cn.luern0313.wristbilibili.util.NetWorkUtil;
import cn.luern0313.wristbilibili.util.SharedPreferencesUtil;
Expand All @@ -32,11 +31,11 @@ public AnimationTimelineApi()
public ArrayList<AnimationTimelineModel> getAnimTimelineList() throws IOException
{
String url = "https://bangumi.bilibili.com/web_api/timeline_global";
LsonObjectUtil result = LsonParser.parseString(NetWorkUtil.get(url, webHeaders).body().string());
LsonObject result = LsonParser.parseAsObject(NetWorkUtil.get(url, webHeaders).body().string());
ArrayList<AnimationTimelineModel> animationTimelineModelArrayList = new ArrayList<>();
if(result.getAsInt("code", -1) == 0)
{
LsonArrayUtil animArray = result.getAsJsonArray("result");
LsonArray animArray = result.getAsJsonArray("result");
for (int i = 6; i >= 0; i--)
animationTimelineModelArrayList.add(LsonUtil.fromJson(animArray.getAsJsonObject(i), AnimationTimelineModel.class));
}
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/cn/luern0313/wristbilibili/api/BangumiApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.net.URLEncoder;
import java.util.ArrayList;

import cn.luern0313.lson.LsonArrayUtil;
import cn.luern0313.lson.LsonObjectUtil;
import cn.luern0313.lson.LsonParser;
import cn.luern0313.lson.LsonUtil;
import cn.luern0313.lson.element.LsonArray;
import cn.luern0313.lson.element.LsonObject;
import cn.luern0313.lson.json.LsonParser;
import cn.luern0313.wristbilibili.models.ListBangumiModel;
import cn.luern0313.wristbilibili.models.bangumi.BangumiModel;
import cn.luern0313.wristbilibili.util.NetWorkUtil;
Expand Down Expand Up @@ -77,11 +77,11 @@ public BangumiModel getBangumiInfo() throws IOException
public ArrayList<ListBangumiModel> getBangumiRecommend() throws IOException
{
String url = "https://api.bilibili.com/pgc/web/recommend/related/recommend?season_id=" + season_id;
LsonObjectUtil result = LsonParser.parseString(NetWorkUtil.get(url, webHeaders).body().string());
LsonObject result = LsonParser.parseAsObject(NetWorkUtil.get(url, webHeaders).body().string());
ArrayList<ListBangumiModel> bangumiRecommendModelArrayList = new ArrayList<>();
if(result.getAsInt("code", -1) == 0)
{
LsonArrayUtil seasonArray = result.getAsJsonObject("result").getAsJsonArray("season");
LsonArray seasonArray = result.getAsJsonObject("result").getAsJsonArray("season");
for(int i = 0; i < seasonArray.size(); i++)
bangumiRecommendModelArrayList.add(LsonUtil.fromJson(seasonArray.getAsJsonObject(i), ListBangumiModel.class));
}
Expand Down
19 changes: 2 additions & 17 deletions app/src/main/java/cn/luern0313/wristbilibili/api/DynamicApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* 不过好在不用动脑子(滑稽)
* 辛苦b站程序们,动态有至少十几种
* 我只做了五种23333
* ——————————————————————————
* 已经重新制作了
*/

public class DynamicApi
Expand Down Expand Up @@ -181,21 +183,4 @@ public String likeDynamic(String dynamicId, String action) throws IOException //
}
return "未知错误,点赞失败。。";
}

public String sendReply(String oid, String type, String text) throws IOException
{
try
{
String url = "https://api.bilibili.com/x/v2/reply/add";
String arg = "oid=" + oid + "&type=" + type + "&message=" + text + "&plat=1&jsonp=jsonp&csrf=" + csrf;
JSONObject result = new JSONObject(NetWorkUtil.post(url, arg, webHeaders).body().string());
if(result.getInt("code") == 0)
return "";
}
catch (JSONException e)
{
e.printStackTrace();
}
return "未知错误,评论失败。。";
}
}
Loading

0 comments on commit f872971

Please sign in to comment.