blob: 93799e138d74a9c0d9d8ba5f6065d86aff43253c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
package it.niedermann.nextcloud.deck.ui;
import android.os.Bundle;
import android.view.MotionEvent;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import it.niedermann.nextcloud.deck.DeckLog;
import it.niedermann.nextcloud.deck.databinding.ActivityAttachmentsBinding;
import it.niedermann.nextcloud.deck.model.Attachment;
import it.niedermann.nextcloud.deck.persistence.sync.SyncManager;
import it.niedermann.nextcloud.deck.ui.attachments.AttachmentAdapter;
import it.niedermann.nextcloud.deck.ui.exception.ExceptionHandler;
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 AttachmentsActivity extends AppCompatActivity {
private ActivityAttachmentsBinding binding;
public static final String BUNDLE_KEY_CURRENT_ATTACHMENT_LOCAL_ID = "currentAttachmenLocaltId";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Thread.currentThread().setUncaughtExceptionHandler(new ExceptionHandler(this));
binding = ActivityAttachmentsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
setSupportActionBar(binding.toolbar);
Bundle extras = getIntent().getExtras();
if (extras == null) {
throw new IllegalArgumentException("Provide localId");
}
long accountId = extras.getLong(BUNDLE_KEY_ACCOUNT_ID);
long cardLocalId = extras.getLong(BUNDLE_KEY_LOCAL_ID);
long currentAttachment = extras.getLong(BUNDLE_KEY_CURRENT_ATTACHMENT_LOCAL_ID);
SyncManager syncManager = new SyncManager(this);
syncManager.readAccount(accountId).observe(this, account ->
syncManager.getCardByLocalId(accountId, cardLocalId).observe(this, fullCard -> {
binding.toolbar.setSubtitle(fullCard.getCard().getTitle());
List<Attachment> attachments = fullCard.getAttachments();
if (fullCard.getAttachments().size() == 0) {
DeckLog.logError(new IllegalStateException(AttachmentsActivity.class.getSimpleName() + " called, but card " + fullCard.getLocalId() + "has no attachments"));
supportFinishAfterTransition();
return;
}
RecyclerView.Adapter adapter = new AttachmentAdapter(account, fullCard.getId(), attachments);
binding.viewPager.setAdapter(adapter);
if (currentAttachment != 0L) {
for (int i = 0; i < attachments.size(); i++) {
if (attachments.get(i).getLocalId() == currentAttachment) {
binding.viewPager.setCurrentItem(i, false);
break;
}
}
}
// TODO
// https://android-developers.googleblog.com/2018/02/continuous-shared-element-transitions.html?m=1
// https://github.com/android/animation-samples/blob/master/GridToPager/app/src/main/java/com/google/samples/gridtopager/fragment/ImagePagerFragment.java
// setEnterSharedElementCallback(new SharedElementCallback() {
// @Override
// public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
// View view = binding.viewPager.getRootView();
// if (view == null) {
// return;
// }
// // Map the first shared element name to the child ImageView.
// sharedElements.put(names.get(0), view.findViewById(R.id.image));
// Log.v("SHARED", "names" + names);
// }
// });
}));
}
@Override
public boolean onTouchEvent(MotionEvent event) {
supportFinishAfterTransition();
return true;
}
@Override
public boolean onSupportNavigateUp() {
supportFinishAfterTransition();
return true;
}
}
|