aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java')
-rw-r--r--app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java250
1 files changed, 0 insertions, 250 deletions
diff --git a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java b/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java
deleted file mode 100644
index f8a1e2e5..00000000
--- a/app/src/main/java/net/lacolaco/smileessence/view/dialog/MessageDetailDialogFragment.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2012-2015 lacolaco.net
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-package net.lacolaco.smileessence.view.dialog;
-
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.graphics.drawable.ColorDrawable;
-import android.os.Bundle;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.ImageButton;
-import android.widget.ListView;
-import android.widget.TextView;
-import net.lacolaco.smileessence.R;
-import net.lacolaco.smileessence.activity.MainActivity;
-import net.lacolaco.smileessence.command.Command;
-import net.lacolaco.smileessence.command.CommandAddHashtag;
-import net.lacolaco.smileessence.command.CommandOpenURL;
-import net.lacolaco.smileessence.command.CommandOpenUserDetail;
-import net.lacolaco.smileessence.entity.DirectMessage;
-import net.lacolaco.smileessence.preference.UserPreferenceHelper;
-import net.lacolaco.smileessence.twitter.task.Messages;
-import net.lacolaco.smileessence.util.SystemServiceHelper;
-import net.lacolaco.smileessence.view.DialogHelper;
-import net.lacolaco.smileessence.view.Partials;
-import net.lacolaco.smileessence.view.adapter.CustomListAdapter;
-import net.lacolaco.smileessence.view.adapter.MessageListAdapter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class MessageDetailDialogFragment extends StackableDialogFragment implements View.OnClickListener {
- private static final String KEY_MESSAGE_ID = "message_id";
- private DirectMessage message;
-
- public static MessageDetailDialogFragment newInstance(DirectMessage message) {
- MessageDetailDialogFragment obj = new MessageDetailDialogFragment();
- Bundle args = new Bundle();
- args.putLong(KEY_MESSAGE_ID, message.getId());
- obj.setArguments(args);
- return obj;
- }
-
- @Override
- public void onClick(final View v) {
- switch (v.getId()) {
- case R.id.button_status_detail_reply: {
- openSendMessageDialog();
- break;
- }
- case R.id.button_status_detail_delete: {
- deleteMessage();
- break;
- }
- case R.id.button_status_detail_menu: {
- openMenu();
- break;
- }
- default: {
- dismiss();
- }
- }
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- message = DirectMessage.fetch(getArguments().getLong(KEY_MESSAGE_ID));
- if (message == null) {
- getWorld().notifyError(R.string.notice_error_get_messages);
- return new DisposeDialog(getActivity());
- }
-
- View header = getTitleView();
- ListView listView = (ListView) header.findViewById(R.id.listview_status_detail_reply_to);
- final MessageListAdapter adapter = new MessageListAdapter(getActivity());
- listView.setAdapter(adapter);
-
- // TODO: 効率的な探索どうする
- DirectMessage replyTo = null;
- // FIXME
- // for (DirectMessage mes : DirectMessage.cached()) {
- // if (message.getId() > mes.getId() &&
- // message.getRecipient() == mes.getSender() &&
- // message.getSender() == mes.getRecipient() &&
- // (replyTo == null || replyTo.getId() < mes.getId())) {
- // replyTo = mes;
- // }
- // }
- if (replyTo != null) {
- listView.setVisibility(View.VISIBLE);
- adapter.add(replyTo);
- adapter.updateForce();
- } else {
- listView.setVisibility(View.GONE);
- }
-
- return new AlertDialog.Builder(getActivity()).setView(header).create();
- }
-
- // -------------------------- OTHER METHODS --------------------------
-
- private void deleteMessage() {
- ConfirmDialogFragment.show(getActivity(), getString(R.string.dialog_confirm_commands), () -> {
- new Messages.DestroyTask(getWorld().getAccount(), message.getId())
- .onDone(x -> getWorld().notify(R.string.notice_message_delete_succeeded))
- .onFail(x -> getWorld().notifyError(R.string.notice_message_delete_failed))
- .execute();
- dismiss();
- });
- }
-
- private void openSendMessageDialog() {
- DialogHelper.showDialog(getActivity(), SendMessageDialogFragment.newInstance(message.getSender()));
- }
-
- private View getTitleView() {
- MainActivity activity = (MainActivity) getActivity();
-
- View view = activity.getLayoutInflater().inflate(R.layout.dialog_status_detail, null);
-
- View messageHeader = Partials.getDirectMessageView(message, activity, view.findViewById(R.id.layout_status_header));
- messageHeader.setClickable(false);
-
- view.setBackgroundColor(((ColorDrawable) messageHeader.getBackground()).getColor());
- updateViewButtons(view);
- updateViewMenu(view);
-
- // status only parts
- view.findViewById(R.id.detail_dialog_divider_top).setVisibility(View.GONE);
- view.findViewById(R.id.button_status_detail_retweet).setVisibility(View.GONE);
- view.findViewById(R.id.button_status_detail_favorite).setVisibility(View.GONE);
- view.findViewById(R.id.image_status_detail_fav_count).setVisibility(View.GONE);
- view.findViewById(R.id.image_status_detail_rt_count).setVisibility(View.GONE);
-
- return view;
- }
-
- private void updateViewButtons(View view) {
- //--- buttons
- ImageButton reply = (ImageButton) view.findViewById(R.id.button_status_detail_reply);
- reply.setOnClickListener(this);
-
- ImageButton delete = (ImageButton) view.findViewById(R.id.button_status_detail_delete);
- delete.setOnClickListener(this);
- delete.setVisibility(View.VISIBLE);
- }
-
- private void updateViewMenu(View view) {
- // -- menu dialog
- ImageButton menu = (ImageButton) view.findViewById(R.id.button_status_detail_menu);
- menu.setOnClickListener(this);
-
- // -- menu embedded in dialog
- View divider = view.findViewById(R.id.detail_dialog_divider_bottom);
- ListView listView = (ListView) view.findViewById(R.id.listview_status_detail_menu);
- List<Command> commands = getCommands();
- if (commands.size() > 0) {
- divider.setVisibility(View.VISIBLE);
- listView.setVisibility(View.VISIBLE);
- final CustomListAdapter<Command> adapter = new CustomListAdapter<Command>() {
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if (convertView == null) {
- convertView = getActivity().getLayoutInflater().inflate(R.layout.menu_item_simple_text, null);
- }
- TextView textView = (TextView) convertView.findViewById(R.id.list_item_textview);
- textView.setTextSize(UserPreferenceHelper.getInstance().getTextSize());
- textView.setText(getItem(position).getText());
- return convertView;
- }
-
- @Override
- protected List<Command> getList() {
- return commands;
- }
- };
- adapter.update();
- listView.setAdapter(adapter);
- listView.setOnItemClickListener((parent, view1, position, id) -> {
- Command command = (Command) parent.getItemAtPosition(position);
- command.execute();
- });
- } else {
- divider.setVisibility(View.GONE);
- listView.setVisibility(View.GONE);
- }
- }
-
- private List<Command> getCommands() {
- MainActivity activity = (MainActivity) getActivity();
- List<Command> commands = new ArrayList<>();
- // Mentions
- if (message.getSender() != message.getRecipient()) {
- commands.add(new CommandOpenUserDetail(activity, message.getRecipient().getScreenName()));
- }
- for (String screenName : message.getMentions()) {
- commands.add(new CommandOpenUserDetail(activity, screenName));
- }
- for (String hashtag : message.getHashtags()) {
- commands.add(new CommandAddHashtag(activity, hashtag));
- }
- // URL
- for (String url : message.getUrlsExpanded()) {
- commands.add(new CommandOpenURL(activity, url));
- }
- for (String url : message.getMediaUrls()) {
- commands.add(new CommandOpenURL(activity, url));
- }
- return commands;
- }
-
- private void openMenu() {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
- builder.setTitle("@" + message.getSender().getScreenName() + ": " + message.getText())
- .setItems(R.array.message_commands, (dialog, which) -> {
- switch (which) {
- case 0:
- SystemServiceHelper.copyToClipboard(getActivity(), "message text", message.getText());
- getWorld().notify(R.string.notice_copy_clipboard);
- break;
- default:
- throw new IllegalStateException();
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
-}