| | 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; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | |
---|
| | |