Skip to content

Commit

Permalink
Migrate to Non-Transitive R Classes and convert switch statements to …
Browse files Browse the repository at this point in the history
…if/else as resources are no longer declared final
  • Loading branch information
nicked committed Feb 27, 2024
1 parent 0037514 commit 05b2c85
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 90 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/activities/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
if (hideStatusBar()) {
BarUtils.transparentStatusBar(this);
} else {
getWindow().setStatusBarColor(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary));
getWindow().setStatusBarColor(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary));
}
try {
baseBind = DataBindingUtil.setContentView(mActivity, mLayoutID);
Expand Down
115 changes: 49 additions & 66 deletions app/src/main/java/ceui/lisa/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,72 +254,55 @@ public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();

Intent intent = null;
switch (id) {
case R.id.nav_gallery:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "下载管理");
intent.putExtra("hideStatusBar", false);
break;
case R.id.nav_slideshow:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "浏览记录");
break;
case R.id.nav_manage:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "设置");
break;
case R.id.nav_share:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "关于软件");
break;
case R.id.main_page:
intent = new Intent(mContext, UserActivity.class);
intent.putExtra(Params.USER_ID, sUserModel.getUser().getId());
break;
case R.id.nav_reverse:
selectPhoto();
break;
case R.id.nav_new_work:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "最新作品");
intent.putExtra("hideStatusBar", false);
break;
case R.id.muted_list:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "标签屏蔽记录");
break;
case R.id.nav_feature:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "精华列");
break;
case R.id.nav_fans:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "粉丝");
break;
case R.id.illust_star:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的插画收藏");
intent.putExtra("hideStatusBar", false);
break;
case R.id.novel_star:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的小说收藏");
intent.putExtra("hideStatusBar", false);
break;
case R.id.follow_user:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的关注");
intent.putExtra("hideStatusBar", false);
break;
case R.id.new_work:
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "网页链接");
intent.putExtra(Params.URL, "https://www.pixiv.net/upload.php");
intent.putExtra(Params.TITLE, getString(R.string.string_444));
intent.putExtra(Params.PREFER_PRESERVE, true);
break;
default:
break;
if (id == R.id.nav_gallery) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "下载管理");
intent.putExtra("hideStatusBar", false);
} else if (id == R.id.nav_slideshow) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "浏览记录");
} else if (id == R.id.nav_manage) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "设置");
} else if (id == R.id.nav_share) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "关于软件");
} else if (id == R.id.main_page) {
intent = new Intent(mContext, UserActivity.class);
intent.putExtra(Params.USER_ID, sUserModel.getUser().getId());
} else if (id == R.id.nav_reverse) {
selectPhoto();
} else if (id == R.id.nav_new_work) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "最新作品");
intent.putExtra("hideStatusBar", false);
} else if (id == R.id.muted_list) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "标签屏蔽记录");
} else if (id == R.id.nav_feature) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "精华列");
} else if (id == R.id.nav_fans) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "粉丝");
} else if (id == R.id.illust_star) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的插画收藏");
intent.putExtra("hideStatusBar", false);
} else if (id == R.id.novel_star) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的小说收藏");
intent.putExtra("hideStatusBar", false);
} else if (id == R.id.follow_user) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "我的关注");
intent.putExtra("hideStatusBar", false);
} else if (id == R.id.new_work) {
intent = new Intent(mContext, TemplateActivity.class);
intent.putExtra(TemplateActivity.EXTRA_FRAGMENT, "网页链接");
intent.putExtra(Params.URL, "https://www.pixiv.net/upload.php");
intent.putExtra(Params.TITLE, getString(R.string.string_444));
intent.putExtra(Params.PREFER_PRESERVE, true);
}
if (intent != null) {
startActivity(intent);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/activities/RankActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
start.set(2008, 0, 1);
dpd.setMinDate(start);
dpd.setMaxDate(now);
dpd.setAccentColor(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary));
dpd.setAccentColor(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary));
dpd.setThemeDark(mContext.getResources().getBoolean(R.bool.is_night_mode));
dpd.show(getSupportFragmentManager(), "DatePickerDialog");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void initLayout() {

@Override
public void bindData(ListTrendingtag.TrendTagsBean target, ViewHolder<RecySearchHintBinding> bindView, int position) {
SpannableString string = matcherSearchText(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary),
SpannableString string = matcherSearchText(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary),
target.getName(), mKeyword);
bindView.baseBind.titleText.setText(string);
if (!TextUtils.isEmpty(target.getTranslated_name()) && !target.getTranslated_name().equals(target.getName())) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/dialogs/MuteDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public View getView(FlowLayout parent, int position, TagsBean o) {
@Override
public void onSelected(int position, View view) {
super.onSelected(position, view);
((TextView) view).setTextColor(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary));
((TextView) view).setTextColor(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary));
view.setBackgroundResource(R.drawable.tag_stroke_checked_bg);
selected.add(mIllust.getTags().get(position));
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ceui/lisa/fragments/FragmentComment.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ public void initView() {
alertDialog.show();
alertDialog
.getButton(AlertDialog.BUTTON_POSITIVE)
.setTextColor(R.attr.colorPrimary);
.setTextColor(androidx.appcompat.R.attr.colorPrimary);
alertDialog
.getButton(AlertDialog.BUTTON_NEGATIVE)
.setTextColor(R.attr.colorPrimary);
.setTextColor(androidx.appcompat.R.attr.colorPrimary);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public void onClick(View v) {
start.set(now.get(Calendar.YEAR) - 100, 0, 1);
dpd.setMinDate(start);
dpd.setMaxDate(now);
dpd.setAccentColor(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary));
dpd.setAccentColor(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary));
dpd.setThemeDark(mContext.getResources().getBoolean(R.bool.is_night_mode));
dpd.show(getParentFragmentManager(), "DatePickerDialog");
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/ceui/lisa/fragments/FragmentFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
}
});*/
baseBind.restrictionToggle.setElements(PixivSearchParamUtil.R18_RESTRICTION_NAME);
baseBind.restrictionToggle.setColors(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary), getResources().getColor(R.color.fragment_center));
baseBind.restrictionToggle.setColors(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary), getResources().getColor(R.color.fragment_center));
baseBind.restrictionToggle.setValue(0);
baseBind.restrictionToggle.setOnValueChangedListener(new ToggleButton.OnValueChangedListener() {
@Override
Expand Down Expand Up @@ -217,7 +217,7 @@ public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayO
start.set(1970, 0, 1);
dpd.setMinDate(start);
dpd.setMaxDate(now);
dpd.setAccentColor(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary));
dpd.setAccentColor(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary));
dpd.setThemeDark(mContext.getResources().getBoolean(R.bool.is_night_mode));
dpd.show(getParentFragmentManager(), "DatePickerDialog");
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/fragments/FragmentIllust.kt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class FragmentIllust : SwipeFragment<FragmentIllustBinding>() {
}

override fun updateDrawState(ds: TextPaint) {
ds.color = Common.resolveThemeAttribute(mContext, R.attr.colorPrimary)
ds.color = Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary)
}
}
val spannableString: SpannableString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void initLayout() {
@Override
public void initView() {
Wave wave = new Wave();
wave.setColor(R.attr.colorPrimary);
wave.setColor(androidx.appcompat.R.attr.colorPrimary);
baseBind.progress.setIndeterminateDrawable(wave);
baseBind.recyclerView.addItemDecoration(new
LinearItemHorizontalDecoration(DensityUtil.dp2px(8.0f)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void loadImage() {
.into(baseBind.bgImage);
break;
case Configuration.UI_MODE_NIGHT_YES:
baseBind.bgImage.setImageResource(R.color.black);
baseBind.bgImage.setImageResource(com.just.agentweb.R.color.black);
break;
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public void onClick(View widget) {

@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(Common.resolveThemeAttribute(mContext, R.attr.colorPrimary));
ds.setColor(Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary));
}
};
SpannableString spannableString;
Expand Down Expand Up @@ -366,7 +366,7 @@ public void onClick(View v) {
baseBind.userName.setText(illust.getUser().getName());

SpannableString sizeString = new SpannableString(getString(R.string.string_193, illust.getWidth(), illust.getHeight()));
int currentPrimaryColorId = Common.resolveThemeAttribute(mContext, R.attr.colorPrimary);
int currentPrimaryColorId = Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary);
sizeString.setSpan(new ForegroundColorSpan(currentPrimaryColorId),
sizeString.length()-illust.getSize().length(), sizeString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
baseBind.illustPx.setText(sizeString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private void loadImage() {
.into(baseBind.bgImage);
break;
case Configuration.UI_MODE_NIGHT_YES:
baseBind.bgImage.setImageResource(R.color.black);
baseBind.bgImage.setImageResource(com.just.agentweb.R.color.black);
break;
}

Expand Down Expand Up @@ -475,7 +475,7 @@ public void onClick(View v) {
baseBind.userName.setText(illust.getUser().getName());

SpannableString sizeString = new SpannableString(getString(R.string.string_193, illust.getWidth(), illust.getHeight()));
int currentPrimaryColorId = Common.resolveThemeAttribute(mContext, R.attr.colorPrimary);
int currentPrimaryColorId = Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary);
sizeString.setSpan(new ForegroundColorSpan(currentPrimaryColorId),
sizeString.length()-illust.getSize().length(), sizeString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
baseBind.illustPx.setText(sizeString);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/fragments/FragmentWebView.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public void onResume() {
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
WebView.HitTestResult result = mWebView.getHitTestResult();
mIntentUrl = result.getExtra();
menu.setHeaderView(new ContextMenuTitleView(mContext, mIntentUrl, Common.resolveThemeAttribute(mContext, R.attr.colorPrimary)));
menu.setHeaderView(new ContextMenuTitleView(mContext, mIntentUrl, Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary)));

if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
mIntentUrl = result.getExtra();
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/ceui/lisa/page/ConstantPageInfo.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package ceui.lisa.page;


import ceui.lisa.R;

public class ConstantPageInfo {

/**
Expand Down Expand Up @@ -31,5 +29,5 @@ public class ConstantPageInfo {
/**
* 默认字体颜色
*/
public static int textColor = R.color.black;
public static int textColor = com.just.agentweb.R.color.black;
}
2 changes: 1 addition & 1 deletion app/src/main/java/ceui/lisa/view/GlareLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void onClick(View v) {
}

private void check(int index) {
int currentColor = Common.resolveThemeAttribute(mContext,R.attr.colorPrimary);
int currentColor = Common.resolveThemeAttribute(mContext, androidx.appcompat.R.attr.colorPrimary);
if (index == 0) {
baseBind.left.setTextColor(currentColor);
baseBind.left.setBackgroundResource(R.drawable.glare_selected);
Expand Down
4 changes: 1 addition & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.injected.testOnly=false
android.nonTransitiveRClass=false
android.nonFinalResIds=false
android.injected.testOnly=false

0 comments on commit 05b2c85

Please sign in to comment.