Commit de7c1b0c authored by Anuththara18's avatar Anuththara18

Automatic Upload of CSV files

parent 96206ad0
plugins {
id 'com.android.application'
}
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 31
buildToolsVersion "30.0.3"
......@@ -33,6 +34,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
implementation 'com.google.firebase:firebase-storage:19.1.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
......@@ -44,5 +46,11 @@ dependencies {
implementation 'com.opencsv:opencsv:4.6' // Here is opencsv library
implementation files('libs\\YouTubeAndroidPlayerApi.jar')
implementation platform('com.google.firebase:firebase-bom:29.3.1')
implementation 'com.google.firebase:firebase-auth'
}
\ No newline at end of file
{
"project_info": {
"project_number": "642347843728",
"project_id": "attention-assessment",
"storage_bucket": "attention-assessment.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:642347843728:android:c7e91fc87a80c3a5b61815",
"android_client_info": {
"package_name": "com.anuththara18.attentionassessment"
}
},
"oauth_client": [
{
"client_id": "642347843728-u7co8a3vsktblmr57r5r6ees4uof65d4.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDth7XK-DMLvkNCziMz55eQkSuNCPzWsZk"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "642347843728-u7co8a3vsktblmr57r5r6ees4uof65d4.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
......@@ -105,7 +105,7 @@ public class ParentDetailsActivity extends AppCompatActivity {
}
else{
diagnosis = (String) genderradioButton.getText();
Toast.makeText(ParentDetailsActivity.this,genderradioButton.getText(), Toast.LENGTH_SHORT).show();
//Toast.makeText(ParentDetailsActivity.this,genderradioButton.getText(), Toast.LENGTH_SHORT).show();
nav = 1;
if (LanguageActivity.text.equals("English")) {
startActivity(new Intent(ParentDetailsActivity.this, ConsentFormActivity.class));
......
......@@ -36,6 +36,12 @@ 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.OnSuccessListener;
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;
......@@ -56,6 +62,8 @@ public class FACompleteScreen extends AppCompatActivity {
List<Focused> dataList;
SQLiteDatabase mDatabase;
String csv;
// declaring width and height
// for our PDF file.
int pageHeight = 1520;
......@@ -161,7 +169,7 @@ public class FACompleteScreen extends AppCompatActivity {
/*******************************************************************************************/
String csv = (Environment.getExternalStorageDirectory().getAbsolutePath() + "/FocusedAttention.csv"); // Here csv file name is MyCsvFile.csv
csv = (Environment.getExternalStorageDirectory().getAbsolutePath() + "/FocusedAttention.csv"); // Here csv file name is MyCsvFile.csv
// csv will create inside phone storage.
CSVWriter writer = null;
......@@ -337,6 +345,33 @@ public class FACompleteScreen extends AppCompatActivity {
}
public void uploadToFirebase() {
FirebaseAuth auth = FirebaseAuth.getInstance();
if ( auth.getCurrentUser().getUid() == null ) {
auth.signInAnonymously();
}
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();
}
});
}
/**************************************************************************************************/
......
......@@ -35,6 +35,15 @@ import com.anuththara18.attentionassessment.consentform.ParentsConsentDatabaseHe
import com.anuththara18.attentionassessment.details.ParentDetailsActivity;
import com.anuththara18.attentionassessment.gender.GenderActivity;
import com.anuththara18.attentionassessment.home.NavigationDrawerActivity;
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;
......@@ -196,6 +205,8 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
e.printStackTrace();
}
uploadToFirebase(csv);
/*******************************************************************************************/
PdfDocument pdfDocument = new PdfDocument();
......@@ -343,4 +354,35 @@ public class SelectiveACompleteScreen extends AppCompatActivity {
return scaledBitmap;
}
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() + "/Game1/" + 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();
}
});
}
}
......@@ -5,8 +5,22 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white"
tools:context=".videos.IntroductoryVideoPortraitActivity">
<TextView
android:id="@+id/skip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:fontFamily="@font/poppins_medium"
android:gravity="center"
android:text="@string/skip"
android:textColor="@color/black"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<WebView android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
......@@ -14,4 +28,12 @@
android:layout_centerHorizontal="true">
</WebView>
<!--
<com.google.android.youtube.player.YouTubePlayerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ytPlayer"
app:layout_constraintTop_toTopOf="parent"/>
-->
</LinearLayout>
\ No newline at end of file
......@@ -12,6 +12,7 @@
<string name="girl">ගැහැණු</string>
<string name="boy">පිරිමි</string>
<string name="next">ඊළඟ</string>
<string name="skip">මඟ හැර යන්න...</string>
<string name="previous">පෙර</string>
<string name="age">ඔබේ දරුවාගේ වයස තෝරන්න:</string>
<string name="language">භාෂාව තෝරන්න:</string>
......
......@@ -11,6 +11,7 @@
<string name="girl">Girl</string>
<string name="boy">Boy</string>
<string name="next">Next</string>
<string name="skip">Skip...</string>
<string name="previous">Previous</string>
<string name="age">Select your child\'s age:</string>
<string name="language">Select language:</string>
......
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