mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-16 11:11:41 +00:00
Only display tasks for logged in user
This commit is contained in:
parent
a7ea0d7714
commit
8d152ab64a
9 changed files with 90 additions and 40 deletions
|
|
@ -1,11 +1,14 @@
|
|||
package com.habitrpg.android.habitica.modules;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.helpers.TagsHelper;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Module;
|
||||
|
|
@ -30,4 +33,14 @@ public class AppModule {
|
|||
public SharedPreferences provideSharedPreferences(Context context) {
|
||||
return PreferenceManager.getDefaultSharedPreferences(context);
|
||||
}
|
||||
|
||||
@Provides @Named("UserID")
|
||||
public String providesUserID(SharedPreferences sharedPreferences) {
|
||||
return sharedPreferences.getString(application.getString(R.string.SP_userID), null);
|
||||
}
|
||||
|
||||
@Provides @Singleton
|
||||
public TagsHelper providesTagsHelper() {
|
||||
return new TagsHelper();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import rx.schedulers.Schedulers;
|
|||
public abstract class BaseTasksRecyclerViewAdapter<VH extends BaseTaskViewHolder>
|
||||
extends RecyclerView.Adapter<VH> {
|
||||
|
||||
private final String userID;
|
||||
int layoutResource;
|
||||
String taskType;
|
||||
Context context;
|
||||
|
|
@ -46,11 +47,12 @@ public abstract class BaseTasksRecyclerViewAdapter<VH extends BaseTaskViewHolder
|
|||
private TagsHelper tagsHelper;
|
||||
|
||||
public BaseTasksRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource,
|
||||
Context newContext) {
|
||||
Context newContext, String userID) {
|
||||
this.setHasStableIds(true);
|
||||
this.taskType = taskType;
|
||||
this.context = newContext;
|
||||
this.tagsHelper = tagsHelper;
|
||||
this.userID = userID;
|
||||
this.filteredContent = new ArrayList<>();
|
||||
|
||||
this.loadContent(true);
|
||||
|
|
@ -182,6 +184,7 @@ public abstract class BaseTasksRecyclerViewAdapter<VH extends BaseTaskViewHolder
|
|||
.begin(Condition.column("completed").eq(false))
|
||||
.or(Condition.column("type").eq("daily"))
|
||||
)
|
||||
.and(Condition.column("user_id").eq(this.userID))
|
||||
.orderBy(OrderBy.columns("position", "dateCreated").descending())
|
||||
.queryList()))
|
||||
.flatMap(Observable::from)
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ public class DailiesRecyclerViewHolder extends BaseTasksRecyclerViewAdapter<Dail
|
|||
|
||||
public int dailyResetOffset;
|
||||
|
||||
public DailiesRecyclerViewHolder(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, int dailyResetOffset) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext);
|
||||
public DailiesRecyclerViewHolder(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, String userID, int dailyResetOffset) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext, userID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
|
||||
public class HabitsRecyclerViewAdapter extends BaseTasksRecyclerViewAdapter<HabitViewHolder> {
|
||||
public HabitsRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext);
|
||||
public HabitsRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, String userID) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext, userID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class RewardsRecyclerViewAdapter extends BaseTasksRecyclerViewAdapter<Rew
|
|||
private APIHelper apiHelper;
|
||||
|
||||
public RewardsRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, HabitRPGUser user, APIHelper apiHelper) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext);
|
||||
super(taskType, tagsHelper, layoutResource, newContext, user.getId());
|
||||
this.user = user;
|
||||
this.apiHelper = apiHelper;
|
||||
this.contentCache = new ContentCache(apiHelper.apiService);
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import android.view.ViewGroup;
|
|||
|
||||
public class TodosRecyclerViewAdapter extends BaseTasksRecyclerViewAdapter<TodoViewHolder> {
|
||||
|
||||
public TodosRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext);
|
||||
public TodosRecyclerViewAdapter(String taskType, TagsHelper tagsHelper, int layoutResource, Context newContext, String userID) {
|
||||
super(taskType, tagsHelper, layoutResource, newContext, userID);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -63,12 +63,16 @@ public abstract class BaseFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
injectFragment(((BaseActivity)getActivity()).getHabiticaApplication().getComponent());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
||||
injectFragment(((BaseActivity)getActivity()).getHabiticaApplication().getComponent());
|
||||
|
||||
// Receive Events
|
||||
try {
|
||||
EventBus.getDefault().register(this);
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.tasks;
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
import com.habitrpg.android.habitica.events.commands.AddNewTaskCommand;
|
||||
import com.habitrpg.android.habitica.helpers.TagsHelper;
|
||||
import com.habitrpg.android.habitica.ui.activities.BaseActivity;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.DailiesRecyclerViewHolder;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.HabitsRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.RewardsRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.TodosRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.menu.DividerItemDecoration;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.BaseTasksRecyclerViewAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Task;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
|
@ -18,6 +26,9 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
/**
|
||||
* TaskRecyclerViewFragment
|
||||
* - Creates the View only once
|
||||
|
|
@ -28,12 +39,43 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
|
|||
public RecyclerView recyclerView;
|
||||
public BaseTasksRecyclerViewAdapter recyclerAdapter;
|
||||
private String classType;
|
||||
private HabitRPGUser user;
|
||||
private static final String CLASS_TYPE_KEY = "CLASS_TYPE_KEY";
|
||||
|
||||
@Inject @Named("UserID")
|
||||
String userID;
|
||||
|
||||
@Inject
|
||||
APIHelper apiHelper;
|
||||
|
||||
@Inject
|
||||
TagsHelper tagsHelper;
|
||||
|
||||
// TODO needs a bit of cleanup
|
||||
public void SetInnerAdapter(BaseTasksRecyclerViewAdapter adapter, String classType) {
|
||||
this.classType = classType;
|
||||
recyclerAdapter = adapter;
|
||||
public void setInnerAdapter() {
|
||||
int layoutOfType;
|
||||
switch (this.classType) {
|
||||
case Task.TYPE_HABIT:
|
||||
layoutOfType = R.layout.habit_item_card;
|
||||
this.recyclerAdapter = new HabitsRecyclerViewAdapter(Task.TYPE_HABIT, tagsHelper, layoutOfType, getContext(), userID);
|
||||
break;
|
||||
case Task.TYPE_DAILY:
|
||||
layoutOfType = R.layout.daily_item_card;
|
||||
int dailyResetOffset = 0;
|
||||
if (user != null) {
|
||||
dailyResetOffset = user.getPreferences().getDayStart();
|
||||
}
|
||||
this.recyclerAdapter = new DailiesRecyclerViewHolder(Task.TYPE_DAILY, tagsHelper, layoutOfType, getContext(), userID, dailyResetOffset);
|
||||
break;
|
||||
case Task.TYPE_TODO:
|
||||
layoutOfType = R.layout.todo_item_card;
|
||||
this.recyclerAdapter = new TodosRecyclerViewAdapter(Task.TYPE_TODO, tagsHelper, layoutOfType, getContext(), userID);
|
||||
return;
|
||||
case Task.TYPE_REWARD:
|
||||
layoutOfType = R.layout.reward_item_card;
|
||||
this.recyclerAdapter = new RewardsRecyclerViewAdapter(Task.TYPE_REWARD, tagsHelper, layoutOfType, getContext(), user, apiHelper);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private View view;
|
||||
|
|
@ -54,6 +96,9 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
|
|||
|
||||
recyclerView.setLayoutManager(layoutManager);
|
||||
}
|
||||
if (recyclerView.getAdapter() == null) {
|
||||
this.setInnerAdapter();
|
||||
}
|
||||
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
|
||||
}
|
||||
|
||||
|
|
@ -106,12 +151,11 @@ public class TaskRecyclerViewFragment extends BaseFragment implements View.OnCli
|
|||
outState.putString(CLASS_TYPE_KEY, this.classType);
|
||||
}
|
||||
|
||||
public static TaskRecyclerViewFragment newInstance(BaseTasksRecyclerViewAdapter adapter, String classType) {
|
||||
public static TaskRecyclerViewFragment newInstance(HabitRPGUser user, String classType) {
|
||||
TaskRecyclerViewFragment fragment = new TaskRecyclerViewFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
|
||||
fragment.SetInnerAdapter(adapter, classType);
|
||||
|
||||
fragment.user = user;
|
||||
fragment.classType = classType;
|
||||
return fragment;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,6 +70,8 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class TasksFragment extends BaseMainFragment implements OnCheckedChangeListener {
|
||||
|
||||
private static final int TASK_CREATED_RESULT = 1;
|
||||
|
|
@ -84,7 +86,9 @@ 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
|
||||
@Inject
|
||||
public TagsHelper tagsHelper; // This will be used for this fragment. Currently being used to help filtering
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -113,10 +117,6 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (this.tagsHelper == null) {
|
||||
this.tagsHelper = new TagsHelper();
|
||||
}
|
||||
|
||||
if (user != null) {
|
||||
fillTagFilterDrawer(user.getTags());
|
||||
}
|
||||
|
|
@ -211,35 +211,21 @@ public class TasksFragment extends BaseMainFragment implements OnCheckedChangeLi
|
|||
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
int layoutOfType;
|
||||
TaskRecyclerViewFragment fragment;
|
||||
BaseTasksRecyclerViewAdapter adapter;
|
||||
|
||||
switch (position) {
|
||||
case 0:
|
||||
layoutOfType = R.layout.habit_item_card;
|
||||
fragment = TaskRecyclerViewFragment.newInstance(new HabitsRecyclerViewAdapter(Task.TYPE_HABIT, TasksFragment.this.tagsHelper, layoutOfType, activity), Task.TYPE_HABIT);
|
||||
|
||||
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_HABIT);
|
||||
break;
|
||||
case 1:
|
||||
layoutOfType = R.layout.daily_item_card;
|
||||
int dailyResetOffset = 0;
|
||||
if (user != null) {
|
||||
dailyResetOffset = user.getPreferences().getDayStart();
|
||||
}
|
||||
adapter = new DailiesRecyclerViewHolder(Task.TYPE_DAILY, TasksFragment.this.tagsHelper, layoutOfType, activity, dailyResetOffset);
|
||||
|
||||
fragment = TaskRecyclerViewFragment.newInstance(adapter, Task.TYPE_DAILY);
|
||||
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_DAILY);
|
||||
break;
|
||||
case 3:
|
||||
layoutOfType = R.layout.reward_item_card;
|
||||
adapter = new RewardsRecyclerViewAdapter(Task.TYPE_REWARD, TasksFragment.this.tagsHelper, layoutOfType, activity, user, apiHelper);
|
||||
|
||||
fragment = TaskRecyclerViewFragment.newInstance(adapter, Task.TYPE_REWARD);
|
||||
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_REWARD);
|
||||
break;
|
||||
default:
|
||||
layoutOfType = R.layout.todo_item_card;
|
||||
fragment = TaskRecyclerViewFragment.newInstance(new TodosRecyclerViewAdapter(Task.TYPE_TODO, TasksFragment.this.tagsHelper, layoutOfType, activity), Task.TYPE_TODO);
|
||||
fragment = TaskRecyclerViewFragment.newInstance(user, Task.TYPE_TODO);
|
||||
}
|
||||
|
||||
ViewFragmentsDictionary.put(position, fragment);
|
||||
|
|
|
|||
Loading…
Reference in a new issue