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..4c3cd5d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,18 +3,18 @@ xmlns:tools="http://schemas.android.com/tools" package="com.example.cosmosclient"> - - + + - + @@ -70,7 +70,8 @@ + android:theme="@style/AppTheme.NoActionBar"> + \ No newline at end of file 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..a9307f1 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,34 @@ //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) { // エディットテキストのテキストを取得 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), selectedSubCategory, "a-hongo"))); finish(); } }); @@ -108,10 +138,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/RequestListActivity.java b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java index 5cdef54..de4d635 100644 --- a/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java +++ b/app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java @@ -44,6 +44,7 @@ boolean productColorFlag = true; //買うもの (true:白, false:黒) boolean deadlineColorFlag = true; //購入期限 boolean locationColorFlag = true; //場所 + boolean nameColorFlag = true; //名前 //Rotation制御 boolean deadlineRotationFlag = false; //(true:回転, false:未回転) @@ -58,6 +59,7 @@ ImageView product = (ImageView) findViewById(R.id.image_product); ImageView deadline = (ImageView) findViewById(R.id.image_deadline); ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); if (!productColorFlag) { product.setColorFilter(null); productColorFlag = true; @@ -75,6 +77,8 @@ deadlineColorFlag = true; location.setColorFilter(null); locationColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; ResetRequestListTable(); AddRequestListTable(SortProduct()); } @@ -89,6 +93,7 @@ ImageView product = (ImageView) findViewById(R.id.image_product); ImageView deadline = (ImageView) findViewById(R.id.image_deadline); ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); if (!deadlineColorFlag) { deadline.setColorFilter(null); deadlineColorFlag = true; @@ -102,6 +107,8 @@ productColorFlag = true; location.setColorFilter(null); locationColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; if (!deadlineRotationFlag) { deadline.setColorFilter(BLACK); @@ -115,7 +122,6 @@ ResetRequestListTable(); AddRequestListTable(ReverseDeadline()); } - } } }; @@ -128,6 +134,7 @@ ImageView product = (ImageView) findViewById(R.id.image_product); ImageView deadline = (ImageView) findViewById(R.id.image_deadline); ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); if (!locationColorFlag) { location.setColorFilter(null); locationColorFlag = true; @@ -145,12 +152,48 @@ productColorFlag = true; deadline.setColorFilter(null); deadlineColorFlag = true; + name.setColorFilter(null); + nameColorFlag = true; ResetRequestListTable(); AddRequestListTable(SortLocation()); } } }; + //locationOnClick + public View.OnClickListener nameOnClick = new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(RequestListActivity.this, "name sorted", Toast.LENGTH_SHORT).show(); + ImageView product = (ImageView) findViewById(R.id.image_product); + ImageView deadline = (ImageView) findViewById(R.id.image_deadline); + ImageView location = (ImageView) findViewById(R.id.image_location); + ImageView name = (ImageView) findViewById(R.id.image_name); + if (!nameColorFlag) { + name.setColorFilter(null); + nameColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(requestlist); + } else { + if(deadlineRotationFlag) { + deadlineRotationFlag = false; + } else { + deadline.setRotation(0); + } + name.setColorFilter(BLACK); + nameColorFlag = false; + location.setColorFilter(null); + locationColorFlag = true; + product.setColorFilter(null); + productColorFlag = true; + deadline.setColorFilter(null); + deadlineColorFlag = true; + ResetRequestListTable(); + AddRequestListTable(SortName()); + } + } + }; + //productSortComparator public Comparator productSortComparator = new Comparator() { @Override @@ -173,9 +216,9 @@ public int compare(Request r1, Request r2) { if (r1.getDeadline() == null || r2.getDeadline() == null) return 0; - if(r1.getDeadline().getDate() >= r2.getDeadline().getDate() || r1.getDeadline().getMonth() < r2.getDeadline().getMonth()) + if((r1.getDeadline().compareTo(r2.getDeadline())) == 1) return -1; - if(r1.getDeadline().getDate() <= r2.getDeadline().getDate() || r1.getDeadline().getMonth() < r2.getDeadline().getMonth()) + if((r1.getDeadline().compareTo(r2.getDeadline())) == -1) return 1; return r1.getDeadline().compareTo(r2.getDeadline()); } @@ -189,6 +232,14 @@ } }; + //nameSortComparator + public Comparator nameSortComparator = new Comparator() { + @Override + public int compare(Request r1, Request r2) { + return collator.compare(r1.getName().toString(), r2.getName().toString()); + } + }; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -236,6 +287,9 @@ LinearLayout locationView = (LinearLayout)findViewById(R.id.location); locationView.setOnClickListener(locationOnClick); + LinearLayout nameView = (LinearLayout)findViewById(R.id.name); + nameView.setOnClickListener(nameOnClick); + } @Override @@ -276,16 +330,12 @@ } 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; } private void AddRequestListTable(ArrayList requestList) { Date now = new Date(); - for (int i = requestList.size()-1; i >= 0; i--) { + for (int i = 0; i < requestList.size(); i++) { TableRow tableRow = new TableRow(this); TextView textProduct = new TextView(this); @@ -368,6 +418,13 @@ Collections.sort(locationsortRequestlist, locationSortComparator); return locationsortRequestlist; } + + private ArrayList SortName() { + ArrayList namesortRequestlist = (ArrayList) requestlist.clone(); + + Collections.sort(namesortRequestlist, nameSortComparator); + return namesortRequestlist; + } } diff --git a/app/src/main/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..1532db5 --- /dev/null +++ b/app/src/main/java/com/example/cosmosclient/yolp/Yolp.java @@ -0,0 +1,87 @@ +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 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_request.xml b/app/src/main/res/layout/activity_add_request.xml index 42bd2ba..5a0f5e9 100644 --- a/app/src/main/res/layout/activity_add_request.xml +++ b/app/src/main/res/layout/activity_add_request.xml @@ -1,105 +1,189 @@ - + 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" />