Commit e1ea293e authored by Anuththara18's avatar Anuththara18

Automatic Video Upload Code Added

parent 4251af72
......@@ -11,6 +11,7 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.pdf.PdfDocument;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
......@@ -32,6 +33,15 @@ import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.opencsv.CSVWriter;
import java.io.File;
......@@ -197,6 +207,8 @@ public class AACompleteScreen extends AppCompatActivity {
e.printStackTrace();
}
uploadToFirebase(csv);
/*******************************************************************************************/
// generate our PDF file.
......@@ -352,6 +364,41 @@ public class AACompleteScreen extends AppCompatActivity {
}
/**************************************************************************************************/
public void uploadToFirebase(String csv) {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser() == null ) {
auth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i("test user", String.valueOf(task.isSuccessful()));
}
});
}
StorageReference storageRef = FirebaseStorage.getInstance().getReference();
Uri file = Uri.fromFile(new File(csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
//Toast.makeText(getApplicationContext(), "Upload Filed", Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Upload successful", Toast.LENGTH_SHORT).show();
}
});
}
/**************************************************************************************************/
/**************************************************************************************************/
......
......@@ -36,6 +36,15 @@ import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.opencsv.CSVWriter;
import java.io.File;
......@@ -198,6 +207,8 @@ public class DACompleteScreen extends AppCompatActivity {
e.printStackTrace();
}
uploadToFirebase(csv);
/*******************************************************************************************/
......@@ -355,6 +366,39 @@ public class DACompleteScreen extends AppCompatActivity {
}
/**************************************************************************************************/
public void uploadToFirebase(String csv) {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser() == null ) {
auth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i("test user", String.valueOf(task.isSuccessful()));
}
});
}
StorageReference storageRef = FirebaseStorage.getInstance().getReference();
Uri file = Uri.fromFile(new File(csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
//Toast.makeText(getApplicationContext(), "Upload Filed", Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Upload successful", Toast.LENGTH_SHORT).show();
}
});
}
/**************************************************************************************************/
......
......@@ -206,6 +206,8 @@ public class FACompleteScreen extends AppCompatActivity {
e.printStackTrace();
}
uploadToFirebase(csv);
/*******************************************************************************************/
......@@ -345,7 +347,7 @@ public class FACompleteScreen extends AppCompatActivity {
}
public void uploadToFirebase() {
public void uploadToFirebase(String csv) {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser().getUid() == null ) {
auth.signInAnonymously();
......@@ -353,7 +355,7 @@ public class FACompleteScreen extends AppCompatActivity {
StorageReference storageRef = FirebaseStorage.getInstance().getReference();
Uri file = Uri.fromFile(new File(csv));
Uri file = Uri.fromFile(new File(this.csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
......
......@@ -370,7 +370,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
Uri file = Uri.fromFile(new File(csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + "/Game1/" + file.getLastPathSegment());
//StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + "/Game1/" + file.getLastPathSegment());
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
......
......@@ -36,6 +36,15 @@ import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
import com.anuththara18.attentionassessment.selective.Selective;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.OnProgressListener;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.opencsv.CSVWriter;
import java.io.File;
......@@ -197,6 +206,8 @@ public class SA1CompleteScreen extends AppCompatActivity {
e.printStackTrace();
}
uploadToFirebase(csv);
/*******************************************************************************************/
// generate our PDF file.
......@@ -352,6 +363,38 @@ public class SA1CompleteScreen extends AppCompatActivity {
}
/**************************************************************************************************/
public void uploadToFirebase(String csv) {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser() == null ) {
auth.signInAnonymously().addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.i("test user", String.valueOf(task.isSuccessful()));
}
});
}
StorageReference storageRef = FirebaseStorage.getInstance().getReference();
Uri file = Uri.fromFile(new File(csv));
StorageReference storageReference = storageRef.child(auth.getCurrentUser().getUid() + file.getLastPathSegment());
storageReference.putFile(file).addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(@NonNull UploadTask.TaskSnapshot snapshot) {
//Toast.makeText(getApplicationContext(), "Upload Filed", Toast.LENGTH_SHORT).show();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getApplicationContext(), "Upload successful", Toast.LENGTH_SHORT).show();
}
});
}
/**************************************************************************************************/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment