aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/com/example
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/example')
-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
7 files changed, 35 insertions, 146 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);