Skip to content

Commit 9cad149

Browse files
committed
Google sign in done, Code for upload not working
1 parent 1b6a599 commit 9cad149

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+70
-844
lines changed

mobile-photo-gallery/Cloudi/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,20 @@ android {
2222
}
2323

2424
dependencies {
25+
2526
compile 'com.firebaseui:firebase-ui-auth:3.1.0'
2627
implementation fileTree(include: ['*.jar'], dir: 'libs')
2728
implementation 'com.android.support:appcompat-v7:26.1.0'
2829
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
2930
implementation 'com.android.support:design:26.1.0'
3031
implementation 'com.android.support:support-vector-drawable:26.1.0'
3132
implementation 'com.google.firebase:firebase-auth:11.4.2'
33+
implementation 'com.google.firebase:firebase-storage:11.4.2'
3234
testImplementation 'junit:junit:4.12'
3335
androidTestImplementation 'com.android.support.test:runner:1.0.1'
3436
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
3537
}
3638

3739

40+
3841
apply plugin: 'com.google.gms.google-services'

mobile-photo-gallery/Cloudi/app/google-services.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
{
22
"project_info": {
3-
"project_number": "108914645069",
4-
"firebase_url": "https://cloudi-8cbf3.firebaseio.com",
5-
"project_id": "cloudi-8cbf3",
6-
"storage_bucket": "cloudi-8cbf3.appspot.com"
3+
"project_number": "353129209490",
4+
"firebase_url": "https://cloudi-8e6fe.firebaseio.com",
5+
"project_id": "cloudi-8e6fe",
6+
"storage_bucket": "cloudi-8e6fe.appspot.com"
77
},
88
"client": [
99
{
1010
"client_info": {
11-
"mobilesdk_app_id": "1:108914645069:android:ac1a56ed8ce5b340",
11+
"mobilesdk_app_id": "1:353129209490:android:ac1a56ed8ce5b340",
1212
"android_client_info": {
1313
"package_name": "com.cornelltech.chumengxu.cloudi"
1414
}
1515
},
1616
"oauth_client": [
1717
{
18-
"client_id": "108914645069-chqor0ukfisaba8gh0s35n42bvagsbnn.apps.googleusercontent.com",
18+
"client_id": "353129209490-i9m2jr5rno5du0fjba5537lki5qfdahp.apps.googleusercontent.com",
1919
"client_type": 1,
2020
"android_info": {
2121
"package_name": "com.cornelltech.chumengxu.cloudi",
22-
"certificate_hash": "c154d9dd36937bc47d28521086a1c148f751ec67"
22+
"certificate_hash": "0fbc19f8faa3b7e6269c04661b7df81ac0345497"
2323
}
2424
},
2525
{
26-
"client_id": "108914645069-tmfm2vi1u092uhaih902sm5pcgv07kjb.apps.googleusercontent.com",
26+
"client_id": "353129209490-6vu92ki58a1tvb354l1a7b1stn32i2oc.apps.googleusercontent.com",
2727
"client_type": 3
2828
}
2929
],
3030
"api_key": [
3131
{
32-
"current_key": "AIzaSyCzGAb0rSkCHR2HtkTmgjuaIUCzQoeRyNI"
32+
"current_key": "AIzaSyB6pW0kjDD2oVDQtVGJBF31oK3Vpqnq970"
3333
}
3434
],
3535
"services": {
@@ -40,7 +40,7 @@
4040
"status": 2,
4141
"other_platform_oauth_client": [
4242
{
43-
"client_id": "108914645069-tmfm2vi1u092uhaih902sm5pcgv07kjb.apps.googleusercontent.com",
43+
"client_id": "353129209490-6vu92ki58a1tvb354l1a7b1stn32i2oc.apps.googleusercontent.com",
4444
"client_type": 3
4545
}
4646
]

mobile-photo-gallery/Cloudi/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<uses-permission android:name="android.permission.READ_PROFILE" />
88
<uses-permission android:name="android.permission.READ_CONTACTS" />
99
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
10+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
1011

1112
<application
1213
android:allowBackup="true"

mobile-photo-gallery/Cloudi/app/src/main/java/com/cornelltech/chumengxu/cloudi/MainActivity.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.support.annotation.NonNull;
66
import android.support.v7.app.AppCompatActivity;
77
import android.support.v7.widget.Toolbar;
8+
import android.util.Log;
89
import android.view.Menu;
910
import android.view.MenuItem;
1011

@@ -23,6 +24,7 @@ public class MainActivity extends AppCompatActivity {
2324
private static final int RC_SIGN_IN = 123;
2425
private Menu menu;
2526
private boolean signed_in=false;
27+
private static final String TAG = "Logger";
2628

2729
@Override
2830
public boolean onCreateOptionsMenu(Menu menu) {
@@ -37,9 +39,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
3739
switch (item.getItemId()) {
3840
case R.id.sign_in:
3941
if (signed_in==false) {
42+
Log.v(TAG, "Not signed in");
4043
// Choose authentication providers
4144
List<AuthUI.IdpConfig> providers = Arrays.asList(
42-
new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
45+
new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
46+
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build());
4347

4448
// Create and launch sign-in intent
4549
startActivityForResult(
@@ -64,8 +68,8 @@ public void onComplete(@NonNull Task<Void> task) {
6468
}
6569

6670
case R.id.upload:
67-
Intent intent2=new Intent(this,UploadActivity.class);
68-
startActivityForResult(intent2,0);
71+
Intent uploadIntent=new Intent(this,UploadActivity.class);
72+
startActivityForResult(uploadIntent,0);
6973
return true;
7074

7175
default:
@@ -81,10 +85,12 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
8185
super.onActivityResult(requestCode, resultCode, data);
8286

8387
if (requestCode == RC_SIGN_IN) {
88+
Log.v(TAG, "Attempting sign in...");
8489
IdpResponse response = IdpResponse.fromResultIntent(data);
8590

86-
if (resultCode == ResultCodes.OK) {
91+
if (resultCode == RESULT_OK) {
8792
// Successfully signed in
93+
Log.v(TAG, "Successfully signed in");
8894
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
8995
MenuItem signinMenuItem=menu.findItem(R.id.sign_in);
9096
signinMenuItem.setTitle("Sign out");
@@ -103,6 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
103109
setContentView(R.layout.activity_main);
104110
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
105111
setSupportActionBar(myToolbar);
112+
Log.v(TAG, "Successfully printed");
106113
}
107114

108115

mobile-photo-gallery/Cloudi/app/src/main/java/com/cornelltech/chumengxu/cloudi/UploadActivity.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
package com.cornelltech.chumengxu.cloudi;
22

3+
import android.app.ProgressDialog;
34
import android.content.Intent;
45
import android.net.Uri;
56
import android.os.Bundle;
67
import android.support.v7.app.AppCompatActivity;
8+
import android.util.Log;
79
import android.view.View;
10+
import android.widget.Button;
811
import android.widget.EditText;
12+
import android.widget.Toast;
13+
14+
import com.google.android.gms.tasks.OnSuccessListener;
15+
import com.google.firebase.storage.FirebaseStorage;
16+
import com.google.firebase.storage.StorageReference;
17+
import com.google.firebase.storage.UploadTask;
918

1019
public class UploadActivity extends AppCompatActivity {
1120

21+
private StorageReference mStorageRef;
22+
23+
private Button mSelectImage;
24+
25+
private ProgressDialog mProgressDialog;
26+
27+
private static final int GALLERY_INTENT = 2;
28+
1229
public void pickImage(View view){
1330
Intent pickImage = new Intent(Intent.ACTION_PICK,
1431
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
@@ -19,6 +36,17 @@ public void pickImage(View view){
1936
protected void onCreate(Bundle savedInstanceState) {
2037
super.onCreate(savedInstanceState);
2138
setContentView(R.layout.activity_upload);
39+
mStorageRef = FirebaseStorage.getInstance().getReference();
40+
mSelectImage = (Button) findViewById(R.id.upload);
41+
mProgressDialog = new ProgressDialog(this);
42+
mSelectImage.setOnClickListener(new View.OnClickListener() {
43+
@Override
44+
public void onClick(View view) {
45+
Intent intent = new Intent(Intent.ACTION_PICK);
46+
intent.setType("image/*");
47+
startActivityForResult(intent,GALLERY_INTENT);
48+
}
49+
});
2250
}
2351

2452
@Override
@@ -27,6 +55,22 @@ protected void onActivityResult(int requestCode, int resultCode, Intent imageRet
2755
Uri selectedImage = imageReturnedIntent.getData();
2856
EditText imagePathText = (EditText) findViewById(R.id.imagePathView);
2957
imagePathText.setText(selectedImage.toString());
58+
59+
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
60+
Log.d("Success","Upload attempt");
61+
mProgressDialog.setMessage("Uploading ....");
62+
mProgressDialog.show();
63+
StorageReference filepath = mStorageRef.child("Public").child(selectedImage.getLastPathSegment());
64+
65+
filepath.putFile(selectedImage).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
66+
@Override
67+
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
68+
Log.d("Success","Upload done");
69+
Toast.makeText(UploadActivity.this,"Upload done.",Toast.LENGTH_LONG).show();
70+
mProgressDialog.dismiss();
71+
}
72+
});
73+
}
3074
}
3175

3276
}

mobile-photo-gallery/Cloudi/app/src/main/res/layout/activity_upload.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
app:layout_constraintTop_toTopOf="parent" />
7272

7373
<Button
74-
android:id="@+id/button4"
74+
android:id="@+id/upload"
7575
android:layout_width="wrap_content"
7676
android:layout_height="wrap_content"
7777
android:layout_marginTop="200dp"

mobile-photo-gallery/photogallery/.gitignore

Lines changed: 0 additions & 9 deletions
This file was deleted.

mobile-photo-gallery/photogallery/app/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

mobile-photo-gallery/photogallery/app/build.gradle

Lines changed: 0 additions & 34 deletions
This file was deleted.

mobile-photo-gallery/photogallery/app/google-services.json

Lines changed: 0 additions & 99 deletions
This file was deleted.

mobile-photo-gallery/photogallery/app/proguard-rules.pro

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)