2016-07-04 03:31:17 +02:00
|
|
|
/*
|
|
|
|
* Twidere - Twitter client for Android
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012-2015 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.util
|
|
|
|
|
|
|
|
import android.content.Context
|
2016-12-24 13:47:35 +01:00
|
|
|
import android.content.SharedPreferences
|
|
|
|
import org.mariotaku.kpreferences.get
|
2016-07-04 03:31:17 +02:00
|
|
|
import org.mariotaku.twidere.Constants
|
2017-01-20 15:08:42 +01:00
|
|
|
import org.mariotaku.twidere.constant.displaySensitiveContentsKey
|
2016-12-24 13:47:35 +01:00
|
|
|
import org.mariotaku.twidere.constant.newDocumentApiKey
|
2016-07-04 03:31:17 +02:00
|
|
|
import org.mariotaku.twidere.model.ParcelableMedia
|
|
|
|
import org.mariotaku.twidere.model.ParcelableStatus
|
|
|
|
import org.mariotaku.twidere.model.UserKey
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mariotaku on 15/1/23.
|
|
|
|
*/
|
2016-12-23 02:26:52 +01:00
|
|
|
open class StatusLinkClickHandler(
|
|
|
|
context: Context,
|
|
|
|
manager: MultiSelectManager,
|
2016-12-24 13:47:35 +01:00
|
|
|
preferences: SharedPreferences
|
2016-12-23 02:26:52 +01:00
|
|
|
) : OnLinkClickHandler(context, manager, preferences), Constants {
|
2016-07-04 03:31:17 +02:00
|
|
|
|
|
|
|
var status: ParcelableStatus? = null
|
|
|
|
|
|
|
|
override fun openMedia(accountKey: UserKey, extraId: Long, sensitive: Boolean,
|
2017-04-10 12:09:16 +02:00
|
|
|
link: String, start: Int, end: Int) {
|
2016-07-04 03:31:17 +02:00
|
|
|
val status = status
|
|
|
|
val current = findByLink(status!!.media, link)
|
|
|
|
if (current == null || current.open_browser) {
|
|
|
|
openLink(link)
|
|
|
|
} else {
|
2017-01-20 15:08:42 +01:00
|
|
|
IntentUtils.openMedia(context, status, current, preferences[newDocumentApiKey],
|
|
|
|
preferences[displaySensitiveContentsKey])
|
2016-07-04 03:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
fun findByLink(media: Array<ParcelableMedia>?, link: String?): ParcelableMedia? {
|
|
|
|
if (link == null || media == null) return null
|
2016-12-06 06:15:22 +01:00
|
|
|
return media.firstOrNull {
|
|
|
|
link == it.media_url || link == it.url || link == it.page_url || link == it.preview_url
|
2016-07-04 03:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|