diff --git a/app/src/main/java/com/example/cosmosclient/entities/Request.java b/app/src/main/java/com/example/cosmosclient/entities/Request.java index b4ccf6e..619f097 100644 --- a/app/src/main/java/com/example/cosmosclient/entities/Request.java +++ b/app/src/main/java/com/example/cosmosclient/entities/Request.java @@ -4,18 +4,32 @@ public class Request { + private String rId; + private String uri; + private Date date; + private String IssuerUid; private String product; private Date deadline; - private String location; - private String name; +// private String location; + private int location; + private String name; //消 + private boolean done = false; - public Request(String product, Date deadline, String location, String name) { + public Request(String product, Date deadline, int location, String name) { this.product = product; this.deadline = deadline; this.location = location; this.name = name; } + public String getrId() { + return rId; + } + + public void setrId(String rId) { + this.rId = rId; + } + public String getProduct() { return product; } @@ -32,11 +46,11 @@ this.deadline = deadline; } - public String getLocation() { + public int getLocation() { return location; } - public void setLocation(String location) { + public void setLocation(int location) { this.location = location; } 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 52bbefd..a102c92 100644 --- a/app/src/main/java/com/example/cosmosclient/resources/GroupsRest.java +++ b/app/src/main/java/com/example/cosmosclient/resources/GroupsRest.java @@ -1,14 +1,27 @@ package com.example.cosmosclient.resources; import com.example.cosmosclient.entities.Group; +import com.example.cosmosclient.entities.Request; + +import java.util.ArrayList; import retrofit2.Call; import retrofit2.http.Field; import retrofit2.http.FormUrlEncoded; +import retrofit2.http.GET; import retrofit2.http.POST; +import retrofit2.http.Path; +import retrofit2.http.Query; public interface GroupsRest { @POST("groups") @FormUrlEncoded Call createGroup(@Field("name") String name,@Field("uId") String uId,@Field("token") String token); + +// @GET("/{gId}/requests") +// Call> getRequestsListByGid(@Path("gid") String gid, @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 a9307f1..5987657 100644 --- a/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java @@ -114,11 +114,47 @@ addButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { +// //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); +// +// Call call = requestsService.getRequestsListByGid(); +// //サーバからのレスポンス +// call.enqueue(new Callback() { +// //成功時 +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()) { +// Request result = response.body(); +// +// //app/Cosmosに情報保存 +// Cosmos app = (Cosmos) getApplication(); +// +// Toast.makeText(RequestListActivity.this, "RequestListに追加しました", Toast.LENGTH_SHORT).show(); +// } else { +// //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(); +// } +// }); + // エディットテキストのテキストを取得 String inputProduct = editTextProduct.getText().toString(); // 取得したテキストを TextView に張り付ける - RequestListActivity.requestlist.add(0, (new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), selectedSubCategory, "a-hongo"))); + RequestListActivity.requestlist.add(0, (new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), Yolp.getInstance().getCodeBySubcategory(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 de4d635..58421c5 100644 --- a/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java @@ -1,6 +1,8 @@ package com.example.cosmosclient.views; +import android.annotation.TargetApi; import android.content.Intent; +import android.os.Build; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; @@ -13,6 +15,7 @@ import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.view.MenuItem; +import android.view.ViewGroup; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TableLayout; @@ -21,7 +24,10 @@ import android.widget.Toast; import com.example.cosmosclient.R; +import com.example.cosmosclient.app.Cosmos; import com.example.cosmosclient.entities.Request; +import com.example.cosmosclient.resources.GroupsRest; +import com.example.cosmosclient.yolp.Yolp; import java.text.Collator; import java.util.ArrayList; @@ -30,6 +36,12 @@ import java.util.Date; import java.util.Locale; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + import static android.graphics.Color.BLACK; public class RequestListActivity extends AppCompatActivity @@ -49,6 +61,11 @@ //Rotation制御 boolean deadlineRotationFlag = false; //(true:回転, false:未回転) + LinearLayout productView; + LinearLayout deadlineView; + LinearLayout locationView; + LinearLayout nameView; + Collator collator = Collator.getInstance(Locale.JAPANESE); //productOnClick @@ -228,7 +245,7 @@ public Comparator locationSortComparator = new Comparator() { @Override public int compare(Request r1, Request r2) { - return r1.getLocation().compareTo(r2.getLocation()); + return Yolp.getInstance().getSubCategoryByCode(r1.getLocation()).getSubName().compareTo(Yolp.getInstance().getSubCategoryByCode(r2.getLocation()).getSubName()); } }; @@ -244,6 +261,69 @@ 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> requestsListByGidCall = requestsService.getRequestsListByGid(gid, token); +// +// //サーバからのレスポンス +// requestsListByGidCall.enqueue(new Callback() { +// //成功時 +// @Override +// public void onResponse(Call call, Response response) { +// if (response.isSuccessful()) { +// Request result = response.body(); +// +// Call requestsDetailByGidAndRidcall = requestsService.getRequestsDetailByGidAndRid(gid, token, result.getrId()); +// //サーバからのレスポンス +// requestsDetailByGidAndRidcall.enqueue(new Callback() { +// //成功時 +// @Override +// public void onResponse(Call call, Response 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 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 call, Throwable t) { +// //t.printStackTrace(); +// Toast.makeText(RequestListActivity.this, "RequestListの取得失敗しました", Toast.LENGTH_SHORT).show(); +// } +// }); + Toolbar toolbar = (Toolbar) findViewById(R.id.requestlist_toolbar); setSupportActionBar(toolbar); @@ -261,9 +341,9 @@ requestlist.clear(); //Add Request - requestlist.add(new Request("わさび", new Date(2019, 6, 7), "スーパー", "a-hongo")); - requestlist.add(new Request("ケーキ" , new Date(2019, 6, 6), "ダニエル", "t-sugisawa")); - requestlist.add(new Request("からし", new Date(2018, 6, 4), "コンビニ", "n-kande")); + 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); @@ -278,16 +358,16 @@ NavigationView navigationView = (NavigationView) findViewById(R.id.request_list_nav_view); navigationView.setNavigationItemSelectedListener(this); - LinearLayout productView = (LinearLayout) findViewById(R.id.product); + productView = (LinearLayout) findViewById(R.id.product); productView.setOnClickListener(productOnClick); - LinearLayout deadlineView = (LinearLayout)findViewById(R.id.deadline); + deadlineView = (LinearLayout)findViewById(R.id.deadline); deadlineView.setOnClickListener(deadlineOnClick); - LinearLayout locationView = (LinearLayout)findViewById(R.id.location); + locationView = (LinearLayout)findViewById(R.id.location); locationView.setOnClickListener(locationOnClick); - LinearLayout nameView = (LinearLayout)findViewById(R.id.name); + nameView = (LinearLayout)findViewById(R.id.name); nameView.setOnClickListener(nameOnClick); } @@ -333,8 +413,12 @@ return requestList.get(i).getDeadline().getMonth() + 1; } + @TargetApi(Build.VERSION_CODES.O) private void AddRequestListTable(ArrayList requestList) { Date now = new Date(); + TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); + requesttable.setShrinkAllColumns(true); + for (int i = 0; i < requestList.size(); i++) { TableRow tableRow = new TableRow(this); @@ -343,7 +427,7 @@ textProduct.setTextSize(20); textProduct.setHeight(150); textProduct.setGravity(Gravity.CENTER); - tableRow.addView(textProduct); + tableRow.addView(textProduct, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); TextView textDeadline = new TextView(this); // if(now.after(requestList.get(i).getDeadline())) { @@ -360,23 +444,22 @@ textDeadline.setTextSize(20); textDeadline.setHeight(150); textDeadline.setGravity(Gravity.CENTER); - tableRow.addView(textDeadline); + tableRow.addView(textDeadline, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); TextView textLocation = new TextView(this); - textLocation.setText(requestList.get(i).getLocation()); + textLocation.setText(Yolp.getInstance().getSubCategoryByCode(requestList.get(i).getLocation()).getSubName()); textLocation.setTextSize(20); textLocation.setHeight(150); textLocation.setGravity(Gravity.CENTER); - tableRow.addView(textLocation); + tableRow.addView(textLocation, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); TextView textName = new TextView(this); textName.setText(requestList.get(i).getName()); textName.setTextSize(20); textName.setHeight(150); textName.setGravity(Gravity.CENTER); - tableRow.addView(textName); + tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT)); - TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); requesttable.addView(tableRow); } } diff --git a/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java b/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java index 1532db5..87e1a8a 100644 --- a/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java +++ b/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java @@ -45,6 +45,17 @@ return codeToSubcategory; } + public int getCodeBySubcategory(String selectedSubCategory) { + int code = 0; + for(SubCategory subCategory : codeToSubcategory.values()) { + if(subCategory.getSubName().equals(selectedSubCategory)) { + code = subCategory.getCode(); + break; + } + } + return code; + } + public void setCodeToSubcategory(HashMap codeToSubcategory) { this.codeToSubcategory = codeToSubcategory; } diff --git a/app/src/main/res/layout/content_request_list.xml b/app/src/main/res/layout/content_request_list.xml index cc9ddf1..c894494 100644 --- a/app/src/main/res/layout/content_request_list.xml +++ b/app/src/main/res/layout/content_request_list.xml @@ -45,28 +45,35 @@ android:id="@+id/RequestList" android:layout_width="match_parent" android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:stretchColumns="0, 1, 2, 3" + android:shrinkColumns="0, 1, 2, 3" android:layout_marginStart="15dp" android:layout_marginTop="20dp" - android:layout_marginLeft="15dp"> + android:layout_marginLeft="15dp" + android:layout_marginRight="15dp"> + android:layout_height="wrap_content" + android:layout_marginRight="20dp">