ブクマ機能実装中

This commit is contained in:
nero 2024-01-23 12:50:30 +09:00
parent bda8496259
commit 1447148fba
6 changed files with 179 additions and 1 deletions

View File

@ -4,6 +4,7 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="GRADLE" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="jbr-17" />
<option name="modules">

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View File

@ -0,0 +1,53 @@
package one.nem.lacerta.component.viewer;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;
import androidx.fragment.app.Fragment;
import java.util.UUID;
import javax.inject.Inject;
// BookMarkFragment.java
public class BookMarkFragment extends Fragment {
@Inject
BookmarkRepository bookmarkRepository;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_bookmark, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// ブックマーク追加ボタンがクリックされた時の処理
view.findViewById(R.id.AddBookmark).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String pageId = "current_page_id";
String title = "current_page_title";
// ブックマークを作成
Bookmark bookmark = new Bookmark(
UUID.randomUUID().toString(),
title,
pageId,
System.currentTimeMillis()
);
// ブックマークを保存
bookmarkRepository.addBookmark(bookmark);
// ユーザーに成功メッセージを表示
Toast.makeText(getContext(), "ブックマークが追加されました", Toast.LENGTH_SHORT).show();
}
});
}
}

View File

@ -0,0 +1,46 @@
package one.nem.lacerta.component.viewer;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import javax.inject.Inject;
// BookMarkListFragment.java
public class BookMarkListFragment extends Fragment {
@Inject
BookmarkRepository bookmarkRepository;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_bookmark_list, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
// ブックマーク一覧を取得
List<Bookmark> bookmarks = bookmarkRepository.getAllBookmarks();
// ブックマーク一覧を表示するRecyclerViewのセットアップ
RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
BookmarkAdapter adapter = new BookmarkAdapter(bookmarks, new OnBookmarkClickListener() {
@Override
public void onBookmarkClick(Bookmark selectedBookmark) {
// ブックマークが選択された時の処理
// : ブックマークに関連するページを表示する
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
recyclerView.setAdapter(adapter);
}
}

View File

@ -0,0 +1,56 @@
package one.nem.lacerta.component.viewer;
// Bookmark.java
public class Bookmark {
private String id; // ブックマークの一意の識別子
private String title;
private String pageId; // ブックマークが参照するページの識別子
private long timestamp; // ブックマークが作成された時刻
public Bookmark(String id, String title, String pageId, long timestamp) {
this.id = id;
this.title = title;
this.pageId = pageId;
this.timestamp = timestamp;
}
public Bookmark() {
// Empty constructor
}
// Getter
public String getId() {
return id;
}
public String getTitle() {
return title;
}
public String getPageId() {
return pageId;
}
public long getTimestamp() {
return timestamp;
}
// Setter
public void setId(String id) {
this.id = id;
}
public void setTitle(String title) {
this.title = title;
}
public void setPageId(String pageId) {
this.pageId = pageId;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}

View File

@ -0,0 +1,21 @@
package one.nem.lacerta.component.viewer;
// BookmarkRepository.java
import java.util.ArrayList;
import java.util.List;
public class BookmarkRepository {
private List<Bookmark> bookmarks = new ArrayList<>();
public List<Bookmark> getAllBookmarks() {
return bookmarks;
}
public void addBookmark(Bookmark bookmark) {
bookmarks.add(bookmark);
}
public void removeBookmark(Bookmark bookmark) {
bookmarks.remove(bookmark);
}
}