2021-04-30 13:40:14 -06:00
|
|
|
package com.example.wiimmterfaceandroid;
|
|
|
|
|
2021-05-04 17:59:55 -06:00
|
|
|
import android.content.Intent;
|
2021-05-02 22:38:15 -06:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
2021-05-04 17:59:55 -06:00
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.EditText;
|
2021-05-02 22:38:15 -06:00
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
2021-05-04 17:59:55 -06:00
|
|
|
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 com.google.android.material.textview.MaterialTextView;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
2021-05-02 22:38:15 -06:00
|
|
|
public class WatchCodeFragment extends Fragment {
|
2021-05-04 17:59:55 -06:00
|
|
|
List<FriendCode> recentFCList;
|
|
|
|
AppDatabase database;
|
2021-05-02 22:38:15 -06:00
|
|
|
|
2021-05-04 17:59:55 -06:00
|
|
|
public WatchCodeFragment(AppDatabase database, List<FriendCode> recentFCList) {
|
|
|
|
super(R.layout.friend_code_input_fragment);
|
|
|
|
this.database = database;
|
|
|
|
this.recentFCList = recentFCList;
|
|
|
|
}
|
2021-05-02 22:38:15 -06:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
|
super.onViewCreated(view, savedInstanceState);
|
2021-05-04 17:59:55 -06:00
|
|
|
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);
|
|
|
|
FriendCodeViewModel friendCodeViewModel = new FriendCodeViewModel(friendCode.getText().toString());
|
|
|
|
if (friendCodeViewModel.getFullFriendCode() == null) {
|
|
|
|
errorText.setText("ERROR: Insert a friend code in the format XXXX-XXXX-XXXX");
|
|
|
|
friendCode.setText("");
|
|
|
|
} else {
|
|
|
|
errorText.setText("");
|
|
|
|
// FriendCodeObj friendCodeObj = new FriendCodeObj();
|
|
|
|
// friendCodeObj.friendCode = friendCode.getText().toString();
|
|
|
|
// database.getFriendCodeDao().insert(friendCodeObj);
|
|
|
|
intent.putExtra("friendCode", friendCodeViewModel.getFullFriendCode());
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2021-05-02 22:38:15 -06:00
|
|
|
}
|
2021-04-30 13:40:14 -06:00
|
|
|
}
|