From 071f6b9be2ba58323a259ea82d42c98676344f97 Mon Sep 17 00:00:00 2001 From: Georg Reisinger <43533139+GeorgReisinger@users.noreply.github.com> Date: Sat, 26 Jan 2019 19:05:08 +0100 Subject: [PATCH] Refresh List, Gui Refresch List by swipe Gui update User image User Image round Full width CardView --- .idea/vcs.xml | 6 + app/build.gradle | 2 + .../at/smartshopper/smartshopper/Dash.java | 85 ++++++++-- .../RoundCornersTransformation.java | 152 ++++++++++++++++++ .../smartshopper/ShoppinglistAdapter.java | 13 +- app/src/main/res/layout/activity_dash.xml | 29 ++-- app/src/main/res/layout/cardview.xml | 25 ++- 7 files changed, 272 insertions(+), 40 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/at/smartshopper/smartshopper/RoundCornersTransformation.java diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 36809f3..d22dc95 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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' } diff --git a/app/src/main/java/at/smartshopper/smartshopper/Dash.java b/app/src/main/java/at/smartshopper/smartshopper/Dash.java index 1c1e85c..9477ce9 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/Dash.java +++ b/app/src/main/java/at/smartshopper/smartshopper/Dash.java @@ -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 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 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 diff --git a/app/src/main/java/at/smartshopper/smartshopper/RoundCornersTransformation.java b/app/src/main/java/at/smartshopper/smartshopper/RoundCornersTransformation.java new file mode 100644 index 0000000..5ef900f --- /dev/null +++ b/app/src/main/java/at/smartshopper/smartshopper/RoundCornersTransformation.java @@ -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; + } +} diff --git a/app/src/main/java/at/smartshopper/smartshopper/ShoppinglistAdapter.java b/app/src/main/java/at/smartshopper/smartshopper/ShoppinglistAdapter.java index 7abab11..a26915b 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/ShoppinglistAdapter.java +++ b/app/src/main/java/at/smartshopper/smartshopper/ShoppinglistAdapter.java @@ -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 - - - + android:layout_height="match_parent"> + + @@ -84,14 +81,6 @@ android:layout_height="wrap_content" android:text="Logout" /> - - + + \ No newline at end of file