修复重复代码

pull/19/head
包尔俊 1 month ago
parent 9b0c7dc689
commit b15940694b

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1768954653382</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>

@ -582,78 +582,3 @@ public class NotesListViewModel extends ViewModel {
Log.d(TAG, "ViewModel cleared");
}
}
isLoading.postValue(true);
errorMessage.postValue(null);
// 检查当前选中笔记的置顶状态
List<NotesRepository.NoteInfo> allNotes = notesLiveData.getValue();
if (allNotes == null) return;
boolean hasUnpinned = false;
for (NotesRepository.NoteInfo note : allNotes) {
if (selectedNoteIds.contains(note.getId())) {
if (!note.isPinned) {
hasUnpinned = true;
break;
}
}
}
// 如果有未置顶的,则全部置顶;否则全部取消置顶
final boolean newPinState = hasUnpinned;
List<Long> noteIds = new ArrayList<>(selectedNoteIds);
repository.batchTogglePin(noteIds, newPinState, new NotesRepository.Callback<Integer>() {
@Override
public void onSuccess(Integer rowsAffected) {
isLoading.postValue(false);
// 保持选中状态,方便用户查看
refreshNotes();
Log.d(TAG, "Successfully toggled pin state to " + newPinState);
}
@Override
public void onError(Exception error) {
isLoading.postValue(false);
String message = "置顶操作失败: " + error.getMessage();
errorMessage.postValue(message);
Log.e(TAG, message, error);
}
});
}
/**
*
*
* @return true
*/
public boolean isAllSelectedPinned() {
if (selectedNoteIds.isEmpty()) return false;
List<NotesRepository.NoteInfo> allNotes = notesLiveData.getValue();
if (allNotes == null) return false;
for (NotesRepository.NoteInfo note : allNotes) {
if (selectedNoteIds.contains(note.getId())) {
if (!note.isPinned) {
return false;
}
}
}
return true;
}
/**
* ViewModel
* <p>
*
* </p>
*/
@Override
protected void onCleared() {
super.onCleared();
selectedNoteIds.clear();
Log.d(TAG, "ViewModel cleared");
}
}

Loading…
Cancel
Save