新增侧边栏功能,修改文件夹显示方式,完善多级文件夹的逻辑,完善多级文件夹和便签同时显现的问题,新增在侧边栏删除文件夹的功能 #27
luhaozhe_branch into master 4 weeks ago
@ -0,0 +1,142 @@
|
||||
package net.micode.notes.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.micode.notes.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SidebarAdapter extends BaseAdapter {
|
||||
private Context mContext;
|
||||
private List<SidebarItem> mItems;
|
||||
|
||||
public SidebarAdapter(Context context, List<SidebarItem> items) {
|
||||
mContext = context;
|
||||
mItems = items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mItems != null ? mItems.size() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return mItems != null ? mItems.get(position) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(mContext).inflate(R.layout.sidebar_item, parent, false);
|
||||
}
|
||||
|
||||
SidebarItem item = mItems.get(position);
|
||||
TextView titleTextView = convertView.findViewById(R.id.item_title);
|
||||
TextView countTextView = convertView.findViewById(R.id.item_count);
|
||||
|
||||
titleTextView.setText(item.getTitle());
|
||||
if (item.getCount() > 0) {
|
||||
countTextView.setVisibility(View.VISIBLE);
|
||||
countTextView.setText(String.valueOf(item.getCount()));
|
||||
} else {
|
||||
countTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (item.isSelected()) {
|
||||
convertView.setBackgroundColor(mContext.getResources().getColor(R.color.primary, null));
|
||||
titleTextView.setTextColor(mContext.getResources().getColor(R.color.onPrimary, null));
|
||||
countTextView.setTextColor(mContext.getResources().getColor(R.color.onPrimary, null));
|
||||
} else {
|
||||
convertView.setBackgroundColor(mContext.getResources().getColor(R.color.surface, null));
|
||||
titleTextView.setTextColor(mContext.getResources().getColor(R.color.onSurface, null));
|
||||
countTextView.setTextColor(mContext.getResources().getColor(R.color.primary, null));
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public static class SidebarItem {
|
||||
private String mTitle;
|
||||
private int mCount;
|
||||
private boolean mSelected;
|
||||
private String mTag;
|
||||
private long mCategoryId;
|
||||
private QuickViewType mQuickViewType;
|
||||
|
||||
public SidebarItem(String title) {
|
||||
mTitle = title;
|
||||
mCount = 0;
|
||||
mSelected = false;
|
||||
}
|
||||
|
||||
public SidebarItem(String title, int count) {
|
||||
mTitle = title;
|
||||
mCount = count;
|
||||
mSelected = false;
|
||||
}
|
||||
|
||||
public SidebarItem(String title, int count, long categoryId) {
|
||||
mTitle = title;
|
||||
mCount = count;
|
||||
mSelected = false;
|
||||
mCategoryId = categoryId;
|
||||
}
|
||||
|
||||
public SidebarItem(String title, int count, String tag) {
|
||||
mTitle = title;
|
||||
mCount = count;
|
||||
mSelected = false;
|
||||
mTag = tag;
|
||||
}
|
||||
|
||||
public SidebarItem(String title, int count, QuickViewType type) {
|
||||
mTitle = title;
|
||||
mCount = count;
|
||||
mSelected = false;
|
||||
mQuickViewType = type;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return mTitle;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mCount;
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
mSelected = selected;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return mTag;
|
||||
}
|
||||
|
||||
public long getCategoryId() {
|
||||
return mCategoryId;
|
||||
}
|
||||
|
||||
public QuickViewType getQuickViewType() {
|
||||
return mQuickViewType;
|
||||
}
|
||||
|
||||
public enum QuickViewType {
|
||||
ALL, PINNED, TODAY, UNTAGGED
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="@color/surfaceVariant" />
|
||||
<corners android:radius="12dp" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/primary"
|
||||
android:alpha="0.3" />
|
||||
</shape>
|
||||
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/onSurfaceVariant"
|
||||
android:pathData="M10,4L12,6L20,6C21.1,6 22,6.9 22,8L22,18C22,19.1 21.1,20 20,20L4,20C2.89,20 2,19.1 2,18L2,6C2,4.89 2.89,4 4,4L10,4ZM10,4L12,6L10,6L10,4ZM11,14L8,14L8,11L6,11L6,14L3,14L3,16L6,16L6,19L8,19L8,16L11,16L11,14Z" />
|
||||
</vector>
|
||||
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 733 B |
|
After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 848 B |
|
After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 726 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 614 B |
|
After Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 597 B |
@ -0,0 +1,32 @@
|
||||
<?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:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/onSurface"
|
||||
android:fontFamily="sans-serif-medium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/item_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/primary"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="4dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:background="@drawable/count_badge"
|
||||
android:visibility="gone" />
|
||||
|
||||
</LinearLayout>
|
||||
@ -0,0 +1,155 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="280dp"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/surface"
|
||||
android:elevation="8dp">
|
||||
|
||||
<!-- 侧边栏头部 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:background="@color/primary">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="便签导航"
|
||||
android:textSize="18sp"
|
||||
android:textColor="@color/onPrimary"
|
||||
android:fontFamily="sans-serif-medium" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 侧边栏内容区域 -->
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<!-- 全部 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="16dp">
|
||||
<LinearLayout
|
||||
android:id="@+id/all_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/surface"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/all_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="全部"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/onSurface"
|
||||
android:fontFamily="sans-serif-medium" />
|
||||
<TextView
|
||||
android:id="@+id/all_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/primary"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="4dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:background="@drawable/count_badge"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 未分类 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:id="@+id/uncategorized_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/surface"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="12dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical">
|
||||
<TextView
|
||||
android:id="@+id/uncategorized_title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="未分类"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@color/onSurface"
|
||||
android:fontFamily="sans-serif-medium" />
|
||||
<TextView
|
||||
android:id="@+id/uncategorized_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/primary"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="4dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:background="@drawable/count_badge"
|
||||
android:visibility="gone" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 我的文件夹标题 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingTop="8dp">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="我的文件夹"
|
||||
android:textSize="14sp"
|
||||
android:textColor="@color/onSurfaceVariant"
|
||||
android:fontFamily="sans-serif-medium" />
|
||||
<ImageView
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:src="@drawable/ic_folder_add"
|
||||
android:layout_marginStart="8dp"
|
||||
android:id="@+id/add_folder_button" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 用户文件夹 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ListView
|
||||
android:id="@+id/user_folder_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="508dp"
|
||||
android:divider="@null"
|
||||
android:dividerHeight="0dp" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||