mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-19 04:14:12 +00:00
first implementation of achievements as grid (auto break newline)
This commit is contained in:
parent
23353cce9b
commit
6840009e93
9 changed files with 285 additions and 0 deletions
|
|
@ -351,5 +351,39 @@
|
|||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:id="@+id/profile_achievements_card"
|
||||
style="@style/CardView.Default"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
style="@style/CardContent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
style="@style/CardTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/profile_achievements"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/avatar_achievements_progress"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:indeterminate="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/achievement_groupList"
|
||||
android:orientation="vertical" />
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
24
Habitica/res/layout/profile_achievement_group.xml
Normal file
24
Habitica/res/layout/profile_achievement_group.xml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?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>
|
||||
24
Habitica/res/layout/profile_achievement_item.xml
Normal file
24
Habitica/res/layout/profile_achievement_item.xml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout 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:orientation="vertical">
|
||||
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/achievement_drawee"
|
||||
|
||||
android:layout_width="28dp"
|
||||
android:layout_height="30dp"
|
||||
|
||||
fresco:actualImageScaleType="centerCrop" />
|
||||
|
||||
<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" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
@ -11,4 +11,6 @@
|
|||
<string name="profile_allocated">Allocated:</string>
|
||||
<string name="profile_boosts">Boosts:</string>
|
||||
<string name="profile_private_message">Private Message</string>
|
||||
<string name="profile_achievements">Achievements</string>
|
||||
|
||||
</resources>
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
|
@ -10,7 +11,12 @@ import android.view.LayoutInflater;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.GridView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.TableLayout;
|
||||
|
|
@ -28,8 +34,10 @@ import com.habitrpg.android.habitica.R;
|
|||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.ui.AvatarView;
|
||||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
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.Buffs;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Outfit;
|
||||
|
|
@ -39,8 +47,14 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
|
|||
|
||||
import net.pherth.android.emoji_library.EmojiEditText;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -107,6 +121,15 @@ public class FullProfileActivity extends BaseActivity {
|
|||
@BindView(R.id.profile_mount_count)
|
||||
TextView mountCount;
|
||||
|
||||
@BindView(R.id.profile_achievements_card)
|
||||
CardView achievementCard;
|
||||
|
||||
@BindView(R.id.avatar_achievements_progress)
|
||||
ProgressBar achievementProgress;
|
||||
|
||||
@BindView(R.id.achievement_groupList)
|
||||
LinearLayout achievementGroupList;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -225,9 +248,61 @@ public class FullProfileActivity extends BaseActivity {
|
|||
|
||||
petCount.setText(countEntries(user.getItems().getPets()) + "");
|
||||
mountCount.setText(countEntriesBool(user.getItems().getMounts()) + "");
|
||||
|
||||
// Load the members achievements now
|
||||
apiHelper.apiService.GetMemberAchievements(this.userId)
|
||||
.compose(apiHelper.configureApiCallObserver())
|
||||
.subscribe(achievements -> fillAchievements(achievements),
|
||||
throwable -> {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void fillAchievements(HashMap<String, Achievement> achievements){
|
||||
LinkedHashMap<String, List<Achievement>> orderedSortedList = new LinkedHashMap<>();
|
||||
|
||||
// Order by ID first
|
||||
ArrayList<Achievement> achievementList = new ArrayList<>(achievements.values());
|
||||
Collections.sort(achievementList, (achievement, t1) -> Double.compare(achievement.index, t1.index));
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
stopAndHideProgress(achievementProgress);
|
||||
}
|
||||
|
||||
|
||||
private int countEntries(HashMap<String, Integer> hashMap) {
|
||||
if(hashMap == null)
|
||||
return 0;
|
||||
|
||||
int _count = 0;
|
||||
|
||||
for (Map.Entry<String, Integer> e : hashMap.entrySet()) {
|
||||
|
|
@ -241,6 +316,9 @@ public class FullProfileActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
private int countEntriesBool(HashMap<String, Boolean> hashMap) {
|
||||
if(hashMap == null)
|
||||
return 0;
|
||||
|
||||
int _count = 0;
|
||||
|
||||
for (Map.Entry<String, Boolean> e : hashMap.entrySet()) {
|
||||
|
|
@ -523,4 +601,5 @@ public class FullProfileActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
// endregion
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,79 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter.social;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
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.R;
|
||||
import com.habitrpg.android.habitica.ui.AvatarView;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Achievement;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class AchievementAdapter extends BaseAdapter {
|
||||
private Context context;
|
||||
private Achievement[] achievements;
|
||||
|
||||
public AchievementAdapter(Context context, Collection<Achievement> achievements) {
|
||||
this.context = context;
|
||||
this.achievements =new Achievement[achievements.size()];
|
||||
achievements.toArray(this.achievements);
|
||||
}
|
||||
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
|
||||
LayoutInflater inflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
View gridView;
|
||||
|
||||
gridView = inflater.inflate(R.layout.profile_achievement_item, null);
|
||||
|
||||
|
||||
TextView counterText = (TextView) gridView.findViewById(R.id.achievement_text);
|
||||
SimpleDraweeView draweeView = (SimpleDraweeView) gridView.findViewById(R.id.achievement_drawee);
|
||||
|
||||
Achievement achiev = achievements[position];
|
||||
|
||||
draweeView.setController(Fresco.newDraweeControllerBuilder()
|
||||
.setUri(AvatarView.IMAGE_URI_ROOT + achiev.icon.toLowerCase() + ".png")
|
||||
.setControllerListener(new BaseControllerListener<ImageInfo>() {
|
||||
@Override
|
||||
public void onFailure(String id, Throwable throwable) {
|
||||
Log.e("Achievemnt", "Couldn't load "+achiev.icon.toLowerCase());
|
||||
}
|
||||
})
|
||||
.build());
|
||||
|
||||
|
||||
return gridView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return achievements.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static class ViewHolder {
|
||||
TextView counterText;
|
||||
SimpleDraweeView draweeView;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.habitrpg.android.habitica.ui.controls;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.GridView;
|
||||
|
||||
public class StaticGridView extends GridView {
|
||||
|
||||
public StaticGridView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public StaticGridView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public StaticGridView(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK, MeasureSpec.AT_MOST));
|
||||
getLayoutParams().height = getMeasuredHeight();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.api;
|
||||
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Achievement;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ChatMessage;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.ContentResult;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
|
|
@ -239,6 +240,9 @@ public interface ApiService {
|
|||
@GET("members/{mid}")
|
||||
Observable<HabitRPGUser> GetMember(@Path("mid") String memberId);
|
||||
|
||||
@GET("members/{mid}/achievements")
|
||||
Observable<HashMap<String, Achievement>> GetMemberAchievements(@Path("mid") String memberId);
|
||||
|
||||
@POST("members/send-private-message")
|
||||
Observable<PostChatMessageResult> postPrivateMessage(@Body HashMap<String, String> messageDetails);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.magicmicky.habitrpgwrapper.lib.models;
|
||||
|
||||
public class Achievement {
|
||||
public String type;
|
||||
public String title;
|
||||
public String text;
|
||||
public String icon;
|
||||
public String category;
|
||||
public String key;
|
||||
public String value;
|
||||
public boolean earned;
|
||||
public int index;
|
||||
}
|
||||
Loading…
Reference in a new issue