aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/WiimmfiActivity.java
blob: c0d4c9fbc90769f50d775803e2ab425a3d8961ef (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package me.brysonsteck.wiimmfiwatcher.wiimmfi;

import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;

import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.navigation.NavigationView;

import org.jsoup.*;

import java.util.ArrayList;

import me.brysonsteck.wiimmfiwatcher.R;

public class WiimmfiActivity extends AppCompatActivity {
    ArrayList<Player> players = new ArrayList<>();
    final String[] playerLink = new String[1];
    String friendCode;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        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);

        int nightModeFlags =
                this.getResources().getConfiguration().uiMode &
                        Configuration.UI_MODE_NIGHT_MASK;
        if (nightModeFlags == Configuration.UI_MODE_NIGHT_YES) {
            // Night mode is active, we're using dark theme
            drawer.setBackgroundColor(Color.parseColor("#313131"));
        }

        toolbar.setTitle(getResources().getString(R.string.watching, friendCode));

        if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "fc", toolbar), 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, players, playerLink[0], "fc", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            if (menuItem.getItemId() == R.id.roles) {
                players.clear();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "roles", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            if (menuItem.getItemId() == R.id.login_regions) {
                players.clear();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "login_regions", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            if (menuItem.getItemId() == R.id.room_match) {
                players.clear();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "room_match", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            if (menuItem.getItemId() == R.id.world) {
                players.clear();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "world", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            if (menuItem.getItemId() == R.id.conn_fail) {
                players.clear();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "conn_fail", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            if (menuItem.getItemId() == R.id.vr_br) {
                players.clear();
                getSupportFragmentManager().beginTransaction()
                        .replace(R.id.room_fragment, new RoomFragment(friendCode, players, playerLink[0], "vr_br", toolbar), null)
                        .setReorderingAllowed(true)
                        .commit();
            }
            return true;
        });
    }

}