mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-01-19 03:29:58 +01:00
improved DM media
This commit is contained in:
parent
b967c1aeb3
commit
735a322d2a
@ -401,7 +401,7 @@ public class DMResponse implements Parcelable {
|
||||
public static class Data implements EntitySupport, Parcelable {
|
||||
|
||||
@JsonField(name = "id")
|
||||
long id;
|
||||
String id;
|
||||
|
||||
@JsonField(name = "time")
|
||||
long time;
|
||||
@ -464,7 +464,7 @@ public class DMResponse implements Parcelable {
|
||||
return time;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -497,6 +497,8 @@ public class DMResponse implements Parcelable {
|
||||
MediaEntity photo;
|
||||
@JsonField(name = "video")
|
||||
MediaEntity video;
|
||||
@JsonField(name = "animated_gif")
|
||||
MediaEntity animatedGif;
|
||||
@JsonField(name = "sticker")
|
||||
StickerEntity sticker;
|
||||
|
||||
@ -508,6 +510,10 @@ public class DMResponse implements Parcelable {
|
||||
return video;
|
||||
}
|
||||
|
||||
public MediaEntity getAnimatedGif() {
|
||||
return animatedGif;
|
||||
}
|
||||
|
||||
public StickerEntity getSticker() {
|
||||
return sticker;
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.fragment.MessagesEntriesFragment;
|
||||
import org.mariotaku.twidere.fragment.message.MessagesEntriesFragment;
|
||||
import org.mariotaku.twidere.model.tab.DrawableHolder;
|
||||
import org.mariotaku.twidere.model.tab.StringHolder;
|
||||
import org.mariotaku.twidere.model.tab.TabConfiguration;
|
||||
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.mariotaku.microblog.library.twitter.model
|
||||
|
||||
import org.mariotaku.microblog.library.MicroBlog
|
||||
import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.DMResponse.Entry.Message
|
||||
|
||||
/**
|
||||
* I don't know why Twitter doesn't return video/animatedGif when requesting DM, but this will help
|
||||
*/
|
||||
fun DMResponse.fixMedia(microBlog: MicroBlog) {
|
||||
entries?.forEach { entry ->
|
||||
// Ensure it's a normal message
|
||||
val data = entry.message?.messageData ?: return@forEach
|
||||
// Ensure this message don't have attachment
|
||||
if (data.attachment != null) return@forEach
|
||||
|
||||
// Don't try if it's a group dm
|
||||
if (conversations?.get(entry.message.conversationId)?.type == DMResponse.Conversation.Type.GROUP_DM) {
|
||||
return@forEach
|
||||
}
|
||||
|
||||
val mediaUrl = "https://twitter.com/messages/media/${data.id}"
|
||||
if (data.entities?.urls?.find { it.expandedUrl == mediaUrl } == null) return@forEach
|
||||
val message = try {
|
||||
microBlog.showDirectMessage(data.id)
|
||||
} catch (e: MicroBlogException) {
|
||||
// Ignore
|
||||
return@forEach
|
||||
}
|
||||
val media = message.entities?.media?.find { it.expandedUrl == mediaUrl } ?: return@forEach
|
||||
|
||||
when (media.type) {
|
||||
MediaEntity.Type.VIDEO -> {
|
||||
data.attachment = attachment { video = media }
|
||||
}
|
||||
MediaEntity.Type.PHOTO -> {
|
||||
data.attachment = attachment { photo = media }
|
||||
}
|
||||
MediaEntity.Type.ANIMATED_GIF -> {
|
||||
data.attachment = attachment { animatedGif = media }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun attachment(apply: Message.Data.Attachment.() -> Unit): Message.Data.Attachment {
|
||||
val attachment = Message.Data.Attachment()
|
||||
apply(attachment)
|
||||
return attachment
|
||||
}
|
@ -834,8 +834,8 @@ class HomeActivity : BaseActivity(), OnClickListener, OnPageChangeListener, Supp
|
||||
private fun triggerActionsClick() {
|
||||
val position = mainPager.currentItem
|
||||
if (pagerAdapter.count == 0) return
|
||||
val fragment = pagerAdapter.instantiateItem(mainPager, position) as? IFloatingActionButtonFragment ?: return
|
||||
val handled = fragment.onActionClick("home") ?: false
|
||||
val fragment = pagerAdapter.instantiateItem(mainPager, position) as? IFloatingActionButtonFragment
|
||||
val handled = fragment?.onActionClick("home") ?: false
|
||||
if (!handled) {
|
||||
startActivity(Intent(INTENT_ACTION_COMPOSE))
|
||||
}
|
||||
|
@ -55,6 +55,10 @@ import org.mariotaku.twidere.fragment.iface.IBaseFragment
|
||||
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback
|
||||
import org.mariotaku.twidere.fragment.iface.IToolBarSupportFragment
|
||||
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback
|
||||
import org.mariotaku.twidere.fragment.message.MessageConversationInfoFragment
|
||||
import org.mariotaku.twidere.fragment.message.MessageNewConversationFragment
|
||||
import org.mariotaku.twidere.fragment.message.MessagesConversationFragment
|
||||
import org.mariotaku.twidere.fragment.message.MessagesEntriesFragment
|
||||
import org.mariotaku.twidere.graphic.EmptyDrawable
|
||||
import org.mariotaku.twidere.model.UserKey
|
||||
import org.mariotaku.twidere.model.analyzer.PurchaseFinished
|
||||
@ -624,13 +628,13 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro
|
||||
args.putString(EXTRA_CONVERSATION_ID, conversationId)
|
||||
}
|
||||
LINK_ID_MESSAGES_CONVERSATION_NEW -> {
|
||||
fragment = Fragment()
|
||||
val conversationId = uri.getQueryParameter(QUERY_PARAM_CONVERSATION_ID) ?: return null
|
||||
fragment = MessageNewConversationFragment()
|
||||
accountRequired = true
|
||||
}
|
||||
LINK_ID_MESSAGES_CONVERSATION_INFO -> {
|
||||
fragment = Fragment()
|
||||
fragment = MessageConversationInfoFragment()
|
||||
val conversationId = uri.getQueryParameter(QUERY_PARAM_CONVERSATION_ID) ?: return null
|
||||
args.putString(EXTRA_CONVERSATION_ID, conversationId)
|
||||
accountRequired = true
|
||||
}
|
||||
LINK_ID_INTERACTIONS -> {
|
||||
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment.message
|
||||
|
||||
import org.mariotaku.twidere.fragment.BaseFragment
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/2/15.
|
||||
*/
|
||||
|
||||
class MessageConversationInfoFragment : BaseFragment()
|
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment.message
|
||||
|
||||
import org.mariotaku.twidere.fragment.BaseFragment
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 2017/2/15.
|
||||
*/
|
||||
class MessageNewConversationFragment: BaseFragment() {
|
||||
|
||||
}
|
@ -1,4 +1,23 @@
|
||||
package org.mariotaku.twidere.fragment
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment.message
|
||||
|
||||
import android.accounts.AccountManager
|
||||
import android.app.Activity
|
||||
@ -31,6 +50,8 @@ import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_CONVERSATION_ID
|
||||
import org.mariotaku.twidere.constant.newDocumentApiKey
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.fragment.AbsContentListRecyclerViewFragment
|
||||
import org.mariotaku.twidere.fragment.EditAltTextDialogFragment
|
||||
import org.mariotaku.twidere.loader.ObjectCursorLoader
|
||||
import org.mariotaku.twidere.model.*
|
||||
import org.mariotaku.twidere.model.ParcelableMessageConversation.ConversationType
|
@ -1,4 +1,23 @@
|
||||
package org.mariotaku.twidere.fragment
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2017 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment.message
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
@ -19,6 +38,7 @@ import org.mariotaku.twidere.adapter.MessagesEntriesAdapter.MessageConversationC
|
||||
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter
|
||||
import org.mariotaku.twidere.constant.newDocumentApiKey
|
||||
import org.mariotaku.twidere.extension.model.user
|
||||
import org.mariotaku.twidere.fragment.AbsContentListRecyclerViewFragment
|
||||
import org.mariotaku.twidere.fragment.iface.IFloatingActionButtonFragment
|
||||
import org.mariotaku.twidere.fragment.iface.IFloatingActionButtonFragment.ActionInfo
|
||||
import org.mariotaku.twidere.loader.ObjectCursorLoader
|
||||
@ -121,14 +141,15 @@ class MessagesEntriesFragment : AbsContentListRecyclerViewFragment<MessagesEntri
|
||||
return ActionInfo(R.drawable.ic_action_add, getString(R.string.new_direct_message))
|
||||
}
|
||||
|
||||
override fun onActionClick(tag: String) {
|
||||
override fun onActionClick(tag: String): Boolean {
|
||||
val accountKey = accountKeys.singleOrNull() ?: run {
|
||||
val selectIntent = Intent(context, AccountSelectorActivity::class.java)
|
||||
selectIntent.putExtra(EXTRA_ACCOUNT_KEYS, accountKeys)
|
||||
startActivityForResult(selectIntent, REQUEST_SELECT_ACCOUNT)
|
||||
return
|
||||
return true
|
||||
}
|
||||
startActivity(IntentUtils.newMessageConversation(accountKey))
|
||||
return true
|
||||
}
|
||||
|
||||
@Subscribe
|
@ -11,6 +11,7 @@ import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.model.DMResponse
|
||||
import org.mariotaku.microblog.library.twitter.model.Paging
|
||||
import org.mariotaku.microblog.library.twitter.model.User
|
||||
import org.mariotaku.microblog.library.twitter.model.fixMedia
|
||||
import org.mariotaku.sqliteqb.library.Expression
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.extension.model.applyFrom
|
||||
@ -162,6 +163,7 @@ class GetMessagesTask(
|
||||
}
|
||||
|
||||
val response = microBlog.getDmConversation(conversationId, paging).conversationTimeline
|
||||
response.fixMedia(microBlog)
|
||||
return createDatabaseUpdateData(context, details, response)
|
||||
}
|
||||
|
||||
@ -178,7 +180,7 @@ class GetMessagesTask(
|
||||
}
|
||||
}).userInbox
|
||||
}
|
||||
|
||||
response.fixMedia(microBlog)
|
||||
return createDatabaseUpdateData(context, details, response)
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import org.mariotaku.microblog.library.MicroBlogException
|
||||
import org.mariotaku.microblog.library.twitter.TwitterUpload
|
||||
import org.mariotaku.microblog.library.twitter.model.DirectMessage
|
||||
import org.mariotaku.microblog.library.twitter.model.NewDm
|
||||
import org.mariotaku.microblog.library.twitter.model.fixMedia
|
||||
import org.mariotaku.twidere.annotation.AccountType
|
||||
import org.mariotaku.twidere.extension.model.isOfficial
|
||||
import org.mariotaku.twidere.extension.model.newMicroBlogInstance
|
||||
@ -92,6 +93,7 @@ class SendMessageTask(
|
||||
deleteOnSuccess?.forEach { it.delete(context) }
|
||||
}
|
||||
deleteAlways?.forEach { it.delete(context) }
|
||||
response.fixMedia(microBlog)
|
||||
return GetMessagesTask.createDatabaseUpdateData(context, account, response)
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
tools:context=".fragment.MessagesConversationFragment">
|
||||
tools:context=".fragment.message.MessagesConversationFragment">
|
||||
|
||||
<include
|
||||
android:id="@+id/listContainer"
|
||||
|
Loading…
Reference in New Issue
Block a user