X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fprofiles%2FProfilesRecyclerViewAdapter.java;h=eb3d0c85db5d0f87fb9012ce71a85e5701b9c12f;hp=a96517c28a0419893f7571425e130c4ba58b4de8;hb=bb9d4a9c9708a568dddf2b1c637ae54ec53caa25;hpb=ebc9d1e219e7b86e35acde2c799252f5da1dc5af diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index a96517c2..eb3d0c85 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -1,18 +1,18 @@ /* * Copyright © 2019 Damyan Ivanov. - * This file is part of MoLe. - * MoLe is free software: you can distribute it and/or modify it - * under the term of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your opinion), any later version. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. * - * MoLe is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License terms for details. + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. * - * You should have received a copy of the GNU General Public License - * along with Mobile-Ledger. If not, see . + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . */ package net.ktnx.mobileledger.ui.profiles; @@ -49,20 +49,10 @@ public class ProfilesRecyclerViewAdapter editProfile(view, profile); }; private ObservableValue editingProfiles = new ObservableValue<>(false); - public void addEditingProfilesObserver(Observer o) { - editingProfiles.addObserver(o); - } - public void deleteEditingProfilesObserver(Observer o) { - editingProfiles.deleteObserver(o); - } private RecyclerView recyclerView; private ItemTouchHelper rearrangeHelper; public ProfilesRecyclerViewAdapter() { - Data.profiles.addObserver((o, arg) -> { - Log.d("profiles", "profile list changed"); - if (arg == null) notifyDataSetChanged(); - else notifyItemChanged((int) arg); - }); + Log.d("flow", "ProfilesRecyclerViewAdapter.new()"); ItemTouchHelper.Callback cb = new ItemTouchHelper.Callback() { @Override @@ -74,7 +64,7 @@ public class ProfilesRecyclerViewAdapter public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { - Collections.swap(Data.profiles.getList(), viewHolder.getAdapterPosition(), + Collections.swap(Data.profiles, viewHolder.getAdapterPosition(), target.getAdapterPosition()); MobileLedgerProfile.storeProfilesOrder(); notifyItemMoved(viewHolder.getAdapterPosition(), target.getAdapterPosition()); @@ -86,6 +76,12 @@ public class ProfilesRecyclerViewAdapter }; rearrangeHelper = new ItemTouchHelper(cb); } + public void addEditingProfilesObserver(Observer o) { + editingProfiles.addObserver(o); + } + public void deleteEditingProfilesObserver(Observer o) { + editingProfiles.deleteObserver(o); + } @Override public void onDetachedFromRecyclerView(@NonNull RecyclerView recyclerView) { rearrangeHelper.attachToRecyclerView(null); @@ -146,7 +142,6 @@ public class ProfilesRecyclerViewAdapter MobileLedgerProfile myProfile = (MobileLedgerProfile) holder.itemView.getTag(); final MobileLedgerProfile currentProfile = Data.profile.get(); final boolean sameProfile = currentProfile.equals(myProfile); - view.setAlpha(sameProfile ? 1 : 0.5f); }); View.OnTouchListener dragStarter = (v, event) -> { @@ -178,8 +173,7 @@ public class ProfilesRecyclerViewAdapter holder.mEditButton.setOnClickListener(mOnClickListener); - final boolean sameProfile = currentProfile.equals(profile); - holder.itemView.setAlpha(sameProfile ? 1 : 0.5f); + final boolean sameProfile = (currentProfile != null) && currentProfile.equals(profile); holder.itemView .setBackground(sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null); if (editingProfiles.get()) {