From fc908199f136acd2a5030e5085f024857cd2cfb5 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Sat, 8 May 2021 14:58:18 -0600 Subject: changed api and package name --- README.md | 15 --- app/build.gradle | 7 +- .../ExampleInstrumentedTest.java | 26 ---- .../wiimmfiwatcher/ExampleInstrumentedTest.java | 26 ++++ app/src/main/AndroidManifest.xml | 24 ++-- .../example/wiimmterfaceandroid/MainActivity.java | 47 ------- .../wiimmterfaceandroid/WatchCodeAdapter.java | 60 --------- .../wiimmterfaceandroid/WatchCodeFragment.java | 111 ----------------- .../wiimmterfaceandroid/database/AppDatabase.java | 11 -- .../database/FriendCodeDao.java | 30 ----- .../wiimmterfaceandroid/model/FriendCode.java | 22 ---- .../viewmodel/FriendCodeViewModel.java | 80 ------------ .../wiimmterfaceandroid/wiimmfi/Player.java | 15 --- .../wiimmterfaceandroid/wiimmfi/RoomAdapter.java | 102 ---------------- .../wiimmterfaceandroid/wiimmfi/RoomData.java | 133 -------------------- .../wiimmterfaceandroid/wiimmfi/RoomFragment.java | 66 ---------- .../wiimmfi/WiimmfiActivity.java | 114 ----------------- .../brysonsteck/wiimmfiwatcher/MainActivity.java | 41 +++++++ .../wiimmfiwatcher/WatchCodeAdapter.java | 60 +++++++++ .../wiimmfiwatcher/WatchCodeFragment.java | 112 +++++++++++++++++ .../wiimmfiwatcher/database/AppDatabase.java | 11 ++ .../wiimmfiwatcher/database/FriendCodeDao.java | 30 +++++ .../wiimmfiwatcher/model/FriendCode.java | 22 ++++ .../viewmodel/FriendCodeViewModel.java | 71 +++++++++++ .../brysonsteck/wiimmfiwatcher/wiimmfi/Player.java | 15 +++ .../wiimmfiwatcher/wiimmfi/RoomAdapter.java | 99 +++++++++++++++ .../wiimmfiwatcher/wiimmfi/RoomData.java | 136 +++++++++++++++++++++ .../wiimmfiwatcher/wiimmfi/RoomFragment.java | 67 ++++++++++ .../wiimmfiwatcher/wiimmfi/WiimmfiActivity.java | 108 ++++++++++++++++ app/src/main/res/values-night/themes.xml | 2 +- app/src/main/res/values/themes.xml | 2 +- app/src/main/wiimmterface_launcher-playstore.png | Bin 331739 -> 0 bytes .../wiimmterfaceandroid/ExampleUnitTest.java | 17 --- .../wiimmfiwatcher/ExampleUnitTest.java | 17 +++ build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 2 +- 37 files changed, 835 insertions(+), 870 deletions(-) delete mode 100644 README.md delete mode 100644 app/src/androidTest/java/com/example/wiimmterfaceandroid/ExampleInstrumentedTest.java create mode 100644 app/src/androidTest/java/me/brysonsteck/wiimmfiwatcher/ExampleInstrumentedTest.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java delete mode 100644 app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeAdapter.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeFragment.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/AppDatabase.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/FriendCodeDao.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/model/FriendCode.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/viewmodel/FriendCodeViewModel.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/Player.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomAdapter.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomData.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomFragment.java create mode 100644 app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/WiimmfiActivity.java delete mode 100644 app/src/main/wiimmterface_launcher-playstore.png delete mode 100644 app/src/test/java/com/example/wiimmterfaceandroid/ExampleUnitTest.java create mode 100644 app/src/test/java/me/brysonsteck/wiimmfiwatcher/ExampleUnitTest.java diff --git a/README.md b/README.md deleted file mode 100644 index d19597f..0000000 --- a/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## This is the `dev` branch!! -**You are on the `dev` branch for Wiimmfi Watcher.** This is seperate from the `master` branch, which contains the currently most stable version, while this branch is made for me to work on the app without changing currently stable code. If you are looking for the `master` branch, [click here.](https://github.com/brysonsteck/wiimmfi-watcher/tree/master) - -# Wiimmfi Watcher - -Wiimmfi Watcher is an Android application that allows you to watch Mario Kart Wii gameplay by simply entering your friend code. - -## TODO - -* Add an indentifiable user agent for Jsoup -* Add a new fragment for the "info" button on the main screen -* Fix the repeating recent friend codes -* Figure out if a license is appropriate -* Create the app on the Play Store -* Create a meaningful README diff --git a/app/build.gradle b/app/build.gradle index 37f338e..1b11131 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,8 +7,8 @@ android { buildToolsVersion "30.0.3" defaultConfig { - applicationId "com.example.wiimmterfaceandroid" - minSdkVersion 29 + applicationId "me.brysonsteck.wiimmfiwatcher" + minSdkVersion 22 targetSdkVersion 30 versionCode 1 versionName "1.0" @@ -31,7 +31,6 @@ android { } } - dependencies { dependencies { dependencies { @@ -43,7 +42,7 @@ dependencies { // LiveData implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version" } - def lifecycle_version = "2.3.1" + def lifecycle_version = "2.3.1" def arch_version = "2.1.0" // ViewModel diff --git a/app/src/androidTest/java/com/example/wiimmterfaceandroid/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/wiimmterfaceandroid/ExampleInstrumentedTest.java deleted file mode 100644 index 1e59b29..0000000 --- a/app/src/androidTest/java/com/example/wiimmterfaceandroid/ExampleInstrumentedTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.example.wiimmterfaceandroid; - -import android.content.Context; - -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.ext.junit.runners.AndroidJUnit4; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.*; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); - assertEquals("com.example.wiimmterfaceandroid", appContext.getPackageName()); - } -} \ No newline at end of file diff --git a/app/src/androidTest/java/me/brysonsteck/wiimmfiwatcher/ExampleInstrumentedTest.java b/app/src/androidTest/java/me/brysonsteck/wiimmfiwatcher/ExampleInstrumentedTest.java new file mode 100644 index 0000000..5d9b03b --- /dev/null +++ b/app/src/androidTest/java/me/brysonsteck/wiimmfiwatcher/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package me.brysonsteck.wiimmfiwatcher; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("me.brysonsteck.wiimmfiwatcher", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3fa2f1f..aaf7fd9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,24 +1,24 @@ + package="me.brysonsteck.wiimmfiwatcher"> - - - + android:theme="@style/Theme.WiimmfiWatcher"> + + + - - - - - + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java b/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java deleted file mode 100644 index 96f1511..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.example.wiimmterfaceandroid; - - - -import androidx.appcompat.app.AppCompatActivity; -import androidx.databinding.ObservableArrayList; -import androidx.fragment.app.FragmentContainerView; -import androidx.room.Room; - -import android.os.Bundle; - -import com.example.wiimmterfaceandroid.database.AppDatabase; -import com.example.wiimmterfaceandroid.model.FriendCode; - -import java.util.List; - -public class MainActivity extends AppCompatActivity { - ObservableArrayList recentFCList = new ObservableArrayList<>(); - AppDatabase database; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); -// FragmentContainerView fcInput = findViewById(R.id.room_fragment); -// this.database = Room.databaseBuilder(this, AppDatabase.class, "friend-codes-db").build(); -// new Thread(() -> { -// try { -// Thread.sleep(1000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// recentFCList.addAll(database.getFriendCodeDao().getAll()); -// }).start(); - - - - if (savedInstanceState == null) { - getSupportFragmentManager().beginTransaction() - .replace(R.id.friend_code_input_fragment, new WatchCodeFragment(), null) - .setReorderingAllowed(true) - .commit(); - - - } - setContentView(R.layout.activity_main); - } -} \ No newline at end of file diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java deleted file mode 100644 index 6e7e69e..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.example.wiimmterfaceandroid; - -import android.content.Context; -import android.content.Intent; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.Button; - -import androidx.annotation.NonNull; -import androidx.databinding.ObservableArrayList; -import androidx.recyclerview.widget.RecyclerView; - -import com.example.wiimmterfaceandroid.model.FriendCode; -import com.example.wiimmterfaceandroid.wiimmfi.WiimmfiActivity; -import com.google.android.material.button.MaterialButton; - -public class WatchCodeAdapter extends RecyclerView.Adapter{ - ObservableArrayList entries; - OnFriendCodeClicked listener; - Context context; - public interface OnFriendCodeClicked { - public void onClick(FriendCode entry); - } - - public WatchCodeAdapter(Context context, ObservableArrayList entries) { - this.context = context; - this.entries = entries; - } - - @NonNull - @Override - public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recent_friend_codes_item, parent, false); - return new ViewHolder(view); - } - - @Override - public void onBindViewHolder(@NonNull ViewHolder holder, int position) { - MaterialButton fcButton = holder.itemView.findViewById(R.id.recent_friend_code_button); - FriendCode currentFC = entries.get(position); - fcButton.setText(currentFC.friendCode); - fcButton.setOnClickListener(view -> { - Intent intent = new Intent(view.getContext(), WiimmfiActivity.class); - intent.putExtra("friendCode", currentFC.friendCode); - context.startActivity(intent); - }); - } - - @Override - public int getItemCount() { - return entries.size(); - } - - class ViewHolder extends RecyclerView.ViewHolder { - public ViewHolder(@NonNull View itemView) { - super(itemView); - } - } -} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java deleted file mode 100644 index 6de02dc..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java +++ /dev/null @@ -1,111 +0,0 @@ -package com.example.wiimmterfaceandroid; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.databinding.ObservableList; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProvider; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; - -import com.example.wiimmterfaceandroid.model.FriendCode; -import com.example.wiimmterfaceandroid.viewmodel.FriendCodeViewModel; -import com.example.wiimmterfaceandroid.wiimmfi.WiimmfiActivity; -import com.google.android.material.textview.MaterialTextView; - -public class WatchCodeFragment extends Fragment { - - public WatchCodeFragment() { - super(R.layout.friend_code_input_fragment); - } - - public boolean isValidFriendCode(String friendCode) { - String[] friendCodeSplit = friendCode.split("-"); - boolean valid = false; - if (friendCodeSplit.length == 3) { - for (String friendCodePart : friendCodeSplit) { - valid = friendCodePart.length() == 4; - if (!valid) { - break; - } - } - } - return valid; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - FriendCodeViewModel viewModel = new ViewModelProvider(getActivity()).get(FriendCodeViewModel.class); - - WatchCodeAdapter adapter = new WatchCodeAdapter(getContext(), viewModel.getEntries()); - viewModel.getEntries().addOnListChangedCallback(new ObservableList.OnListChangedCallback>() { - @Override - public void onChanged(ObservableList sender) { - getActivity().runOnUiThread(() -> { - adapter.notifyDataSetChanged(); - }); - } - - @Override - public void onItemRangeChanged(ObservableList sender, int positionStart, int itemCount) { - getActivity().runOnUiThread(() -> { - adapter.notifyItemRangeChanged(positionStart, itemCount); - }); - } - - @Override - public void onItemRangeInserted(ObservableList sender, int positionStart, int itemCount) { - getActivity().runOnUiThread(() -> { - adapter.notifyItemRangeInserted(positionStart, itemCount); - }); - } - - @Override - public void onItemRangeMoved(ObservableList sender, int fromPosition, int toPosition, int itemCount) { - getActivity().runOnUiThread(() -> { - adapter.notifyItemMoved(fromPosition, toPosition); - }); - } - - @Override - public void onItemRangeRemoved(ObservableList sender, int positionStart, int itemCount) { - getActivity().runOnUiThread(() -> { - adapter.notifyItemRangeRemoved(positionStart, itemCount); - }); - } - }); - RecyclerView recyclerView = view.findViewById(R.id.recent_friend_codes_recycler_view); - recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - recyclerView.setAdapter(adapter); - Button watchButton = view.findViewById(R.id.watch_button); - EditText friendCode = view.findViewById(R.id.friend_code_edit_text); - MaterialTextView errorText = view.findViewById(R.id.error_text); - watchButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(view.getContext(), WiimmfiActivity.class); - if (!isValidFriendCode(friendCode.getText().toString())) { - errorText.setText("ERROR: Insert a friend code in the format XXXX-XXXX-XXXX"); - friendCode.setText(""); - } else { - errorText.setText(""); - viewModel.saveFriendCode("", friendCode.getText().toString()); -// FriendCodeObj friendCodeObj = new FriendCodeObj(); -// friendCodeObj.friendCode = friendCode.getText().toString(); -// database.getFriendCodeDao().insert(friendCodeObj); - intent.putExtra("friendCode", friendCode.getText().toString()); - startActivity(intent); - } - } - }); - - - } -} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java b/app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java deleted file mode 100644 index 0f01149..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/database/AppDatabase.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.wiimmterfaceandroid.database; - -import androidx.room.Database; -import androidx.room.RoomDatabase; - -import com.example.wiimmterfaceandroid.model.FriendCode; - -@Database(entities = {FriendCode.class}, version=1) -public abstract class AppDatabase extends RoomDatabase { - public abstract FriendCodeDao getFriendCodeDao(); -} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java b/app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java deleted file mode 100644 index dbfb9c5..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/database/FriendCodeDao.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.example.wiimmterfaceandroid.database; - -import androidx.room.Dao; -import androidx.room.Delete; -import androidx.room.Insert; -import androidx.room.Query; -import androidx.room.Update; - -import com.example.wiimmterfaceandroid.model.FriendCode; - -import java.util.List; - -@Dao -public interface FriendCodeDao { - - @Query("SELECT * FROM friendcode") - public List getAll(); - -// @Query("SELECT * FROM friendcodeobj") -// public FriendCodeObj findByCode(String friendCode); - - @Insert - public void insert(FriendCode friendCode); - - @Update - public void update(FriendCode friendCode); - - @Delete - public void delete(FriendCode friendCode); -} diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java b/app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java deleted file mode 100644 index 3aad0a1..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/model/FriendCode.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.wiimmterfaceandroid.model; - -import androidx.annotation.NonNull; -import androidx.room.ColumnInfo; -import androidx.room.Entity; -import androidx.room.PrimaryKey; - -import java.io.Serializable; - -@Entity -public class FriendCode implements Serializable { - @PrimaryKey (autoGenerate = true) - public long id; - - @ColumnInfo(name="name") - public String name; - - @NonNull - @ColumnInfo(name="friendCode") - public String friendCode; - -} \ No newline at end of file diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java deleted file mode 100644 index c7bbe7d..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.example.wiimmterfaceandroid.viewmodel; - -import android.app.Application; - -import androidx.lifecycle.AndroidViewModel; -import androidx.lifecycle.MutableLiveData; - -import com.example.wiimmterfaceandroid.database.AppDatabase; -import com.example.wiimmterfaceandroid.model.FriendCode; - -import androidx.databinding.ObservableArrayList; -import androidx.lifecycle.AndroidViewModel; -import androidx.lifecycle.MutableLiveData; -import androidx.lifecycle.ViewModel; -import androidx.room.Room; -import androidx.room.RoomDatabase; - -import androidx.databinding.ObservableArrayList; - -import java.util.LinkedHashSet; - -public class FriendCodeViewModel extends AndroidViewModel { - ObservableArrayList entries = new ObservableArrayList<>(); - MutableLiveData saving = new MutableLiveData<>(); - MutableLiveData currentEntry = new MutableLiveData<>(); - AppDatabase db; - public FriendCodeViewModel(Application app) { - super(app); - saving.setValue(false); - db = Room.databaseBuilder(app, AppDatabase.class, "friend-codes-db").build(); - new Thread(() -> { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - entries.addAll(db.getFriendCodeDao().getAll()); - }).start(); - } - - public void setCurrentEntry(FriendCode entry) { - currentEntry.postValue(entry); - } - - public MutableLiveData getCurrentEntry() { - return currentEntry; - } - - public MutableLiveData getSaving() { - return saving; - } - - public ObservableArrayList getEntries() { - return entries; - } - - public void saveFriendCode(String name, String friendCode) { - saving.setValue(true); - new Thread(() -> { - if (currentEntry.getValue() != null) { - - } else { - FriendCode newEntry = new FriendCode(); - newEntry.name = name; - newEntry.friendCode = friendCode; - db.getFriendCodeDao().insert(newEntry); - entries.add(newEntry); - } - - saving.postValue(false); - }).start(); - } - - public void deleteEntry(FriendCode entry) { - new Thread(() -> { - db.getFriendCodeDao().delete(entry); - entries.remove(entry); - }).start(); - } - } diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java deleted file mode 100644 index 792f14f..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/Player.java +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index dfa51e7..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomAdapter.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.example.wiimmterfaceandroid.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 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{ - - String display; - String playerLink; - String header; - ArrayList players; - boolean online = true; - public RoomAdapter (String display, String playerLink, String header, ArrayList 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 deleted file mode 100644 index 3799180..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java +++ /dev/null @@ -1,133 +0,0 @@ -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 players = new ArrayList<>(); - - public RoomData (ArrayList players, String playerLink, String friendCode) { - this.friendCode = friendCode; - getPlayerLink(); - Document doc = null; - - if (this.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 void 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); - break; - } - } - } - - - } catch (Exception e) { - e.printStackTrace(); - } - } - public ArrayList 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 deleted file mode 100644 index 463c635..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.wiimmterfaceandroid.wiimmfi; - -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 players; - RoomData roomData; - - public RoomFragment(String friendCode, String header, ArrayList 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) { - 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 (header == 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 deleted file mode 100644 index 1d1101d..0000000 --- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/WiimmfiActivity.java +++ /dev/null @@ -1,114 +0,0 @@ -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 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(); - 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; - }); - } - -} - diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java new file mode 100644 index 0000000..31f74fd --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/MainActivity.java @@ -0,0 +1,41 @@ +package me.brysonsteck.wiimmfiwatcher; + + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.databinding.ObservableArrayList; +import me.brysonsteck.wiimmfiwatcher.database.AppDatabase; +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; + +public class MainActivity extends AppCompatActivity { + ObservableArrayList recentFCList = new ObservableArrayList<>(); + AppDatabase database; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); +// FragmentContainerView fcInput = findViewById(R.id.room_fragment); +// this.database = Room.databaseBuilder(this, AppDatabase.class, "friend-codes-db").build(); +// new Thread(() -> { +// try { +// Thread.sleep(1000); +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// recentFCList.addAll(database.getFriendCodeDao().getAll()); +// }).start(); + + + + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.friend_code_input_fragment, new WatchCodeFragment(), null) + .setReorderingAllowed(true) + .commit(); + + + } + setContentView(R.layout.activity_main); + } +} \ No newline at end of file diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeAdapter.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeAdapter.java new file mode 100644 index 0000000..beb684f --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeAdapter.java @@ -0,0 +1,60 @@ +package me.brysonsteck.wiimmfiwatcher; + +import android.content.Context; +import android.content.Intent; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.databinding.ObservableArrayList; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.button.MaterialButton; + +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; +import me.brysonsteck.wiimmfiwatcher.wiimmfi.WiimmfiActivity; + +public class WatchCodeAdapter extends RecyclerView.Adapter{ + ObservableArrayList entries; + OnFriendCodeClicked listener; + Context context; + public interface OnFriendCodeClicked { + public void onClick(FriendCode entry); + } + + public WatchCodeAdapter(Context context, ObservableArrayList entries) { + this.context = context; + this.entries = entries; + } + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recent_friend_codes_item, parent, false); + return new ViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + MaterialButton fcButton = holder.itemView.findViewById(R.id.recent_friend_code_button); + FriendCode currentFC = entries.get(position); + fcButton.setText(currentFC.friendCode); + fcButton.setOnClickListener(view -> { + Intent intent = new Intent(view.getContext(), WiimmfiActivity.class); + intent.putExtra("friendCode", currentFC.friendCode); + context.startActivity(intent); + }); + } + + @Override + public int getItemCount() { + return entries.size(); + } + + class ViewHolder extends RecyclerView.ViewHolder { + public ViewHolder(@NonNull View itemView) { + super(itemView); + } + } +} diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeFragment.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeFragment.java new file mode 100644 index 0000000..942da0f --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/WatchCodeFragment.java @@ -0,0 +1,112 @@ +package me.brysonsteck.wiimmfiwatcher; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.databinding.ObservableList; +import androidx.fragment.app.Fragment; +import androidx.lifecycle.ViewModelProvider; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.google.android.material.textview.MaterialTextView; + +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; +import me.brysonsteck.wiimmfiwatcher.viewmodel.FriendCodeViewModel; +import me.brysonsteck.wiimmfiwatcher.wiimmfi.WiimmfiActivity; + +public class WatchCodeFragment extends Fragment { + + public WatchCodeFragment() { + super(R.layout.friend_code_input_fragment); + } + + public boolean isValidFriendCode(String friendCode) { + String[] friendCodeSplit = friendCode.split("-"); + boolean valid = false; + if (friendCodeSplit.length == 3) { + for (String friendCodePart : friendCodeSplit) { + valid = friendCodePart.length() == 4; + if (!valid) { + break; + } + } + } + return valid; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + FriendCodeViewModel viewModel = new ViewModelProvider(getActivity()).get(FriendCodeViewModel.class); + + WatchCodeAdapter adapter = new WatchCodeAdapter(getContext(), viewModel.getEntries()); + viewModel.getEntries().addOnListChangedCallback(new ObservableList.OnListChangedCallback>() { + @Override + public void onChanged(ObservableList sender) { + getActivity().runOnUiThread(() -> { + adapter.notifyDataSetChanged(); + }); + } + + @Override + public void onItemRangeChanged(ObservableList sender, int positionStart, int itemCount) { + getActivity().runOnUiThread(() -> { + adapter.notifyItemRangeChanged(positionStart, itemCount); + }); + } + + @Override + public void onItemRangeInserted(ObservableList sender, int positionStart, int itemCount) { + getActivity().runOnUiThread(() -> { + adapter.notifyItemRangeInserted(positionStart, itemCount); + }); + } + + @Override + public void onItemRangeMoved(ObservableList sender, int fromPosition, int toPosition, int itemCount) { + getActivity().runOnUiThread(() -> { + adapter.notifyItemMoved(fromPosition, toPosition); + }); + } + + @Override + public void onItemRangeRemoved(ObservableList sender, int positionStart, int itemCount) { + getActivity().runOnUiThread(() -> { + adapter.notifyItemRangeRemoved(positionStart, itemCount); + }); + } + }); + RecyclerView recyclerView = view.findViewById(R.id.recent_friend_codes_recycler_view); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + recyclerView.setAdapter(adapter); + Button watchButton = view.findViewById(R.id.watch_button); + EditText friendCode = view.findViewById(R.id.friend_code_edit_text); + MaterialTextView errorText = view.findViewById(R.id.error_text); + watchButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(view.getContext(), WiimmfiActivity.class); + if (!isValidFriendCode(friendCode.getText().toString())) { + errorText.setText("ERROR: Insert a friend code in the format XXXX-XXXX-XXXX"); + friendCode.setText(""); + } else { + errorText.setText(""); + viewModel.saveFriendCode("", friendCode.getText().toString()); +// FriendCodeObj friendCodeObj = new FriendCodeObj(); +// friendCodeObj.friendCode = friendCode.getText().toString(); +// database.getFriendCodeDao().insert(friendCodeObj); + intent.putExtra("friendCode", friendCode.getText().toString()); + startActivity(intent); + } + } + }); + + + } +} diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/AppDatabase.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/AppDatabase.java new file mode 100644 index 0000000..01884c2 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/AppDatabase.java @@ -0,0 +1,11 @@ +package me.brysonsteck.wiimmfiwatcher.database; + +import androidx.room.Database; +import androidx.room.RoomDatabase; + +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; + +@Database(entities = {FriendCode.class}, version=1) +public abstract class AppDatabase extends RoomDatabase { + public abstract FriendCodeDao getFriendCodeDao(); +} diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/FriendCodeDao.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/FriendCodeDao.java new file mode 100644 index 0000000..24e8762 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/database/FriendCodeDao.java @@ -0,0 +1,30 @@ +package me.brysonsteck.wiimmfiwatcher.database; + +import androidx.room.Dao; +import androidx.room.Delete; +import androidx.room.Insert; +import androidx.room.Query; +import androidx.room.Update; + +import java.util.List; + +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; + +@Dao +public interface FriendCodeDao { + + @Query("SELECT * FROM friendcode") + public List getAll(); + +// @Query("SELECT * FROM friendcodeobj") +// public FriendCodeObj findByCode(String friendCode); + + @Insert + public void insert(FriendCode friendCode); + + @Update + public void update(FriendCode friendCode); + + @Delete + public void delete(FriendCode friendCode); +} diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/model/FriendCode.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/model/FriendCode.java new file mode 100644 index 0000000..5856a22 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/model/FriendCode.java @@ -0,0 +1,22 @@ +package me.brysonsteck.wiimmfiwatcher.model; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +import java.io.Serializable; + +@Entity +public class FriendCode implements Serializable { + @PrimaryKey (autoGenerate = true) + public long id; + + @ColumnInfo(name="name") + public String name; + + @NonNull + @ColumnInfo(name="friendCode") + public String friendCode; + +} \ No newline at end of file diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/viewmodel/FriendCodeViewModel.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/viewmodel/FriendCodeViewModel.java new file mode 100644 index 0000000..ae300c0 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/viewmodel/FriendCodeViewModel.java @@ -0,0 +1,71 @@ +package me.brysonsteck.wiimmfiwatcher.viewmodel; + +import android.app.Application; + +import androidx.databinding.ObservableArrayList; +import androidx.lifecycle.AndroidViewModel; +import androidx.lifecycle.MutableLiveData; +import androidx.room.Room; + +import me.brysonsteck.wiimmfiwatcher.database.AppDatabase; +import me.brysonsteck.wiimmfiwatcher.model.FriendCode; + +public class FriendCodeViewModel extends AndroidViewModel { + ObservableArrayList entries = new ObservableArrayList<>(); + MutableLiveData saving = new MutableLiveData<>(); + MutableLiveData currentEntry = new MutableLiveData<>(); + AppDatabase db; + public FriendCodeViewModel(Application app) { + super(app); + saving.setValue(false); + db = Room.databaseBuilder(app, AppDatabase.class, "friend-codes-db").build(); + new Thread(() -> { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + entries.addAll(db.getFriendCodeDao().getAll()); + }).start(); + } + + public void setCurrentEntry(FriendCode entry) { + currentEntry.postValue(entry); + } + + public MutableLiveData getCurrentEntry() { + return currentEntry; + } + + public MutableLiveData getSaving() { + return saving; + } + + public ObservableArrayList getEntries() { + return entries; + } + + public void saveFriendCode(String name, String friendCode) { + saving.setValue(true); + new Thread(() -> { + if (currentEntry.getValue() != null) { + + } else { + FriendCode newEntry = new FriendCode(); + newEntry.name = name; + newEntry.friendCode = friendCode; + db.getFriendCodeDao().insert(newEntry); + entries.add(newEntry); + } + + saving.postValue(false); + }).start(); + } + + public void deleteEntry(FriendCode entry) { + new Thread(() -> { + db.getFriendCodeDao().delete(entry); + entries.remove(entry); + }).start(); + } + } diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/Player.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/Player.java new file mode 100644 index 0000000..fe9e072 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/Player.java @@ -0,0 +1,15 @@ +package me.brysonsteck.wiimmfiwatcher.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/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomAdapter.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomAdapter.java new file mode 100644 index 0000000..0cf7a6e --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomAdapter.java @@ -0,0 +1,99 @@ +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{ + + String display; + String playerLink; + String header; + ArrayList players; + boolean online = true; + public RoomAdapter (String display, String playerLink, String header, ArrayList 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/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomData.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomData.java new file mode 100644 index 0000000..f0d9db7 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomData.java @@ -0,0 +1,136 @@ +package me.brysonsteck.wiimmfiwatcher.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 players = new ArrayList<>(); + + public RoomData (ArrayList players, String playerLink, String friendCode) { + this.friendCode = friendCode; + getPlayerLink(); + Document doc = null; + + if (this.playerLink == null) { + System.out.println("The player link is null for some reason"); + } else { + + try { + doc = Jsoup.connect("https://wiimmfi.de/" + this.playerLink) + .userAgent("Wiimmfi Watcher for Android (https://github.com/brysonsteck/wiimmfi-watcher) (UNDER DEVELOPMENT)") + .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 void getPlayerLink() { + try { + Document doc = null; + + doc = Jsoup.connect("https://wiimmfi.de/stats/mkw") + .userAgent("Wiimmfi Watcher for Android (https://github.com/brysonsteck/wiimmfi-watcher) (UNDER DEVELOPMENT)") + .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); + break; + } + } + } + + + } catch (Exception e) { + e.printStackTrace(); + } + } + public ArrayList getPlayers() { return players; } + + public String getRoomHeader() { return this.roomHeader; } + + public RoomData refresh() { + players.clear(); + roomHeader = ""; + return new RoomData(players, playerLink, friendCode); + } +} + diff --git a/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomFragment.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomFragment.java new file mode 100644 index 0000000..cbadf63 --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/RoomFragment.java @@ -0,0 +1,67 @@ +package me.brysonsteck.wiimmfiwatcher.wiimmfi; + +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.google.android.material.floatingactionbutton.FloatingActionButton; + +import java.util.ArrayList; + +import me.brysonsteck.wiimmfiwatcher.R; + +public class RoomFragment extends Fragment { + String display; + String header; + String playerLink; + ArrayList players; + RoomData roomData; + + public RoomFragment(String friendCode, String header, ArrayList 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) { + 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 (header == 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/me/brysonsteck/wiimmfiwatcher/wiimmfi/WiimmfiActivity.java b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/WiimmfiActivity.java new file mode 100644 index 0000000..24affee --- /dev/null +++ b/app/src/main/java/me/brysonsteck/wiimmfiwatcher/wiimmfi/WiimmfiActivity.java @@ -0,0 +1,108 @@ +package me.brysonsteck.wiimmfiwatcher.wiimmfi; + +import android.content.Intent; +import android.os.Bundle; +import android.os.StrictMode; + +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 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(); + 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; + }); + } + +} + diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 93b7175..359a761 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -1,6 +1,6 @@ -