Newer
Older
NemophilaClient / app / src / main / java / com / example / nemophila / TestActivity.java
  1. package com.example.nemophila;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.lifecycle.ViewModelProvider;
  5.  
  6. import android.content.Intent;
  7. import android.net.Uri;
  8. import android.os.Bundle;
  9. import android.view.View;
  10. import android.widget.AdapterView;
  11. import android.widget.AdapterView.OnItemSelectedListener;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.Button;
  14. import android.widget.ImageView;
  15. import android.widget.Spinner;
  16.  
  17. import com.example.nemophila.viewmodels.AccountViewModel;
  18. import com.example.nemophila.viewmodels.FriendViewModel;
  19. import com.example.nemophila.viewmodels.PostsViewModel;
  20. import com.example.nemophila.viewmodels.ShopsViewModel;
  21.  
  22. import java.util.Base64;
  23.  
  24. public class TestActivity extends AppCompatActivity {
  25. int position;
  26.  
  27. @Override
  28. protected void onCreate(Bundle savedInstanceState) {
  29. super.onCreate(savedInstanceState);
  30. setContentView(R.layout.activity_test);
  31.  
  32. Nemophila nemophila = (Nemophila) this.getApplication();
  33.  
  34. //テスト用ViewModel(ViewModelが増えた場合はここで準備。spinnerItemに名前も追加すること)
  35. //ViewModelへのアクセス
  36. ShopsViewModel shopsViewModel = new ViewModelProvider(this).get(ShopsViewModel.class);
  37. AccountViewModel accountViewModel = new ViewModelProvider(this).get(AccountViewModel.class);
  38. PostsViewModel postsViewModel = new ViewModelProvider(this).get(PostsViewModel.class);
  39. FriendViewModel friendViewModel = new ViewModelProvider(this).get(FriendViewModel.class);
  40.  
  41. //テスト用のspinner
  42. Spinner spinner = findViewById(R.id.testspinner);
  43. String[] spinnerItems = {"ShopsViewModel", "AccountViewModel", "PostsViewModel", "FriendsViewModel"}; //ここに名前を追加
  44. ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, spinnerItems);
  45. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  46. spinner.setAdapter(adapter);
  47. spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
  48. @Override
  49. public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
  50. position = i;
  51. }
  52. @Override
  53. public void onNothingSelected(AdapterView<?> adapterView) {
  54.  
  55. }
  56. });
  57.  
  58. // setViewModelのテスト用
  59. Button setViewModelButton = (Button)findViewById(R.id.setViewModel);
  60. setViewModelButton.setOnClickListener(new View.OnClickListener() {
  61. @Override
  62. public void onClick(View view) {
  63. switch (position){
  64. //ここにテストしたい処理を追加する( 0はShopsViewModel、1はAccountViewModel、2はPostsViewModel)
  65. case 0:
  66. shopsViewModel.setViewArea(20.0, 40.0, 10.0, 30.0);
  67. // shopsViewModel.start(500, nemophila);
  68. break;
  69. case 1:
  70. //accountViewModel.getAccountPosts("1111");
  71. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
  72. String s = "Y29udGVudDovL2NvbS5hbmRyb2lkLnByb3ZpZGVycy5tZWRpYS5kb2N1bWVudHMvZG9jdW1lbnQvaW1hZ2UlM0EzNA==";
  73. s = new String(Base64.getDecoder().decode(s));
  74. Uri uri = Uri.parse(s);
  75. ImageView imageView = findViewById(R.id.imageView4);
  76. imageView.setImageURI(uri);
  77. break;
  78. case 2:
  79. postsViewModel.createPost("1114", "dbfd3740-8dcc-4b9c-b3b0-42c908da1c65", "151347fa-2c90-44d7-ba48-f23f475b910d", 1,
  80. "和食", "辛いね", "", "", "");
  81. break;
  82. case 3:
  83. // friendViewModel.putRequesting("1111", "1112", "a95d68cc-4efb-49e2-8f55-799f768a5c09");
  84. }
  85. }
  86. });
  87. }
  88. }