update to new api-result, list achievements in 3 columns, show achievement dialog

This commit is contained in:
Negue 2016-09-08 17:22:59 +02:00
parent 6840009e93
commit 85d0ac004d
11 changed files with 229 additions and 115 deletions

View file

@ -377,11 +377,13 @@
android:layout_height="wrap_content"
android:indeterminate="true" />
<LinearLayout
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/achievement_groupList"
android:orientation="vertical" />
android:layout_height="match_parent"
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="@color/md_grey_500"
android:scrollbars="vertical" />
</LinearLayout>
</android.support.v7.widget.CardView>

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dip">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:id="@+id/achievement_image"
android:layout_width="30dp"
android:layout_height="33dp"
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/achievement_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:paddingLeft="15dip"
android:text="example title" />
</LinearLayout>
<TextView
android:id="@+id/achievement_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="example text"
android:paddingTop="15dip" />
</LinearLayout>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<TextView
android:id="@+id/label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/section_leftright_padding"
android:layout_marginRight="@dimen/section_leftright_padding"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="@+id/purchaseSetButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>

View file

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
style="@style/CardText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/achievement_title"
android:textStyle="bold" />
<com.habitrpg.android.habitica.ui.controls.StaticGridView
android:id="@+id/achievement_gridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="40dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:layout_marginBottom="10dp"
android:gravity="center"/>
</LinearLayout>

View file

@ -1,24 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="@+id/achievement_item_layout"
android:orientation="vertical">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/achievement_drawee"
android:layout_width="28dp"
android:layout_height="30dp"
android:layout_width="30dp"
android:layout_height="33dp"
fresco:actualImageScaleType="centerCrop" />
android:layout_gravity="center_horizontal" />
<TextView
android:id="@+id/achievement_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="2dip"
android:layout_marginRight="2dip" />
android:layout_gravity="center_horizontal"
android:gravity="center" />
</FrameLayout>
</LinearLayout>

View file

@ -7,6 +7,8 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@ -38,6 +40,8 @@ import com.habitrpg.android.habitica.ui.adapter.social.AchievementAdapter;
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
import com.habitrpg.android.habitica.ui.helpers.UiUtils;
import com.magicmicky.habitrpgwrapper.lib.models.Achievement;
import com.magicmicky.habitrpgwrapper.lib.models.AchievementGroup;
import com.magicmicky.habitrpgwrapper.lib.models.AchievementResult;
import com.magicmicky.habitrpgwrapper.lib.models.Buffs;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Outfit;
@ -127,8 +131,8 @@ public class FullProfileActivity extends BaseActivity {
@BindView(R.id.avatar_achievements_progress)
ProgressBar achievementProgress;
@BindView(R.id.achievement_groupList)
LinearLayout achievementGroupList;
@BindView(R.id.recyclerView)
RecyclerView achievementGroupList;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -257,47 +261,42 @@ public class FullProfileActivity extends BaseActivity {
});
}
private void fillAchievements(AchievementResult achievements) {
List<Object> items = new ArrayList<>();
private void fillAchievements(HashMap<String, Achievement> achievements){
LinkedHashMap<String, List<Achievement>> orderedSortedList = new LinkedHashMap<>();
fillAchievements(achievements.basic, items);
fillAchievements(achievements.seasonal, items);
fillAchievements(achievements.special, items);
// Order by ID first
ArrayList<Achievement> achievementList = new ArrayList<>(achievements.values());
Collections.sort(achievementList, (achievement, t1) -> Double.compare(achievement.index, t1.index));
AchievementAdapter adapter = new AchievementAdapter();
adapter.setItemList(items);
// Map to Category
for(Achievement achievement : achievementList){
if(orderedSortedList.containsKey(achievement.category)){
orderedSortedList.get(achievement.category).add(achievement);
} else {
ArrayList<Achievement> arrayList = new ArrayList<>();
arrayList.add(achievement);
orderedSortedList.put(achievement.category, arrayList);
GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (adapter.getItemViewType(position) == 0) {
return layoutManager.getSpanCount();
} else {
return 1;
}
}
}
for(Map.Entry<String, List<Achievement>> entry : orderedSortedList.entrySet())
{
LinearLayout groupRow = (LinearLayout) getLayoutInflater().inflate(R.layout.profile_achievement_group, null);
GridView groupGrid = (GridView) groupRow.findViewById(R.id.achievement_gridview);
TextView textView = (TextView) groupRow.findViewById(R.id.achievement_title);
textView.setText(entry.getKey());
AchievementAdapter adapter = new AchievementAdapter(this, entry.getValue());
groupGrid.setAdapter(adapter);
achievementGroupList.addView(groupRow);
}
});
achievementGroupList.setLayoutManager(layoutManager);
achievementGroupList.setAdapter(adapter);
stopAndHideProgress(achievementProgress);
}
private void fillAchievements(AchievementGroup achievementGroup, List<Object> targetList){
// Order by ID first
ArrayList<Achievement> achievementList = new ArrayList<>(achievementGroup.achievements.values());
Collections.sort(achievementList, (achievement, t1) -> Double.compare(achievement.index, t1.index));
targetList.add(achievementGroup.label);
targetList.addAll(achievementList);
}
private int countEntries(HashMap<String, Integer> hashMap) {
if(hashMap == null)

View file

@ -1,79 +1,144 @@
package com.habitrpg.android.habitica.ui.adapter.social;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Animatable;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.controller.BaseControllerListener;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.image.ImageInfo;
import com.habitrpg.android.habitica.HabiticaApplication;
import com.habitrpg.android.habitica.R;
import com.habitrpg.android.habitica.ui.AvatarView;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder;
import com.magicmicky.habitrpgwrapper.lib.models.Achievement;
import java.util.Collection;
import java.util.List;
public class AchievementAdapter extends BaseAdapter {
private Context context;
private Achievement[] achievements;
import butterknife.BindView;
import butterknife.ButterKnife;
public AchievementAdapter(Context context, Collection<Achievement> achievements) {
this.context = context;
this.achievements =new Achievement[achievements.size()];
achievements.toArray(this.achievements);
public class AchievementAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public String itemType;
public MainActivity activity;
private List<Object> itemList;
public <T extends Achievement> void setItemList(List<Object> itemList) {
this.itemList = itemList;
this.notifyDataSetChanged();
}
public View getView(int position, View convertView, ViewGroup parent) {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == 0) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.profile_achievement_category, parent, false);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return new SectionViewHolder(view);
} else {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.profile_achievement_item, parent, false);
View gridView;
return new AchievementViewHolder(view);
}
}
gridView = inflater.inflate(R.layout.profile_achievement_item, null);
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
Object obj = this.itemList.get(position);
if (obj.getClass().equals(String.class)) {
((SectionViewHolder) holder).bind((String) obj);
} else {
((AchievementViewHolder) holder).bind((Achievement) itemList.get(position));
}
}
@Override
public int getItemViewType(int position) {
if (this.itemList.get(position).getClass().equals(String.class)) {
return 0;
} else {
return 1;
}
}
TextView counterText = (TextView) gridView.findViewById(R.id.achievement_text);
SimpleDraweeView draweeView = (SimpleDraweeView) gridView.findViewById(R.id.achievement_drawee);
@Override
public int getItemCount() {
return itemList == null ? 0 : itemList.size();
}
Achievement achiev = achievements[position];
class AchievementViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
Achievement achievement;
draweeView.setController(Fresco.newDraweeControllerBuilder()
.setUri(AvatarView.IMAGE_URI_ROOT + achiev.icon.toLowerCase() + ".png")
@BindView(R.id.achievement_drawee)
SimpleDraweeView draweeView;
@BindView(R.id.achievement_text)
TextView titleView;
@BindView(R.id.achievement_item_layout)
LinearLayout item_layout;
Resources resources;
public AchievementViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
item_layout = (LinearLayout) itemView;
resources = itemView.getResources();
item_layout.setClickable(true);
item_layout.setOnClickListener(this);
}
public void bind(Achievement item) {
draweeView.setController(Fresco.newDraweeControllerBuilder()
.setUri(AvatarView.IMAGE_URI_ROOT + item.icon.toLowerCase() + ".png")
.setControllerListener(new BaseControllerListener<ImageInfo>() {
@Override
public void onFailure(String id, Throwable throwable) {
Log.e("Achievemnt", "Couldn't load "+achiev.icon.toLowerCase());
Log.e("Achievemnt", "Couldn't load "+item.icon.toLowerCase());
}
})
.build());
return gridView;
}
@Override
public int getCount() {
return achievements.length;
}
this.achievement = item;
titleView.setText(item.title);
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public void onClick(View view) {
AlertDialog.Builder b = new AlertDialog.Builder(HabiticaApplication.currentActivity);
@Override
public long getItemId(int position) {
return 0;
}
View customView = LayoutInflater.from(itemView.getContext())
.inflate(R.layout.dialog_achievement_details, null);
ImageView achievementImage = (ImageView)customView.findViewById(R.id.achievement_image);
achievementImage.setImageDrawable(draweeView.getDrawable());
static class ViewHolder {
TextView counterText;
SimpleDraweeView draweeView;
TextView titleView = (TextView) customView.findViewById(R.id.achievement_title);
titleView.setText(achievement.title);
TextView textView = (TextView) customView.findViewById(R.id.achievement_text);
textView.setText(achievement.text);
b.setView(customView);
b.show();
}
}
}
}

View file

@ -1,6 +1,6 @@
package com.magicmicky.habitrpgwrapper.lib.api;
import com.magicmicky.habitrpgwrapper.lib.models.Achievement;
import com.magicmicky.habitrpgwrapper.lib.models.AchievementResult;
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
import com.magicmicky.habitrpgwrapper.lib.models.ContentResult;
import com.magicmicky.habitrpgwrapper.lib.models.Group;
@ -29,7 +29,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.DELETE;
import retrofit2.http.GET;
@ -241,7 +240,7 @@ public interface ApiService {
Observable<HabitRPGUser> GetMember(@Path("mid") String memberId);
@GET("members/{mid}/achievements")
Observable<HashMap<String, Achievement>> GetMemberAchievements(@Path("mid") String memberId);
Observable<AchievementResult> GetMemberAchievements(@Path("mid") String memberId);
@POST("members/send-private-message")
Observable<PostChatMessageResult> postPrivateMessage(@Body HashMap<String, String> messageDetails);

View file

@ -10,4 +10,5 @@ public class Achievement {
public String value;
public boolean earned;
public int index;
public int optionalCount;
}

View file

@ -0,0 +1,8 @@
package com.magicmicky.habitrpgwrapper.lib.models;
import java.util.HashMap;
public class AchievementGroup {
public String label;
public HashMap<String, Achievement> achievements;
}

View file

@ -0,0 +1,7 @@
package com.magicmicky.habitrpgwrapper.lib.models;
public class AchievementResult {
public AchievementGroup basic;
public AchievementGroup seasonal;
public AchievementGroup special;
}