Skip to content

Commit

Permalink
#248 Add Deck as a "share to" location
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-niedermann committed Mar 15, 2020
1 parent d469d5f commit fc711d8
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 19 deletions.
45 changes: 34 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
<application
android:name="it.niedermann.nextcloud.deck.Application"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:hardwareAccelerated="true"
android:theme="@style/AppTheme"
android:networkSecurityConfig="@xml/network_security_config"
tools:ignore="GoogleAppIndexingWarning">

<activity
android:name=".ui.MainActivity"
android:label="@string/app_name_short"
android:theme="@style/SplashTheme">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -40,22 +41,44 @@
android:value=".ui.MainActivity" />
</activity>

<activity
android:name=".ui.SelectCardActivity"
android:label="@string/app_name_short"
android:theme="@style/SplashTheme">

<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>

<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<meta-data
android:name="android.app.default_searchable"
android:value=".ui.MainActivity" />
</activity>

<activity
android:name=".ui.EditActivity"
android:label="@string/edit"
android:theme="@style/AppTheme"
android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity" />
android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity"
android:theme="@style/AppTheme" />

<activity
android:name=".ui.AttachmentsActivity"
android:theme="@style/TransparentTheme"
android:parentActivityName="it.niedermann.nextcloud.deck.ui.EditActivity" />
android:parentActivityName="it.niedermann.nextcloud.deck.ui.EditActivity"
android:theme="@style/TransparentTheme" />

<activity
android:name=".ui.SettingsActivity"
android:label="@string/simple_settings"
android:theme="@style/AppTheme"
android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity" />
android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity"
android:theme="@style/AppTheme" />

<activity
android:name=".ui.ImportAccountActivity"
Expand All @@ -65,18 +88,18 @@
<activity
android:name=".ui.AboutActivity"
android:label="@string/about"
android:theme="@style/AppTheme"
android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity" />
android:parentActivityName="it.niedermann.nextcloud.deck.ui.MainActivity"
android:theme="@style/AppTheme" />

<activity
android:name=".ui.exception.ExceptionActivity"
android:process=":error_activity" />

<service
android:name=".ui.tiles.EditCardTileService"
android:description="@string/add_a_new_card_using_the_button"
android:icon="@drawable/ic_app_logo"
android:label="@string/add_card"
android:description="@string/add_a_new_card_using_the_button"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package it.niedermann.nextcloud.deck.ui;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

import androidx.annotation.NonNull;

import java.io.File;

import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.model.full.FullCard;
import it.niedermann.nextcloud.deck.ui.card.CardAdapter;
import it.niedermann.nextcloud.deck.util.FileUtils;

public class SelectCardActivity extends MainActivity implements CardAdapter.SelectCardListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding.addStackButton.setVisibility(View.GONE);
}

@Override
public void onCardSelected(FullCard fullCard) {
Intent receivedIntent = getIntent();
String receivedAction = receivedIntent.getAction();
String receivedType = receivedIntent.getType();
DeckLog.info(receivedAction);
DeckLog.info(receivedType);
if (receivedType != null) {
if (receivedType.startsWith("text/")) {
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT);
if (receivedText != null) {
appendText(fullCard, receivedText);
} else {
DeckLog.warn("Did not receive any text.");
}
} else if (receivedType.startsWith("image/")) {
Uri receivedUri = receivedIntent.getParcelableExtra(Intent.EXTRA_STREAM);
if (receivedUri != null) {
appendAttachment(fullCard, receivedUri);
} else {
DeckLog.warn("Did not receive any extra.");
}
}
syncManager.updateCard(fullCard);
} else {
DeckLog.logError(new IllegalArgumentException("receivedType must not be null for " + SelectCardActivity.class.getCanonicalName()));
}
finish();
}

private void appendText(@NonNull FullCard fullCard, @NonNull String receivedText) {
DeckLog.log(receivedText);
String oldDescription = fullCard.getCard().getDescription();
if (oldDescription == null || oldDescription.length() == 0) {
fullCard.getCard().setDescription(receivedText);
} else {
fullCard.getCard().setDescription(oldDescription + "\n\n" + receivedText);
}
}

private void appendAttachment(@NonNull FullCard fullCard, @NonNull Uri uri) {
DeckLog.info("Uri: " + uri.toString());
String path = FileUtils.getPath(this, uri);
if (path != null) {
File uploadFile = new File(path);
syncManager.addAttachmentToCard(fullCard.getAccountId(), fullCard.getCard().getLocalId(), Attachment.getMimetypeForUri(this, uri), uploadFile);
} else {
DeckLog.warn("path to file is null");
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
Expand Down Expand Up @@ -75,15 +76,23 @@ public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ItemCardViewHo
private LifecycleOwner lifecycleOwner;
private List<FullStack> availableStacks = new ArrayList<>();

@Nullable
private final SelectCardListener selectCardListener;

private int maxAvatarCount;
private int maxLabelsShown;
private int maxLabelsChars;

public CardAdapter(long boardId, boolean canEdit, @NonNull SyncManager syncManager, @NonNull Fragment fragment) {
this(boardId, canEdit, syncManager, fragment, null);
}

public CardAdapter(long boardId, boolean canEdit, @NonNull SyncManager syncManager, @NonNull Fragment fragment, @Nullable SelectCardListener selectCardListener) {
this.lifecycleOwner = fragment;
this.boardId = boardId;
this.canEdit = canEdit;
this.syncManager = syncManager;
this.selectCardListener = selectCardListener;
}

@NonNull
Expand Down Expand Up @@ -113,14 +122,18 @@ public void onBindViewHolder(@NonNull ItemCardViewHolder viewHolder, int positio
FullCard card = cardList.get(position);

viewHolder.binding.card.setOnClickListener((View clickedView) -> {
Intent intent = new Intent(clickedView.getContext(), EditActivity.class);
intent.putExtra(BUNDLE_KEY_ACCOUNT_ID, card.getAccountId());
intent.putExtra(BUNDLE_KEY_BOARD_ID, boardId);
intent.putExtra(BUNDLE_KEY_LOCAL_ID, card.getLocalId());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
if (selectCardListener == null) {
Intent intent = new Intent(clickedView.getContext(), EditActivity.class);
intent.putExtra(BUNDLE_KEY_ACCOUNT_ID, card.getAccountId());
intent.putExtra(BUNDLE_KEY_BOARD_ID, boardId);
intent.putExtra(BUNDLE_KEY_LOCAL_ID, card.getLocalId());
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} else {
selectCardListener.onCardSelected(card);
}
});
if (canEdit) {
if (canEdit && selectCardListener == null) {
viewHolder.binding.card.setOnLongClickListener((View draggedView) -> {
ClipData dragData = ClipData.newPlainText("cardid", card.getLocalId() + "");

Expand Down Expand Up @@ -402,4 +415,8 @@ private ItemCardViewHolder(ItemCardBinding binding) {
this.binding = binding;
}
}

public interface SelectCardListener {
void onCardSelected(FullCard fullCard);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,

syncManager = new SyncManager(activity);

adapter = new CardAdapter(boardId, getArguments().getBoolean(KEY_HAS_EDIT_PERMISSION), syncManager, this);
if(requireActivity() instanceof CardAdapter.SelectCardListener) {
adapter = new CardAdapter(boardId, getArguments().getBoolean(KEY_HAS_EDIT_PERMISSION), syncManager, this, (CardAdapter.SelectCardListener) requireActivity());
} else {
adapter = new CardAdapter(boardId, getArguments().getBoolean(KEY_HAS_EDIT_PERMISSION), syncManager, this);
}
binding.recyclerView.setAdapter(adapter);
if (onScrollListener != null) {
binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
Expand Down
Empty file.
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/4000.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- #248 Add Deck as a "share to" location

0 comments on commit fc711d8

Please sign in to comment.