Benutzer Bearbeiten v1
Bild wird in firebase storage gespeichert Aber es kommt keine download url back
This commit is contained in:
parent
43532e2673
commit
4fc6c7c85e
BIN
.idea/caches/gradle_models.ser
generated
BIN
.idea/caches/gradle_models.ser
generated
Binary file not shown.
@ -5,7 +5,7 @@ android {
|
||||
compileSdkVersion 28
|
||||
defaultConfig {
|
||||
applicationId "at.smartshopper.smartshopper"
|
||||
minSdkVersion 19
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@ -30,10 +30,10 @@ dependencies {
|
||||
implementation 'com.google.firebase:firebase-auth:16.1.0'
|
||||
implementation 'com.google.firebase:firebase-messaging:17.3.4'
|
||||
implementation 'com.google.firebase:firebase-core:16.0.6'
|
||||
implementation 'com.google.firebase:firebase-storage:16.0.5'
|
||||
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
|
||||
implementation 'com.google.android.gms:play-services-auth:16.0.1'
|
||||
implementation 'com.firebaseui:firebase-ui-auth:4.1.0'
|
||||
// http://mvnrepository.com/artifact/postgresql/postgresql
|
||||
implementation group: 'postgresql', name: 'postgresql', version: '9.1-901.jdbc4'
|
||||
implementation 'com.squareup.picasso:picasso:2.71828'
|
||||
implementation 'com.android.support:swiperefreshlayout:28.0.0-alpha1'
|
||||
@ -42,5 +42,4 @@ dependencies {
|
||||
implementation 'com.android.support:recyclerview-v7:28.0.0'
|
||||
implementation 'com.android.support:support-v4:28.0.0'
|
||||
implementation 'cz.msebera.android:httpclient:4.4.1.2'
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,10 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
<activity android:name=".activitys.DoneItemActivity"></activity>
|
||||
<activity
|
||||
android:name=".activitys.EditUser"
|
||||
android:label="@string/title_activity_edit_user"></activity>
|
||||
<activity android:name=".activitys.DoneItemActivity" />
|
||||
<activity
|
||||
android:name=".activitys.ItemListActivity"
|
||||
android:label="@string/title_activity_item_list" />
|
||||
|
@ -607,6 +607,10 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte
|
||||
Intent intent = new Intent(Dash.this, DoneItemActivity.class);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
case R.id.editUser:
|
||||
Intent intent2 = new Intent(Dash.this, EditUser.class);
|
||||
startActivity(intent2);
|
||||
return true;
|
||||
default:
|
||||
// If we got here, the user's action was not recognized.
|
||||
// Invoke the superclass to handle it.
|
||||
|
@ -0,0 +1,128 @@
|
||||
package at.smartshopper.smartshopper.activitys;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
import com.google.firebase.auth.UserProfileChangeRequest;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
import at.smartshopper.smartshopper.R;
|
||||
import at.smartshopper.smartshopper.storage.ImgSaver;
|
||||
|
||||
public class EditUser extends Activity {
|
||||
|
||||
private EditText editname;
|
||||
private ImageView userbild;
|
||||
private Button finish, chooseImg;
|
||||
private Bitmap userBitmap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_edit_user);
|
||||
userbild = (ImageView) findViewById(R.id.userImage);
|
||||
editname = (EditText) findViewById(R.id.editName);
|
||||
finish = (Button) findViewById(R.id.editFinish);
|
||||
chooseImg = (Button)findViewById(R.id.chooseImg);
|
||||
|
||||
final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
||||
if (user != null) {
|
||||
// Name, email address, and profile photo Url
|
||||
String name = user.getDisplayName();
|
||||
Uri photoUrl = user.getPhotoUrl();
|
||||
|
||||
userbild.setImageDrawable(LoadImageFromWebOperations(photoUrl.toString()));
|
||||
|
||||
editname.setText(name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
chooseImg.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
getIntent.setType("image/*");
|
||||
|
||||
Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
||||
pickIntent.setType("image/*");
|
||||
|
||||
Intent chooserIntent = Intent.createChooser(getIntent, "Select Image");
|
||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent});
|
||||
|
||||
startActivityForResult(chooserIntent, 1);
|
||||
}
|
||||
});
|
||||
|
||||
finish.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Uri uri = ImgSaver.uploadImg(userBitmap, FirebaseAuth.getInstance().getUid());
|
||||
Log.d("SmartShopper", "https://lh3.googleusercontent.com/-ZBYkQh5lTyA/AAAAAAAAAAI/AAAAAAAAEas/zCXYWfty-FE/photo.jpg");
|
||||
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
|
||||
.setDisplayName(editname.getText().toString())
|
||||
.setPhotoUri(uri)
|
||||
.build();
|
||||
|
||||
user.updateProfile(profileUpdates)
|
||||
.addOnCompleteListener(new OnCompleteListener<Void>() {
|
||||
@Override
|
||||
public void onComplete(@NonNull Task<Void> task) {
|
||||
if (task.isSuccessful()) {
|
||||
Log.d("SmartShopper", "User profile updated.");
|
||||
finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (requestCode == 1) {
|
||||
try {
|
||||
final Uri imageUri = data.getData();
|
||||
final InputStream imageStream = getContentResolver().openInputStream(imageUri);
|
||||
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
|
||||
userBitmap = selectedImage;
|
||||
userbild.setImageBitmap(selectedImage);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable LoadImageFromWebOperations(String url) {
|
||||
try {
|
||||
InputStream is = (InputStream) new URL(url).getContent();
|
||||
Drawable d = Drawable.createFromStream(is, "src name");
|
||||
return d;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package at.smartshopper.smartshopper.storage;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.tasks.Continuation;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.OnFailureListener;
|
||||
import com.google.android.gms.tasks.OnSuccessListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.storage.FirebaseStorage;
|
||||
import com.google.firebase.storage.StorageReference;
|
||||
import com.google.firebase.storage.UploadTask;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
public class ImgSaver {
|
||||
|
||||
private static FirebaseStorage storage = FirebaseStorage.getInstance();
|
||||
private static Uri downloadUriFinal = null;
|
||||
|
||||
public static Uri uploadImg(Bitmap bitmap, String uid){
|
||||
final StorageReference storageRef = storage.getReference("/" + uid);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
|
||||
byte[] data = baos.toByteArray();
|
||||
|
||||
final UploadTask uploadTask = storageRef.putBytes(data);
|
||||
uploadTask.addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception exception) {
|
||||
// Handle unsuccessful uploads
|
||||
Log.d("SmartShopper", exception.getMessage());
|
||||
}
|
||||
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
|
||||
@Override
|
||||
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
|
||||
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, etc.
|
||||
// ...
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
storage.getReference().child("/" + uid).getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
|
||||
@Override
|
||||
public void onSuccess(Uri uri) {
|
||||
Log.d("SmartShopper", uri.toString());
|
||||
|
||||
}
|
||||
}).addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception exception) {
|
||||
// Handle any errors
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return downloadUriFinal;
|
||||
}
|
||||
}
|
100
app/src/main/res/layout/activity_edit_user.xml
Normal file
100
app/src/main/res/layout/activity_edit_user.xml
Normal file
@ -0,0 +1,100 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activitys.EditUser">
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView7"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Name"
|
||||
android:textAlignment="center"
|
||||
android:textSize="18dp"
|
||||
android:textStyle="bold" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/Bild"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Bild"
|
||||
android:textAlignment="center"
|
||||
android:textSize="18dp"
|
||||
android:textStyle="bold" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/userImage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:src="@tools:sample/avatars" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/chooseImg"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Bild auswählen" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/editFinish"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Fertig" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
</android.support.constraint.ConstraintLayout>
|
@ -6,6 +6,9 @@
|
||||
<item
|
||||
android:id="@+id/doneEinkauf"
|
||||
android:title="Erledigte Einkäufe" />
|
||||
<item
|
||||
android:id="@+id/editUser"
|
||||
android:title="Benutzer bearbeiten" />
|
||||
<item
|
||||
android:id="@+id/logoutBtn"
|
||||
android:enabled="true"
|
||||
|
@ -7,6 +7,7 @@
|
||||
<string name="title_activity_item_list">ItemListActivity</string>
|
||||
<string name="firebase_sender_id">221332577314</string>
|
||||
<string name="StringTag">SmartShopper</string>
|
||||
<string name="title_activity_edit_user">EditUser</string>
|
||||
|
||||
</resources>
|
||||
|
||||
|
@ -7,7 +7,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.3.0'
|
||||
classpath 'com.android.tools.build:gradle:3.3.2'
|
||||
classpath 'com.google.gms:google-services:4.0.1'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
|
Loading…
x
Reference in New Issue
Block a user