aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi')
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java15
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java100
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java134
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java64
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java97
5 files changed, 407 insertions, 3 deletions
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java
new file mode 100644
index 0000000..792f14f
--- /dev/null
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java
@@ -0,0 +1,15 @@
+package com.example.wiimmterfaceandroid.wiimmfi;
+
+public class Player {
+ String rosterNumber;
+ String miiName;
+ String friendCode;
+ String role;
+ String loginRegion;
+ String roomMatch;
+ String world;
+ String connFail;
+ String vr;
+ String br;
+ boolean watching;
+}
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java
index 4145db7..dfa51e7 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java
@@ -1,4 +1,102 @@
package com.example.wiimmterfaceandroid.wiimmfi;
-public class RoomAdapter {
+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 org.jsoup.*;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.example.wiimmterfaceandroid.R;
+import com.google.android.material.card.MaterialCardView;
+import com.google.android.material.color.MaterialColors;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class RoomAdapter extends RecyclerView.Adapter<RoomAdapter.ViewHolder>{
+
+ String display;
+ String playerLink;
+ String header;
+ ArrayList<Player> players;
+ boolean online = true;
+ 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);
+ }
+ }
}
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
new file mode 100644
index 0000000..2fccffc
--- /dev/null
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
@@ -0,0 +1,134 @@
+package com.example.wiimmterfaceandroid.wiimmfi;
+
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public class RoomData {
+ String roomHeader;
+ String playerLink;
+ String friendCode;
+ ArrayList<Player> players = new ArrayList<>();
+
+ public RoomData (ArrayList<Player> players, String playerLink, String friendCode) {
+ this.playerLink = getPlayerLink();
+ this.friendCode = friendCode;
+ Document doc = null;
+
+ if (playerLink == null) {
+ System.out.println("The player link is null for some reason");
+ } else {
+
+ try {
+ doc = Jsoup.connect("https://wiimmfi.de/" + this.playerLink).get();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ Element table = doc.select("table").get(0);
+ Elements rows = table.select("tr");
+
+ for (int i = 0; i < rows.size(); i++) {
+ Element row = rows.get(i);
+ Elements colPlayers = row.select("td");
+ Elements colHeader = row.select("th");
+
+ if (colHeader.size() > 0) {
+ if (!colHeader.get(0).text().equals("friend code")) {
+ roomHeader = colHeader.get(0).text();
+ }
+ }
+ if (colPlayers.size() > 0) {
+
+ Player currentPlayer = new Player();
+ for (int j = 0; j < colPlayers.size(); j++) {
+ System.out.println("Player Data: " + colPlayers.get(j).text());
+ switch (j) {
+ case 0:
+ currentPlayer.friendCode = colPlayers.get(0).text();
+ break;
+ case 1:
+ currentPlayer.role = colPlayers.get(1).text().split(" ")[1];
+ currentPlayer.rosterNumber = colPlayers.get(1).text().split(" ")[0].replaceAll("\\s", "");
+ break;
+ case 2:
+ currentPlayer.loginRegion = colPlayers.get(2).text();
+ break;
+ case 3:
+ currentPlayer.roomMatch = colPlayers.get(3).text();
+ break;
+ case 4:
+ currentPlayer.world = colPlayers.get(4).text();
+ break;
+ case 5:
+ currentPlayer.connFail = colPlayers.get(5).text();
+ break;
+ case 6:
+ currentPlayer.vr = colPlayers.get(6).text();
+ break;
+ case 7:
+ currentPlayer.br = colPlayers.get(7).text();
+ break;
+ case 8:
+ currentPlayer.miiName = colPlayers.get(8).text();
+ break;
+ }
+ }
+ if (currentPlayer.friendCode.equals(friendCode)) {
+ currentPlayer.watching = true;
+ }
+ players.add(currentPlayer);
+ }
+
+ }
+ }
+ }
+
+ public String getPlayerLink() {
+ try {
+ Document doc = null;
+
+ doc = Jsoup.connect("https://wiimmfi.de/stats/mkw").get();
+ Element table = doc.select("table").get(0);
+ Elements rows = table.select("tr");
+
+ for (int i = 0; i < rows.size(); i++) {
+ Element row = rows.get(i);
+ Elements colPlayers = row.select("td");
+ Elements colHeader = row.select("th");
+
+
+ if (colPlayers.size() > 0) {
+
+ String data = colPlayers.get(0).select("a").toString();
+// System.out.println(data);
+ if (data.contains(friendCode)) {
+ System.out.println("Found friend code");
+ playerLink = data.split("\"")[3];
+ System.out.println("Player link: " + playerLink);
+
+ }
+ }
+ }
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return playerLink;
+ }
+ public ArrayList<Player> getPlayers() { return players; }
+
+ public String getRoomHeader() { return this.roomHeader; }
+
+ public RoomData refresh() {
+ players.clear();
+ roomHeader = "";
+ RoomData returningData = new RoomData(players, playerLink, friendCode);
+ return returningData;
+ }
+}
+
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java
index 98c5235..9592186 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java
@@ -1,4 +1,66 @@
package com.example.wiimmterfaceandroid.wiimmfi;
-public class RoomFragment {
+import android.os.Bundle;
+import android.view.View;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.fragment.app.Fragment;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.example.wiimmterfaceandroid.R;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+
+import java.util.ArrayList;
+
+public class RoomFragment extends Fragment {
+ String display;
+ String header;
+ String playerLink;
+ ArrayList<Player> players;
+ RoomData roomData;
+
+ public RoomFragment(String friendCode, String header, ArrayList<Player> players, String playerLink, String display) {
+ super(R.layout.fragment_room);
+ this.roomData = new RoomData(players, playerLink, friendCode);
+ this.header = roomData.getRoomHeader();
+ this.display = display;
+ this.players = players;
+ this.playerLink = playerLink;
+
+ }
+ @Override
+ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ FloatingActionButton refreshButton = view.findViewById(R.id.refresh_button);
+ TextView headerTextView = view.findViewById(R.id.room_header_text);
+ if (header == null || playerLink == null || players == null) {
+ header = "This player is not online, not inside a room or does not exist. Click the refresh button to try again, or click on the back button to enter a different friend code.";
+ }
+ headerTextView.setText(header);
+ RecyclerView recyclerView = view.findViewById(R.id.player_data_recycler_view);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ recyclerView.setAdapter(new RoomAdapter(display, playerLink, header, players));
+
+ refreshButton.setOnClickListener((buttonView) -> {
+ refreshButton.setEnabled(false);
+ players.clear();
+ this.header = "";
+ roomData = roomData.refresh();
+ RoomData newRoomData = roomData.refresh();
+ players = roomData.getPlayers();
+ playerLink = roomData.getPlayerLink();
+ String otherPlayerLink = newRoomData.getPlayerLink();
+ header = newRoomData.getRoomHeader();
+ if (playerLink == null) {
+ header = "This player is not online, not inside a room or does not exist. Click the refresh button to try again, or click on the back button to enter a different friend code.";
+ }
+ headerTextView.setText(header);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
+ recyclerView.setAdapter(new RoomAdapter(display, playerLink, header, players));
+ refreshButton.setEnabled(true);
+ });
+ }
}
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java
index 2a2ce0d..1d1101d 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java
@@ -1,19 +1,114 @@
package com.example.wiimmterfaceandroid.wiimmfi;
import android.content.Intent;
+import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.StrictMode;
+import android.widget.TextView;
+
import org.jsoup.*;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.jsoup.select.Elements;
import androidx.appcompat.app.AppCompatActivity;
+import androidx.drawerlayout.widget.DrawerLayout;
+import androidx.room.Room;
import com.example.wiimmterfaceandroid.R;
+import com.google.android.material.appbar.MaterialToolbar;
+import com.google.android.material.navigation.NavigationView;
+
+import java.io.IOException;
+import java.util.ArrayList;
public class WiimmfiActivity extends AppCompatActivity {
+ ArrayList<Player> players = new ArrayList<>();
+ final String[] playerLink = new String[1];
+ String friendCode;
+ String roomHeader;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
- String friendCode;
+ friendCode = intent.getStringExtra("friendCode");
+ System.out.println(friendCode);
setContentView(R.layout.activity_wiimmfi);
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+ StrictMode.setThreadPolicy(policy);
+
+
+ MaterialToolbar toolbar = findViewById(R.id.toolbar);
+ DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
+ NavigationView drawer = findViewById(R.id.navigation_view);
+
+ toolbar.setTitle("Watching " + friendCode);
+
+ if (savedInstanceState == null) {
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "fc"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ toolbar.setNavigationOnClickListener(view -> {
+ drawerLayout.open();
+ });
+ drawer.setNavigationItemSelectedListener(menuItem -> {
+ menuItem.setChecked(true);
+ drawerLayout.close();
+ if (menuItem.getItemId() == R.id.friend_code) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "fc"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ if (menuItem.getItemId() == R.id.roles) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "roles"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ if (menuItem.getItemId() == R.id.login_regions) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "login_regions"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ if (menuItem.getItemId() == R.id.room_match) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "room_match"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ if (menuItem.getItemId() == R.id.world) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "world"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ if (menuItem.getItemId() == R.id.conn_fail) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "conn_fail"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ if (menuItem.getItemId() == R.id.vr_br) {
+ players.clear();
+ getSupportFragmentManager().beginTransaction()
+ .replace(R.id.room_fragment, new RoomFragment(friendCode, roomHeader, players, playerLink[0], "vr_br"), null)
+ .setReorderingAllowed(true)
+ .commit();
+ }
+ return true;
+ });
}
+
}
+