Skip to content

Commit

Permalink
Data Grabber in Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Julius Fan committed Nov 22, 2019
2 parents 94e784c + a53049e commit a2988d2
Show file tree
Hide file tree
Showing 22 changed files with 383 additions and 266 deletions.
12 changes: 12 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions WinRate.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":" external.linked.project.path="C:\Users\Julius Fan\Documents\WinRate" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":" />
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" />
<option name="LAST_KNOWN_AGP_VERSION" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
12 changes: 0 additions & 12 deletions WinRate/Arin_comments.txt

This file was deleted.

191 changes: 83 additions & 108 deletions WinRate/app/src/main/java/com/ucsc/winrate/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
Expand All @@ -25,8 +24,6 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
Expand All @@ -37,21 +34,19 @@
import java.util.Calendar;
import java.util.Date;

public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
public class MainActivity extends AppCompatActivity {

//declare the necessary variables.
static int winC, loseC, curWinSum, curLoseSum;//winC,loseC are the counter of win or lose.
static int winC,loseC,curWinSum,curLoseSum;//winC,loseC are the counter of win or lose.
static int DataCounter = 0;
static boolean result;//result iss used for storing the value of switch.
EditText playerDeck, opponentName, opponentDeck;// EditText for user input.
//View parentView;//ID of parent view for reference
EditText playerDeck,opponentName, opponentDeck;// EditText for user input.
Switch WinLose;
Button submit,UserProfile;

FirebaseDatabase mFireBase = FirebaseDatabase.getInstance();//declare Firebase database
DatabaseReference myRef = mFireBase.getReference();//reference of database, mainly used by us as a path for storing files
FirebaseUser curUser = FirebaseAuth.getInstance().getCurrentUser();//Current User, it is used to get Displayname, email or Uid.
private AppBarConfiguration mAppBarConfiguration;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -66,11 +61,10 @@ protected void onCreate(Bundle savedInstanceState) {
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.activityMain);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// Passing each menu ID as a set of Ids because each
// menu should be considered as top level destinations.
mAppBarConfiguration = new AppBarConfiguration.Builder(
R.id.navInputForm, R.id.navStatistics,R.id.navContactBook,R.id.navLifeCounter,R.id.navSettings)
R.id.nav_inputForm, R.id.nav_stats)
.setDrawerLayout(drawer)
.build();
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
Expand All @@ -83,120 +77,101 @@ protected void onCreate(Bundle savedInstanceState) {
//}
//});
//declare each element in the input layout
//playerDeck = findViewById(R.id.playerDeckText);
//opponentName = findViewById(R.id.opponentNameText);
//opponentDeck = findViewById(R.id.opponentDeckText);
playerDeck = findViewById(R.id.playerDeckText);
opponentName = findViewById(R.id.opponentNameText);
opponentDeck = findViewById(R.id.opponentDeckText);

//WinLose = findViewById(R.id.winSwitch);
WinLose = findViewById(R.id.winSwitch);

//submit = findViewById(R.id.submitButton);
submit = findViewById(R.id.submitButton);
//OnCheckChangeListener is a listener which can detect the switch is on or off
//WinLose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
//@Override
//public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//result = isChecked;
//if(isChecked){
//winC = 1;
//}else{
//loseC = 1;
//}
//}
//});
WinLose.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
result = isChecked;
if(isChecked){
winC = 1;
}else{
loseC = 1;
}
}
});

//myRef.addValueEventListener(new ValueEventListener() {
//@Override
//public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

//}
}

//@Override
//public void onCancelled(@NonNull DatabaseError databaseError) {
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

//}
//});
}
});

//submit.setOnClickListener(new View.OnClickListener() {
//@Override
//public void onClick(View v) {
//addData();
//}
//});
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
addData();
}
});


//addData() will add the data to the firebase
//private void addData(){
//String UserID = curUser.getDisplayName();
//String id = myRef.push().getKey();
//get date data by Calendar.
//And get text from elements in layout and convert them to string
//Date curD = Calendar.getInstance().getTime();
//String pD = playerDeck.getText().toString();
//String oN = opponentName.getText().toString();
//String oD = opponentDeck.getText().toString();
//String DataName = "data" + DataCounter;
//Toast.makeText(this,UserID,Toast.LENGTH_LONG).show();

//WinRateData winData = new WinRateData(pD,oN,oD,result,curD);
//DatabaseReference newRef = myRef.child(curUser.getUid());
//newRef.addValueEventListener(new ValueEventListener() {
//@Override
//public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//curWinSum = Integer.parseInt(dataSnapshot.child("winSum").getValue().toString());
//curLoseSum = Integer.parseInt(dataSnapshot.child("loseSum").getValue().toString());
//curWinSum = curWinSum + winC;
//curLoseSum = curLoseSum + loseC;
//}

//@Override
//public void onCancelled(@NonNull DatabaseError databaseError) {
//}
//});

//myRef.child(curUser.getUid()).child("winSum").setValue(curWinSum);
//myRef.child(curUser.getUid()).child("loseSum").setValue(curLoseSum);
//myRef.child(curUser.getUid()).child("winSum").setValue(winC);
//myRef.child(curUser.getUid()).child("loseSum").setValue(loseC);
//myRef.child(curUser.getUid()).child(myRef.push().getKey()).setValue(winData);

//LargeData newdata = new LargeData(winC, loseC, winData, DataName, curUser, myRef);
//DataCounter++;

}

//@Override
//public boolean onCreateOptionsMenu(Menu menu) {
//Inflate the menu; this adds items to the action bar if it is present.
// getMenuInflater().inflate(R.menu.options_menu, menu);
// return true;
//}
//addData() will add the data to the firebase
private void addData(){
//String UserID = curUser.getDisplayName();
//String id = myRef.push().getKey();
//get date data by Calendar.
//And get text from elements in layout and convert them to string
Date curD = Calendar.getInstance().getTime();
String pD = playerDeck.getText().toString();
String oN = opponentName.getText().toString();
String oD = opponentDeck.getText().toString();
//String DataName = "data" + DataCounter;
//Toast.makeText(this,UserID,Toast.LENGTH_LONG).show();

WinRateData winData = new WinRateData(pD,oN,oD,result,curD);
DatabaseReference newRef = myRef.child(curUser.getUid());
newRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
curWinSum = Integer.parseInt(dataSnapshot.child("winSum").getValue().toString());
curLoseSum = Integer.parseInt(dataSnapshot.child("loseSum").getValue().toString());
curWinSum = curWinSum + winC;
curLoseSum = curLoseSum + loseC;
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});

myRef.child(curUser.getUid()).child("winSum").setValue(curWinSum);
myRef.child(curUser.getUid()).child("loseSum").setValue(curLoseSum);
//myRef.child(curUser.getUid()).child("winSum").setValue(winC);
//myRef.child(curUser.getUid()).child("loseSum").setValue(loseC);
myRef.child(curUser.getUid()).child(myRef.push().getKey()).setValue(winData);

//LargeData newdata = new LargeData(winC, loseC, winData, DataName, curUser, myRef);
DataCounter++;

/*BEGIN INITIALIZATION OF ROOM DATABASE*/
RecyclerView recyclerView = findViewById(R.id.recyclerview);
final GameLogAdapter adapter = new GameLogAdapter(this);
//recyclerView.setAdapter(adapter); // bugs on these two lines
//recyclerView.setLayoutManager(new LinearLayoutManager(this));

/*END INITIALIZATION OF ROOM DATABASE*/

@Override
public boolean onSupportNavigateUp() {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
return NavigationUI.navigateUp(navController, mAppBarConfiguration)
|| super.onSupportNavigateUp();
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
switch (item.getItemId()) {
case R.id.navInputForm:
navController.navigate(R.id.navInputForm);
break;
case R.id.navStatistics:
navController.navigate(R.id.navStatistics);
break;
case R.id.navContactBook:
navController.navigate(R.id.navContactBook);
break;
case R.id.navLifeCounter:
navController.navigate(R.id.navLifeCounter);
break;
case R.id.navSettings:
navController.navigate(R.id.navSettings);
break;
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.draw_menu, menu);
return true;
}
}
Loading

0 comments on commit a2988d2

Please sign in to comment.