mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 05:38:55 +00:00
Allow users to select owned customizations
This commit is contained in:
parent
d57c9eb612
commit
d9d795fb3b
16 changed files with 717 additions and 79 deletions
|
|
@ -8,13 +8,15 @@
|
|||
<variable name="valueInt" type="int"/>
|
||||
<variable name="imageNamed" type="String"/>
|
||||
</data>
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="60dp"
|
||||
android:padding="5dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:clickable="true"
|
||||
android:background="@drawable/btn_habit_background">
|
||||
<ImageView
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
|
|
@ -35,11 +37,9 @@
|
|||
<TextView android:layout_margin="5dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/task_gray"
|
||||
android:textColor="@android:color/darker_gray"
|
||||
tools:text="Value"
|
||||
android:text="@{value != null ? value : (valueInt != 0 ? String.valueOf(valueInt) : @string/avatar_nothing)}" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
</layout>
|
||||
24
Habitica/res/layout/customization_grid_item.xml
Normal file
24
Habitica/res/layout/customization_grid_item.xml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/card_view"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent">
|
||||
<LinearLayout
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="60dp"
|
||||
android:padding="5dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:orientation="vertical"
|
||||
android:clickable="true"
|
||||
android:background="@drawable/btn_habit_background">
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:scaleType="fitEnd"/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
11
Habitica/res/layout/customization_section_header.xml
Normal file
11
Habitica/res/layout/customization_section_header.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="horizontal" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/label"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_marginTop="12dp"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -35,45 +35,60 @@
|
|||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp">
|
||||
android:layout_margin="@dimen/card_horizontal_padding">
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="40dp">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/textView3"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:text="@string/avatar_size"
|
||||
android:gravity="center_vertical"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/avatar_size_spinner"
|
||||
android:spinnerMode="dropdown"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:entries="@array/avatar_sizes"/>
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:id="@+id/textView3"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:text="@string/avatar_size"
|
||||
android:gravity="center_vertical"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/avatar_size_spinner"
|
||||
android:spinnerMode="dropdown"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:entries="@array/avatar_sizes"/>
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_shirt"
|
||||
bind:title="@{@string/avatar_shirt}"
|
||||
bind:value="@{preferences.getShirt}"
|
||||
bind:imageNamed='@{preferences.getSize + "_shirt_" + preferences.getShirt}'/>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_skin"
|
||||
bind:title="@{@string/avatar_skin}"
|
||||
bind:value="@{preferences.getSkin}"
|
||||
bind:imageNamed='@{"skin_" + preferences.getSkin}' />
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_shirt}"
|
||||
bind:value="@{preferences.getShirt}"
|
||||
bind:imageNamed='@{preferences.getSize + "_shirt_" + preferences.getShirt}'/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_skin}"
|
||||
bind:value="@{preferences.getSkin}"
|
||||
bind:imageNamed='@{"skin_" + preferences.getSkin}' />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -81,31 +96,66 @@
|
|||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_margin="5dp"/>
|
||||
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_color}"
|
||||
bind:value="@{preferences.getHair.getColor}"
|
||||
bind:imageNamed='@{"hair_bangs_1_" + preferences.getHair.getColor}' />
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_base}"
|
||||
bind:valueInt="@{preferences.getHair.getBase}"
|
||||
bind:imageNamed='@{preferences.getHair.getBase == 0 ? null : "hair_base_" + preferences.getHair.getBase + "_" + preferences.getHair.getColor}' />
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_bangs}"
|
||||
bind:valueInt="@{preferences.getHair.getBangs}"
|
||||
bind:imageNamed='@{preferences.getHair.getBangs == 0 ? null : "hair_bangs_" + preferences.getHair.getBangs + "_" + preferences.getHair.getColor}' />
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_flower}"
|
||||
bind:valueInt="@{preferences.getHair.getFlower}"
|
||||
bind:imageNamed='@{preferences.getHair.getFlower == 0 ? null : "hair_flower_" + preferences.getHair.getFlower}' />
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_beard}"
|
||||
bind:valueInt="@{preferences.getHair.getBeard}"
|
||||
bind:imageNamed='@{preferences.getHair.getBeard == 0 ? null : "hair_beard_" + preferences.getHair.getBeard + "_" + preferences.getHair.getColor}' />
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
bind:title="@{@string/avatar_mustache}"
|
||||
bind:valueInt="@{preferences.getHair.getMustache}"
|
||||
bind:imageNamed='@{preferences.getHair.getMustache == 0 ? null : "hair_mustache_" + preferences.getHair.getMustache + "_" + preferences.getHair.getColor}' />
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_hair_color"
|
||||
bind:title="@{@string/avatar_color}"
|
||||
bind:value="@{preferences.getHair.getColor}"
|
||||
bind:imageNamed='@{"hair_bangs_1_" + preferences.getHair.getColor}' />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_hair_base"
|
||||
bind:title="@{@string/avatar_base}"
|
||||
bind:valueInt="@{preferences.getHair.getBase}"
|
||||
bind:imageNamed='@{preferences.getHair.getBase == 0 ? null : "hair_base_" + preferences.getHair.getBase + "_" + preferences.getHair.getColor}' />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_hair_bangs"
|
||||
bind:title="@{@string/avatar_bangs}"
|
||||
bind:valueInt="@{preferences.getHair.getBangs}"
|
||||
bind:imageNamed='@{preferences.getHair.getBangs == 0 ? null : "hair_bangs_" + preferences.getHair.getBangs + "_" + preferences.getHair.getColor}' />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_hair_flower"
|
||||
bind:title="@{@string/avatar_flower}"
|
||||
bind:valueInt="@{preferences.getHair.getFlower}"
|
||||
bind:imageNamed='@{preferences.getHair.getFlower == 0 ? null : "hair_flower_" + preferences.getHair.getFlower}' />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_hair_beard"
|
||||
bind:title="@{@string/avatar_beard}"
|
||||
bind:valueInt="@{preferences.getHair.getBeard}"
|
||||
bind:imageNamed='@{preferences.getHair.getBeard == 0 ? null : "hair_beard_" + preferences.getHair.getBeard + "_" + preferences.getHair.getColor}' />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/hairline_height"
|
||||
android:background="@android:color/darker_gray"/>
|
||||
<include layout="@layout/avatar_overview_card"
|
||||
android:id="@+id/avatar_hair_mustache"
|
||||
bind:title="@{@string/avatar_mustache}"
|
||||
bind:valueInt="@{preferences.getHair.getMustache}"
|
||||
bind:imageNamed='@{preferences.getHair.getMustache == 0 ? null : "hair_mustache_" + preferences.getHair.getMustache + "_" + preferences.getHair.getColor}' />
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
</layout>
|
||||
|
|
@ -49,4 +49,5 @@
|
|||
<dimen name="login_field_width">350dp</dimen>
|
||||
<dimen name="task_top_bottom_padding">20dp</dimen>
|
||||
<dimen name="reward_spacing">8dp</dimen>
|
||||
<dimen name="grid_item_margin">6dp</dimen>
|
||||
</resources>
|
||||
|
|
@ -9,6 +9,11 @@ import com.google.gson.ExclusionStrategy;
|
|||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
|
@ -21,6 +26,7 @@ import com.magicmicky.habitrpgwrapper.lib.api.ApiService;
|
|||
import com.magicmicky.habitrpgwrapper.lib.api.InAppPurchasesApiService;
|
||||
import com.magicmicky.habitrpgwrapper.lib.api.Server;
|
||||
import com.magicmicky.habitrpgwrapper.lib.api.TypeAdapter.TagsAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PurchaseValidationRequest;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.PurchaseValidationResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.SkillList;
|
||||
|
|
@ -47,6 +53,7 @@ import retrofit.Profiler;
|
|||
import retrofit.RequestInterceptor;
|
||||
import retrofit.RestAdapter;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.converter.ConversionException;
|
||||
import retrofit.converter.GsonConverter;
|
||||
|
||||
|
||||
|
|
@ -209,6 +216,10 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
public String err;
|
||||
}
|
||||
|
||||
public class ErrorListResponse {
|
||||
public List<String> err;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Throwable handleError(RetrofitError cause) {
|
||||
|
||||
|
|
@ -219,17 +230,24 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
} else if (cause.getKind().equals(RetrofitError.Kind.HTTP)) {
|
||||
retrofit.client.Response response = cause.getResponse();
|
||||
|
||||
ErrorResponse res = (ErrorResponse) cause.getBodyAs(ErrorResponse.class) ;
|
||||
ErrorResponse res = null;
|
||||
|
||||
try {
|
||||
res = (ErrorResponse) cause.getBodyAs(ErrorResponse.class) ;
|
||||
} catch (RuntimeException e) {
|
||||
//Can cause errors when error is a list and not a string
|
||||
ErrorListResponse resList = (ErrorListResponse) cause.getBodyAs(ErrorListResponse.class);
|
||||
if (resList.err != null && resList.err.size() >= 1) {
|
||||
res = new ErrorResponse();
|
||||
res.err = resList.err.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
int status = response.getStatus();
|
||||
if (status == 401) {
|
||||
|
||||
if(res.err != null && !res.err.isEmpty())
|
||||
{
|
||||
if(res != null && res.err != null && !res.err.isEmpty()) {
|
||||
showConnectionProblemDialog("", res.err);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
showConnectionProblemDialog(R.string.authentication_error_title, R.string.authentication_error_body);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ public class HabitDatabase {
|
|||
|
||||
public static final String NAME = "Habitica";
|
||||
|
||||
public static final int VERSION = 5;
|
||||
public static final int VERSION = 6;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package com.habitrpg.android.habitica.events.commands;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by viirus on 13/01/16.
|
||||
*/
|
||||
public class UpdateUserCommand {
|
||||
|
||||
public Map<String, String> updateData;
|
||||
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@ import com.habitrpg.android.habitica.events.ToggledInnStateEvent;
|
|||
import com.habitrpg.android.habitica.events.commands.BuyRewardCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.DeleteTaskCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.OpenGemPurchaseFragmentCommand;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.ui.UiUtils;
|
||||
|
|
@ -461,6 +462,10 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
avatarInHeader.updateData(user);
|
||||
}
|
||||
|
||||
public void onEvent(UpdateUserCommand event) {
|
||||
mAPIHelper.apiService.updateUser(event.updateData, new HabitRPGUserCallback(this));
|
||||
}
|
||||
|
||||
public void onEvent(final BuyRewardCommand event) {
|
||||
final String rewardKey = event.Reward.getId();
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,172 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.commands.UpdateUserCommand;
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Customization;
|
||||
import com.raizlabs.android.dbflow.sql.language.Update;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
import de.greenrobot.event.EventBus;
|
||||
|
||||
/**
|
||||
* Created by viirus on 13/01/16.
|
||||
*/
|
||||
public class CustomizationRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private List<Object> customizationList;
|
||||
private String activeCustomization;
|
||||
public String userSize;
|
||||
public String hairColor;
|
||||
|
||||
public void setCustomizationList(List<Customization> newCustomizationList) {
|
||||
this.customizationList = new ArrayList<Object>();
|
||||
String lastSetName = null;
|
||||
for (Customization customization : newCustomizationList) {
|
||||
if (customization.getSet() != null && !customization.getSet().equals(lastSetName)) {
|
||||
customizationList.add(customization.getSet());
|
||||
lastSetName = customization.getSet();
|
||||
}
|
||||
customizationList.add(customization);
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setActiveCustomization(String activeCustomization) {
|
||||
this.activeCustomization = activeCustomization;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
|
||||
if (viewType == 0) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.customization_section_header, parent, false);
|
||||
|
||||
return new SectionViewHolder(view);
|
||||
} else {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.customization_grid_item, parent, false);
|
||||
|
||||
return new CustomizationViewHolder(view);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
||||
Object obj = customizationList.get(position);
|
||||
if (obj.getClass().equals(String.class)) {
|
||||
((SectionViewHolder)holder).bind((String) obj);
|
||||
} else {
|
||||
((CustomizationViewHolder)holder).bind((Customization) customizationList.get(position));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return customizationList == null ? 0 : customizationList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (this.customizationList.get(position).getClass().equals(String.class)) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
class CustomizationViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
|
||||
@Bind(R.id.card_view)
|
||||
CardView cardView;
|
||||
|
||||
@Bind(R.id.linearLayout)
|
||||
LinearLayout linearLayout;
|
||||
|
||||
@Bind(R.id.imageView)
|
||||
ImageView imageView;
|
||||
|
||||
Customization customization;
|
||||
|
||||
public CustomizationViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
linearLayout.setOnClickListener(this);
|
||||
}
|
||||
|
||||
public void bind(Customization customization) {
|
||||
this.customization = customization;
|
||||
|
||||
|
||||
DataBindingUtils.loadImage(this.imageView, customization.getImageName(userSize, hairColor));
|
||||
cardView.setCardBackgroundColor(android.R.color.white);
|
||||
if (customization.isUsable()) {
|
||||
imageView.setAlpha(1.0f);
|
||||
if (customization.getIdentifier().equals(activeCustomization)) {
|
||||
cardView.setCardBackgroundColor(R.color.brand_500);
|
||||
}
|
||||
} else {
|
||||
imageView.setAlpha(0.3f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!customization.isUsable() && customization.getIdentifier().equals(activeCustomization)) {
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateUserCommand command = new UpdateUserCommand();
|
||||
Map<String, String> updateData = new HashMap<String, String>();
|
||||
String updatePath = "preferences." + customization.getType();
|
||||
if (customization.getGroup() != null) {
|
||||
updatePath = updatePath + "." + customization.getGroup();
|
||||
}
|
||||
updateData.put(updatePath, customization.getIdentifier());
|
||||
command.updateData = updateData;
|
||||
|
||||
EventBus.getDefault().post(command);
|
||||
}
|
||||
}
|
||||
|
||||
class SectionViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private String sectionName;
|
||||
|
||||
@Bind(R.id.label)
|
||||
TextView label;
|
||||
|
||||
public SectionViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
ButterKnife.bind(this, itemView);
|
||||
}
|
||||
|
||||
public void bind(String sectionName) {
|
||||
this.sectionName = sectionName;
|
||||
String uppercasedSectionName = sectionName.substring(0, 1).toUpperCase() + sectionName.substring(1);
|
||||
this.label.setText(uppercasedSectionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,7 +23,6 @@ import de.greenrobot.event.EventBus;
|
|||
*/
|
||||
public class SkillsRecyclerViewAdapter extends RecyclerView.Adapter<SkillsRecyclerViewAdapter.SkillViewHolder> {
|
||||
|
||||
|
||||
private List<Skill> skillList;
|
||||
|
||||
public Double mana;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,141 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.widget.GridLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.adapter.CustomizationRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Customization;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Preferences;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Skill;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.sql.language.Where;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
/**
|
||||
* Created by viirus on 12/01/16.
|
||||
*/
|
||||
public class AvatarCustomizationFragment extends BaseFragment {
|
||||
|
||||
public String type;
|
||||
public String group;
|
||||
public String activeCustomization;
|
||||
|
||||
@Bind(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
CustomizationRecyclerViewAdapter adapter;
|
||||
GridLayoutManager layoutManager;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
View v = inflater.inflate(R.layout.fragment_recyclerview, container, false);
|
||||
|
||||
ButterKnife.bind(this, v);
|
||||
adapter = new CustomizationRecyclerViewAdapter();
|
||||
|
||||
layoutManager = new GridLayoutManager(activity, 2);
|
||||
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
|
||||
@Override
|
||||
public int getSpanSize(int position) {
|
||||
if (adapter.getItemViewType(position) == 0) {
|
||||
return layoutManager.getSpanCount();
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
setGridSpanCount(container.getWidth());
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
recyclerView.addItemDecoration(new MarginDecoration(activity));
|
||||
|
||||
recyclerView.setAdapter(adapter);
|
||||
this.loadCustomizations();
|
||||
|
||||
this.updateActiveCustomization();
|
||||
this.adapter.userSize = this.user.getPreferences().getSize();
|
||||
this.adapter.hairColor = this.user.getPreferences().getHair().getColor();
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private void loadCustomizations() {
|
||||
if(user == null || adapter == null){
|
||||
return;
|
||||
}
|
||||
|
||||
Where<Customization> select = new Select()
|
||||
.from(Customization.class)
|
||||
.where(Condition.column("type").eq(this.type))
|
||||
.and(Condition.CombinedCondition.begin(Condition.column("purchasable").eq(true))
|
||||
.or(Condition.column("purchased").eq(true))
|
||||
.or(Condition.column("price").eq(0))
|
||||
.or(Condition.column("price").isNull()));
|
||||
if (this.group != null) {
|
||||
select = select.and(Condition.column("group").eq(this.group));
|
||||
}
|
||||
select.orderBy(true, "set", "identifier");
|
||||
|
||||
List<Customization> customizations = select.queryList();
|
||||
adapter.setCustomizationList(customizations);
|
||||
}
|
||||
|
||||
private void setGridSpanCount(int width) {
|
||||
int spanCount = width / 100;
|
||||
layoutManager.setSpanCount(spanCount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(HabitRPGUser user) {
|
||||
super.updateUserData(user);
|
||||
this.updateActiveCustomization();
|
||||
}
|
||||
|
||||
private void updateActiveCustomization() {
|
||||
Preferences prefs = this.user.getPreferences();
|
||||
switch (this.type) {
|
||||
case "skin":
|
||||
this.activeCustomization = prefs.getSkin();
|
||||
break;
|
||||
case "shirt":
|
||||
this.activeCustomization = prefs.getShirt();
|
||||
break;
|
||||
case "hair":
|
||||
switch (this.group) {
|
||||
case "bangs":
|
||||
this.activeCustomization = String.valueOf(prefs.getHair().getBangs());
|
||||
break;
|
||||
case "base":
|
||||
this.activeCustomization = String.valueOf(prefs.getHair().getBase());
|
||||
break;
|
||||
case "color":
|
||||
this.activeCustomization = prefs.getHair().getColor();
|
||||
break;
|
||||
case "flower":
|
||||
this.activeCustomization = String.valueOf(prefs.getHair().getFlower());
|
||||
break;
|
||||
case "beard":
|
||||
this.activeCustomization = String.valueOf(prefs.getHair().getBeard());
|
||||
break;
|
||||
case "mustache":
|
||||
this.activeCustomization = String.valueOf(prefs.getHair().getMustache());
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.adapter.setActiveCustomization(this.activeCustomization);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -12,6 +15,7 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.databinding.FragmentAvatarOverviewBinding;
|
||||
import com.habitrpg.android.habitica.databinding.FragmentPartyInfoBinding;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Customization;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -30,6 +34,30 @@ public class AvatarOverviewFragment extends BaseFragment implements AdapterView.
|
|||
@Bind(R.id.avatar_size_spinner)
|
||||
Spinner avatarSizeSpinner;
|
||||
|
||||
@Bind(R.id.avatar_shirt)
|
||||
View avatarShirtView;
|
||||
|
||||
@Bind(R.id.avatar_skin)
|
||||
View avatarSkinView;
|
||||
|
||||
@Bind(R.id.avatar_hair_color)
|
||||
View avatarHairColorView;
|
||||
|
||||
@Bind(R.id.avatar_hair_base)
|
||||
View avatarHairBaseView;
|
||||
|
||||
@Bind(R.id.avatar_hair_bangs)
|
||||
View avatarHairBangsView;
|
||||
|
||||
@Bind(R.id.avatar_hair_flower)
|
||||
View avatarHairFlowerView;
|
||||
|
||||
@Bind(R.id.avatar_hair_beard)
|
||||
View avatarHairBeardView;
|
||||
|
||||
@Bind(R.id.avatar_hair_mustache)
|
||||
View avatarHairMustacheView;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
|
@ -44,9 +72,67 @@ public class AvatarOverviewFragment extends BaseFragment implements AdapterView.
|
|||
this.setSize(this.user.getPreferences().getSize());
|
||||
avatarSizeSpinner.setOnItemSelectedListener(this);
|
||||
|
||||
avatarShirtView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("shirt", null);
|
||||
}
|
||||
});
|
||||
|
||||
avatarSkinView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("skin", null);
|
||||
}
|
||||
});
|
||||
|
||||
avatarHairColorView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("hair", "color");
|
||||
}
|
||||
});
|
||||
avatarHairBangsView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("hair", "bangs");
|
||||
}
|
||||
});
|
||||
avatarHairBaseView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("hair", "base");
|
||||
}
|
||||
});
|
||||
avatarHairFlowerView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("hair", "flower");
|
||||
}
|
||||
});
|
||||
avatarHairBeardView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("hair", "beard");
|
||||
}
|
||||
});
|
||||
avatarHairMustacheView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
displayCustomizationFragment("hair", "mustache");
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
private void displayCustomizationFragment(String type, String group) {
|
||||
AvatarCustomizationFragment fragment = new AvatarCustomizationFragment();
|
||||
fragment.type = type;
|
||||
fragment.group = group;
|
||||
activity.displayFragment(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(HabitRPGUser user) {
|
||||
super.updateUserData(user);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.habitrpg.android.habitica.ui.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
/**
|
||||
* Created by viirus on 13/01/16.
|
||||
*/
|
||||
public class MarginDecoration extends RecyclerView.ItemDecoration {
|
||||
private int margin;
|
||||
|
||||
public MarginDecoration(Context context) {
|
||||
margin = context.getResources().getDimensionPixelSize(R.dimen.grid_item_margin);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(
|
||||
Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
outRect.set(margin, margin, margin, margin);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
import com.habitrpg.android.habitica.HabitDatabase;
|
||||
import com.raizlabs.android.dbflow.annotation.Column;
|
||||
import com.raizlabs.android.dbflow.annotation.ConflictAction;
|
||||
import com.raizlabs.android.dbflow.annotation.PrimaryKey;
|
||||
import com.raizlabs.android.dbflow.annotation.Table;
|
||||
import com.raizlabs.android.dbflow.annotation.Unique;
|
||||
import com.raizlabs.android.dbflow.annotation.UniqueGroup;
|
||||
import com.raizlabs.android.dbflow.structure.BaseModel;
|
||||
|
||||
/**
|
||||
* Created by viirus on 13/01/16.
|
||||
*/
|
||||
@Table(databaseName = HabitDatabase.NAME)
|
||||
public class Customization extends BaseModel {
|
||||
|
||||
@Column
|
||||
@PrimaryKey
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
private String identifier, group, type, notes, set, text;
|
||||
|
||||
@Column
|
||||
private boolean purchasable, purchased;
|
||||
|
||||
@Column
|
||||
private Integer price;
|
||||
|
||||
public void updateID() {
|
||||
this.id = this.identifier + "_" + this.type + "_" + this.group;
|
||||
}
|
||||
|
||||
public void setIdentifier(String identifier) {
|
||||
this.identifier = identifier;
|
||||
this.updateID();
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
this.updateID();
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
this.updateID();
|
||||
}
|
||||
|
||||
public void setId(String id) {this.id = id;}
|
||||
public void setNotes(String notes) {this.notes = notes;}
|
||||
public void setSet(String set) {this.set = set;}
|
||||
public void setText(String text) {this.text = text;}
|
||||
public void setPurchasable(boolean purchasable) {this.purchasable = purchasable;}
|
||||
public void setPurchased(boolean purchased) {this.purchased = purchased;}
|
||||
public void setPrice(Integer price) {this.price = price;}
|
||||
|
||||
public String getId() { return this.id; }
|
||||
public String getIdentifier() { return this.identifier; }
|
||||
public String getGroup() { return this.group; }
|
||||
public String getType() { return this.type; }
|
||||
public String getNotes() { return this.notes; }
|
||||
public String getSet() { return this.set; }
|
||||
public String getText() { return this.text; }
|
||||
public boolean getPurchasable() { return this.purchasable; }
|
||||
public boolean getPurchased() { return this.purchased; }
|
||||
public Integer getPrice() { return this.price; }
|
||||
|
||||
public String getImageName(String userSize, String hairColor) {
|
||||
|
||||
switch (this.type) {
|
||||
case "skin":
|
||||
return "skin_" + this.identifier;
|
||||
case "shirt":
|
||||
return userSize + "_shirt_" + this.identifier;
|
||||
case "hair":
|
||||
if (this.identifier.equals("0")) {
|
||||
return "head_0";
|
||||
}
|
||||
|
||||
switch (this.group) {
|
||||
case "color":
|
||||
return "hair_bangs_1_" + this.identifier;
|
||||
case "flower":
|
||||
return "hair_flower_" + this.identifier;
|
||||
default:
|
||||
return "hair_" + this.group + "_" + this.identifier + "_" + hairColor;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isUsable() {
|
||||
return this.price == null || this.price == 0 || this.purchased;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -12,10 +12,7 @@ import com.raizlabs.android.dbflow.annotation.Table;
|
|||
public class Stats extends PlayerMinStats{
|
||||
|
||||
@Column
|
||||
private int toNextLevel;//xp needed to be earned
|
||||
|
||||
@Column
|
||||
private int maxHealth, maxMP;
|
||||
private int toNextLevel, maxHealth, maxMP;
|
||||
|
||||
|
||||
public int getToNextLevel() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue