Fix various crashes

This commit is contained in:
Phillip Thelen 2017-04-19 15:02:42 +02:00
parent 568cfb6f12
commit 98541abf2d
14 changed files with 59 additions and 28 deletions

View file

@ -72,9 +72,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom|center"
android:layout_gravity="bottom|center_horizontal"
android:layout_alignParentBottom="true"
app:layout_behavior="com.habitrpg.android.habitica.ui.helpers.FloatingActionMenuBehavior">
app:layout_behavior="com.habitrpg.android.habitica.ui.helpers.FloatingActionMenuBehavior"
android:padding="0dp">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/floating_menu_wrapper"
android:layout_width="match_parent"
@ -93,6 +94,8 @@
app:bb_behavior="underNavbar"
app:bb_badgesHideWhenActive="true"
app:bb_badgeBackgroundColor="@color/brand_400"
android:layout_gravity="bottom"
android:layout_margin="0dp"
/>
</LinearLayout>

View file

@ -25,11 +25,11 @@ public class TaskFilterHelper {
this.tagsId.add(tags);
}
public int howMany(String type) {
public int howMany(@Nullable String type) {
return this.tagsId.size() + (isTaskFilterActive(type) ? 1 : 0);
}
private boolean isTaskFilterActive(String type) {
private boolean isTaskFilterActive(@Nullable String type) {
if (activeFilters.get(type) == null) {
return false;
}
@ -53,6 +53,9 @@ public class TaskFilterHelper {
}
public List<Task> filter(List<Task> tasks) {
if (tasks.size() == 0) {
return tasks;
}
List<Task> filtered = new ArrayList<>();
String activeFilter = null;
if (activeFilters != null && activeFilters.size() > 0) {

View file

@ -350,7 +350,7 @@ public class LoginActivity extends BaseActivity
if (requestCode == FacebookSdk.getCallbackRequestCodeOffset()) {
//This is necessary because the regular login callback is not called for some reason
AccessToken accessToken = AccessToken.getCurrentAccessToken();
if (accessToken.getToken() != null) {
if (accessToken != null && accessToken.getToken() != null) {
apiClient.connectSocial("facebook", accessToken.getUserId(), accessToken.getToken())
.subscribe(LoginActivity.this, throwable -> hideProgress());
}

View file

@ -298,6 +298,6 @@ public class SetupActivity extends BaseActivity implements ViewPager.OnPageChang
}
private boolean isLastPage() {
return this.pager.getCurrentItem() == this.pager.getAdapter().getCount()-1;
return this.pager == null || this.pager.getCurrentItem() == this.pager.getAdapter().getCount() - 1;
}
}

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.adapter.setup;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -70,8 +71,10 @@ public class TaskSetupAdapter extends RecyclerView.Adapter<TaskSetupAdapter.Task
itemView.setOnClickListener(this);
icon = ContextCompat.getDrawable(context, R.drawable.ic_check_white_18dp);
icon.setColorFilter(ContextCompat.getColor(context, R.color.brand_100), PorterDuff.Mode.MULTIPLY);
icon = VectorDrawableCompat.create(context.getResources(), R.drawable.ic_check_white_18dp, null);
if (icon != null) {
icon.setColorFilter(ContextCompat.getColor(context, R.color.brand_100), PorterDuff.Mode.MULTIPLY);
}
}
public void bind(String[] taskGroup, Boolean isChecked) {

View file

@ -55,16 +55,15 @@ public class ChallengesListViewAdapter extends RecyclerView.Adapter<ChallengesLi
}
public void setFilterByGroups(ChallengeFilterOptions filterOptions){
this.challenges = $.filter(challengesSource, arg ->
{
this.challenges = $.filter(challengesSource, arg -> {
boolean showChallenge = $.find(filterOptions.showByGroups, g -> g.id.contains(arg.groupId)).isPresent();
boolean showByOwnership = true;
if(filterOptions.showOwned == filterOptions.notOwned && this.user != null){
if (filterOptions.showOwned) {
showByOwnership = Objects.equals(arg.leaderId, this.user.getId());
showByOwnership = arg.leaderId.equals(this.user.getId());
} else {
showByOwnership = !Objects.equals(arg.leaderId, this.user.getId());
showByOwnership = !arg.leaderId.equals(this.user.getId());
}
}
@ -164,11 +163,11 @@ public class ChallengesListViewAdapter extends RecyclerView.Adapter<ChallengesLi
}
public static String getLabelByTypeAndCount(Context context, String type, int count) {
if (Objects.equals(type, Challenge.TASK_ORDER_DAILYS)) {
if (Challenge.TASK_ORDER_DAILYS.equals(type)) {
return context.getString(count == 1 ? R.string.daily : R.string.dailies);
} else if (Objects.equals(type, Challenge.TASK_ORDER_HABITS)) {
} else if (Challenge.TASK_ORDER_HABITS.equals(type)) {
return context.getString(count == 1 ? R.string.habit : R.string.habits);
} else if (Objects.equals(type, Challenge.TASK_ORDER_REWARDS)) {
} else if (Challenge.TASK_ORDER_REWARDS.equals(type)) {
return context.getString(count == 1 ? R.string.reward : R.string.rewards);
} else {
return context.getString(count == 1 ? R.string.todo : R.string.todos);

View file

@ -27,7 +27,7 @@ public abstract class SortableTasksRecyclerViewAdapter<VH extends BaseTaskViewHo
@Override
public void onItemMove(int fromPosition, int toPosition) {
if (filteredContent.size() < fromPosition || filteredContent.size() < toPosition) {
if (filteredContent.size() <= fromPosition || filteredContent.size() <= toPosition) {
return;
}
Collections.swap(filteredContent, fromPosition, toPosition);

View file

@ -117,7 +117,7 @@ public class AvatarOverviewFragment extends BaseMainFragment implements AdapterV
@Override
public void updateUserData(HabitRPGUser user) {
super.updateUserData(user);
if (user != null) {
if (user != null && viewBinding != null) {
viewBinding.setPreferences(user.getPreferences());
this.setSize(user.getPreferences().getSize());
}

View file

@ -72,6 +72,7 @@ public class ItemRecyclerFragment extends BaseFragment {
public Item hatchingItem;
public Pet feedingPet;
public HashMap<String, Integer> ownedPets;
@Nullable
public HabitRPGUser user;
LinearLayoutManager layoutManager = null;
@ -156,7 +157,7 @@ public class ItemRecyclerFragment extends BaseFragment {
@Override
public void onResume() {
if (this.isHatching != null && this.isHatching) {
if (this.isHatching != null && this.isHatching && getDialog().getWindow() != null) {
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = ViewGroup.LayoutParams.MATCH_PARENT;
params.height = ViewGroup.LayoutParams.MATCH_PARENT;
@ -202,7 +203,7 @@ public class ItemRecyclerFragment extends BaseFragment {
}
if (this.itemType.equals("special")) {
if (user.getPurchased() != null && user.getPurchased().getPlan().isActive()) {
if (user != null && user.getPurchased() != null && user.getPurchased().getPlan().isActive()) {
Item mysterItem = SpecialItem.makeMysteryItem(getContext());
mysterItem.setOwned(user.getPurchased().getPlan().mysteryItems.size());
items.add(mysterItem);

View file

@ -88,7 +88,7 @@ public class ChallengeTasksRecyclerViewFragment extends BaseFragment {
public void setInnerAdapter() {
this.recyclerAdapter = new ChallengeTasksRecyclerViewAdapter(null, 0, getContext(), userID, null);
if (tasksOnInitialize.size() != 0 && recyclerAdapter != null && recyclerAdapter.getItemCount() == 0) {
if (tasksOnInitialize != null && tasksOnInitialize.size() != 0 && recyclerAdapter != null && recyclerAdapter.getItemCount() == 0) {
recyclerAdapter.setTasks(tasksOnInitialize);
}
}

View file

@ -197,7 +197,9 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
if (viewHolder != null) {
viewHolder.itemView.setBackgroundColor(Color.LTGRAY);
}
swipeRefreshLayout.setEnabled(false);
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(false);
}
}
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
@ -220,8 +222,10 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
super.clearView(recyclerView, viewHolder);
swipeRefreshLayout.setEnabled(true);
if (swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(true);
}
viewHolder.itemView.setBackgroundColor(Color.WHITE);
if (mFromPosition != null) {
((ItemTouchHelperDropCallback) recyclerAdapter).onDrop(mFromPosition, viewHolder.getAdapterPosition());
@ -256,7 +260,7 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
if (newState == RecyclerView.SCROLL_STATE_IDLE && swipeRefreshLayout != null) {
swipeRefreshLayout.setEnabled(((MainActivity)getActivity()).isAppBarExpanded());
}
}

View file

@ -170,7 +170,9 @@ public class TasksFragment extends BaseMainFragment {
dialog.setActiveTags(taskFilterHelper.getTags());
if (getActiveFragment() != null) {
String taskType = getActiveFragment().classType;
dialog.setTaskType(taskType, taskFilterHelper.getActiveFilter(taskType));
if (taskType != null) {
dialog.setTaskType(taskType, taskFilterHelper.getActiveFilter(taskType));
}
}
dialog.setListener((activeTaskFilter, activeTags) -> {
int activePos = viewPager.getCurrentItem();
@ -472,7 +474,8 @@ public class TasksFragment extends BaseMainFragment {
private int indexForTaskType(String taskType) {
if (taskType != null) {
for (int index = 0; index < viewFragmentsDictionary.size(); index++) {
if (taskType.equals(viewFragmentsDictionary.get(index).getClassName())) {
TaskRecyclerViewFragment fragment = viewFragmentsDictionary.get(index);
if (fragment != null && taskType.equals(fragment.getClassName())) {
return index;
}
}

View file

@ -4,14 +4,17 @@ import com.commonsware.cwac.anddown.AndDown;
import net.pherth.android.emoji_library.EmojiParser;
import android.support.annotation.Nullable;
import android.text.Html;
import static android.text.Html.FROM_HTML_MODE_LEGACY;
/**
* @author data5tream
*/
public class MarkdownParser {
static AndDown processor = new AndDown();
private static AndDown processor = new AndDown();
/**
* Parses formatted markdown and returns it as styled CharSequence
@ -20,7 +23,15 @@ public class MarkdownParser {
* @return Stylized CharSequence
*/
public static CharSequence parseMarkdown(String input) {
CharSequence output = Html.fromHtml(processor.markdownToHtml(EmojiParser.parseEmojis(input.trim())));
if (input == null) {
return "";
}
CharSequence output;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
output = Html.fromHtml(processor.markdownToHtml(EmojiParser.parseEmojis(input.trim())), FROM_HTML_MODE_LEGACY);
} else {
output = Html.fromHtml(processor.markdownToHtml(EmojiParser.parseEmojis(input.trim())));
}
if (output.length() >= 2) output = output.subSequence(0, output.length() - 2);
return output;
}
@ -31,6 +42,7 @@ public class MarkdownParser {
* @param input Stylized CharSequence
* @return Markdown formatted String
*/
@Nullable
public static String parseCompiled(CharSequence input) {
return EmojiParser.convertToCheatCode(input.toString());
}

View file

@ -238,6 +238,9 @@ public class TaskFilterDialog extends AlertDialog implements RadioGroup.OnChecke
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (index >= tags.size()) {
return;
}
Tag tag = tags.get(index);
tag.setName(s.toString());
if (createdTags.containsKey(tag.getId())) {