finish android merge wiring
This commit is contained in:
@@ -179,4 +179,16 @@ public class NetworkModule {
|
|||||||
public static UserApi provideUserApi(Retrofit retrofit) {
|
public static UserApi provideUserApi(Retrofit retrofit) {
|
||||||
return retrofit.create(UserApi.class);
|
return retrofit.create(UserApi.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public static EmployeeApi provideEmployeeApi(Retrofit retrofit) {
|
||||||
|
return retrofit.create(EmployeeApi.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Provides
|
||||||
|
@Singleton
|
||||||
|
public static RefundApi provideRefundApi(Retrofit retrofit) {
|
||||||
|
return retrofit.create(RefundApi.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.util.Log;
|
|||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
@@ -97,7 +98,7 @@ public class AdoptionFragment extends Fragment implements AdoptionAdapter.OnAdop
|
|||||||
|
|
||||||
private void loadAdoptions() {
|
private void loadAdoptions() {
|
||||||
if (swipeRefresh != null) swipeRefresh.setRefreshing(true);
|
if (swipeRefresh != null) swipeRefresh.setRefreshing(true);
|
||||||
api.getAllAdoptions(0, 100).enqueue(new Callback<PageResponse<AdoptionDTO>>() {
|
api.getAllAdoptions(0, 100, null, null, null, null, null).enqueue(new Callback<PageResponse<AdoptionDTO>>() {
|
||||||
public void onResponse(Call<PageResponse<AdoptionDTO>> c,
|
public void onResponse(Call<PageResponse<AdoptionDTO>> c,
|
||||||
Response<PageResponse<AdoptionDTO>> r) {
|
Response<PageResponse<AdoptionDTO>> r) {
|
||||||
if (swipeRefresh != null) swipeRefresh.setRefreshing(false);
|
if (swipeRefresh != null) swipeRefresh.setRefreshing(false);
|
||||||
@@ -119,7 +120,6 @@ public class AdoptionFragment extends Fragment implements AdoptionAdapter.OnAdop
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openDetail(int position) {
|
private void openDetail(int position) {
|
||||||
AdoptionDetailFragment detail = new AdoptionDetailFragment();
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
|
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
@@ -131,12 +131,12 @@ public class AdoptionFragment extends Fragment implements AdoptionAdapter.OnAdop
|
|||||||
args.putString("adoptionStatus", a.getAdoptionStatus());
|
args.putString("adoptionStatus", a.getAdoptionStatus());
|
||||||
if (a.getEmployeeId() != null)
|
if (a.getEmployeeId() != null)
|
||||||
args.putLong("employeeId", a.getEmployeeId());}
|
args.putLong("employeeId", a.getEmployeeId());}
|
||||||
|
NavHostFragment.findNavController(this).navigate(R.id.nav_adoption_detail, args);
|
||||||
detail.setArguments(args);
|
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
|
||||||
if (lf != null) lf.loadFragment(detail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAdoptionClick(int position) { openDetail(position); }
|
public void onAdoptionClick(int position) { openDetail(position); }
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void onSelectionChanged(int count) {}
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,15 +32,21 @@ public class AnalyticsFragment extends Fragment {
|
|||||||
loadAnalytics();
|
loadAnalytics();
|
||||||
|
|
||||||
btnRefresh.setOnClickListener(v -> loadAnalytics());
|
btnRefresh.setOnClickListener(v -> loadAnalytics());
|
||||||
hamburger.setOnClickListener(v -> {
|
hamburger.setOnClickListener(v -> openDrawer());
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
|
||||||
if (lf != null)
|
|
||||||
lf.openDrawer();
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openDrawer() {
|
||||||
|
Fragment parent = getParentFragment();
|
||||||
|
if (parent != null) {
|
||||||
|
Fragment grandParent = parent.getParentFragment();
|
||||||
|
if (grandParent instanceof ListFragment) {
|
||||||
|
((ListFragment) grandParent).openDrawer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void initViews(View v) {
|
private void initViews(View v) {
|
||||||
tvTotalRevenue = v.findViewById(R.id.tvTotalRevenue);
|
tvTotalRevenue = v.findViewById(R.id.tvTotalRevenue);
|
||||||
tvTotalTransactions = v.findViewById(R.id.tvTotalTransactions);
|
tvTotalTransactions = v.findViewById(R.id.tvTotalTransactions);
|
||||||
@@ -325,4 +331,4 @@ public class AnalyticsFragment extends Fragment {
|
|||||||
tvTotalItems.setText("—");
|
tvTotalItems.setText("—");
|
||||||
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package com.example.petstoremobile.fragments.listfragments;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@@ -13,38 +15,43 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
import com.example.petstoremobile.adapters.SaleAdapter;
|
import com.example.petstoremobile.adapters.SaleAdapter;
|
||||||
import com.example.petstoremobile.api.SaleApi;
|
|
||||||
import com.example.petstoremobile.databinding.FragmentSaleBinding;
|
import com.example.petstoremobile.databinding.FragmentSaleBinding;
|
||||||
|
import com.example.petstoremobile.dtos.SaleDTO;
|
||||||
import com.example.petstoremobile.fragments.ListFragment;
|
import com.example.petstoremobile.fragments.ListFragment;
|
||||||
import com.example.petstoremobile.models.Sale;
|
import com.example.petstoremobile.utils.Resource;
|
||||||
|
import com.example.petstoremobile.viewmodels.SaleViewModel;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import dagger.hilt.android.AndroidEntryPoint;
|
import dagger.hilt.android.AndroidEntryPoint;
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
public class SaleFragment extends Fragment implements SaleAdapter.OnSaleClickListener {
|
public class SaleFragment extends Fragment implements SaleAdapter.OnSaleClickListener {
|
||||||
|
|
||||||
private FragmentSaleBinding binding;
|
private FragmentSaleBinding binding;
|
||||||
private List<Sale> saleList = new ArrayList<>();
|
private List<SaleDTO> saleList = new ArrayList<>();
|
||||||
private List<Sale> filteredList = new ArrayList<>();
|
private List<SaleDTO> filteredList = new ArrayList<>();
|
||||||
private SaleAdapter adapter;
|
private SaleAdapter adapter;
|
||||||
|
private SaleViewModel saleViewModel;
|
||||||
@Inject SaleApi api;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
binding = FragmentSaleBinding.inflate(inflater, container, false);
|
binding = FragmentSaleBinding.inflate(inflater, container, false);
|
||||||
|
return binding.getRoot();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
saleViewModel = new ViewModelProvider(this).get(SaleViewModel.class);
|
||||||
|
|
||||||
setupRecyclerView();
|
setupRecyclerView();
|
||||||
loadSaleData();
|
|
||||||
setupSearch();
|
setupSearch();
|
||||||
setupSwipeRefresh();
|
setupSwipeRefresh();
|
||||||
|
loadSales();
|
||||||
|
|
||||||
// Make the hamburger button open the drawer from listFragment
|
|
||||||
binding.btnHamburger.setOnClickListener(v -> {
|
binding.btnHamburger.setOnClickListener(v -> {
|
||||||
Fragment parent = getParentFragment();
|
Fragment parent = getParentFragment();
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
@@ -55,7 +62,11 @@ public class SaleFragment extends Fragment implements SaleAdapter.OnSaleClickLis
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return binding.getRoot();
|
binding.fabAddSale.setOnClickListener(v ->
|
||||||
|
NavHostFragment.findNavController(this).navigate(R.id.nav_sale_detail));
|
||||||
|
|
||||||
|
binding.btnOpenRefund.setOnClickListener(v ->
|
||||||
|
NavHostFragment.findNavController(this).navigate(R.id.nav_refund));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,19 +75,20 @@ public class SaleFragment extends Fragment implements SaleAdapter.OnSaleClickLis
|
|||||||
binding = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupRecyclerView() {
|
||||||
|
adapter = new SaleAdapter(filteredList, this);
|
||||||
|
binding.recyclerViewSales.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
binding.recyclerViewSales.setAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
private void setupSearch() {
|
private void setupSearch() {
|
||||||
binding.etSearchSale.addTextChangedListener(new TextWatcher() {
|
binding.etSearchSale.addTextChangedListener(new TextWatcher() {
|
||||||
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||||
}
|
@Override public void afterTextChanged(Editable s) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
filterSales(s.toString());
|
filterSales(s.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,60 +98,46 @@ public class SaleFragment extends Fragment implements SaleAdapter.OnSaleClickLis
|
|||||||
filteredList.addAll(saleList);
|
filteredList.addAll(saleList);
|
||||||
} else {
|
} else {
|
||||||
String lower = query.toLowerCase();
|
String lower = query.toLowerCase();
|
||||||
for (Sale s : saleList) {
|
for (SaleDTO s : saleList) {
|
||||||
if (s.getItemName().toLowerCase().contains(lower)
|
if ((s.getEmployeeName() != null && s.getEmployeeName().toLowerCase().contains(lower))
|
||||||
|| s.getEmployeeName().toLowerCase().contains(lower)
|
|| (s.getSaleDate() != null && s.getSaleDate().toLowerCase().contains(lower))
|
||||||
|| s.getSaleDate().toLowerCase().contains(lower)
|
|| (s.getPaymentMethod() != null && s.getPaymentMethod().toLowerCase().contains(lower))
|
||||||
|| s.getPaymentMethod().toLowerCase().contains(lower)
|
|| (s.getSaleId() != null && String.valueOf(s.getSaleId()).contains(lower))) {
|
||||||
|| String.valueOf(s.getSaleId()).contains(lower)) {
|
|
||||||
filteredList.add(s);
|
filteredList.add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adapter.notifyDataSetChanged();
|
if (adapter != null) adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSwipeRefresh() {
|
private void setupSwipeRefresh() {
|
||||||
binding.swipeRefreshSale.setOnRefreshListener(() -> {
|
binding.swipeRefreshSale.setOnRefreshListener(() -> {
|
||||||
loadSaleData();
|
loadSales();
|
||||||
binding.swipeRefreshSale.setRefreshing(false);
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadSales() {
|
||||||
|
saleViewModel.getAllSales(0, 200).observe(getViewLifecycleOwner(), resource -> {
|
||||||
|
binding.swipeRefreshSale.setRefreshing(false);
|
||||||
|
if (resource.status == Resource.Status.SUCCESS && resource.data != null) {
|
||||||
|
saleList.clear();
|
||||||
|
saleList.addAll(resource.data.getContent());
|
||||||
|
filterSales(binding.etSearchSale.getText() != null
|
||||||
|
? binding.etSearchSale.getText().toString() : "");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// When a sale row is clicked, open the refund screen for that sale
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaleClick(int position) {
|
public void onSaleClick(int position) {
|
||||||
Sale sale = filteredList.get(position);
|
SaleDTO sale = filteredList.get(position);
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putInt("saleId", sale.getSaleId());
|
if (sale.getSaleId() != null) {
|
||||||
args.putString("saleDate", sale.getSaleDate());
|
args.putLong("saleId", sale.getSaleId());
|
||||||
args.putString("employeeName", sale.getEmployeeName());
|
}
|
||||||
args.putDouble("total", sale.getTotal());
|
if (sale.getIsRefund() != null) {
|
||||||
args.putString("paymentMethod", sale.getPaymentMethod());
|
args.putBoolean("isRefund", sale.getIsRefund());
|
||||||
|
}
|
||||||
NavHostFragment.findNavController(this).navigate(R.id.nav_refund_detail, args);
|
NavHostFragment.findNavController(this).navigate(R.id.nav_sale_detail, args);
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadSales() {
|
|
||||||
loadSaleData();
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Replace with actual API call - GET v1/sales
|
|
||||||
private void loadSaleData() {
|
|
||||||
saleList.clear();
|
|
||||||
saleList.add(new Sale(1, "2026-03-01", "John Smith", "Premium Dog Food", 2, 45.99, 91.98, "Card", false));
|
|
||||||
saleList.add(new Sale(2, "2026-03-02", "Jane Doe", "Cat Toy Bundle", 1, 19.99, 19.99, "Cash", false));
|
|
||||||
saleList.add(new Sale(3, "2026-03-03", "John Smith", "Pet Shampoo", 3, 12.99, 38.97, "Card", false));
|
|
||||||
saleList.add(new Sale(4, "2026-03-04", "Jane Doe", "Dog Bed - Large", 1, 89.99, 89.99, "Cash", true));
|
|
||||||
filteredList.clear();
|
|
||||||
filteredList.addAll(saleList);
|
|
||||||
if (adapter != null)
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupRecyclerView() {
|
|
||||||
adapter = new SaleAdapter(filteredList, this);
|
|
||||||
binding.recyclerViewSales.setLayoutManager(new LinearLayoutManager(getContext()));
|
|
||||||
binding.recyclerViewSales.setAdapter(adapter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ import android.text.*;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
@@ -15,7 +18,6 @@ import com.example.petstoremobile.api.RetrofitClient;
|
|||||||
import com.example.petstoremobile.dtos.EmployeeDTO;
|
import com.example.petstoremobile.dtos.EmployeeDTO;
|
||||||
import com.example.petstoremobile.dtos.PageResponse;
|
import com.example.petstoremobile.dtos.PageResponse;
|
||||||
import com.example.petstoremobile.fragments.ListFragment;
|
import com.example.petstoremobile.fragments.ListFragment;
|
||||||
import com.example.petstoremobile.fragments.listfragments.detailfragments.StaffDetailFragment;
|
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import retrofit2.*;
|
import retrofit2.*;
|
||||||
@@ -29,7 +31,7 @@ public class StaffFragment extends Fragment implements EmployeeAdapter.OnEmploye
|
|||||||
private EditText etSearch;
|
private EditText etSearch;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.fragment_staff, container, false);
|
View view = inflater.inflate(R.layout.fragment_staff, container, false);
|
||||||
|
|
||||||
@@ -42,14 +44,21 @@ public class StaffFragment extends Fragment implements EmployeeAdapter.OnEmploye
|
|||||||
fab.setOnClickListener(v -> openDetail(-1));
|
fab.setOnClickListener(v -> openDetail(-1));
|
||||||
|
|
||||||
ImageButton hamburger = view.findViewById(R.id.btnHamburgerStaff);
|
ImageButton hamburger = view.findViewById(R.id.btnHamburgerStaff);
|
||||||
hamburger.setOnClickListener(v -> {
|
hamburger.setOnClickListener(v -> openDrawer());
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
|
||||||
if (lf != null) lf.openDrawer();
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openDrawer() {
|
||||||
|
Fragment parent = getParentFragment();
|
||||||
|
if (parent != null) {
|
||||||
|
Fragment grandParent = parent.getParentFragment();
|
||||||
|
if (grandParent instanceof ListFragment) {
|
||||||
|
((ListFragment) grandParent).openDrawer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setupRecyclerView(View view) {
|
private void setupRecyclerView(View view) {
|
||||||
RecyclerView rv = view.findViewById(R.id.recyclerViewStaff);
|
RecyclerView rv = view.findViewById(R.id.recyclerViewStaff);
|
||||||
adapter = new EmployeeAdapter(filteredList, this);
|
adapter = new EmployeeAdapter(filteredList, this);
|
||||||
@@ -115,7 +124,6 @@ public class StaffFragment extends Fragment implements EmployeeAdapter.OnEmploye
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void openDetail(int position) {
|
private void openDetail(int position) {
|
||||||
StaffDetailFragment detail = new StaffDetailFragment();
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
EmployeeDTO e = filteredList.get(position);
|
EmployeeDTO e = filteredList.get(position);
|
||||||
@@ -129,13 +137,11 @@ public class StaffFragment extends Fragment implements EmployeeAdapter.OnEmploye
|
|||||||
args.putBoolean("active", Boolean.TRUE.equals(e.getActive()));
|
args.putBoolean("active", Boolean.TRUE.equals(e.getActive()));
|
||||||
args.putBoolean("isEditing", true);
|
args.putBoolean("isEditing", true);
|
||||||
}
|
}
|
||||||
detail.setArguments(args);
|
NavHostFragment.findNavController(this).navigate(R.id.nav_staff_detail, args);
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
|
||||||
if (lf != null) lf.loadFragment(detail);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEmployeeClick(int position) {
|
public void onEmployeeClick(int position) {
|
||||||
openDetail(position);
|
openDetail(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
package com.example.petstoremobile.fragments.listfragments.detailfragments;
|
package com.example.petstoremobile.fragments.listfragments.detailfragments;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
import com.example.petstoremobile.api.RetrofitClient;
|
import com.example.petstoremobile.api.RetrofitClient;
|
||||||
import com.example.petstoremobile.dtos.SaleDTO;
|
import com.example.petstoremobile.dtos.SaleDTO;
|
||||||
import com.example.petstoremobile.dtos.PageResponse;
|
import com.example.petstoremobile.dtos.PageResponse;
|
||||||
import com.example.petstoremobile.fragments.ListFragment;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -506,7 +505,6 @@ public class RefundFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void navigateBack() {
|
private void navigateBack() {
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
NavHostFragment.findNavController(this).popBackStack();
|
||||||
if (lf != null) lf.getChildFragmentManager().popBackStack();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,10 @@ import android.widget.*;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
import com.example.petstoremobile.api.*;
|
import com.example.petstoremobile.api.*;
|
||||||
import com.example.petstoremobile.dtos.*;
|
import com.example.petstoremobile.dtos.*;
|
||||||
import com.example.petstoremobile.fragments.ListFragment;
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import retrofit2.*;
|
import retrofit2.*;
|
||||||
@@ -144,7 +144,7 @@ public class SaleDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadProducts() {
|
private void loadProducts() {
|
||||||
RetrofitClient.getProductApi(requireContext()).getAllProducts(null, 0, 200)
|
RetrofitClient.getProductApi(requireContext()).getAllProducts(null, null, 0, 200, null)
|
||||||
.enqueue(new Callback<PageResponse<ProductDTO>>() {
|
.enqueue(new Callback<PageResponse<ProductDTO>>() {
|
||||||
public void onResponse(Call<PageResponse<ProductDTO>> c,
|
public void onResponse(Call<PageResponse<ProductDTO>> c,
|
||||||
Response<PageResponse<ProductDTO>> r) {
|
Response<PageResponse<ProductDTO>> r) {
|
||||||
@@ -329,12 +329,9 @@ public class SaleDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void showRefundDialog() {
|
private void showRefundDialog() {
|
||||||
RefundFragment refundFragment = new RefundFragment();
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("saleId", saleId);
|
args.putLong("saleId", saleId);
|
||||||
refundFragment.setArguments(args);
|
NavHostFragment.findNavController(this).navigate(R.id.nav_refund, args);
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
|
||||||
if (lf != null) lf.loadFragment(refundFragment);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void submitRefund() {
|
private void submitRefund() {
|
||||||
@@ -366,8 +363,6 @@ public class SaleDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void navigateBack() {
|
private void navigateBack() {
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
NavHostFragment.findNavController(this).popBackStack();
|
||||||
if (lf != null)
|
|
||||||
lf.getChildFragmentManager().popBackStack();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ import android.widget.*;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
import com.example.petstoremobile.R;
|
import com.example.petstoremobile.R;
|
||||||
import com.example.petstoremobile.api.EmployeeApi;
|
import com.example.petstoremobile.api.EmployeeApi;
|
||||||
import com.example.petstoremobile.api.RetrofitClient;
|
import com.example.petstoremobile.api.RetrofitClient;
|
||||||
import com.example.petstoremobile.dtos.EmployeeDTO;
|
import com.example.petstoremobile.dtos.EmployeeDTO;
|
||||||
import com.example.petstoremobile.fragments.ListFragment;
|
|
||||||
import retrofit2.*;
|
import retrofit2.*;
|
||||||
|
|
||||||
public class StaffDetailFragment extends Fragment {
|
public class StaffDetailFragment extends Fragment {
|
||||||
@@ -194,7 +194,6 @@ public class StaffDetailFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void navigateBack() {
|
private void navigateBack() {
|
||||||
ListFragment lf = (ListFragment) getParentFragment();
|
NavHostFragment.findNavController(this).popBackStack();
|
||||||
if (lf != null) lf.getChildFragmentManager().popBackStack();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.example.petstoremobile.repositories;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import com.example.petstoremobile.api.EmployeeApi;
|
||||||
|
import com.example.petstoremobile.dtos.EmployeeDTO;
|
||||||
|
import com.example.petstoremobile.dtos.PageResponse;
|
||||||
|
import com.example.petstoremobile.utils.Resource;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class EmployeeRepository extends BaseRepository {
|
||||||
|
private final EmployeeApi employeeApi;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public EmployeeRepository(EmployeeApi employeeApi) {
|
||||||
|
super("EmployeeRepository");
|
||||||
|
this.employeeApi = employeeApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<PageResponse<EmployeeDTO>>> getAllEmployees(int page, int size) {
|
||||||
|
return executeCall(employeeApi.getAllEmployees(page, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<EmployeeDTO>> getEmployeeById(Long id) {
|
||||||
|
return executeCall(employeeApi.getEmployeeById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<EmployeeDTO>> createEmployee(EmployeeDTO dto) {
|
||||||
|
return executeCall(employeeApi.createEmployee(dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<EmployeeDTO>> updateEmployee(Long id, EmployeeDTO dto) {
|
||||||
|
return executeCall(employeeApi.updateEmployee(id, dto));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<Void>> deleteEmployee(Long id) {
|
||||||
|
return executeCall(employeeApi.deleteEmployee(id));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.example.petstoremobile.repositories;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
|
||||||
|
import com.example.petstoremobile.api.SaleApi;
|
||||||
|
import com.example.petstoremobile.dtos.PageResponse;
|
||||||
|
import com.example.petstoremobile.dtos.SaleDTO;
|
||||||
|
import com.example.petstoremobile.utils.Resource;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
public class SaleRepository extends BaseRepository {
|
||||||
|
private final SaleApi saleApi;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public SaleRepository(SaleApi saleApi) {
|
||||||
|
super("SaleRepository");
|
||||||
|
this.saleApi = saleApi;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<PageResponse<SaleDTO>>> getAllSales(int page, int size) {
|
||||||
|
return executeCall(saleApi.getAllSales(page, size));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<SaleDTO>> getSaleById(Long id) {
|
||||||
|
return executeCall(saleApi.getSaleById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<SaleDTO>> createSale(SaleDTO sale) {
|
||||||
|
return executeCall(saleApi.createSale(sale));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.example.petstoremobile.viewmodels;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
import com.example.petstoremobile.dtos.EmployeeDTO;
|
||||||
|
import com.example.petstoremobile.dtos.PageResponse;
|
||||||
|
import com.example.petstoremobile.repositories.EmployeeRepository;
|
||||||
|
import com.example.petstoremobile.utils.Resource;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel;
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
public class EmployeeViewModel extends ViewModel {
|
||||||
|
private final EmployeeRepository employeeRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public EmployeeViewModel(EmployeeRepository employeeRepository) {
|
||||||
|
this.employeeRepository = employeeRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<PageResponse<EmployeeDTO>>> getAllEmployees(int page, int size) {
|
||||||
|
return employeeRepository.getAllEmployees(page, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<EmployeeDTO>> getEmployeeById(Long id) {
|
||||||
|
return employeeRepository.getEmployeeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<EmployeeDTO>> createEmployee(EmployeeDTO dto) {
|
||||||
|
return employeeRepository.createEmployee(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<EmployeeDTO>> updateEmployee(Long id, EmployeeDTO dto) {
|
||||||
|
return employeeRepository.updateEmployee(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<Void>> deleteEmployee(Long id) {
|
||||||
|
return employeeRepository.deleteEmployee(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.example.petstoremobile.viewmodels;
|
||||||
|
|
||||||
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.ViewModel;
|
||||||
|
|
||||||
|
import com.example.petstoremobile.dtos.PageResponse;
|
||||||
|
import com.example.petstoremobile.dtos.SaleDTO;
|
||||||
|
import com.example.petstoremobile.repositories.SaleRepository;
|
||||||
|
import com.example.petstoremobile.utils.Resource;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import dagger.hilt.android.lifecycle.HiltViewModel;
|
||||||
|
|
||||||
|
@HiltViewModel
|
||||||
|
public class SaleViewModel extends ViewModel {
|
||||||
|
private final SaleRepository saleRepository;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public SaleViewModel(SaleRepository saleRepository) {
|
||||||
|
this.saleRepository = saleRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<PageResponse<SaleDTO>>> getAllSales(int page, int size) {
|
||||||
|
return saleRepository.getAllSales(page, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<SaleDTO>> getSaleById(Long id) {
|
||||||
|
return saleRepository.getSaleById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LiveData<Resource<SaleDTO>> createSale(SaleDTO sale) {
|
||||||
|
return saleRepository.createSale(sale);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,21 +80,6 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="16dp"/>
|
android:layout_marginBottom="16dp"/>
|
||||||
|
|
||||||
<!-- Employee -->
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="Assign Employee"
|
|
||||||
android:textColor="@color/text_dark"
|
|
||||||
android:textSize="12sp"
|
|
||||||
android:layout_marginBottom="4dp"/>
|
|
||||||
|
|
||||||
<Spinner
|
|
||||||
android:id="@+id/spinnerAdoptionEmployee"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginBottom="16dp"/>
|
|
||||||
|
|
||||||
<!-- Pet -->
|
<!-- Pet -->
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
@@ -128,9 +128,33 @@
|
|||||||
tools:layout="@layout/fragment_product_detail" />
|
tools:layout="@layout/fragment_product_detail" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/nav_refund_detail"
|
android:id="@+id/nav_refund"
|
||||||
android:name="com.example.petstoremobile.fragments.listfragments.detailfragments.RefundDetailFragment"
|
android:name="com.example.petstoremobile.fragments.listfragments.detailfragments.RefundFragment"
|
||||||
android:label="Refund Details"
|
android:label="Refund"
|
||||||
tools:layout="@layout/fragment_refund_detail" />
|
tools:layout="@layout/fragment_refund" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/nav_sale_detail"
|
||||||
|
android:name="com.example.petstoremobile.fragments.listfragments.detailfragments.SaleDetailFragment"
|
||||||
|
android:label="Sale Details"
|
||||||
|
tools:layout="@layout/fragment_sale_detail" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/nav_staff"
|
||||||
|
android:name="com.example.petstoremobile.fragments.listfragments.StaffFragment"
|
||||||
|
android:label="Staff"
|
||||||
|
tools:layout="@layout/fragment_staff" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/nav_staff_detail"
|
||||||
|
android:name="com.example.petstoremobile.fragments.listfragments.detailfragments.StaffDetailFragment"
|
||||||
|
android:label="Staff Details"
|
||||||
|
tools:layout="@layout/fragment_staff_detail" />
|
||||||
|
|
||||||
|
<fragment
|
||||||
|
android:id="@+id/nav_analytics"
|
||||||
|
android:name="com.example.petstoremobile.fragments.listfragments.AnalyticsFragment"
|
||||||
|
android:label="Analytics"
|
||||||
|
tools:layout="@layout/fragment_analytics" />
|
||||||
|
|
||||||
</navigation>
|
</navigation>
|
||||||
|
|||||||
Reference in New Issue
Block a user