Skip to content

Commit

Permalink
优化 卡片磁贴自定义页面UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan095 committed May 7, 2024
1 parent 9e4f59e commit 8a0ba67
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -28,6 +27,7 @@
public class CardTileEditPreference extends Preference {

GridLayoutManager mCradLayoutManager;
View mItemView;
RecyclerView mCardTiles;
RecyclerView mAddCardTiles;
CardTileAdapter mCardTileAdapter;
Expand All @@ -53,9 +53,9 @@ public CardTileEditPreference(@NonNull Context context, @Nullable AttributeSet a
@Override
public void onBindViewHolder(@NonNull PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View itemView = holder.itemView;
mCardTiles = itemView.findViewById(android.R.id.list);
mAddCardTiles = itemView.findViewById(R.id.card_tile_add_list);
mItemView = holder.itemView;
mCardTiles = mItemView.findViewById(android.R.id.list);
mAddCardTiles = mItemView.findViewById(R.id.card_tile_add_list);
initView();
}

Expand All @@ -77,6 +77,12 @@ private void initView() {
mAddCardTileAdapter.setOnDataChangeListener((changed, tile) -> {
onDataSetChanged(tile, false);
});
setVisibility(PrefsUtils.mSharedPreferences.getBoolean("prefs_key_systemui_plugin_card_tiles_enabled", false));
}

@Override
public void onDependencyChanged(@NonNull Preference dependency, boolean disableDependent) {
setVisibility(!disableDependent);
}

private void createCardView(RecyclerView cardView, RecyclerView.Adapter adapter) {
Expand All @@ -86,6 +92,12 @@ private void createCardView(RecyclerView cardView, RecyclerView.Adapter adapter)
cardView.setNestedScrollingEnabled(false);
}

public void setVisibility(boolean visibility) {
if (mItemView != null) {
mItemView.setVisibility(visibility ? View.VISIBLE : View.GONE);
}
}

private List<String> getTileList() {
String str = PrefsUtils.mSharedPreferences.getString("prefs_key_systemui_plugin_card_tiles", "");
return TextUtils.isEmpty(str) ? new ArrayList<>() : Arrays.asList(str.split("\\|"));
Expand Down
79 changes: 43 additions & 36 deletions app/src/main/res/layout/preference_card_tile.xml
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingHorizontal="25dp">
android:layout_height="match_parent">

<TextView
<LinearLayout
android:id="@+id/prefs_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:text="已添加"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.PreferenceCategory" />
android:orientation="vertical"
android:paddingHorizontal="25dp">

<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:text="已添加"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.PreferenceCategory" />

<View style="@style/DividerViewStyle" />
<androidx.recyclerview.widget.RecyclerView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:text="未添加"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.PreferenceCategory" />
<View style="@style/DividerViewStyle" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/card_tile_add_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:text="未添加"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.PreferenceCategory" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginTop="@dimen/divider_margin_top"
android:text="仅xxx支持圆角磁贴"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.PreferenceCategory" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/card_tile_add_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginTop="@dimen/divider_margin_top"
android:text="仅xxx支持圆角磁贴"
android:textAlignment="viewStart"
android:textAppearance="@style/TextAppearance.PreferenceCategory" />

</LinearLayout>

</LinearLayout>
</FrameLayout>
11 changes: 0 additions & 11 deletions app/src/main/res/values-night/styles.xml

This file was deleted.

4 changes: 2 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<style name="DividerViewStyle">
<item name="android:background" tools:ignore="PrivateResource">@color/preference_first_last_divider_line_light</item>
<item name="android:background">@color/card_tile_disabled_color_legacy</item>
<item name="android:layout_gravity">center</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">0.74dp</item>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/xml/system_ui_control_center_card_tile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
android:key="prefs_key_systemui_plugin_card_tiles_enabled" />

<com.sevtinge.hyperceiler.ui.fragment.systemui.prefs.CardTileEditPreference
android:persistent="false"
android:key="prefs_key_systemui_plugin_card_tiles_edit"
android:dependency="prefs_key_systemui_plugin_card_tiles_enabled"/>

</PreferenceScreen>

0 comments on commit 8a0ba67

Please sign in to comment.