[app] Add hint textview (#1280)

This commit is contained in:
LoveSy 2021-10-15 19:43:21 +08:00 committed by GitHub
parent def6cfe579
commit 233569b40e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 11 deletions

View File

@ -380,9 +380,12 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
} }
}); });
SpannableStringBuilder sb = new SpannableStringBuilder(android ? "" : activity.getString(R.string.app_description, appInfo.packageName, appInfo.packageInfo.versionName)); SpannableStringBuilder sb = new SpannableStringBuilder(android ? "" : activity.getString(R.string.app_description, appInfo.packageName, appInfo.packageInfo.versionName));
holder.appDescription.setVisibility(View.VISIBLE); if (android) holder.appDescription.setVisibility(View.GONE);
else {
holder.appDescription.setText(sb);
sb = new SpannableStringBuilder();
}
if (!recommendedList.isEmpty() && recommendedList.contains(appInfo.application)) { if (!recommendedList.isEmpty() && recommendedList.contains(appInfo.application)) {
if (!android) sb.append("\n");
String recommended = activity.getString(R.string.requested_by_module); String recommended = activity.getString(R.string.requested_by_module);
sb.append(recommended); sb.append(recommended);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(activity.getTheme(), androidx.appcompat.R.attr.colorAccent)); final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(activity.getTheme(), androidx.appcompat.R.attr.colorAccent));
@ -394,10 +397,8 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
sb.setSpan(styleSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(styleSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
} }
sb.setSpan(foregroundColorSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(foregroundColorSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
} else if (android) {
holder.appDescription.setVisibility(View.GONE);
} }
holder.appDescription.setText(sb); holder.hint.setText(sb);;
holder.itemView.setOnCreateContextMenuListener((menu, v, menuInfo) -> { holder.itemView.setOnCreateContextMenuListener((menu, v, menuInfo) -> {
activity.getMenuInflater().inflate(R.menu.menu_app_item, menu); activity.getMenuInflater().inflate(R.menu.menu_app_item, menu);
@ -551,6 +552,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
ImageView appIcon; ImageView appIcon;
TextView appName; TextView appName;
TextView appDescription; TextView appDescription;
TextView hint;
MaterialCheckBox checkbox; MaterialCheckBox checkbox;
ViewHolder(ItemModuleBinding binding) { ViewHolder(ItemModuleBinding binding) {
@ -560,6 +562,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
appName = binding.appName; appName = binding.appName;
appDescription = binding.description; appDescription = binding.description;
checkbox = binding.checkbox; checkbox = binding.checkbox;
hint = binding.hint;
checkbox.setVisibility(View.VISIBLE); checkbox.setVisibility(View.VISIBLE);
} }
} }

View File

@ -444,6 +444,9 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
} else { } else {
sb.append(getString(R.string.module_empty_description)); sb.append(getString(R.string.module_empty_description));
} }
holder.appDescription.setText(sb);
sb = new SpannableStringBuilder();
int installXposedVersion = ConfigManager.getXposedApiVersion(); int installXposedVersion = ConfigManager.getXposedApiVersion();
String warningText = null; String warningText = null;
@ -457,7 +460,6 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
warningText = getString(R.string.warning_installed_on_external_storage); warningText = getString(R.string.warning_installed_on_external_storage);
} }
if (warningText != null) { if (warningText != null) {
sb.append("\n");
sb.append(warningText); sb.append(warningText);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ContextCompat.getColor(requireActivity(), rikka.material.R.color.material_red_500)); final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ContextCompat.getColor(requireActivity(), rikka.material.R.color.material_red_500));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@ -472,7 +474,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
if (repoLoader.isRepoLoaded()) { if (repoLoader.isRepoLoaded()) {
var ver = repoLoader.getModuleLatestVersion(item.packageName); var ver = repoLoader.getModuleLatestVersion(item.packageName);
if (ver != null && ver.first > item.versionCode) { if (ver != null && ver.first > item.versionCode) {
sb.append("\n"); if (warningText != null) sb.append("\n");
String recommended = getString(R.string.update_available, ver.second); String recommended = getString(R.string.update_available, ver.second);
sb.append(recommended); sb.append(recommended);
final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(requireActivity().getTheme(), androidx.appcompat.R.attr.colorAccent)); final ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(ResourceUtils.resolveColor(requireActivity().getTheme(), androidx.appcompat.R.attr.colorAccent));
@ -486,7 +488,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
sb.setSpan(foregroundColorSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); sb.setSpan(foregroundColorSpan, sb.length() - recommended.length(), sb.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
} }
} }
holder.appDescription.setText(sb); holder.hint.setText(sb);
if (!isPick) { if (!isPick) {
holder.root.setAlpha(moduleUtil.isModuleEnabled(item.packageName) ? 1.0f : .5f); holder.root.setAlpha(moduleUtil.isModuleEnabled(item.packageName) ? 1.0f : .5f);
@ -605,6 +607,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
TextView appName; TextView appName;
TextView appDescription; TextView appDescription;
TextView appVersion; TextView appVersion;
TextView hint;
MaterialCheckBox checkBox; MaterialCheckBox checkBox;
ViewHolder(ItemModuleBinding binding) { ViewHolder(ItemModuleBinding binding) {
@ -614,6 +617,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
appName = binding.appName; appName = binding.appName;
appDescription = binding.description; appDescription = binding.description;
appVersion = binding.versionName; appVersion = binding.versionName;
hint = binding.hint;
checkBox = binding.checkbox; checkBox = binding.checkbox;
} }
} }

View File

@ -68,11 +68,25 @@
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceListItemSecondary" android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorSecondary" android:textColor="?android:attr/textColorSecondary"
app:layout_constraintBottom_toBottomOf="@id/hint"
app:layout_constraintEnd_toStartOf="@id/checkbox"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@id/app_name"
app:layout_constraintTop_toBottomOf="@id/app_name"
tools:text="@tools:sample/lorem" />
<TextView
android:id="@+id/hint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textAppearance="?android:attr/textAppearanceListItemSecondary"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/checkbox" app:layout_constraintEnd_toStartOf="@id/checkbox"
app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/app_name" app:layout_constraintStart_toStartOf="@id/description"
app:layout_constraintTop_toBottomOf="@id/app_name" app:layout_constraintTop_toBottomOf="@id/description"
tools:text="@tools:sample/lorem" /> tools:text="@tools:sample/lorem" />
<TextView <TextView
@ -90,7 +104,7 @@
android:visibility="gone" android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0" app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/app_name" app:layout_constraintStart_toEndOf="@id/app_name"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" tools:ignore="RtlHardcoded"
tools:text="@tools:sample/last_names" /> tools:text="@tools:sample/last_names" />