mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 11:49:01 +00:00
fix various crashes
This commit is contained in:
parent
71d92c8fb4
commit
95359dfbc5
11 changed files with 191 additions and 175 deletions
|
|
@ -2,6 +2,8 @@ package com.habitrpg.android.habitica.callbacks;
|
|||
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import rx.functions.Action1;
|
||||
|
||||
/**
|
||||
|
|
@ -10,9 +12,10 @@ import rx.functions.Action1;
|
|||
*/
|
||||
public class HabitRPGUserCallback implements Action1<HabitRPGUser> {
|
||||
|
||||
@Nullable
|
||||
public final OnUserReceived callBack;
|
||||
|
||||
public HabitRPGUserCallback(OnUserReceived callback) {
|
||||
public HabitRPGUserCallback(@Nullable OnUserReceived callback) {
|
||||
this.callBack = callback;
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +23,9 @@ public class HabitRPGUserCallback implements Action1<HabitRPGUser> {
|
|||
public void call(HabitRPGUser habitRPGUser) {
|
||||
// Negue: once everything is refactored to DbFlowTaskLocalRepository, this will be removed
|
||||
habitRPGUser.async().save();
|
||||
callBack.onUserReceived(habitRPGUser);
|
||||
if (callBack != null) {
|
||||
callBack.onUserReceived(habitRPGUser);
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnUserReceived {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ package com.habitrpg.android.habitica.callbacks;
|
|||
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
|
||||
public class MergeUserCallback extends HabitRPGUserCallback {
|
||||
|
||||
private HabitRPGUser user;
|
||||
|
||||
public MergeUserCallback(HabitRPGUserCallback.OnUserReceived callback, HabitRPGUser user) {
|
||||
public MergeUserCallback(@Nullable HabitRPGUserCallback.OnUserReceived callback, HabitRPGUser user) {
|
||||
super(callback);
|
||||
this.user = user;
|
||||
}
|
||||
|
|
@ -29,6 +31,8 @@ public class MergeUserCallback extends HabitRPGUserCallback {
|
|||
|
||||
this.user.async().save();
|
||||
|
||||
callBack.onUserReceived(this.user);
|
||||
if (callBack != null) {
|
||||
callBack.onUserReceived(this.user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,10 +7,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.ItemData;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by krh12 on 3/31/2017.
|
||||
*/
|
||||
|
||||
public class UserStatComputer {
|
||||
|
||||
// @TODO: Not really sure if this is correct
|
||||
|
|
@ -35,7 +31,7 @@ public class UserStatComputer {
|
|||
}
|
||||
|
||||
public List<StatsRow> computeClassBonus (List<ItemData> itemDataList, HabitRPGUser user) {
|
||||
List<StatsRow> skillRows = new ArrayList();
|
||||
List<StatsRow> skillRows = new ArrayList<>();
|
||||
|
||||
float strAttributes = 0;
|
||||
float intAttributes = 0;
|
||||
|
|
@ -62,16 +58,16 @@ public class UserStatComputer {
|
|||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (str_ != 0) {
|
||||
sb.append("STR " + str_ + ", ");
|
||||
sb.append("STR ").append(str_).append(", ");
|
||||
}
|
||||
if (int_ != 0) {
|
||||
sb.append("INT " + int_ + ", ");
|
||||
sb.append("INT ").append(int_).append(", ");
|
||||
}
|
||||
if (con_ != 0) {
|
||||
sb.append("CON " + con_ + ", ");
|
||||
sb.append("CON ").append(con_).append(", ");
|
||||
}
|
||||
if (per_ != 0) {
|
||||
sb.append("PER " + per_ + ", ");
|
||||
sb.append("PER ").append(per_).append(", ");
|
||||
}
|
||||
|
||||
// remove the last comma
|
||||
|
|
@ -102,27 +98,29 @@ public class UserStatComputer {
|
|||
|
||||
if (!userClassMatchesGearClass && !userClassMatchesGearSpecialClass) classBonus = 0;
|
||||
|
||||
if (itemClass.isEmpty()) {
|
||||
if (itemClass == null || itemClass.isEmpty()) {
|
||||
itemClass = itemSpecialClass;
|
||||
}
|
||||
|
||||
switch (itemClass) {
|
||||
case "rogue":
|
||||
strClassBonus = str_ * classBonus;
|
||||
perClassBonus = per_ * classBonus;
|
||||
break;
|
||||
case "healer":
|
||||
conClassBonus = con_ * classBonus;
|
||||
intClassBonus = int_ * classBonus;
|
||||
break;
|
||||
case "warrior":
|
||||
strClassBonus = str_ * classBonus;
|
||||
conClassBonus = con_ * classBonus;
|
||||
break;
|
||||
case "wizard":
|
||||
intClassBonus = int_ * classBonus;
|
||||
perClassBonus = per_ * classBonus;
|
||||
break;
|
||||
if (itemClass != null) {
|
||||
switch (itemClass) {
|
||||
case "rogue":
|
||||
strClassBonus = str_ * classBonus;
|
||||
perClassBonus = per_ * classBonus;
|
||||
break;
|
||||
case "healer":
|
||||
conClassBonus = con_ * classBonus;
|
||||
intClassBonus = int_ * classBonus;
|
||||
break;
|
||||
case "warrior":
|
||||
strClassBonus = str_ * classBonus;
|
||||
conClassBonus = con_ * classBonus;
|
||||
break;
|
||||
case "wizard":
|
||||
intClassBonus = int_ * classBonus;
|
||||
perClassBonus = per_ * classBonus;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -319,16 +319,18 @@ public class ChallengeDetailActivity extends BaseActivity {
|
|||
public void bind(Challenge challenge) {
|
||||
this.challenge = challenge;
|
||||
|
||||
challengeName.setText(EmojiParser.parseEmojis(challenge.name));
|
||||
if (challengeName != null) {
|
||||
challengeName.setText(EmojiParser.parseEmojis(challenge.name));
|
||||
}
|
||||
challengeDescription.setText(MarkdownParser.parseMarkdown(challenge.description));
|
||||
|
||||
memberCountTextView.setText(challenge.memberCount + "");
|
||||
memberCountTextView.setText(String.valueOf(challenge.memberCount));
|
||||
|
||||
if (challenge.prize == 0) {
|
||||
gem_prize_layout.setVisibility(View.GONE);
|
||||
} else {
|
||||
gem_prize_layout.setVisibility(View.VISIBLE);
|
||||
gemPrizeTextView.setText(challenge.prize + "");
|
||||
gemPrizeTextView.setText(String.valueOf(challenge.prize));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -382,19 +382,21 @@ public class FullProfileActivity extends BaseActivity {
|
|||
UserStatComputer userStatComputer = new UserStatComputer();
|
||||
List<UserStatComputer.StatsRow> statsRows = userStatComputer.computeClassBonus(itemDataList, user);
|
||||
|
||||
// @TODO: MAke this dynamic by iterating over rows and check type?
|
||||
UserStatComputer.EquipmentRow equipmentRow = (UserStatComputer.EquipmentRow) statsRows.get(0);
|
||||
addEquipmentRow(equipmentTableLayout, equipmentRow.gearKey, equipmentRow.text, equipmentRow.stats);
|
||||
for (UserStatComputer.StatsRow row : statsRows) {
|
||||
if (row.getClass().equals(UserStatComputer.EquipmentRow.class)) {
|
||||
UserStatComputer.EquipmentRow equipmentRow = (UserStatComputer.EquipmentRow) row;
|
||||
addEquipmentRow(equipmentTableLayout, equipmentRow.gearKey, equipmentRow.text, equipmentRow.stats);
|
||||
} else if (row.getClass().equals(UserStatComputer.AttributeRow.class)) {
|
||||
UserStatComputer.AttributeRow attributeRow2 = (UserStatComputer.AttributeRow) row;
|
||||
addAttributeRow(getString(attributeRow2.labelId), attributeRow2.strVal, attributeRow2.intVal, attributeRow2.conVal, attributeRow2.perVal, attributeRow2.roundDown, attributeRow2.isSummary);
|
||||
}
|
||||
}
|
||||
|
||||
stopAndHideProgress(equipmentProgress);
|
||||
equipmentTableLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
// @TOOD: We could probably remove the excess parameters - thank you classes
|
||||
UserStatComputer.AttributeRow attributeRow1 = (UserStatComputer.AttributeRow) statsRows.get(1);
|
||||
addAttributeRow(getString(attributeRow1.labelId) + ": ", attributeRow1.strVal, attributeRow1.intVal, attributeRow1.conVal, attributeRow1.perVal, attributeRow1.roundDown, attributeRow1.isSummary);
|
||||
|
||||
UserStatComputer.AttributeRow attributeRow2 = (UserStatComputer.AttributeRow) statsRows.get(2);
|
||||
addAttributeRow(getString(attributeRow2.labelId), attributeRow2.strVal, attributeRow2.intVal, attributeRow2.conVal, attributeRow2.perVal, attributeRow2.roundDown, attributeRow2.isSummary);
|
||||
stopAndHideProgress(attributesProgress);
|
||||
attributesTableLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void gotCostume(List<ItemData> obj) {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
|||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.roughike.bottombar.BottomBar;
|
||||
import com.squareup.haha.perflib.Main;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -23,8 +24,11 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
|
||||
@Inject
|
||||
public ApiClient apiClient;
|
||||
@Nullable
|
||||
public MainActivity activity;
|
||||
@Nullable
|
||||
public TabLayout tabLayout;
|
||||
@Nullable
|
||||
public BottomBar bottomNavigation;
|
||||
public ViewGroup floatingMenuWrapper;
|
||||
public boolean usesTabLayout;
|
||||
|
|
@ -43,11 +47,11 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
public void setTabLayout(TabLayout tabLayout) {
|
||||
public void setTabLayout(@Nullable TabLayout tabLayout) {
|
||||
this.tabLayout = tabLayout;
|
||||
}
|
||||
|
||||
public void setBottomNavigation(BottomBar bottomNavigation) {
|
||||
public void setBottomNavigation(@Nullable BottomBar bottomNavigation) {
|
||||
this.bottomNavigation = bottomNavigation;
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +59,7 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
this.floatingMenuWrapper = view;
|
||||
}
|
||||
|
||||
public void setActivity(MainActivity activity) {
|
||||
public void setActivity(@Nullable MainActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
|
|
@ -68,10 +72,8 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
try {
|
||||
if (getActivity().getClass().equals(MainActivity.class)) {
|
||||
this.activity = (MainActivity) getActivity();
|
||||
} catch (ClassCastException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -109,14 +109,18 @@ public class AvatarOverviewFragment extends BaseMainFragment implements AdapterV
|
|||
AvatarCustomizationFragment fragment = new AvatarCustomizationFragment();
|
||||
fragment.type = type;
|
||||
fragment.category = category;
|
||||
activity.displayFragment(fragment);
|
||||
if (activity != null) {
|
||||
activity.displayFragment(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserData(HabitRPGUser user) {
|
||||
super.updateUserData(user);
|
||||
viewBinding.setPreferences(user.getPreferences());
|
||||
this.setSize(user.getPreferences().getSize());
|
||||
if (user != null) {
|
||||
viewBinding.setPreferences(user.getPreferences());
|
||||
this.setSize(user.getPreferences().getSize());
|
||||
}
|
||||
}
|
||||
|
||||
private void setSize(String size) {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@ public class ChallegeDetailDialogHolder {
|
|||
|
||||
private AlertDialog dialog;
|
||||
private ApiClient apiClient;
|
||||
@Nullable
|
||||
private HabitRPGUser user;
|
||||
private Challenge challenge;
|
||||
private Action1<Challenge> challengeJoinedAction;
|
||||
|
|
@ -94,7 +95,7 @@ public class ChallegeDetailDialogHolder {
|
|||
challegeDetailDialogHolder.bind(builder.show(), apiClient, user, challenge, challengeJoinedAction, challengeLeftAction);
|
||||
}
|
||||
|
||||
public void bind(AlertDialog dialog, ApiClient apiClient, HabitRPGUser user, Challenge challenge,
|
||||
public void bind(AlertDialog dialog, ApiClient apiClient, @Nullable HabitRPGUser user, Challenge challenge,
|
||||
Action1<Challenge> challengeJoinedAction, Action1<Challenge> challengeLeftAction) {
|
||||
this.dialog = dialog;
|
||||
this.apiClient = apiClient;
|
||||
|
|
@ -106,15 +107,15 @@ public class ChallegeDetailDialogHolder {
|
|||
changeViewsByChallenge(challenge);
|
||||
}
|
||||
|
||||
public void changeViewsByChallenge(Challenge challenge) {
|
||||
private void changeViewsByChallenge(Challenge challenge) {
|
||||
setJoined(challenge.user_id != null && !challenge.user_id.isEmpty());
|
||||
|
||||
challengeName.setText(EmojiParser.parseEmojis(challenge.name));
|
||||
challengeDescription.setText(MarkdownParser.parseMarkdown(challenge.description));
|
||||
challengeLeader.setText(challenge.leaderName);
|
||||
|
||||
gem_amount.setText(challenge.prize + "");
|
||||
member_count.setText(challenge.memberCount + "");
|
||||
gem_amount.setText(String.valueOf(challenge.prize));
|
||||
member_count.setText(String.valueOf(challenge.memberCount));
|
||||
|
||||
apiClient.getChallengeTasks(challenge.id)
|
||||
.subscribe(taskList -> {
|
||||
|
|
@ -163,7 +164,7 @@ public class ChallegeDetailDialogHolder {
|
|||
}
|
||||
|
||||
private void addHabits(ArrayList<Task> habits) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, task_group_layout);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
|
@ -174,7 +175,7 @@ public class ChallegeDetailDialogHolder {
|
|||
for (int i = 0; i < size; i++) {
|
||||
Task task = habits.get(i);
|
||||
|
||||
View habitEntry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_habit, null);
|
||||
View habitEntry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_habit, tasks_layout);
|
||||
TextView habitTitle = (TextView) habitEntry.findViewById(R.id.habit_title);
|
||||
ImageView plusImg = (ImageView) habitEntry.findViewById(task.up ? R.id.plus_img_tinted : R.id.plus_img);
|
||||
ImageView minusImg = (ImageView) habitEntry.findViewById(task.down ? R.id.minus_img_tinted : R.id.minus_img);
|
||||
|
|
@ -184,25 +185,22 @@ public class ChallegeDetailDialogHolder {
|
|||
|
||||
habitTitle.setText(EmojiParser.parseEmojis(task.text));
|
||||
|
||||
tasks_layout.addView(habitEntry);
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
private void addDailys(ArrayList<Task> dailys) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
private void addDailys(ArrayList<Task> dailies) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, task_group_layout);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
||||
int size = dailys.size();
|
||||
groupName.setText(dailys.size() + " " + ChallengesListViewAdapter.ChallengeViewHolder.getLabelByTypeAndCount(context, Challenge.TASK_ORDER_DAILYS, size));
|
||||
int size = dailies.size();
|
||||
groupName.setText(dailies.size() + " " + ChallengesListViewAdapter.ChallengeViewHolder.getLabelByTypeAndCount(context, Challenge.TASK_ORDER_DAILYS, size));
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Task task = dailys.get(i);
|
||||
Task task = dailies.get(i);
|
||||
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_daily, null);
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_daily, tasks_layout);
|
||||
TextView title = (TextView) entry.findViewById(R.id.daily_title);
|
||||
title.setText(EmojiParser.parseEmojis(task.text));
|
||||
|
||||
|
|
@ -212,17 +210,14 @@ public class ChallegeDetailDialogHolder {
|
|||
checklistIndicatorWrapper.setVisibility(View.VISIBLE);
|
||||
|
||||
TextView checkListAllTextView = (TextView) entry.findViewById(R.id.checkListAllTextView);
|
||||
checkListAllTextView.setText(task.checklist.size() + "");
|
||||
checkListAllTextView.setText(String.valueOf(task.checklist.size()));
|
||||
}
|
||||
|
||||
tasks_layout.addView(entry);
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
private void addTodos(ArrayList<Task> todos) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, task_group_layout);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
|
@ -233,27 +228,23 @@ public class ChallegeDetailDialogHolder {
|
|||
for (int i = 0; i < size; i++) {
|
||||
Task task = todos.get(i);
|
||||
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_todo, null);
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_todo, tasks_layout);
|
||||
TextView title = (TextView) entry.findViewById(R.id.todo_title);
|
||||
title.setText(EmojiParser.parseEmojis(task.text));
|
||||
|
||||
tasks_layout.addView(entry);
|
||||
|
||||
if (task.checklist != null && !task.checklist.isEmpty()) {
|
||||
View checklistIndicatorWrapper = entry.findViewById(R.id.checklistIndicatorWrapper);
|
||||
|
||||
checklistIndicatorWrapper.setVisibility(View.VISIBLE);
|
||||
|
||||
TextView checkListAllTextView = (TextView) entry.findViewById(R.id.checkListAllTextView);
|
||||
checkListAllTextView.setText(task.checklist.size() + "");
|
||||
checkListAllTextView.setText(String.valueOf(task.checklist.size()));
|
||||
}
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
private void addRewards(ArrayList<Task> rewards) {
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, null);
|
||||
LinearLayout taskGroup = (LinearLayout) context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_task_group, task_group_layout);
|
||||
TextView groupName = (TextView) taskGroup.findViewById(R.id.task_group_name);
|
||||
|
||||
LinearLayout tasks_layout = (LinearLayout) taskGroup.findViewById(R.id.tasks_layout);
|
||||
|
|
@ -264,17 +255,13 @@ public class ChallegeDetailDialogHolder {
|
|||
for (int i = 0; i < size; i++) {
|
||||
Task task = rewards.get(i);
|
||||
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_reward, null);
|
||||
View entry = context.getLayoutInflater().inflate(R.layout.dialog_challenge_detail_reward, tasks_layout);
|
||||
TextView title = (TextView) entry.findViewById(R.id.reward_title);
|
||||
title.setText(EmojiParser.parseEmojis(task.text));
|
||||
|
||||
tasks_layout.addView(entry);
|
||||
}
|
||||
|
||||
task_group_layout.addView(taskGroup);
|
||||
}
|
||||
|
||||
public void setJoined(boolean joined) {
|
||||
private void setJoined(boolean joined) {
|
||||
joinedHeader.setVisibility(joined ? View.VISIBLE : View.GONE);
|
||||
leaveButton.setVisibility(joined ? View.VISIBLE : View.GONE);
|
||||
|
||||
|
|
@ -283,12 +270,12 @@ public class ChallegeDetailDialogHolder {
|
|||
}
|
||||
|
||||
@OnClick(R.id.challenge_leader)
|
||||
public void openLeaderProfile() {
|
||||
void openLeaderProfile() {
|
||||
EventBus.getDefault().post(new OpenFullProfileCommand(challenge.leaderId));
|
||||
}
|
||||
|
||||
@OnClick(R.id.challenge_go_to_btn)
|
||||
public void openChallengeActivity() {
|
||||
void openChallengeActivity() {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(ChallengeDetailActivity.CHALLENGE_ID, challenge.id);
|
||||
|
||||
|
|
@ -300,10 +287,12 @@ public class ChallegeDetailDialogHolder {
|
|||
}
|
||||
|
||||
@OnClick(R.id.challenge_join_btn)
|
||||
public void joinChallenge() {
|
||||
void joinChallenge() {
|
||||
this.apiClient.joinChallenge(challenge.id)
|
||||
.subscribe(challenge -> {
|
||||
challenge.user_id = this.user.getId();
|
||||
if (this.user != null) {
|
||||
challenge.user_id = this.user.getId();
|
||||
}
|
||||
challenge.async().save();
|
||||
|
||||
if (challengeJoinedAction != null) {
|
||||
|
|
@ -316,7 +305,7 @@ public class ChallegeDetailDialogHolder {
|
|||
}
|
||||
|
||||
@OnClick(R.id.challenge_leave_btn)
|
||||
public void leaveChallenge() {
|
||||
void leaveChallenge() {
|
||||
new AlertDialog.Builder(context)
|
||||
.setTitle(context.getString(R.string.challenge_leave_title))
|
||||
.setMessage(String.format(context.getString(R.string.challenge_leave_text), challenge.name))
|
||||
|
|
@ -327,7 +316,9 @@ public class ChallegeDetailDialogHolder {
|
|||
challenge.user_id = null;
|
||||
challenge.async().save();
|
||||
|
||||
this.user.resetChallengeList();
|
||||
if (this.user != null) {
|
||||
this.user.resetChallengeList();
|
||||
}
|
||||
|
||||
if (challengeLeftAction != null) {
|
||||
challengeLeftAction.call(challenge);
|
||||
|
|
@ -335,9 +326,7 @@ public class ChallegeDetailDialogHolder {
|
|||
|
||||
this.dialog.dismiss();
|
||||
}, throwable -> {
|
||||
}))).setNegativeButton(context.getString(R.string.no), (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
}).show();
|
||||
}))).setNegativeButton(context.getString(R.string.no), (dialog, which) -> dialog.dismiss()).show();
|
||||
}
|
||||
|
||||
// refactor as an UseCase later - see ChallengeDetailActivity
|
||||
|
|
|
|||
|
|
@ -1,20 +1,19 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.social.challenges;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengesFilterRecyclerViewAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Challenge;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.adapter.social.challenges.ChallengesFilterRecyclerViewAdapter;
|
||||
import com.magicmicky.habitrpgwrapper.lib.api.ApiClient;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Challenge;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.Group;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
|
@ -45,8 +44,6 @@ class ChallegeFilterDialogHolder {
|
|||
CheckBox checkboxNotOwned;
|
||||
|
||||
private AlertDialog dialog;
|
||||
private ApiClient apiClient;
|
||||
private HabitRPGUser user;
|
||||
private List<Challenge> challengesViewed;
|
||||
private ChallengeFilterOptions currentFilter;
|
||||
private Action1<ChallengeFilterOptions> selectedGroupsCallback;
|
||||
|
|
@ -54,14 +51,14 @@ class ChallegeFilterDialogHolder {
|
|||
private ChallengesFilterRecyclerViewAdapter adapter;
|
||||
|
||||
|
||||
protected ChallegeFilterDialogHolder(View view, Activity context) {
|
||||
private ChallegeFilterDialogHolder(View view, Activity context) {
|
||||
this.context = context;
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
public static void showDialog(Activity activity, ApiClient apiClient, HabitRPGUser user, List<Challenge> challengesViewed,
|
||||
ChallengeFilterOptions currentFilter,
|
||||
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
|
||||
static void showDialog(Activity activity, List<Challenge> challengesViewed,
|
||||
ChallengeFilterOptions currentFilter,
|
||||
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
|
||||
View dialogLayout = activity.getLayoutInflater().inflate(R.layout.dialog_challenge_filter, null);
|
||||
|
||||
ChallegeFilterDialogHolder challegeFilterDialogHolder = new ChallegeFilterDialogHolder(dialogLayout, activity);
|
||||
|
|
@ -69,15 +66,13 @@ class ChallegeFilterDialogHolder {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(activity)
|
||||
.setView(dialogLayout);
|
||||
|
||||
challegeFilterDialogHolder.bind(builder.show(), apiClient, user, challengesViewed, currentFilter, selectedGroupsCallback);
|
||||
challegeFilterDialogHolder.bind(builder.show(), challengesViewed, currentFilter, selectedGroupsCallback);
|
||||
}
|
||||
|
||||
public void bind(AlertDialog dialog, ApiClient apiClient, HabitRPGUser user, List<Challenge> challengesViewed,
|
||||
public void bind(AlertDialog dialog, List<Challenge> challengesViewed,
|
||||
ChallengeFilterOptions currentFilter,
|
||||
Action1<ChallengeFilterOptions> selectedGroupsCallback) {
|
||||
this.dialog = dialog;
|
||||
this.apiClient = apiClient;
|
||||
this.user = user;
|
||||
this.challengesViewed = challengesViewed;
|
||||
this.currentFilter = currentFilter;
|
||||
this.selectedGroupsCallback = selectedGroupsCallback;
|
||||
|
|
@ -101,24 +96,24 @@ class ChallegeFilterDialogHolder {
|
|||
this.groupRecyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
||||
private Collection<Group> getGroups(List<Challenge> challenges){
|
||||
private Collection<Group> getGroups(@Nullable List<Challenge> challenges){
|
||||
HashMap<String, Group> groupMap = new HashMap<>();
|
||||
|
||||
for (Challenge c : challenges) {
|
||||
if(!groupMap.containsKey(c.groupName)){
|
||||
if (challenges != null) {
|
||||
challenges.stream().filter(c -> !groupMap.containsKey(c.groupName)).forEach(c -> {
|
||||
Group g = new Group();
|
||||
g.id = c.groupId;
|
||||
g.name = c.groupName;
|
||||
|
||||
groupMap.put(c.groupName, g);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return groupMap.values();
|
||||
}
|
||||
|
||||
@OnClick(R.id.challenge_filter_button_done)
|
||||
public void doneClicked() {
|
||||
void doneClicked() {
|
||||
ChallengeFilterOptions options = new ChallengeFilterOptions();
|
||||
options.showByGroups = this.adapter.getCheckedEntries();
|
||||
options.showOwned = checkboxOwned.isChecked();
|
||||
|
|
@ -130,12 +125,12 @@ class ChallegeFilterDialogHolder {
|
|||
|
||||
|
||||
@OnClick(R.id.challenge_filter_button_all)
|
||||
public void allClicked() {
|
||||
void allClicked() {
|
||||
this.adapter.selectAll();
|
||||
}
|
||||
|
||||
@OnClick(R.id.challenge_filter_button_none)
|
||||
public void noneClicked() {
|
||||
void noneClicked() {
|
||||
this.adapter.deSelectAll();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -124,8 +124,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
challengeFilterLayout.setVisibility(withFilter?View.VISIBLE:View.GONE);
|
||||
challengeFilterLayout.setClickable(true);
|
||||
challengeFilterLayout.setOnClickListener(view -> ChallegeFilterDialogHolder.showDialog(HabiticaApplication.currentActivity, this.apiClient,
|
||||
HabiticaApplication.User, currentChallengesInView, lastFilterOptions, filterOptions -> {
|
||||
challengeFilterLayout.setOnClickListener(view -> ChallegeFilterDialogHolder.showDialog(HabiticaApplication.currentActivity, currentChallengesInView, lastFilterOptions, filterOptions -> {
|
||||
challengeAdapter.setFilterByGroups(filterOptions);
|
||||
this.lastFilterOptions = filterOptions;
|
||||
}));
|
||||
|
|
@ -164,7 +163,7 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
|
||||
Where<Challenge> query = new Select().from(Challenge.class).where(Condition.column("name").isNotNull());
|
||||
|
||||
if (viewUserChallengesOnly) {
|
||||
if (viewUserChallengesOnly && user != null) {
|
||||
query = query.and(Condition.column("user_id").is(user.getId()));
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +199,9 @@ public class ChallengeListFragment extends BaseMainFragment implements SwipeRefr
|
|||
}
|
||||
|
||||
private void fetchOnlineChallenges() {
|
||||
refreshCallback.call();
|
||||
if (refreshCallback != null) {
|
||||
refreshCallback.call();
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(Challenge challenge) {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,5 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.tasks;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.clans.fab.FloatingActionButton;
|
||||
import com.github.clans.fab.FloatingActionMenu;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
|
|
@ -45,9 +23,28 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
|||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.HashMap;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v4.view.MenuItemCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -64,6 +61,7 @@ public class TasksFragment extends BaseMainFragment {
|
|||
SparseArray<TaskRecyclerViewFragment> viewFragmentsDictionary = new SparseArray<>();
|
||||
|
||||
private boolean displayingTaskForm;
|
||||
@Nullable
|
||||
private TextView filterCountTextView;
|
||||
|
||||
public void setActivity(MainActivity activity) {
|
||||
|
|
@ -83,7 +81,7 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
viewPager = (ViewPager) v.findViewById(R.id.view_pager);
|
||||
View view = inflater.inflate(R.layout.floating_menu_tasks, floatingMenuWrapper, true);
|
||||
if (view.getClass() == FloatingActionMenu.class) {
|
||||
if (Objects.equals(view.getClass(), FloatingActionMenu.class)) {
|
||||
floatingMenu = (FloatingActionMenu) view;
|
||||
} else {
|
||||
ViewGroup frame = (ViewGroup) view;
|
||||
|
|
@ -99,21 +97,25 @@ public class TasksFragment extends BaseMainFragment {
|
|||
reward_fab.setOnClickListener(v1 -> openNewTaskActivity("reward"));
|
||||
floatingMenu.setOnMenuButtonLongClickListener(this::onFloatingMenuLongClicked);
|
||||
|
||||
this.activity.unlockDrawer(GravityCompat.END);
|
||||
if (this.activity != null) {
|
||||
this.activity.unlockDrawer(GravityCompat.END);
|
||||
}
|
||||
|
||||
loadTaskLists();
|
||||
|
||||
bottomNavigation.setOnTabSelectListener(tabId -> {
|
||||
if (tabId == R.id.tab_habits) {
|
||||
viewPager.setCurrentItem(0);
|
||||
} else if (tabId == R.id.tab_dailies) {
|
||||
viewPager.setCurrentItem(1);
|
||||
} else if (tabId == R.id.tab_todos) {
|
||||
viewPager.setCurrentItem(2);
|
||||
} else if (tabId == R.id.tab_rewards) {
|
||||
viewPager.setCurrentItem(3);
|
||||
}
|
||||
});
|
||||
if (bottomNavigation != null) {
|
||||
bottomNavigation.setOnTabSelectListener(tabId -> {
|
||||
if (tabId == R.id.tab_habits) {
|
||||
viewPager.setCurrentItem(0);
|
||||
} else if (tabId == R.id.tab_dailies) {
|
||||
viewPager.setCurrentItem(1);
|
||||
} else if (tabId == R.id.tab_todos) {
|
||||
viewPager.setCurrentItem(2);
|
||||
} else if (tabId == R.id.tab_rewards) {
|
||||
viewPager.setCurrentItem(3);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
@ -164,8 +166,10 @@ public class TasksFragment extends BaseMainFragment {
|
|||
dialog.setTags(user.getTags());
|
||||
}
|
||||
dialog.setActiveTags(taskFilterHelper.getTags());
|
||||
String taskType = getActiveFragment().classType;
|
||||
dialog.setTaskType(taskType, taskFilterHelper.getActiveFilter(taskType));
|
||||
if (getActiveFragment() != null) {
|
||||
String taskType = getActiveFragment().classType;
|
||||
dialog.setTaskType(taskType, taskFilterHelper.getActiveFilter(taskType));
|
||||
}
|
||||
dialog.setListener((activeTaskFilter, activeTags) -> {
|
||||
int activePos = viewPager.getCurrentItem();
|
||||
if (activePos >= 1) {
|
||||
|
|
@ -182,7 +186,9 @@ public class TasksFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
public void refresh() {
|
||||
getActiveFragment().onRefresh();
|
||||
if (getActiveFragment() != null) {
|
||||
getActiveFragment().onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void loadTaskLists() {
|
||||
|
|
@ -229,15 +235,17 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return activity.getString(R.string.habits);
|
||||
case 1:
|
||||
return activity.getString(R.string.dailies);
|
||||
case 2:
|
||||
return activity.getString(R.string.todos);
|
||||
case 3:
|
||||
return activity.getString(R.string.rewards);
|
||||
if (activity != null) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return activity.getString(R.string.habits);
|
||||
case 1:
|
||||
return activity.getString(R.string.dailies);
|
||||
case 2:
|
||||
return activity.getString(R.string.todos);
|
||||
case 3:
|
||||
return activity.getString(R.string.rewards);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
@ -251,7 +259,9 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
@Override
|
||||
public void onPageSelected(int position) {
|
||||
bottomNavigation.selectTabAtPosition(position);
|
||||
if (bottomNavigation != null) {
|
||||
bottomNavigation.selectTabAtPosition(position);
|
||||
}
|
||||
updateFilterIcon();
|
||||
}
|
||||
|
||||
|
|
@ -263,6 +273,9 @@ public class TasksFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private void updateFilterIcon() {
|
||||
if (filterCountTextView == null) {
|
||||
return;
|
||||
}
|
||||
int filterCount = 0;
|
||||
if (getActiveFragment() != null) {
|
||||
filterCount = taskFilterHelper.howMany(getActiveFragment().classType);
|
||||
|
|
@ -322,7 +335,9 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
@Subscribe
|
||||
public void onEvent(RefreshUserCommand event) {
|
||||
getActiveFragment().onRefresh();
|
||||
if (getActiveFragment() != null) {
|
||||
getActiveFragment().onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
@ -369,7 +384,6 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
this.activity.lockDrawer(GravityCompat.END);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
|
@ -397,7 +411,7 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
private void switchToTaskTab(String taskType) {
|
||||
for (int index = 0; index < viewFragmentsDictionary.size(); index++) {
|
||||
if (viewFragmentsDictionary.get(index).getClassName().equals(taskType)) {
|
||||
if (viewFragmentsDictionary.get(index).getClassName().equals(taskType) && viewPager != null) {
|
||||
viewPager.setCurrentItem(index);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue