| | package com.example.cosmosclient.views; |
---|
| | |
---|
| | import android.annotation.TargetApi; |
---|
| | import android.content.Intent; |
---|
| | import android.graphics.Color; |
---|
| | import android.os.Build; |
---|
| | import android.os.Bundle; |
---|
| | import android.support.design.widget.FloatingActionButton; |
---|
| | import android.support.design.widget.Snackbar; |
---|
| |
---|
| | import android.support.v7.app.AppCompatActivity; |
---|
| | import android.support.v7.widget.Toolbar; |
---|
| | import android.view.MenuItem; |
---|
| | import android.view.ViewGroup; |
---|
| | import android.widget.Button; |
---|
| | import android.widget.ImageView; |
---|
| | import android.widget.LinearLayout; |
---|
| | import android.widget.TableLayout; |
---|
| | import android.widget.TableRow; |
---|
| |
---|
| | import android.widget.Toast; |
---|
| | |
---|
| | import com.example.cosmosclient.R; |
---|
| | import com.example.cosmosclient.app.Cosmos; |
---|
| | import com.example.cosmosclient.entities.AddRequestsResponse; |
---|
| | import com.example.cosmosclient.entities.Request; |
---|
| | import com.example.cosmosclient.entities.Requests; |
---|
| | import com.example.cosmosclient.resources.GroupsRest; |
---|
| | import com.example.cosmosclient.yolp.Yolp; |
---|
| |
---|
| | import java.text.Collator; |
---|
| | import java.util.Collections; |
---|
| | import java.util.Comparator; |
---|
| | import java.util.Date; |
---|
| | import java.util.HashMap; |
---|
| | import java.util.List; |
---|
| | import java.util.Locale; |
---|
| | import java.util.TimeZone; |
---|
| | |
---|
| |
---|
| | |
---|
| | public class RequestListActivity extends AppCompatActivity |
---|
| | implements NavigationView.OnNavigationItemSelectedListener { |
---|
| | |
---|
| | //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); |
---|
| | |
---|
| | Toast toast; //動作テスト用 |
---|
| | |
---|
| | //Request List |
---|
| | Requests requests; |
---|
| |
---|
| | LinearLayout nameView; |
---|
| | |
---|
| | Collator collator = Collator.getInstance(Locale.JAPANESE); |
---|
| | |
---|
| | // TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | TableLayout requesttable; |
---|
| | // TableLayout accomplishedRequesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | |
---|
| | HashMap<Integer, View> selectedRequestList = new HashMap<>(); |
---|
| | |
---|
| | Button deleteButton; |
---|
| | Button accomplishButton; |
---|
| | |
---|
| | //productOnClick |
---|
| | public View.OnClickListener productOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| |
---|
| | } |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //locationOnClick |
---|
| | //nameOnClick |
---|
| | public View.OnClickListener nameOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | Toast.makeText(RequestListActivity.this, "name sorted", Toast.LENGTH_SHORT).show(); |
---|
| |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //requestListRowOnClick |
---|
| | // public View.OnClickListener requestListRowOnClick = new View.OnClickListener() { |
---|
| | // @Override |
---|
| | // public void onClick(View view) { |
---|
| | public View.OnLongClickListener requestListRowOnClick = 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); |
---|
| | } |
---|
| | |
---|
| | // 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(); |
---|
| | return false; |
---|
| | } |
---|
| | } |
---|
| | 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(); |
---|
| | return false; |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //nameOnClick |
---|
| | public View.OnClickListener deleteOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| | public void onClick(View view) { |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //nameOnClick |
---|
| | public View.OnClickListener accomplishOnClick = 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<AddRequestsResponse> updateReqestCall = requestsService.updateRequest(gId, request.getrId(), uId, request.getProduct(), deadline, request.getLocation(), true, token); |
---|
| | requests.removeRequest(i - 1); |
---|
| | |
---|
| | //サーバからのレスポンス |
---|
| | updateReqestCall.enqueue(new Callback<AddRequestsResponse>() { |
---|
| | //成功時 |
---|
| | @Override |
---|
| | public void onResponse(Call<AddRequestsResponse> call, Response<AddRequestsResponse> 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<AddRequestsResponse> call, Throwable t) { |
---|
| | t.printStackTrace(); |
---|
| | Toast.makeText(RequestListActivity.this, "RequestListの達成失敗しました", Toast.LENGTH_SHORT).show(); |
---|
| | } |
---|
| | }); |
---|
| | } |
---|
| | deleteButton.setVisibility(View.INVISIBLE); |
---|
| | accomplishButton.setVisibility(View.INVISIBLE); |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //productSortComparator |
---|
| | public Comparator<Request> productSortComparator = new Comparator<Request>() { |
---|
| | @Override |
---|
| |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //deadlineSortComparator |
---|
| | //!null処理 |
---|
| | public Comparator<Request> deadlineSortComparator = new Comparator<Request>() { |
---|
| | @Override |
---|
| | public int compare(Request r1, Request r2) { |
---|
| | return r1.getDeadline().compareTo(r2.getDeadline()); |
---|
| |
---|
| | |
---|
| | NavigationView navigationView = (NavigationView) findViewById(R.id.request_list_nav_view); |
---|
| | navigationView.setNavigationItemSelectedListener(this); |
---|
| | |
---|
| | requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | |
---|
| | productView = (LinearLayout) findViewById(R.id.product); |
---|
| | productView.setOnClickListener(productOnClick); |
---|
| | |
---|
| | deadlineView = (LinearLayout)findViewById(R.id.deadline); |
---|
| |
---|
| | locationView.setOnClickListener(locationOnClick); |
---|
| | |
---|
| | nameView = (LinearLayout)findViewById(R.id.name); |
---|
| | nameView.setOnClickListener(nameOnClick); |
---|
| | |
---|
| | deleteButton = findViewById(R.id.buttonDelete); |
---|
| | deleteButton.setVisibility(View.INVISIBLE); |
---|
| | |
---|
| | accomplishButton = findViewById(R.id.buttonAccomplish); |
---|
| | accomplishButton.setVisibility(View.INVISIBLE); |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | protected void onStart() { |
---|
| | super.onStart(); |
---|
| | |
---|
| | //retrofitの処理 |
---|
| | final Retrofit retrofit = new Retrofit.Builder() |
---|
| | .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/") |
---|
| | // 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); |
---|
| | // .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | // .build(); |
---|
| | |
---|
| | // //interfaceから実装を取得 |
---|
| | // final GroupsRest requestsService = retrofit.create(GroupsRest.class); |
---|
| | |
---|
| | //RequestList取得するための必要な情報 |
---|
| | Cosmos app = (Cosmos) getApplication(); |
---|
| | final String gId = app.getCurentGroup().getgId(); |
---|
| |
---|
| | |
---|
| | if (id == R.id.nav_member_list) { |
---|
| | // Handle the member list action |
---|
| | toast = Toast.makeText(RequestListActivity.this, "Next Member List Activity", Toast.LENGTH_LONG); |
---|
| | startActivity(new Intent(RequestListActivity.this, MemberListActivity.class)); |
---|
| | toast.show(); |
---|
| | } else if (id == R.id.nav_add_member) { |
---|
| | startActivity(new Intent(RequestListActivity.this, AddMemberActivity.class)); |
---|
| | } else if (id == R.id.nav_notification) { |
---|
| |
---|
| | |
---|
| | @TargetApi(Build.VERSION_CODES.O) |
---|
| | private void AddRequestListTable(Requests requests) { |
---|
| | Date now = new Date(); |
---|
| | TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | // TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | requesttable.setShrinkAllColumns(true); |
---|
| | |
---|
| | for (int i = 0; i < requests.getRequestCount(); i++) { |
---|
| | TableRow tableRow = new TableRow(this); |
---|
| |
---|
| | textName.setHeight(150); |
---|
| | textName.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); |
---|
| | |
---|
| | // tableRow.setOnClickListener(requestListRowOnClick); |
---|
| | tableRow.setOnLongClickListener(requestListRowOnClick); |
---|
| | |
---|
| | requesttable.addView(tableRow); |
---|
| | } |
---|
| | } |
---|
| |
---|
| | |
MemberListActivityへの遷移追加しました。
確認お願いいたします。
確認しました。お疲れ様です。
aa98733
intomaster
fromRequestListActivity
on 2 Oct 2019