mirror of
https://github.com/jwdeveloper/TikTokLiveJava.git
synced 2026-02-28 01:09:40 -05:00
Update gifts manager
This commit is contained in:
@@ -93,6 +93,8 @@ public class TikTokLive {
|
||||
}
|
||||
|
||||
|
||||
private static GiftsManager giftsManager;
|
||||
|
||||
/**
|
||||
* Fetch gifts from endpoint and returns GiftManager
|
||||
*
|
||||
@@ -100,17 +102,20 @@ public class TikTokLive {
|
||||
*/
|
||||
public static GiftsManager gifts()
|
||||
{
|
||||
return new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
|
||||
if(giftsManager != null)
|
||||
{
|
||||
return giftsManager;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
giftsManager = new TikTokGiftsManager(requests().fetchGiftsData().getGifts());
|
||||
return giftsManager;
|
||||
} catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param fetchGifts fetch gifts from internet or return empty giftManager
|
||||
* @return
|
||||
*/
|
||||
public static GiftsManager gifts(boolean fetchGifts) {
|
||||
if (fetchGifts) {
|
||||
return gifts();
|
||||
}
|
||||
return new TikTokGiftsManager(List.of());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ package io.github.jwdeveloper.tiktok.http.mappers;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import io.github.jwdeveloper.tiktok.data.models.Picture;
|
||||
import io.github.jwdeveloper.tiktok.data.models.gifts.Gift;
|
||||
import io.github.jwdeveloper.tiktok.data.requests.GiftsData;
|
||||
|
||||
@@ -48,7 +49,7 @@ public class GiftsDataMapper {
|
||||
var id = jsonObject.get("id").getAsInt();
|
||||
var name = jsonObject.get("name").getAsString();
|
||||
var diamondCost = jsonObject.get("diamondCost").getAsInt();
|
||||
var image =jsonObject.get("image").getAsString();
|
||||
return new Gift(id, name, diamondCost, image, jsonObject);
|
||||
var image = jsonObject.get("image").getAsString();
|
||||
return new Gift(id, name, diamondCost, new Picture(image), jsonObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user