mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 15:40:14 -04:00
Tasks are shown in the tabs (cycles + names)
This commit is contained in:
@@ -25,4 +25,5 @@ dependencies {
|
||||
compile 'com.android.support:appcompat-v7:23.1.1'
|
||||
compile 'com.android.support:design:23.1.1'
|
||||
compile 'com.android.support:support-v4:23.1.1'
|
||||
compile 'com.android.support:recyclerview-v7:23.1.1'
|
||||
}
|
||||
|
@@ -12,30 +12,26 @@ import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.adapters.TaskCursorAdapter;
|
||||
import com.wismna.geoffroy.donext.dao.Task;
|
||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||
import com.wismna.geoffroy.donext.database.TaskDataAccess;
|
||||
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
|
||||
import com.wismna.geoffroy.donext.fragments.NewTaskFragment;
|
||||
import com.wismna.geoffroy.donext.fragments.TaskFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements NewTaskFragment.NewTaskListener {
|
||||
public class MainActivity extends AppCompatActivity implements NewTaskFragment.NewTaskListener, TaskFragment.OnListFragmentInteractionListener {
|
||||
|
||||
protected TaskDataAccess taskDataAccess;
|
||||
protected TaskCursorAdapter adapter;
|
||||
/**
|
||||
* The {@link android.support.v4.view.PagerAdapter} that will provide
|
||||
* fragments for each of the sections. We use a
|
||||
@@ -171,47 +167,9 @@ public class MainActivity extends AppCompatActivity implements NewTaskFragment.N
|
||||
newTaskFragment.show(manager, "Create new task");
|
||||
}
|
||||
|
||||
/**
|
||||
* A placeholder fragment containing a simple view.
|
||||
*/
|
||||
public static class PlaceholderFragment extends Fragment {
|
||||
/**
|
||||
* The fragment argument representing the section number for this
|
||||
* fragment.
|
||||
*/
|
||||
private static final String ARG_SECTION_NUMBER = "section_number";
|
||||
|
||||
public PlaceholderFragment() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new instance of this fragment for the given section
|
||||
* number.
|
||||
*/
|
||||
public static PlaceholderFragment newInstance(int sectionNumber) {
|
||||
PlaceholderFragment fragment = new PlaceholderFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
|
||||
TextView textView = (TextView) rootView.findViewById(R.id.section_label);
|
||||
textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
|
||||
public void onListFragmentInteraction(Task item) {
|
||||
|
||||
// TODO: implement task list
|
||||
|
||||
/*ListView listView = (ListView) rootView.findViewById(android.R.id.list);
|
||||
|
||||
adapter = new TaskCursorAdapter(
|
||||
rootView.getContext(), R.layout.item_task, taskDataAccess.getAllTasksCursor(), 0);
|
||||
listView.setAdapter(adapter);*/
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +186,7 @@ public class MainActivity extends AppCompatActivity implements NewTaskFragment.N
|
||||
public Fragment getItem(int position) {
|
||||
// getItem is called to instantiate the fragment for the given page.
|
||||
// Return a PlaceholderFragment (defined as a static inner class below).
|
||||
return PlaceholderFragment.newInstance(position + 1);
|
||||
return TaskFragment.newInstance(taskLists.get(position).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -14,6 +14,8 @@ import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.adapters.TaskListCursorAdapter;
|
||||
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
|
||||
|
||||
// TODO: create a fragment
|
||||
// TODO: replace ListView with RecycleView
|
||||
public class TaskListActivity extends AppCompatActivity {
|
||||
private TaskListDataAccess dataAccess;
|
||||
private TaskListCursorAdapter adapter;
|
||||
|
@@ -0,0 +1,78 @@
|
||||
package com.wismna.geoffroy.donext.adapters;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.dao.Task;
|
||||
import com.wismna.geoffroy.donext.fragments.TaskFragment.OnListFragmentInteractionListener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* {@link RecyclerView.Adapter} that can display a {@link Task} and makes a call to the
|
||||
* specified {@link OnListFragmentInteractionListener}.
|
||||
* TODO: Replace the implementation with code for your data type.
|
||||
*/
|
||||
public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.ViewHolder> {
|
||||
|
||||
private final List<Task> mValues;
|
||||
private final OnListFragmentInteractionListener mListener;
|
||||
|
||||
public TaskAdapter(List<Task> items, OnListFragmentInteractionListener listener) {
|
||||
mValues = items;
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.fragment_task, parent, false);
|
||||
return new ViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
holder.mItem = mValues.get(position);
|
||||
holder.mIdView.setText(String.valueOf(holder.mItem.getCycle()));
|
||||
holder.mContentView.setText(holder.mItem.getName());
|
||||
|
||||
holder.mView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (null != mListener) {
|
||||
// Notify the active callbacks interface (the activity, if the
|
||||
// fragment is attached to one) that an item has been selected.
|
||||
mListener.onListFragmentInteraction(holder.mItem);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mValues.size();
|
||||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public final View mView;
|
||||
public final TextView mIdView;
|
||||
public final TextView mContentView;
|
||||
public Task mItem;
|
||||
|
||||
public ViewHolder(View view) {
|
||||
super(view);
|
||||
mView = view;
|
||||
mIdView = (TextView) view.findViewById(R.id.task_cycle);
|
||||
mContentView = (TextView) view.findViewById(R.id.task_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " '" + mContentView.getText() + "'";
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,45 +0,0 @@
|
||||
package com.wismna.geoffroy.donext.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ResourceCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.database.DatabaseHelper;
|
||||
|
||||
/**
|
||||
* Created by geoffroy on 15-11-27.
|
||||
*/
|
||||
public class TaskCursorAdapter extends ResourceCursorAdapter {
|
||||
public TaskCursorAdapter(Context context, int layout, Cursor cursor, int flags) {
|
||||
super(context, layout, cursor, flags);
|
||||
}
|
||||
|
||||
// The newView method is used to inflate a new view and return it,
|
||||
// you don't bind any data to the view at this point.
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return LayoutInflater.from(context).inflate(R.layout.item_task, parent, false);
|
||||
}
|
||||
|
||||
// The bindView method is used to bind all data to a given view
|
||||
// such as setting the text on a TextView.
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
// Find fields to populate in inflated template
|
||||
TextView taskListName = (TextView) view.findViewById(R.id.task_name);
|
||||
// Extract properties from cursor
|
||||
String name = cursor.getString(cursor.getColumnIndexOrThrow(DatabaseHelper.TASKS_COLUMN_NAME));
|
||||
// Populate fields with extracted properties
|
||||
taskListName.setText(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return super.getView(position, convertView, parent);
|
||||
}
|
||||
}
|
@@ -59,10 +59,10 @@ public class TaskDataAccess {
|
||||
return getAllTasksCursor();
|
||||
}
|
||||
|
||||
public List<Task> getAllTasks() {
|
||||
public List<Task> getAllTasks(long id) {
|
||||
List<Task> tasks = new ArrayList<>();
|
||||
|
||||
Cursor cursor = getAllTasksCursor();
|
||||
Cursor cursor = id != -1 ? getAllTasksCursor(id) : getAllTasksCursor();
|
||||
|
||||
cursor.moveToFirst();
|
||||
while (!cursor.isAfterLast()) {
|
||||
@@ -80,6 +80,11 @@ public class TaskDataAccess {
|
||||
taskColumns, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public Cursor getAllTasksCursor(long id) {
|
||||
return database.query(DatabaseHelper.TASKS_TABLE_NAME,
|
||||
taskColumns, DatabaseHelper.TASKS_COLUMN_LIST + " = " + id, null, null, null, null);
|
||||
}
|
||||
|
||||
private Task cursorToTask(Cursor cursor) {
|
||||
Task task = new Task();
|
||||
task.setId(cursor.getLong(0));
|
||||
|
@@ -0,0 +1,106 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.adapters.TaskAdapter;
|
||||
import com.wismna.geoffroy.donext.dao.Task;
|
||||
import com.wismna.geoffroy.donext.database.TaskDataAccess;
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Items.
|
||||
* <p/>
|
||||
* Activities containing this fragment MUST implement the {@link OnListFragmentInteractionListener}
|
||||
* interface.
|
||||
*/
|
||||
public class TaskFragment extends Fragment {
|
||||
|
||||
private TaskDataAccess taskDataAccess;
|
||||
private static final String TASK_LIST_ID = "task_list_id";
|
||||
private long taskListId = -1;
|
||||
private OnListFragmentInteractionListener mListener;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
* fragment (e.g. upon screen orientation changes).
|
||||
*/
|
||||
public TaskFragment() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static TaskFragment newInstance(long taskListId) {
|
||||
TaskFragment fragment = new TaskFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putLong(TASK_LIST_ID, taskListId);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getArguments() != null) {
|
||||
taskListId = getArguments().getLong(TASK_LIST_ID);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_task_list, container, false);
|
||||
|
||||
// Set the adapter
|
||||
if (view instanceof RecyclerView) {
|
||||
Context context = view.getContext();
|
||||
RecyclerView recyclerView = (RecyclerView) view;
|
||||
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
|
||||
taskDataAccess = new TaskDataAccess(view.getContext());
|
||||
taskDataAccess.open();
|
||||
TaskAdapter taskAdapter = new TaskAdapter(taskDataAccess.getAllTasks(taskListId), mListener);
|
||||
((RecyclerView) view).setAdapter(taskAdapter);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnListFragmentInteractionListener) {
|
||||
mListener = (OnListFragmentInteractionListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnListFragmentInteractionListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* This interface must be implemented by activities that contain this
|
||||
* fragment to allow an interaction in this fragment to be communicated
|
||||
* to the activity and potentially other fragments contained in that
|
||||
* activity.
|
||||
* <p/>
|
||||
* See the Android Training lesson <a href=
|
||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
||||
* >Communicating with Other Fragments</a> for more information.
|
||||
*/
|
||||
public interface OnListFragmentInteractionListener {
|
||||
void onListFragmentInteraction(Task item);
|
||||
}
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
tools:context=".activities.MainActivity$PlaceholderFragment">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/section_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
</ListView>
|
||||
</RelativeLayout>
|
20
DoNExt/app/src/main/res/layout/fragment_task.xml
Normal file
20
DoNExt/app/src/main/res/layout/fragment_task.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_cycle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/task_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/text_margin"
|
||||
android:textAppearance="?attr/textAppearanceListItem" />
|
||||
</LinearLayout>
|
13
DoNExt/app/src/main/res/layout/fragment_task_list.xml
Normal file
13
DoNExt/app/src/main/res/layout/fragment_task_list.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/list"
|
||||
android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
app:layoutManager="LinearLayoutManager"
|
||||
tools:context=".fragments.TaskFragment"
|
||||
tools:listitem="@layout/fragment_task" />
|
@@ -4,4 +4,5 @@
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="appbar_padding_top">8dp</dimen>
|
||||
<dimen name="text_margin">16dp</dimen>
|
||||
</resources>
|
||||
|
Reference in New Issue
Block a user