diff options
author | stefan-niedermann <info@niedermann.it> | 2020-03-01 20:05:13 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-03-04 22:42:44 +0300 |
commit | f1ef8ef4b388f0da8765767191bcbdda8f6e3958 (patch) | |
tree | dbced8079332093eb1b88c814d0a1fc8af254822 /app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java | |
parent | b49dc9f3c0c3c721b284f382d8c30915354f5b92 (diff) |
#285 Migrate from ButterKnife to ViewBinding
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java | 146 |
1 files changed, 57 insertions, 89 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java index 65c4c4169..c6f5434f6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardDetailsFragment.java @@ -17,7 +17,6 @@ import android.view.ViewGroup; import android.widget.DatePicker; import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.TextView; import android.widget.TimePicker; import androidx.annotation.NonNull; @@ -27,11 +26,9 @@ import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.Fragment; import com.google.android.material.chip.Chip; -import com.google.android.material.chip.ChipGroup; import com.google.android.material.snackbar.Snackbar; import com.nextcloud.android.sso.exceptions.NextcloudFilesAppAccountNotFoundException; import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException; -import com.yydcdut.markdown.MarkdownEditText; import com.yydcdut.markdown.MarkdownProcessor; import com.yydcdut.markdown.syntax.edit.EditFactory; @@ -42,18 +39,14 @@ import java.util.Date; import java.util.Locale; import java.util.Objects; -import butterknife.BindDrawable; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; +import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabDetailsBinding; import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; -import it.niedermann.nextcloud.deck.ui.widget.DelayedAutoCompleteTextView; import it.niedermann.nextcloud.deck.util.ColorUtil; import it.niedermann.nextcloud.deck.util.DimensionUtil; import it.niedermann.nextcloud.deck.util.MarkDownUtil; @@ -68,8 +61,11 @@ import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.NO_LOCAL_ID; public class CardDetailsFragment extends Fragment implements DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener { + private static final String TAG = CardDetailsFragment.class.getCanonicalName(); + private FragmentCardEditTabDetailsBinding binding; + private boolean canEdit = false; private FullCard fullCard; private SyncManager syncManager; @@ -78,30 +74,9 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On private String baseUrl; private int avatarSize; private LinearLayout.LayoutParams avatarLayoutParams; - private Unbinder unbinder; private CardDetailsListener cardDetailsListener; private Activity activity; - @BindView(R.id.description) - MarkdownEditText description; - @BindView(R.id.people) - DelayedAutoCompleteTextView people; - @BindView(R.id.labels) - DelayedAutoCompleteTextView labels; - @BindView(R.id.peopleList) - LinearLayout peopleList; - @BindView(R.id.dueDateDate) - TextView dueDate; - @BindView(R.id.dueDateTime) - TextView dueDateTime; - @BindView(R.id.clearDueDate) - ImageView clearDueDate; - @BindView(R.id.labelsGroup) - ChipGroup labelsGroup; - - @BindDrawable(R.drawable.ic_close_circle_grey600) - Drawable closeCircleDrawable; - public CardDetailsFragment() { } @@ -137,8 +112,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_card_edit_tab_details, container, false); - unbinder = ButterKnife.bind(this, view); + binding = FragmentCardEditTabDetailsBinding.inflate(inflater, container, false); dateFormat = android.text.format.DateFormat.getDateFormat(activity); Bundle args = getArguments(); @@ -159,7 +133,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On } else { observeOnce(syncManager.getCardByLocalId(accountId, localId), CardDetailsFragment.this, (next) -> { fullCard = next; - description.setText(fullCard.getCard().getDescription()); + binding.description.setText(fullCard.getCard().getDescription()); setupView(accountId, boardId, canEdit); }); } @@ -175,7 +149,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On DeckLog.logError(e); } - return view; + return binding.getRoot(); } private void setupView(long accountId, long boardId, boolean canEdit) { @@ -188,15 +162,15 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On private void setupDescription() { if (canEdit) { MarkdownProcessor markdownProcessor = new MarkdownProcessor(requireContext()); - markdownProcessor.config(MarkDownUtil.getMarkDownConfiguration(description.getContext()).build()); + markdownProcessor.config(MarkDownUtil.getMarkDownConfiguration(binding.description.getContext()).build()); markdownProcessor.factory(EditFactory.create()); - markdownProcessor.live(description); - description.addTextChangedListener(new TextWatcher() { + markdownProcessor.live(binding.description); + binding.description.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (fullCard != null) { - cardDetailsListener.onDescriptionChanged(description.getText().toString()); - fullCard.getCard().setDescription(description.getText().toString()); + cardDetailsListener.onDescriptionChanged(binding.description.getText().toString()); + fullCard.getCard().setDescription(binding.description.getText().toString()); } } @@ -209,7 +183,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On } }); } else { - description.setEnabled(false); + binding.description.setEnabled(false); } } @@ -253,18 +227,18 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On private void setupDueDate() { if (this.fullCard.getCard().getDueDate() != null) { - dueDate.setText(dateFormat.format(this.fullCard.getCard().getDueDate())); - dueDateTime.setText(dueTime.format(this.fullCard.getCard().getDueDate())); - clearDueDate.setVisibility(View.VISIBLE); + binding.dueDateDate.setText(dateFormat.format(this.fullCard.getCard().getDueDate())); + binding.dueDateTime.setText(dueTime.format(this.fullCard.getCard().getDueDate())); + binding.clearDueDate.setVisibility(View.VISIBLE); } else { - clearDueDate.setVisibility(View.GONE); - dueDate.setText(null); - dueDateTime.setText(null); + binding.clearDueDate.setVisibility(View.GONE); + binding.dueDateDate.setText(null); + binding.dueDateTime.setText(null); } if (canEdit) { - dueDate.setOnClickListener(v -> { + binding.dueDateDate.setOnClickListener(v -> { if (fullCard != null && fullCard.getCard() != null) { createDatePickerDialogFromDate(activity, this, fullCard.getCard().getDueDate()).show(); } else { @@ -272,7 +246,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On } }); - dueDateTime.setOnClickListener(v -> { + binding.dueDateTime.setOnClickListener(v -> { if (fullCard != null && fullCard.getCard() != null) { createTimePickerDialogFromDate(activity, this, fullCard.getCard().getDueDate()).show(); } else { @@ -280,56 +254,56 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On } }); - clearDueDate.setOnClickListener(v -> { + binding.clearDueDate.setOnClickListener(v -> { cardDetailsListener.onDueDateChanged(null); - dueDate.setText(null); - dueDateTime.setText(null); + binding.dueDateDate.setText(null); + binding.dueDateTime.setText(null); fullCard.getCard().setDueDate(null); - clearDueDate.setVisibility(View.GONE); + binding.clearDueDate.setVisibility(View.GONE); }); } else { - dueDate.setEnabled(false); - dueDateTime.setEnabled(false); - clearDueDate.setVisibility(View.GONE); + binding.dueDateDate.setEnabled(false); + binding.dueDateTime.setEnabled(false); + binding.clearDueDate.setVisibility(View.GONE); } } private void setupLabels(long accountId, long boardId, boolean canEdit) { - labelsGroup.removeAllViews(); + binding.labelsGroup.removeAllViews(); if (canEdit) { Long localCardId = fullCard.getCard().getLocalId(); localCardId = localCardId == null ? -1 : localCardId; - labels.setAdapter(new LabelAutoCompleteAdapter(this, activity, accountId, boardId, localCardId)); - labels.setOnItemClickListener((adapterView, view, position, id) -> { + binding.labels.setAdapter(new LabelAutoCompleteAdapter(this, activity, accountId, boardId, localCardId)); + binding.labels.setOnItemClickListener((adapterView, view, position, id) -> { Label label = (Label) adapterView.getItemAtPosition(position); if (LabelAutoCompleteAdapter.CREATE_ID == label.getLocalId()) { Label newLabel = new Label(label); - newLabel.setTitle(((LabelAutoCompleteAdapter) labels.getAdapter()).getLastFilterText()); + newLabel.setTitle(((LabelAutoCompleteAdapter) binding.labels.getAdapter()).getLastFilterText()); newLabel.setLocalId(null); observeOnce(syncManager.createLabel(accountId, newLabel, boardId), CardDetailsFragment.this, createdLabel -> { newLabel.setLocalId(createdLabel.getLocalId()); cardDetailsListener.onLabelAdded(createdLabel); - labelsGroup.addView(createChipFromLabel(newLabel)); - labelsGroup.setVisibility(View.VISIBLE); + binding.labelsGroup.addView(createChipFromLabel(newLabel)); + binding.labelsGroup.setVisibility(View.VISIBLE); }); } else { cardDetailsListener.onLabelAdded(label); - labelsGroup.addView(createChipFromLabel(label)); - labelsGroup.setVisibility(View.VISIBLE); + binding.labelsGroup.addView(createChipFromLabel(label)); + binding.labelsGroup.setVisibility(View.VISIBLE); } - labels.setText(""); + binding.labels.setText(""); }); } else { - labels.setEnabled(false); + binding.labels.setEnabled(false); } if (fullCard.getLabels() != null && fullCard.getLabels().size() > 0) { for (Label label : fullCard.getLabels()) { - labelsGroup.addView(createChipFromLabel(label)); + binding.labelsGroup.addView(createChipFromLabel(label)); } - labelsGroup.setVisibility(View.VISIBLE); + binding.labelsGroup.setVisibility(View.VISIBLE); } else { - labelsGroup.setVisibility(View.INVISIBLE); + binding.labelsGroup.setVisibility(View.INVISIBLE); } } @@ -338,10 +312,10 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On Chip chip = new Chip(activity); chip.setText(label.getTitle()); if (canEdit) { - chip.setCloseIcon(closeCircleDrawable); + chip.setCloseIcon(getResources().getDrawable(R.drawable.ic_close_circle_grey600)); chip.setCloseIconVisible(true); chip.setOnCloseIconClickListener(v -> { - labelsGroup.removeView(chip); + binding.labelsGroup.removeView(chip); cardDetailsListener.onLabelRemoved(label); }); } @@ -366,18 +340,18 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On if (canEdit) { Long localCardId = fullCard.getCard().getLocalId(); localCardId = localCardId == null ? -1 : localCardId; - people.setAdapter(new UserAutoCompleteAdapter(this, activity, accountId, boardId, localCardId)); - people.setOnItemClickListener((adapterView, view, position, id) -> { + binding.people.setAdapter(new UserAutoCompleteAdapter(this, activity, accountId, boardId, localCardId)); + binding.people.setOnItemClickListener((adapterView, view, position, id) -> { User user = (User) adapterView.getItemAtPosition(position); cardDetailsListener.onUserAdded(user); if (baseUrl != null) { addAvatar(baseUrl, user); } - people.setText(""); + binding.people.setText(""); }); if (this.fullCard.getAssignedUsers() != null) { - peopleList.removeAllViews(); + binding.peopleList.removeAllViews(); if (baseUrl != null) { for (User user : this.fullCard.getAssignedUsers()) { addAvatar(baseUrl, user); @@ -385,7 +359,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On } } } else { - people.setEnabled(false); + binding.people.setEnabled(false); } } @@ -395,7 +369,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On if (canEdit) { avatar.setOnClickListener(v -> { cardDetailsListener.onUserRemoved(user); - peopleList.removeView(avatar); + binding.peopleList.removeView(avatar); Snackbar.make( Objects.requireNonNull(getView()), getString(R.string.unassigned_user, user.getDisplayname()), Snackbar.LENGTH_LONG) @@ -405,24 +379,18 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On }).show(); }); } - peopleList.addView(avatar); + binding.peopleList.addView(avatar); avatar.requestLayout(); ViewUtil.addAvatar(getContext(), avatar, baseUrl, user.getUid(), avatarSize, R.drawable.ic_person_grey600_24dp); } @Override - public void onDestroy() { - super.onDestroy(); - unbinder.unbind(); - } - - @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Calendar c = Calendar.getInstance(); int hourOfDay; int minute; - if (dueDateTime.getText() != null && dueDateTime.length() > 0) { + if (binding.dueDateTime.getText() != null && binding.dueDateTime.length() > 0) { hourOfDay = this.fullCard.getCard().getDueDate().getHours(); minute = this.fullCard.getCard().getDueDate().getMinutes(); } else { @@ -432,13 +400,13 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On c.set(year, month, dayOfMonth, hourOfDay, minute); this.fullCard.getCard().setDueDate(c.getTime()); - dueDate.setText(dateFormat.format(c.getTime())); + binding.dueDateDate.setText(dateFormat.format(c.getTime())); cardDetailsListener.onDueDateChanged(fullCard.card.getDueDate()); if (this.fullCard.getCard().getDueDate() == null || this.fullCard.getCard().getDueDate().getTime() == 0) { - clearDueDate.setVisibility(View.GONE); + binding.clearDueDate.setVisibility(View.GONE); } else { - clearDueDate.setVisibility(View.VISIBLE); + binding.clearDueDate.setVisibility(View.VISIBLE); } } @@ -449,12 +417,12 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On } this.fullCard.getCard().getDueDate().setHours(hourOfDay); this.fullCard.getCard().getDueDate().setMinutes(minute); - dueDateTime.setText(dueTime.format(this.fullCard.getCard().getDueDate().getTime())); + binding.dueDateTime.setText(dueTime.format(this.fullCard.getCard().getDueDate().getTime())); cardDetailsListener.onDueDateChanged(fullCard.card.getDueDate()); if (this.fullCard.getCard().getDueDate() == null || this.fullCard.getCard().getDueDate().getTime() == 0) { - clearDueDate.setVisibility(View.GONE); + binding.clearDueDate.setVisibility(View.GONE); } else { - clearDueDate.setVisibility(View.VISIBLE); + binding.clearDueDate.setVisibility(View.VISIBLE); } } |