(再々々)locationをStringからintに変更しました
1 parent c4a4744 commit cfa1851fcb4a10fed233d8a959a0dc8deee22d2b
a-hongo authored on 16 Jul 2019
Showing 5 changed files
View
28
app/src/main/java/com/example/cosmosclient/entities/Request.java
import java.util.Date;
 
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;
public void setDeadline(Date deadline) {
this.deadline = deadline;
}
 
public String getLocation() {
public int getLocation() {
return location;
}
 
public void setLocation(String location) {
public void setLocation(int location) {
this.location = location;
}
 
public String getName() {
 
public void setName(String name) {
this.name = name;
}
 
}
View
155
app/src/main/java/com/example/cosmosclient/views/AddRequestActivity.java
 
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();
 
//DatePickerDialogインスタンスを取得
DatePickerDialog datePickerDialog = new DatePickerDialog(AddRequestActivity.this, new DatePickerDialog.OnDateSetListener() {
 
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
curYear = year;
curMonth = month;
curDayOfMonth = 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();
}
});
@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(AddRequestActivity.this, new DatePickerDialog.OnDateSetListener() {
 
@Override
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
curYear = year;
curMonth = month;
curDayOfMonth = 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()メソッドを定義
}
});
 
// 追加ボタン
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// エディットテキストのテキストを取得
String inputProduct = editTextProduct.getText().toString();
 
// 取得したテキストを TextView に張り付ける
RequestListActivity.requestlist.add(0, (new Request(inputProduct, new Date(curYear, curMonth, curDayOfMonth), selectedSubCategory, "a-hongo")));
finish();
}
});
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<Request> call = requestsService.getRequestsListByGid();
// //サーバからのレスポンス
// call.enqueue(new Callback<Request>() {
// //成功時
// @Override
// public void onResponse(Call<Request> call, Response<Request> 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<Request> 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), Yolp.getInstance().getCodeBySubcategory(selectedSubCategory), "a-hongo")));
finish();
}
});
 
// リスナーを登録
category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// アイテムが選択された時
}
 
 
}
View
123
app/src/main/java/com/example/cosmosclient/views/RequestListActivity.java
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;
import android.view.Gravity;
import android.support.v7.app.ActionBarDrawerToggle;
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;
import android.widget.TableRow;
import android.widget.TextView;
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;
import java.util.Collections;
import java.util.Comparator;
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
implements NavigationView.OnNavigationItemSelectedListener {
 
Toast toast; //動作テスト用
 
 
 
//Request List
public static ArrayList<Request> requestlist = new ArrayList<>();
 
boolean nameColorFlag = true; //名前
 
//Rotation制御
boolean deadlineRotationFlag = false; //(true:回転, false:未回転)
 
LinearLayout productView;
LinearLayout deadlineView;
LinearLayout locationView;
LinearLayout nameView;
 
Collator collator = Collator.getInstance(Locale.JAPANESE);
 
//productOnClick
//locationSortComparator
public Comparator<Request> locationSortComparator = new Comparator<Request>() {
@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
@Override
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<ArrayList<Request>> requestsListByGidCall = requestsService.getRequestsListByGid(gid, token);
//
// //サーバからのレスポンス
// requestsListByGidCall.enqueue(new Callback<Request>() {
// //成功時
// @Override
// public void onResponse(Call<Request> call, Response<Request> response) {
// if (response.isSuccessful()) {
// Request result = response.body();
//
// Call<Request> requestsDetailByGidAndRidcall = requestsService.getRequestsDetailByGidAndRid(gid, token, result.getrId());
// //サーバからのレスポンス
// requestsDetailByGidAndRidcall.enqueue(new Callback<Request>() {
// //成功時
// @Override
// public void onResponse(Call<Request> call, Response<Request> 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<Request> 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<Request> call, Throwable t) {
// //t.printStackTrace();
// Toast.makeText(RequestListActivity.this, "RequestListの取得失敗しました", Toast.LENGTH_SHORT).show();
// }
// });
 
Toolbar toolbar = (Toolbar) findViewById(R.id.requestlist_toolbar);
setSupportActionBar(toolbar);
 
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.addrequest_button);
 
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);
 
//LEFT hamburger button
DrawerLayout requestlistDrawer = (DrawerLayout) findViewById(R.id.request_list_drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, requestlistDrawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
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.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);
 
}
 
private int ConvertMonth(int i, ArrayList<Request> requestList) {
return requestList.get(i).getDeadline().getMonth() + 1;
}
 
@TargetApi(Build.VERSION_CODES.O)
private void AddRequestListTable(ArrayList<Request> 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);
 
TextView textProduct = new TextView(this);
textProduct.setText(requestList.get(i).getProduct());
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())) {
// textDeadline.setText("期限切れ");
// textDeadline.setText(now.getMonth() + "/" + now.getDate());
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);
 
TableLayout requesttable = (TableLayout)findViewById(R.id.RequestList);
tableRow.addView(textName, new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT));
 
requesttable.addView(tableRow);
}
}
 
Collections.sort(namesortRequestlist, nameSortComparator);
return namesortRequestlist;
}
}
 
 
 
 
View
app/src/main/java/com/example/cosmosclient/yolp/Yolp.java
View
app/src/main/res/layout/content_request_list.xml