diff --git a/DoNExt/.idea/misc.xml b/DoNExt/.idea/misc.xml index 5d19981..ba7052b 100644 --- a/DoNExt/.idea/misc.xml +++ b/DoNExt/.idea/misc.xml @@ -1,8 +1,5 @@ - - - - - - - - - - - - - - + diff --git a/DoNExt/app/app-release.apk b/DoNExt/app/app-release.apk index 69ff3a9..7aefe83 100644 Binary files a/DoNExt/app/app-release.apk and b/DoNExt/app/app-release.apk differ diff --git a/DoNExt/app/build.gradle b/DoNExt/app/build.gradle index a6a0a02..534cf4f 100644 --- a/DoNExt/app/build.gradle +++ b/DoNExt/app/build.gradle @@ -1,15 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion '25.0.2' + compileSdkVersion 26 + buildToolsVersion '26.0.2' defaultConfig { applicationId "com.wismna.geoffroy.donext" minSdkVersion 19 - targetSdkVersion 25 - versionCode 22 - versionName "1.4.7" + targetSdkVersion 26 + versionCode 23 + versionName "1.4.8" } buildTypes { release { @@ -21,12 +21,13 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:25.3.1' - compile 'com.android.support:design:25.3.1' - compile 'com.android.support:support-v4:25.3.1' - compile 'com.android.support:percent:25.3.1' - compile 'com.android.support:recyclerview-v7:25.3.1' - compile 'com.google.android.gms:play-services-ads:10.2.1' + compile 'com.android.support:appcompat-v7:26.1.0' + compile 'com.android.support:design:26.1.0' + compile 'com.android.support:support-v4:26.1.0' + compile 'com.android.support:percent:26.1.0' + compile 'com.android.support:recyclerview-v7:26.1.0' + compile 'com.google.android.gms:play-services-ads:11.6.2' compile 'net.danlew:android.joda:2.9.7' + compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' } diff --git a/DoNExt/app/src/main/AndroidManifest.xml b/DoNExt/app/src/main/AndroidManifest.xml index a847bbc..97cb50b 100644 --- a/DoNExt/app/src/main/AndroidManifest.xml +++ b/DoNExt/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + - + + + @@ -54,6 +59,7 @@ android:name="android.support.PARENT_ACTIVITY" android:value=".activities.MainActivity" /> + \ No newline at end of file diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java index bb3fa93..2098eac 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/MainActivity.java @@ -2,132 +2,30 @@ package com.wismna.geoffroy.donext.activities; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Point; -import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; import com.wismna.geoffroy.donext.R; -import com.wismna.geoffroy.donext.adapters.SmartFragmentStatePagerAdapter; -import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter; -import com.wismna.geoffroy.donext.dao.Task; -import com.wismna.geoffroy.donext.dao.TaskList; -import com.wismna.geoffroy.donext.database.TaskListDataAccess; +import com.wismna.geoffroy.donext.fragments.MainFragment; import com.wismna.geoffroy.donext.fragments.TaskFormDialogFragment; import com.wismna.geoffroy.donext.fragments.TasksFragment; -import java.util.List; - -public class MainActivity extends AppCompatActivity implements TasksFragment.TaskChangedAdapter { - - /** - * The {@link android.support.v4.view.PagerAdapter} that will provide - * fragments for each of the sections. We use a - * {@link FragmentPagerAdapter} derivative, which will keep every - * loaded fragment in memory. If this becomes too memory intensive, it - * may be best to switch to a - * {@link android.support.v4.app.FragmentStatePagerAdapter}. - */ - private SectionsPagerAdapter mSectionsPagerAdapter; - /** - * The {@link ViewPager} that will host the section contents. - */ - private ViewPager mViewPager; - private TabLayout tabLayout; - private List taskLists; - private boolean mIsLargeLayout; +/** + * Main Activity class + */ +public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - mIsLargeLayout = getResources().getBoolean(R.bool.large_layout); - - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); - setSupportActionBar(toolbar); - - // Create the adapter that will return a fragment for each of the three - // primary sections of the activity. - mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - - SharedPreferences sharedPref = - PreferenceManager.getDefaultSharedPreferences(MainActivity.this); - - // Access database to retrieve Tabs - try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(this)) { - taskLists = taskListDataAccess.getAllTaskLists(); - mSectionsPagerAdapter.notifyDataSetChanged(); - } - if (taskLists.size() == 0) { - Intent intent = new Intent(this, TaskListActivity.class); - startActivity(intent); - } - else { - - // Set up the ViewPager with the sections adapter. - mViewPager = (ViewPager) findViewById(R.id.container); - mViewPager.setAdapter(mSectionsPagerAdapter); - // Open last opened tab - int lastOpenedList = sharedPref.getInt("last_opened_tab", 0); - mViewPager.setCurrentItem(lastOpenedList); - - if (!mIsLargeLayout) { - tabLayout = (TabLayout) findViewById(R.id.tabs); - tabLayout.setupWithViewPager(mViewPager); - - // Handles scroll detection (only available for SDK version >=23) - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - toggleTabLayoutArrows(tabLayout.getScrollX()); - //tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT); - tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() { - @Override - public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { - toggleTabLayoutArrows(scrollX); - } - }); - } - } - else { - ListView listView = (ListView) findViewById(R.id.list); - //listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskLists)); - listView.setAdapter(new ArrayAdapter<>(this, R.layout.list_tasklist_item, taskLists)); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView parent, View view, int position, long id) { - mViewPager.setCurrentItem(position); - } - }); - } - } - } - - @Override - protected void onPause() { - super.onPause(); - - // No tabs exist yet, nothing to save - if (mViewPager == null) return; - // Otherwise, save currently opened tab - SharedPreferences sharedPref = - PreferenceManager.getDefaultSharedPreferences(MainActivity.this); - SharedPreferences.Editor editor = sharedPref.edit(); - editor.putInt("last_opened_tab", mViewPager.getCurrentItem()); - editor.apply(); } @Override @@ -159,46 +57,6 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas return id == R.id.action_settings || super.onOptionsItemSelected(item); } - @Override - public void onTaskListChanged(Task task, int tabPosition) { - TaskRecyclerViewAdapter destinationTaskAdapter = getSpecificTabAdapter(tabPosition); - if (destinationTaskAdapter != null) destinationTaskAdapter.add(task, destinationTaskAdapter.getItemCount()); - } - - /** Called when user clicks on the New Task floating button */ - public void onNewTaskClick(View view) { - int currentTabPosition = mViewPager.getCurrentItem(); - TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance(null, - mSectionsPagerAdapter.getAllItems(), - (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(currentTabPosition)); - - // Set some configuration values for the tab - SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - Bundle args = new Bundle(); - args.putInt("list", currentTabPosition); - args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false)); - args.putBoolean("neutral", false); - args.putString("button_positive", getString(R.string.new_task_save)); - args.putString("button_negative", getString(R.string.new_task_cancel)); - args.putString("button_neutral", getString(R.string.new_task_delete)); - taskDialogFragment.setArguments(args); - - String title = getString(R.string.action_new_task); - FragmentManager fragmentManager = getSupportFragmentManager(); - if (mIsLargeLayout) - taskDialogFragment.show(fragmentManager, title); - else { - // The device is smaller, so show the fragment fullscreen - FragmentTransaction transaction = fragmentManager.beginTransaction(); - // For a little polish, specify a transition animation - transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); - // To make it fullscreen, use the 'content' root view as the container - // for the fragment, which is always the root view for the activity - transaction.add(android.R.id.content, taskDialogFragment, title) - .addToBackStack(null).commit(); - } - } - /** Called when the user clicks on the Today List button */ public void showTodayList(MenuItem item) { Intent intent = new Intent(this, TodayActivity.class); @@ -215,7 +73,9 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas editor.apply(); // Update the ViewPagerAdapter to refresh all tabs - mSectionsPagerAdapter.notifyDataSetChanged(); + MainFragment fragment = getMainFragment(); + fragment.getViewPager().getAdapter().notifyDataSetChanged(); + //mSectionsPagerAdapter.notifyDataSetChanged(); } /** Called when the user clicks the Edit Lists button */ @@ -224,6 +84,12 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas startActivity(intent); } + /** Called when the user clicks the History button*/ + public void openHistory(MenuItem item) { + MainFragment fragment = getMainFragment(); + fragment.toggleHistory(); + } + /** Called when the user clicks the Settings button */ public void openSettings(MenuItem menuItem) { Intent intent = new Intent(this, SettingsActivity.class); @@ -236,70 +102,46 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas startActivity(intent); } - private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) { - TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position); - if (taskFragment == null) return null; - View view = taskFragment.getView(); - if (view == null) return null; - RecyclerView recyclerView = ((RecyclerView) view.findViewById(R.id.task_list_view)); - if (recyclerView == null) return null; - return (TaskRecyclerViewAdapter) recyclerView.getAdapter(); - } + /** Called when user clicks on the New Task floating button */ + public void onNewTaskClick(View view) { - /** Toggles scrolling arrows visibility */ - private void toggleTabLayoutArrows(int scrollX){ - // Hide left arrow when scrolled to the left - View leftArrow = findViewById(R.id.left_arrow); - if (leftArrow != null) { - if (scrollX <= 1) leftArrow.setVisibility(View.INVISIBLE); - else leftArrow.setVisibility(View.VISIBLE); - } - // Hide right arrow when scrolled to the right - View rightArrow = findViewById(R.id.right_arrow); - if (rightArrow != null) { - Point size = new Point(); - getWindowManager().getDefaultDisplay().getSize(size); - if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - tabLayout.getMeasuredWidth()) - rightArrow.setVisibility(View.INVISIBLE); - else rightArrow.setVisibility(View.VISIBLE); + MainFragment fragment = getMainFragment(); + ViewPager viewPager = fragment.getViewPager(); + int currentTabPosition = viewPager.getCurrentItem(); + MainFragment.SectionsPagerAdapter pagerAdapter = (MainFragment.SectionsPagerAdapter) viewPager.getAdapter(); + TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance(null, + pagerAdapter.getAllItems(), + (TasksFragment) pagerAdapter.getRegisteredFragment(currentTabPosition)); + + // Set some configuration values for the tab + SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); + Bundle args = new Bundle(); + args.putInt("list", currentTabPosition); + args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false)); + args.putBoolean("neutral", false); + args.putString("button_positive", getString(R.string.new_task_save)); + args.putString("button_negative", getString(R.string.new_task_cancel)); + args.putString("button_neutral", getString(R.string.new_task_delete)); + taskDialogFragment.setArguments(args); + + String title = getString(R.string.action_new_task); + FragmentManager fragmentManager = getSupportFragmentManager(); + if (!getResources().getBoolean(R.bool.large_layout)) + taskDialogFragment.show(fragmentManager, title); + else { + // The device is smaller, so show the fragment fullscreen + FragmentTransaction transaction = fragmentManager.beginTransaction(); + // For a little polish, specify a transition animation + transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); + // To make it fullscreen, use the 'content' root view as the container + // for the fragment, which is always the root view for the activity + transaction.add(android.R.id.content, taskDialogFragment, title) + .addToBackStack(null).commit(); } } - /** - * A {@link FragmentPagerAdapter} that returns a fragment corresponding to - * one of the sections/tabs/pages. - */ - public class SectionsPagerAdapter extends SmartFragmentStatePagerAdapter { - - SectionsPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - 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). - TaskList taskList = taskLists.get(position); - return TasksFragment.newTaskListInstance(taskList.getId(), MainActivity.this); - } - - @Override - public int getCount() { - if (taskLists != null) { - // Show the task lists - return taskLists.size(); - } - return 3; - } - - @Override - public CharSequence getPageTitle(int position) { - if (taskLists == null) return "N/A"; - return taskLists.get(position).getName(); - } - - public List getAllItems(){ - return taskLists; - } + private MainFragment getMainFragment(){ + FragmentManager manager = getSupportFragmentManager(); + return (MainFragment)manager.findFragmentById(R.id.fragment_main); } } diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TaskListActivity.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TaskListActivity.java index ef80965..6c265d9 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TaskListActivity.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/activities/TaskListActivity.java @@ -11,5 +11,4 @@ public class TaskListActivity extends AppCompatActivity{ super.onCreate(savedInstanceState); setContentView(R.layout.activity_tasklists); } - } diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java index af2adc2..6fe760f 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/database/TaskDataAccess.java @@ -93,7 +93,7 @@ public class TaskDataAccess implements AutoCloseable { " ON " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_LIST + " = " + DatabaseHelper.TASKLIST_TABLE_NAME + "." + DatabaseHelper.COLUMN_ID + " WHERE " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 + - " AND " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + 0 + " AND " + DatabaseHelper.TASKS_TABLE_NAME + "." + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + 0 , null); List tasks = new ArrayList<>(); @@ -113,11 +113,12 @@ public class TaskDataAccess implements AutoCloseable { return tasks; } - public List getAllTasksFromList(long id) { + public List getAllTasksFromList(long id, boolean isHistory) { + int history = isHistory ? 1 : 0; Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns, DatabaseHelper.TASKS_COLUMN_LIST + " = " + id + - " AND " + DatabaseHelper.TASKS_COLUMN_DONE + " = " + 0 + - " AND " + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + 0, + " AND (" + DatabaseHelper.TASKS_COLUMN_DONE + " = " + history + + (isHistory ? " OR " : " AND ") + DatabaseHelper.TASKS_COLUMN_DELETED + " = " + history + ")", null, null, null, DatabaseHelper.TASKS_COLUMN_CYCLE + ", " + DatabaseHelper.COLUMN_ID + " DESC"); return getTasksFromCursor(cursor); diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java index 921e047..9587c75 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/DynamicDialogFragment.java @@ -164,7 +164,7 @@ public abstract class DynamicDialogFragment extends DialogFragment { /** Sets the title of the Fragment from the Tag */ private Toolbar setToolbarTitle(View view) { - Toolbar toolbar = (Toolbar) view.findViewById(R.id.dialog_toolbar); + Toolbar toolbar = view.findViewById(R.id.dialog_toolbar); toolbar.setTitle(getTag()); return toolbar; } @@ -174,7 +174,7 @@ public abstract class DynamicDialogFragment extends DialogFragment { // Ensure that the content view is set if (mContentLayoutId == 0) return; // Insert the content view - FrameLayout content = (FrameLayout) view.findViewById(R.id.dynamic_fragment_content); + FrameLayout content = view.findViewById(R.id.dynamic_fragment_content); content.addView(inflater.inflate(mContentLayoutId, (ViewGroup) view.getParent())); } diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java new file mode 100644 index 0000000..6eb072a --- /dev/null +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/MainFragment.java @@ -0,0 +1,234 @@ +package com.wismna.geoffroy.donext.fragments; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Point; +import android.os.Build; +import android.os.Bundle; +import android.preference.PreferenceManager; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; + +import com.wismna.geoffroy.donext.R; +import com.wismna.geoffroy.donext.activities.TaskListActivity; +import com.wismna.geoffroy.donext.adapters.SmartFragmentStatePagerAdapter; +import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter; +import com.wismna.geoffroy.donext.dao.Task; +import com.wismna.geoffroy.donext.dao.TaskList; +import com.wismna.geoffroy.donext.database.TaskListDataAccess; + +import java.util.List; + +/** + * Fragment that will handle the main display + */ +public class MainFragment extends Fragment implements TasksFragment.TaskChangedAdapter { + + private View mView; + private ViewPager mViewPager; + private SectionsPagerAdapter mSectionsPagerAdapter; + private TabLayout tabLayout; + private List taskLists; + private boolean isHistory = false; + + public MainFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param isHistory Will this fragment show the task history? + * @return A new instance of fragment MainFragment. + */ + // TODO: Rename and change types and number of parameters + public static MainFragment newInstance(boolean isHistory) { + MainFragment fragment = new MainFragment(); + Bundle args = new Bundle(); + args.putBoolean("history", isHistory); + fragment.setArguments(args); + return fragment; + } + + public ViewPager getViewPager() { + return mViewPager; + } + + public void toggleHistory() { + isHistory = !isHistory; + mSectionsPagerAdapter.notifyDataSetChanged(); + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + isHistory = getArguments().getBoolean("history"); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + mView = inflater.inflate(R.layout.fragment_main, container, false); + AppCompatActivity activity = (AppCompatActivity) getActivity(); + Toolbar toolbar = mView.findViewById(R.id.toolbar); + activity.setSupportActionBar(toolbar); + + // Create the adapter that will return a fragment for each of the three + // primary sections of the activity. + mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); + + SharedPreferences sharedPref = + PreferenceManager.getDefaultSharedPreferences(activity); + + // Access database to retrieve Tabs + try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(activity)) { + taskLists = taskListDataAccess.getAllTaskLists(); + mSectionsPagerAdapter.notifyDataSetChanged(); + } + if (taskLists.size() == 0) { + Intent intent = new Intent(getContext(), TaskListActivity.class); + startActivity(intent); + } + else { + + // Set up the ViewPager with the sections adapter. + mViewPager = mView.findViewById(R.id.container); + mViewPager.setAdapter(mSectionsPagerAdapter); + // Open last opened tab + int lastOpenedList = sharedPref.getInt("last_opened_tab", 0); + mViewPager.setCurrentItem(lastOpenedList); + + if (!getResources().getBoolean(R.bool.large_layout)) { + tabLayout = mView.findViewById(R.id.tabs); + tabLayout.setupWithViewPager(mViewPager); + + // Handles scroll detection (only available for SDK version >=23) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + toggleTabLayoutArrows(tabLayout.getScrollX()); + //tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT); + tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() { + @Override + public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + toggleTabLayoutArrows(scrollX); + } + }); + } + } + else { + ListView listView = mView.findViewById(R.id.list); + //listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, taskLists)); + listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists)); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + mViewPager.setCurrentItem(position); + } + }); + } + } + return mView; + } + + @Override + public void onPause() { + super.onPause(); + + // No tabs exist yet, nothing to save + if (mViewPager == null) return; + // Otherwise, save currently opened tab + SharedPreferences sharedPref = + PreferenceManager.getDefaultSharedPreferences(getContext()); + SharedPreferences.Editor editor = sharedPref.edit(); + editor.putInt("last_opened_tab", mViewPager.getCurrentItem()); + editor.apply(); + } + + @Override + public void onTaskListChanged(Task task, int tabPosition) { + TaskRecyclerViewAdapter destinationTaskAdapter = getSpecificTabAdapter(tabPosition); + if (destinationTaskAdapter != null) destinationTaskAdapter.add(task, destinationTaskAdapter.getItemCount()); + } + + private TaskRecyclerViewAdapter getSpecificTabAdapter(int position) { + TasksFragment taskFragment = (TasksFragment) mSectionsPagerAdapter.getRegisteredFragment(position); + if (taskFragment == null) return null; + View view = taskFragment.getView(); + if (view == null) return null; + RecyclerView recyclerView = view.findViewById(R.id.task_list_view); + if (recyclerView == null) return null; + return (TaskRecyclerViewAdapter) recyclerView.getAdapter(); + } + + /** Toggles scrolling arrows visibility */ + private void toggleTabLayoutArrows(int scrollX){ + // Hide left arrow when scrolled to the left + View leftArrow = mView.findViewById(R.id.left_arrow); + if (leftArrow != null) { + if (scrollX <= 1) leftArrow.setVisibility(View.INVISIBLE); + else leftArrow.setVisibility(View.VISIBLE); + } + // Hide right arrow when scrolled to the right + View rightArrow = mView.findViewById(R.id.right_arrow); + if (rightArrow != null) { + Point size = new Point(); + getActivity().getWindowManager().getDefaultDisplay().getSize(size); + if (scrollX == tabLayout.getChildAt(0).getMeasuredWidth() - tabLayout.getMeasuredWidth()) + rightArrow.setVisibility(View.INVISIBLE); + else rightArrow.setVisibility(View.VISIBLE); + } + } + + /** + * A {@link FragmentPagerAdapter} that returns a fragment corresponding to + * one of the sections/tabs/pages. + */ + public class SectionsPagerAdapter extends SmartFragmentStatePagerAdapter { + + SectionsPagerAdapter(FragmentManager fm) { + super(fm); + } + + @Override + 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). + TaskList taskList = taskLists.get(position); + return TasksFragment.newTaskListInstance(taskList.getId(), isHistory, MainFragment.this); + } + + @Override + public int getCount() { + if (taskLists != null) { + // Show the task lists + return taskLists.size(); + } + return 3; + } + + @Override + public CharSequence getPageTitle(int position) { + if (taskLists == null) return "N/A"; + return taskLists.get(position).getName(); + } + + public List getAllItems(){ + return taskLists; + } + } +} diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java index 2c56acf..2f685b2 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskFormDialogFragment.java @@ -73,7 +73,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment { @Override protected void onPositiveButtonClick(View view) { if (view == null) return; - EditText titleText = (EditText) view.findViewById(R.id.new_task_name); + EditText titleText = view.findViewById(R.id.new_task_name); // handle confirmation button click hereEditText titleText = (EditText) d.findViewById(R.id.new_task_name); if (titleText.getText().toString().matches("")) titleText.setError(getResources().getString(R.string.new_task_name_error)); diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsFragment.java index 84bd8fb..9788984 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TaskListsFragment.java @@ -59,11 +59,11 @@ public class TaskListsFragment extends Fragment implements mView = inflater.inflate(R.layout.fragment_tasklists, container, false); - Button createTaskListButton = (Button) mView.findViewById(R.id.new_task_list_button); + Button createTaskListButton = mView.findViewById(R.id.new_task_list_button); createTaskListButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - EditText editText = (EditText) mView.findViewById(R.id.new_task_list_name); + EditText editText = mView.findViewById(R.id.new_task_list_name); String text = editText.getText().toString(); if (text.matches("")) { editText.setError(getResources().getString(R.string.task_list_new_list_error)); @@ -97,7 +97,7 @@ public class TaskListsFragment extends Fragment implements } private void toggleVisibleCreateNewTaskListLayout(View view) { - LinearLayout layout = (LinearLayout) view.findViewById(R.id.new_task_list_layout); + LinearLayout layout = view.findViewById(R.id.new_task_list_layout); int taskListCount = taskListRecyclerViewAdapter.getItemCount(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "5"); @@ -134,7 +134,7 @@ public class TaskListsFragment extends Fragment implements @Override public void onConfirmDialogClick(DialogFragment dialog, ConfirmDialogFragment.ButtonEvent event) { // Handle never ask again checkbox - CheckBox neverAskAgainCheckBox = (CheckBox) dialog.getDialog().findViewById(R.id.task_confirmation_never); + CheckBox neverAskAgainCheckBox = dialog.getDialog().findViewById(R.id.task_confirmation_never); if (neverAskAgainCheckBox.isChecked()) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); @@ -195,7 +195,7 @@ public class TaskListsFragment extends Fragment implements // Set the adapter Context context = mView.getContext(); - RecyclerView recyclerView = (RecyclerView) mView.findViewById(R.id.task_lists_view); + RecyclerView recyclerView = mView.findViewById(R.id.task_lists_view); recyclerView.setLayoutManager(new LinearLayoutManager(context)); recyclerView.setAdapter(taskListRecyclerViewAdapter); diff --git a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java index 45946e1..335e337 100644 --- a/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java +++ b/DoNExt/app/src/main/java/com/wismna/geoffroy/donext/fragments/TasksFragment.java @@ -26,7 +26,6 @@ import android.widget.Spinner; import android.widget.TextView; import com.wismna.geoffroy.donext.R; -import com.wismna.geoffroy.donext.activities.MainActivity; import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter; import com.wismna.geoffroy.donext.dao.Task; import com.wismna.geoffroy.donext.dao.TaskList; @@ -49,13 +48,14 @@ public class TasksFragment extends Fragment implements ConfirmDialogFragment.ConfirmDialogListener, TaskTouchHelper.TaskTouchHelperAdapter{ - public interface TaskChangedAdapter { + interface TaskChangedAdapter { void onTaskListChanged(Task task, int tabPosition); } private static final String TASK_LIST_ID = "task_list_id"; private long taskListId = -1; private boolean isTodayView = true; + private boolean isHistory = false; private TaskRecyclerViewAdapter taskRecyclerViewAdapter; private View view; private RecyclerView recyclerView; @@ -69,10 +69,12 @@ public class TasksFragment extends Fragment implements public TasksFragment() { } - public static TasksFragment newTaskListInstance(long taskListId, TaskChangedAdapter taskChangedAdapter) { + public static TasksFragment newTaskListInstance(long taskListId, boolean isHistory, + TaskChangedAdapter taskChangedAdapter) { TasksFragment fragment = new TasksFragment(); Bundle args = new Bundle(); args.putLong(TASK_LIST_ID, taskListId); + args.putBoolean("history", isHistory); fragment.setArguments(args); fragment.mAdapter = taskChangedAdapter; fragment.isTodayView = false; @@ -86,6 +88,7 @@ public class TasksFragment extends Fragment implements if (getArguments() != null) { taskListId = getArguments().getLong(TASK_LIST_ID); + isHistory = getArguments().getBoolean("history"); } } @@ -96,7 +99,7 @@ public class TasksFragment extends Fragment implements final Context context = view.getContext(); // Set the Recycler view - recyclerView = (RecyclerView) view.findViewById(R.id.task_list_view); + recyclerView = view.findViewById(R.id.task_list_view); recyclerView.setLayoutManager(new NoScrollingLayoutManager(context)); // Set RecyclerView Adapter @@ -105,7 +108,7 @@ public class TasksFragment extends Fragment implements // Get all tasks try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext())) { taskRecyclerViewAdapter = new TaskRecyclerViewAdapter( - isTodayView? taskDataAccess.getTodayTasks() : taskDataAccess.getAllTasksFromList(taskListId), + isTodayView? taskDataAccess.getTodayTasks() : taskDataAccess.getAllTasksFromList(taskListId, isHistory), Integer.valueOf(sharedPref.getString("pref_conf_task_layout", "1")), isTodayView); } recyclerView.setAdapter(taskRecyclerViewAdapter); @@ -134,11 +137,11 @@ public class TasksFragment extends Fragment implements args.putString("button_neutral", getString(R.string.new_task_delete)); // Set current tab value to new task dialog - ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.container); + ViewPager viewPager = getActivity().findViewById(R.id.container); List taskLists; Task task = taskRecyclerViewAdapter.getItem(position); if (viewPager != null) { - taskLists = ((MainActivity.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems(); + taskLists = ((MainFragment.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems(); args.putInt("list", viewPager.getCurrentItem()); } else { @@ -188,14 +191,14 @@ public class TasksFragment extends Fragment implements // Update total cycle count int totalCycles = taskRecyclerViewAdapter.getCycleCount(); - TextView totalCyclesView = (TextView) view.findViewById(R.id.total_task_cycles); + TextView totalCyclesView = view.findViewById(R.id.total_task_cycles); if (totalCycles != 0) totalCyclesView.setText(resources.getQuantityString(R.plurals.task_total_cycles, totalCycles, totalCycles)); else totalCyclesView.setText(""); // Update total tasks int totalTasks = taskRecyclerViewAdapter.getItemCount(); - TextView totalTasksView = (TextView) view.findViewById(R.id.total_task_count); + TextView totalTasksView = view.findViewById(R.id.total_task_count); View noMoreTasks = view.findViewById(R.id.no_more_tasks); if (totalTasks == 0) { noMoreTasks.setVisibility(View.VISIBLE); @@ -208,7 +211,7 @@ public class TasksFragment extends Fragment implements } // Update remaining tasks - TextView remainingTasksView = (TextView) view.findViewById(R.id.remaining_task_count); + TextView remainingTasksView = view.findViewById(R.id.remaining_task_count); NoScrollingLayoutManager layoutManager = (NoScrollingLayoutManager) recyclerView.getLayoutManager(); int remainingTaskCount = totalTasks - layoutManager.findLastVisibleItemPosition() - 1; if (remainingTaskCount == 0) remainingTasksView.setText(""); @@ -236,7 +239,7 @@ public class TasksFragment extends Fragment implements int direction = args.getInt("Direction"); // Handle never ask again checkbox - CheckBox neverAskAgainCheckBox = (CheckBox) dialog.getDialog().findViewById(R.id.task_confirmation_never); + CheckBox neverAskAgainCheckBox = dialog.getDialog().findViewById(R.id.task_confirmation_never); if (neverAskAgainCheckBox.isChecked()) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); @@ -273,14 +276,14 @@ public class TasksFragment extends Fragment implements if (task != null) id = task.getId(); // Get the controls - Spinner listSpinner = (Spinner) dialogView.findViewById(R.id.new_task_list); - EditText nameText = (EditText) dialogView.findViewById(R.id.new_task_name); - EditText descText = (EditText) dialogView.findViewById(R.id.new_task_description); - SeekBar seekBar = (SeekBar) dialogView.findViewById(R.id.new_task_priority); - CheckBox setDueDate = (CheckBox) dialogView.findViewById(R.id.new_task_due_date_set); - DatePicker dueDatePicker = (DatePicker) dialogView.findViewById(R.id.new_task_due_date); + Spinner listSpinner = dialogView.findViewById(R.id.new_task_list); + EditText nameText = dialogView.findViewById(R.id.new_task_name); + EditText descText = dialogView.findViewById(R.id.new_task_description); + SeekBar seekBar = dialogView.findViewById(R.id.new_task_priority); + CheckBox setDueDate = dialogView.findViewById(R.id.new_task_due_date_set); + DatePicker dueDatePicker = dialogView.findViewById(R.id.new_task_due_date); TaskList taskList = (TaskList) listSpinner.getSelectedItem(); - CheckBox todayList = (CheckBox) dialogView.findViewById(R.id.new_task_today); + CheckBox todayList = dialogView.findViewById(R.id.new_task_today); boolean isToday = todayList.isChecked(); // Add the task to the database try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) { diff --git a/DoNExt/app/src/main/res/layout/activity_main.xml b/DoNExt/app/src/main/res/layout/activity_main.xml index 90639cd..777f176 100644 --- a/DoNExt/app/src/main/res/layout/activity_main.xml +++ b/DoNExt/app/src/main/res/layout/activity_main.xml @@ -8,48 +8,12 @@ android:fitsSystemWindows="true" tools:context=".activities.MainActivity"> - - - - - - - - - - - + android:name="com.wismna.geoffroy.donext.fragments.MainFragment" + /> + + + + + + + + + + + + + + diff --git a/DoNExt/app/src/main/res/menu/menu_main.xml b/DoNExt/app/src/main/res/menu/menu_main.xml index edeb127..263e3b9 100644 --- a/DoNExt/app/src/main/res/menu/menu_main.xml +++ b/DoNExt/app/src/main/res/menu/menu_main.xml @@ -30,6 +30,13 @@ android:onClick="openTaskLists" android:icon="@drawable/ic_list_white_24dp" app:showAsAction="ifRoom" /> + Choisissez des tâches Nom de la liste Sorry, your Android version is not supported. + Historique \ No newline at end of file diff --git a/DoNExt/app/src/main/res/values/strings.xml b/DoNExt/app/src/main/res/values/strings.xml index 74b8ec1..f65767c 100644 --- a/DoNExt/app/src/main/res/values/strings.xml +++ b/DoNExt/app/src/main/res/values/strings.xml @@ -77,4 +77,9 @@ Select tasks List name Sorry, your Android version is not supported. + History + + + Hello blank fragment + Main2Activity diff --git a/DoNExt/build.gradle b/DoNExt/build.gradle index b78a0b8..3be019c 100644 --- a/DoNExt/build.gradle +++ b/DoNExt/build.gradle @@ -3,9 +3,13 @@ buildscript { repositories { jcenter() + maven { + url 'https://maven.google.com/' + name 'Google' + } } dependencies { - classpath 'com.android.tools.build:gradle:2.3.1' + classpath 'com.android.tools.build:gradle:3.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +19,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/DoNExt/gradle/wrapper/gradle-wrapper.properties b/DoNExt/gradle/wrapper/gradle-wrapper.properties index 683b18f..c1de61b 100644 --- a/DoNExt/gradle/wrapper/gradle-wrapper.properties +++ b/DoNExt/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Mar 15 12:45:45 EDT 2017 +#Sat Dec 02 18:11:16 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip