Skip to content

Commit

Permalink
Merge pull request #43 from zVolt/feature/deletedebitcard
Browse files Browse the repository at this point in the history
Feature/deletedebitcard
  • Loading branch information
zkhan93 authored Feb 8, 2022
2 parents 3bfd974 + e96398e commit aaca568
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import io.github.zkhan93.familyfinance.adapters.BankSpinnerAdapter;
import io.github.zkhan93.familyfinance.events.ConfirmDeleteEvent;
import io.github.zkhan93.familyfinance.events.DeleteConfirmedEvent;
import io.github.zkhan93.familyfinance.events.UpdateEvent;
import io.github.zkhan93.familyfinance.models.DCard;
import io.github.zkhan93.familyfinance.util.CardNumberWatcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

import org.greenrobot.eventbus.EventBus;
Expand Down Expand Up @@ -48,6 +49,7 @@ public class FragmentCCards extends Fragment implements ItemInteractionListener<

private String familyId;
private CCardListAdapter cCardListAdapter;
private DatabaseReference baseCardRef;
AppState appState;
RecyclerView ccardsList;

Expand Down Expand Up @@ -77,8 +79,8 @@ public void onCreate(Bundle savedInstanceState) {
familyId = bundle.getString(ARG_FAMILY_ID, null);
}
if (familyId == null) {
familyId =
PreferenceManager.getDefaultSharedPreferences(requireActivity()).getString(ARG_FAMILY_ID, null);
familyId = PreferenceManager.getDefaultSharedPreferences(requireActivity())
.getString(ARG_FAMILY_ID, null);
}
appState = new ViewModelProvider(requireActivity()).get(AppState.class);
}
Expand All @@ -95,6 +97,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
ccardsList.setAdapter(cCardListAdapter);
setHasOptionsMenu(true);
initFab();
baseCardRef = FirebaseDatabase.getInstance()
.getReference()
.child("ccards")
.child(familyId);
return rootView;
}

Expand Down Expand Up @@ -126,7 +132,6 @@ public void onStop() {
cCardListAdapter.unregisterForEvent();
}


private void initFab() {
appState.enableFab(R.drawable.ic_add_white_24dp, TAG);
appState.getFabAction().observe(getViewLifecycleOwner(), event -> {
Expand All @@ -141,6 +146,7 @@ private void initFab() {

@Override
public void delete(CCard cCard) {
// Just show a confirmation dialog
String title = "You want to delete Credit Card " + cCard.getNumber();
DialogFragmentConfirm<CCard> dialogFragmentConfirm = new DialogFragmentConfirm<>();
Bundle bundle = new Bundle();
Expand All @@ -167,7 +173,7 @@ public void view(CCard cCard) {
navController.navigate(R.id.ccard_detail, bundle);
}

//TODO: call this from relevant place
// call this from relevant place, maybe from details view fab + button
public void addAddonCard(CCard cCard) {
DialogFragmentAddonCard.newInstance(familyId, cCard.getNumber()).show(getParentFragmentManager(),
DialogFragmentAddonCard.TAG);
Expand All @@ -179,7 +185,6 @@ public void copyToClipboard(CCard cCard) {
}



@Override
public boolean onQueryTextSubmit(String query) {
Log.d(TAG, "saarch for: " + query);
Expand Down Expand Up @@ -212,6 +217,7 @@ public void deleteCCard(DeleteEvent event) {
cCardListAdapter.deleteCcard(addonCard.getNumber(), true);
}
}

@Subscribe()
public void confirmDelete(ConfirmDeleteEvent event) {
if (event == null || event.getItem() == null) return;
Expand All @@ -220,26 +226,24 @@ public void confirmDelete(ConfirmDeleteEvent event) {
delete(card);
}
}

@Subscribe()
public void createCCard(CreateEvent event) {
if (event == null || event.getItem() == null) return;
if (event.getItem() instanceof CCard) {
CCard card = (CCard) event.getItem();
FirebaseDatabase.getInstance()
.getReference("ccards")
.child(familyId)
baseCardRef
.child(card.getNumber())
.setValue(card);
}
}

@Subscribe()
public void updateCCard(UpdateEvent event) {
if (event == null || event.getItem() == null) return;
if (event.getItem() instanceof CCard) {
CCard card = (CCard) event.getItem();
FirebaseDatabase.getInstance()
.getReference("ccards")
.child(familyId)
baseCardRef
.child(card.getNumber())
.setValue(card);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public class FragmentDCards extends Fragment {
AppState appState;

public FragmentDCards() {
// Required empty public constructor
adapterInteraction = () -> {
if (dCardListAdapter.getItemCount() == 0) {
Util.Log.d(TAG, "show blank image");
Expand Down Expand Up @@ -241,7 +240,7 @@ public void updateDCard(UpdateEvent event) {
@Subscribe()
public void confirmDelete(ConfirmDeleteEvent event) {
if (event == null || event.getItem() == null) return;
if (event.getItem() instanceof CCard) {
if (event.getItem() instanceof DCard) {
DCard card = (DCard) event.getItem();
cardInteractionListener.delete(card);
}
Expand Down

0 comments on commit aaca568

Please sign in to comment.