aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorBryson Steck <steck.bryson@gmail.com>2021-05-04 23:31:34 -0600
committerBryson Steck <steck.bryson@gmail.com>2021-05-04 23:31:34 -0600
commitb202760cdc2b443fd07dcee593ed7f3e09d6b77b (patch)
tree959051ae90e51212590db5b513e4de93261136cf /app/src
parent50dfc57c61a01dc20a42129246b458bf90e26154 (diff)
downloadwiimmfi-watcher-b202760cdc2b443fd07dcee593ed7f3e09d6b77b.tar
wiimmfi-watcher-b202760cdc2b443fd07dcee593ed7f3e09d6b77b.tar.gz
wiimmfi-watcher-b202760cdc2b443fd07dcee593ed7f3e09d6b77b.tar.bz2
watched friend codes work
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java28
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java101
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java (renamed from app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesAdapter.java)22
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java10
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java3
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java9
-rw-r--r--app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java8
-rw-r--r--app/src/main/res/layout/friend_code_input_fragment.xml2
-rw-r--r--app/src/main/res/layout/recent_friend_codes_item.xml12
9 files changed, 43 insertions, 152 deletions
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java b/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java
index 71b25fa..96f1511 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/MainActivity.java
@@ -21,31 +21,27 @@ public class MainActivity extends AppCompatActivity {
@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();
+// 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();
- setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.friend_code_input_fragment, new WatchCodeFragment(), null)
.setReorderingAllowed(true)
.commit();
- getSupportFragmentManager().beginTransaction()
- .replace(R.id.room_fragment, new RecentCodesFragment(), 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/RecentCodesFragment.java b/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java
deleted file mode 100644
index bde507f..0000000
--- a/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesFragment.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.example.wiimmterfaceandroid;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.constraintlayout.widget.ConstraintLayout;
-import androidx.fragment.app.Fragment;
-
-import com.example.wiimmterfaceandroid.database.AppDatabase;
-import com.example.wiimmterfaceandroid.model.FriendCode;
-import com.example.wiimmterfaceandroid.viewmodel.FriendCodeViewModel;
-import com.example.wiimmterfaceandroid.wiimmfi.WiimmfiActivity;
-
-import java.util.List;
-
-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;
-
-public class RecentCodesFragment extends Fragment {
-
- public RecentCodesFragment() {
-
- }
- FriendCodeViewModel viewModel;
-
- @Override
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
- super.onViewCreated(view, savedInstanceState);
- viewModel = new ViewModelProvider(getActivity()).get(FriendCodeViewModel.class);
-
- RecentCodesAdapter adapter = new RecentCodesAdapter(
- viewModel.getEntries(),
- (entry) -> {
- viewModel.setCurrentEntry(entry);
- Intent intent = new Intent(view.getContext(), WiimmfiActivity.class);
- intent.putExtra("friendCode", entry.friendCode);
- startActivity(intent);
- }
- );
- viewModel.getEntries().addOnListChangedCallback(new ObservableList.OnListChangedCallback<ObservableList<FriendCode>>() {
- @Override
- public void onChanged(ObservableList<FriendCode> sender) {
- getActivity().runOnUiThread(adapter::notifyDataSetChanged);
- }
-
- @Override
- public void onItemRangeChanged(ObservableList<FriendCode> sender, int positionStart, int itemCount) {
- getActivity().runOnUiThread(() -> {
- adapter.notifyItemRangeChanged(positionStart, itemCount);
- });
- }
-
- @Override
- public void onItemRangeInserted(ObservableList<FriendCode> sender, int positionStart, int itemCount) {
- getActivity().runOnUiThread(() -> {
- adapter.notifyItemRangeInserted(positionStart, itemCount);
- });
- }
-
- @Override
- public void onItemRangeMoved(ObservableList<FriendCode> sender, int fromPosition, int toPosition, int itemCount) {
- getActivity().runOnUiThread(() -> {
- adapter.notifyItemMoved(fromPosition, toPosition);
- });
- }
-
- @Override
- public void onItemRangeRemoved(ObservableList<FriendCode> sender, int positionStart, int itemCount) {
- getActivity().runOnUiThread(() -> {
- adapter.notifyItemRangeRemoved(positionStart, itemCount);
- });
- }
- });
- RecyclerView recyclerView = view.findViewById(R.id.recent_friend_codes_recycler_view);
- recyclerView.setAdapter(adapter);
- recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
-
-// view.findViewById(R.id.fab).setOnClickListener((button) -> {
-// viewModel.setCurrentEntry(null);
-// getActivity().getSupportFragmentManager().beginTransaction()
-// .replace(R.id.fragment_container_view, CreateOrUpdateFriendCodeFragment.class, null)
-// .setReorderingAllowed(true)
-// .addToBackStack(null)
-// .commit();
-// });
-// RecyclerView recyclerView = view.findViewById(R.id.recent_friend_codes_recycler_view);
-// recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
-// recyclerView.setAdapter(new RecentCodesAdapter(recentFCList));
- }
-
-}
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesAdapter.java b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java
index 7d278de..aacd9ef 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/RecentCodesAdapter.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeAdapter.java
@@ -1,31 +1,29 @@
package com.example.wiimmterfaceandroid;
+import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
-import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.recyclerview.widget.RecyclerView;
import com.example.wiimmterfaceandroid.model.FriendCode;
-import com.google.android.material.card.MaterialCardView;
-import com.google.android.material.textview.MaterialTextView;
+import com.example.wiimmterfaceandroid.wiimmfi.WiimmfiActivity;
+import com.google.android.material.button.MaterialButton;
-import java.util.List;
-
-public class RecentCodesAdapter extends RecyclerView.Adapter<RecentCodesAdapter.ViewHolder>{
+public class WatchCodeAdapter extends RecyclerView.Adapter<WatchCodeAdapter.ViewHolder>{
ObservableArrayList<FriendCode> entries;
OnFriendCodeClicked listener;
public interface OnFriendCodeClicked {
public void onClick(FriendCode entry);
}
- public RecentCodesAdapter (ObservableArrayList<FriendCode> entries, OnFriendCodeClicked listener) {
+ public WatchCodeAdapter(ObservableArrayList<FriendCode> entries) {
+
this.entries = entries;
- this.listener = listener;
}
@NonNull
@@ -37,12 +35,14 @@ public class RecentCodesAdapter extends RecyclerView.Adapter<RecentCodesAdapter.
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
- Button fcButton = holder.itemView.findViewById(R.id.recent_friend_code_button);
+ MaterialButton fcButton = holder.itemView.findViewById(R.id.recent_friend_code_button);
FriendCode currentFC = entries.get(position);
fcButton.setText(currentFC.friendCode);
fcButton.setOnClickListener(view -> {
- if (listener == null) return;
- listener.onClick(currentFC);
+ Intent intent = new Intent(view.getContext(), WiimmfiActivity.class);
+ intent.putExtra("friendCode", currentFC.friendCode);
+ view.getContext();
+
});
}
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java
index 98ef40b..67dfdcd 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/WatchCodeFragment.java
@@ -44,15 +44,7 @@ public class WatchCodeFragment extends Fragment {
super.onViewCreated(view, savedInstanceState);
FriendCodeViewModel viewModel = new ViewModelProvider(getActivity()).get(FriendCodeViewModel.class);
- RecentCodesAdapter adapter = new RecentCodesAdapter(
- viewModel.getEntries(),
- (entry) -> {
- viewModel.setCurrentEntry(entry);
- Intent intent = new Intent(view.getContext(), WiimmfiActivity.class);
- intent.putExtra("friendCode", entry.friendCode);
- startActivity(intent);
- }
- );
+ WatchCodeAdapter adapter = new WatchCodeAdapter(viewModel.getEntries());
viewModel.getEntries().addOnListChangedCallback(new ObservableList.OnListChangedCallback<ObservableList<FriendCode>>() {
@Override
public void onChanged(ObservableList<FriendCode> sender) {
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java
index ac039ff..c7bbe7d 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/viewmodel/FriendCodeViewModel.java
@@ -17,6 +17,8 @@ import androidx.room.RoomDatabase;
import androidx.databinding.ObservableArrayList;
+import java.util.LinkedHashSet;
+
public class FriendCodeViewModel extends AndroidViewModel {
ObservableArrayList<FriendCode> entries = new ObservableArrayList<>();
MutableLiveData<Boolean> saving = new MutableLiveData<>();
@@ -62,6 +64,7 @@ public class FriendCodeViewModel extends AndroidViewModel {
newEntry.name = name;
newEntry.friendCode = friendCode;
db.getFriendCodeDao().insert(newEntry);
+ entries.add(newEntry);
}
saving.postValue(false);
diff --git a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
index 46f35d8..3799180 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomData.java
@@ -16,10 +16,10 @@ public class RoomData {
public RoomData (ArrayList<Player> players, String playerLink, String friendCode) {
this.friendCode = friendCode;
- this.playerLink = getPlayerLink();
+ getPlayerLink();
Document doc = null;
- if (playerLink == null) {
+ if (this.playerLink == null) {
System.out.println("The player link is null for some reason");
} else {
@@ -87,7 +87,7 @@ public class RoomData {
}
}
- public String getPlayerLink() {
+ public void getPlayerLink() {
try {
Document doc = null;
@@ -109,7 +109,7 @@ public class RoomData {
System.out.println("Found friend code");
playerLink = data.split("\"")[3];
System.out.println("Player link: " + playerLink);
-
+ break;
}
}
}
@@ -118,7 +118,6 @@ public class RoomData {
} catch (Exception e) {
e.printStackTrace();
}
- return playerLink;
}
public ArrayList<Player> getPlayers() { return players; }
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 9592186..e72e38a 100644
--- a/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java
+++ b/app/src/main/java/com/example/wiimmterfaceandroid/wiimmfi/RoomFragment.java
@@ -36,7 +36,7 @@ public class RoomFragment extends Fragment {
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) {
+ if (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);
@@ -51,10 +51,10 @@ public class RoomFragment extends Fragment {
roomData = roomData.refresh();
RoomData newRoomData = roomData.refresh();
players = roomData.getPlayers();
- playerLink = roomData.getPlayerLink();
- String otherPlayerLink = newRoomData.getPlayerLink();
+// playerLink = roomData.getPlayerLink();
+// String otherPlayerLink = newRoomData.getPlayerLink();
header = newRoomData.getRoomHeader();
- if (playerLink == null) {
+ 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);
diff --git a/app/src/main/res/layout/friend_code_input_fragment.xml b/app/src/main/res/layout/friend_code_input_fragment.xml
index a70e6df..4421a65 100644
--- a/app/src/main/res/layout/friend_code_input_fragment.xml
+++ b/app/src/main/res/layout/friend_code_input_fragment.xml
@@ -56,7 +56,7 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recent_friend_codes_recycler_view"
android:layout_width="match_parent"
- android:layout_height="0dp"
+ android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3"
tools:layout_editor_absoluteX="15dp" />
diff --git a/app/src/main/res/layout/recent_friend_codes_item.xml b/app/src/main/res/layout/recent_friend_codes_item.xml
index 7609cdc..7a4f42a 100644
--- a/app/src/main/res/layout/recent_friend_codes_item.xml
+++ b/app/src/main/res/layout/recent_friend_codes_item.xml
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
-<androidx.constraintlayout.widget.ConstraintLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
- android:layout_height="match_parent">
+ android:layout_height="wrap_content">
<Button
android:id="@+id/recent_friend_code_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:backgroundTint="#949494"
android:text="Button"
- app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent" />
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file