blob: c3d1aca504e71405414b812193d75a797f05e1ed (
plain)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
package com.mapswithme.maps.news;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.R;
import com.mapswithme.maps.downloader.UpdaterDialogFragment;
import com.mapswithme.util.Counters;
import com.mapswithme.util.SharedPropertiesUtils;
public class NewsFragment extends BaseNewsFragment
{
private class Adapter extends BaseNewsFragment.Adapter
{
@Override
int getTitleKeys()
{
return TITLE_KEYS;
}
@Override
int getSubtitles1()
{
return R.array.news_messages_1;
}
@Override
int getSubtitles2()
{
return R.array.news_messages_2;
}
@Override
int getButtonLabels()
{
return R.array.news_button_labels;
}
@Override
int getButtonLinks()
{
return R.array.news_button_links;
}
@Override
int getSwitchTitles()
{
return R.array.news_switch_titles;
}
@Override
int getSwitchSubtitles()
{
return R.array.news_switch_subtitles;
}
@Override
int getImages()
{
return R.array.news_images;
}
}
@Override
BaseNewsFragment.Adapter createAdapter()
{
return new Adapter();
}
@Override
protected void onDoneClick()
{
if (!UpdaterDialogFragment.showOn(getActivity(), getListener()))
super.onDoneClick();
else
dismissAllowingStateLoss();
}
/**
* Displays "What's new" dialog on given {@code activity}. Or not.
* @return whether "What's new" dialog should be shown.
*/
public static boolean showOn(@NonNull FragmentActivity activity,
final @Nullable NewsDialogListener listener)
{
if (Counters.getFirstInstallVersion() >= BuildConfig.VERSION_CODE)
return false;
FragmentManager fm = activity.getSupportFragmentManager();
if (fm.isDestroyed())
return false;
Fragment f = fm.findFragmentByTag(UpdaterDialogFragment.class.getName());
if (f != null)
return UpdaterDialogFragment.showOn(activity, listener);
String currentTitle = getCurrentTitleConcatenation(activity.getApplicationContext());
String oldTitle = SharedPropertiesUtils.getWhatsNewTitleConcatenation();
if (currentTitle.equals(oldTitle) && !recreate(activity, NewsFragment.class))
return false;
create(activity, NewsFragment.class, listener);
Counters.setWhatsNewShown();
SharedPropertiesUtils.setWhatsNewTitleConcatenation(currentTitle);
Counters.setShowReviewForOldUser(true);
return true;
}
@NonNull
private static String getCurrentTitleConcatenation(@NonNull Context context)
{
String[] keys = context.getResources().getStringArray(TITLE_KEYS);
final int length = keys.length;
if (length == 0)
return "";
StringBuilder sb = new StringBuilder("");
for (String key : keys)
sb.append(key);
return sb.toString().trim();
}
}
|