diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3d3910e..3666b54 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,9 +12,10 @@ android:supportsRtl="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true"> + + android:label="@string/title_activity_item_list" /> @@ -41,7 +42,9 @@ - + diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java index 04ec27a..7ce5da1 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/Dash.java @@ -9,6 +9,7 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Handler; +import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.design.widget.TabLayout; @@ -34,8 +35,12 @@ import android.widget.TabHost; import android.widget.TextView; import android.widget.Toast; +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.iid.FirebaseInstanceId; +import com.google.firebase.iid.InstanceIdResult; import com.google.gson.JsonSerializer; import com.squareup.picasso.Picasso; @@ -85,6 +90,40 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte } + /** + * Holt den msg token + * + * SETZT IHN NOCH NED + * + * + * WEITER PROGRAMMIERN + * + * MIR FEHLT NOCH DIE DB VON LUKAS + */ + private void setMsgId(){ + FirebaseInstanceId.getInstance().getInstanceId() + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (!task.isSuccessful()) { + Log.w("SmartShopper", "getInstanceId failed", task.getException()); + return; + } + + // Get new Instance ID token + String token = task.getResult().getToken(); + Log.d("SmartShopper MSG", token); + + /* Log and toast + String msg = getString(R.string.msg_token_fmt, token); + Log.d(TAG, msg); + Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show(); + + */ + } + }); + } + /** * Convertiert eine int farbe in eine hexa dezimale Farbe * @@ -103,6 +142,7 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte color = "ffffff"; + setMsgId(); // Erstellt die Tabs tabHoster(); @@ -429,6 +469,10 @@ public class Dash extends AppCompatActivity implements ShoppinglistAdapter.OnIte case R.id.addInvite: popupaddInvite(); + case R.id.doneEinkauf: + Intent intent = new Intent(Dash.this, DoneItemActivity.class); + startActivity(intent); + default: // If we got here, the user's action was not recognized. // Invoke the superclass to handle it. diff --git a/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java b/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java new file mode 100644 index 0000000..9b700a7 --- /dev/null +++ b/app/src/main/java/at/smartshopper/smartshopper/activitys/DoneItemActivity.java @@ -0,0 +1,74 @@ +package at.smartshopper.smartshopper.activitys; + +import android.support.v4.widget.SwipeRefreshLayout; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +import org.json.JSONException; + +import java.sql.SQLException; +import java.util.List; + +import at.smartshopper.smartshopper.R; +import at.smartshopper.smartshopper.customViews.SpaceItemDecoration; +import at.smartshopper.smartshopper.db.Database; +import at.smartshopper.smartshopper.shoppinglist.Shoppinglist; +import at.smartshopper.smartshopper.shoppinglist.ShoppinglistSharedAdapter; +import at.smartshopper.smartshopper.shoppinglist.details.item.Item; +import at.smartshopper.smartshopper.shoppinglist.details.item.ItemShoppinglistDetailsAdapter; + +public class DoneItemActivity extends AppCompatActivity { + + private Database db; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_done_item); + + db = new Database(); + + final SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.doneItemListRefresh); + + swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { + @Override + public void onRefresh() { + swipeRefreshLayout.setRefreshing(true); + try { + showDoneItems(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + swipeRefreshLayout.setRefreshing(false); + } + }); + + try { + showDoneItems(); + } catch (SQLException e) { + e.printStackTrace(); + } catch (JSONException e) { + e.printStackTrace(); + } + } + + /** + * Zeigt alle erledigten Items an + * @throws SQLException + * @throws JSONException + */ + private void showDoneItems() throws SQLException, JSONException { + RecyclerView doneRecycle = (RecyclerView) findViewById(R.id.doneitemsrecycle); + doneRecycle.setHasFixedSize(true); + int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.item_spacing); + doneRecycle.addItemDecoration(new SpaceItemDecoration(spacingInPixels)); + doneRecycle.setLayoutManager(new LinearLayoutManager(this)); + List doneItems = db.getDoneItems(); + ItemShoppinglistDetailsAdapter islAdapter = new ItemShoppinglistDetailsAdapter(doneItems); + doneRecycle.setAdapter(islAdapter); + } +} diff --git a/app/src/main/java/at/smartshopper/smartshopper/messaging/MyFirebaseMessagingService.java b/app/src/main/java/at/smartshopper/smartshopper/messaging/MyFirebaseMessagingService.java index e4f00b5..e6cb332 100644 --- a/app/src/main/java/at/smartshopper/smartshopper/messaging/MyFirebaseMessagingService.java +++ b/app/src/main/java/at/smartshopper/smartshopper/messaging/MyFirebaseMessagingService.java @@ -24,49 +24,10 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService { * * @param remoteMessage Object representing the message received from Firebase Cloud Messaging. */ - // [START receive_message] @Override public void onMessageReceived(RemoteMessage remoteMessage) { - // [START_EXCLUDE] - // There are two types of messages data messages and notification messages. Data messages - // are handled - // here in onMessageReceived whether the app is in the foreground or background. Data - // messages are the type - // traditionally used with GCM. Notification messages are only received here in - // onMessageReceived when the app - // is in the foreground. When the app is in the background an automatically generated - // notification is displayed. - // When the user taps on the notification they are returned to the app. Messages - // containing both notification - // and data payloads are treated as notification messages. The Firebase console always - // sends notification - // messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options - // [END_EXCLUDE] - - // TODO(developer): Handle FCM messages here. - // Not getting messages here? See why this may be: https://goo.gl/39bRNJ - Log.d(TAG, "From: " + remoteMessage.getFrom()); - - // Check if message contains a data payload. - if (remoteMessage.getData().size() > 0) { - Log.d(TAG, "Message data payload: " + remoteMessage.getData()); - sendNotification(remoteMessage.getData() + ""); - - } - - // Check if message contains a notification payload. - if (remoteMessage.getNotification() != null) { - Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody()); - sendNotification(remoteMessage.getNotification().getBody()); - } - - // Also if you intend on generating your own notifications as a result of a received FCM - // message, here is where that should be initiated. See sendNotification method below. + super.onMessageReceived(remoteMessage); } - // [END receive_message] - - - // [START on_new_token] /** * Called if InstanceID token is updated. This may occur if the security of diff --git a/app/src/main/res/layout/activity_done_item.xml b/app/src/main/res/layout/activity_done_item.xml new file mode 100644 index 0000000..b39f2dc --- /dev/null +++ b/app/src/main/res/layout/activity_done_item.xml @@ -0,0 +1,36 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/dash_menu.xml b/app/src/main/res/menu/dash_menu.xml index df283ff..d92888b 100644 --- a/app/src/main/res/menu/dash_menu.xml +++ b/app/src/main/res/menu/dash_menu.xml @@ -4,6 +4,9 @@ +