[android] fix: WhatsNew for editor.

This commit is contained in:
Alexander Marchuk 2016-04-28 14:34:24 +03:00 committed by Alex Zolotarev
parent e3562cd75c
commit 7b03d64450
3 changed files with 226 additions and 2 deletions

View file

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mapswithme.maps.widget.HeightLimitedFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_base_plus"
android:layout_marginBottom="@dimen/margin_base"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:text="@string/whatsnew_update_editor_title"
android:textAppearance="@style/MwmTextAppearance.Title"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:fontFamily="@string/robotoMedium"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_base"
android:layout_gravity="center_horizontal"
android:src="@drawable/img_news_editor"
android:tag="@string/tag_height_limited"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:text="@string/whatsnew_update_editor_message"
android:textAppearance="@style/MwmTextAppearance.Body1"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"/>
<TextView
android:id="@+id/migrate_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_base_plus"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:text="Update maps!"
android:textAppearance="@style/MwmTextAppearance.Body1"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"/>
<Space
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="@dimen/margin_base">
<TextView
android:id="@+id/done"
android:layout_width="wrap_content"
style="@style/MwmWidget.Button"
android:paddingLeft="@dimen/margin_base"
android:paddingRight="@dimen/margin_base"
android:layout_gravity="right|bottom"
android:gravity="center"
android:text="@string/done"
android:textAppearance="@style/MwmTextAppearance.Button"
android:textColor="?colorAccent"/>
<LinearLayout
android:id="@+id/migrate_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/margin_base"
android:clipToPadding="false"
android:orientation="horizontal">
<TextView
android:id="@+id/close"
android:layout_width="0dp"
android:layout_weight="3"
style="@style/MwmWidget.Button"
android:gravity="center"
android:text="@string/not_now"
android:textAppearance="@style/MwmTextAppearance.Button"
android:textColor="?colorAccent"/>
<Button
android:id="@+id/migrate"
android:layout_width="0dp"
android:layout_weight="5"
style="@style/MwmWidget.Button.Accent"
android:layout_marginLeft="@dimen/margin_base"
android:text="@string/migration_update_all_button"
android:textAppearance="@style/MwmTextAppearance.Button"
android:textColor="?android:textColorPrimaryInverse"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</com.mapswithme.maps.widget.HeightLimitedFrameLayout>

View file

@ -54,7 +54,7 @@ import com.mapswithme.maps.editor.ViralFragment;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationPredictor;
import com.mapswithme.maps.news.FirstStartFragment;
import com.mapswithme.maps.news.NewsFragment;
import com.mapswithme.maps.news.SinglePageNewsFragment;
import com.mapswithme.maps.routing.NavigationController;
import com.mapswithme.maps.routing.RoutingController;
import com.mapswithme.maps.routing.RoutingInfo;
@ -931,7 +931,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
}
});
}
if (!isFirstStart && !NewsFragment.showOn(this))
if (!isFirstStart && !SinglePageNewsFragment.showOn(this))
{
if (ViralFragment.shouldDisplay())
new ViralFragment().show(getSupportFragmentManager(), "");

View file

@ -0,0 +1,120 @@
package com.mapswithme.maps.news;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.Window;
import com.mapswithme.maps.BuildConfig;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.R;
import com.mapswithme.maps.base.BaseMwmDialogFragment;
import com.mapswithme.maps.downloader.MapManager;
import com.mapswithme.util.Config;
import com.mapswithme.util.UiUtils;
// TODO (trashkalmar): This is temporary class
public class SinglePageNewsFragment extends BaseMwmDialogFragment
{
@Override
protected int getCustomTheme()
{
return (UiUtils.isTablet() ? super.getCustomTheme()
: getFullscreenTheme());
}
@Override
public @NonNull Dialog onCreateDialog(Bundle savedInstanceState)
{
Dialog res = super.onCreateDialog(savedInstanceState);
res.requestWindowFeature(Window.FEATURE_NO_TITLE);
View content = View.inflate(getActivity(), R.layout.fragment_news_single, null);
res.setContentView(content);
View done = content.findViewById(R.id.done);
if (MapManager.nativeIsLegacyMode())
{
UiUtils.hide(done);
done = content.findViewById(R.id.close);
content.findViewById(R.id.migrate).setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
((MwmActivity) getActivity()).showDownloader(false);
dismiss();
}
});
}
else
{
UiUtils.hide(content.findViewById(R.id.migrate_message));
UiUtils.hide(content.findViewById(R.id.migrate_buttons));
}
done.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
dismiss();
}
});
return res;
}
@SuppressWarnings("TryWithIdenticalCatches")
private static void create(FragmentActivity activity)
{
try
{
SinglePageNewsFragment fragment = SinglePageNewsFragment.class.newInstance();
fragment.show(activity.getSupportFragmentManager(), SinglePageNewsFragment.class.getName());
} catch (java.lang.InstantiationException ignored)
{}
catch (IllegalAccessException ignored)
{}
}
private static boolean recreate(FragmentActivity activity)
{
FragmentManager fm = activity.getSupportFragmentManager();
Fragment f = fm.findFragmentByTag(SinglePageNewsFragment.class.getName());
if (f == null)
return false;
// If we're here, it means that the user has rotated the screen.
// We use different dialog themes for landscape and portrait modes on tablets,
// so the fragment should be recreated to be displayed correctly.
fm.beginTransaction().remove(f).commitAllowingStateLoss();
fm.executePendingTransactions();
return true;
}
public static boolean showOn(FragmentActivity activity)
{
if (Config.getFirstInstallVersion() >= BuildConfig.VERSION_CODE)
return false;
FragmentManager fm = activity.getSupportFragmentManager();
if (fm.isDestroyed())
return false;
if (Config.getLastWhatsNewVersion() / 10 >= BuildConfig.VERSION_CODE / 10 &&
!recreate(activity))
return false;
create(activity);
Config.setWhatsNewShown();
return true;
}
}