| |
---|
| | |
---|
| | import com.example.cosmosclient.R; |
---|
| | import com.example.cosmosclient.app.Cosmos; |
---|
| | 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.io.IOException; |
---|
| | import java.text.Collator; |
---|
| | import java.util.ArrayList; |
---|
| | import java.util.Collections; |
---|
| | import java.util.Comparator; |
---|
| | import java.util.Date; |
---|
| | import java.util.List; |
---|
| | import java.util.Locale; |
---|
| | import java.util.TimeZone; |
---|
| | |
---|
| | import retrofit2.Call; |
---|
| | import retrofit2.Callback; |
---|
| | import retrofit2.Response; |
---|
| |
---|
| | implements NavigationView.OnNavigationItemSelectedListener { |
---|
| | |
---|
| | Toast toast; //動作テスト用 |
---|
| | |
---|
| | |
---|
| | |
---|
| | //Request List |
---|
| | public static ArrayList<Request> requestlist = new ArrayList<>(); |
---|
| | Requests requests; |
---|
| | |
---|
| | //Color制御 |
---|
| | boolean productColorFlag = true; //買うもの (true:白, false:黒) |
---|
| | boolean deadlineColorFlag = true; //購入期限 |
---|
| |
---|
| | LinearLayout locationView; |
---|
| | LinearLayout nameView; |
---|
| | |
---|
| | Collator collator = Collator.getInstance(Locale.JAPANESE); |
---|
| | |
---|
| | // TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | // TableLayout accomplishedRequesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | |
---|
| | //productOnClick |
---|
| | public View.OnClickListener productOnClick = new View.OnClickListener() { |
---|
| | @Override |
---|
| |
---|
| | if (!productColorFlag) { |
---|
| | product.setColorFilter(null); |
---|
| | productColorFlag = true; |
---|
| | ResetRequestListTable(); |
---|
| | AddRequestListTable(requestlist); |
---|
| | AddRequestListTable(requests); |
---|
| | } else { |
---|
| | if(deadlineRotationFlag) { |
---|
| | deadlineRotationFlag = false; |
---|
| | } else { |
---|
| |
---|
| | if (!deadlineColorFlag) { |
---|
| | deadline.setColorFilter(null); |
---|
| | deadlineColorFlag = true; |
---|
| | ResetRequestListTable(); |
---|
| | AddRequestListTable(requestlist); |
---|
| | AddRequestListTable(requests); |
---|
| | if(!deadlineRotationFlag) { |
---|
| | deadline.setRotation(0); |
---|
| | } |
---|
| | } else { |
---|
| |
---|
| | if (!locationColorFlag) { |
---|
| | location.setColorFilter(null); |
---|
| | locationColorFlag = true; |
---|
| | ResetRequestListTable(); |
---|
| | AddRequestListTable(requestlist); |
---|
| | AddRequestListTable(requests); |
---|
| | } else { |
---|
| | if(deadlineRotationFlag) { |
---|
| | deadlineRotationFlag = false; |
---|
| | } else { |
---|
| |
---|
| | if (!nameColorFlag) { |
---|
| | name.setColorFilter(null); |
---|
| | nameColorFlag = true; |
---|
| | ResetRequestListTable(); |
---|
| | AddRequestListTable(requestlist); |
---|
| | AddRequestListTable(requests); |
---|
| | } else { |
---|
| | if(deadlineRotationFlag) { |
---|
| | deadlineRotationFlag = false; |
---|
| | } else { |
---|
| |
---|
| | } |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //requestListRowOnClick |
---|
| | // public View.OnClickListener requestListRowOnClick = new View.OnClickListener() { |
---|
| | // @Override |
---|
| | // public void onClick(View view) { |
---|
| | // requesttable.removeView(view); |
---|
| | // } |
---|
| | // }; |
---|
| | |
---|
| | //productSortComparator |
---|
| | public Comparator<Request> productSortComparator = new Comparator<Request>() { |
---|
| | @Override |
---|
| | public int compare(Request r1, Request r2) { |
---|
| | return collator.compare(r1.getProduct().toString(), r2.getProduct().toString()); |
---|
| | return collator.compare(r1.getProduct(), r2.getProduct()); |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | //deadlineSortComparator |
---|
| |
---|
| | //nameSortComparator |
---|
| | public Comparator<Request> nameSortComparator = new Comparator<Request>() { |
---|
| | @Override |
---|
| | public int compare(Request r1, Request r2) { |
---|
| | return collator.compare(r1.getName().toString(), r2.getName().toString()); |
---|
| | return collator.compare(r1.getIssuer().getName(), r2.getIssuer().getName()); |
---|
| | } |
---|
| | }; |
---|
| | |
---|
| | @Override |
---|
| | protected void onCreate(Bundle savedInstanceState) { |
---|
| | super.onCreate(savedInstanceState); |
---|
| | setContentView(R.layout.activity_request_list); |
---|
| | |
---|
| | // //retrofitの処理 |
---|
| | // final Retrofit retrofit = new Retrofit.Builder() |
---|
| | // .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/") |
---|
| | // .addConverterFactory(JacksonConverterFactory.create()) |
---|
| | // .build(); |
---|
| | // |
---|
| | // //interfaceから実装を取得 |
---|
| | // final GroupsRest requestsService = retrofit.create(GroupsRest.class); |
---|
| | // |
---|
| | // //RequestList取得するための必要な情報 |
---|
| | // Cosmos app = (Cosmos) getApplication(); |
---|
| | // final String gid = app.getCurentGroup().getgId(); |
---|
| | // final String token = app.getToken(); |
---|
| | // |
---|
| | // final Call<ArrayList<Request>> requestsListByGidCall = requestsService.getRequestsListByGid(gid, token); |
---|
| | // |
---|
| | // //サーバからのレスポンス |
---|
| | // requestsListByGidCall.enqueue(new Callback<Request>() { |
---|
| | // //成功時 |
---|
| | // @Override |
---|
| | // public void onResponse(Call<Request> call, Response<Request> response) { |
---|
| | // if (response.isSuccessful()) { |
---|
| | // Request result = response.body(); |
---|
| | // |
---|
| | // Call<Request> requestsDetailByGidAndRidcall = requestsService.getRequestsDetailByGidAndRid(gid, token, result.getrId()); |
---|
| | // //サーバからのレスポンス |
---|
| | // requestsDetailByGidAndRidcall.enqueue(new Callback<Request>() { |
---|
| | // //成功時 |
---|
| | // @Override |
---|
| | // public void onResponse(Call<Request> call, Response<Request> response) { |
---|
| | // if (response.isSuccessful()) { |
---|
| | // Request result = response.body(); |
---|
| | // |
---|
| | // |
---|
| | // Toast.makeText(RequestListActivity.this, "RequestList詳細を取得しました", Toast.LENGTH_SHORT).show(); |
---|
| | // } else { |
---|
| | // //onFailureでキャッチできないエラーの処理 |
---|
| | // Toast.makeText(RequestListActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); |
---|
| | // } |
---|
| | // } |
---|
| | // //失敗時 |
---|
| | // @Override |
---|
| | // public void onFailure(Call<Request> call, Throwable t) { |
---|
| | // //t.printStackTrace(); |
---|
| | // Toast.makeText(RequestListActivity.this, "RequestList詳細の取得失敗しました", Toast.LENGTH_SHORT).show(); |
---|
| | // } |
---|
| | // }); |
---|
| | // Toast.makeText(RequestListActivity.this, "RequestListを取得しました", Toast.LENGTH_SHORT).show(); |
---|
| | // } else { |
---|
| | // //onFailureでキャッチできないエラーの処理 |
---|
| | // Toast.makeText(RequestListActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); |
---|
| | // } |
---|
| | // } |
---|
| | // |
---|
| | // //失敗時 |
---|
| | // @Override |
---|
| | // public void onFailure(Call<Request> call, Throwable t) { |
---|
| | // //t.printStackTrace(); |
---|
| | // Toast.makeText(RequestListActivity.this, "RequestListの取得失敗しました", Toast.LENGTH_SHORT).show(); |
---|
| | // } |
---|
| | // }); |
---|
| | |
---|
| | Toolbar toolbar = (Toolbar) findViewById(R.id.requestlist_toolbar); |
---|
| | setSupportActionBar(toolbar); |
---|
| | |
---|
| |
---|
| | startActivity(new Intent(RequestListActivity.this, AddRequestActivity.class)); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | requestlist.clear(); |
---|
| | |
---|
| | //Add Request |
---|
| | requestlist.add(new Request("わさび", new Date(2019, 6, 7), 205002, "a-hongo")); |
---|
| | requestlist.add(new Request("ケーキ" , new Date(2019, 6, 6), 205001, "t-sugisawa")); |
---|
| | requestlist.add(new Request("からし", new Date(2018, 6, 4), 205002, "n-kande")); |
---|
| | |
---|
| | //Add RequestList Table |
---|
| | AddRequestListTable(requestlist); |
---|
| | |
---|
| | //LEFT hamburger button |
---|
| | DrawerLayout requestlistDrawer = (DrawerLayout) findViewById(R.id.request_list_drawer_layout); |
---|
| | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( |
---|
| | this, requestlistDrawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); |
---|
| |
---|
| | locationView.setOnClickListener(locationOnClick); |
---|
| | |
---|
| | nameView = (LinearLayout)findViewById(R.id.name); |
---|
| | nameView.setOnClickListener(nameOnClick); |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| | 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(); |
---|
| | final String token = app.getToken(); |
---|
| | final boolean detail = true; |
---|
| | int quantity = 20; |
---|
| | |
---|
| | final Call<Requests> requestsListByGidCall = requestsService.getRequestsListByGid(gId, token, detail, quantity); |
---|
| | |
---|
| | //サーバからのレスポンス |
---|
| | requestsListByGidCall.enqueue(new Callback<Requests>() { |
---|
| | //成功時 |
---|
| | @Override |
---|
| | public void onResponse(Call<Requests> call, Response<Requests> response) { |
---|
| | if (response.isSuccessful()) { |
---|
| | TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo")); |
---|
| | requests = response.body(); |
---|
| | |
---|
| | //Add RequestList Table |
---|
| | AddRequestListTable(requests); |
---|
| | |
---|
| | Toast.makeText(RequestListActivity.this, "RequestListを取得しました", Toast.LENGTH_SHORT).show(); |
---|
| | } else { |
---|
| | try { |
---|
| | System.out.println("a" + response.errorBody().string()); |
---|
| | } catch (IOException e) { |
---|
| | e.printStackTrace(); |
---|
| | } |
---|
| | //onFailureでキャッチできないエラーの処理 |
---|
| | Toast.makeText(RequestListActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | //失敗時 |
---|
| | @Override |
---|
| | public void onFailure(Call<Requests> call, Throwable t) { |
---|
| | t.printStackTrace(); |
---|
| | Toast.makeText(RequestListActivity.this, "RequestListの取得失敗しました", Toast.LENGTH_SHORT).show(); |
---|
| | } |
---|
| | }); |
---|
| | |
---|
| | } |
---|
| | |
---|
| | @Override |
---|
| |
---|
| | super.onRestart(); |
---|
| | |
---|
| | ResetRequestListTable(); |
---|
| | |
---|
| | //Add RequestList Table |
---|
| | AddRequestListTable(requestlist); |
---|
| | requests.clearRequest(); |
---|
| | |
---|
| | // //Add RequestList Table |
---|
| | // AddRequestListTable(requests); |
---|
| | } |
---|
| | |
---|
| | @SuppressWarnings("StatementWithEmptyBody") |
---|
| | @Override |
---|
| |
---|
| | requestlistDrawer.closeDrawer(GravityCompat.START); |
---|
| | return true; |
---|
| | } |
---|
| | |
---|
| | private int ConvertMonth(int i, ArrayList<Request> requestList) { |
---|
| | return requestList.get(i).getDeadline().getMonth() + 1; |
---|
| | private int ConvertMonth(int i, Requests requests) { |
---|
| | return requests.getRequest(i).getDeadline().getMonth() + 1; |
---|
| | } |
---|
| | |
---|
| | @TargetApi(Build.VERSION_CODES.O) |
---|
| | private void AddRequestListTable(ArrayList<Request> requestList) { |
---|
| | private void AddRequestListTable(Requests requests) { |
---|
| | Date now = new Date(); |
---|
| | TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | requesttable.setShrinkAllColumns(true); |
---|
| | |
---|
| | for (int i = 0; i < requestList.size(); i++) { |
---|
| | for (int i = 0; i < requests.getRequestCount(); i++) { |
---|
| | TableRow tableRow = new TableRow(this); |
---|
| | |
---|
| | TextView textProduct = new TextView(this); |
---|
| | textProduct.setText(requestList.get(i).getProduct()); |
---|
| | textProduct.setText(requests.getRequest(i).getProduct()); |
---|
| | textProduct.setTextSize(20); |
---|
| | textProduct.setHeight(150); |
---|
| | textProduct.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textProduct, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); |
---|
| |
---|
| | // } |
---|
| | // if (requestList.get(i).getDeadline().getMonth() == now.getMonth() && requestList.get(i).getDeadline().getDate() - now.getDate() == 1) { |
---|
| | // textDeadline.setText("明日まで"); |
---|
| | // } |
---|
| | textDeadline.setText(ConvertMonth(i, requestList) + "/" + requestList.get(i).getDeadline().getDate()); |
---|
| | if(requests.getRequest(i).getDeadline() != null) { |
---|
| | textDeadline.setText(ConvertMonth(i, requests) + "/" + requests.getRequest(i).getDeadline().getDate()); |
---|
| | } |
---|
| | // textDeadline.setText(now.getMonth() + "/" + now.getDate()); |
---|
| | textDeadline.setTextSize(20); |
---|
| | textDeadline.setHeight(150); |
---|
| | textDeadline.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textDeadline, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); |
---|
| | |
---|
| | TextView textLocation = new TextView(this); |
---|
| | textLocation.setText(Yolp.getInstance().getSubCategoryByCode(requestList.get(i).getLocation()).getSubName()); |
---|
| | if(Yolp.getInstance().getSubCategoryByCode(requests.getRequest(i).getLocation()) != null) { |
---|
| | textLocation.setText(Yolp.getInstance().getSubCategoryByCode(requests.getRequest(i).getLocation()).getSubName()); |
---|
| | } |
---|
| | |
---|
| | textLocation.setTextSize(20); |
---|
| | textLocation.setHeight(150); |
---|
| | textLocation.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textLocation, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); |
---|
| | |
---|
| | TextView textName = new TextView(this); |
---|
| | textName.setText(requestList.get(i).getName()); |
---|
| | textName.setText(requests.getRequest(i).getIssuer().getName()); |
---|
| | textName.setTextSize(20); |
---|
| | textName.setHeight(150); |
---|
| | textName.setGravity(Gravity.CENTER); |
---|
| | tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); |
---|
| | |
---|
| | // tableRow.setOnClickListener(requestListRowOnClick); |
---|
| | |
---|
| | requesttable.addView(tableRow); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | // Can not to reset! |
---|
| | private void ResetRequestListTable() { |
---|
| | TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); |
---|
| | int childCount = requesttable.getChildCount(); |
---|
| | |
---|
| |
---|
| | requesttable.removeViews(1, childCount - 1); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | private ArrayList<Request> SortProduct() { |
---|
| | ArrayList<Request> productsortRequestlist = (ArrayList<Request>) requestlist.clone(); |
---|
| | private Requests SortProduct() { |
---|
| | List<Request> productsortRequestlist = (List<Request>) requests.getRequests(); |
---|
| | |
---|
| | Collections.sort(productsortRequestlist, productSortComparator); |
---|
| | return productsortRequestlist; |
---|
| | } |
---|
| | |
---|
| | private ArrayList<Request> SortDeadline() { |
---|
| | ArrayList<Request> deadlinesortRequestlist = (ArrayList<Request>) requestlist.clone(); |
---|
| | return new Requests(productsortRequestlist); |
---|
| | } |
---|
| | |
---|
| | private Requests SortDeadline() { |
---|
| | List<Request> deadlinesortRequestlist = (List<Request>) requests.getRequests(); |
---|
| | |
---|
| | Collections.sort(deadlinesortRequestlist, deadlineSortComparator); |
---|
| | return deadlinesortRequestlist; |
---|
| | } |
---|
| | |
---|
| | private ArrayList<Request> ReverseDeadline() { |
---|
| | ArrayList<Request> deadlinesortRequestlist = (ArrayList<Request>) requestlist.clone(); |
---|
| | return new Requests(deadlinesortRequestlist); |
---|
| | } |
---|
| | |
---|
| | private Requests ReverseDeadline() { |
---|
| | List<Request> deadlinesortRequestlist = (List<Request>) requests.getRequests(); |
---|
| | |
---|
| | Collections.sort(deadlinesortRequestlist, deadlineReverseComparator); |
---|
| | return deadlinesortRequestlist; |
---|
| | } |
---|
| | |
---|
| | private ArrayList<Request> SortLocation() { |
---|
| | ArrayList<Request> locationsortRequestlist = (ArrayList<Request>) requestlist.clone(); |
---|
| | return new Requests(deadlinesortRequestlist); |
---|
| | } |
---|
| | |
---|
| | private Requests SortLocation() { |
---|
| | List<Request> locationsortRequestlist = (List<Request>) requests.getRequests(); |
---|
| | |
---|
| | Collections.sort(locationsortRequestlist, locationSortComparator); |
---|
| | return locationsortRequestlist; |
---|
| | } |
---|
| | |
---|
| | private ArrayList<Request> SortName() { |
---|
| | ArrayList<Request> namesortRequestlist = (ArrayList<Request>) requestlist.clone(); |
---|
| | return new Requests(locationsortRequestlist); |
---|
| | } |
---|
| | |
---|
| | private Requests SortName() { |
---|
| | List<Request> namesortRequestlist = (List<Request>) requests.getRequests(); |
---|
| | |
---|
| | Collections.sort(namesortRequestlist, nameSortComparator); |
---|
| | return namesortRequestlist; |
---|
| | return new Requests(namesortRequestlist); |
---|
| | } |
---|
| | } |
---|
| | |