mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-20 12:49:02 +00:00
fix several crashes
This commit is contained in:
parent
b045807647
commit
14162a478b
5 changed files with 59 additions and 36 deletions
|
|
@ -260,13 +260,22 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
ErrorResponse res = null;
|
||||
|
||||
try {
|
||||
res = (ErrorResponse) cause.getBodyAs(ErrorResponse.class) ;
|
||||
res = new ErrorResponse();
|
||||
res.err = (String) cause.getBodyAs(String.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);
|
||||
try {
|
||||
res = (ErrorResponse) cause.getBodyAs(ErrorResponse.class);
|
||||
} catch (RuntimeException e2) {
|
||||
try {
|
||||
ErrorListResponse resList = (ErrorListResponse) cause.getBodyAs(ErrorListResponse.class);
|
||||
if (resList.err != null && resList.err.size() >= 1) {
|
||||
res = new ErrorResponse();
|
||||
res.err = resList.err.get(0);
|
||||
}
|
||||
} catch (RuntimeException e3) {
|
||||
res = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -498,7 +498,9 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
drawer.getDrawerLayout().closeDrawer(GravityCompat.END);
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
this.activeFragment.updateUserData(user);
|
||||
if (this.activeFragment != null) {
|
||||
this.activeFragment.updateUserData(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -902,6 +904,10 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
|
|||
}
|
||||
|
||||
public String getUserID(){
|
||||
return user.getId();
|
||||
if (this.user != null) {
|
||||
return user.getId();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
private List<String> tags;
|
||||
private List<String> tagsName; //added this
|
||||
private CheckListAdapter checklistAdapter;
|
||||
private CheckBox tagsCheckBox; //added this
|
||||
private List<CharSequence> userSelectedTags;
|
||||
private List<CheckBox> allTags;
|
||||
private List<String> userSelectedTagIds;
|
||||
|
|
@ -465,7 +464,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
for(int i = 0; i < tagsName.size(); i++){
|
||||
TableRow row = new TableRow(tagsContainerLinearLayout.getContext());
|
||||
row.setId(i);
|
||||
tagsCheckBox = new CheckBox(tagsContainerLinearLayout.getContext());
|
||||
CheckBox tagsCheckBox = new CheckBox(tagsContainerLinearLayout.getContext());
|
||||
tagsCheckBox.setText(tagsName.get(i)); // set text Name
|
||||
tagsCheckBox.setId(i);
|
||||
//This is to check if the tag was selected by the user. Similar to onClickListener
|
||||
|
|
|
|||
|
|
@ -61,7 +61,9 @@ public class PublicGuildsFragment extends BaseMainFragment implements Callback<A
|
|||
}
|
||||
|
||||
private void fetchGuilds() {
|
||||
this.mAPIHelper.apiService.listGroups("public", this);
|
||||
if (this.mAPIHelper != null) {
|
||||
this.mAPIHelper.apiService.listGroups("public", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
Map<Integer, TaskRecyclerViewFragment> ViewFragmentsDictionary = new HashMap<>();
|
||||
|
||||
private TagsHelper tagsHelper; // This will be used for this fragment. Currently being used to help filtering
|
||||
private TagsHelper tagsNameHelper; // Added this so other activities/fragments can get the String names, not IDs
|
||||
private TagsHelper tagsIdHelper; // Added this so other activities/fragments can get the IDs
|
||||
private ArrayList<String> tagNames; // Added this so other activities/fragments can get the String names, not IDs
|
||||
private ArrayList<String> tagIds; // Added this so other activities/fragments can get the IDs
|
||||
private ContentCache contentCache;
|
||||
|
||||
private boolean displayingTaskForm;
|
||||
|
|
@ -119,25 +119,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
this.tagsHelper = new TagsHelper();
|
||||
}
|
||||
|
||||
//Without these following if statements, the Fragment has no way to pass the Tags to other activities/fragments
|
||||
|
||||
if (this.tagsIdHelper == null && user != null) {
|
||||
this.tagsIdHelper = new TagsHelper();
|
||||
//Pass in the information of the user because TagsHelper does the filtering.
|
||||
for (Tag userTags : user.getTags()) {
|
||||
tagsIdHelper.addTags(userTags.getId());
|
||||
}
|
||||
}
|
||||
|
||||
//This is to pass the names into other activities, not just their IDs
|
||||
if (this.tagsNameHelper == null && user != null) {
|
||||
this.tagsNameHelper = new TagsHelper();
|
||||
for (Tag userTags : user.getTags()) {
|
||||
|
||||
tagsNameHelper.addTags(userTags.getName());
|
||||
}
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
fillTagFilterDrawer(user.getTags());
|
||||
}
|
||||
|
|
@ -391,8 +372,8 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("type", type);
|
||||
bundle.putStringArrayList("tagsId", new ArrayList<>(this.tagsIdHelper.getTags()));
|
||||
bundle.putStringArrayList("tagsName", new ArrayList<>(this.tagsNameHelper.getTags()));
|
||||
bundle.putStringArrayList("tagsId", new ArrayList<>(this.getTagIds()));
|
||||
bundle.putStringArrayList("tagsName", new ArrayList<>(this.getTagNames()));
|
||||
|
||||
Intent intent = new Intent(activity, TaskFormActivity.class);
|
||||
intent.putExtras(bundle);
|
||||
|
|
@ -437,8 +418,8 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
Bundle bundle = new Bundle();
|
||||
bundle.putString("type", event.Task.getType());
|
||||
bundle.putString("taskId", event.Task.getId());
|
||||
bundle.putStringArrayList("tagsId", new ArrayList<>(this.tagsIdHelper.getTags()));
|
||||
bundle.putStringArrayList("tagsName", new ArrayList<>(this.tagsNameHelper.getTags()));
|
||||
bundle.putStringArrayList("tagsId", new ArrayList<>(this.getTagIds()));
|
||||
bundle.putStringArrayList("tagsName", new ArrayList<>(this.getTagNames()));
|
||||
Intent intent = new Intent(activity, TaskFormActivity.class);
|
||||
intent.putExtras(bundle);
|
||||
this.displayingTaskForm = true;
|
||||
|
|
@ -556,4 +537,30 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
public String getDisplayedClassName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
private ArrayList<String>getTagNames() {
|
||||
if (this.tagNames == null) {
|
||||
this.tagNames = new ArrayList<>();
|
||||
}
|
||||
if (this.user != null && this.user.getTags().size() != this.tagNames.size()) {
|
||||
this.tagNames.clear();
|
||||
for (Tag tag : this.user.getTags()) {
|
||||
this.tagNames.add(tag.getName());
|
||||
}
|
||||
}
|
||||
return this.tagNames;
|
||||
}
|
||||
|
||||
private ArrayList<String>getTagIds() {
|
||||
if (this.tagIds == null) {
|
||||
this.tagIds = new ArrayList<>();
|
||||
}
|
||||
if (this.user != null && this.user.getTags().size() != this.tagIds.size()) {
|
||||
this.tagIds.clear();
|
||||
for (Tag tag : this.user.getTags()) {
|
||||
this.tagIds.add(tag.getName());
|
||||
}
|
||||
}
|
||||
return this.tagIds;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue