胶囊功能调整

pull/32/head
包尔俊 2 months ago
parent a2dc685b07
commit 48344838f1

@ -110,6 +110,12 @@
android:exported="false" />
<!-- ==================== 待办任务列表活动 ==================== -->
<activity
android:name=".ui.CapsuleListActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:screenOrientation="portrait"
android:theme="@style/Theme.Notesmaster" />
<activity
android:name=".ui.TaskListActivity"
android:label="Tasks"

@ -149,6 +149,14 @@ public class MainActivity extends AppCompatActivity implements SidebarFragment.O
closeSidebar();
}
@Override
public void onCapsuleSelected() {
Log.d(TAG, "Capsule selected");
Intent intent = new Intent(this, net.micode.notes.ui.CapsuleListActivity.class);
startActivity(intent);
closeSidebar();
}
@Override
public void onCreateFolder() {
Log.d(TAG, "Create folder");

@ -1254,7 +1254,7 @@ public class NotesRepository {
}
ContentValues values = new ContentValues();
// 同时更新 TITLE 和 SNIPPET保持一致性
// 同时更新 TITLE 和 SNIPPET保持一致性文件夹名存储在SNIPPET中
values.put(NoteColumns.TITLE, newName);
values.put(NoteColumns.SNIPPET, newName);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
@ -1295,9 +1295,8 @@ public class NotesRepository {
}
ContentValues values = new ContentValues();
// 同时更新 TITLE 和 SNIPPET保持一致性
// 仅更新 TITLE保留原始 SNIPPET内容预览
values.put(NoteColumns.TITLE, newName);
values.put(NoteColumns.SNIPPET, newName);
values.put(NoteColumns.LOCAL_MODIFIED, 1);
Uri uri = ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);

@ -442,8 +442,11 @@ public class WorkingNote {
public void setTitle(String title) {
mTitle = title;
mNote.setNoteValue(NoteColumns.TITLE, mTitle);
// 同步设置SNIPPET字段以保持兼容性
mNote.setNoteValue(NoteColumns.SNIPPET, mTitle);
// 只有文件夹需要将标题同步到SNIPPET字段文件夹名存储在SNIPPET中以保持兼容性
// 普通便签的SNIPPET应由内容触发器自动维护
if (mType == Notes.TYPE_FOLDER) {
mNote.setNoteValue(NoteColumns.SNIPPET, mTitle);
}
}
public String getTitle() {

@ -0,0 +1,33 @@
package net.micode.notes.ui;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import net.micode.notes.R;
public class CapsuleListActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_capsule_list);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new CapsuleListFragment())
.commit();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

@ -1,21 +1,25 @@
package net.micode.notes.ui;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.NotesRepository;
import net.micode.notes.model.Note;
import java.text.SimpleDateFormat;
@ -29,6 +33,7 @@ public class CapsuleListFragment extends Fragment {
private RecyclerView mRecyclerView;
private CapsuleAdapter mAdapter;
private TextView mEmptyView;
private Toolbar mToolbar;
@Nullable
@Override
@ -36,6 +41,9 @@ public class CapsuleListFragment extends Fragment {
View view = inflater.inflate(R.layout.fragment_capsule_list, container, false);
mRecyclerView = view.findViewById(R.id.capsule_list);
mEmptyView = view.findViewById(R.id.tv_empty);
mToolbar = view.findViewById(R.id.toolbar);
setupToolbar();
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
mAdapter = new CapsuleAdapter();
@ -44,6 +52,17 @@ public class CapsuleListFragment extends Fragment {
return view;
}
private void setupToolbar() {
if (mToolbar != null && getActivity() instanceof AppCompatActivity) {
AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(mToolbar);
if (activity.getSupportActionBar() != null) {
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
activity.getSupportActionBar().setTitle("速记胶囊");
}
}
}
@Override
public void onResume() {
super.onResume();
@ -54,15 +73,13 @@ public class CapsuleListFragment extends Fragment {
new Thread(() -> {
if (getContext() == null) return;
// Query notes in CAPSULE folder
String selection = Notes.NoteColumns.PARENT_ID + "=?";
String[] selectionArgs = new String[]{String.valueOf(Notes.ID_CAPSULE_FOLDER)};
// Query notes in CAPSULE folder.
// Join with Data table to get DATA3 (source package)
Cursor cursor = getContext().getContentResolver().query(
Notes.CONTENT_NOTE_URI,
null,
selection,
selectionArgs,
Notes.NoteColumns.PARENT_ID + "=?",
new String[]{String.valueOf(Notes.ID_CAPSULE_FOLDER)},
Notes.NoteColumns.MODIFIED_DATE + " DESC"
);
@ -73,14 +90,18 @@ public class CapsuleListFragment extends Fragment {
String snippet = cursor.getString(cursor.getColumnIndexOrThrow(Notes.NoteColumns.SNIPPET));
long modifiedDate = cursor.getLong(cursor.getColumnIndexOrThrow(Notes.NoteColumns.MODIFIED_DATE));
// We need to fetch DATA3 (source) which is in DATA table.
// For performance, we might do a join or lazy load.
// For now, let's just use snippet and date.
// To get Source, we really should query DATA table or use a projection if CONTENT_NOTE_URI supports joining.
// NotesProvider usually joins. Let's check NoteColumns.
// Notes.DataColumns.DATA3 is NOT in NoteColumns.
// Try to get source from projection (if joined) or query separately
String source = "";
try {
int sourceIdx = cursor.getColumnIndex(Notes.DataColumns.DATA3);
if (sourceIdx != -1) {
source = cursor.getString(sourceIdx);
}
} catch (Exception e) {
// Not joined, ignore for now or lazy load
}
items.add(new CapsuleItem(id, snippet, modifiedDate, "Loading source..."));
items.add(new CapsuleItem(id, snippet, modifiedDate, source));
}
cursor.close();
}
@ -95,6 +116,13 @@ public class CapsuleListFragment extends Fragment {
}).start();
}
private void openNoteEditor(long noteId) {
Intent intent = new Intent(getActivity(), NoteEditActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(Intent.EXTRA_UID, noteId);
startActivity(intent);
}
private static class CapsuleItem {
long id;
String summary;
@ -133,15 +161,14 @@ public class CapsuleListFragment extends Fragment {
holder.tvTime.setText(sdf.format(new Date(item.time)));
if (item.source != null && !item.source.isEmpty()) {
holder.tvSource.setText("Source: " + item.source);
holder.tvSource.setText(item.source);
holder.tvSource.setVisibility(View.VISIBLE);
} else {
holder.tvSource.setVisibility(View.GONE);
}
holder.itemView.setOnClickListener(v -> {
// Open Note Edit
// We need to implement this
openNoteEditor(item.id);
});
}

@ -368,6 +368,10 @@ public class NotesListActivity extends AppCompatActivity implements SidebarFragm
@Override public void onExportSelected() { binding.drawerLayout.closeDrawer(GravityCompat.START); Toast.makeText(this, "导出功能待实现", Toast.LENGTH_SHORT).show(); }
@Override public void onTemplateSelected() { binding.drawerLayout.closeDrawer(GravityCompat.START); viewModel.enterFolder(Notes.ID_TEMPLATE_FOLDER); }
@Override public void onSettingsSelected() { binding.drawerLayout.closeDrawer(GravityCompat.START); startActivity(new Intent(this, SettingsActivity.class)); }
@Override public void onCapsuleSelected() {
binding.drawerLayout.closeDrawer(GravityCompat.START);
startActivity(new Intent(this, CapsuleListActivity.class));
}
@Override public void onCreateFolder() { binding.drawerLayout.closeDrawer(GravityCompat.START); /* Show dialog */ }
@Override public void onCloseSidebar() { binding.drawerLayout.closeDrawer(GravityCompat.START); }
@Override public void onRenameFolder(long folderId) { /* Handle rename */ }

@ -71,6 +71,7 @@ public class SidebarFragment extends Fragment {
private LinearLayout menuTemplates;
private LinearLayout menuExport;
private LinearLayout menuSettings;
private LinearLayout menuCapsule;
private LinearLayout menuLogin;
private LinearLayout menuLogout;
@ -106,6 +107,7 @@ public class SidebarFragment extends Fragment {
void onExportSelected();
void onTemplateSelected();
void onSettingsSelected();
void onCapsuleSelected();
void onCreateFolder();
void onCloseSidebar();
void onRenameFolder(long folderId);
@ -170,6 +172,7 @@ public class SidebarFragment extends Fragment {
menuTemplates = view.findViewById(R.id.menu_templates);
menuExport = view.findViewById(R.id.menu_export);
menuSettings = view.findViewById(R.id.menu_settings);
menuCapsule = view.findViewById(R.id.menu_capsule);
menuLogin = view.findViewById(R.id.menu_login);
menuLogout = view.findViewById(R.id.menu_logout);
@ -237,6 +240,15 @@ public class SidebarFragment extends Fragment {
}
});
if (menuCapsule != null) {
menuCapsule.setOnClickListener(v -> {
if (listener != null) {
listener.onCapsuleSelected();
listener.onCloseSidebar();
}
});
}
menuLogin.setOnClickListener(v -> {
if (listener != null) {
listener.onLoginSelected();

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />

@ -163,6 +163,34 @@
</LinearLayout>
<!-- 速记胶囊 -->
<LinearLayout
android:id="@+id/menu_capsule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:paddingHorizontal="16dp"
android:paddingVertical="12dp"
android:background="?attr/selectableItemBackground">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_menu_rich_text"
app:tint="?attr/colorOnSurfaceVariant" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginStart="16dp"
android:text="速记胶囊"
android:textSize="14sp"
android:textColor="?attr/colorOnSurface" />
</LinearLayout>
<!-- 同步设置 -->
<LinearLayout
android:id="@+id/menu_sync_settings"

@ -1,36 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:background="?android:attr/selectableItemBackground">
android:layout_marginHorizontal="12dp"
android:layout_marginVertical="6dp"
app:cardCornerRadius="16dp"
app:cardElevation="2dp"
app:cardBackgroundColor="@android:color/white">
<TextView
android:id="@+id/tv_summary"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:maxLines="2"
android:ellipsize="end" />
<TextView
android:id="@+id/tv_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="@android:color/darker_gray"
android:layout_marginTop="4dp" />
android:orientation="vertical"
android:padding="16dp"
android:background="?android:attr/selectableItemBackground">
<TextView
android:id="@+id/tv_source"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="12sp"
android:textColor="@color/text_color_secondary"
android:gravity="end"
android:layout_marginTop="8dp" />
<TextView
android:id="@+id/tv_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:maxLines="3"
android:ellipsize="end" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="8dp"
android:gravity="center_vertical">
<TextView
android:id="@+id/tv_time"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="12sp"
android:textColor="@android:color/darker_gray" />
<TextView
android:id="@+id/tv_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="11sp"
android:textColor="#1976D2"
android:paddingHorizontal="8dp"
android:paddingVertical="2dp"
android:background="@drawable/swipe_button_bg"
android:backgroundTint="#F0F0F0" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>

Loading…
Cancel
Save