2017-01-23 16:19:30 +11:00
|
|
|
/* Copyright 2017 Andrew Dawson
|
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This file is a part of Tusky.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
|
|
|
* Tusky is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
2017-04-10 10:12:31 +10:00
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
|
|
|
* Public License for more details.
|
2017-01-23 16:19:30 +11:00
|
|
|
*
|
2017-04-10 10:12:31 +10:00
|
|
|
* You should have received a copy of the GNU General Public License along with Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2017-05-05 08:55:34 +10:00
|
|
|
package com.keylesspalace.tusky.fragment;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2017-09-26 04:15:04 +10:00
|
|
|
import android.content.ClipData;
|
|
|
|
import android.content.ClipboardManager;
|
|
|
|
import android.content.Context;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.annotation.Nullable;
|
2017-07-14 15:26:58 +10:00
|
|
|
import android.support.v4.app.ActivityOptionsCompat;
|
|
|
|
import android.support.v4.view.ViewCompat;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.support.v7.widget.PopupMenu;
|
2017-02-27 16:21:46 +11:00
|
|
|
import android.text.Spanned;
|
2017-01-23 16:19:30 +11:00
|
|
|
import android.view.View;
|
|
|
|
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.AccountActivity;
|
|
|
|
import com.keylesspalace.tusky.ComposeActivity;
|
|
|
|
import com.keylesspalace.tusky.R;
|
|
|
|
import com.keylesspalace.tusky.ReportActivity;
|
2018-02-04 08:45:14 +11:00
|
|
|
import com.keylesspalace.tusky.TuskyApplication;
|
2017-06-25 15:07:41 +10:00
|
|
|
import com.keylesspalace.tusky.ViewMediaActivity;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.ViewTagActivity;
|
|
|
|
import com.keylesspalace.tusky.ViewThreadActivity;
|
|
|
|
import com.keylesspalace.tusky.ViewVideoActivity;
|
2018-02-04 08:45:14 +11:00
|
|
|
import com.keylesspalace.tusky.db.AccountEntity;
|
2018-03-10 08:02:32 +11:00
|
|
|
import com.keylesspalace.tusky.db.AccountManager;
|
2017-12-01 06:12:09 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Attachment;
|
2017-03-09 10:27:37 +11:00
|
|
|
import com.keylesspalace.tusky.entity.Status;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.interfaces.AdapterItemRemover;
|
2018-03-28 04:47:00 +11:00
|
|
|
import com.keylesspalace.tusky.network.TimelineCases;
|
2017-05-05 08:55:34 +10:00
|
|
|
import com.keylesspalace.tusky.util.HtmlUtils;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
2018-04-18 03:06:28 +10:00
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.Set;
|
2017-01-23 16:19:30 +11:00
|
|
|
|
|
|
|
/* Note from Andrew on Jan. 22, 2017: This class is a design problem for me, so I left it with an
|
|
|
|
* awkward name. TimelineFragment and NotificationFragment have significant overlap but the nature
|
|
|
|
* of that is complicated by how they're coupled with Status and Notification and the corresponding
|
|
|
|
* adapters. I feel like the profile pages and thread viewer, which I haven't made yet, will also
|
|
|
|
* overlap functionality. So, I'm momentarily leaving it and hopefully working on those will clear
|
|
|
|
* up what needs to be where. */
|
2017-07-14 11:31:31 +10:00
|
|
|
public abstract class SFragment extends BaseFragment implements AdapterItemRemover {
|
2017-06-30 16:31:58 +10:00
|
|
|
protected static final int COMPOSE_RESULT = 1;
|
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
protected String loggedInAccountId;
|
|
|
|
protected String loggedInUsername;
|
2018-03-28 04:47:00 +11:00
|
|
|
|
|
|
|
protected abstract TimelineCases timelineCases();
|
2017-01-23 16:19:30 +11:00
|
|
|
|
|
|
|
@Override
|
2018-03-10 08:02:32 +11:00
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
AccountEntity activeAccount = TuskyApplication.getInstance(getContext()).getServiceLocator()
|
|
|
|
.get(AccountManager.class).getActiveAccount();
|
|
|
|
if (activeAccount != null) {
|
2018-02-04 08:45:14 +11:00
|
|
|
loggedInAccountId = activeAccount.getAccountId();
|
|
|
|
loggedInUsername = activeAccount.getUsername();
|
|
|
|
}
|
2017-06-30 16:31:58 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startActivity(Intent intent) {
|
|
|
|
super.startActivity(intent);
|
|
|
|
getActivity().overridePendingTransition(R.anim.slide_from_right, R.anim.slide_to_left);
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
|
2018-03-28 04:47:00 +11:00
|
|
|
protected void openReblog(@Nullable final Status status) {
|
|
|
|
if (status == null) return;
|
|
|
|
viewAccount(status.getAccount().getId());
|
|
|
|
}
|
|
|
|
|
2017-01-23 16:19:30 +11:00
|
|
|
protected void reply(Status status) {
|
2017-03-09 10:27:37 +11:00
|
|
|
String inReplyToId = status.getActionableId();
|
2017-04-01 06:47:41 +11:00
|
|
|
Status actionableStatus = status.getActionableStatus();
|
2017-11-17 05:18:11 +11:00
|
|
|
Status.Visibility replyVisibility = actionableStatus.getVisibility();
|
2018-03-03 23:24:03 +11:00
|
|
|
String contentWarning = actionableStatus.getSpoilerText();
|
|
|
|
Status.Mention[] mentions = actionableStatus.getMentions();
|
2018-04-18 03:06:28 +10:00
|
|
|
Set<String> mentionedUsernames = new LinkedHashSet<>();
|
2018-03-03 23:24:03 +11:00
|
|
|
mentionedUsernames.add(actionableStatus.getAccount().getUsername());
|
2017-01-31 15:51:02 +11:00
|
|
|
for (Status.Mention mention : mentions) {
|
2018-03-03 23:24:03 +11:00
|
|
|
mentionedUsernames.add(mention.getUsername());
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
mentionedUsernames.remove(loggedInUsername);
|
2017-11-02 06:59:29 +11:00
|
|
|
Intent intent = new ComposeActivity.IntentBuilder()
|
|
|
|
.inReplyToId(inReplyToId)
|
|
|
|
.replyVisibility(replyVisibility)
|
|
|
|
.contentWarning(contentWarning)
|
|
|
|
.mentionedUsernames(mentionedUsernames)
|
2018-03-03 23:24:03 +11:00
|
|
|
.repyingStatusAuthor(actionableStatus.getAccount().getLocalUsername())
|
|
|
|
.replyingStatusContent(actionableStatus.getContent().toString())
|
2017-11-02 06:59:29 +11:00
|
|
|
.build(getContext());
|
2017-04-16 03:44:29 +10:00
|
|
|
startActivityForResult(intent, COMPOSE_RESULT);
|
|
|
|
}
|
|
|
|
|
2017-07-14 11:31:31 +10:00
|
|
|
protected void more(final Status status, View view, final int position) {
|
2017-03-09 10:27:37 +11:00
|
|
|
final String id = status.getActionableId();
|
2018-03-03 23:24:03 +11:00
|
|
|
final String accountId = status.getActionableStatus().getAccount().getId();
|
|
|
|
final String accountUsename = status.getActionableStatus().getAccount().getUsername();
|
|
|
|
final Spanned content = status.getActionableStatus().getContent();
|
|
|
|
final String statusUrl = status.getActionableStatus().getUrl();
|
2017-01-23 16:19:30 +11:00
|
|
|
PopupMenu popup = new PopupMenu(getContext(), view);
|
|
|
|
// Give a different menu depending on whether this is the user's own toot or not.
|
|
|
|
if (loggedInAccountId == null || !loggedInAccountId.equals(accountId)) {
|
|
|
|
popup.inflate(R.menu.status_more);
|
|
|
|
} else {
|
|
|
|
popup.inflate(R.menu.status_more_for_user);
|
|
|
|
}
|
2018-03-28 04:47:00 +11:00
|
|
|
popup.setOnMenuItemClickListener(item -> {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.status_share_content: {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(status.getAccount().getUsername());
|
|
|
|
sb.append(" - ");
|
|
|
|
sb.append(status.getContent().toString());
|
|
|
|
|
|
|
|
Intent sendIntent = new Intent();
|
|
|
|
sendIntent.setAction(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, sb.toString());
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_content_to)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.status_share_link: {
|
|
|
|
Intent sendIntent = new Intent();
|
|
|
|
sendIntent.setAction(Intent.ACTION_SEND);
|
|
|
|
sendIntent.putExtra(Intent.EXTRA_TEXT, statusUrl);
|
|
|
|
sendIntent.setType("text/plain");
|
|
|
|
startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_status_link_to)));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.status_copy_link: {
|
|
|
|
ClipboardManager clipboard = (ClipboardManager)
|
|
|
|
getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
|
|
|
|
ClipData clip = ClipData.newPlainText(null, statusUrl);
|
|
|
|
clipboard.setPrimaryClip(clip);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.status_mute: {
|
|
|
|
timelineCases().mute(accountId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.status_block: {
|
|
|
|
timelineCases().block(accountId);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.status_report: {
|
|
|
|
openReportPage(accountId, accountUsename, id, content);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.status_delete: {
|
|
|
|
timelineCases().delete(id);
|
|
|
|
removeItem(position);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2017-01-23 16:19:30 +11:00
|
|
|
popup.show();
|
|
|
|
}
|
|
|
|
|
2017-12-01 06:12:09 +11:00
|
|
|
protected void viewMedia(String[] urls, int urlIndex, Attachment.Type type,
|
2017-07-14 15:26:58 +10:00
|
|
|
@Nullable View view) {
|
2017-01-23 16:19:30 +11:00
|
|
|
switch (type) {
|
|
|
|
case IMAGE: {
|
2017-06-25 15:07:41 +10:00
|
|
|
Intent intent = new Intent(getContext(), ViewMediaActivity.class);
|
|
|
|
intent.putExtra("urls", urls);
|
|
|
|
intent.putExtra("urlIndex", urlIndex);
|
2017-07-14 15:26:58 +10:00
|
|
|
if (view != null) {
|
|
|
|
String url = urls[urlIndex];
|
|
|
|
ViewCompat.setTransitionName(view, url);
|
|
|
|
ActivityOptionsCompat options =
|
|
|
|
ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),
|
2018-03-10 08:02:32 +11:00
|
|
|
view, url);
|
2017-07-14 15:26:58 +10:00
|
|
|
startActivity(intent, options.toBundle());
|
|
|
|
} else {
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
break;
|
|
|
|
}
|
2017-03-10 07:21:55 +11:00
|
|
|
case GIFV:
|
2017-01-23 16:19:30 +11:00
|
|
|
case VIDEO: {
|
|
|
|
Intent intent = new Intent(getContext(), ViewVideoActivity.class);
|
2017-06-25 15:07:41 +10:00
|
|
|
intent.putExtra("url", urls[urlIndex]);
|
2017-01-23 16:19:30 +11:00
|
|
|
startActivity(intent);
|
|
|
|
break;
|
|
|
|
}
|
2017-03-06 11:58:36 +11:00
|
|
|
case UNKNOWN: {
|
|
|
|
/* Intentionally do nothing. This case is here is to handle when new attachment
|
|
|
|
* types are added to the API before code is added here to handle them. So, the
|
|
|
|
* best fallback is to just show the preview and ignore requests to view them. */
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void viewThread(Status status) {
|
|
|
|
Intent intent = new Intent(getContext(), ViewThreadActivity.class);
|
2017-11-09 20:08:52 +11:00
|
|
|
intent.putExtra("id", status.getActionableId());
|
2018-03-03 23:24:03 +11:00
|
|
|
intent.putExtra("url", status.getActionableStatus().getUrl());
|
2017-01-23 16:19:30 +11:00
|
|
|
startActivity(intent);
|
|
|
|
}
|
2017-01-27 11:34:32 +11:00
|
|
|
|
|
|
|
protected void viewTag(String tag) {
|
|
|
|
Intent intent = new Intent(getContext(), ViewTagActivity.class);
|
|
|
|
intent.putExtra("hashtag", tag);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
2017-01-28 14:33:43 +11:00
|
|
|
|
2017-03-03 11:25:35 +11:00
|
|
|
protected void viewAccount(String id) {
|
2017-01-28 14:33:43 +11:00
|
|
|
Intent intent = new Intent(getContext(), AccountActivity.class);
|
|
|
|
intent.putExtra("id", id);
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
2017-02-27 16:21:46 +11:00
|
|
|
|
2017-03-03 11:25:35 +11:00
|
|
|
protected void openReportPage(String accountId, String accountUsername, String statusId,
|
2018-03-10 08:02:32 +11:00
|
|
|
Spanned statusContent) {
|
2017-02-27 16:21:46 +11:00
|
|
|
Intent intent = new Intent(getContext(), ReportActivity.class);
|
|
|
|
intent.putExtra("account_id", accountId);
|
2017-03-03 11:25:35 +11:00
|
|
|
intent.putExtra("account_username", accountUsername);
|
2017-02-27 16:21:46 +11:00
|
|
|
intent.putExtra("status_id", statusId);
|
|
|
|
intent.putExtra("status_content", HtmlUtils.toHtml(statusContent));
|
|
|
|
startActivity(intent);
|
|
|
|
}
|
2017-01-23 16:19:30 +11:00
|
|
|
}
|