diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f677df0..27624e1 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,7 +16,6 @@ - @@ -64,6 +63,9 @@ android:name=".views.AddRequestActivity" android:label="@string/title_activity_add_request" /> + + android:theme="@style/AppTheme.NoActionBar" /> + + + + + + - - - - - - + android:exported="false" /> - - - + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/cosmosclient/entities/RequestList.java b/app/src/main/java/com/example/cosmosclient/entities/RequestList.java index 3a5b319..c83e755 100644 --- a/app/src/main/java/com/example/cosmosclient/entities/RequestList.java +++ b/app/src/main/java/com/example/cosmosclient/entities/RequestList.java @@ -32,6 +32,15 @@ return requests.get(index); } + public Request getRequestById(String rId){ + for(Request request : getRequests()){ + if(request.getrId().equals(rId)){ + return request; + } + } + return null; + } + public void clearRequest() { requests.clear(); } @@ -40,9 +49,9 @@ requests.remove(index); } -// public void removeRequests(List requests) { -// requests.removeAll(requests); -// } + public void removeRequests(List requests) { + this.requests.removeAll(requests); + } public int getRequestCount() { return requests.size(); diff --git a/app/src/main/java/com/example/cosmosclient/resources/GroupsRest.java b/app/src/main/java/com/example/cosmosclient/resources/GroupsRest.java index a424816..10d3353 100644 --- a/app/src/main/java/com/example/cosmosclient/resources/GroupsRest.java +++ b/app/src/main/java/com/example/cosmosclient/resources/GroupsRest.java @@ -1,12 +1,13 @@ package com.example.cosmosclient.resources; +import com.example.cosmosclient.entities.AddRequestsResponse; import com.example.cosmosclient.entities.GroupListResponse; import com.example.cosmosclient.entities.CreateGroupResponse; -import com.example.cosmosclient.entities.AddRequestsResponse; import com.example.cosmosclient.entities.MemberListResponse; import com.example.cosmosclient.entities.RequestList; import retrofit2.Call; +import retrofit2.http.DELETE; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; @@ -35,6 +36,9 @@ @FormUrlEncoded Call updateRequest(@Path("gId") String gId, @Path("rId") String rId, @Field("uId") String uId, @Field("product") String product, @Field("deadline") String deadline, @Field("location") int location, @Field("done") boolean done, @Field("token") String token); + @DELETE("groups/{gId}/requests/{rId}") + Call deleteRequest(@Path("gId") String gId, @Path("rId") String rId, @Query("token") String token); + // @GET("{gId}/requests/{rId}") // Call getRequestsDetailByGidAndRid(@Path("gid") String gid, @Path("rid") String rid, @Query("token") String token); 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 425b4b6..483d1f0 100644 --- a/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java @@ -36,11 +36,23 @@ public class AddRequestActivity extends AppCompatActivity { private InputMethodManager inputMethodManager; - private ImageButton calenderButton; + //retrofitの処理 + private Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/rest/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); - private Integer deadlineYear; - private Integer deadlineMonth; - private Integer deadlineDayOfMonth; + //interfaceから実装を取得 + private GroupsRest addRequestsService = retrofit.create(GroupsRest.class); + + //RequestList取得するための必要な情報 + private Cosmos app = null; + private String uId = null; + private String gId = null; + private String token = null; + private String deadline = null; + + private ImageButton calenderButton; private EditText editTextProduct; private EditText editTextDeadline; @@ -48,10 +60,14 @@ private Spinner category; private Spinner subCategory; - private String selectedSubCategory; - private Button addButton; + private Integer deadlineYear; + private Integer deadlineMonth; + private Integer deadlineDayOfMonth; + + private String selectedSubCategory; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -67,7 +83,6 @@ category = findViewById(R.id.spinnerLocationCategory); subCategory = findViewById(R.id.spinnerLocationSubCategory); - setSpinner(category, Yolp.getInstance().getCategoryNames()); addButton = findViewById(R.id.buttonAdd); @@ -135,23 +150,11 @@ // エディットテキストのテキストを取得 String inputProduct = editTextProduct.getText().toString(); - //retrofitの処理 - final Retrofit retrofit = new Retrofit.Builder() - .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/rest/") -// .baseUrl("http://10.0.2.2:8080/") - .addConverterFactory(JacksonConverterFactory.create()) - .build(); - - //interfaceから実装を取得 - final GroupsRest addRequestsService = retrofit.create(GroupsRest.class); - //RequestList取得するための必要な情報 - Cosmos app = (Cosmos) getApplication(); - final String uId = app.getuId(); - final String gId = app.getCurentGroup().getgId(); - final String token = app.getToken(); - final boolean detail = true; - String deadline = null; + app = (Cosmos) getApplication(); + uId = app.getuId(); + gId = app.getCurentGroup().getgId(); + token = app.getToken(); if(deadlineYear != null && deadlineMonth != null && deadlineDayOfMonth != null) { deadline = String.format("%d-%02d-%02d %02d:%02d:%02d", deadlineYear, deadlineMonth +1, deadlineDayOfMonth, 23, 59, 59); @@ -167,16 +170,14 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { AddRequestsResponse result = response.body(); - finish(); - Toast.makeText(AddRequestActivity.this, "RequestListに追加しました", Toast.LENGTH_SHORT).show(); + finish(); } else { try { System.out.println(response.errorBody().string()); } catch (IOException e) { e.printStackTrace(); } - //onFailureでキャッチできないエラーの処理 Toast.makeText(AddRequestActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); } 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 e92a1fd..5af2a8d 100644 --- a/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java @@ -1,13 +1,11 @@ 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.os.Handler; import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; +import android.util.Log; import android.view.Gravity; import android.view.View; import android.support.design.widget.NavigationView; @@ -36,10 +34,12 @@ 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.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.TimeZone; @@ -52,402 +52,135 @@ import static android.graphics.Color.BLACK; -public class RequestListActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener { +public class RequestListActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener { + private String TAG = UpdateRequestActivity.class.getSimpleName(); //retrofitの処理 - final Retrofit retrofit = new Retrofit.Builder() + private final Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/rest/") - // .baseUrl("http://10.0.2.2:8080/rest/") .addConverterFactory(JacksonConverterFactory.create()) .build(); //interfaceから実装を取得 - final GroupsRest requestsService = retrofit.create(GroupsRest.class); + private final GroupsRest requestListService = retrofit.create(GroupsRest.class); - Toast toast; //動作テスト用 + //RequestList取得するための必要な情報 + private Cosmos app = null; + private String gId = null; + private String uId = null; + private String token = null; + private boolean detail = true; //リクエスト詳細度 + private int quantity = 20; //Request List - RequestList requestList; + private RequestList requestList; + private TableLayout requestTable; // requestListの表 //Color制御 - boolean productColorFlag = true; //買うもの (true:白, false:黒) - boolean deadlineColorFlag = true; //購入期限 - boolean locationColorFlag = true; //場所 - boolean nameColorFlag = true; //名前 + private boolean productColorFlag = true; //買うもの (true:白, false:黒) + private boolean deadlineColorFlag = true; //購入期限 + private boolean locationColorFlag = true; //場所 + private boolean nameColorFlag = true; //名前 //Rotation制御 - boolean deadlineRotationFlag = false; //(true:回転, false:未回転) + private boolean deadlineRotationFlag = false; //(true:回転, false:未回転) - LinearLayout productView; - LinearLayout deadlineView; - LinearLayout locationView; - LinearLayout nameView; + private LinearLayout productView; + private LinearLayout deadlineView; + private LinearLayout locationView; + private LinearLayout nameView; - Collator collator = Collator.getInstance(Locale.JAPANESE); + private ImageView productImage; + private ImageView deadlineImage; + private ImageView locationImage; + private ImageView nameImage; - TableLayout requesttable; -// TableLayout accomplishedRequesttable = (TableLayout)findViewById(R.id.RequestList); + private Button deleteButton; + private Button accomplishButton; - HashMap selectedRequestMap = new HashMap<>(); + private Collator collator = Collator.getInstance(Locale.JAPANESE); + private HashMap selectedRequestMap = new HashMap<>(); // + private HashMap requestListMap = new HashMap<>(); // - Button deleteButton; - Button accomplishButton; + private int accomplishRequestNum; // 達成したリクエスト数 - //productOnClick - public View.OnClickListener productOnClick = new View.OnClickListener() { - @Override - public void onClick(View view) { - Toast.makeText(RequestListActivity.this, "product 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 (!productColorFlag) { - product.setColorFilter(null); - productColorFlag = true; - ResetRequestListTable(); - AddRequestListTable(requestList); - } else { - if(deadlineRotationFlag) { - deadlineRotationFlag = false; - } else { - deadline.setRotation(0); - } - product.setColorFilter(BLACK); - productColorFlag = false; - deadline.setColorFilter(null); - deadlineColorFlag = true; - location.setColorFilter(null); - locationColorFlag = true; - name.setColorFilter(null); - nameColorFlag = true; - ResetRequestListTable(); - AddRequestListTable(SortProduct()); - } - } - }; - - //deadlineOnClick - public View.OnClickListener deadlineOnClick = new View.OnClickListener() { - @Override - public void onClick(View view) { - Toast.makeText(RequestListActivity.this, "deadline 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 (!deadlineColorFlag) { - deadline.setColorFilter(null); - deadlineColorFlag = true; - ResetRequestListTable(); - AddRequestListTable(requestList); - if(!deadlineRotationFlag) { - deadline.setRotation(0); - } - } else { - product.setColorFilter(null); - productColorFlag = true; - location.setColorFilter(null); - locationColorFlag = true; - name.setColorFilter(null); - nameColorFlag = true; - - if (!deadlineRotationFlag) { - deadline.setColorFilter(BLACK); - deadlineRotationFlag = true; - ResetRequestListTable(); - AddRequestListTable(SortDeadline()); - } else { - deadline.setRotation(180); - deadlineColorFlag = false; - deadlineRotationFlag = false; - ResetRequestListTable(); - AddRequestListTable(ReverseDeadline()); - } - } - } - }; - - //locationOnClick - public View.OnClickListener locationOnClick = new View.OnClickListener() { - @Override - public void onClick(View view) { - Toast.makeText(RequestListActivity.this, "location 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 (!locationColorFlag) { - location.setColorFilter(null); - locationColorFlag = true; - ResetRequestListTable(); - AddRequestListTable(requestList); - } else { - if(deadlineRotationFlag) { - deadlineRotationFlag = false; - } else { - deadline.setRotation(0); - } - location.setColorFilter(BLACK); - locationColorFlag = false; - product.setColorFilter(null); - productColorFlag = true; - deadline.setColorFilter(null); - deadlineColorFlag = true; - name.setColorFilter(null); - nameColorFlag = true; - ResetRequestListTable(); - AddRequestListTable(SortLocation()); - } - } - }; - - //nameOnClick - 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()); - } - } - }; - - //requestListRowOnClick - 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 : selectedRequestMap.values()) { - if(view.equals(selectedRow)) { - selectedRequestMap.remove(selectedRow); - view.setBackgroundColor(Color.rgb(255, 255, 255)); - Toast.makeText(RequestListActivity.this, view + " Reset Clicked!", Toast.LENGTH_SHORT).show(); - return false; - } - } - selectedRequestMap.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 final View.OnClickListener accomplishOnClick = new View.OnClickListener() { - Handler handler = new Handler(); -// List selectedRequestList = new ArrayList<>(); - - @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(); - - new Thread(new Runnable() { - public void run() { - for (Integer i : selectedRequestMap.keySet()) { - Request request = requestList.getRequest(i - 1); -// selectedRequestList.add(request); - 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); - Response response; - try { - response = updateReqestCall.execute(); - if (response.isSuccessful()) { - AddRequestsResponse result = response.body(); -// Toast.makeText(RequestListActivity.this, "RequestListを達成しました", Toast.LENGTH_SHORT).show(); -// requestList.removeRequests(selectedRequestList); - handler.post(new Runnable() { - @Override - public void run() { - ResetRequestListTable(); - AddRequestListTable(requestList); - } - }); - } else { - // onFailure - try { - System.out.println(response.errorBody().string()); - } catch (IOException e) { - e.printStackTrace(); - } - - //onFailureでキャッチできないエラーの処理 -// Toast.makeText(RequestListActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); - } - } catch (IOException e) { - e.printStackTrace(); -// Toast.makeText(RequestListActivity.this, "RequestListの達成失敗しました", Toast.LENGTH_SHORT).show(); - - } - - } - } - }).start(); - deleteButton.setVisibility(View.INVISIBLE); - accomplishButton.setVisibility(View.INVISIBLE); - } - }; - - //productSortComparator - public Comparator productSortComparator = new Comparator() { - @Override - public int compare(Request r1, Request r2) { - return collator.compare(r1.getProduct(), r2.getProduct()); - } - }; - - //deadlineSortComparator - //!null処理 - public Comparator deadlineSortComparator = new Comparator() { - @Override - public int compare(Request r1, Request r2) { - return r1.getDeadline().compareTo(r2.getDeadline()); - } - }; - - //deadlineReverseComparator - public Comparator deadlineReverseComparator = new Comparator() { - @Override - public int compare(Request r1, Request r2) { - if (r1.getDeadline() == null || r2.getDeadline() == null) - return 0; - if((r1.getDeadline().compareTo(r2.getDeadline())) == 1) - return -1; - if((r1.getDeadline().compareTo(r2.getDeadline())) == -1) - return 1; - return r1.getDeadline().compareTo(r2.getDeadline()); - } - }; - - //locationSortComparator - public Comparator locationSortComparator = new Comparator() { - @Override - public int compare(Request r1, Request r2) { - return Yolp.getInstance().getSubCategoryByCode(r1.getLocation()).getSubName().compareTo(Yolp.getInstance().getSubCategoryByCode(r2.getLocation()).getSubName()); - } - }; - - //nameSortComparator - public Comparator nameSortComparator = new Comparator() { - @Override - public int compare(Request r1, Request r2) { - return collator.compare(r1.getIssuer().getName(), r2.getIssuer().getName()); - } - }; + private Toast toast; //動作テスト用 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_request_list); + Log.d(TAG, "onCreate"); - Toolbar toolbar = (Toolbar) findViewById(R.id.requestlist_toolbar); + Toolbar toolbar = findViewById(R.id.requestlist_toolbar); setSupportActionBar(toolbar); - FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.addrequest_button); + FloatingActionButton fab = findViewById(R.id.addrequest_button); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Snackbar.make(view, "Next Add Request Activity", Snackbar.LENGTH_LONG) - .setAction("Action", null).show(); - +// Snackbar.make(view, "Next Add Request Activity", Snackbar.LENGTH_LONG) +// .setAction("Action", null).show(); startActivity(new Intent(RequestListActivity.this, AddRequestActivity.class)); } }); //LEFT hamburger button - DrawerLayout requestlistDrawer = (DrawerLayout) findViewById(R.id.request_list_drawer_layout); + DrawerLayout requestlistDrawer = findViewById(R.id.request_list_drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, requestlistDrawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); requestlistDrawer.addDrawerListener(toggle); toggle.syncState(); - NavigationView navigationView = (NavigationView) findViewById(R.id.request_list_nav_view); + NavigationView navigationView = findViewById(R.id.request_list_nav_view); navigationView.setNavigationItemSelectedListener(this); - requesttable = (TableLayout)findViewById(R.id.RequestList); + requestTable = (TableLayout)findViewById(R.id.RequestList); - productView = (LinearLayout) findViewById(R.id.product); + productView = (LinearLayout)findViewById(R.id.product); productView.setOnClickListener(productOnClick); - deadlineView = (LinearLayout)findViewById(R.id.deadline); deadlineView.setOnClickListener(deadlineOnClick); - locationView = (LinearLayout)findViewById(R.id.location); locationView.setOnClickListener(locationOnClick); - nameView = (LinearLayout)findViewById(R.id.name); nameView.setOnClickListener(nameOnClick); + productImage = (ImageView) findViewById(R.id.image_product); + deadlineImage = (ImageView) findViewById(R.id.image_deadline); + locationImage = (ImageView) findViewById(R.id.image_location); + nameImage = (ImageView) findViewById(R.id.image_name); + deleteButton = findViewById(R.id.buttonDelete); deleteButton.setVisibility(View.INVISIBLE); - accomplishButton = findViewById(R.id.buttonAccomplish); accomplishButton.setVisibility(View.INVISIBLE); } @Override + protected void onRestart() { + Log.d(TAG, "onRestart"); + super.onRestart(); + + if (requestList != null) { + ResetRequestListTable(); + } + } + + @Override protected void onStart() { super.onStart(); + Log.d(TAG, "onStart"); + Log.d(TAG, "accomplishRequestNum:" + accomplishRequestNum); //RequestList取得するための必要な情報 - final Cosmos app = (Cosmos) getApplication(); - final String gId = app.getCurentGroup().getgId(); - final String token = app.getToken(); - final boolean detail = true; - int quantity = 20; + app = (Cosmos) getApplication(); + gId = app.getCurentGroup().getgId(); + token = app.getToken(); + detail = true; - final Call requestsListByGidCall = requestsService.getRequestsListByGid(gId, token, detail, quantity); + final Call requestsListByGidCall = requestListService.getRequestsListByGid(gId, token, detail, quantity); //サーバからのレスポンス requestsListByGidCall.enqueue(new Callback() { @@ -456,12 +189,12 @@ public void onResponse(Call call, Response response) { if (response.isSuccessful()) { TimeZone.setDefault(TimeZone.getTimeZone("Asia/Tokyo")); + if(requestList != null) { + requestList.clearRequest(); + } requestList = response.body(); app.getCurentGroup().setRequestList(requestList); - - //Add RequestList Table - AddRequestListTable(requestList); - + AddRequestListTable(requestList); //Add RequestList Table Toast.makeText(RequestListActivity.this, "RequestListを取得しました", Toast.LENGTH_SHORT).show(); } else { try { @@ -485,54 +218,39 @@ } @Override - protected void onRestart() { - super.onRestart(); - - ResetRequestListTable(); - - requestList.clearRequest(); - -// //Add RequestList Table -// AddRequestListTable(requestList); - } - - @SuppressWarnings("StatementWithEmptyBody") - @Override public boolean onNavigationItemSelected(MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); - - 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) { - toast = Toast.makeText(RequestListActivity.this, "Next Notification Activity", Toast.LENGTH_LONG); - toast.show(); - } else if (id == R.id.nav_settings) { - toast = Toast.makeText(RequestListActivity.this, "Next Settings Activity", Toast.LENGTH_LONG); - toast.show(); - } else if (id == R.id.request_list_nav_close) { - + switch (item.getItemId()) { + case R.id.nav_member_list: + // Handle the member list action + // toast = Toast.makeText(RequestListActivity.this, "Next Member List Activity", Toast.LENGTH_LONG); + // toast.show(); + startActivity(new Intent(RequestListActivity.this, MemberListActivity.class)); + break; + case R.id.nav_notification: + toast = Toast.makeText(RequestListActivity.this, "Next Notification Activity", Toast.LENGTH_LONG); + toast.show(); + break; + case R.id.nav_settings: + toast = Toast.makeText(RequestListActivity.this, "Next Settings Activity", Toast.LENGTH_LONG); + toast.show(); + break; + case R.id.request_list_nav_close: + break; } - - DrawerLayout requestlistDrawer = (DrawerLayout) findViewById(R.id.request_list_drawer_layout); + DrawerLayout requestlistDrawer = findViewById(R.id.request_list_drawer_layout); requestlistDrawer.closeDrawer(GravityCompat.START); return true; } - private int ConvertMonth(int i, RequestList requestList) { - return requestList.getRequest(i).getDeadline().getMonth() + 1; - } - - @TargetApi(Build.VERSION_CODES.O) + // Add RequestList to requestListTable. private void AddRequestListTable(RequestList requestList) { + Log.d(TAG, "AddRequestListTable()"); Date now = new Date(); -// TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); - requesttable.setShrinkAllColumns(true); + requestTable.setShrinkAllColumns(true); + accomplishRequestNum = 0; + requestListMap.clear(); for (int i = 0; i < requestList.getRequestCount(); i++) { TableRow tableRow = new TableRow(this); @@ -542,7 +260,6 @@ textProduct.setTextSize(20); textProduct.setHeight(150); textProduct.setGravity(Gravity.CENTER); - tableRow.addView(textProduct, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); TextView textDeadline = new TextView(this); // if(now.after(requestList.get(i).getDeadline())) { @@ -554,81 +271,456 @@ // if (requestList.get(i).getDeadline().getMonth() == now.getMonth() && requestList.get(i).getDeadline().getDate() - now.getDate() == 1) { // textDeadline.setText("明日まで"); // } - if(requestList.getRequest(i).getDeadline() != null) { + if (requestList.getRequest(i).getDeadline() != null) { textDeadline.setText(ConvertMonth(i, requestList) + "/" + requestList.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); - if(Yolp.getInstance().getSubCategoryByCode(requestList.getRequest(i).getLocation()) != null) { + if (Yolp.getInstance().getSubCategoryByCode(requestList.getRequest(i).getLocation()) != null) { textLocation.setText(Yolp.getInstance().getSubCategoryByCode(requestList.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.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.setOnLongClickListener(requestListRowOnClick); - - requesttable.addView(tableRow); + if (!requestList.getRequest(i).isDone()) { + int insertRow = requestTable.getChildCount() - accomplishRequestNum - 1; + System.out.println(requestTable.getChildCount()); + tableRow.addView(textProduct, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.addView(textDeadline, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.addView(textLocation, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.setOnClickListener(requestListRowOnClick); + tableRow.setOnLongClickListener(requestListRowOnLongClick); + requestTable.addView(tableRow, insertRow); + requestListMap .put(insertRow, requestList.getRequest(i).getrId()); + } else { + accomplishRequestNum++; + Log.d(TAG, "accomplishRequestNum++ : " + accomplishRequestNum); + tableRow.addView(textProduct, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.addView(textDeadline, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.addView(textLocation, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); + requestTable.addView(tableRow); + } } } - // Can not to reset! + // Reset requestListTable. private void ResetRequestListTable() { - TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); - int childCount = requesttable.getChildCount(); + Log.d(TAG, "ResetRequestListTable()"); + int childCount = requestTable.getChildCount(); + int lastRow = childCount - 1; // Remove all rows except the first one - if (childCount > 1) { - requesttable.removeViews(1, childCount - 1); + if (childCount > 2) { + requestTable.removeViews(1, lastRow - accomplishRequestNum - 1); + Log.d(TAG, "removeViewupAccomplishRequest : " + 1 + " - " + (lastRow - accomplishRequestNum - 1)); + if(accomplishRequestNum > 0) { + for(int i = 0; i < accomplishRequestNum; i++) { + childCount = requestTable.getChildCount(); + lastRow = childCount - 1; + Log.d(TAG, "removeViewaccomplishRequest:" + lastRow); + requestTable.removeView(requestTable.getChildAt(lastRow)); + } + } } } + //productOnClick + public View.OnClickListener productOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(RequestListActivity.this, "product sorted", Toast.LENGTH_SHORT).show(); + if (!productColorFlag) { + productImage.setColorFilter(null); + productColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(requestList); + } else { + if(deadlineRotationFlag) { + deadlineRotationFlag = false; + } else { + deadlineImage.setRotation(0); + } + productImage.setColorFilter(BLACK); + productColorFlag = false; + deadlineImage.setColorFilter(null); + deadlineColorFlag = true; + locationImage.setColorFilter(null); + locationColorFlag = true; + nameImage.setColorFilter(null); + nameColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(SortProduct()); + } + } + }; + + //deadlineOnClick + public View.OnClickListener deadlineOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(RequestListActivity.this, "deadline sorted", Toast.LENGTH_SHORT).show(); + if (!deadlineColorFlag) { + deadlineImage.setColorFilter(null); + deadlineColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(requestList); + if(!deadlineRotationFlag) { + deadlineImage.setRotation(0); + } + } else { + productImage.setColorFilter(null); + productColorFlag = true; + locationImage.setColorFilter(null); + locationColorFlag = true; + nameImage.setColorFilter(null); + nameColorFlag = true; + + if (!deadlineRotationFlag) { + deadlineImage.setColorFilter(BLACK); + deadlineRotationFlag = true; + ResetRequestListTable(); + AddRequestListTable(SortDeadline()); + } else { + deadlineImage.setRotation(180); + deadlineColorFlag = false; + deadlineRotationFlag = false; + ResetRequestListTable(); + AddRequestListTable(ReverseDeadline()); + } + } + } + }; + + //locationOnClick + public View.OnClickListener locationOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(RequestListActivity.this, "location sorted", Toast.LENGTH_SHORT).show(); + if (!locationColorFlag) { + locationImage.setColorFilter(null); + locationColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(requestList); + } else { + if(deadlineRotationFlag) { + deadlineRotationFlag = false; + } else { + deadlineImage.setRotation(0); + } + locationImage.setColorFilter(BLACK); + locationColorFlag = false; + productImage.setColorFilter(null); + productColorFlag = true; + deadlineImage.setColorFilter(null); + deadlineColorFlag = true; + nameImage.setColorFilter(null); + nameColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(SortLocation()); + } + } + }; + + //nameOnClick + public View.OnClickListener nameOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(RequestListActivity.this, "name sorted", Toast.LENGTH_SHORT).show(); + if (!nameColorFlag) { + nameImage.setColorFilter(null); + nameColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(requestList); + } else { + if(deadlineRotationFlag) { + deadlineRotationFlag = false; + } else { + deadlineImage.setRotation(0); + } + nameImage.setColorFilter(BLACK); + nameColorFlag = false; + locationImage.setColorFilter(null); + locationColorFlag = true; + productImage.setColorFilter(null); + productColorFlag = true; + deadlineImage.setColorFilter(null); + deadlineColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(SortName()); + } + } + }; + + //requestListRowOnClick + public View.OnClickListener requestListRowOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + if (selectedRequestMap.isEmpty()) { + Log.d(TAG, requestList.getRequestById(requestListMap.get(requestTable.indexOfChild(view))).getProduct() + " touched!"); + Intent intent = new Intent(RequestListActivity.this, UpdateRequestActivity.class); + String rId = requestList.getRequestById(requestListMap.get(requestTable.indexOfChild(view))).getrId(); + intent.putExtra("rId", rId); + startActivity(intent); + } else { + selectedRequestMap.remove(view); + view.setBackgroundColor(Color.rgb(255, 255, 255)); + Log.d(TAG, requestTable.indexOfChild(view) + " : " + requestTable.indexOfChild(view) + " Reset Clicked!"); + if(selectedRequestMap.isEmpty()) { + deleteButton.setVisibility(View.INVISIBLE); + accomplishButton.setVisibility(View.INVISIBLE); + } + } + } + }; + + //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); + } + + if(selectedRequestMap.containsKey(view)) { + selectedRequestMap.remove(view); + view.setBackgroundColor(Color.rgb(255, 255, 255)); + Log.d(TAG, requestTable.indexOfChild(view) + " : " + requestTable.indexOfChild(view) + " Reset Clicked!"); + return true; + } + + selectedRequestMap.put(view, requestTable.indexOfChild(view)); + Log.d(TAG, requestTable.indexOfChild(view) + " : " + requestList.getRequestById(requestListMap.get(requestTable.indexOfChild(view))).getProduct() + " Clicked!"); + view.setBackgroundColor(Color.rgb(200, 200, 200)); + return true; + } + }; + + //deleteOnClick + public View.OnClickListener deleteOnClick = new View.OnClickListener() { + Handler handler = new Handler(); + + @Override + public void onClick(View view) { + //RequestList取得するための必要な情報 + app = (Cosmos) getApplication(); + gId = app.getCurentGroup().getgId(); + token = app.getToken(); + final List selectedRequest = new ArrayList<>(); + + new Thread(new Runnable() { + public void run() { + final Iterator iterator = selectedRequestMap.keySet().iterator(); + for (final Integer i : selectedRequestMap.values()) { + final Request request = requestList.getRequestById(requestListMap.get(i)); + final Call deleteRequestCall = requestListService.deleteRequest(gId, request.getrId(), token); + Response response; + selectedRequest.add(request); + try { + response = deleteRequestCall.execute(); + if (response.isSuccessful()) { + String result = response.body(); + handler.post(new Runnable() { + @Override + public void run() { + ResetRequestListTable(); + iterator.next(); + Log.d(TAG, request.getrId() + " | " + requestListMap.get(i) + " | " + iterator.hasNext()); + Log.d(TAG, request.getProduct() + "削除!"); + if(!iterator.hasNext()) { + requestList.removeRequests(selectedRequest); + AddRequestListTable(requestList); + selectedRequestMap.clear(); + } + } + }); + } else { + // onFailure + try { + System.out.println(response.errorBody().string()); + } catch (IOException e) { + e.printStackTrace(); + } + //onFailureでキャッチできないエラーの処理 + Log.d(TAG, "通信エラー"); + } + } catch (IOException e) { + e.printStackTrace(); + Log.d(TAG, "RequestListの削除失敗しました"); + } + } + } + }).start(); + deleteButton.setVisibility(View.INVISIBLE); + accomplishButton.setVisibility(View.INVISIBLE); + } + }; + + //accomplishOnClick + public final View.OnClickListener accomplishOnClick = new View.OnClickListener() { + Handler handler = new Handler(); + + @Override + public void onClick(View view) { + + //RequestList取得するための必要な情報 + app = (Cosmos) getApplication(); + gId = app.getCurentGroup().getgId(); + uId = app.getuId(); + token = app.getToken(); + + new Thread(new Runnable() { + public void run() { + final Iterator iterator = selectedRequestMap.keySet().iterator(); + for (final Integer i : selectedRequestMap.values()) { + final Request request = requestList.getRequestById(requestListMap.get(i)); + 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 = requestListService.updateRequest(gId, request.getrId(), uId, request.getProduct(), deadline, request.getLocation(), true, token); + Response response; + try { + response = updateReqestCall.execute(); + if (response.isSuccessful()) { + AddRequestsResponse result = response.body(); + handler.post(new Runnable() { + @Override + public void run() { + requestList.getRequestById(request.getrId()).setDone(true); + iterator.next(); + Log.d(TAG, request.getrId() + " | " + requestListMap.get(i) + " | " + iterator.hasNext()); + Log.d(TAG, request.getProduct() + "達成!"); + if(!iterator.hasNext()) { + ResetRequestListTable(); + AddRequestListTable(requestList); + selectedRequestMap.clear(); + } + } + }); + } else { + // onFailure + try { + System.out.println(response.errorBody().string()); + } catch (IOException e) { + e.printStackTrace(); + } + //onFailureでキャッチできないエラーの処理 + Log.d(TAG, "通信エラー"); + } + } catch (IOException e) { + e.printStackTrace(); + Log.d(TAG, "RequestListの達成失敗しました"); + } + } + } + }).start(); + deleteButton.setVisibility(View.INVISIBLE); + accomplishButton.setVisibility(View.INVISIBLE); + } + }; + + //productSortComparator + private Comparator productSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + return collator.compare(r1.getProduct(), r2.getProduct()); + } + }; + + //deadlineSortComparator + private Comparator deadlineSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + if (r1.getDeadline() == null || r2.getDeadline() == null) + return 0; + return r1.getDeadline().compareTo(r2.getDeadline()); + } + }; + + //deadlineReverseComparator + private Comparator deadlineReverseComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + if (r1.getDeadline() == null || r2.getDeadline() == null) + return 0; + if((r1.getDeadline().compareTo(r2.getDeadline())) == 1) + return -1; + if((r1.getDeadline().compareTo(r2.getDeadline())) == -1) + return 1; + return r1.getDeadline().compareTo(r2.getDeadline()); + } + }; + + //locationSortComparator + private Comparator locationSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + return Yolp.getInstance().getSubCategoryByCode(r1.getLocation()).getSubName().compareTo(Yolp.getInstance().getSubCategoryByCode(r2.getLocation()).getSubName()); + } + }; + + //nameSortComparator + private Comparator nameSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + return collator.compare(r1.getIssuer().getName(), r2.getIssuer().getName()); + } + }; + private RequestList SortProduct() { - List productsortRequestlist = (List) requestList.getRequests(); + List productsortRequestlist = new ArrayList<>(requestList.getRequests()); Collections.sort(productsortRequestlist, productSortComparator); return new RequestList(productsortRequestlist); } private RequestList SortDeadline() { - List deadlinesortRequestlist = (List) requestList.getRequests(); + List deadlinesortRequestlist = new ArrayList<>(requestList.getRequests()); Collections.sort(deadlinesortRequestlist, deadlineSortComparator); return new RequestList(deadlinesortRequestlist); } private RequestList ReverseDeadline() { - List deadlinesortRequestlist = (List) requestList.getRequests(); + List deadlinesortRequestlist = new ArrayList<>(requestList.getRequests()); Collections.sort(deadlinesortRequestlist, deadlineReverseComparator); return new RequestList(deadlinesortRequestlist); } private RequestList SortLocation() { - List locationsortRequestlist = (List) requestList.getRequests(); + List locationsortRequestlist = new ArrayList<>(requestList.getRequests()); Collections.sort(locationsortRequestlist, locationSortComparator); return new RequestList(locationsortRequestlist); } private RequestList SortName() { - List namesortRequestlist = (List) requestList.getRequests(); + List namesortRequestlist = new ArrayList<>(requestList.getRequests()); Collections.sort(namesortRequestlist, nameSortComparator); return new RequestList(namesortRequestlist); } + + private int ConvertMonth(int i, RequestList requestList) { + return requestList.getRequest(i).getDeadline().getMonth() + 1; + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/cosmosclient/views/UpdateRequestActivity.java b/app/src/main/java/com/example/cosmosclient/views/UpdateRequestActivity.java new file mode 100644 index 0000000..35685ef --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/views/UpdateRequestActivity.java @@ -0,0 +1,387 @@ +package com.example.cosmosclient.views; + +import android.app.DatePickerDialog; +import android.content.Context; +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; +import android.view.KeyEvent; +import android.view.View; +import android.view.inputmethod.InputMethodManager; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.Spinner; +import android.widget.TextView; +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.resources.GroupsRest; +import com.example.cosmosclient.yolp.Category; +import com.example.cosmosclient.yolp.SubCategory; +import com.example.cosmosclient.yolp.Yolp; + +import java.io.IOException; +import java.util.Calendar; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + +public class UpdateRequestActivity extends AppCompatActivity{ + private String TAG = UpdateRequestActivity.class.getSimpleName(); + + private InputMethodManager inputMethodManager; + + //retrofitの処理 + private Retrofit retrofit = new Retrofit.Builder() +// .baseUrl("http://localhost:8080/") +// .baseUrl("http://10.0.2.2:8080/") + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/cosmos/rest/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + + //interfaceから実装を取得 + private GroupsRest groupRestService = retrofit.create(GroupsRest.class); + + //RequestList取得するための必要な情報 + private Cosmos app = null; + private String uId = null; + private String gId = null; + private String token = null; + private boolean detail = true; + String deadline = null; + + private Request updateRequest; + + private Integer deadlineYear; + private Integer deadlineMonth; + private Integer deadlineDayOfMonth; + + private EditText editTextProduct; + private EditText editTextDeadline; + + private Spinner category; + private Spinner subCategory; + + private Button updateButton; + private Button accomplishButton; + private Button deleteButton; + + private ImageButton calenderButton; + + private String selectedSubCategory; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_update_request); + + app = (Cosmos)getApplication(); + + //キーボード表示を制御するためのオブジェクト + inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + + calenderButton = findViewById(R.id.calenderButton); + + editTextProduct = findViewById(R.id.editTextProduct); + editTextDeadline = findViewById(R.id.editTextDeadline); + + category = (Spinner)findViewById(R.id.spinnerLocationCategory); + subCategory = (Spinner)findViewById(R.id.spinnerLocationSubCategory); + setSpinner(category, Yolp.getInstance().getCategoryNames()); + + updateButton = findViewById(R.id.buttonUpdate); + accomplishButton = findViewById(R.id.buttonAccomplish); + deleteButton = findViewById(R.id.buttonDelete); + + String rId = getIntent().getStringExtra("rId"); + updateRequest = app.getCurentGroup().getRequestList().getRequestById(rId); + + //現在のリクエスト情報を設定 + editTextProduct.setText(updateRequest.getProduct(), TextView.BufferType.NORMAL); + if(updateRequest.getDeadline() != null) { + //setした日付を取得して表示 + editTextDeadline.setText(String.format("%d / %02d / %02d", updateRequest.getDeadline().getYear() + 1900, updateRequest.getDeadline().getMonth() + 1, updateRequest.getDeadline().getDate())); + } + setSpinnerSelectedCode(); + + + calenderButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //キーボードを閉じる + inputMethodManager.hideSoftInputFromWindow(editTextProduct.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); + + //Calendarインスタンスを取得 + final Calendar calender = Calendar.getInstance(); + + //DatePickerDialogインスタンスを取得 + DatePickerDialog datePickerDialog = new DatePickerDialog(UpdateRequestActivity.this, new DatePickerDialog.OnDateSetListener() { + + @Override + public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { + deadlineYear = year; + deadlineMonth = month; + deadlineDayOfMonth = dayOfMonth; + + //setした日付を取得して表示 + editTextDeadline.setText(String.format("%d / %02d / %02d", year, month+1, dayOfMonth)); + } + }, + calender.get(Calendar.YEAR), + calender.get(Calendar.MONTH), + calender.get(Calendar.DATE) + ); + + //dialogを表示 + datePickerDialog.show(); + } + }); + + //editTextDeadlineにリスナーをセット + editTextDeadline.setOnKeyListener(new View.OnKeyListener() { + //コールバックとしてonKey()メソッドを定義 + @Override + public boolean onKey(View v, int keyCode, KeyEvent event) { + //イベントを取得するタイミングには、ボタンが押されてなおかつエンターキーだったときを指定 + if((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)){ + //キーボードを閉じる + inputMethodManager.hideSoftInputFromWindow(editTextProduct.getWindowToken(), InputMethodManager.RESULT_UNCHANGED_SHOWN); + + return true; + } + return false; + } + }); + + // 変更ボタン + updateButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //ボタン連打防止 + updateButton.setEnabled(false); + new Handler().postDelayed(new Runnable() { + public void run() { + updateButton.setEnabled(true); + } + }, 3000L); + + // エディットテキストのテキストを取得 + String inputProduct = editTextProduct.getText().toString(); + + //RequestList取得するための必要な情報 + app = (Cosmos) getApplication(); + uId = app.getuId(); + gId = app.getCurentGroup().getgId(); + token = app.getToken(); + + if(deadlineYear != null && deadlineMonth != null && deadlineDayOfMonth != null) { + deadline = String.format("%d-%02d-%02d %02d:%02d:%02d", deadlineYear, deadlineMonth +1, deadlineDayOfMonth, 23, 59, 59); + } + Call call = groupRestService.updateRequest(gId, updateRequest.getrId(), uId, inputProduct, deadline, Yolp.getInstance().getCodeBySubcategory(selectedSubCategory), false, token); + + //サーバからのレスポンス + call.enqueue(new Callback() { + //成功時 + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + AddRequestsResponse result = response.body(); + Toast.makeText(UpdateRequestActivity.this, "RequestListに変更しました", Toast.LENGTH_SHORT).show(); + finish(); + } else { + try { + System.out.println(response.errorBody().string()); + } catch (IOException e) { + e.printStackTrace(); + } + + //onFailureでキャッチできないエラーの処理 + Toast.makeText(UpdateRequestActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); + } + } + + //失敗時 + @Override + public void onFailure(Call call, Throwable t) { + t.printStackTrace(); + Toast.makeText(UpdateRequestActivity.this, "RequestListの変更失敗しました", Toast.LENGTH_SHORT).show(); + } + }); + } + }); + + // 達成ボタン + accomplishButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //ボタン連打防止 + accomplishButton.setEnabled(false); + new Handler().postDelayed(new Runnable() { + public void run() { + accomplishButton.setEnabled(true); + } + }, 3000L); + + //RequestList取得するための必要な情報 + app = (Cosmos) getApplication(); + uId = app.getuId(); + gId = app.getCurentGroup().getgId(); + token = app.getToken(); + if (updateRequest.getDeadline() != null) { + deadline = String.format("%d-%02d-%02d %02d:%02d:%02d", updateRequest.getDeadline().getYear(), updateRequest.getDeadline().getMonth() + 1, updateRequest.getDeadline().getDate() + 1, 23, 59, 59); + } + Call call = groupRestService.updateRequest(gId, updateRequest.getrId(), uId, updateRequest.getProduct(), deadline, updateRequest.getLocation(), true, token); + + //サーバからのレスポンス + call.enqueue(new Callback() { + //成功時 + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + AddRequestsResponse result = response.body(); + Toast.makeText(UpdateRequestActivity.this, "RequestListに達成しました", Toast.LENGTH_SHORT).show(); + finish(); + } else { + try { + System.out.println(response.errorBody().string()); + } catch (IOException e) { + e.printStackTrace(); + } + //onFailureでキャッチできないエラーの処理 + Toast.makeText(UpdateRequestActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); + } + } + + //失敗時 + @Override + public void onFailure(Call call, Throwable t) { + t.printStackTrace(); + Toast.makeText(UpdateRequestActivity.this, "RequestListの達成失敗しました", Toast.LENGTH_SHORT).show(); + } + }); + } + }); + + // 削除ボタン + deleteButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + //ボタン連打防止 + deleteButton.setEnabled(false); + new Handler().postDelayed(new Runnable() { + public void run() { + deleteButton.setEnabled(true); + } + }, 3000L); + + //RequestList取得するための必要な情報 + app = (Cosmos) getApplication(); + gId = app.getCurentGroup().getgId(); + token = app.getToken(); + Call call = groupRestService.deleteRequest(gId, updateRequest.getrId(), token); + //サーバからのレスポンス + call.enqueue(new Callback() { + //成功時 + @Override + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + String result = response.body(); + Toast.makeText(UpdateRequestActivity.this, "RequestListに削除しました", Toast.LENGTH_SHORT).show(); + finish(); + } else { + try { + System.out.println(response.errorBody().string()); + } catch (IOException e) { + e.printStackTrace(); + } + //onFailureでキャッチできないエラーの処理 + Toast.makeText(UpdateRequestActivity.this, "通信エラー", Toast.LENGTH_SHORT).show(); + } + } + + //失敗時 + @Override + public void onFailure(Call call, Throwable t) { + t.printStackTrace(); + Toast.makeText(UpdateRequestActivity.this, "RequestListの削除失敗しました", Toast.LENGTH_SHORT).show(); + } + }); + } + }); + + // リスナーを登録 + category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + // アイテムが選択された時 + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + Spinner spinner = (Spinner)parent; + String selectedCategory = (String)spinner.getSelectedItem(); + SearchSubCategory(selectedCategory); + } + + // アイテムが選択されなかった + public void onNothingSelected(AdapterView parent) { + } + }); + + // リスナーを登録 + subCategory.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + // アイテムが選択された時 + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + Spinner spinner = (Spinner)parent; + selectedSubCategory = (String)spinner.getSelectedItem(); + } + + // アイテムが選択されなかった + public void onNothingSelected(AdapterView parent) { + } + }); + + } + + private void SearchSubCategory(String selectedCategory) { + switch(selectedCategory) { + case "家電・携帯電話": + setSpinner(subCategory, Yolp.getInstance().getCategoryByName("家電・携帯電話").getSubCategoryNames().toArray(new String[0])); + break; + case "コンビニ・スーパー": + setSpinner(subCategory, Yolp.getInstance().getCategoryByName("コンビニ・スーパー").getSubCategoryNames().toArray(new String[0])); + break; + } + } + + private void setSpinner(Spinner spinner, String[] arr){ + ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, arr); + adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + spinner.setAdapter(adapter); + } + + private void setSpinnerSelectedCode() { + int i = 0, j = 0; + for (Category category : Yolp.getInstance().getCategories()) { + for (SubCategory subCategory : category.getSubCategories()) { + if (subCategory.getCode() == updateRequest.getLocation()) { + this.category.setSelection(i, true); + SearchSubCategory(category.getName()); + this.subCategory.setSelection(j, true); + break; + } + j++; + } + i++; + j = 0; + } + } + +} diff --git a/app/src/main/res/layout/activity_update_request.xml b/app/src/main/res/layout/activity_update_request.xml new file mode 100644 index 0000000..cbcdf9b --- /dev/null +++ b/app/src/main/res/layout/activity_update_request.xml @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + +