diff --git a/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java b/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java index 32e21ef..28a99cb 100644 --- a/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java +++ b/app/src/main/java/org/ntlab/amaryllis/client/MainActivity.java @@ -28,11 +28,18 @@ import com.google.android.material.bottomnavigation.BottomNavigationView; +import org.ntlab.amaryllis.client.entities.Category; import org.ntlab.amaryllis.client.fragment.MapsFragment; import org.ntlab.amaryllis.client.resources.AccountsRest; +import org.ntlab.amaryllis.client.resources.CategoriesRest; import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; @@ -42,6 +49,7 @@ private static final String TAG = MainActivity.class.getSimpleName(); LocationManager locationManager; private ArrayList listeners = new ArrayList<>(); + private HashMap categories; @Override protected void onCreate(Bundle savedInstanceState) { @@ -56,6 +64,29 @@ NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration); NavigationUI.setupWithNavController(navView, navController); + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/amaryllis/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + final CategoriesRest categoryService = retrofit.create(CategoriesRest.class); + Call> call = categoryService.getcategories(); + call.enqueue(new Callback>() { + @Override + public void onResponse(Call> call, Response> response) { + List clist = response.body(); + HashMap categories = new HashMap<>(); + for (Category c : clist){ + categories.put(c.getcId(),c); + } + MainActivity.this.categories = categories; + } + + @Override + public void onFailure(Call> call, Throwable t) { + + } + }); + LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { @@ -63,6 +94,7 @@ } manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } + private void locationStart(){ Log.d("debug","locationStart()"); @@ -160,4 +192,8 @@ android.os.Process.killProcess(android.os.Process.myPid()); } + public Category getCategory(String cid){ + return categories.get(cid); + } + } \ No newline at end of file