diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 361b5c3..4934277 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -114,22 +114,22 @@
android:name=".PostActivity"
android:exported="true"
android:label="@string/title_activity_post">
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/example/nemophila/ShopActivity.java b/app/src/main/java/com/example/nemophila/ShopActivity.java
index 53c5ff9..96b6d4d 100644
--- a/app/src/main/java/com/example/nemophila/ShopActivity.java
+++ b/app/src/main/java/com/example/nemophila/ShopActivity.java
@@ -30,27 +30,38 @@
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shop);
- //NemophilaからcurrentShopを取得し店名の表示
+ //テスト用に仮にcurrentShopをセットしたい
+ Shop kariShop = new Shop();
+ kariShop.setSid("151347fa-2c90-44d7-ba48-f23f475b910d");
+ kariShop.setName("店D");
+ kariShop.setLongitude(56.7);
+ kariShop.setLatitude(78.9);
+ ((Nemophila)getApplication()).setCurrentShop(kariShop);
+
+ //NemophilaからcurrentShopを取得、店名の表示
//currentshopに何もないとgetNameとgetSidでアプリが落ちます
Shop shop;
String shopName;
String sid;
shop = ((Nemophila)getApplication()).getCurrentShop();
-// shopName = shop.getName();
-// sid = shop.getSid();
+ shopName = shop.getName();
+ sid = shop.getSid();
TextView nameView = (TextView) findViewById(R.id.shopName);
- //テスト用に仮店名でセット
- nameView.setText("お店A");
-// nameView.setText(shopName);
+ nameView.setText(shopName);
//右上のボタンで投稿画面(PostActivity)へ遷移
Button toPostButton = (Button)findViewById(R.id.toPostAcButton);
toPostButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
- Intent intent = new Intent(getApplication(), PostActivity.class);
+ Intent intent = new Intent(ShopActivity.this, PostActivity.class);
+ intent.putExtra("toPostSid",sid);
startActivity(intent);
}
});
+// PostActivity側でsidを受け取ってください
+// Intent intent = getIntent();
+// sid = intent.getStringExtra("toPostSid");
+// みたいな感じで受け取れるはずです
//左上のボタンでメイン画面へ遷移
Button returnButton = (Button)findViewById(R.id.shopAcReturnButton);
@@ -63,12 +74,14 @@
List postsDataset = new ArrayList<>();
- //RecyclerView(表示以外の設定)
+ //RecyclerView(表示の設定、直接表示するところはLivedataを購読しているonChanged内)
+ //xmlからrvにRecyclerViewを取得、アダプターを宣言
RecyclerView rv = (RecyclerView) findViewById(R.id.postsList);
adapter = new ShopActivityAdapter(postsDataset);
+ //一行ずつを縦に(LinearLayout)表示するLayoutManagerを宣言
LinearLayoutManager llm = new LinearLayoutManager(this);
-
+ //
RecyclerView.ItemDecoration itemDecoration =
new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
rv.addItemDecoration(itemDecoration);
@@ -76,23 +89,21 @@
rv.setHasFixedSize(true);
rv.setLayoutManager(llm);
- //PostViewModelを宣言し、LiveDataへの購読
+ //PostViewModelを宣言し、currentShopから取得したsidの店舗の投稿をロード
PostsViewModel postsViewModel = new ViewModelProvider(this).get(PostsViewModel.class);
- //通信テスト用データ(本来currentShopのsidをPostJsonに送る)
- postsViewModel.loadShopPost("151347fa-2c90-44d7-ba48-f23f475b910d");
+ postsViewModel.loadShopPost(sid);
//LiveDataへの購読
postsViewModel.getShopPostLiveData().observe(this, new Observer>() {
@Override
public void onChanged(List ShopPosts) {
- //postsDatasetを一旦クリアし、LiveDataから受け取ったデータを一つずつセット
+ //postsDatasetを一旦クリアし、LiveDataから受け取ったデータを一つずつセット(重複しないように)
postsDataset.clear();
for (Post post: ShopPosts){
PostDataModel data = new PostDataModel();
data.setName(post.getName());
data.setDate(post.getDate());
-
- //intで受け取った評価を対応した星の数のStringに変換
+ //rateはintで受け取った評価に対応した星の数のStringに変換してセット
int intRate = post.getRate();
String strRate = "";
for (int i = 0; i < 5; i++){
@@ -108,7 +119,7 @@
postsDataset.add(data);
}
- //RecyclerViewをonChangedが呼ばれるたび表示
+ //RecyclerViewをonChangedが呼ばれるたび表示(アダプターを更新してRecyclerViewにセット)
adapter.setList(postsDataset);
rv.setAdapter(adapter);
}