From cf7958163834edebcadbe73b34718c21f02dfa9d Mon Sep 17 00:00:00 2001 From: nero Date: Wed, 24 Jan 2024 10:22:57 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=96=E3=82=AF=E3=83=9E=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=83=BB=E4=BF=9D=E5=AD=98=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component/viewer/BookMarkFragment.java | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/BookMarkFragment.java b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/BookMarkFragment.java index 33e579de..75573893 100644 --- a/component/viewer/src/main/java/one/nem/lacerta/component/viewer/BookMarkFragment.java +++ b/component/viewer/src/main/java/one/nem/lacerta/component/viewer/BookMarkFragment.java @@ -1,10 +1,11 @@ package one.nem.lacerta.component.viewer; import android.os.Bundle; +import android.view.GestureDetector; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.widget.Button; import android.widget.Toast; import androidx.fragment.app.Fragment; @@ -15,9 +16,12 @@ import javax.inject.Inject; // BookMarkFragment.java public class BookMarkFragment extends Fragment { + @Inject BookmarkRepository bookmarkRepository; + private GestureDetector gestureDetector; + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_bookmark, container, false); @@ -27,27 +31,41 @@ public class BookMarkFragment extends Fragment { 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"; + gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() { + @Override + public boolean onDoubleTap(MotionEvent e) { + // ダブルタップが検出された時の処理 + handleDoubleTap(); + return true; + } + }); - // ブックマークを作成 - Bookmark bookmark = new Bookmark( - UUID.randomUUID().toString(), - title, - pageId, - System.currentTimeMillis() - ); - - // ブックマークを保存 - bookmarkRepository.addBookmark(bookmark); - - // ユーザーに成功メッセージを表示 - Toast.makeText(getContext(), "ブックマークが追加されました", Toast.LENGTH_SHORT).show(); - } + // ブックマークボタンがダブルタップされた時の処理 + view.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + return gestureDetector.onTouchEvent(event); + } }); } + + private void handleDoubleTap() { + // ダブルタップが検出された時の処理 + // ブックマークを作成 + 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(); + } }