mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
fix various crashes
This commit is contained in:
parent
7261d88103
commit
c9e376466d
37 changed files with 94 additions and 85 deletions
|
|
@ -72,6 +72,7 @@
|
|||
android:layout_margin="5dp"
|
||||
android:ellipsize="middle"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
android:text="class"
|
||||
android:textColor="@color/white" />
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@
|
|||
android:layout_centerVertical="true"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
tools:text="Habitica"/>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
android:textAllCaps="true"
|
||||
android:paddingTop="8dp"
|
||||
android:textColor="@color/white_50_alpha"
|
||||
android:ellipsize="marquee"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:gravity="center"
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
android:layout_gravity="center"
|
||||
android:ellipsize="middle"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
tools:text="0"
|
||||
android:textColor="@color/gem_icon_color"
|
||||
android:textSize="12sp"
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@
|
|||
android:layout_margin="5dp"
|
||||
android:ellipsize="middle"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
tools:text="class"
|
||||
android:textColor="@color/white" />
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@
|
|||
android:id="@+id/tableRowTextView1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
android:singleLine="true"
|
||||
android:lines="1"
|
||||
android:textSize="@dimen/abc_text_size_subhead_material"
|
||||
android:ellipsize="end" />
|
||||
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@
|
|||
android:layout_margin="5dp"
|
||||
android:ellipsize="middle"
|
||||
android:lines="1"
|
||||
android:singleLine="true"
|
||||
tools:text="Username" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -102,6 +103,8 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center|right"
|
||||
android:layout_marginRight="8dp"
|
||||
android:ellipsize="end" />
|
||||
android:singleLine="true"
|
||||
android:lines="1"
|
||||
android:ellipsize="end"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -15,6 +15,7 @@ import android.preference.PreferenceManager;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.multidex.MultiDexApplication;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.util.Log;
|
||||
|
||||
import com.amplitude.api.Amplitude;
|
||||
|
|
@ -125,6 +126,8 @@ public abstract class HabiticaBaseApplication extends MultiDexApplication {
|
|||
createBillingAndCheckout();
|
||||
HabiticaIconsHelper.init(this);
|
||||
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
|
||||
|
||||
if (!BuildConfig.DEBUG) {
|
||||
try {
|
||||
Amplitude.getInstance().initialize(this, getString(R.string.amplitude_app_id)).enableForegroundTracking(this);
|
||||
|
|
|
|||
|
|
@ -179,7 +179,7 @@ public interface ApiService {
|
|||
Observable<HabitResponse<User>> disableClasses();
|
||||
|
||||
@POST("user/mark-pms-read")
|
||||
Observable<HabitResponse<Void>> markPrivateMessagesRead();
|
||||
Observable<HabitResponse<List<Void>>> markPrivateMessagesRead();
|
||||
|
||||
|
||||
|
||||
|
|
@ -276,7 +276,7 @@ public interface ApiService {
|
|||
|
||||
//Push notifications
|
||||
@POST("user/push-devices")
|
||||
Observable<HabitResponse<Void>> addPushDevice(@Body Map<String, String> pushDeviceData);
|
||||
Observable<HabitResponse<List<Void>>> addPushDevice(@Body Map<String, String> pushDeviceData);
|
||||
|
||||
@DELETE("user/push-devices/{regId}")
|
||||
Observable<HabitResponse<Void>> deletePushDevice(@Path("regId") String regId);
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ public interface ApiClient {
|
|||
|
||||
Observable<User> disableClasses();
|
||||
|
||||
Observable<Void> markPrivateMessagesRead();
|
||||
Observable<List<Void>> markPrivateMessagesRead();
|
||||
|
||||
/* Group API */
|
||||
|
||||
|
|
@ -190,7 +190,7 @@ public interface ApiClient {
|
|||
Observable<Shop> fetchShopInventory(String identifier);
|
||||
|
||||
//Push notifications
|
||||
Observable<Void> addPushDevice(Map<String, String> pushDeviceData);
|
||||
Observable<List<Void>> addPushDevice(Map<String, String> pushDeviceData);
|
||||
|
||||
Observable<Void> deletePushDevice(String regId);
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ public interface SocialRepository extends BaseRepository {
|
|||
|
||||
Observable<Member> getMember(String userId);
|
||||
|
||||
Observable<Void> markPrivateMessagesRead(User user);
|
||||
Observable<List<Void>> markPrivateMessagesRead(User user);
|
||||
|
||||
Observable<RealmResults<Group>> getUserGroups();
|
||||
|
||||
|
|
|
|||
|
|
@ -636,7 +636,7 @@ public class ApiClientImpl implements Action1<Throwable>, ApiClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> markPrivateMessagesRead() {
|
||||
public Observable<List<Void>> markPrivateMessagesRead() {
|
||||
return apiService.markPrivateMessagesRead().compose(configureApiCallObserver());
|
||||
}
|
||||
|
||||
|
|
@ -786,7 +786,7 @@ public class ApiClientImpl implements Action1<Throwable>, ApiClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> addPushDevice(Map<String, String> pushDeviceData) {
|
||||
public Observable<List<Void>> addPushDevice(Map<String, String> pushDeviceData) {
|
||||
return apiService.addPushDevice(pushDeviceData).compose(configureApiCallObserver());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public class SocialRepositoryImpl extends BaseRepositoryImpl<SocialLocalReposito
|
|||
}
|
||||
|
||||
@Override
|
||||
public Observable<Void> markPrivateMessagesRead(User user) {
|
||||
public Observable<List<Void>> markPrivateMessagesRead(User user) {
|
||||
return apiClient.markPrivateMessagesRead()
|
||||
.doOnNext(aVoid -> localRepository.executeTransaction(realm -> user.getInbox().setNewMessages(0)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import rx.Observable;
|
|||
|
||||
public class UserRepositoryImpl extends BaseRepositoryImpl<UserLocalRepository> implements UserRepository {
|
||||
|
||||
private final Context context;
|
||||
private Date lastSync;
|
||||
private String userId;
|
||||
|
||||
|
|
@ -42,7 +41,6 @@ public class UserRepositoryImpl extends BaseRepositoryImpl<UserLocalRepository>
|
|||
public UserRepositoryImpl(UserLocalRepository localRepository, ApiClient apiClient, Context context, String userId, TaskRepository taskRepository) {
|
||||
super(localRepository, apiClient);
|
||||
this.taskRepository = taskRepository;
|
||||
this.context = context;
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ public class RemoteConfigManager {
|
|||
try {
|
||||
JSONObject obj = new JSONObject(storedPreferences);
|
||||
enableRepeatbles = obj.getBoolean("enableRepeatables");
|
||||
enableNewShops = obj.getBoolean("enableNewShops");
|
||||
if (obj.has("enableNewShops")) {
|
||||
enableNewShops = obj.getBoolean("enableNewShops");
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,12 +81,12 @@ public class TaskFilterHelper {
|
|||
switch (activeFilter) {
|
||||
case Task.FILTER_ACTIVE:
|
||||
if (task.type.equals(Task.TYPE_DAILY)) {
|
||||
return task.isDisplayedActive(0);
|
||||
return task.isDisplayedActive();
|
||||
} else {
|
||||
return !task.completed;
|
||||
}
|
||||
case Task.FILTER_GRAY:
|
||||
return task.completed || !task.isDisplayedActive(0);
|
||||
return task.completed || !task.isDisplayedActive();
|
||||
case Task.FILTER_WEAK:
|
||||
return task.value < 0;
|
||||
case Task.FILTER_STRONG:
|
||||
|
|
|
|||
|
|
@ -450,13 +450,12 @@ public class Task extends RealmObject implements Parcelable {
|
|||
return R.color.blue_10;
|
||||
}
|
||||
|
||||
public Boolean checkIfDue(int offset) {
|
||||
public Boolean checkIfDue() {
|
||||
if (this.getCompleted()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Calendar today = new GregorianCalendar();
|
||||
today.add(Calendar.HOUR, -offset);
|
||||
|
||||
Calendar startDate = new GregorianCalendar();
|
||||
Calendar startDateAtMidnight;
|
||||
|
|
@ -489,15 +488,15 @@ public class Task extends RealmObject implements Parcelable {
|
|||
}
|
||||
}
|
||||
|
||||
public Boolean isDisplayedActive(int offset) {
|
||||
public Boolean isDisplayedActive() {
|
||||
if (this.isDue != null && !this.completed) {
|
||||
return this.isDue;
|
||||
}
|
||||
return this.checkIfDue(offset) && !this.completed;
|
||||
return this.checkIfDue() && !this.completed;
|
||||
}
|
||||
|
||||
public Boolean isChecklistDisplayActive(int offset) {
|
||||
return this.isDisplayedActive(offset) && (this.checklist.size() != this.getCompletedChecklistCount());
|
||||
public Boolean isChecklistDisplayActive() {
|
||||
return this.isDisplayedActive() && (this.checklist.size() != this.getCompletedChecklistCount());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class NotificationPublisher extends WakefulBroadcastReceiver {
|
|||
taskRepository.getTasks(Task.TYPE_DAILY, userId).subscribe(dailies -> {
|
||||
boolean showNotifications = false;
|
||||
for (Task task : dailies) {
|
||||
if (task.checkIfDue(0)) {
|
||||
if (task.checkIfDue()) {
|
||||
showNotifications = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,6 +82,8 @@ import butterknife.BindView;
|
|||
import butterknife.OnClick;
|
||||
import io.realm.RealmList;
|
||||
|
||||
import static android.widget.AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL;
|
||||
|
||||
public class TaskFormActivity extends BaseActivity implements AdapterView.OnItemSelectedListener {
|
||||
public static final String TASK_ID_KEY = "taskId";
|
||||
public static final String USER_ID_KEY = "userId";
|
||||
|
|
@ -770,7 +772,6 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
}
|
||||
|
||||
private void changeEmojiKeyboardIcon(Boolean keyboardOpened) {
|
||||
|
||||
if (keyboardOpened) {
|
||||
emojiToggle0.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_keyboard_grey600_24dp));
|
||||
emojiToggle1.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_keyboard_grey600_24dp));
|
||||
|
|
@ -825,6 +826,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
|
||||
remindersRecyclerView.setLayoutManager(new WrapContentRecyclerViewLayoutManager(this));
|
||||
|
||||
|
||||
ItemTouchHelper.Callback callback = new SimpleItemTouchHelperCallback(remindersAdapter);
|
||||
ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback);
|
||||
mItemTouchHelper.attachToRecyclerView(remindersRecyclerView);
|
||||
|
|
@ -941,8 +943,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
this.frequencyContainer.addView(dayRow);
|
||||
}
|
||||
|
||||
if (this.task != null) {
|
||||
|
||||
if (this.task != null && this.task.isValid()) {
|
||||
if (this.dailyFrequencySpinner.getSelectedItemPosition() == 0) {
|
||||
int offset = firstDayOfTheWeekHelper.getDailyTaskFormOffset();
|
||||
this.weekdayCheckboxes.get(offset).setChecked(this.task.getRepeat().getM());
|
||||
|
|
@ -1098,8 +1099,12 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
}
|
||||
|
||||
taskRepository.executeTransaction(realm -> {
|
||||
task.text = text;
|
||||
try {
|
||||
task.text = text;
|
||||
task.notes = MarkdownParser.parseCompiled(taskNotes.getText());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
|
||||
}
|
||||
if (checklistAdapter != null) {
|
||||
if (checklistAdapter.getCheckListItems() != null) {
|
||||
RealmList<ChecklistItem> newChecklist = new RealmList<>();
|
||||
|
|
@ -1121,7 +1126,6 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
taskTags.addAll(selectedTags);
|
||||
task.setTags(taskTags);
|
||||
|
||||
task.notes = MarkdownParser.parseCompiled(taskNotes.getText());
|
||||
|
||||
if (taskDifficultySpinner.getSelectedItemPosition() == 0) {
|
||||
task.setPriority((float) 0.1);
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ public class AchievementAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||
public void onClick(View view) {
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(context);
|
||||
|
||||
View customView = LayoutInflater.from(itemView.getContext())
|
||||
View customView = LayoutInflater.from(context)
|
||||
.inflate(R.layout.dialog_achievement_details, null);
|
||||
ImageView achievementImage = (ImageView) customView.findViewById(R.id.achievement_image);
|
||||
achievementImage.setImageDrawable(draweeView.getDrawable());
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challeng
|
|||
}
|
||||
|
||||
public static class ChallengeViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
private final Context context;
|
||||
@BindView(R.id.challenge_name)
|
||||
EmojiTextView challengeName;
|
||||
|
||||
|
|
@ -131,9 +132,9 @@ public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challeng
|
|||
ChallengeViewHolder(View itemView, boolean viewUserChallengesOnly) {
|
||||
super(itemView);
|
||||
this.viewUserChallengesOnly = viewUserChallengesOnly;
|
||||
|
||||
ButterKnife.bind(this, itemView);
|
||||
|
||||
context = itemView.getContext();
|
||||
itemView.setOnClickListener(this);
|
||||
|
||||
gemIconView.setImageBitmap(HabiticaIconsHelper.imageOfGem());
|
||||
|
|
@ -158,7 +159,7 @@ public class ChallengesListViewAdapter extends RealmRecyclerViewAdapter<Challeng
|
|||
} else {
|
||||
challengeParticipatingTextView.setVisibility(challenge.isParticipating ? View.VISIBLE : View.GONE);
|
||||
|
||||
leaderName.setText(itemView.getContext().getString(R.string.byLeader, challenge.leaderName));
|
||||
leaderName.setText(context.getString(R.string.byLeader, challenge.leaderName));
|
||||
participantCount.setText(String.valueOf(challenge.memberCount));
|
||||
leaderParticipantLayout.setVisibility(View.VISIBLE);
|
||||
arrowImage.setVisibility(View.GONE);
|
||||
|
|
|
|||
|
|
@ -124,8 +124,10 @@ public class PartyMemberRecyclerViewAdapter extends RealmRecyclerViewAdapter<Mem
|
|||
ViewHelper.SetBackgroundTint(classBackground, ContextCompat.getColor(context, colorResourceID));
|
||||
userName.setText(user.getProfile().getName());
|
||||
|
||||
itemView.setClickable(true);
|
||||
itemView.setOnClickListener(view -> userClickedEvents.onNext(user.getId()));
|
||||
if (itemView != null) {
|
||||
itemView.setClickable(true);
|
||||
itemView.setOnClickListener(view -> userClickedEvents.onNext(user.getId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class PublicGuildsRecyclerViewAdapter extends RealmRecyclerViewAdapter<Gr
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(GuildViewHolder holder, int position) {
|
||||
if (getData() != null) {
|
||||
if (getData() != null && holder != null) {
|
||||
Group guild = getData().get(position);
|
||||
boolean isInGroup = isInGroup(guild);
|
||||
holder.bind(guild, isInGroup);
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ public class ChallengeTasksRecyclerViewAdapter
|
|||
viewHolder = new HabitViewHolder(getContentView(parent, R.layout.habit_item_card));
|
||||
break;
|
||||
case TYPE_DAILY:
|
||||
viewHolder = new DailyViewHolder(getContentView(parent, R.layout.daily_item_card), dailyResetOffset);
|
||||
viewHolder = new DailyViewHolder(getContentView(parent, R.layout.daily_item_card));
|
||||
break;
|
||||
case TYPE_TODO:
|
||||
viewHolder = new TodoViewHolder(getContentView(parent, R.layout.todo_item_card));
|
||||
|
|
|
|||
|
|
@ -11,15 +11,13 @@ import io.realm.OrderedRealmCollection;
|
|||
|
||||
public class DailiesRecyclerViewHolder extends RealmBaseTasksRecyclerViewAdapter<DailyViewHolder> {
|
||||
|
||||
public int dailyResetOffset;
|
||||
|
||||
public DailiesRecyclerViewHolder(@Nullable OrderedRealmCollection<Task> data, boolean autoUpdate, int layoutResource, int dailyResetOffset, TaskFilterHelper taskFilterHelper) {
|
||||
super(data, autoUpdate, layoutResource, taskFilterHelper);
|
||||
this.dailyResetOffset = dailyResetOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DailyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DailyViewHolder(getContentView(parent), dailyResetOffset);
|
||||
return new DailyViewHolder(getContentView(parent));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -176,6 +176,9 @@ public class SkillsFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private void useSkill(Skill skill, @Nullable String taskId) {
|
||||
if (skill == null) {
|
||||
return;
|
||||
}
|
||||
displayProgressDialog();
|
||||
Observable<SkillResponse> observable;
|
||||
if (taskId != null) {
|
||||
|
|
|
|||
|
|
@ -274,7 +274,9 @@ public class ChatListFragment extends BaseFragment implements SwipeRefreshLayout
|
|||
if (chatText.length() > 0) {
|
||||
chatEditText.setText(null);
|
||||
socialRepository.postGroupChat(groupId, chatText).subscribe(postChatMessageResult -> {
|
||||
recyclerView.scrollToPosition(0);
|
||||
if (recyclerView != null) {
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -182,7 +182,9 @@ public class InboxMessageListFragment extends BaseMainFragment
|
|||
if (chatText.length() > 0) {
|
||||
chatEditText.setText(null);
|
||||
socialRepository.postPrivateMessage(replyToUserUUID, chatText).subscribe(postChatMessageResult -> {
|
||||
recyclerView.scrollToPosition(0);
|
||||
if (recyclerView != null) {
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,6 +80,9 @@ public class ChallengeDetailDialogHolder {
|
|||
}
|
||||
|
||||
public static void showDialog(Activity activity, ChallengeRepository challengeRepository, Challenge challenge, Action1<Challenge> challengeLeftAction) {
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
View dialogLayout = activity.getLayoutInflater().inflate(R.layout.dialog_challenge_detail, null);
|
||||
|
||||
ChallengeDetailDialogHolder challengeDetailDialogHolder = new ChallengeDetailDialogHolder(dialogLayout, activity);
|
||||
|
|
|
|||
|
|
@ -78,7 +78,9 @@ public class ChallengeTasksRecyclerViewFragment extends BaseFragment {
|
|||
public void setInnerAdapter() {
|
||||
this.recyclerAdapter = new ChallengeTasksRecyclerViewAdapter(null, 0, getContext(), userID, null, true, true);
|
||||
|
||||
this.recyclerAdapter.setDailyResetOffset(user.getPreferences().getDayStart());
|
||||
if (user != null && user.getPreferences() != null) {
|
||||
this.recyclerAdapter.setDailyResetOffset(user.getPreferences().getDayStart());
|
||||
}
|
||||
|
||||
if (tasksOnInitialize != null && tasksOnInitialize.size() != 0 && recyclerAdapter != null && recyclerAdapter.getItemCount() == 0) {
|
||||
recyclerAdapter.setTasks(tasksOnInitialize);
|
||||
|
|
|
|||
|
|
@ -221,8 +221,10 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
|
|||
if (swipeRefreshLayout != null) {
|
||||
swipeRefreshLayout.setEnabled(true);
|
||||
}
|
||||
|
||||
viewHolder.itemView.setBackgroundColor(Color.WHITE);
|
||||
|
||||
if (viewHolder != null) {
|
||||
viewHolder.itemView.setBackgroundColor(Color.WHITE);
|
||||
}
|
||||
if (mFromPosition != null) {
|
||||
taskRepository.updateTaskPosition(viewHolder.getAdapterPosition())
|
||||
.subscribe(taskPositions -> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import android.support.annotation.Nullable;
|
|||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.SparseArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
|
@ -30,8 +29,6 @@ import com.habitrpg.android.habitica.models.tasks.Task;
|
|||
import com.habitrpg.android.habitica.models.user.User;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.TaskFormActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.DailiesRecyclerViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.TaskRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment;
|
||||
import com.habitrpg.android.habitica.ui.views.tasks.TaskFilterDialog;
|
||||
import com.roughike.bottombar.BottomBarTab;
|
||||
|
|
@ -42,6 +39,8 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
|
@ -57,7 +56,7 @@ public class TasksFragment extends BaseMainFragment {
|
|||
TagRepository tagRepository;
|
||||
MenuItem refreshItem;
|
||||
FloatingActionMenu floatingMenu;
|
||||
SparseArray<TaskRecyclerViewFragment> viewFragmentsDictionary = new SparseArray<>();
|
||||
Map<Integer, TaskRecyclerViewFragment> viewFragmentsDictionary = new WeakHashMap<>();
|
||||
|
||||
private boolean displayingTaskForm;
|
||||
@Nullable
|
||||
|
|
@ -127,10 +126,11 @@ public class TasksFragment extends BaseMainFragment {
|
|||
}
|
||||
|
||||
private boolean onFloatingMenuLongClicked(View view) {
|
||||
int currentType = viewPager.getCurrentItem();
|
||||
TaskRecyclerViewFragment currentFragment = viewFragmentsDictionary.get(currentType);
|
||||
String className = currentFragment.getClassName();
|
||||
openNewTaskActivity(className);
|
||||
TaskRecyclerViewFragment currentFragment = getActiveFragment();
|
||||
if (currentFragment != null) {
|
||||
String className = currentFragment.getClassName();
|
||||
openNewTaskActivity(className);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -181,10 +181,10 @@ public class TasksFragment extends BaseMainFragment {
|
|||
return;
|
||||
}
|
||||
int activePos = viewPager.getCurrentItem();
|
||||
if (activePos >= 1 && viewFragmentsDictionary.get(activePos-1).recyclerAdapter != null) {
|
||||
if (activePos >= 1 && viewFragmentsDictionary.get(activePos-1) != null && activePos >= 1 && viewFragmentsDictionary.get(activePos-1).recyclerAdapter != null) {
|
||||
viewFragmentsDictionary.get(activePos-1).recyclerAdapter.filter();
|
||||
}
|
||||
if (activePos < viewPager.getAdapter().getCount()-1 && viewFragmentsDictionary.get(activePos+1).recyclerAdapter != null) {
|
||||
if (activePos < viewPager.getAdapter().getCount()-1 && viewFragmentsDictionary.get(activePos+1) != null && viewFragmentsDictionary.get(activePos+1).recyclerAdapter != null) {
|
||||
viewFragmentsDictionary.get(activePos+1).recyclerAdapter.filter();
|
||||
}
|
||||
if (getActiveFragment() != null) {
|
||||
|
|
@ -341,19 +341,6 @@ public class TasksFragment extends BaseMainFragment {
|
|||
//region Events
|
||||
public void updateUserData(User user) {
|
||||
super.updateUserData(user);
|
||||
if (this.user != null) {
|
||||
for (int index = 0; index < viewFragmentsDictionary.size(); index++) {
|
||||
TaskRecyclerViewFragment fragment = viewFragmentsDictionary.get(index);
|
||||
if (fragment != null) {
|
||||
TaskRecyclerViewAdapter adapter = fragment.recyclerAdapter;
|
||||
if (adapter.getClass().equals(DailiesRecyclerViewHolder.class)) {
|
||||
final DailiesRecyclerViewHolder dailyAdapter = (DailiesRecyclerViewHolder) fragment.recyclerAdapter;
|
||||
dailyAdapter.dailyResetOffset = this.user.getPreferences().getDayStart();
|
||||
}
|
||||
//AsyncTask.execute(() -> adapter.loadContent(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void openNewTaskActivity(String type) {
|
||||
|
|
@ -382,6 +369,7 @@ public class TasksFragment extends BaseMainFragment {
|
|||
|
||||
@Nullable
|
||||
private TaskRecyclerViewFragment getActiveFragment() {
|
||||
|
||||
return viewFragmentsDictionary.get(viewPager.getCurrentItem());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,6 +146,9 @@ public abstract class ChecklistedViewHolder extends BaseTaskViewHolder implement
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (buttonView.equals(checkbox)) {
|
||||
if (!task.isValid()) {
|
||||
return;
|
||||
}
|
||||
if (isChecked != task.getCompleted()) {
|
||||
TaskCheckedCommand event = new TaskCheckedCommand();
|
||||
event.Task = task;
|
||||
|
|
|
|||
|
|
@ -10,19 +10,17 @@ import butterknife.BindView;
|
|||
|
||||
public class DailyViewHolder extends ChecklistedViewHolder {
|
||||
|
||||
private final int dailyResetOffset;
|
||||
@BindView(R.id.streakTextView)
|
||||
TextView streakTextView;
|
||||
|
||||
public DailyViewHolder(View itemView, int dailyResetOffset) {
|
||||
public DailyViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
this.dailyResetOffset = dailyResetOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindHolder(Task newTask, int position) {
|
||||
super.bindHolder(newTask, position);
|
||||
if (this.task.isChecklistDisplayActive(dailyResetOffset)) {
|
||||
if (this.task.isChecklistDisplayActive()) {
|
||||
this.checklistIndicatorWrapper.setBackgroundResource(this.task.getLightTaskColor());
|
||||
} else {
|
||||
this.checklistIndicatorWrapper.setBackgroundColor(this.taskGray);
|
||||
|
|
@ -31,7 +29,7 @@ public class DailyViewHolder extends ChecklistedViewHolder {
|
|||
|
||||
@Override
|
||||
public Boolean shouldDisplayAsActive() {
|
||||
return this.task.isDisplayedActive(this.dailyResetOffset);
|
||||
return this.task.isDisplayedActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ public class RewardViewHolder extends BaseTaskViewHolder {
|
|||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!task.isValid()) {
|
||||
return;
|
||||
}
|
||||
if (task.specialTag != null && task.specialTag.equals("item")) {
|
||||
ItemDetailDialog dialog = new ItemDetailDialog(context);
|
||||
dialog.setTitle(task.getText());
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import android.support.annotation.NonNull;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
|
@ -90,7 +89,7 @@ public class YesterdailyDialog extends AlertDialog {
|
|||
}
|
||||
|
||||
private void configureTaskView(View taskView, Task task) {
|
||||
boolean completed = !task.isDisplayedActive(0);
|
||||
boolean completed = !task.isDisplayedActive();
|
||||
CheckBox checkbox = (CheckBox) taskView.findViewById(R.id.checkBox);
|
||||
View checkboxHolder = taskView.findViewById(R.id.checkBoxHolder);
|
||||
checkbox.setChecked(completed);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ public abstract class TaskListFactory implements RemoteViewsService.RemoteViewsF
|
|||
TaskRepository taskRepository;
|
||||
@Inject
|
||||
UserRepository userRepository;
|
||||
private Integer customDayStart;
|
||||
private int listItemResId;
|
||||
private int listItemTextResId;
|
||||
private String taskType;
|
||||
|
|
@ -58,16 +57,7 @@ public abstract class TaskListFactory implements RemoteViewsService.RemoteViewsF
|
|||
if (userID == null) {
|
||||
HabiticaApplication.getComponent().inject(this);
|
||||
}
|
||||
|
||||
if (customDayStart == null) {
|
||||
userRepository.getUser(userID)
|
||||
.subscribe(habitRPGUser -> {
|
||||
customDayStart = habitRPGUser.getPreferences().getDayStart();
|
||||
this.loadData();
|
||||
}, RxErrorHandler.handleEmptyError());
|
||||
} else {
|
||||
this.loadData();
|
||||
}
|
||||
this.loadData();
|
||||
}
|
||||
|
||||
private void loadData() {
|
||||
|
|
@ -75,7 +65,7 @@ public abstract class TaskListFactory implements RemoteViewsService.RemoteViewsF
|
|||
mainHandler.post(() -> taskRepository.getTasks(taskType, userID)
|
||||
.first()
|
||||
.flatMap(Observable::from)
|
||||
.filter(task -> (task.type.equals(Task.TYPE_TODO) && !task.completed) || task.isDisplayedActive(customDayStart))
|
||||
.filter(task -> (task.type.equals(Task.TYPE_TODO) && !task.completed) || task.isDisplayedActive())
|
||||
.toList()
|
||||
.flatMap(tasks -> taskRepository.getTaskCopies(tasks))
|
||||
.subscribeOn(AndroidSchedulers.mainThread())
|
||||
|
|
|
|||
Loading…
Reference in a new issue