mirror of
				https://github.com/lacerta-doc/Lacerta.git
				synced 2025-09-09 12:09:25 +00:00 
			
		
		
		
	ブクマ作成・保存機能
This commit is contained in:
		
							parent
							
								
									7beecca0da
								
							
						
					
					
						commit
						cf79581638
					
				| 
						 | 
					@ -1,10 +1,11 @@
 | 
				
			||||||
package one.nem.lacerta.component.viewer;
 | 
					package one.nem.lacerta.component.viewer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import android.os.Bundle;
 | 
					import android.os.Bundle;
 | 
				
			||||||
 | 
					import android.view.GestureDetector;
 | 
				
			||||||
import android.view.LayoutInflater;
 | 
					import android.view.LayoutInflater;
 | 
				
			||||||
 | 
					import android.view.MotionEvent;
 | 
				
			||||||
import android.view.View;
 | 
					import android.view.View;
 | 
				
			||||||
import android.view.ViewGroup;
 | 
					import android.view.ViewGroup;
 | 
				
			||||||
import android.widget.Button;
 | 
					 | 
				
			||||||
import android.widget.Toast;
 | 
					import android.widget.Toast;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import androidx.fragment.app.Fragment;
 | 
					import androidx.fragment.app.Fragment;
 | 
				
			||||||
| 
						 | 
					@ -15,9 +16,12 @@ import javax.inject.Inject;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// BookMarkFragment.java
 | 
					// BookMarkFragment.java
 | 
				
			||||||
public class BookMarkFragment extends Fragment {
 | 
					public class BookMarkFragment extends Fragment {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Inject
 | 
					    @Inject
 | 
				
			||||||
    BookmarkRepository bookmarkRepository;
 | 
					    BookmarkRepository bookmarkRepository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private GestureDetector gestureDetector;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 | 
					    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
 | 
				
			||||||
        return inflater.inflate(R.layout.fragment_bookmark, container, false);
 | 
					        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) {
 | 
					    public void onViewCreated(View view, Bundle savedInstanceState) {
 | 
				
			||||||
        super.onViewCreated(view, savedInstanceState);
 | 
					        super.onViewCreated(view, savedInstanceState);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // ブックマーク追加ボタンがクリックされた時の処理
 | 
					        gestureDetector = new GestureDetector(getContext(), new GestureDetector.SimpleOnGestureListener() {
 | 
				
			||||||
        view.findViewById(R.id.AddBookmark).setOnClickListener(new View.OnClickListener() {
 | 
					            @Override
 | 
				
			||||||
        @Override
 | 
					            public boolean onDoubleTap(MotionEvent e) {
 | 
				
			||||||
            public void onClick(View v) {
 | 
					                // ダブルタップが検出された時の処理
 | 
				
			||||||
                String pageId = "current_page_id";
 | 
					                handleDoubleTap();
 | 
				
			||||||
                String title = "current_page_title";
 | 
					                return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // ブックマークを作成
 | 
					        // ブックマークボタンがダブルタップされた時の処理
 | 
				
			||||||
            Bookmark bookmark = new Bookmark(
 | 
					        view.setOnTouchListener(new View.OnTouchListener() {
 | 
				
			||||||
                    UUID.randomUUID().toString(),
 | 
					            @Override
 | 
				
			||||||
                    title,
 | 
					            public boolean onTouch(View v, MotionEvent event) {
 | 
				
			||||||
                    pageId,
 | 
					                return gestureDetector.onTouchEvent(event);
 | 
				
			||||||
                    System.currentTimeMillis()
 | 
					            }
 | 
				
			||||||
            );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // ブックマークを保存
 | 
					 | 
				
			||||||
                bookmarkRepository.addBookmark(bookmark);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                // ユーザーに成功メッセージを表示
 | 
					 | 
				
			||||||
            Toast.makeText(getContext(), "ブックマークが追加されました", Toast.LENGTH_SHORT).show();
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user