package com.example.nemophila; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import com.example.nemophila.viewmodels.PostsViewModel; import java.util.ArrayList; import java.util.List; public class RequestingActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_requesting); //Nemophilaから自分のuidとtokenを取得 String uid = ((Nemophila)getApplication()).getUid(); String token = ((Nemophila)getApplication()).getToken(); String requestingId; //左上のボタンでマイページへ遷移 Button returnButton = (Button)findViewById(R.id.requestingAcReturnButton); returnButton.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){ Intent intent = new Intent(getApplication(), MyPageActivity.class); startActivity(intent); } }); //フレンド検索ボタン Button requestingButton = (Button)findViewById(R.id.requestingSearchButton); requestingButton.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ //入力されたIDを取得 EditText editSearchId = (EditText) findViewById(R.id.inputRequestingId); String searchingId = editSearchId.getText().toString(); //取得したIDのユーザー名を受け取り、OKならreqyestingIdに入れる String requestingName; //申請を送るダイアログを表示 RequestingDialogFragment dialog = new RequestingDialogFragment(); dialog.show(getSupportFragmentManager(), "Requesting_dialog"); //OK押したら申請するメソッドにuid、requestingId、tokenを渡す } }); //RecyclerView(表示の設定、直接表示するところはLivedataを購読しているonChanged内にしたい) List<ShopActivity.ShopAcDataModel> requestingDataSet = new ArrayList<>(); List<RequestingActivity.RequestingDataModel> RequestingDataList = new ArrayList<>(); //xmlからrvにRecyclerViewを取得、アダプターを宣言 RecyclerView rv = (RecyclerView) findViewById(R.id.requestingList); RequestingActivity.RequestingAdapter adapter = new RequestingActivity.RequestingAdapter(RequestingDataList); //一行ずつを縦に(LinearLayout)表示するLayoutManagerを宣言 LinearLayoutManager llm = new LinearLayoutManager(this); // RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL); rv.addItemDecoration(itemDecoration); rv.setHasFixedSize(true); rv.setLayoutManager(llm); //表示テスト用に仮データ List<RequestingDataModel> testDataSet = new ArrayList<>(); for (int i = 0; i < 15; i++) { RequestingDataModel data = new RequestingDataModel(); data.setName("ネモフィラ太郎"+ i + "号(テスト)"); testDataSet.add(data); } //onChange内に書くべき表示部分 adapter.setList(testDataSet); rv.setAdapter(adapter); } //RecyclerViewのための内部クラス //とりあえずnameのみで作成 //Adapter public class RequestingAdapter extends RecyclerView.Adapter<RequestingActivity.RequestingViewHolder> { private List<RequestingActivity.RequestingDataModel> list; public RequestingAdapter(List<RequestingActivity.RequestingDataModel> list) { this.list =list; } public void setList(List<RequestingActivity.RequestingDataModel> list) { this.list = list; } @NonNull @Override public RequestingActivity.RequestingViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_requesting_activity, parent,false); RequestingActivity.RequestingViewHolder vh = new RequestingActivity.RequestingViewHolder(inflate); return vh; } @Override public void onBindViewHolder(@NonNull RequestingActivity.RequestingViewHolder holder, int position) { holder.nameView.setText(list.get(position).getName()); } @Override public int getItemCount() { return list.size(); } } //ViewHolder public class RequestingViewHolder extends RecyclerView.ViewHolder { public TextView nameView; public RequestingViewHolder(@NonNull View itemView) { super(itemView); nameView = (TextView) itemView.findViewById(R.id.requestingName); } } //DataModel public static class RequestingDataModel { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } }