Functioning welcome activity
This commit is contained in:
		
					parent
					
						
							
								c5c5daef07
							
						
					
				
			
			
				commit
				
					
						0670be555f
					
				
			
		
					 6 changed files with 56 additions and 74 deletions
				
			
		| 
						 | 
				
			
			@ -100,41 +100,9 @@ public class MainActivity extends ActionBarActivity{
 | 
			
		|||
                healDialog();
 | 
			
		||||
            }
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (id == R.id.action_edit_basics) {
 | 
			
		||||
            Intent intent = new Intent(this, Introduction.class);
 | 
			
		||||
            startActivity(intent.putExtra(
 | 
			
		||||
                    "first_time",
 | 
			
		||||
                    !p.getBoolean("saved", false)
 | 
			
		||||
            ));
 | 
			
		||||
            restoreData();
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (id == R.id.action_undo) {
 | 
			
		||||
            undo();
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (id == R.id.action_reset) {
 | 
			
		||||
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
 | 
			
		||||
            alert.setTitle(R.string.reset_confirmation_title);
 | 
			
		||||
            alert.setMessage(R.string.reset_confirmation);
 | 
			
		||||
            alert.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
 | 
			
		||||
                public void onClick(DialogInterface dialog, int whichButton) {
 | 
			
		||||
                    Toast.makeText(
 | 
			
		||||
                            getApplicationContext(),
 | 
			
		||||
                            R.string.message_reset,
 | 
			
		||||
                            Toast.LENGTH_LONG
 | 
			
		||||
                    ).show();
 | 
			
		||||
                    p.edit().clear().apply();
 | 
			
		||||
                    player = null;
 | 
			
		||||
                    restoreData();
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            alert.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
 | 
			
		||||
                public void onClick(DialogInterface dialog, int whichButton) {
 | 
			
		||||
                    // Canceled.
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            alert.show();
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (id == R.id.action_time_encounter_end) {
 | 
			
		||||
            AlertDialog.Builder alert = new AlertDialog.Builder(this);
 | 
			
		||||
            alert.setTitle(R.string.px_awarded_title);
 | 
			
		||||
| 
						 | 
				
			
			@ -184,14 +152,6 @@ public class MainActivity extends ActionBarActivity{
 | 
			
		|||
            alert.show();
 | 
			
		||||
            input.requestFocus();
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (id == R.id.action_download) {
 | 
			
		||||
            //TODO: create self-updater
 | 
			
		||||
            Toast.makeText(
 | 
			
		||||
                    getApplicationContext(),
 | 
			
		||||
                    "This function is not ready yet",
 | 
			
		||||
                    Toast.LENGTH_LONG
 | 
			
		||||
            ).show();
 | 
			
		||||
            return true;
 | 
			
		||||
        } else if (id == R.id.action_time_long_rest) {
 | 
			
		||||
            player.rest(true);
 | 
			
		||||
            Toast.makeText(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,35 +1,44 @@
 | 
			
		|||
package com.kauron.dungeonmanager;
 | 
			
		||||
 | 
			
		||||
import android.content.Intent;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.support.v7.app.ActionBarActivity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.view.Menu;
 | 
			
		||||
import android.view.MenuItem;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
import android.widget.Button;
 | 
			
		||||
import android.widget.TextView;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class Welcome extends ActionBarActivity {
 | 
			
		||||
 | 
			
		||||
    private Button load, newChar;
 | 
			
		||||
    private Button load;
 | 
			
		||||
    private SharedPreferences p;
 | 
			
		||||
    private TextView newText;
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        setContentView(R.layout.activity_welcome);
 | 
			
		||||
        newChar = (Button) findViewById(R.id.newCharacter);
 | 
			
		||||
        p = getSharedPreferences("basics", MODE_PRIVATE);
 | 
			
		||||
        load = (Button) findViewById(R.id.loadCharacter);
 | 
			
		||||
        load.setEnabled(
 | 
			
		||||
                getSharedPreferences("basics", MODE_PRIVATE).getBoolean("basics", false)
 | 
			
		||||
        );
 | 
			
		||||
        newText = (TextView) findViewById(R.id.newText);
 | 
			
		||||
        if (p.getBoolean("saved", false)) {
 | 
			
		||||
            load.setEnabled(true);
 | 
			
		||||
            load.setText(String.format(getString(R.string.load_text), p.getString("playerName", "")));
 | 
			
		||||
            newText.setVisibility(View.VISIBLE);
 | 
			
		||||
        } else {
 | 
			
		||||
            load.setEnabled(false);
 | 
			
		||||
            load.setText(R.string.load_character);
 | 
			
		||||
            newText.setVisibility(View.GONE);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO: putBoolean in the intent correctly
 | 
			
		||||
    public void onNewClick(View view) {
 | 
			
		||||
        startActivity(new Intent(this, Introduction.class).putExtra("first_time", true));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //TODO: get correctly the state of the saved game
 | 
			
		||||
    public void onLoadClick(View view) {
 | 
			
		||||
        startActivity(new Intent(this, MainActivity.class));
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -55,4 +64,18 @@ public class Welcome extends ActionBarActivity {
 | 
			
		|||
 | 
			
		||||
        return super.onOptionsItemSelected(item);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected void onResume() {
 | 
			
		||||
        super.onResume();
 | 
			
		||||
        if (p.getBoolean("saved", false)) {
 | 
			
		||||
            load.setEnabled(true);
 | 
			
		||||
            load.setText(String.format(getString(R.string.load_text), p.getString("playerName", "")));
 | 
			
		||||
            newText.setVisibility(View.VISIBLE);
 | 
			
		||||
        } else {
 | 
			
		||||
            load.setEnabled(false);
 | 
			
		||||
            load.setText(R.string.load_character);
 | 
			
		||||
            newText.setVisibility(View.GONE);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,12 +7,12 @@
 | 
			
		|||
    tools:context="com.kauron.dungeonmanager.Welcome"
 | 
			
		||||
    android:orientation="vertical">
 | 
			
		||||
 | 
			
		||||
    <Button
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:layout_width="wrap_content"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:text="Load character"
 | 
			
		||||
        android:id="@+id/loadCharacter"
 | 
			
		||||
        android:onClick="onLoadClick" />
 | 
			
		||||
        android:textAppearance="?android:attr/textAppearanceMedium"
 | 
			
		||||
        android:text="@string/new_character_warning"
 | 
			
		||||
        android:id="@+id/newText" />
 | 
			
		||||
 | 
			
		||||
    <Button
 | 
			
		||||
        android:layout_width="fill_parent"
 | 
			
		||||
| 
						 | 
				
			
			@ -21,4 +21,12 @@
 | 
			
		|||
        android:id="@+id/newCharacter"
 | 
			
		||||
        android:onClick="onNewClick" />
 | 
			
		||||
 | 
			
		||||
    <Button
 | 
			
		||||
        android:layout_width="match_parent"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:text="@string/load_character"
 | 
			
		||||
        android:id="@+id/loadCharacter"
 | 
			
		||||
        android:onClick="onLoadClick"
 | 
			
		||||
        android:layout_marginTop="10dp" />
 | 
			
		||||
 | 
			
		||||
</LinearLayout>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    xmlns:app="http://schemas.android.com/apk/res-auto"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
 | 
			
		||||
    <!--TODO: create fancy responsive toasts-->
 | 
			
		||||
    <item
 | 
			
		||||
        android:id="@+id/action_undo"
 | 
			
		||||
        android:title="@string/action_undo"
 | 
			
		||||
| 
						 | 
				
			
			@ -37,24 +38,6 @@
 | 
			
		|||
                    android:orderInCategory="2"
 | 
			
		||||
                    app:showAsAction="never"/>
 | 
			
		||||
            </menu>
 | 
			
		||||
 | 
			
		||||
        </item>
 | 
			
		||||
 | 
			
		||||
    <item
 | 
			
		||||
        android:id="@+id/action_edit_basics"
 | 
			
		||||
        android:title="@string/action_edit_basics"
 | 
			
		||||
        android:orderInCategory="20"
 | 
			
		||||
        app:showAsAction="never"
 | 
			
		||||
        android:icon="@drawable/ic_action_edit"/>
 | 
			
		||||
    <item
 | 
			
		||||
        android:id="@+id/action_download"
 | 
			
		||||
        android:title="@string/action_download"
 | 
			
		||||
        android:orderInCategory="25"
 | 
			
		||||
        app:showAsAction="never"/>
 | 
			
		||||
    <item
 | 
			
		||||
        android:id="@+id/action_reset"
 | 
			
		||||
        android:title="@string/action_reset"
 | 
			
		||||
        android:orderInCategory="30"
 | 
			
		||||
        app:showAsAction="never" />
 | 
			
		||||
 | 
			
		||||
</menu>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -66,7 +66,13 @@
 | 
			
		|||
    <string name="dialog_resolve_max_pg_title">Atención</string>
 | 
			
		||||
    <string name="empty_field">Por favor, escribe algo</string>
 | 
			
		||||
    <string name="action_download">Actualizar app</string>
 | 
			
		||||
    <string name="message_no_back_button_intro">No puedes volver atrás. Para crear tu personaje pulsa el botón de guardar</string>
 | 
			
		||||
    <string name="message_no_back_button_intro">Tu personaje no se ha guardado</string>
 | 
			
		||||
    <string name="long_rest_done">Has descansado y restaurado todos tus poderes</string>
 | 
			
		||||
    <string name="rest_done">Tus poderes de encuentro han sido restaurados</string>
 | 
			
		||||
    <string name="action_settings">Ajustes</string>
 | 
			
		||||
    <string name="load_text">Cargar %1$s</string>
 | 
			
		||||
    <string name="new_character">Nuevo personaje</string>
 | 
			
		||||
    <string name="title_activity_welcome">Bienvenido</string>
 | 
			
		||||
    <string name="load_character">Cargar personaje</string>
 | 
			
		||||
    <string name="new_character_warning">Esto borrará al personaje anterior</string>
 | 
			
		||||
</resources>
 | 
			
		||||
| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
    <string name="VOL">VOL</string>
 | 
			
		||||
    <string name="defense">Defense</string>
 | 
			
		||||
    <string name="curative_efforts">Curative efforts</string>
 | 
			
		||||
    <string name="load_text">Load %1$s</string>
 | 
			
		||||
    <string name="rest_done">Your encounter powers have been restored</string>
 | 
			
		||||
    <string name="long_rest_done">All your stats have been restored</string>
 | 
			
		||||
    <string name="action_reset">Reset</string>
 | 
			
		||||
| 
						 | 
				
			
			@ -73,10 +74,11 @@
 | 
			
		|||
    <string name="dialog_resolve_max_pg_title">Alert</string>
 | 
			
		||||
    <string name="dialog_resolve_max_pg_message">Couldn\'t compute your max PG based on your level</string>
 | 
			
		||||
    <string name="action_download">Update app</string>
 | 
			
		||||
    <string name="message_no_back_button_intro">You can\'t go back. Fill the information and press the save button.</string>
 | 
			
		||||
    <string name="message_no_back_button_intro">Your information hasn\'t been saved</string>
 | 
			
		||||
    <string name="title_activity_welcome">Welcome</string>
 | 
			
		||||
 | 
			
		||||
    <string name="hello_world">Hello world!</string>
 | 
			
		||||
    <string name="action_settings">Settings</string>
 | 
			
		||||
    <string name="new_character">New character</string>
 | 
			
		||||
    <string name="load_character">Load character</string>
 | 
			
		||||
    <string name="new_character_warning">This will erase any previously existing data saved</string>
 | 
			
		||||
</resources>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue