diff options
Diffstat (limited to 'app')
6 files changed, 285 insertions, 233 deletions
diff --git a/app/build.gradle b/app/build.gradle index 0acd27f76..be5d482db 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,6 +16,9 @@ android { } } } + dataBinding { + enabled = true + } buildTypes { release { minifyEnabled false diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/viewmodel/FullCardViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/viewmodel/FullCardViewModel.java new file mode 100644 index 000000000..204d38b8d --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/viewmodel/FullCardViewModel.java @@ -0,0 +1,12 @@ +package it.niedermann.nextcloud.deck.model.viewmodel; + +import android.arch.lifecycle.LiveData; +import android.arch.lifecycle.ViewModel; + +import it.niedermann.nextcloud.deck.model.full.FullCard; + +public class FullCardViewModel extends ViewModel { + + public LiveData<FullCard> fullCard; + +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/EditActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/EditActivity.java index 67ae8a51e..3ca3be3d4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/EditActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/EditActivity.java @@ -1,5 +1,7 @@ package it.niedermann.nextcloud.deck.ui; +import android.arch.lifecycle.ViewModelProviders; +import android.databinding.DataBindingUtil; import android.os.Bundle; import com.google.android.material.tabs.TabLayout; import androidx.viewpager.widget.ViewPager; @@ -12,7 +14,9 @@ import butterknife.ButterKnife; import butterknife.Unbinder; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.SupportUtil; +import it.niedermann.nextcloud.deck.databinding.ActivityEditBinding; import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.model.viewmodel.FullCardViewModel; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.ui.card.CardTabAdapter; @@ -21,7 +25,6 @@ import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ public class EditActivity extends AppCompatActivity { - FullCard card; SyncManager syncManager; @BindView(R.id.title) @@ -36,6 +39,7 @@ public class EditActivity extends AppCompatActivity { @BindView(R.id.pager) ViewPager pager; + FullCardViewModel fullCardViewModel; private Unbinder unbinder; private long accountId; @@ -44,36 +48,46 @@ public class EditActivity extends AppCompatActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.activity_edit); + + + fullCardViewModel = ViewModelProviders.of(this) + .get(FullCardViewModel.class); + + ActivityEditBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_edit); + + // Assign the component to a property in the binding class. + binding.setLifecycleOwner(this); + binding.setEditmodel(fullCardViewModel); + + //setContentView(R.layout.activity_edit); unbinder = ButterKnife.bind(this); + Bundle extras = getIntent().getExtras(); if (extras != null) { accountId = extras.getLong(BUNDLE_KEY_ACCOUNT_ID); localId = extras.getLong(BUNDLE_KEY_LOCAL_ID); syncManager = new SyncManager(getApplicationContext(), this); - syncManager.getCardByLocalId(accountId, localId) - .observe(EditActivity.this, (FullCard card) -> { - this.card = card; - if (this.card != null) { - title.setText(this.card.getCard().getTitle()); - if (this.card.getCard().getCreatedAt() != null - && this.card.getCard().getLastModified() != null) { - timestamps.setText( - getString( - R.string.modified_created_time, - SupportUtil.getRelativeDateTimeString( - this, - this.card.getCard().getLastModified().getTime()), - SupportUtil.getRelativeDateTimeString( - this, - this.card.getCard().getCreatedAt().getTime()) - ) - ); - } - } - }); + fullCardViewModel.fullCard = syncManager.getCardByLocalId(accountId, localId); + fullCardViewModel.fullCard.observe(EditActivity.this, (FullCard card) -> { + if (card != null) { + if (card.getCard().getCreatedAt() != null + && card.getCard().getLastModified() != null) { + timestamps.setText( + getString( + R.string.modified_created_time, + SupportUtil.getRelativeDateTimeString( + this, + card.getCard().getLastModified().getTime()), + SupportUtil.getRelativeDateTimeString( + this, + card.getCard().getCreatedAt().getTime()) + ) + ); + } + } + }); } else { throw new IllegalArgumentException("No localId argument"); } @@ -94,7 +108,8 @@ public class EditActivity extends AppCompatActivity { @Override protected void onPause() { - syncManager.updateCard(this.card.card); + // TODO ???? + syncManager.updateCard(fullCardViewModel.fullCard.getValue().card); super.onPause(); } 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 ffa1ec430..cb4c357eb 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 @@ -2,7 +2,9 @@ package it.niedermann.nextcloud.deck.ui.card; import android.app.DatePickerDialog; import android.app.TimePickerDialog; +import android.arch.lifecycle.ViewModelProviders; import android.content.res.ColorStateList; +import android.databinding.DataBindingUtil; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.net.Uri; @@ -18,7 +20,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.DatePicker; -import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -43,9 +44,11 @@ import it.niedermann.nextcloud.deck.ColorUtil; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.SupportUtil; +import it.niedermann.nextcloud.deck.databinding.FragmentCardEditTabDetailsBinding; 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.model.viewmodel.FullCardViewModel; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.ui.widget.DelayedAutoCompleteTextView; @@ -56,6 +59,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On TimePickerDialog.OnTimeSetListener { private static final String TAG = CardDetailsFragment.class.getCanonicalName(); + private FullCardViewModel fullCardViewModel; private FullCard card; private SyncManager syncManager; private DateFormat dateFormat; @@ -80,9 +84,6 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On @BindView(R.id.labelsGroup) ChipGroup labelsGroup; - @BindView(R.id.description) - EditText description; - public static CardDetailsFragment newInstance(long accountId, long localId) { Bundle bundle = new Bundle(); bundle.putLong(BUNDLE_KEY_ACCOUNT_ID, accountId); @@ -99,8 +100,17 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On ViewGroup container, Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_card_edit_tab_details, container, false); - unbinder = ButterKnife.bind(this, view); + + fullCardViewModel = ViewModelProviders.of(this) + .get(FullCardViewModel.class); + + + FragmentCardEditTabDetailsBinding binding = DataBindingUtil.inflate(inflater, R.layout.fragment_card_edit_tab_details, container, false); + + binding.setLifecycleOwner(this); + binding.setEditmodel(fullCardViewModel); + + unbinder = ButterKnife.bind(this, binding.getRoot()); dateFormat = android.text.format.DateFormat.getDateFormat(getActivity()); //dueTime = android.text.format.DateFormat.getTimeFormat(getActivity()); @@ -112,30 +122,27 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On setupView(accountId, localId); } - return view; + return binding.getRoot(); } private void setupView(long accountId, long localId) { syncManager = new SyncManager(getActivity().getApplicationContext(), getActivity()); - syncManager.getCardByLocalId(accountId, localId) - .observe(CardDetailsFragment.this, (FullCard card) -> { - // TODO read/set available card details data - this.card = card; - if (this.card != null) { - // people - setupPeople(accountId); + this.fullCardViewModel.fullCard = syncManager.getCardByLocalId(accountId, localId); + this.fullCardViewModel.fullCard.observe(CardDetailsFragment.this, (FullCard card) -> { + // TODO read/set available card details data + this.card = card; + if (this.card != null) { + // people + setupPeople(accountId); - // labels - setupLabels(); + // labels + setupLabels(); - // due date - setupDueDate(); - - // description - setupDescription(); - } - }); + // due date + setupDueDate(); + } + }); dueDate.setOnClickListener(v -> { int year; @@ -176,12 +183,6 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On }); } - private void setupDescription() { - if (this.card.getCard().getDescription() != null) { - description.setText(this.card.getCard().getDescription()); - } - } - private void setupDueDate() { if (this.card.getCard().getDueDate() != null) { dueDate.setText(dateFormat.format(this.card.getCard().getDueDate())); @@ -244,7 +245,7 @@ public class CardDetailsFragment extends Fragment implements DatePickerDialog.On ImageView avatar; String baseUrl = account.url; int px = SupportUtil.getAvatarDimension(getContext()); - int margin = SupportUtil.dpToPx(getContext(),8); + int margin = SupportUtil.dpToPx(getContext(), 8); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(px, px); params.setMargins( 0, 0, margin, 0); diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml index 087f77915..ba09053d5 100644 --- a/app/src/main/res/layout/activity_edit.xml +++ b/app/src/main/res/layout/activity_edit.xml @@ -1,40 +1,50 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical"> - - <EditText - android:id="@+id/title" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:hint="@string/label_title" - android:importantForAutofill="no" - android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" - android:inputType="textPersonName" /> - - <TextView - android:id="@+id/timestamps" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginBottom="16dp" - android:layout_marginLeft="19dp" - android:layout_marginRight="19dp" - tools:text="Modified: 12 days ago Created: 12 days ago"/> - - <com.google.android.material.tabs.TabLayout - android:id="@+id/tab_layout" - android:layout_width="match_parent" - android:layout_height="wrap_content" - app:tabGravity="center" - app:tabMode="fixed" /> +<layout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> - <androidx.viewpager.widget.ViewPager - android:id="@+id/pager" + <data> + <variable + name="editmodel" + type="it.niedermann.nextcloud.deck.model.viewmodel.FullCardViewModel" /> + </data> + + <LinearLayout xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="fill_parent"/> + android:layout_height="match_parent" + android:orientation="vertical"> + + + <EditText + android:id="@+id/title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="16dp" + android:layout_marginRight="16dp" + android:text="@{editmodel.fullCard.card.title}" + android:hint="@string/label_title" + android:importantForAutofill="no" + android:inputType="textPersonName" /> + + <TextView + android:id="@+id/timestamps" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginLeft="19dp" + android:layout_marginRight="19dp" + android:layout_marginBottom="16dp" + tools:text="Modified: 12 days ago Created: 12 days ago" /> + + <com.google.android.material.tabs.TabLayout + android:id="@+id/tab_layout" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:tabGravity="center" + app:tabMode="fixed" /> + + <androidx.viewpager.widget.ViewPager + android:id="@+id/pager" + android:layout_width="match_parent" + android:layout_height="fill_parent" /> -</LinearLayout>
\ No newline at end of file + </LinearLayout> +</layout>
\ No newline at end of file diff --git a/app/src/main/res/layout/fragment_card_edit_tab_details.xml b/app/src/main/res/layout/fragment_card_edit_tab_details.xml index 8bb5c938e..4dd57bcee 100644 --- a/app/src/main/res/layout/fragment_card_edit_tab_details.xml +++ b/app/src/main/res/layout/fragment_card_edit_tab_details.xml @@ -1,151 +1,162 @@ <?xml version="1.0" encoding="utf-8"?> -<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:fillViewport="true"> -<LinearLayout - xmlns:app="http://schemas.android.com/apk/res-auto" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:padding="16dp" - android:orientation="vertical"> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal"> +<layout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> - <ImageView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="12dp" - android:layout_marginEnd="@dimen/standard_margin" - android:layout_marginRight="@dimen/standard_margin" - android:contentDescription="@null" - app:srcCompat="@drawable/ic_person_grey600_24dp" /> - - <it.niedermann.nextcloud.deck.ui.widget.DelayedAutoCompleteTextView - android:id="@+id/people" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:hint="@string/hint_assign_people" /> - </LinearLayout> + <data> - <LinearLayout - android:id="@+id/peopleList" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal" - android:layout_marginStart="40dp" - android:layout_marginLeft="40dp"/> + <variable + name="editmodel" + type="it.niedermann.nextcloud.deck.model.viewmodel.FullCardViewModel" /> + </data> - <LinearLayout + <ScrollView android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal"> + android:layout_height="match_parent" + android:fillViewport="true"> - <ImageView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="12dp" - android:layout_marginEnd="@dimen/standard_margin" - android:layout_marginRight="@dimen/standard_margin" - android:contentDescription="@null" - app:srcCompat="@drawable/ic_label_grey600_24dp" /> - - <AutoCompleteTextView - android:id="@+id/labels" + <LinearLayout xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:hint="@string/label_labels" /> - </LinearLayout> - - <com.google.android.material.chip.ChipGroup - android:id="@+id/labelsGroup" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:layout_marginLeft="40dp" - android:layout_marginStart="40dp" /> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="horizontal"> - - <ImageView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="12dp" - android:layout_marginEnd="@dimen/standard_margin" - android:layout_marginRight="@dimen/standard_margin" - android:contentDescription="@null" - app:srcCompat="@drawable/calendar_blank_grey600_24dp" /> - - <EditText - android:id="@+id/dueDateDate" - android:layout_width="116dp" - android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:drawablePadding="4dp" - android:enabled="true" - android:focusable="false" - android:hint="@string/hint_due_date_date" - android:maxLines="1" - android:padding="4dp" - android:textAlignment="center" - tools:text="01/07/2020" /> - - <EditText - android:id="@+id/dueDateTime" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="8dp" - android:drawablePadding="4dp" - android:enabled="true" - android:focusable="false" - android:hint="@string/hint_due_date_time" - android:maxLines="1" - android:minLines="0" - android:padding="4dp" - android:textAlignment="center" - tools:text="11:45" /> - - <ImageView - android:id="@+id/clearDueDate" - android:layout_width="wrap_content" - android:layout_height="match_parent" - android:paddingLeft="4dp" - android:paddingTop="6dp" - android:paddingRight="4dp" - app:srcCompat="@drawable/ic_close_circle_grey600" /> - </LinearLayout> - - <LinearLayout - android:layout_width="match_parent" - android:layout_height="0dp" - android:layout_weight="1" - android:orientation="horizontal"> - - <ImageView - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_marginTop="12dp" - android:layout_marginEnd="@dimen/standard_margin" - android:layout_marginRight="@dimen/standard_margin" - android:contentDescription="@null" - app:srcCompat="@drawable/ic_format_align_left_black_24dp" /> - - <EditText - android:id="@+id/description" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:gravity="top" - android:hint="@string/label_description" - android:inputType="textMultiLine|textCapSentences" - android:scrollbars="vertical" - /> - </LinearLayout> - -</LinearLayout> - </ScrollView>
\ No newline at end of file + android:orientation="vertical" + android:padding="16dp"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:layout_marginEnd="@dimen/standard_margin" + android:layout_marginRight="@dimen/standard_margin" + android:contentDescription="@null" + app:srcCompat="@drawable/ic_person_grey600_24dp" /> + + <it.niedermann.nextcloud.deck.ui.widget.DelayedAutoCompleteTextView + android:id="@+id/people" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="@string/hint_assign_people" /> + </LinearLayout> + + <LinearLayout + android:id="@+id/peopleList" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="40dp" + android:layout_marginLeft="40dp" + android:orientation="horizontal" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:layout_marginEnd="@dimen/standard_margin" + android:layout_marginRight="@dimen/standard_margin" + android:contentDescription="@null" + app:srcCompat="@drawable/ic_label_grey600_24dp" /> + + <AutoCompleteTextView + android:id="@+id/labels" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:hint="@string/label_labels" /> + </LinearLayout> + + <com.google.android.material.chip.ChipGroup + android:id="@+id/labelsGroup" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginStart="40dp" + android:layout_marginLeft="40dp" /> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:layout_marginEnd="@dimen/standard_margin" + android:layout_marginRight="@dimen/standard_margin" + android:contentDescription="@null" + app:srcCompat="@drawable/calendar_blank_grey600_24dp" /> + + <EditText + android:id="@+id/dueDateDate" + android:layout_width="116dp" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:drawablePadding="4dp" + android:enabled="true" + android:focusable="false" + android:hint="@string/hint_due_date_date" + android:maxLines="1" + android:padding="4dp" + android:textAlignment="center" + tools:text="01/07/2020" /> + + <EditText + android:id="@+id/dueDateTime" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="8dp" + android:drawablePadding="4dp" + android:enabled="true" + android:focusable="false" + android:hint="@string/hint_due_date_time" + android:maxLines="1" + android:minLines="0" + android:padding="4dp" + android:textAlignment="center" + tools:text="11:45" /> + + <ImageView + android:id="@+id/clearDueDate" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:paddingLeft="4dp" + android:paddingTop="6dp" + android:paddingRight="4dp" + app:srcCompat="@drawable/ic_close_circle_grey600" /> + </LinearLayout> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="0dp" + android:layout_weight="1" + android:orientation="horizontal"> + + <ImageView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginTop="12dp" + android:layout_marginEnd="@dimen/standard_margin" + android:layout_marginRight="@dimen/standard_margin" + android:contentDescription="@null" + app:srcCompat="@drawable/ic_format_align_left_black_24dp" /> + + <EditText + android:id="@+id/description" + android:text="@{editmodel.fullCard.card.description}" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="top" + android:hint="@string/label_description" + android:inputType="textMultiLine|textCapSentences" + android:scrollbars="vertical" /> + </LinearLayout> + + </LinearLayout> + </ScrollView> +</layout>
\ No newline at end of file |