diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 2996d53..f43d428 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -8,6 +8,12 @@ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 694e8e9..88f3f83 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,10 +3,10 @@ xmlns:tools="http://schemas.android.com/tools" package="com.example.cosmosclient"> - - + + - + + + android:label="グループ作成" /> @@ -70,7 +74,8 @@ + android:theme="@style/AppTheme.NoActionBar"> + \ No newline at end of file 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/AddMemberActivity.java b/app/src/main/java/com/example/cosmosclient/views/AddMemberActivity.java index 5ef1453..174c8e7 100644 --- a/app/src/main/java/com/example/cosmosclient/views/AddMemberActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/AddMemberActivity.java @@ -19,8 +19,8 @@ public class AddMemberActivity extends AppCompatActivity implements AdapterView.OnItemClickListener { private static final String[] scenes = { - "QRコードで追加", - "IDで追加", + "QRコードで招待", + "IDで招待", "LINEで招待" }; @@ -64,11 +64,10 @@ if(selectedText.contains("QR")==true){ intent = new Intent(this.getApplicationContext(), DisplayQRActivity.class); }else if(selectedText.contains("ID")==true){ - intent = new Intent(this.getApplicationContext(), DisplayQRActivity.class); - }else{ + intent = new Intent(this.getApplicationContext(), DisplayGroupIDActivity.class); + }else if(selectedText.contains("LINE")==true){ // intent = new Intent(this.getApplicationContext(), DisplayQRActivity.class); - Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("line://msg/text/?GroupID")); - startActivity(i); + intent = new Intent(Intent.ACTION_VIEW, Uri.parse("line://msg/text/?GroupID")); } // Intent intent = new Intent(this.getApplicationContext(), DisplayQRActivity.class); 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 1abc948..5987657 100644 --- a/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java @@ -1,10 +1,12 @@ package com.example.cosmosclient.views; import android.app.DatePickerDialog; -import android.content.Intent; +import android.content.Context; import android.os.Bundle; 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; @@ -12,48 +14,60 @@ import android.widget.EditText; import android.widget.ImageButton; import android.widget.Spinner; -import android.widget.TextView; import com.example.cosmosclient.R; import com.example.cosmosclient.entities.Request; +import com.example.cosmosclient.yolp.Yolp; import java.sql.Date; import java.util.Calendar; public class AddRequestActivity extends AppCompatActivity { - private Request requestList; + private InputMethodManager inputMethodManager; private ImageButton calenderButton; - private EditText editTextProduct; - private int curYear; private int curMonth; private int curDayOfMonth; + private EditText editTextProduct; private EditText editTextDeadline; - private Button addButon; + private Spinner category; + private Spinner subCategory; + + private String selectedSubCategory; + + private Button addButton; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_request); + //キーボード表示を制御するためのオブジェクト + inputMethodManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); + calenderButton = findViewById(R.id.calenderButton); editTextProduct = findViewById(R.id.editTextProduct); - editTextDeadline = findViewById(R.id.editTextDeadline); - Spinner category = findViewById(R.id.spinnerLocationCategory); + category = findViewById(R.id.spinnerLocationCategory); + subCategory = findViewById(R.id.spinnerLocationSubCategory); - addButon = findViewById(R.id.buttonAdd); + setSpinner(category, Yolp.getInstance().getCategoryNames()); + + addButton = findViewById(R.id.buttonAdd); 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(); @@ -77,18 +91,70 @@ //dialogを表示 datePickerDialog.show(); - } }); - addButon.setOnClickListener(new View.OnClickListener() { + //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; + } + }); + + // 追加ボタン + 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((new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), "スーパー", "a-hongo"))); + RequestListActivity.requestlist.add(0, (new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), Yolp.getInstance().getCodeBySubcategory(selectedSubCategory), "a-hongo"))); finish(); } }); @@ -108,10 +174,31 @@ } }); + // リスナーを登録 + 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){ diff --git a/app/src/main/java/com/example/cosmosclient/views/DisplayGroupIDActivity.java b/app/src/main/java/com/example/cosmosclient/views/DisplayGroupIDActivity.java new file mode 100644 index 0000000..f3b1841 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/views/DisplayGroupIDActivity.java @@ -0,0 +1,50 @@ +package com.example.cosmosclient.views; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.os.Build; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.example.cosmosclient.R; +import com.example.cosmosclient.app.Cosmos; +import com.example.cosmosclient.entities.Group; + +public class DisplayGroupIDActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_display_group_id); + + EditText groupID = (EditText)findViewById(R.id.groupID); + // ボタンを設定 + Button copyButton = findViewById(R.id.copy_Button); + //読み取り専用にする設定 + groupID.setEnabled(false); +// //現在のグループ情報を格納しているものからgIdを取得 +// Cosmos app = (Cosmos) getApplication(); +// Group curentGroup = app.getCurentGroup(); +// //元となるgIdを取得完了 +// String gId = curentGroup.getgId(); + final String gId = "vrehngortis"; + groupID.setText(gId); + + copyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + ClipboardManager clipboard + = (ClipboardManager) getSystemService( + Context.CLIPBOARD_SERVICE); + clipboard.setPrimaryClip(ClipData.newPlainText("", gId)); + } + }); + + } + +} 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 5cdef54..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 @@ -44,10 +56,16 @@ boolean productColorFlag = true; //買うもの (true:白, false:黒) boolean deadlineColorFlag = true; //購入期限 boolean locationColorFlag = true; //場所 + boolean nameColorFlag = true; //名前 //Rotation制御 boolean deadlineRotationFlag = false; //(true:回転, false:未回転) + LinearLayout productView; + LinearLayout deadlineView; + LinearLayout locationView; + LinearLayout nameView; + Collator collator = Collator.getInstance(Locale.JAPANESE); //productOnClick @@ -58,6 +76,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 +94,8 @@ deadlineColorFlag = true; location.setColorFilter(null); locationColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; ResetRequestListTable(); AddRequestListTable(SortProduct()); } @@ -89,6 +110,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 +124,8 @@ productColorFlag = true; location.setColorFilter(null); locationColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; if (!deadlineRotationFlag) { deadline.setColorFilter(BLACK); @@ -115,7 +139,6 @@ ResetRequestListTable(); AddRequestListTable(ReverseDeadline()); } - } } }; @@ -128,6 +151,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 +169,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 @@ -173,9 +233,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()); } @@ -185,7 +245,15 @@ 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()); + } + }; + + //nameSortComparator + public Comparator nameSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + return collator.compare(r1.getName().toString(), r2.getName().toString()); } }; @@ -193,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); @@ -210,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); @@ -227,15 +358,18 @@ 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); + nameView = (LinearLayout)findViewById(R.id.name); + nameView.setOnClickListener(nameOnClick); + } @Override @@ -276,16 +410,16 @@ } private int ConvertMonth(int i, ArrayList requestList) { - if(requestList.get(i).getDeadline().getMonth() == 0) { - return 12; - } else { - return requestList.get(i).getDeadline().getMonth(); - } + return requestList.get(i).getDeadline().getMonth() + 1; } + @TargetApi(Build.VERSION_CODES.O) private void AddRequestListTable(ArrayList requestList) { Date now = new Date(); - for (int i = requestList.size()-1; i >= 0; i--) { + TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList); + requesttable.setShrinkAllColumns(true); + + for (int i = 0; i < requestList.size(); i++) { TableRow tableRow = new TableRow(this); TextView textProduct = new TextView(this); @@ -293,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())) { @@ -310,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); } } @@ -368,6 +501,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/java/com/example/cosmosclient/yolp/Category.java b/app/src/main/java/com/example/cosmosclient/yolp/Category.java new file mode 100644 index 0000000..c3ad816 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/yolp/Category.java @@ -0,0 +1,53 @@ +package com.example.cosmosclient.yolp; + +import java.util.ArrayList; + +public class Category { + String name; + ArrayList subCategories = new ArrayList(); + + public Category(String name) { + this.name = name; + } + + public Category(String name, ArrayList subCategoryNames) { + this.name = name; + this.subCategories = subCategoryNames; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ArrayList getSubCategories() { + return subCategories; + } + + public ArrayList getSubCategoryNames() { + ArrayList subNames = new ArrayList(); + for (SubCategory subCategory: subCategories) { + subNames.add(subCategory.getSubName()); + } + return subNames; + } + + public void setSubCategories(ArrayList subCategories) { + this.subCategories = subCategories; + } + + public void addSubCategory(SubCategory subCategory) { + this.subCategories.add(subCategory); + } + +// @Override +// public boolean equals(Object obj) { +// if (this == obj) return true; +// if (obj == null || getClass() != obj.getClass()) return false; +// Category that = (Category) obj; +// return subCategories.equals(that.subCategories) && name.equals(that.name); +// } +} diff --git a/app/src/main/java/com/example/cosmosclient/yolp/SubCategory.java b/app/src/main/java/com/example/cosmosclient/yolp/SubCategory.java new file mode 100644 index 0000000..891ba9d --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/yolp/SubCategory.java @@ -0,0 +1,35 @@ +package com.example.cosmosclient.yolp; + +public class SubCategory { + private int code; // 業種コード + private String subName; + + public SubCategory(int code, String name) { + this.code = code; + this.subName = name; + } + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public String getSubName() { + return subName; + } + + public void setSubName(String subName) { + this.subName = subName; + } + +// @Override +// public boolean equals(Object obj) { +// if (this == obj) return true; +// if (obj == null || getClass() != obj.getClass()) return false; +// SubCategory that = (SubCategory) obj; +// return code == that.code && subName == that.subName; +// } +} diff --git a/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java b/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java new file mode 100644 index 0000000..87e1a8a --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java @@ -0,0 +1,98 @@ +package com.example.cosmosclient.yolp; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; + +public class Yolp { + private static Yolp theInstance = null; + + private HashMap codeToSubcategory = new HashMap<>(); + private HashMap nameToCategory = new HashMap<>(); + + private Yolp() { +// Yolp.getInstance().getCategoryByName("ショッピング").getSubCategories(); +// for (Category c: Yolp.getInstance().getCategories()) { +// } +// for (String n: Yolp.getInstance().getCategoryNames()) { +// } + Category cat203 = new Category("家電・携帯電話"); + cat203.addSubCategory(new SubCategory(203001, "電化製品")); + cat203.addSubCategory(new SubCategory(203002,"家電量販店")); + cat203.addSubCategory(new SubCategory(203003,"携帯電話")); + cat203.addSubCategory(new SubCategory(203004, "パソコン")); + putNameToCategory(cat203.getName(),cat203); + + Category cat205 = new Category("コンビニ・スーパー"); + cat205.addSubCategory(new SubCategory(205001, "コンビニ")); + cat205.addSubCategory(new SubCategory(205002, "スーパー")); + putNameToCategory(cat205.getName(), cat205); + } + + public static Yolp getInstance() { + if (theInstance == null) { + theInstance = new Yolp(); + } + return theInstance; + } + + // 業種コードから業種名3 + public SubCategory getSubCategoryByCode(int code) { + return codeToSubcategory.get(code); + } + + public HashMap getCodeToSubcategory() { + 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; + } + + public void putCodeToSubCategory(int code, SubCategory subCategory) { + codeToSubcategory.put(code, subCategory); + } + + // 業種名2から業種名3 + public String[] getCategoryNames() { + return nameToCategory.keySet().toArray(new String[0]); + } + + public Collection getCategories() { + return nameToCategory.values(); + } + + public Category getCategoryByName(String name) { + return nameToCategory.get(name); + } + + public void setNameToCategory(HashMap nameToCategory) { + this.nameToCategory = nameToCategory; + } + + public void putNameToCategory(String name, Category category) { + nameToCategory.put(name, category); + for (SubCategory s: category.getSubCategories()) { + codeToSubcategory.put(s.getCode(), s); + } + } + +// @Override +// public boolean equals(Object o) { +// if (this == o) return true; +// if (o == null || getClass() != o.getClass()) return false; +// Yolp yolp = (Yolp) o; +// return codeToSubcategory.equals(yolp.codeToSubcategory) || nameToCategory.equals(yolp.nameToCategory); +// } +} diff --git a/app/src/main/res/layout/activity_add_member.xml b/app/src/main/res/layout/activity_add_member.xml index 7274a61..242f8aa 100644 --- a/app/src/main/res/layout/activity_add_member.xml +++ b/app/src/main/res/layout/activity_add_member.xml @@ -18,8 +18,8 @@ tools:layout_editor_absoluteX="0dp" /> - + android:theme="@style/AppTheme.AppBarOverlay" + app:layout_constraintTop_toTopOf="parent"> - + android:textSize="20sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/editTextProduct" + app:layout_constraintHorizontal_bias="0.01" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/appBarLayout" + app:layout_constraintVertical_bias="0.0" /> + android:paddingBottom="8dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@+id/textProductName" + app:layout_constraintTop_toBottomOf="@+id/appBarLayout" + app:layout_constraintVertical_bias="0.0" /> + android:textSize="20sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/editTextDeadline" + app:layout_constraintHorizontal_bias="0.01" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0" /> - + android:inputType="date" + app:layout_constraintEnd_toStartOf="@+id/calenderButton" + app:layout_constraintStart_toEndOf="@+id/textDeadline" + app:layout_constraintTop_toBottomOf="@+id/editTextProduct" + app:layout_constraintTop_toTopOf="parent" /> + android:layout_marginEnd="5dp" + android:layout_marginRight="5dp" + android:layout_marginBottom="8dp" + android:src="@drawable/ic_date_range" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@+id/editTextDeadline" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0" /> + android:textSize="20sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toStartOf="@+id/spinnerLocationCategory" + app:layout_constraintHorizontal_bias="0.01" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0" /> + android:layout_marginStart="10dp" + android:layout_marginLeft="10dp" + android:layout_marginTop="250dp" + android:layout_marginEnd="5dp" + android:layout_marginRight="5dp" + android:layout_marginBottom="8dp" + android:spinnerMode="dropdown" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toEndOf="@+id/textLocation" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.0" /> + android:layout_marginStart="20dp" + android:layout_marginLeft="20dp" + android:layout_marginTop="25dp" + android:layout_marginEnd="5dp" + android:layout_marginRight="5dp" + android:layout_marginBottom="270dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.0" + app:layout_constraintStart_toEndOf="@+id/textLocation" + app:layout_constraintTop_toBottomOf="@+id/spinnerLocationCategory" + app:layout_constraintVertical_bias="0.00999999" />