aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomAdapter.java
blob: c7a0f292575da508385a8cfa2e984086efd25e2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package me.brysonsteck.wiimmfiwatcher.wiimmfi;

import android.annotation.SuppressLint;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.card.MaterialCardView;

import org.jsoup.*;

import java.util.ArrayList;

import me.brysonsteck.wiimmfiwatcher.R;

public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.ViewHolder>{
    String display;
    String playerLink;
    String header;
    ArrayList<Player> players;

    public RoomAdapter (String display, String playerLink, String header, ArrayList<Player> players) {
        this.display = display;
        this.playerLink = playerLink;
        this.header = header;
        this.players = players;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.room_player_data_item, parent, false);
        return new ViewHolder(view);
    }

    @SuppressLint("ResourceAsColor")
    @Override
    public void onBindViewHolder(@NonNull RoomAdapter.ViewHolder holder, int position) {
        MaterialCardView cardView = holder.itemView.findViewById(R.id.player_card_view);
        TextView rosterNumber = holder.itemView.findViewById(R.id.roster_number);
        TextView miiName = holder.itemView.findViewById(R.id.mii_names);
        TextView variableDisplay = holder.itemView.findViewById(R.id.variable_side_data);
        Player currentPlayer = players.get(position);
        if (currentPlayer.watching) {
            cardView.setCardBackgroundColor(Color.parseColor("#0D47A1"));
            rosterNumber.setTextColor(Color.WHITE);
            miiName.setTextColor(Color.WHITE);
            variableDisplay.setTextColor(Color.WHITE);
        }
        rosterNumber.setText(currentPlayer.rosterNumber + ")  ");
        miiName.setText(currentPlayer.miiName);

        switch (display) {
            case "fc":
                variableDisplay.setText(currentPlayer.friendCode);
                break;
            case "roles":
                variableDisplay.setText(currentPlayer.role);
                break;
            case "login_regions":
                variableDisplay.setText(currentPlayer.loginRegion);
                break;
            case "room_match":
                variableDisplay.setText(currentPlayer.roomMatch);
                break;
            case "world":
                variableDisplay.setText(currentPlayer.world);
                break;
            case "conn_fail":
                variableDisplay.setText(currentPlayer.connFail);
                break;
            case "vr_br":
                variableDisplay.setText("VR: " + currentPlayer.vr + " / BR: " + currentPlayer.br);
                break;
        }

    }

    @Override
    public int getItemCount() {
        if (players == null) {
            return 0;
        } else {
            return players.size();
        }
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}