import java.lang.ref.WeakReference;
import java.text.DateFormat;
import java.util.Date;
+import java.util.Observable;
+import java.util.Observer;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;
mProfileListAdapter = new ProfilesRecyclerViewAdapter();
root.setAdapter(mProfileListAdapter);
+ mProfileListAdapter.addEditingProfilesObserver(new Observer() {
+ @Override
+ public void update(Observable o, Object arg) {
+ if (mProfileListAdapter.isEditingProfiles()) {
+ findViewById(R.id.nav_profiles_arrow).setVisibility(View.GONE);
+ findViewById(R.id.nav_profiles_arrow).setAlpha(0f);
+ findViewById(R.id.nav_profiles_cancel_edit).setVisibility(View.VISIBLE);
+ }
+ else {
+ findViewById(R.id.nav_profiles_arrow).setVisibility(View.VISIBLE);
+ findViewById(R.id.nav_profiles_arrow).setAlpha(1f);
+ findViewById(R.id.nav_profiles_cancel_edit).setVisibility(View.GONE);
+ }
+ }
+ });
+
+ findViewById(R.id.nav_profiles_cancel_edit).setOnClickListener((v) -> {
+ mProfileListAdapter.stopEditingProfiles();
+ });
LinearLayoutManager llm = new LinearLayoutManager(this);
llm.setOrientation(RecyclerView.VERTICAL);
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.ui.activity.ProfileDetailActivity;
import net.ktnx.mobileledger.utils.Colors;
+import net.ktnx.mobileledger.utils.ObservableValue;
import java.util.Collections;
+import java.util.Observer;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ItemTouchHelper;
MobileLedgerProfile profile = (MobileLedgerProfile) ((View) view.getParent()).getTag();
editProfile(view, profile);
};
- private boolean editingProfiles = false;
+ private ObservableValue<Boolean> 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() {
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
this.recyclerView = recyclerView;
- if (editingProfiles) rearrangeHelper.attachToRecyclerView(recyclerView);
- }
- public boolean editingProfiles() {
- return this.editingProfiles;
+ if (editingProfiles.get()) rearrangeHelper.attachToRecyclerView(recyclerView);
}
public void startEditingProfiles() {
- if (editingProfiles) return;
- this.editingProfiles = true;
+ if (editingProfiles.get()) return;
+ this.editingProfiles.set(true);
notifyDataSetChanged();
rearrangeHelper.attachToRecyclerView(recyclerView);
}
public void stopEditingProfiles() {
- if (!editingProfiles) return;
- this.editingProfiles = false;
+ if (!editingProfiles.get()) return;
+ this.editingProfiles.set(false);
notifyDataSetChanged();
rearrangeHelper.attachToRecyclerView(null);
}
public void flipEditingProfiles() {
- if (editingProfiles) stopEditingProfiles();
+ if (editingProfiles.get()) stopEditingProfiles();
else startEditingProfiles();
}
private void editProfile(View view, MobileLedgerProfile profile) {
holder.itemView.setAlpha(sameProfile ? 1 : 0.5f);
holder.itemView
.setBackground(sameProfile ? new ColorDrawable(Colors.tableRowDarkBG) : null);
- if (editingProfiles) {
+ if (editingProfiles.get()) {
holder.mRearrangeHandle.setVisibility(View.VISIBLE);
holder.mEditButton.setVisibility(View.VISIBLE);
}
public int getItemCount() {
return Data.profiles.size();
}
+ public boolean isEditingProfiles() {
+ return editingProfiles.get();
+ }
class ProfileListViewHolder extends RecyclerView.ViewHolder {
final TextView mEditButton;
final TextView mTitle, mColorTag;
android:layout_height="@dimen/thumb_row_height"
android:paddingEnd="@dimen/activity_horizontal_margin">
- <TextView
- android:id="@+id/nav_profiles_arrow"
+ <androidx.appcompat.widget.LinearLayoutCompat
+ android:id="@+id/nav_profile_list_head_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:drawableStart="@drawable/ic_expand_more_black_24dp"
- android:gravity="end|center_vertical"
- android:onClick="navProfilesHeadClicked"
+ android:gravity="center_vertical"
+ android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
+ app:layout_constraintTop_toTopOf="parent">
+
+ <ImageView
+ android:id="@+id/nav_profiles_arrow"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/ic_expand_more_black_24dp"
+ android:gravity="end|center_vertical"
+ android:onClick="navProfilesHeadClicked"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ <ImageView
+ android:id="@+id/nav_profiles_cancel_edit"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/ic_clear_black_24dp"
+ android:gravity="end|center_vertical"
+ android:visibility="gone"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toTopOf="parent" />
+
+ </androidx.appcompat.widget.LinearLayoutCompat>
<TextView
android:id="@+id/nav_profiles_label"
android:layout_marginEnd="8dp"
android:drawableStart="@drawable/ic_view_list_black_24dp"
android:gravity="start|center_vertical"
- android:text="@string/profiles"
android:onClick="navProfilesHeadClicked"
+ android:text="@string/profiles"
app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toStartOf="@+id/nav_profiles_arrow"
+ app:layout_constraintEnd_toStartOf="@+id/nav_profile_list_head_buttons"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />