2015-01-03 16:16:50 +01: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.graphics.Point;
|
2015-04-09 19:39:51 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2015-01-03 16:16:50 +01:00
|
|
|
import android.support.v4.app.Fragment;
|
|
|
|
|
2015-12-20 12:54:05 +01:00
|
|
|
import org.mariotaku.twidere.fragment.support.card.CardPollFragment;
|
2015-12-31 09:32:27 +01:00
|
|
|
import org.mariotaku.twidere.model.ParcelableCardEntity;
|
2015-12-27 07:18:16 +01:00
|
|
|
import org.mariotaku.twidere.model.ParcelableStatus;
|
2015-01-03 16:16:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by mariotaku on 15/1/1.
|
|
|
|
*/
|
|
|
|
public class TwitterCardUtils {
|
|
|
|
|
|
|
|
private static final TwitterCardFragmentFactory sFactory = TwitterCardFragmentFactory.getInstance();
|
|
|
|
|
2015-01-19 18:46:14 +01:00
|
|
|
public static final String CARD_NAME_PLAYER = "player";
|
|
|
|
public static final String CARD_NAME_AUDIO = "audio";
|
|
|
|
public static final String CARD_NAME_ANIMATED_GIF = "animated_gif";
|
|
|
|
|
2015-04-09 19:39:51 +02:00
|
|
|
@Nullable
|
2015-12-27 07:18:16 +01:00
|
|
|
public static Fragment createCardFragment(ParcelableStatus status) {
|
|
|
|
final ParcelableCardEntity card = status.card;
|
|
|
|
if (card == null || card.name == null) return null;
|
2015-01-19 18:46:14 +01:00
|
|
|
if (CARD_NAME_PLAYER.equals(card.name)) {
|
2015-01-03 16:16:50 +01:00
|
|
|
final Fragment playerFragment = sFactory.createPlayerFragment(card);
|
|
|
|
if (playerFragment != null) return playerFragment;
|
|
|
|
return TwitterCardFragmentFactory.createGenericPlayerFragment(card);
|
2015-01-19 18:46:14 +01:00
|
|
|
} else if (CARD_NAME_AUDIO.equals(card.name)) {
|
2015-01-03 16:16:50 +01:00
|
|
|
final Fragment playerFragment = sFactory.createAudioFragment(card);
|
|
|
|
if (playerFragment != null) return playerFragment;
|
|
|
|
return TwitterCardFragmentFactory.createGenericPlayerFragment(card);
|
2015-01-19 18:46:14 +01:00
|
|
|
} else if (CARD_NAME_ANIMATED_GIF.equals(card.name)) {
|
2015-01-03 16:16:50 +01:00
|
|
|
final Fragment playerFragment = sFactory.createAnimatedGifFragment(card);
|
|
|
|
if (playerFragment != null) return playerFragment;
|
|
|
|
return TwitterCardFragmentFactory.createGenericPlayerFragment(card);
|
2015-12-31 09:32:27 +01:00
|
|
|
} else if (CardPollFragment.isPoll(card)) {
|
2015-12-27 07:18:16 +01:00
|
|
|
return TwitterCardFragmentFactory.createCardPollFragment(status);
|
2015-01-03 16:16:50 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Point getCardSize(ParcelableCardEntity card) {
|
2015-12-27 07:18:16 +01:00
|
|
|
final int playerWidth = card.getAsInteger("player_width", -1);
|
|
|
|
final int playerHeight = card.getAsInteger("player_height", -1);
|
|
|
|
if (playerWidth > 0 && playerHeight > 0) {
|
|
|
|
return new Point(playerWidth, playerHeight);
|
2015-01-03 16:16:50 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-12-27 07:18:16 +01:00
|
|
|
public static boolean isCardSupported(ParcelableStatus status) {
|
2015-12-27 07:48:14 +01:00
|
|
|
if (status.card == null || status.card_name == null) return false;
|
|
|
|
switch (status.card_name) {
|
2015-10-27 07:40:12 +01:00
|
|
|
case CARD_NAME_PLAYER: {
|
2015-12-27 07:18:16 +01:00
|
|
|
return ParcelableCardEntity.getValue(status.card, "player_stream_url") == null;
|
2015-10-27 07:40:12 +01:00
|
|
|
}
|
|
|
|
case CARD_NAME_AUDIO: {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-12-31 09:32:27 +01:00
|
|
|
if (CardPollFragment.isPoll(status.card)) {
|
2015-12-20 12:54:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-27 07:40:12 +01:00
|
|
|
return false;
|
2015-01-03 16:16:50 +01:00
|
|
|
}
|
|
|
|
|
2015-12-27 07:48:14 +01:00
|
|
|
public static boolean isPoll(ParcelableStatus status) {
|
2015-12-31 09:32:27 +01:00
|
|
|
if (status.card_name == null || status.card == null) return false;
|
|
|
|
return CardPollFragment.isPoll(status.card);
|
2015-12-27 07:48:14 +01:00
|
|
|
}
|
2015-01-03 16:16:50 +01:00
|
|
|
}
|