[android] Changed whats new screen showing rules

This commit is contained in:
Alexander Zatsepin 2018-05-24 16:37:11 +03:00 committed by yoksnod
parent 19155f87dd
commit bde74d7240
5 changed files with 62 additions and 12 deletions

View file

@ -6,8 +6,8 @@
<item>@drawable/img_wn_business</item>
</integer-array>
<string-array name="news_titles">
<item>@string/whats_new_localbiz_title</item>
<string-array name="news_title_keys">
<item>whats_new_localbiz_title</item>
</string-array>
<string-array name="news_messages_1">

View file

@ -8,6 +8,7 @@ import android.support.annotation.ArrayRes;
import android.support.annotation.CallSuper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
@ -37,6 +38,8 @@ import java.util.List;
public abstract class BaseNewsFragment extends BaseMwmDialogFragment
{
@ArrayRes
static final int TITLE_KEYS = R.array.news_title_keys;
private ViewPager mPager;
private View mPrevButton;
private View mNextButton;
@ -67,7 +70,7 @@ public abstract class BaseNewsFragment extends BaseMwmDialogFragment
{
Resources res = MwmApplication.get().getResources();
mTitles = res.getStringArray(getTitles());
mTitles = getTitles(res);
mSubtitles = res.getStringArray(getSubtitles1());
int subtitles2 = getSubtitles2();
@ -94,8 +97,26 @@ public abstract class BaseNewsFragment extends BaseMwmDialogFragment
images.recycle();
}
@NonNull
private String[] getTitles(@NonNull Resources res)
{
String[] keys = res.getStringArray(getTitleKeys());
final int length = keys.length;
if (length == 0)
throw new AssertionError("Title keys must me non-empty!");
String[] titles = new String[length];
for (int i = 0; i < length; i++)
{
@StringRes
int id = res.getIdentifier(keys[i], "string", getContext().getPackageName());
titles[i] = res.getString(id);
}
return titles;
}
@ArrayRes
abstract int getTitles();
abstract int getTitleKeys();
@ArrayRes
abstract int getSubtitles1();
@ArrayRes

View file

@ -1,5 +1,6 @@
package com.mapswithme.maps.news;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
@ -10,6 +11,7 @@ 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
{
@ -17,9 +19,9 @@ public class NewsFragment extends BaseNewsFragment
private class Adapter extends BaseNewsFragment.Adapter
{
@Override
int getTitles()
int getTitleKeys()
{
return R.array.news_titles;
return TITLE_KEYS;
}
@Override
@ -98,15 +100,32 @@ public class NewsFragment extends BaseNewsFragment
if (f != null)
return UpdaterDialogFragment.showOn(activity, listener);
if (Counters.getLastWhatsNewVersion() / 10 >= BuildConfig.VERSION_CODE / 10 &&
!recreate(activity, NewsFragment.class))
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();
}
}

View file

@ -52,10 +52,6 @@ public final class Counters
.apply();
}
public static int getLastWhatsNewVersion()
{
return MwmApplication.prefs().getInt(KEY_MISC_NEWS_LAST_VERSION, 0);
}
public static void setWhatsNewShown()
{

View file

@ -2,6 +2,8 @@ package com.mapswithme.util;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
@ -12,6 +14,7 @@ public final class SharedPropertiesUtils
{
private static final String PREFS_SHOW_EMULATE_BAD_STORAGE_SETTING = "ShowEmulateBadStorageSetting";
private static final String PREFS_BACKUP_WIDGET_EXPANDED = "BackupWidgetExpanded";
private static final String PREFS_WHATS_NEW_TITLE_CONCATENATION = "WhatsNewTitleConcatenation";
private static final SharedPreferences PREFS
= PreferenceManager.getDefaultSharedPreferences(MwmApplication.get());
@ -57,6 +60,17 @@ public final class SharedPropertiesUtils
return PREFS.getBoolean(PREFS_BACKUP_WIDGET_EXPANDED, true);
}
@Nullable
public static String getWhatsNewTitleConcatenation()
{
return PREFS.getString(PREFS_WHATS_NEW_TITLE_CONCATENATION, null);
}
public static void setWhatsNewTitleConcatenation(@NonNull String concatenation)
{
PREFS.edit().putString(PREFS_WHATS_NEW_TITLE_CONCATENATION, concatenation).apply();
}
//Utils class
private SharedPropertiesUtils()
{