diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-26 20:07:30 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-04-26 20:07:30 +0300 |
commit | b9505b39d6edec0707cef1585e2b318587f4eb11 (patch) | |
tree | 875e9217c737613b1ff5b2f8e61fa668b0e96035 /app/src/main | |
parent | 6d8a43aaf0c7d5ac033fe7066557cfecd118ee04 (diff) |
Fix #424 Deck as a "share to" location -> create new card
Diffstat (limited to 'app/src/main')
8 files changed, 68 insertions, 20 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3de20e21a..1bd2ad936 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -87,8 +87,16 @@ <activity android:name=".ui.preparecreate.PrepareCreateActivity" - android:label="@string/simple_select" - android:theme="@style/AppTheme" /> + android:description="@string/add_a_new_card_using_the_button" + android:label="@string/add_card" + android:theme="@style/AppTheme"> + + <intent-filter> + <action android:name="android.intent.action.SEND" /> + <category android:name="android.intent.category.DEFAULT" /> + <data android:mimeType="text/*" /> + </intent-filter> + </activity> <activity android:name=".ui.about.AboutActivity" diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java index e6308ec63..9d67de48e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/MainActivity.java @@ -256,7 +256,7 @@ public class MainActivity extends BrandedActivity implements DeleteStackListener if (this.boardsList.size() > 0) { try { Long stackId = stackAdapter.getItem(binding.viewPager.getCurrentItem()).getLocalId(); - startActivity(EditActivity.createIntent(this, viewModel.getCurrentAccount(), viewModel.getCurrentBoardLocalId(), stackId, NO_LOCAL_ID)); + startActivity(EditActivity.createNewCardIntent(this, viewModel.getCurrentAccount(), viewModel.getCurrentBoardLocalId(), stackId, NO_LOCAL_ID)); } catch (IndexOutOfBoundsException e) { EditStackDialogFragment.newInstance(NO_STACK_ID).show(getSupportFragmentManager(), addList); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java index 0eedd68a7..f3d462c90 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/PushNotificationActivity.java @@ -159,7 +159,7 @@ public class PushNotificationActivity extends AppCompatActivity implements Brand DeckLog.logError(t); } DeckLog.info("starting " + EditActivity.class.getSimpleName() + " with [" + account + ", " + boardId + ", " + cardId + "]"); - startActivity(EditActivity.createIntent(this, account, boardId, cardId)); + startActivity(EditActivity.createEditCardIntent(this, account, boardId, cardId)); finish(); } 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 dab0c955f..e9092ee68 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 @@ -49,8 +49,6 @@ public class CardAdapter extends RecyclerView.Adapter<ItemCardViewHolder> implem public static final String BUNDLE_KEY_ACCOUNT = "account"; public static final String BUNDLE_KEY_LOCAL_ID = "localId"; - public static final String BUNDLE_KEY_BOARD_ID = "boardId"; - public static final String BUNDLE_KEY_STACK_ID = "stackId"; public static final Long NO_LOCAL_ID = -1L; protected final SyncManager syncManager; @@ -111,7 +109,7 @@ public class CardAdapter extends RecyclerView.Adapter<ItemCardViewHolder> implem viewHolder.binding.card.setOnClickListener((v) -> { if (selectCardListener == null) { - context.startActivity(EditActivity.createIntent(context, account, boardId, card.getCard().getStackId(), card.getLocalId())); + context.startActivity(EditActivity.createNewCardIntent(context, account, boardId, card.getCard().getStackId(), card.getLocalId())); } else { selectCardListener.onCardSelected(card); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java index 5cdc03c5e..9963ec50f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/EditActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.view.Menu; import android.view.MenuInflater; @@ -28,13 +29,14 @@ import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler; import it.niedermann.nextcloud.deck.util.CardUtil; import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce; -import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_ACCOUNT; -import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_BOARD_ID; -import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_LOCAL_ID; -import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.BUNDLE_KEY_STACK_ID; -import static it.niedermann.nextcloud.deck.ui.card.CardAdapter.NO_LOCAL_ID; public class EditActivity extends BrandedActivity { + private static final String BUNDLE_KEY_ACCOUNT = "account"; + private static final String BUNDLE_KEY_LOCAL_ID = "localId"; + private static final String BUNDLE_KEY_BOARD_ID = "boardId"; + private static final String BUNDLE_KEY_STACK_ID = "stackId"; + private static final String BUNDLE_KEY_TITLE = "title"; + private static final Long NO_LOCAL_ID = -1L; private ActivityEditBinding binding; private EditCardViewModel viewModel; @@ -107,6 +109,14 @@ public class EditActivity extends BrandedActivity { invalidateOptionsMenu(); if (viewModel.isCreateMode()) { viewModel.initializeNewCard(account, boardId, args.getLong(BUNDLE_KEY_STACK_ID)); + String title = args.getString(BUNDLE_KEY_TITLE); + if (!TextUtils.isEmpty(title)) { + if (title.length() >= 100) { + viewModel.getFullCard().getCard().setDescription(title); + } else { + viewModel.getFullCard().getCard().setTitle(title); + } + } setupViewPager(); setupTitle(viewModel.isCreateMode()); } else { @@ -225,7 +235,6 @@ public class EditActivity extends BrandedActivity { } }); } else { -// binding.titleTextInputLayout.setHintEnabled(false); binding.title.setEnabled(false); } } @@ -261,17 +270,22 @@ public class EditActivity extends BrandedActivity { final int highlightColor = Color.argb(77, Color.red(textColor), Color.green(textColor), Color.blue(textColor)); binding.title.setHighlightColor(highlightColor); binding.title.setTextColor(textColor); -// DrawableCompat.setTintList(binding.title.getBackground(), ColorStateList.valueOf(textColor)); } @NonNull - public static Intent createIntent(@NonNull Context context, @NonNull Account account, Long boardId, Long stackId, Long cardId) { - return createIntent(context, account, boardId, cardId) + public static Intent createNewCardIntent(@NonNull Context context, @NonNull Account account, Long boardId, Long stackId, Long cardId, @NonNull String title) { + return createNewCardIntent(context, account, boardId, stackId, cardId) + .putExtra(BUNDLE_KEY_TITLE, title); + } + + @NonNull + public static Intent createNewCardIntent(@NonNull Context context, @NonNull Account account, Long boardId, Long stackId, Long cardId) { + return createEditCardIntent(context, account, boardId, cardId) .putExtra(BUNDLE_KEY_STACK_ID, stackId); } @NonNull - public static Intent createIntent(@NonNull Context context, @NonNull Account account, Long boardId, Long cardId) { + public static Intent createEditCardIntent(@NonNull Context context, @NonNull Account account, Long boardId, Long cardId) { return new Intent(context, EditActivity.class) .putExtra(BUNDLE_KEY_ACCOUNT, account) .putExtra(BUNDLE_KEY_BOARD_ID, boardId) diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java index 1e861720c..b949134b2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/preparecreate/PrepareCreateActivity.java @@ -1,7 +1,9 @@ package it.niedermann.nextcloud.deck.ui.preparecreate; +import android.content.ClipData; import android.content.Intent; import android.os.Bundle; +import android.text.TextUtils; import android.widget.ArrayAdapter; import android.widget.Toast; @@ -174,7 +176,12 @@ public class PrepareCreateActivity extends BrandedActivity { if (account != null) { final long boardId = binding.boardSelect.getSelectedItemId(); final long stackId = binding.stackSelect.getSelectedItemId(); - startActivity(EditActivity.createIntent(this, account, boardId, stackId, NO_LOCAL_ID)); + final String receivedClipData = getReceivedClipData(getIntent()); + if (receivedClipData == null) { + startActivity(EditActivity.createNewCardIntent(this, account, boardId, stackId, NO_LOCAL_ID)); + } else { + startActivity(EditActivity.createNewCardIntent(this, account, boardId, stackId, NO_LOCAL_ID, receivedClipData)); + } Application.saveCurrentAccountId(this, account.getId()); Application.saveCurrentBoardId(this, account.getId(), boardId); @@ -189,6 +196,27 @@ public class PrepareCreateActivity extends BrandedActivity { } } + @Nullable + private static String getReceivedClipData(@Nullable Intent intent) { + if (intent == null) { + return null; + } + final ClipData clipData = intent.getClipData(); + if (clipData == null) { + return null; + } + final int itemCount = clipData.getItemCount(); + if (itemCount <= 0) { + return null; + } + final ClipData.Item item = clipData.getItemAt(0); + if (item == null) { + return null; + } + final CharSequence text = item.getText(); + return TextUtils.isEmpty(text) ? null : text.toString(); + } + private void applyTemporaryBrand(@Nullable Account account) { try { if (account != null && brandingEnabled) { diff --git a/app/src/main/res/layout/activity_prepare_create.xml b/app/src/main/res/layout/activity_prepare_create.xml index d67221759..932e74855 100644 --- a/app/src/main/res/layout/activity_prepare_create.xml +++ b/app/src/main/res/layout/activity_prepare_create.xml @@ -84,6 +84,6 @@ android:layout_marginStart="@dimen/spacer_1x" android:layout_marginLeft="@dimen/spacer_1x" android:layout_weight=".5" - android:text="@string/add_card" /> + android:text="@string/simple_add" /> </LinearLayout> </RelativeLayout>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d9deb9e88..d754910e5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -87,7 +87,7 @@ <string name="add_account">Add account</string> <string name="choose_account">Choose account</string> - <string name="add_card">Add card</string> + <string name="add_card">Add new card</string> <string name="activity">Activity</string> <string name="add_list">Add list</string> <string name="rename_list">Rename list</string> |