Skip to content

Commit

Permalink
Converted WarmWelcomeFragment to screen+layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
codeka committed Sep 6, 2017
1 parent 27b1aad commit f72b9b1
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import au.com.codeka.warworlds.client.ctrl.DebugView;
import au.com.codeka.warworlds.client.game.starfield.StarfieldManager;
import au.com.codeka.warworlds.client.game.welcome.CreateEmpireFragment;
import au.com.codeka.warworlds.client.game.welcome.WarmWelcomeFragment;
import au.com.codeka.warworlds.client.game.welcome.WarmWelcomeScreen;
import au.com.codeka.warworlds.client.game.welcome.WelcomeScreen;
import au.com.codeka.warworlds.client.opengl.RenderSurfaceView;
import au.com.codeka.warworlds.client.ui.ScreenStack;
Expand Down Expand Up @@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
// TODO: restore the view state?
}
if (!GameSettings.i.getBoolean(GameSettings.Key.WARM_WELCOME_SEEN)) {
getFragmentTransitionManager().replaceFragment(WarmWelcomeFragment.class);
screenStack.push(new WarmWelcomeScreen());
} else if (GameSettings.i.getString(GameSettings.Key.COOKIE).isEmpty()) {
getFragmentTransitionManager().replaceFragment(CreateEmpireFragment.class);
} else {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package au.com.codeka.warworlds.client.game.welcome;

import android.content.Context;
import android.widget.RelativeLayout;
import au.com.codeka.warworlds.client.R;
import au.com.codeka.warworlds.client.ctrl.TransparentWebView;
import au.com.codeka.warworlds.client.util.ViewBackgroundGenerator;
import javax.annotation.Nonnull;

/**
* Layout for {@link WarmWelcomeScreen}.
*/
public class WarmWelcomeLayout extends RelativeLayout {
public interface Callbacks {
void onStartClick();
void onPrivacyPolicyClick();
void onHelpClick();
}

private final Callbacks callbacks;

public WarmWelcomeLayout(Context context, @Nonnull Callbacks callbacks) {
super(context);
inflate(context, R.layout.frag_warm_welcome, this);
this.callbacks = callbacks;

ViewBackgroundGenerator.setBackground(this);

TransparentWebView welcome = findViewById(R.id.welcome);
String msg = TransparentWebView.getHtmlFile(getContext(), "html/warm-welcome.html");
welcome.loadHtml("html/skeleton.html", msg);

findViewById(R.id.next_btn).setOnClickListener(v -> callbacks.onStartClick());
findViewById(R.id.help_btn).setOnClickListener(v -> callbacks.onHelpClick());
findViewById(R.id.privacy_policy_btn).setOnClickListener(v -> callbacks.onPrivacyPolicyClick());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package au.com.codeka.warworlds.client.game.welcome;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import au.com.codeka.warworlds.client.R;
import au.com.codeka.warworlds.client.activity.BaseFragment;
import au.com.codeka.warworlds.client.activity.SharedViewHolder;
import au.com.codeka.warworlds.client.ctrl.TransparentWebView;
import au.com.codeka.warworlds.client.ui.Screen;
import au.com.codeka.warworlds.client.ui.ScreenContext;
import au.com.codeka.warworlds.client.util.GameSettings;
import au.com.codeka.warworlds.client.util.ViewBackgroundGenerator;

/**
* This fragment is shown the first time you start the game. We give you a quick intro, some links
* to the website and stuff like that.
*/
public class WarmWelcomeScreen extends Screen {
private WarmWelcomeLayout layout;

@Override
public void onCreate(ScreenContext context, LayoutInflater layoutInflater, ViewGroup container) {
layout = new WarmWelcomeLayout(layoutInflater.getContext(), new WarmWelcomeLayout.Callbacks() {
@Override
public void onStartClick() {
// save the fact that we've finished the warm welcome
GameSettings.i.edit()
.setBoolean(GameSettings.Key.WARM_WELCOME_SEEN, true)
.commit();

context.pushScreen(new WelcomeScreen());
// TODO: should be CreateEmpireScreen().
// getFragmentTransitionManager().replaceFragment(
// CreateEmpireFragment.class,
// SharedViewHolder.builder()
// .addSharedView(R.id.title_icon, "title_icon")
// .addSharedView(R.id.title, "title")
// .addSharedView(R.id.next_btn, "done_btn")
// .build());
}

@Override
public void onPrivacyPolicyClick() {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.war-worlds.com/privacy-policy"));
context.startActivity(i);
}

@Override
public void onHelpClick() {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.war-worlds.com/doc/getting-started"));
context.startActivity(i);
}
});
}

@Override
public View onShow() {
return layout;
}
}
6 changes: 4 additions & 2 deletions client/src/main/res/layout/frag_warm_welcome.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:parentTag="RelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false">
Expand Down Expand Up @@ -78,4 +80,4 @@
android:layout_marginLeft="@dimen/tablet_margin"
android:layout_marginRight="@dimen/tablet_margin"
android:layout_marginTop="10dp"/>
</RelativeLayout>
</merge>

0 comments on commit f72b9b1

Please sign in to comment.