-
Notifications
You must be signed in to change notification settings - Fork 4
Tkt 4 add task button #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
p0stante
wants to merge
4
commits into
master
Choose a base branch
from
tkt-4-add-task-button
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Ganttproject_mobile/app/src/main/java/com/bardsoftware/ganttproject_mobile/Constants.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package com.bardsoftware.ganttproject_mobile; | ||
|
|
||
| public class Constants { | ||
| public static final String FILE_PATH = "FilePath"; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
Ganttproject_mobile/app/src/main/java/com/bardsoftware/ganttproject_mobile/TaskAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| package com.bardsoftware.ganttproject_mobile; | ||
|
|
||
| import android.content.Context; | ||
| import android.graphics.Paint; | ||
| import android.support.annotation.NonNull; | ||
| import android.support.v7.widget.RecyclerView; | ||
| import android.util.SparseBooleanArray; | ||
| import android.view.LayoutInflater; | ||
| import android.view.View; | ||
| import android.view.ViewGroup; | ||
| import android.widget.CheckBox; | ||
| import android.widget.ImageButton; | ||
| import android.widget.TextView; | ||
| import android.view.View.OnClickListener; | ||
|
|
||
| import butterknife.BindView; | ||
| import butterknife.ButterKnife; | ||
|
|
||
| import static dataformat.Dataformat.Task; | ||
| import static dataformat.Dataformat.Tasks; | ||
|
|
||
| public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.TaskViewHolder> { | ||
| private Tasks.Builder tasksBuilder; | ||
| private SparseBooleanArray taskStateArray = new SparseBooleanArray(); | ||
| private int currentSelectedPosition = RecyclerView.NO_POSITION; | ||
|
|
||
| @NonNull | ||
| @Override | ||
| public TaskViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
| Context context = parent.getContext(); | ||
| LayoutInflater inflater = LayoutInflater.from(context); | ||
| View view = inflater.inflate(R.layout.task_row, parent, false); | ||
| return new TaskAdapter.TaskViewHolder(view); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBindViewHolder(@NonNull TaskViewHolder holder, final int position) { | ||
| if (tasksBuilder == null) return; | ||
| String taskName = tasksBuilder.getTask(position).getName(); | ||
| boolean itemIsChecked = tasksBuilder.getTask(position).getIsDone(); | ||
| taskStateArray.append(position, itemIsChecked); | ||
| holder.taskView.setText(taskName); | ||
| holder.taskCheckbox.setChecked(itemIsChecked); | ||
| if (itemIsChecked) { | ||
| holder.taskView.setPaintFlags(holder.taskView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); | ||
| } else | ||
| holder.taskView.setPaintFlags(holder.taskView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG)); | ||
| if (currentSelectedPosition == position) { | ||
| holder.deleteButton.setVisibility(View.VISIBLE); | ||
| holder.deleteButton.setOnClickListener(new View.OnClickListener() { | ||
| @Override | ||
| public void onClick(View view) { | ||
| tasksBuilder.removeTask(position); | ||
| taskStateArray.delete(position); | ||
| currentSelectedPosition = RecyclerView.NO_POSITION; | ||
| notifyDataSetChanged(); | ||
|
|
||
| } | ||
| }); | ||
| } else { | ||
| holder.deleteButton.setVisibility(View.GONE); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public int getItemCount() { | ||
| if (tasksBuilder == null) return 0; | ||
| return tasksBuilder.getTaskCount(); | ||
| } | ||
|
|
||
| public void setData(Tasks tasks1) { | ||
| tasksBuilder = tasks1.toBuilder(); | ||
| notifyDataSetChanged(); | ||
| } | ||
|
|
||
| public Tasks getTasks() { | ||
| Tasks.Builder tasks1 = Tasks.newBuilder(); | ||
| for (int i = 0; i < getItemCount(); i++) { | ||
| Task task = Task.newBuilder() | ||
| .setName(tasksBuilder.getTask(i).getName()) | ||
| .setIsDone(tasksBuilder.getTask(i).getIsDone()) | ||
| .build(); | ||
| tasks1.addTask(task); | ||
| } | ||
| return tasks1.build(); | ||
| } | ||
|
|
||
| public void addTask(String name) { | ||
| Task task = Task.newBuilder().setName(name).setIsDone(false).build(); | ||
| tasksBuilder.addTask(task); | ||
| taskStateArray.append(tasksBuilder.getTaskCount(), false); | ||
| notifyDataSetChanged(); | ||
| } | ||
|
|
||
| public class TaskViewHolder extends RecyclerView.ViewHolder { | ||
| @BindView(R.id.task_textview) | ||
| TextView taskView; | ||
| @BindView(R.id.task_checkbox) | ||
| CheckBox taskCheckbox; | ||
| @BindView(R.id.delete_task_button) | ||
| ImageButton deleteButton; | ||
|
|
||
| TaskViewHolder(View view) { | ||
| super(view); | ||
| ButterKnife.bind(this, view); | ||
| taskView.setOnClickListener(new OnClickListener() { | ||
| @Override | ||
| public void onClick(View view) { | ||
| currentSelectedPosition = getAdapterPosition(); | ||
| notifyDataSetChanged(); | ||
| } | ||
| }); | ||
| taskCheckbox.setOnClickListener(new OnClickListener() { | ||
| public void onClick(View v) { | ||
| int adapterPosition = getAdapterPosition(); | ||
| if (!taskStateArray.get(adapterPosition, false)) { | ||
| taskCheckbox.setChecked(true); | ||
| taskView.setPaintFlags(taskView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); | ||
| taskStateArray.put(adapterPosition, true); | ||
| Task task1 = Task.newBuilder().setName(tasksBuilder.getTask(adapterPosition).getName()).setIsDone(true).build(); | ||
| tasksBuilder.setTask(adapterPosition, task1); | ||
| } else { | ||
| taskCheckbox.setChecked(false); | ||
| taskStateArray.put(adapterPosition, false); | ||
| taskView.setPaintFlags(taskView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG)); | ||
| Task task1 = Task.newBuilder().setName(tasksBuilder.getTask(adapterPosition).getName()).setIsDone(false).build(); | ||
| tasksBuilder.setTask(adapterPosition, task1); | ||
| } | ||
| currentSelectedPosition = getAdapterPosition(); | ||
| notifyDataSetChanged(); | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add copyright notice header to all Java source code files: