1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
package com.mapswithme.maps.widget.placepage;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
import android.text.TextUtils;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;
import com.mapswithme.maps.bookmarks.data.MapObject;
import com.mapswithme.maps.bookmarks.data.Metadata;
@UiThread
public final class SponsoredHotel
{
private static class Price
{
final String price;
final String currency;
private Price(String price, String currency)
{
this.price = price;
this.currency = currency;
}
}
interface OnPriceReceivedListener
{
void onPriceReceived(String id, String price, String currency);
}
// Hotel ID -> Price
private static final Map<String, Price> sPriceCache = new HashMap<>();
private static WeakReference<OnPriceReceivedListener> sListener;
private String mId;
final String rating;
final String price;
final String urlBook;
final String urlDescription;
public SponsoredHotel(String rating, String price, String urlBook, String urlDescription)
{
this.rating = rating;
this.price = price;
this.urlBook = urlBook;
this.urlDescription = urlDescription;
}
void updateId(MapObject point)
{
mId = point.getMetadata(Metadata.MetadataType.FMD_SPONSORED_ID);
}
public String getId()
{
return mId;
}
public String getRating()
{
return rating;
}
public String getPrice()
{
return price;
}
public String getUrlBook()
{
return urlBook;
}
public String getUrlDescription()
{
return urlDescription;
}
public static void setListener(OnPriceReceivedListener listener)
{
sListener = new WeakReference<>(listener);
}
static void requestPrice(String id, String currencyCode)
{
Price p = sPriceCache.get(id);
if (p != null)
onPriceReceived(id, p.price, p.currency);
nativeRequestPrice(id, currencyCode);
}
@SuppressWarnings("unused")
private static void onPriceReceived(String id, String price, String currency)
{
if (TextUtils.isEmpty(price))
return;
sPriceCache.put(id, new Price(price, currency));
OnPriceReceivedListener listener = sListener.get();
if (listener == null)
sListener = null;
else
listener.onPriceReceived(id, price, currency);
}
@Nullable
public static native SponsoredHotel nativeGetCurrent();
private static native void nativeRequestPrice(String id, String currencyCode);
}
|