Shoppinglist CRUD Funktionen

Shoppinglisten Hinzufügen, Bearbeiten und Löschen
Shoppinglisten zeigen jetzt Farben an
This commit is contained in:
Georg Reisinger 2019-01-28 20:03:58 +01:00
parent c3e20bdf95
commit a3ea7191ef
21 changed files with 1056 additions and 86 deletions

View File

@ -16,10 +16,36 @@
<entry key="actionbar">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipArt">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="color" value="000000" />
</map>
</option>
</PersistentState>
</value>
</entry>
<entry key="image">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="color" value="000000" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="assetType" value="IMAGE" />
<entry key="imageAsset" value="C:\Users\georg\Downloads\2x\baseline_add_circle_outline_black_18dp.png" />
<entry key="imageAsset" value="C:\Users\georg\Downloads\close.png" />
<entry key="outputName" value="logo" />
<entry key="theme" value="CUSTOM" />
<entry key="themeColor" value="000000" />
@ -50,12 +76,62 @@
<map>
<entry key="backgroundAssetType" value="COLOR" />
<entry key="backgroundColor" value="353535" />
<entry key="foregroundImage" value="G:\Teamablagen\SmartShopper\Design\Logo\logo.png" />
<entry key="backgroundLayerName" value="ic_launcher_background" />
<entry key="foregroundImage" value="C:\Users\georg\Downloads\close.png" />
<entry key="foregroundLayerName" value="ic_launcher_foreground" />
<entry key="outputName" value="close" />
</map>
</option>
</PersistentState>
</value>
</entry>
<entry key="launcherLegacy">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipArt">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="color" value="000000" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
<entry key="notification">
<value>
<PersistentState>
<option name="children">
<map>
<entry key="clipArt">
<value>
<PersistentState>
<option name="values">
<map>
<entry key="color" value="000000" />
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
</PersistentState>
</value>
</entry>
</map>
</option>
<option name="values">
<map>
<entry key="outputIconType" value="ACTIONBAR" />
</map>
</option>
</PersistentState>

BIN
.idea/caches/gradle_models.ser generated Normal file

Binary file not shown.

3
.idea/gradle.xml generated
View File

@ -3,6 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">

10
.idea/misc.xml generated
View File

@ -5,7 +5,7 @@
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="7">
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
@ -13,18 +13,24 @@
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="6">
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>

View File

@ -29,6 +29,7 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
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.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'
@ -36,4 +37,6 @@ dependencies {
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'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.github.danielnilsson9:color-picker-view:1.4.0@aar'
}

View File

@ -12,6 +12,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<activity android:name=".activitys.Colorpicker"></activity>
<activity android:name=".activitys.LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -36,17 +37,15 @@
-->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
<!-- [START firebase_service] -->
android:resource="@color/colorAccent" /> <!-- [START firebase_service] -->
<service android:name=".messaging.MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<!-- [END firebase_service] -->
</service> <!-- [END firebase_service] -->
<activity
android:name=".activitys.ShoppinglistDetails"
android:label="@string/title_activity_shoppinglist_details"></activity>
android:label="@string/title_activity_shoppinglist_details" />
</application>
</manifest>

View File

@ -0,0 +1,102 @@
package at.smartshopper.smartshopper.activitys;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import com.github.danielnilsson9.colorpickerview.view.ColorPanelView;
import com.github.danielnilsson9.colorpickerview.view.ColorPickerView;
import at.smartshopper.smartshopper.R;
public class Colorpicker extends AppCompatActivity {
private ColorPickerView mColorPickerView;
private ColorPanelView mOldColorPanelView;
private ColorPanelView mNewColorPanelView;
private Button mOkButton;
private Button mCancelButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_colorpicker);
init();
}
private void init() {
mColorPickerView = (ColorPickerView) findViewById(R.id.colorpickerview__color_picker_view);
mOldColorPanelView = (ColorPanelView) findViewById(R.id.colorpickerview__color_panel_old);
mNewColorPanelView = (ColorPanelView) findViewById(R.id.colorpickerview__color_panel_new);
mOkButton = (Button) findViewById(R.id.okButton);
mCancelButton = (Button) findViewById(R.id.cancelButton);
((LinearLayout) mOldColorPanelView.getParent()).setPadding(
mColorPickerView.getPaddingLeft(), 0,
mColorPickerView.getPaddingRight(), 0);
mColorPickerView.setOnColorChangedListener(new ColorPickerView.OnColorChangedListener() {
@Override
public void onColorChanged(int newColor) {
mNewColorPanelView.setColor(mColorPickerView.getColor());
}
});
mColorPickerView.setColor(Color.parseColor("#FFFFFF"), true);
mOldColorPanelView.setColor(Color.parseColor("#FFFFFF"));
mOkButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
exitResult(mColorPickerView.getColor() + "");
}
});
mCancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
exitResult(null);
}
});
}
/**
* Bendet den Colorpicker und sendet an die vorherige activity einen STring
*
* @param result String der an die Aufrufactivity zurückgesendet werden soll. Wenn null dann wird nichts gesendet
*/
private void exitResult(String result) {
if (result == null) {
finish();
} else {
Intent data = new Intent();
//---set the data to pass back---
data.setData(Uri.parse(result));
setResult(RESULT_OK, data);
//---close the activity---
finish();
}
}
/**
* Wenn zurück geklickt wird, wird das Program ohne result geschlosen
*/
@Override
public void onBackPressed() {
exitResult(mColorPickerView.getColor() + "");
}
}

View File

@ -1,44 +1,90 @@
package at.smartshopper.smartshopper.activitys;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
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.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import at.smartshopper.smartshopper.R;
import android.widget.PopupWindow;
import android.widget.TabHost;
import android.widget.Toast;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.squareup.picasso.Picasso;
import org.json.JSONException;
import java.sql.SQLException;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.db.Database;
import at.smartshopper.smartshopper.shoppinglist.Shoppinglist;
import at.smartshopper.smartshopper.shoppinglist.ShoppinglistAdapter;
public class Dash extends AppCompatActivity {
public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnItemClicked, ShoppinglistAdapter.OnChangeItemClick {
private Database db = new Database();
private SwipeRefreshLayout ownswiperefresh;
private FloatingActionButton addShoppinglistFab;
private PopupWindow popupWindowAdd;
private String color;
private Button colorBtn;
/**
* Setzt das atribut color wenn die activity colorpicker beendet wird
*
* @param requestCode
* @param resultCode
* @param data
*/
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
int color = Integer.parseInt(data.getData().toString());
this.color = colorToHexString(color);
colorBtn.setBackgroundColor(Color.parseColor(this.color));
}
}
}
/**
* Convertiert eine int farbe in eine hexa dezimale Farbe
*
* @param color Farbe zum umwandeln in int
* @return farbe als hex im string
*/
private static String colorToHexString(int color) {
return String.format("#%06X", 0xFFFFFFFF & color);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dash);
color = "ffffff";
// Erstellt die Tabs
@ -88,10 +134,131 @@ public class Dash extends AppCompatActivity {
}
});
addShoppinglistFab = (FloatingActionButton) findViewById(R.id.addShoppinglistFab);
addShoppinglistFab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
showShoppinglistEditView(false, null, v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
}
/**
* Zeigt ein Popup das zum Bearbeiten/Erstellen einer Shoppingliste dient.
* Wenn eine Shoppingliste bearbeitet werden soll, muss fromDB true sein und sl_id mit einer id gefüllt
* Wenn erstellt werden soll muss fromDB false sein und sl_id null
*
* @param fromDB True wenn daten von der DB kommen sollen, wenn false dann muss die sl_id null sein
* @param sl_id Muss nur eine sl_id drinnen sein wenn fromDB true ist
* @param v der View auf dem das Popup sein soll
*/
private void showShoppinglistEditView(final boolean fromDB, String sl_id, View v) throws SQLException, JSONException {
final LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final String username = FirebaseAuth.getInstance().getCurrentUser().getUid();
View customView = inflater.inflate(R.layout.add_shoppinglist_dialog, null);
ImageButton addClose = (ImageButton) customView.findViewById(R.id.addClose);
colorBtn = (Button) customView.findViewById(R.id.addColor);
Button addFertig = (Button) customView.findViewById(R.id.addFertig);
final EditText name = (EditText) customView.findViewById(R.id.addName);
final EditText description = (EditText) customView.findViewById(R.id.addDescription);
Picasso.get().load(R.drawable.close).into(addClose);
if (fromDB) {
Shoppinglist dbShoppinglist = db.getShoppinglist(sl_id);
String colorstring;
if(dbShoppinglist.getcolor().contains("#")){
colorstring = dbShoppinglist.getcolor();
}else{
colorstring = "#" + dbShoppinglist.getcolor();
}
colorBtn.setBackgroundColor(Color.parseColor(colorstring));
name.setText(dbShoppinglist.getname());
description.setText(dbShoppinglist.getdescription());
} else {
color = "ffffff";
}
final String sl_idString = sl_id;
addFertig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(fromDB){
try {
db.editShoppinglist(sl_idString, name.getText().toString(), description.getText().toString(), color);
color = "ffffff";
popupWindowAdd.dismiss();
showOwnShoppingList(username);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}else {
try {
db.addShoppinglist(name.getText().toString(), description.getText().toString(), username, color);
color = "ffffff";
popupWindowAdd.dismiss();
showOwnShoppingList(username);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
colorBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Dash.this, Colorpicker.class);
startActivityForResult(intent, 1);
}
});
addClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindowAdd.dismiss();
}
});
popupWindowAdd = new PopupWindow(customView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
// Set an elevation value for popup window
// Call requires API level 21
if (Build.VERSION.SDK_INT >= 21) {
popupWindowAdd.setElevation(5.0f);
}
popupWindowAdd.setOutsideTouchable(false);
popupWindowAdd.setFocusable(true);
popupWindowAdd.showAtLocation(v, Gravity.CENTER, 0, 0);
popupWindowAdd.update();
}
/**
* Logt den User aus und geht zur Login Activity
*/
@ -139,7 +306,10 @@ public class Dash extends AppCompatActivity {
ownRecycleView.setLayoutManager(new LinearLayoutManager(this));
List<Shoppinglist> ownListsList = db.getMyShoppinglists(uid);
ShoppinglistAdapter shpAdapter = new ShoppinglistAdapter(Dash.this, ownListsList);
shpAdapter.setOnDelClick(Dash.this);
shpAdapter.setOnChangeClick(Dash.this);
ownRecycleView.setAdapter(shpAdapter);
}
/**
@ -184,6 +354,7 @@ public class Dash extends AppCompatActivity {
/**
* Menu item Action listener
*
* @param item Action Item
* @return True wenn erfolgreich
*/
@ -230,4 +401,36 @@ public class Dash extends AppCompatActivity {
}, 2000);
}
/**
* Das ist der Onclick für die einzelnen shoppinglists. Löscht eine shoppinglist und refreshed alle anderen
*
* @param sl_id Die Shoppingliste dieser Id wird gelöscht
*/
@Override
public void onItemClick(String sl_id) {
try {
db.delShoppinglist(sl_id);
showOwnShoppingList(FirebaseAuth.getInstance().getCurrentUser().getUid());
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* Das ist der oncklick für eine einzelen Shoppinglist. Bearbeitet eine Shoppinglist
*
* @param sl_id Die Shoppinglist die bearbeitet werden soll
*/
@Override
public void onChangeItemClick(String sl_id, View v) {
try {
showShoppinglistEditView(true, sl_id, v);
} catch (SQLException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
}

View File

@ -50,6 +50,116 @@ public class Database {
System.out.println("Database connected!");
}
/**
* Löscht eine Shoppingliste aus der Tabelle:
* Shoppinglist / - member / -admin
*
* @param sl_id Shoppinglist Id welche gelöscht werden soll
* @throws SQLException
*/
public void delShoppinglist(String sl_id) throws SQLException {
sqlUpdate("DELETE FROM \"Shoppinglist_admin\" WHERE sl_id = ?", sl_id);
sqlUpdate("DELETE FROM \"Shoppinglist_member\" WHERE sl_id = ?", sl_id);
sqlUpdate("DELETE FROM \"Shoppinglist\" WHERE sl_id = ?", sl_id);
}
/**
* Erstellt eine neue Shoppingliste mit den dazugehörigen Usern
*
* @param name Name der Shoppingliste
* @param description Beschreibung der Shoppingliste
* @param username Username des erstellers der Shoppingliste
* @param color Farbe der Shoppingliste
* @throws SQLException
*/
public void addShoppinglist(String name, String description, String username, String color) throws SQLException {
String sl_id = generateSL_Id();
if (!checkIfUserExists(username)) {
createUser(username);
}
createShoppinglist(sl_id, name, description, color);
createAdmin(sl_id, username);
}
/**
* Erstellt einen neuen Admin in der Tabelle Shoppinglist_admin
*
* @param sl_id Die Shopppinglist Id
* @param username Der username des Admins
* @throws SQLException
*/
private void createAdmin(String sl_id, String username) throws SQLException {
String SQL = "INSERT INTO \"Shoppinglist_admin\" (username, sl_id) VALUES (?, ?)";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, username);
pstmt.setString(2, sl_id);
pstmt.executeUpdate();
}
/**
* Erstellt einen neue Shoppingliste in der Tabelle Shoppinglist
*
* @param sl_id Shopppinglist Id
* @param name Shoppinglist name
* @param description Shoppinglist beschriebung
* @param color Shoppinglist Farbe
* @throws SQLException
*/
private void createShoppinglist(String sl_id, String name, String description, String color) throws SQLException {
String SQL = "INSERT INTO \"Shoppinglist\" (sl_id, name, description, color) VALUES (?, ?, ?, ?)";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, sl_id);
pstmt.setString(2, name);
pstmt.setString(3, description);
pstmt.setString(4, color);
pstmt.executeUpdate();
}
/**
* Erstellt einen neuen User, wenn keiner existiert
*
* @param username Der Username des neuen Users
* @throws SQLException
*/
private void createUser(String username) throws SQLException {
String SQL = "INSERT INTO \"User\" (username) VALUES (?)";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, username);
pstmt.executeUpdate();
}
/**
* Prüft ob ein User bereits in der DB vorhanden ist. Wenn ja dann wird true returned
*
* @param username Der username nach dem geprüft werden soll
* @return True wenn User existiert, False wenn nicht
* @throws SQLException
*/
private boolean checkIfUserExists(String username) throws SQLException {
String SQL = "SELECT username FROM \"User\"";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
ResultSet rs = pstmt.executeQuery();
ArrayList<String> outUserList = new ArrayList<String>();
while (rs.next()) {
outUserList.add(rs.getString(1));
}
if (outUserList.contains(username)) {
return true;
} else {
return false;
}
}
/**
* Verbindet sich mit dem Server
* Holt die eigenen Shoppinglisten vom Server. Und speichert diese in eine List mit Shoppinglist Objekten
@ -94,6 +204,7 @@ public class Database {
/**
* Hoolt alle groups und items der list und erstelt ein Detail objekt von jeder group. Die detail objekte kommen in eine List
*
* @param sl_id Shoppinglist Id mit der gearbeitet wird
* @return Eine List mit Details über jede Shoppinglist
* @throws SQLException
@ -121,6 +232,24 @@ public class Database {
}
/**
* Generiert eine neue 8 stellige sl_id
*
* @return Neue Sl_id
*/
private String generateSL_Id() {
String possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
String output = "";
for (int i = 0; i < 8; i++) {
output += possible.charAt((int) Math.floor(Math.random() * possible.length()));
}
System.out.println("Generate SL_ID: " + output);
return output;
}
/**
* Holt alle Items einer bestimmten shoppingliste, angegeben durch die shoppinglist id
*
@ -191,6 +320,84 @@ public class Database {
}
/**
* Bearbeitet die Eigenschaften einer Shoppingliste
* @param sl_id Shoppinglist Id welche zu bearbeiten ist
* @param newname Neuer Shoppinglistname
* @param newdescription Neue Shoppinglist Beschreibung
* @param newColor Neue Shoppinglist Farbe
* @throws SQLException
* @throws JSONException
*/
public void editShoppinglist(String sl_id, String newname, String newdescription, String newColor) throws SQLException, JSONException {
Shoppinglist oldShoppinglist = getShoppinglist(sl_id);
if(!oldShoppinglist.getname().equals(newname) && newname != null){
sqlUpdate2Param("UPDATE \"Shoppinglist\" SET name = ? WHERE sl_id = ?", newname, sl_id);
}
if(!oldShoppinglist.getdescription().equals(newdescription) && newdescription != null){
sqlUpdate2Param("UPDATE \"Shoppinglist\" SET description = ? WHERE sl_id = ?", newdescription, sl_id);
}
if(!oldShoppinglist.getcolor().equals(newColor) && newColor != null){
sqlUpdate2Param("UPDATE \"Shoppinglist\" SET color = ? WHERE sl_id = ?", newColor, sl_id);
}
}
/**
* Führt einen SQL Befehl durch der keine rückgabe hat.
*
* @param SQL Der SQL befehl
* @param param ein Parameter
* @param param2 ein 2. Parameter
* @throws SQLException
*/
private void sqlUpdate2Param(String SQL, String param, String param2) throws SQLException {
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.setString(2, param2);
pstmt.executeUpdate();
}
/**
* Führt einen SQL Befehl durch der keine rückgabe hat.
*
* @param SQL Der SQL befehl
* @param param ein Parameter
* @throws SQLException
*/
private void sqlUpdate(String SQL, String param) throws SQLException {
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, param);
pstmt.executeUpdate();
}
/**
* Hollt eine Shoppingliste vom server
* @param sl_id Shoppingliste welche heruntergelanden werden soll
* @return Ein Shoppinglist Objekt
* @throws SQLException
* @throws JSONException
*/
public Shoppinglist getShoppinglist(String sl_id) throws SQLException, JSONException {
String SQL = "SELECT row_to_json(\"Shoppinglist\") AS obj FROM \"Shoppinglist\" JOIN \"Shoppinglist_admin\" USING (sl_id) WHERE sl_id = ?";
connectDatabase();
PreparedStatement pstmt = conect.prepareStatement(SQL);
System.out.println(sl_id);
pstmt.setString(1, sl_id);
ResultSet rs = pstmt.executeQuery();
rs.next();
String resultString = rs.getString(1);
JSONObject jsonObject = new JSONObject(resultString);
return new Shoppinglist(sl_id, jsonObject.getString("name"), jsonObject.getString("description"), jsonObject.getString("invitelink"), jsonObject.getString("color"));
}
/**
* NICHT VERWENDEN FUNKTIONIERT NICHT!!
* <p>
@ -206,19 +413,15 @@ public class Database {
private ResultSet databaseRequest(String SQL, String uid) throws SQLException {
connectDatabase();
ResultSet rs = null;
try (PreparedStatement pstmt = conect.prepareStatement(SQL)) {
PreparedStatement pstmt = conect.prepareStatement(SQL);
pstmt.setString(1, uid);
rs = pstmt.executeQuery();
ResultSet rs = pstmt.executeQuery();
System.out.println(uid);
//HIER
//WEITER
//PROGRAMMIEREN
} catch (SQLException ex) {
System.out.println(ex.getMessage());
}
return rs;
}
}

View File

@ -2,12 +2,16 @@ package at.smartshopper.smartshopper.shoppinglist;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
@ -15,14 +19,19 @@ import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.squareup.picasso.Picasso;
import java.sql.SQLException;
import java.util.List;
import at.smartshopper.smartshopper.R;
import at.smartshopper.smartshopper.activitys.ShoppinglistDetails;
import at.smartshopper.smartshopper.customViews.RoundCornersTransformation;
import at.smartshopper.smartshopper.db.Database;
public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapter.ShoppinglistViewHolder> {
private OnChangeItemClick onChangeClick;
private OnItemClicked onClick;
private at.smartshopper.smartshopper.db.Database db;
//this context we will use to inflate the layout
private Context mCtx;
@ -38,6 +47,7 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
/**
* Erstellt einen Neuen view holder mit aktueller view
*
* @param parent
* @param viewType
* @return
@ -52,18 +62,46 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
/**
* Setzt alle Daten in die View elemente
*
* @param holder Das View Holder Objekt mit allen elementen
* @param position Der Index welcher aus der data list genommen werden soll
*/
@Override
public void onBindViewHolder(ShoppinglistViewHolder holder, int position) {
public void onBindViewHolder(ShoppinglistViewHolder holder, final int position) {
//getting the product of the specified position,
Shoppinglist shoppinglist = this.shoppinglist.get(position);
final Shoppinglist shoppinglist = this.shoppinglist.get(position);
db = new Database();
//binding the data with the viewholder views
holder.textViewTitle.setText(shoppinglist.getname());
System.out.println(shoppinglist.getname());
holder.textViewBeschreibung.setText(shoppinglist.getdescription());
holder.bearbeiten.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onChangeClick.onChangeItemClick(shoppinglist.getSlId(), v);
}
});
holder.del.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onClick.onItemClick(shoppinglist.getSlId());
}
});
int cardcolor;
try {
cardcolor = Color.parseColor(shoppinglist.getcolor());
} catch (Exception e) {
cardcolor = Color.parseColor("#FFFFFF");
}
holder.ownList.setCardBackgroundColor(cardcolor);
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
if (user != null) {
// Name, email address, and profile photo Url
@ -81,17 +119,49 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
}
}
/**
* Holt die anzahl der items in dem Adapter
* @return Anzahl der Items in dem Adapter
*/
@Override
public int getItemCount() {
return shoppinglist.size();
}
/**
* Interface damit onoclick in der dash activity ausgeführt werden kann
*/
public interface OnItemClicked {
void onItemClick(String sl_id);
}
/**
* Interface damit onoclick in der dash activity ausgeführt werden kann
*/
public interface OnChangeItemClick{
void onChangeItemClick(String sl_id, View v);
}
/**
* Setzt das OnChangeItemClick event
* @param onChangeClick Der Click event Listener
*/
public void setOnChangeClick(OnChangeItemClick onChangeClick){
this.onChangeClick = onChangeClick;
}
/**
* Setzt das OnItemClicked event
* @param onClick Der Click Listener
*/
public void setOnDelClick(OnItemClicked onClick)
{
this.onClick=onClick;
}
/**
* Haltet alle elemente. Durch ein Objekt von dem kann jedes Element welches hier drinnen angeführt ist verwendet werden
@ -100,6 +170,8 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
TextView textViewTitle, textViewBeschreibung, ownerName;
ImageView imageView;
CardView ownList;
ImageButton bearbeiten, del;
public ShoppinglistViewHolder(View itemView) {
super(itemView);
@ -108,6 +180,9 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
textViewBeschreibung = itemView.findViewById(R.id.shoppinglistBeschreibung);
imageView = itemView.findViewById(R.id.shoppinglistOwner);
ownerName = itemView.findViewById(R.id.ownerName);
ownList = itemView.findViewById(R.id.ownLists);
bearbeiten = itemView.findViewById(R.id.bearbeiteShoppinglist);
del = itemView.findViewById(R.id.deleteShoppinglist);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
@ -121,12 +196,10 @@ public class ShoppinglistAdapter extends RecyclerView.Adapter<ShoppinglistAdapte
v.getContext().startActivity(intent);
}
});
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 544 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 865 B

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:picker="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:padding="16dp" >
<com.github.danielnilsson9.colorpickerview.view.ColorPickerView
android:id="@id/colorpickerview__color_picker_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
picker:alphaChannelVisible="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignLeft="@id/colorpickerview__color_picker_view"
android:layout_alignRight="@id/colorpickerview__color_picker_view"
android:layout_below="@id/colorpickerview__color_picker_view"
android:layout_marginTop="16dp"
android:orientation="horizontal" >
<com.github.danielnilsson9.colorpickerview.view.ColorPanelView
android:id="@id/colorpickerview__color_panel_old"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center"
android:text="→"
android:textColor="#646464"
android:textSize="20sp" />
<com.github.danielnilsson9.colorpickerview.view.ColorPanelView
android:id="@id/colorpickerview__color_panel_new"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="0.5" />
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/buttonbar"
style="@android:style/ButtonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/okButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok" />
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/cancel" />
</LinearLayout>
</LinearLayout>

View File

@ -90,7 +90,7 @@
</TabHost>
<android.support.design.widget.FloatingActionButton
android:id="@+id/floatingActionButton4"
android:id="@+id/addShoppinglistFab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"

View File

@ -0,0 +1,153 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="true"
app:cardUseCompatPadding="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="vertical">
<ImageButton
android:id="@+id/addClose"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="@color/fui_transparent"
app:srcCompat="@drawable/close" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Shoppingliste Hinzufügen"
android:textAlignment="center"
android:textColor="@android:color/background_dark"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/nameTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Name:" />
<EditText
android:id="@+id/addName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="@+id/descriptionTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Beschreibung:" />
<EditText
android:id="@+id/addDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/addColor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Farbe auswählen" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<Button
android:id="@+id/addFertig"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fertig" />
</LinearLayout>
</TableRow>
</TableLayout>
</android.support.v7.widget.CardView>

View File

@ -8,20 +8,66 @@
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:orientation="vertical"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="@+id/guideline"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent">
<ImageView
android:id="@+id/shoppinglistOwner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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
android:id="@+id/ownerName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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" />
</LinearLayout>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
card_view:layout_constraintGuide_begin="96dp" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="@+id/guideline2"
card_view:layout_constraintStart_toStartOf="@+id/guideline"
card_view:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/shoppinglistName"
android:layout_width="wrap_content"
@ -49,19 +95,45 @@
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toEndOf="@+id/shoppinglistOwner"
card_view:layout_constraintTop_toBottomOf="@+id/shoppinglistName" />
</LinearLayout>
<TextView
android:id="@+id/ownerName"
<android.support.constraint.Guideline
android:id="@+id/guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginBottom="8dp"
android:text="OwnerName"
android:textSize="10sp"
android:orientation="vertical"
card_view:layout_constraintGuide_begin="343dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:gravity="right|top"
android:orientation="horizontal"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toBottomOf="@+id/shoppinglistOwner" />
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="@+id/guideline2"
card_view:layout_constraintTop_toTopOf="parent">
<ImageButton
android:id="@+id/bearbeiteShoppinglist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/fui_transparent"
card_view:srcCompat="@drawable/bearbeiten" />
<ImageButton
android:id="@+id/deleteShoppinglist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/fui_transparent"
card_view:srcCompat="@drawable/delete" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
</TableRow>
</android.support.v7.widget.CardView>

View File

@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,5 +1,6 @@
#Mon Jan 28 14:20:03 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip