diff --git a/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java index ed8ce4c..3559520 100644 --- a/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java @@ -124,6 +124,7 @@ ResetRequestListTable(); AddRequestListTable(SortProduct()); } + isButtonShow(false); } }; @@ -165,6 +166,7 @@ AddRequestListTable(ReverseDeadline()); } } + isButtonShow(false); } }; @@ -199,6 +201,7 @@ ResetRequestListTable(); AddRequestListTable(SortLocation()); } + isButtonShow(false); } }; @@ -233,23 +236,35 @@ ResetRequestListTable(); AddRequestListTable(SortName()); } + isButtonShow(false); } }; //requestListRowOnClick - public View.OnLongClickListener requestListRowOnClick = new View.OnLongClickListener() { +// public View.OnClickListener requestListRowOnClick = new View.OnClickListener() { +// @Override +// public void onClick(View view) { +// isButtonShow(true); + +// requesttable.removeView(view); +// for(View selectedRow : selectedRequestList.values()) { +// if(view.equals(selectedRow)) { +// selectedRequestList.remove(selectedRow); +// view.setBackgroundColor(Color.rgb(255, 255, 255)); +// Toast.makeText(RequestListActivity.this, view + " Reset Clicked!", Toast.LENGTH_SHORT).show(); +// } +// } +// selectedRequestList.put(requesttable.indexOfChild(view), view); +// view.setBackgroundColor(Color.rgb(200, 200, 200)); +// Toast.makeText(RequestListActivity.this, requesttable.indexOfChild(view) + "row Clicked!", Toast.LENGTH_SHORT).show(); +// } +// }; + + //requestListRowOnLongClick + public View.OnLongClickListener requestListRowOnLongClick = new View.OnLongClickListener() { @Override public boolean onLongClick(View view) { - if(!deleteButton.isShown()) { - deleteButton.setVisibility(View.VISIBLE); - accomplishButton.setVisibility(View.VISIBLE); - - deleteButton.setClickable(true); - accomplishButton.setClickable(true); - - deleteButton.setOnClickListener(deleteOnClick); - accomplishButton.setOnClickListener(accomplishOnClick); - } + isButtonShow(true); // requesttable.removeView(view); for(View selectedRow : selectedRequestList.values()) { @@ -267,14 +282,62 @@ } }; - //nameOnClick + //deleteButtonOnClick public View.OnClickListener deleteOnClick = new View.OnClickListener() { @Override public void onClick(View view) { + + //RequestList取得するための必要な情報 +// Cosmos app = (Cosmos) getApplication(); +// final String gId = app.getCurentGroup().getgId(); +// final String uId = app.getuId(); +// final String token = app.getToken(); +// +// for(Integer i : selectedRequestList.keySet()) { +// Request request = requests.getRequest(i - 1); +// String deadline = null; +// if(request.getDeadline() != null) { +// deadline = String.format("%d-%02d-%02d %02d:%02d:%02d", request.getDeadline().getYear(), request.getDeadline().getMonth() + 1, request.getDeadline().getDate() + 1, 23, 59, 59); +// } +// final Call updateReqestCall = requestsService.updateRequest(gId, request.getrId(), uId, request.getProduct(), deadline, request.getLocation(), true, token); +// requests.removeRequest(i - 1); +// +// //サーバからのレスポンス +// updateReqestCall.enqueue(new Callback() { +// //成功時 +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()) { +// AddRequestsResponse result = response.body(); +// Toast.makeText(RequestListActivity.this, "RequestListを達成しました", Toast.LENGTH_SHORT).show(); +// +// ResetRequestListTable(); +// AddRequestListTable(requests); +// } else { +// try { +// System.out.println(response.errorBody().string()); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// +// //onFailureでキャッチできないエラーの処理 +// Toast.makeText(RequestListActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); +// } +// } +// +// //失敗時 +// @Override +// public void onFailure(Call call, Throwable t) { +// t.printStackTrace(); +// Toast.makeText(RequestListActivity.this, "RequestListの達成失敗しました", Toast.LENGTH_SHORT).show(); +// } +// }); +// } +// isButtonShow(false); } }; - //nameOnClick + //accomplishButtonOnClick public View.OnClickListener accomplishOnClick = new View.OnClickListener() { @Override public void onClick(View view) { @@ -325,8 +388,7 @@ } }); } - deleteButton.setVisibility(View.INVISIBLE); - accomplishButton.setVisibility(View.INVISIBLE); + isButtonShow(false); } }; @@ -431,16 +493,6 @@ protected void onStart() { super.onStart(); - //retrofitの処理 -// final Retrofit retrofit = new Retrofit.Builder() -//// .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/") -// .baseUrl("http://10.0.2.2:8080/") -// .addConverterFactory(JacksonConverterFactory.create()) -// .build(); - -// //interfaceから実装を取得 -// final GroupsRest requestsService = retrofit.create(GroupsRest.class); - //RequestList取得するための必要な情報 Cosmos app = (Cosmos) getApplication(); final String gId = app.getCurentGroup().getgId(); @@ -462,7 +514,7 @@ //Add RequestList Table AddRequestListTable(requests); - Toast.makeText(RequestListActivity.this, "RequestListを取得しました", Toast.LENGTH_SHORT).show(); +// Toast.makeText(RequestListActivity.this, "RequestListを取得しました", Toast.LENGTH_SHORT).show(); } else { try { System.out.println("a" + response.errorBody().string()); @@ -580,7 +632,7 @@ textName.setGravity(Gravity.CENTER); tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); - tableRow.setOnLongClickListener(requestListRowOnClick); + tableRow.setOnLongClickListener(requestListRowOnLongClick); requesttable.addView(tableRow); } @@ -597,6 +649,27 @@ } } + private void isButtonShow(boolean flag) { + if(!flag && deleteButton.isShown()) { //編集ボタンが見えているとき + deleteButton.setVisibility(View.INVISIBLE); + accomplishButton.setVisibility(View.INVISIBLE); + + deleteButton.setClickable(false); + accomplishButton.setClickable(false); + + selectedRequestList.clear(); + } else if(flag && !deleteButton.isShown()){ + deleteButton.setVisibility(View.VISIBLE); + accomplishButton.setVisibility(View.VISIBLE); + + deleteButton.setClickable(true); + accomplishButton.setClickable(true); + + deleteButton.setOnClickListener(deleteOnClick); + accomplishButton.setOnClickListener(accomplishOnClick); + } + } + private Requests SortProduct() { List productsortRequestlist = (List) requests.getRequests();