diff --git a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java index debd96f..a5d716e 100644 --- a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java +++ b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java @@ -69,10 +69,10 @@ Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); - setupWithViewModel(); + gameViewModel = new ViewModelProvider(this).get(GameViewModel.class); + resources = getResources(); View view = inflater.inflate(R.layout.fragment_card_drawing, container, false); - Context context = getContext(); // ImageButton16個の型を使いまわしやすいように配列で使用 imageButtons = new ImageButton[] { @@ -113,34 +113,6 @@ (ImageView) view.findViewById(R.id.backColour15) }; - for (int i = 0; i < drawingList.size(); i++) { - // タップとロングタップのセット - imageButtons[i].setOnClickListener(this::onClick); - imageButtons[i].setOnLongClickListener(this::onLongTap); - backColors[i].setOnLongClickListener(this::onLongTap); - - // 画像のセット - String urlSt = drawingList.get(map.get(i)).getDrawing(); - setImage(i, urlSt, context); - - // 初回だけセットする外枠の、メンバーとマスターで表示分け - // メンバー:全て肌色、マスター:赤・青・黒・グレーの表示 - if(isMaster == true) { - if (colorList.get(i) == "r") { - backColors[i].setBackground(resources.getDrawable(R.drawable.red_image)); - } else if (colorList.get(i) == "b") { - backColors[i].setBackground(resources.getDrawable(R.drawable.blue_image)); - } else if (colorList.get(i) == "g") { - backColors[i].setBackground(resources.getDrawable(R.drawable.gray_image)); - } else if (colorList.get(i) == "d") { - backColors[i].setBackground(resources.getDrawable(R.drawable.black_image)); - } - } else { - backColors[i].setBackground(resources.getDrawable(R.drawable.skin_image)); - } - - } - // Openされた画像ををObserveして、Viewに反映 gameViewModel.getOpenLiveData().observe ( getViewLifecycleOwner(), @@ -150,6 +122,15 @@ } ); + gameViewModel.getImageLiveData().observe( + getViewLifecycleOwner(), + gameJsonObserver -> { + System.out.println("Hello"); + System.out.println(gameJsonObserver.getDrawingList()); + setupWithViewModel(); + } + ); + return view; } @@ -189,70 +170,46 @@ } private void setupWithViewModel() { - gameViewModel = new ViewModelProvider(this).get(GameViewModel.class); - //drawingList = gameViewModel.getGame().getDrawingList(); - //map = gameViewModel.getGame().getMap(); - //colorList = gameViewModel.getGame().getColorList(); + Iris iris = (Iris) this.getActivity().getApplication(); + myTeam = iris.getTeam(); + drawingList = gameViewModel.getGame().getDrawingList(); + map = gameViewModel.getGame().getMap(); + colorList = gameViewModel.getGame().getColorList(); - // 本来は上を開放するが、値が空なので仮値を指定(テストフローでも値が空) - Drawing drawing0 = new Drawing(); - Drawing drawing1 = new Drawing(); - Drawing drawing2 = new Drawing(); - Drawing drawing3 = new Drawing(); - Drawing drawing4 = new Drawing(); - Drawing drawing5 = new Drawing(); - Drawing drawing6 = new Drawing(); - Drawing drawing7 = new Drawing(); - Drawing drawing8 = new Drawing(); - Drawing drawing9 = new Drawing(); - Drawing drawing10 = new Drawing(); - Drawing drawing11 = new Drawing(); - Drawing drawing12 = new Drawing(); - Drawing drawing13 = new Drawing(); - Drawing drawing14 = new Drawing(); - Drawing drawing15 = new Drawing(); - drawing0.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test16.jpg"); - drawing1.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test01.jpg"); - drawing2.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test02.jpg"); - drawing3.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test03.jpg"); - drawing4.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test04.jpg"); - drawing5.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test05.jpg"); - drawing6.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test06.jpg"); - drawing7.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test07.jpg"); - drawing8.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test08.jpg"); - drawing9.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test09.jpg"); - drawing10.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test10.jpg"); - drawing11.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test11.jpg"); - drawing12.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test12.jpg"); - drawing13.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test13.jpg"); - drawing14.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test14.jpg"); - drawing15.setDrawing("http://nitta-lab-www.is.konan-u.ac.jp/irisdata/image/test15.jpg"); + Context context = getContext(); - drawingList = new HashMap() { - { - put(11, drawing11); - put(12, drawing12); - put(1, drawing1); - put(8, drawing8); - put(6, drawing6); - put(14, drawing14); - put(4, drawing4); - put(15, drawing15); - put(10, drawing10); - put(2, drawing2); - put(0, drawing0); - put(7, drawing7); - put(13, drawing13); - put(3, drawing3); - put(5, drawing5); - put(9, drawing9); + for (int i = 0; i < drawingList.size(); i++) { + // タップとロングタップのセット + imageButtons[i].setOnClickListener(this::onClick); + imageButtons[i].setOnLongClickListener(this::onLongTap); + backColors[i].setOnLongClickListener(this::onLongTap); + + // 画像のセット + String urlSt = drawingList.get(map.get(i)).getDrawing(); + setImage(i, urlSt, context); + + System.out.println(colorList.get(i)); + String color = colorList.get(i); + // 初回だけセットする外枠の、メンバーとマスターで表示分け + // メンバー:全て肌色、マスター:赤・青・黒・グレーの表示 + if(isMaster == true) { + if (colorList.get(i).contains("r")) { + backColors[i].setBackground(resources.getDrawable(R.drawable.red_image)); + } else if (colorList.get(i).contains("b")) { + backColors[i].setBackground(resources.getDrawable(R.drawable.blue_image)); + } else if (colorList.get(i).contains("g")) { + backColors[i].setBackground(resources.getDrawable(R.drawable.gray_image)); + } else if (colorList.get(i).contains("d")) { + backColors[i].setBackground(resources.getDrawable(R.drawable.black_image)); + } else { + System.out.println("本当は...:「" + colorList.get(i) + "」"); + } + } else { + backColors[i].setBackground(resources.getDrawable(R.drawable.skin_image)); } - }; - map = new ArrayList<>(Arrays.asList(2, 13, 6, 0, 7, 8, 4, 9, 14, 1, 3, 15, 11, 5, 12, 10)); - colorList = new ArrayList<>(Arrays.asList("r", "b", "b", "r", "b", "r", "d", "b", "g", "b", "r", "g", "b", "r", "g", "r")); - System.out.print(drawingList.size()); - System.out.print("よばれたよ"); + } + } /** @@ -336,16 +293,16 @@ for(int i=0; i< openList.size(); i++) { if (openList.get(i) == true) { // オープンだったときの描画 - if (colorList.get(i) == "r") { + if (colorList.get(i).contains("r")) { backColors[i].setBackground(resources.getDrawable(R.drawable.red_image)); imageButtons[i].setVisibility(View.INVISIBLE); - } else if (colorList.get(i) == "b") { + } else if (colorList.get(i).contains("b")) { backColors[i].setBackground(resources.getDrawable(R.drawable.blue_image)); imageButtons[i].setVisibility(View.INVISIBLE); - } else if (colorList.get(i) == "g") { + } else if (colorList.get(i).contains("g")) { backColors[i].setBackground(resources.getDrawable(R.drawable.gray_image)); imageButtons[i].setVisibility(View.INVISIBLE); - } else if (colorList.get(i) == "d") { + } else if (colorList.get(i).contains("d")) { backColors[i].setBackground(resources.getDrawable(R.drawable.black_image)); imageButtons[i].setVisibility(View.INVISIBLE); finishGameAlertMake(i, myTeam, nowTurn); @@ -380,16 +337,16 @@ private void setOpenRealTime(int cno, boolean isOK) { // 裏返す処理 if(isOK) { - if (colorList.get(cno) == "r") { + if (colorList.get(cno).contains("r")) { backColors[cno].setBackground(resources.getDrawable(R.drawable.red_image)); imageButtons[cno].setVisibility(View.INVISIBLE); - } else if (colorList.get(cno) == "b") { + } else if (colorList.get(cno).contains("b")) { backColors[cno].setBackground(resources.getDrawable(R.drawable.blue_image)); imageButtons[cno].setVisibility(View.INVISIBLE); - } else if (colorList.get(cno) == "g") { + } else if (colorList.get(cno).contains("g")) { backColors[cno].setBackground(resources.getDrawable(R.drawable.gray_image)); imageButtons[cno].setVisibility(View.INVISIBLE); - } else if (colorList.get(cno) == "d") { + } else if (colorList.get(cno).contains("d")) { backColors[cno].setBackground(resources.getDrawable(R.drawable.black_image)); imageButtons[cno].setVisibility(View.INVISIBLE); finishGameAlertMake(cno, myTeam, nowTurn); @@ -397,6 +354,7 @@ setAnime(cno); } //TODO: gameViewModel.set〇〇(cno)が完成したら + //gameViewModel.se }