Skip to content

Commit

Permalink
New Improvements
Browse files Browse the repository at this point in the history
- Users Orders Can be accepted and rejected now.
  • Loading branch information
Iltwats committed Dec 4, 2020
1 parent 8b80e88 commit 5494cd7
Show file tree
Hide file tree
Showing 21 changed files with 813 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id 'com.android.application'
id 'com.google.gms.google-services'
id 'com.google.firebase.crashlytics'
}

android {
Expand Down Expand Up @@ -39,10 +40,14 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation platform('com.google.firebase:firebase-bom:26.1.0')
implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation("com.squareup.okhttp3:okhttp:4.9.0")

}
37 changes: 34 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,53 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


<application
android:allowBackup="true"
android:name=".MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ECommerce">
<activity android:name=".MainActivity">
<activity android:name=".NotificationActivity"
android:label="Notification Manager"
android:parentActivityName=".CatalogActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CatalogActivity" />
</activity>
<activity android:name=".OrderActivity"
android:label="All Orders"
android:parentActivityName=".CatalogActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CatalogActivity" />
</activity>

<activity android:name=".CatalogActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<service
android:name=".fcm.AdminFCM"
android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>

<activity
android:name=".MainActivity"
android:label="Edit Product"
android:parentActivityName=".CatalogActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".CatalogActivity" />
</activity>
</application>

</manifest>
52 changes: 52 additions & 0 deletions app/src/main/java/com/atul/android/ecommerce/CatalogActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.atul.android.ecommerce;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.atul.android.ecommerce.databinding.ActivityCatalogBinding;

public class CatalogActivity extends AppCompatActivity {

private ActivityCatalogBinding bind;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
bind = ActivityCatalogBinding.inflate(getLayoutInflater());
setContentView(bind.getRoot());

userActivity();
}

private void userActivity() {
bind.editProducts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(CatalogActivity.this,"Clicked Edit Products",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(CatalogActivity.this,MainActivity.class);
startActivity(intent);
}
});
bind.orders.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(CatalogActivity.this,"Clicked Orders",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(CatalogActivity.this,OrderActivity.class);
startActivity(intent);
}
});
bind.notifyUsers.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(CatalogActivity.this,"Clicked Notify Users",Toast.LENGTH_SHORT).show();
Intent intent = new Intent(CatalogActivity.this,NotificationActivity.class);
startActivity(intent);
}
});
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,9 @@
public class Constants {
public static final String INVENTORY = "inventory";
public static final String PRODUCTS = "products";
public static final String ORDERS = "Orders";
public static final String DETAILS = "Order Info";
public static final String ADMIN = "admin";
public static final String USER = "users";
public static final String ORDER_TIME = "orderTime";
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.messaging.FirebaseMessaging;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

Expand Down Expand Up @@ -58,6 +59,7 @@ protected void onCreate(Bundle savedInstanceState) {
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

FirebaseMessaging.getInstance().subscribeToTopic(Constants.ADMIN);
sharedPreferences = getSharedPreferences(sharedPreferencesFile, MODE_PRIVATE);
gson = new Gson();
setup();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.atul.android.ecommerce;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.atul.android.ecommerce.databinding.ActivityNotificationBinding;

public class NotificationActivity extends AppCompatActivity {

private ActivityNotificationBinding notifyb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
notifyb = ActivityNotificationBinding.inflate(getLayoutInflater());
setContentView(notifyb.getRoot());
}
}
81 changes: 81 additions & 0 deletions app/src/main/java/com/atul/android/ecommerce/OrderActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.atul.android.ecommerce;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.atul.android.ecommerce.Constants.Constants;
import com.atul.android.ecommerce.adapter.OrdersAdapter;
import com.atul.android.ecommerce.databinding.ActivityOrderBinding;
import com.atul.android.ecommerce.fcm.FCMSender;
import com.atul.android.ecommerce.fcm.MessageFormatter;
import com.atul.android.ecommerce.model.Order;
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.firestore.Query;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.firestore.SetOptions;

import org.jetbrains.annotations.NotNull;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

public class OrderActivity extends AppCompatActivity {

private ActivityOrderBinding orderBinding;
private MyApp myApp;
OrdersAdapter ordersAdapter;
List<Order> orderList = new ArrayList<>();
ArrayList<String> orderIDs=new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
orderBinding = ActivityOrderBinding.inflate(getLayoutInflater());
setContentView(orderBinding.getRoot());

myApp = (MyApp) getApplicationContext();
fetchAllOrdersFromDB();
}

private void fetchAllOrdersFromDB() {
myApp.db.collection(Constants.ORDERS)
.orderBy(Constants.ORDER_TIME, Query.Direction.DESCENDING)
.get()
.addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
for (QueryDocumentSnapshot snapshot : task.getResult()) {
Order order = snapshot.toObject(Order.class);
orderList.add(order);
orderIDs.add(snapshot.getId());
}
setupAdapter();
}
});
}

private void setupAdapter() {
ordersAdapter = new OrdersAdapter(OrderActivity.this, orderList,myApp,orderIDs);
orderBinding.allOrders.setAdapter(ordersAdapter);
orderBinding.allOrders.setLayoutManager(new LinearLayoutManager(OrderActivity.this));
orderBinding.allOrders.addItemDecoration(
new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)
);

}

}
Loading

0 comments on commit 5494cd7

Please sign in to comment.