Skip to content

Commit

Permalink
Create WelcomeActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
StefMa committed Jun 14, 2016
1 parent 2b3ad75 commit 022b545
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".onboarding.WelcomeActivity"
android:excludeFromRecents="true"
android:noHistory="true"/>
<activity
android:name=".main.MainActivity"
android:label="@string/app_name"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onResponse(Call<UserResult> call, Response<UserResult> response) {
dialog.dismiss();
} else if (Objects.equals(userResult.getResult(), UserResult.RESULT_OK)) {
SettingsManager.saveUserToken(context, userResult.getToken());
context.startActivity(MainActivity.newInstance(context));
context.startActivity(WelcomeActivity.newInstance(context, userResult));
dialog.dismiss();
}
} else {
Expand Down
36 changes: 36 additions & 0 deletions app/src/main/java/guru/stefma/timetracking/onboarding/Welcome.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package guru.stefma.timetracking.onboarding;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import guru.stefma.timetracking.main.MainActivity;

public class Welcome {

public static final String KEY_USER_TOKEN = "KEY_USER_TOKEN";

public static final String KEY_USERNAME = "KEY_USERNAME";

private final Context mContext;

private final Bundle mExtras;

public Welcome(Context context, Bundle extras) {
mContext = context;
mExtras = extras;
}

public String getUsername() {
return mExtras.getString(KEY_USERNAME);
}

public String getToken() {
return mExtras.getString(KEY_USER_TOKEN);
}

public void onOkClicked(View view) {
mContext.startActivity(MainActivity.newInstance(mContext));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package guru.stefma.timetracking.onboarding;

import android.content.Context;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import guru.stefma.restapi.objects.user.UserResult;
import guru.stefma.timetracking.R;
import guru.stefma.timetracking.databinding.ActivityWelcomeBinding;

public class WelcomeActivity extends AppCompatActivity {

public static Intent newInstance(Context context, UserResult token) {
Intent intent = new Intent(context, WelcomeActivity.class);
intent.putExtra(Welcome.KEY_USER_TOKEN, token.getToken());
intent.putExtra(Welcome.KEY_USERNAME, token.getUsername());
return intent;
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityWelcomeBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_welcome);
binding.setWelcome(new Welcome(this, getIntent().getExtras()));
}

}
83 changes: 83 additions & 0 deletions app/src/main/res/layout/activity_welcome.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<layout 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">

<data>

<variable
name="welcome"
type="guru.stefma.timetracking.onboarding.Welcome"/>
</data>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<View
android:layout_width="match_parent"
android:layout_height="188dp"
android:background="@color/colorPrimaryDark"/>

<TextView
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/monster"
android:layout_marginTop="@dimen/big"
android:text="@string/welcome"
android:textAppearance="@style/TextAppearance.AppCompat.Display2"/>

<TextView
android:id="@+id/token"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/welcome"
android:layout_marginEnd="@dimen/monster"
android:layout_marginStart="@dimen/monster"
android:text="@{welcome.token}"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textIsSelectable="true"
tools:text="12891280192918289129"/>

<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/token"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/monster"
android:layout_marginEnd="@dimen/monster"
android:layout_marginStart="@dimen/monster"
android:layout_marginTop="@dimen/normal"
android:elevation="@dimen/cardview_default_elevation"
app:cardBackgroundColor="@color/cardview_dark_background"
app:cardCornerRadius="@dimen/cardview_default_radius">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/small"
android:text="@{@string/introducing(welcome.username)}"
tools:text="@string/introducing"/>
</ScrollView>

</android.support.v7.widget.CardView>

<Button
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="match_parent"
android:layout_height="@dimen/monster"
android:layout_alignParentBottom="true"
android:elevation="4dp"
android:gravity="end|center_vertical"
android:onClick="@{welcome.onOkClicked}"
android:paddingEnd="@dimen/big"
android:paddingStart="@dimen/big"
android:text="@string/ok"/>

</RelativeLayout>
</layout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@
<dimen name="small">8dp</dimen>
<dimen name="tiny">4dp</dimen>
<dimen name="normal">16dp</dimen>
<dimen name="big">32dp</dimen>
<dimen name="monster">48dp</dimen>
<dimen name="tile_size">48dp</dimen>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@
<string name="have_account">Already have a Account?</string>
<string name="token">Token</string>
<string name="login">Login</string>
<string name="introducing">Hello %1$s,\n\nThis is your user token. It\'s very important to save it on a safe place. \n\n<b>Caution: </b>This is your \"password\" too. If you want to login on a other device you can use this token.</string>
<string name="welcome">Welcome</string>
<string name="ok">OK</string>
</resources>

0 comments on commit 022b545

Please sign in to comment.