diff --git a/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java b/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java index e5dedeb..4348ce5 100644 --- a/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java @@ -96,7 +96,7 @@ String inputProduct = editTextProduct.getText().toString(); // 取得したテキストを TextView に張り付ける - RequestListActivity.requestlist.add((new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), selectedSubCategory, "a-hongo"))); + RequestListActivity.requestlist.add(0, (new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), selectedSubCategory, "a-hongo"))); finish(); } }); 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 7187cf3..de4d635 100644 --- a/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java @@ -44,6 +44,7 @@ boolean productColorFlag = true; //買うもの (true:白, false:黒) boolean deadlineColorFlag = true; //購入期限 boolean locationColorFlag = true; //場所 + boolean nameColorFlag = true; //名前 //Rotation制御 boolean deadlineRotationFlag = false; //(true:回転, false:未回転) @@ -58,6 +59,7 @@ ImageView product = (ImageView) findViewById(R.id.image_product); ImageView deadline = (ImageView) findViewById(R.id.image_deadline); ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); if (!productColorFlag) { product.setColorFilter(null); productColorFlag = true; @@ -75,6 +77,8 @@ deadlineColorFlag = true; location.setColorFilter(null); locationColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; ResetRequestListTable(); AddRequestListTable(SortProduct()); } @@ -89,6 +93,7 @@ ImageView product = (ImageView) findViewById(R.id.image_product); ImageView deadline = (ImageView) findViewById(R.id.image_deadline); ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); if (!deadlineColorFlag) { deadline.setColorFilter(null); deadlineColorFlag = true; @@ -102,6 +107,8 @@ productColorFlag = true; location.setColorFilter(null); locationColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; if (!deadlineRotationFlag) { deadline.setColorFilter(BLACK); @@ -115,7 +122,6 @@ ResetRequestListTable(); AddRequestListTable(ReverseDeadline()); } - } } }; @@ -128,6 +134,7 @@ ImageView product = (ImageView) findViewById(R.id.image_product); ImageView deadline = (ImageView) findViewById(R.id.image_deadline); ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); if (!locationColorFlag) { location.setColorFilter(null); locationColorFlag = true; @@ -145,12 +152,48 @@ productColorFlag = true; deadline.setColorFilter(null); deadlineColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; ResetRequestListTable(); AddRequestListTable(SortLocation()); } } }; + //locationOnClick + public View.OnClickListener nameOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(RequestListActivity.this, "name sorted", Toast.LENGTH_SHORT).show(); + ImageView product = (ImageView) findViewById(R.id.image_product); + ImageView deadline = (ImageView) findViewById(R.id.image_deadline); + ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); + if (!nameColorFlag) { + name.setColorFilter(null); + nameColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(requestlist); + } else { + if(deadlineRotationFlag) { + deadlineRotationFlag = false; + } else { + deadline.setRotation(0); + } + name.setColorFilter(BLACK); + nameColorFlag = false; + location.setColorFilter(null); + locationColorFlag = true; + product.setColorFilter(null); + productColorFlag = true; + deadline.setColorFilter(null); + deadlineColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(SortName()); + } + } + }; + //productSortComparator public Comparator productSortComparator = new Comparator() { @Override @@ -164,13 +207,6 @@ @Override public int compare(Request r1, Request r2) { return r1.getDeadline().compareTo(r2.getDeadline()); -// if (r1.getDeadline() == null || r2.getDeadline() == null) -// return 0; -// if(r1.getDeadline().getDate() >= r2.getDeadline().getDate() || r1.getDeadline().getMonth() > r2.getDeadline().getMonth()) -// return -1; -// if(r1.getDeadline().getDate() <= r2.getDeadline().getDate() || r1.getDeadline().getMonth() > r2.getDeadline().getMonth()) -// return 1; -// return r1.getDeadline().compareTo(r2.getDeadline()); } }; @@ -180,9 +216,9 @@ public int compare(Request r1, Request r2) { if (r1.getDeadline() == null || r2.getDeadline() == null) return 0; - if(r1.getDeadline().getDate() <= r2.getDeadline().getDate() || r1.getDeadline().getMonth() < r2.getDeadline().getMonth()) + if((r1.getDeadline().compareTo(r2.getDeadline())) == 1) return -1; - if(r1.getDeadline().getDate() >= r2.getDeadline().getDate() || r1.getDeadline().getMonth() < r2.getDeadline().getMonth()) + if((r1.getDeadline().compareTo(r2.getDeadline())) == -1) return 1; return r1.getDeadline().compareTo(r2.getDeadline()); } @@ -196,6 +232,14 @@ } }; + //nameSortComparator + public Comparator nameSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + return collator.compare(r1.getName().toString(), r2.getName().toString()); + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -243,6 +287,9 @@ LinearLayout locationView = (LinearLayout)findViewById(R.id.location); locationView.setOnClickListener(locationOnClick); + LinearLayout nameView = (LinearLayout)findViewById(R.id.name); + nameView.setOnClickListener(nameOnClick); + } @Override @@ -288,7 +335,7 @@ private void AddRequestListTable(ArrayList requestList) { Date now = new Date(); - for (int i = requestList.size()-1; i >= 0; i--) { + for (int i = 0; i < requestList.size(); i++) { TableRow tableRow = new TableRow(this); TextView textProduct = new TextView(this); @@ -371,6 +418,13 @@ Collections.sort(locationsortRequestlist, locationSortComparator); return locationsortRequestlist; } + + private ArrayList SortName() { + ArrayList namesortRequestlist = (ArrayList) requestlist.clone(); + + Collections.sort(namesortRequestlist, nameSortComparator); + return namesortRequestlist; + } } diff --git a/app/src/main/res/layout/app_bar_request_list.xml b/app/src/main/res/layout/app_bar_request_list.xml index bf60b74..f6b6957 100644 --- a/app/src/main/res/layout/app_bar_request_list.xml +++ b/app/src/main/res/layout/app_bar_request_list.xml @@ -22,124 +22,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/content_request_list.xml b/app/src/main/res/layout/content_request_list.xml index fe54b93..cc9ddf1 100644 --- a/app/src/main/res/layout/content_request_list.xml +++ b/app/src/main/res/layout/content_request_list.xml @@ -8,4 +8,148 @@ tools:context=".views.RequestListActivity" tools:showIn="@layout/app_bar_request_list"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file