| | package com.example.citrusclient.views; |
---|
| | |
---|
| | import android.annotation.SuppressLint; |
---|
| | import android.content.Context; |
---|
| | import android.graphics.Color; |
---|
| | import android.os.Bundle; |
---|
| | |
---|
| | import androidx.annotation.NonNull; |
---|
| | import androidx.annotation.Nullable; |
---|
| |
---|
| | import android.view.View; |
---|
| | import android.view.ViewGroup; |
---|
| | import android.widget.AdapterView; |
---|
| | import android.widget.ArrayAdapter; |
---|
| | import android.widget.Button; |
---|
| | import android.widget.EditText; |
---|
| | import android.widget.LinearLayout; |
---|
| | import android.widget.SearchView; |
---|
| | import android.widget.Spinner; |
---|
| | import android.widget.TextView; |
---|
| | |
---|
| | import com.example.citrusclient.R; |
---|
| | import com.example.citrusclient.models.Book; |
---|
| | import com.example.citrusclient.viewmodels.PublicBooksViewModel; |
---|
| | import com.example.citrusclient.viewmodels.FavoritesViewModel; |
---|
| | |
---|
| | import java.util.ArrayList; |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | /** |
---|
| | * A simple {@link Fragment} subclass. |
---|
| | * Use the {@link SearchFragment#newInstance} factory method to |
---|
| |
---|
| | private MyAdapter adapter; |
---|
| | private RecyclerView recyclerView; |
---|
| | private RecyclerView recyclerView1; // sort_by用のRecyclerView |
---|
| | private PublicBooksViewModel publicBooksViewModel; |
---|
| | private FavoritesViewModel favoritesViewModel; |
---|
| | |
---|
| | private Integer sortBy = 0; |
---|
| | |
---|
| | EditText editText; |
---|
| |
---|
| | mParam2 = getArguments().getString(ARG_PARAM2); |
---|
| | } |
---|
| | |
---|
| | publicBooksViewModel = new ViewModelProvider(this).get(PublicBooksViewModel.class); |
---|
| | favoritesViewModel = new ViewModelProvider(this).get(FavoritesViewModel.class); |
---|
| | } |
---|
| | |
---|
| | // @Override |
---|
| | // public View onCreateView(LayoutInflater inflater, ViewGroup container, |
---|
| |
---|
| | // フラグメントのレイアウトをインフレート |
---|
| | return inflater.inflate(R.layout.fragment_search, container, false); |
---|
| | } |
---|
| | @SuppressLint("WrongViewCast") |
---|
| | // public void onViewCreated(@NonNull View view, @NonNull Bundle saveInstanceState){ |
---|
| | // super.onViewCreated(view, saveInstanceState); |
---|
| | // |
---|
| | // adapter = new MyAdapter(new ArrayList<>()); |
---|
| | // RecyclerView recyclerView = view.findViewById(R.id.public_list); |
---|
| | // recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); |
---|
| | // recyclerView.setAdapter(adapter); |
---|
| | // RecyclerView recyclerView1 = view.findViewById(R.id.sort_by); |
---|
| | // recyclerView1.setLayoutManager(new LinearLayoutManager(view.getContext())); |
---|
| | // recyclerView1.setAdapter(adapter); |
---|
| | // |
---|
| | // publicBooksViewModel.getAllBooksLiveData().observe(getViewLifecycleOwner(), new Observer<ArrayList<Book>>() { |
---|
| | // @Override |
---|
| | // public void onChanged(ArrayList<Book> books) { |
---|
| | // if (books != null) { |
---|
| | // publicList = new ArrayList<>(books); |
---|
| | // adapter.setBooks(publicList); // アダプターに新しいリストを渡す |
---|
| | // } |
---|
| | // } |
---|
| | // }); |
---|
| | // |
---|
| | // publicBooksViewModel.loadAllBooks(); |
---|
| | // |
---|
| | // view.findViewById(R.id.rbLike).setOnClickListener(view1 -> sortBy = 0);// |
---|
| | // view.findViewById(R.id.rbOld).setOnClickListener(view1 -> sortBy = 1);// |
---|
| | // //view.findViewById(R.id.rbNew).setOnClickListener(view1 -> sortBy = 2);//favorite |
---|
| | // |
---|
| | // SearchView searchView = view.findViewById(R.id.search_word); |
---|
| | // searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { |
---|
| | // @Override |
---|
| | // public boolean onQueryTextSubmit(String query) { |
---|
| | // loadSearchResults(query, sortBy); |
---|
| | // Log.d(TAG, "Search query: " + query); |
---|
| | // return true; |
---|
| | // } |
---|
| | // public boolean onQueryTextChange(String newText) { |
---|
| | // adapter.filter(newText); // フィルタリングを実行 |
---|
| | // return true; |
---|
| | // } |
---|
| | // |
---|
| | // }); |
---|
| | // } |
---|
| | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { |
---|
| | adapter = new MyAdapter(new ArrayList<>()); |
---|
| | RecyclerView recyclerView = view.findViewById(R.id.public_list); |
---|
| | recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext())); |
---|
| |
---|
| | if(title != "") { |
---|
| | if (accountId != "") { |
---|
| | publicBooksViewModel.loadSearchBooks(title, accountId, sortBy);//title,accountidでの検索 |
---|
| | System.out.println("title: "+title+" accountId: "+accountId+" sortBy: "+sortBy); |
---|
| | }/* else { |
---|
| | publicBooksViewModel.loadSearchTitleBooks(title, sortBy);//titleのみの検索 |
---|
| | } |
---|
| | if (accountId != null) { |
---|
| | publicBooksViewModel.loadSearchAccountIdBooks(accountId, sortBy);//accountidでの検索 |
---|
| | } */else { |
---|
| | }else { |
---|
| | publicBooksViewModel.loadAllBooks(); |
---|
| | } |
---|
| | // titleとaccountIdを使って検索 |
---|
| | } |
---|
| | |
かみ合わせの都合上FaboriteManagerとFavoriteRestも微修正
いいね実装!!
aae379a
intomaster
fromSearchFragment
on 10 Oct