Refresh List, Gui
Refresch List by swipe Gui update User image User Image round Full width CardView
This commit is contained in:
parent
dc55cca26c
commit
071f6b9be2
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -32,4 +32,6 @@ dependencies {
|
||||
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'
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package at.smartshopper.smartshopper;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TabHost;
|
||||
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
@ -23,6 +27,12 @@ import java.util.jar.JarInputStream;
|
||||
public class Dash extends AppCompatActivity {
|
||||
|
||||
private Database db = new Database();
|
||||
private SwipeRefreshLayout ownswiperefresh;
|
||||
|
||||
private void goLogin() {
|
||||
Intent intent = new Intent(this, LoginActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ -31,9 +41,17 @@ public class Dash extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_dash);
|
||||
|
||||
|
||||
|
||||
tabHoster();
|
||||
|
||||
Button logoutBtn = (Button) findViewById(R.id.logoutBtn);
|
||||
logoutBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FirebaseAuth.getInstance().signOut();
|
||||
goLogin();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
/*
|
||||
Get userinformations
|
||||
@ -44,9 +62,7 @@ public class Dash extends AppCompatActivity {
|
||||
String name = user.getDisplayName();
|
||||
String email = user.getEmail();
|
||||
Uri photoUrl = user.getPhotoUrl();
|
||||
RecyclerView ownRecycleView = (RecyclerView) findViewById(R.id.ownrecycler);
|
||||
ownRecycleView.setHasFixedSize(true);
|
||||
ownRecycleView.setLayoutManager(new LinearLayoutManager(this));
|
||||
|
||||
|
||||
// Check if user's email is verified
|
||||
boolean emailVerified = user.isEmailVerified();
|
||||
@ -54,20 +70,67 @@ public class Dash extends AppCompatActivity {
|
||||
// The user's ID, unique to the Firebase project. Do NOT use this value to
|
||||
// authenticate with your backend server, if you have one. Use
|
||||
// FirebaseUser.getIdToken() instead.
|
||||
String uid = user.getUid();
|
||||
final String uid = user.getUid();
|
||||
|
||||
|
||||
try {
|
||||
List<Shoppinglist> ownListsList = db.getMyShoppinglists(uid);
|
||||
|
||||
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList);
|
||||
|
||||
ownRecycleView.setAdapter(shpAdapter);
|
||||
}catch (JSONException e){
|
||||
showOwnShoppingList(uid);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ownswiperefresh = (SwipeRefreshLayout) findViewById(R.id.ownSwipe);
|
||||
|
||||
ownswiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
|
||||
@Override
|
||||
public void onRefresh() {
|
||||
refreshOwnShoppinglist(uid);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshed die eigene shoppinglist und veranlasst das das refreshen beendet wird
|
||||
* @param uid Von dem benutzer von welchem die Shoppinglists angezeigt werden sollen
|
||||
*/
|
||||
private void refreshOwnShoppinglist(String uid){
|
||||
try {
|
||||
showOwnShoppingList(uid);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
refreshOwnShoppinglistFinish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stoppt das refreshen der OwnShoppinglist
|
||||
*/
|
||||
private void refreshOwnShoppinglistFinish() {
|
||||
// Update the adapter and notify data set changed
|
||||
// ...
|
||||
|
||||
// Stop refresh animation
|
||||
ownswiperefresh.setRefreshing(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Macht eine Datenbankverbindung und holt alle Shoppinglists die dem User gehören, diese werden auf dem recycled view angezeigt
|
||||
*
|
||||
* @param uid Die UserId damit von diesem user die shoppinglisten angezeigt werden
|
||||
*/
|
||||
private void showOwnShoppingList(String uid) throws JSONException {
|
||||
RecyclerView ownRecycleView = (RecyclerView) findViewById(R.id.ownrecycler);
|
||||
ownRecycleView.setHasFixedSize(true);
|
||||
ownRecycleView.setLayoutManager(new LinearLayoutManager(this));
|
||||
List<Shoppinglist> ownListsList = db.getMyShoppinglists(uid);
|
||||
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList);
|
||||
ownRecycleView.setAdapter(shpAdapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ist dafür Zuständig das es Tabs in der App gibt. Ohne dieser Funktion werden die Tabs nichtmehr Angezeigt.
|
||||
* Hier wird auch der Name der Tabs gesetzt
|
||||
|
@ -0,0 +1,152 @@
|
||||
package at.smartshopper.smartshopper;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
|
||||
|
||||
// enables hardware accelerated rounded corners
|
||||
// original idea here : http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/
|
||||
// https://gist.github.com/aprock/6213395
|
||||
// https://gist.github.com/amardeshbd/06b491d4adb568b1b226a20d4953a180
|
||||
public class RoundCornersTransformation implements com.squareup.picasso.Transformation {
|
||||
private final int radius; // dp
|
||||
private final int margin; // dp
|
||||
private String KEY = "";
|
||||
private boolean topCorners = true;
|
||||
private boolean bottomCorners = true;
|
||||
|
||||
/**
|
||||
* Creates rounded transformation for all corners.
|
||||
*
|
||||
* @param radius radius is corner radii in dp
|
||||
* @param margin margin is the board in dp
|
||||
*/
|
||||
public RoundCornersTransformation(final int radius, final int margin) {
|
||||
this.radius = radius;
|
||||
this.margin = margin;
|
||||
if (KEY.isEmpty()) KEY = "rounded_" + radius + margin;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates rounded transformation for top or bottom corners.
|
||||
*
|
||||
* @param radius radius is corner radii in dp
|
||||
* @param margin margin is the board in dp
|
||||
* @param topCornersOnly Rounded corner for top corners only.
|
||||
* @param bottomCornersOnly Rounded corner for bottom corners only.
|
||||
*/
|
||||
public RoundCornersTransformation(final int radius, final int margin, boolean topCornersOnly,
|
||||
boolean bottomCornersOnly) {
|
||||
this(radius, margin);
|
||||
topCorners = topCornersOnly;
|
||||
bottomCorners = bottomCornersOnly;
|
||||
KEY = "rounded_" + radius + margin + topCorners + bottomCorners;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap transform(final Bitmap source) {
|
||||
final Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
if(topCorners && bottomCorners) {
|
||||
// Uses native method to draw symmetric rounded corners
|
||||
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin,
|
||||
source.getHeight() - margin), radius, radius, paint);
|
||||
} else {
|
||||
// Uses custom path to generate rounded corner individually
|
||||
canvas.drawPath(RoundedRect(margin, margin, source.getWidth() - margin,
|
||||
source.getHeight() - margin, radius, radius, topCorners, topCorners,
|
||||
bottomCorners, bottomCorners), paint);
|
||||
}
|
||||
|
||||
|
||||
if (source != output) {
|
||||
source.recycle();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "rounded_" + radius + margin;
|
||||
// return KEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares a path for rounded corner selectively.
|
||||
* Source taken from http://stackoverflow.com/a/35668889/6635889
|
||||
* @param leftX The X coordinate of the left side of the rectangle
|
||||
* @param topY The Y coordinate of the top of the rectangle
|
||||
* @param rightX The X coordinate of the right side of the rectangle
|
||||
* @param bottomY The Y coordinate of the bottom of the rectangle
|
||||
* @param rx The x-radius of the oval used to round the corners
|
||||
* @param ry The y-radius of the oval used to round the corners
|
||||
* @param topLeft
|
||||
* @param topRight
|
||||
* @param bottomRight
|
||||
* @param bottomLeft
|
||||
* @return
|
||||
*/
|
||||
public static Path RoundedRect(float leftX, float topY, float rightX, float bottomY, float rx,
|
||||
float ry, boolean topLeft, boolean topRight, boolean
|
||||
bottomRight, boolean bottomLeft) {
|
||||
Path path = new Path();
|
||||
if (rx < 0) rx = 0;
|
||||
if (ry < 0) ry = 0;
|
||||
float width = rightX - leftX;
|
||||
float height = bottomY - topY;
|
||||
if (rx > width / 2) rx = width / 2;
|
||||
if (ry > height / 2) ry = height / 2;
|
||||
float widthMinusCorners = (width - (2 * rx));
|
||||
float heightMinusCorners = (height - (2 * ry));
|
||||
|
||||
path.moveTo(rightX, topY + ry);
|
||||
if (topRight)
|
||||
path.rQuadTo(0, -ry, -rx, -ry);//top-right corner
|
||||
else{
|
||||
path.rLineTo(0, -ry);
|
||||
path.rLineTo(-rx,0);
|
||||
}
|
||||
path.rLineTo(-widthMinusCorners, 0);
|
||||
if (topLeft)
|
||||
path.rQuadTo(-rx, 0, -rx, ry); //top-left corner
|
||||
else{
|
||||
path.rLineTo(-rx, 0);
|
||||
path.rLineTo(0,ry);
|
||||
}
|
||||
path.rLineTo(0, heightMinusCorners);
|
||||
|
||||
if (bottomLeft)
|
||||
path.rQuadTo(0, ry, rx, ry);//bottom-left corner
|
||||
else{
|
||||
path.rLineTo(0, ry);
|
||||
path.rLineTo(rx,0);
|
||||
}
|
||||
|
||||
path.rLineTo(widthMinusCorners, 0);
|
||||
if (bottomRight)
|
||||
path.rQuadTo(rx, 0, rx, -ry); //bottom-right corner
|
||||
else{
|
||||
path.rLineTo(rx,0);
|
||||
path.rLineTo(0, -ry);
|
||||
}
|
||||
|
||||
path.rLineTo(0, -heightMinusCorners);
|
||||
|
||||
path.close();//Given close, last lineto can be removed.
|
||||
|
||||
return path;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package at.smartshopper.smartshopper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
@ -11,6 +12,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.auth.FirebaseUser;
|
||||
import com.squareup.picasso.Picasso;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -33,13 +35,13 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
|
||||
public ShoppinglistViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
//inflating and returning our view holder
|
||||
LayoutInflater inflater = LayoutInflater.from(mCtx);
|
||||
View view = inflater.inflate(R.layout.cardview, null);
|
||||
View view = inflater.inflate(R.layout.cardview, parent, false);
|
||||
return new ShoppinglistViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ShoppinglistViewHolder holder, int position) {
|
||||
//getting the product of the specified position
|
||||
//getting the product of the specified position,
|
||||
Shoppinglist shoppinglist = this.shoppinglist.get(position);
|
||||
|
||||
//binding the data with the viewholder views
|
||||
@ -51,7 +53,9 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
|
||||
// Name, email address, and profile photo Url
|
||||
String name = user.getDisplayName();
|
||||
Uri photoUrl = user.getPhotoUrl();
|
||||
holder.imageView.setImageURI(photoUrl);
|
||||
holder.ownerName.setText(name);
|
||||
Picasso.get().load(photoUrl).resize(250, 250).transform(new RoundCornersTransformation(30, 30, true, true)).into(holder.imageView);
|
||||
// holder.imageView.setImageDrawable(Drawable.createFromPath("@drawable/common_google_signin_btn_icon_dark"));
|
||||
|
||||
// Check if user's email is verified
|
||||
|
||||
@ -73,7 +77,7 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
|
||||
|
||||
class ShoppinglistViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
TextView textViewTitle, textViewBeschreibung;
|
||||
TextView textViewTitle, textViewBeschreibung, ownerName;
|
||||
ImageView imageView;
|
||||
|
||||
public ShoppinglistViewHolder(View itemView) {
|
||||
@ -82,6 +86,7 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
|
||||
textViewTitle = itemView.findViewById(R.id.shoppinglistName);
|
||||
textViewBeschreibung = itemView.findViewById(R.id.shoppinglistBeschreibung);
|
||||
imageView = itemView.findViewById(R.id.shoppinglistOwner);
|
||||
ownerName = itemView.findViewById(R.id.ownerName);
|
||||
}
|
||||
}
|
||||
}
|
@ -46,21 +46,18 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Logout" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
<android.support.v4.widget.SwipeRefreshLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/ownSwipe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Eigene Einkaufslisten"
|
||||
android:textAlignment="center"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/ownrecycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/ownrecycler"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</android.support.v4.widget.SwipeRefreshLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -84,14 +81,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Logout" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Geteilte Einkaufslisten"
|
||||
android:textAlignment="center"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/sharedrecycler"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -16,8 +16,10 @@
|
||||
android:id="@+id/shoppinglistOwner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:scaleType="centerCrop"
|
||||
card_view:layout_constraintStart_toStartOf="parent"
|
||||
card_view:layout_constraintTop_toTopOf="parent"
|
||||
tools:srcCompat="@drawable/common_google_signin_btn_icon_dark" />
|
||||
|
||||
<TextView
|
||||
@ -31,7 +33,7 @@
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold"
|
||||
card_view:layout_constraintEnd_toEndOf="parent"
|
||||
card_view:layout_constraintStart_toStartOf="parent"
|
||||
card_view:layout_constraintStart_toEndOf="@+id/shoppinglistOwner"
|
||||
card_view:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
@ -41,11 +43,24 @@
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="Beschreibung"
|
||||
card_view:layout_constraintBottom_toBottomOf="parent"
|
||||
card_view:layout_constraintEnd_toEndOf="parent"
|
||||
card_view:layout_constraintHorizontal_bias="0.498"
|
||||
card_view:layout_constraintStart_toStartOf="parent"
|
||||
card_view:layout_constraintStart_toEndOf="@+id/shoppinglistOwner"
|
||||
card_view:layout_constraintTop_toBottomOf="@+id/shoppinglistName" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ownerName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:text="OwnerName"
|
||||
android:textSize="10sp"
|
||||
card_view:layout_constraintBottom_toBottomOf="parent"
|
||||
card_view:layout_constraintStart_toStartOf="parent"
|
||||
card_view:layout_constraintTop_toBottomOf="@+id/shoppinglistOwner" />
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
Loading…
x
Reference in New Issue
Block a user