diff options
author | desperateCoder <echotodevnull@gmail.com> | 2019-02-08 16:49:39 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2019-02-08 16:49:39 +0300 |
commit | c39bd5a9b5288ef12d6a337994d34dcf459bb546 (patch) | |
tree | 5f83a440be094bf340520c1aaeab00171d722b9c /app | |
parent | 5234c4ef82a02a436f6924b1a600926be5d078b9 (diff) | |
parent | 5de5c3b41d37673046683634bd91979f2d1479bf (diff) |
Merge branch 'edit' of github.com:stefan-niedermann/nextcloud-deck into edit
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/EditActivity.java | 33 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java | 57 |
2 files changed, 62 insertions, 28 deletions
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 f2da0183a..e9bd428cd 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 @@ -10,11 +10,21 @@ import android.widget.TextView; 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.model.Card; +import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.ui.card.CardTabAdapter; +import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_ACCOUNT_ID; +import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ID; + public class EditActivity extends AppCompatActivity { + FullCard card; + SyncManager syncManager; + @BindView(R.id.title) EditText title; @@ -35,6 +45,23 @@ public class EditActivity extends AppCompatActivity { setContentView(R.layout.activity_edit); unbinder = ButterKnife.bind(this); + Bundle extras = getIntent().getExtras(); + if (extras != null) { + syncManager = new SyncManager(getApplicationContext(), this); + + syncManager.getCardByLocalId( + extras.getLong(BUNDLE_KEY_ACCOUNT_ID), + extras.getLong(BUNDLE_KEY_LOCAL_ID) + ).observe(EditActivity.this, (FullCard card) -> { + this.card = card; + if(this.card != null) { + title.setText(this.card.getCard().getTitle()); + } + }); + } else { + throw new IllegalArgumentException("No localId argument"); + } + setupViewPager(); } @@ -48,4 +75,10 @@ public class EditActivity extends AppCompatActivity { tabLayout.setupWithViewPager(pager); } + + @Override + protected void onPause() { + super.onPause(); + syncManager.updateCard(this.card.card); + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java index ad5a93485..a83fe8ab0 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java @@ -36,6 +36,8 @@ import it.niedermann.nextcloud.deck.ui.EditActivity; public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder> { private static final String TAG = CardAdapter.class.getCanonicalName(); + public static final String BUNDLE_KEY_ACCOUNT_ID = "accountId"; + public static final String BUNDLE_KEY_LOCAL_ID = "localId"; private Context context; private List<FullCard> cardList = new ArrayList<>(); @@ -51,6 +53,33 @@ public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder @Override public void onBindViewHolder(@NonNull CardViewHolder viewHolder, int position) { FullCard card = cardList.get(position); + + viewHolder.card.setOnClickListener((View clickedView) -> { + Intent intent = new Intent(clickedView.getContext(), EditActivity.class); + intent.putExtra(BUNDLE_KEY_ACCOUNT_ID, card.getAccountId()); + intent.putExtra(BUNDLE_KEY_LOCAL_ID, card.getLocalId()); + context.startActivity(intent); + }); + viewHolder.card.setOnLongClickListener((View draggedView) -> { + + // Create a new ClipData. + // This is done in two steps to provide clarity. The convenience method + // ClipData.newPlainText() can create a plain text ClipData in one step. + + // Create a new ClipData.Item from the ImageView object's tag + ClipData dragData = ClipData.newPlainText("TEST", "TEST2"); + + // Starts the drag + draggedView.startDrag(dragData, // the data to be dragged + new View.DragShadowBuilder(draggedView), // the drag shadow builder + draggedView, // no need to use local data + 0 // flags (not currently used, set to 0) + ); + viewHolder.card.setVisibility(View.INVISIBLE); + DeckLog.log("onLongClickListener"); + return true; + }); + viewHolder.cardTitle.setText(card.getCard().getTitle()); if (card.getCard().getDescription() != null && !card.getCard().getDescription().isEmpty()) { @@ -187,34 +216,6 @@ public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder private CardViewHolder(View view) { super(view); ButterKnife.bind(this, view); - card.setOnClickListener((View clickedView) -> { - if (Build.VERSION.SDK_INT >= 16) { - cardDescription.setMaxLines(cardDescription.getMaxLines() == 3 ? Integer.MAX_VALUE : 3); - } - }); - card.setOnClickListener((View clickedView) -> { - Intent intent = new Intent(clickedView.getContext(), EditActivity.class); - clickedView.getContext().startActivity(intent); - }); - card.setOnLongClickListener((View draggedView) -> { - - // Create a new ClipData. - // This is done in two steps to provide clarity. The convenience method - // ClipData.newPlainText() can create a plain text ClipData in one step. - - // Create a new ClipData.Item from the ImageView object's tag - ClipData dragData = ClipData.newPlainText("TEST", "TEST2"); - - // Starts the drag - draggedView.startDrag(dragData, // the data to be dragged - new View.DragShadowBuilder(draggedView), // the drag shadow builder - draggedView, // no need to use local data - 0 // flags (not currently used, set to 0) - ); - view.setVisibility(View.INVISIBLE); - DeckLog.log("onLongClickListener"); - return true; - }); } } } |