Code cleanup
ViewPagerAdapter now has its own file Async classes are static with WeakReferences to containing entity History and Today icons are changed Created new History activity Modified TasksFragment to determine parent activity (Today, History or else)
@@ -8,13 +8,14 @@ android {
|
||||
applicationId "com.wismna.geoffroy.donext"
|
||||
minSdkVersion 19
|
||||
targetSdkVersion 27
|
||||
versionCode 23
|
||||
versionName "1.4.8"
|
||||
versionCode 24
|
||||
versionName "1.5"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
zipAlignEnabled true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -50,8 +50,19 @@
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activities.MainActivity" />
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".activities.HistoryActivity"
|
||||
android:label="@string/title_activity_history"
|
||||
android:parentActivityName=".activities.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activities.MainActivity" />
|
||||
</activity>
|
||||
<activity android:name=".activities.HistoryActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@@ -8,6 +8,9 @@ import android.widget.TextView;
|
||||
import com.wismna.geoffroy.donext.BuildConfig;
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
|
||||
/**
|
||||
* About Activity class
|
||||
*/
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -15,10 +18,10 @@ public class AboutActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
TextView versionDonext = (TextView) findViewById(R.id.version_donext);
|
||||
TextView versionDonext = findViewById(R.id.version_donext);
|
||||
versionDonext.setText(getResources().getString(R.string.about_version_donext, BuildConfig.VERSION_NAME));
|
||||
|
||||
TextView versionAndroid = (TextView) findViewById(R.id.version_android);
|
||||
TextView versionAndroid = findViewById(R.id.version_android);
|
||||
versionAndroid.setText(getResources().getString(R.string.about_version_android, Build.VERSION.SDK_INT));
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,19 @@
|
||||
package com.wismna.geoffroy.donext.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
|
||||
/**
|
||||
* Created by gbe on 17-12-19.
|
||||
* History Activity class
|
||||
*/
|
||||
public class HistoryActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_history);
|
||||
}
|
||||
}
|
@@ -12,6 +12,7 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.adapters.SectionsPagerAdapter;
|
||||
import com.wismna.geoffroy.donext.fragments.MainFragment;
|
||||
import com.wismna.geoffroy.donext.fragments.TaskFormDialogFragment;
|
||||
import com.wismna.geoffroy.donext.fragments.TaskListsDialogFragment;
|
||||
@@ -73,9 +74,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
editor.apply();
|
||||
|
||||
// Update the ViewPagerAdapter to refresh all tabs
|
||||
MainFragment fragment = getMainFragment();
|
||||
fragment.getViewPager().getAdapter().notifyDataSetChanged();
|
||||
//mSectionsPagerAdapter.notifyDataSetChanged();
|
||||
ViewPager viewPager = getMainFragmentViewPager();
|
||||
viewPager.getAdapter().notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/** Called when the user clicks the Edit Lists button */
|
||||
@@ -96,8 +96,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/** Called when the user clicks the History button*/
|
||||
public void openHistory(MenuItem item) {
|
||||
MainFragment fragment = getMainFragment();
|
||||
fragment.toggleHistory();
|
||||
Intent intent = new Intent(this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
/** Called when the user clicks the Settings button */
|
||||
@@ -114,12 +114,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/** Called when user clicks on the New Task floating button */
|
||||
public void onNewTaskClick(View view) {
|
||||
|
||||
MainFragment fragment = getMainFragment();
|
||||
ViewPager viewPager = fragment.getViewPager();
|
||||
ViewPager viewPager = getMainFragmentViewPager();
|
||||
if (viewPager == null) return;
|
||||
int currentTabPosition = viewPager.getCurrentItem();
|
||||
MainFragment.SectionsPagerAdapter pagerAdapter = (MainFragment.SectionsPagerAdapter) viewPager.getAdapter();
|
||||
SectionsPagerAdapter pagerAdapter = (SectionsPagerAdapter) viewPager.getAdapter();
|
||||
assert pagerAdapter != null;
|
||||
TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance(null,
|
||||
pagerAdapter.getAllItems(),
|
||||
(TasksFragment) pagerAdapter.getRegisteredFragment(currentTabPosition));
|
||||
@@ -141,8 +140,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
taskDialogFragment.showFragment(fragmentManager, title, getResources().getBoolean(R.bool.large_layout));
|
||||
}
|
||||
|
||||
private MainFragment getMainFragment(){
|
||||
private ViewPager getMainFragmentViewPager(){
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
return (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
||||
MainFragment fragment = (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
||||
return fragment.getViewPager();
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ public class TodayActivity extends AppCompatActivity
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_today);
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
// Get a support ActionBar corresponding to this toolbar
|
||||
@@ -79,16 +79,16 @@ public class TodayActivity extends AppCompatActivity
|
||||
|
||||
@Override
|
||||
public void onTodayTaskDialogPositiveClick(View dialogView) {
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTodayTasksUpdated() {
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setEnabled(true);
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(this)) {
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.task_list_view);
|
||||
RecyclerView recyclerView = findViewById(R.id.task_list_view);
|
||||
((TaskRecyclerViewAdapter)recyclerView.getAdapter()).setItems(taskDataAccess.getTodayTasks());
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,51 @@
|
||||
package com.wismna.geoffroy.donext.adapters;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
|
||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||
import com.wismna.geoffroy.donext.fragments.TasksFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
||||
* one of the sections/tabs/pages.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends SmartFragmentStatePagerAdapter {
|
||||
|
||||
private List<TaskList> taskLists;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm, List<TaskList> taskLists) {
|
||||
super(fm);
|
||||
this.taskLists = taskLists;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (taskLists != null) {
|
||||
// Show the task lists
|
||||
return taskLists.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getPageTitle(int position) {
|
||||
if (taskLists == null) return "N/A";
|
||||
return taskLists.get(position).getName();
|
||||
}
|
||||
|
||||
public List<TaskList> getAllItems(){
|
||||
return taskLists;
|
||||
}
|
||||
}
|
@@ -1,5 +1,6 @@
|
||||
package com.wismna.geoffroy.donext.adapters;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentStatePagerAdapter;
|
||||
@@ -17,16 +18,17 @@ public abstract class SmartFragmentStatePagerAdapter extends FragmentStatePagerA
|
||||
// Sparse array to keep track of registered fragments in memory
|
||||
private final SparseArray<Fragment> registeredFragments = new SparseArray<>();
|
||||
|
||||
public SmartFragmentStatePagerAdapter(FragmentManager fragmentManager) {
|
||||
SmartFragmentStatePagerAdapter(FragmentManager fragmentManager) {
|
||||
super(fragmentManager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
public int getItemPosition(@NonNull Object object) {
|
||||
return POSITION_NONE;
|
||||
}
|
||||
|
||||
// Register the fragment when the item is instantiated
|
||||
@NonNull
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
Fragment fragment = (Fragment) super.instantiateItem(container, position);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.wismna.geoffroy.donext.adapters;
|
||||
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
@@ -54,12 +53,11 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
||||
holder.mTaskCountView.setText(String.valueOf(mValues.get(position).getTaskCount()));
|
||||
holder.mTaskNameView.setText(mValues.get(position).getName());
|
||||
|
||||
|
||||
// TODO: correct this...
|
||||
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (MotionEventCompat.getActionMasked(event) ==
|
||||
MotionEvent.ACTION_DOWN) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
mListener.onStartDrag(holder);
|
||||
}
|
||||
return false;
|
||||
@@ -147,10 +145,10 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
|
||||
ViewHolder(View view) {
|
||||
super(view);
|
||||
mView = view;
|
||||
handleView = (ImageView) itemView.findViewById(R.id.handle);
|
||||
mTaskCountView = (TextView) view.findViewById(R.id.task_list_count);
|
||||
mTaskNameView = (TextView) view.findViewById(R.id.task_list_name);
|
||||
mTaskDeleteButton = (Button) view.findViewById(R.id.task_list_delete);
|
||||
handleView = itemView.findViewById(R.id.handle);
|
||||
mTaskCountView = view.findViewById(R.id.task_list_count);
|
||||
mTaskNameView = view.findViewById(R.id.task_list_name);
|
||||
mTaskDeleteButton = view.findViewById(R.id.task_list_delete);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -98,10 +98,6 @@ public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerVi
|
||||
return viewType;
|
||||
}
|
||||
|
||||
public void setItemViewType(int viewType) {
|
||||
this.viewType = viewType;
|
||||
}
|
||||
|
||||
public void add(Task item, int position) {
|
||||
mValues.add(position, item);
|
||||
notifyItemInserted(position);
|
||||
@@ -146,10 +142,10 @@ public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerVi
|
||||
super(view);
|
||||
mView = view;
|
||||
|
||||
mIdView = (TextView) view.findViewById(R.id.task_id);
|
||||
mAlarmView = (ImageView) view.findViewById(R.id.task_alarm);
|
||||
mCycleView = (TextView) view.findViewById(R.id.task_cycle);
|
||||
mTitleView = (TextView) view.findViewById(R.id.task_name);
|
||||
mIdView = view.findViewById(R.id.task_id);
|
||||
mAlarmView = view.findViewById(R.id.task_alarm);
|
||||
mCycleView = view.findViewById(R.id.task_cycle);
|
||||
mTitleView = view.findViewById(R.id.task_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,7 +159,7 @@ public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerVi
|
||||
|
||||
private DetailedViewHolder(View view) {
|
||||
super(view);
|
||||
mDescriptionView = (TextView) view.findViewById(R.id.task_description);
|
||||
mDescriptionView = view.findViewById(R.id.task_description);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,9 +34,9 @@ public class TodayArrayAdapter extends ArrayAdapter<Task> {
|
||||
if (convertView == null) {
|
||||
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_task_item, parent, false);
|
||||
}
|
||||
TextView titleView = (TextView) convertView.findViewById(R.id.task_list_item_title);
|
||||
TextView taskView = (TextView) convertView.findViewById(R.id.task_list_item_tasklist);
|
||||
LinearLayout layoutView = (LinearLayout) convertView.findViewById(R.id.task_list_item_layout);
|
||||
TextView titleView = convertView.findViewById(R.id.task_list_item_title);
|
||||
TextView taskView = convertView.findViewById(R.id.task_list_item_tasklist);
|
||||
LinearLayout layoutView = convertView.findViewById(R.id.task_list_item_layout);
|
||||
Task item = this.getItem(position);
|
||||
if (item != null) {
|
||||
titleView.setText(item.getName());
|
||||
|
@@ -59,18 +59,10 @@ public class Task {
|
||||
this.cycle = cycle;
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return done != 0;
|
||||
}
|
||||
|
||||
public void setDone(int done) {
|
||||
this.done = done;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted != 0;
|
||||
}
|
||||
|
||||
public void setDeleted(int deleted) {
|
||||
this.deleted = deleted;
|
||||
}
|
||||
|
@@ -8,8 +8,6 @@ public class TaskList {
|
||||
private long id;
|
||||
private String name;
|
||||
private long taskCount;
|
||||
private int order;
|
||||
private Boolean visible;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
@@ -35,20 +33,6 @@ public class TaskList {
|
||||
this.taskCount = taskCount;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public void setVisible(int visible) {
|
||||
this.visible = visible != 0;
|
||||
}
|
||||
public Boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
|
@@ -133,25 +133,25 @@ public class TaskDataAccess implements AutoCloseable {
|
||||
return getTasksFromCursor(cursor);
|
||||
}
|
||||
|
||||
public int setDone(long id) {
|
||||
return update(id, DatabaseHelper.TASKS_COLUMN_DONE, 1);
|
||||
public void setDone(long id) {
|
||||
update(id, DatabaseHelper.TASKS_COLUMN_DONE, 1);
|
||||
}
|
||||
|
||||
public int increaseCycle(int newCycle, long id) {
|
||||
return update(id, DatabaseHelper.TASKS_COLUMN_CYCLE, newCycle);
|
||||
public void increaseCycle(int newCycle, long id) {
|
||||
update(id, DatabaseHelper.TASKS_COLUMN_CYCLE, newCycle);
|
||||
}
|
||||
|
||||
public int deleteTask(long id) {
|
||||
public void deleteTask(long id) {
|
||||
/*database.delete(DatabaseHelper.TASKS_TABLE_NAME,
|
||||
DatabaseHelper.COLUMN_ID + " = " + taskId, null);*/
|
||||
return update(id, DatabaseHelper.TASKS_COLUMN_DELETED, 1);
|
||||
update(id, DatabaseHelper.TASKS_COLUMN_DELETED, 1);
|
||||
}
|
||||
|
||||
private int update(long id, String column, Object value) {
|
||||
private void update(long id, String column, Object value) {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
if (value instanceof Integer)
|
||||
contentValues.put(column, (int) value);
|
||||
return database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
||||
database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues, DatabaseHelper.COLUMN_ID + " = " + id, null);
|
||||
}
|
||||
|
||||
private Task cursorToTask(Cursor cursor) {
|
||||
|
@@ -133,8 +133,8 @@ public class TaskListDataAccess implements AutoCloseable {
|
||||
TaskList taskList = new TaskList();
|
||||
taskList.setId(cursor.getLong(0));
|
||||
taskList.setName(cursor.getString(1));
|
||||
taskList.setOrder(cursor.getInt(2));
|
||||
taskList.setVisible(cursor.getInt(3));
|
||||
//taskList.setOrder(cursor.getInt(2));
|
||||
//taskList.setVisible(cursor.getInt(3));
|
||||
// Get "false" count column if it exists
|
||||
if (cursor.getColumnCount() == 5)
|
||||
taskList.setTaskCount(cursor.getLong(4));
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
@@ -49,7 +48,8 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
Bundle args = getArguments();
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
// No need for a parent in a Dialog Fragment
|
||||
@SuppressLint("InflateParams") View view = inflater.inflate(R.layout.fragment_task_confirmation, null);
|
||||
View view = inflater.inflate(R.layout.fragment_task_confirmation, null);
|
||||
assert args != null;
|
||||
builder.setView(view).setMessage(args.getString("message"))
|
||||
.setPositiveButton(args.getInt("button"), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
@@ -63,10 +62,12 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
@NonNull
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
// Inflate and set the layout for the dialog
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
Activity activity = getActivity();
|
||||
assert activity != null;
|
||||
LayoutInflater inflater = activity.getLayoutInflater();
|
||||
// As it is a Dialog, the root ViewGroup can be null without issues
|
||||
@SuppressLint("InflateParams") final View view = inflater.inflate(R.layout.fragment_dynamic_dialog, null);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final View view = inflater.inflate(R.layout.fragment_dynamic_dialog, null);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
Bundle args = getArguments();
|
||||
// Set the dialog buttons
|
||||
assert args != null;
|
||||
@@ -102,7 +103,6 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
//super.onCreateOptionsMenu(menu, inflater);
|
||||
menu.clear();
|
||||
getActivity().getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu);
|
||||
}
|
||||
@@ -110,6 +110,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
Bundle args = getArguments();
|
||||
assert args != null;
|
||||
// Show the neutral button if needed
|
||||
if (mButtonCount < 3) {
|
||||
menu.removeItem(R.id.menu_neutral_button);
|
||||
|
@@ -1,14 +1,15 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Point;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
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;
|
||||
@@ -21,7 +22,7 @@ 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.SectionsPagerAdapter;
|
||||
import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter;
|
||||
import com.wismna.geoffroy.donext.dao.Task;
|
||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||
@@ -38,72 +39,46 @@ public class MainFragment extends Fragment implements TasksFragment.TaskChangedA
|
||||
private ViewPager mViewPager;
|
||||
private SectionsPagerAdapter mSectionsPagerAdapter;
|
||||
private TabLayout tabLayout;
|
||||
private List<TaskList> 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
|
||||
// TODO: History should get its own activity and this fragment
|
||||
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,
|
||||
public View onCreateView(@NonNull 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);
|
||||
assert activity != null;
|
||||
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
|
||||
List<TaskList> taskLists;
|
||||
try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(activity)) {
|
||||
taskLists = taskListDataAccess.getAllTaskLists();
|
||||
|
||||
// Create the adapter that will return a fragment for each of the three
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), taskLists);
|
||||
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
boolean isLargeLayout = getResources().getBoolean(R.bool.large_layout);
|
||||
|
||||
// TODO: determine whether this is the first startup, and if so, show a tutorial of sorts
|
||||
// No tasks, show the edit task lists fragment
|
||||
if (taskLists.size() == 0) {
|
||||
TaskListsDialogFragment taskListFragment = new TaskListsDialogFragment();
|
||||
String title = getString(R.string.task_list_no_lists);
|
||||
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
||||
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||
|
||||
// Set the arguments
|
||||
Bundle args = new Bundle();
|
||||
@@ -113,6 +88,7 @@ public class MainFragment extends Fragment implements TasksFragment.TaskChangedA
|
||||
|
||||
taskListFragment.showFragment(fragmentManager, title, getResources().getBoolean(R.bool.large_layout));
|
||||
}
|
||||
// Otherwise, show the normal view
|
||||
else {
|
||||
int lastOpenedList = sharedPref.getInt("last_opened_tab", 0);
|
||||
// Set up the ViewPager with the sections adapter.
|
||||
@@ -121,9 +97,11 @@ public class MainFragment extends Fragment implements TasksFragment.TaskChangedA
|
||||
// Open last opened tab
|
||||
mViewPager.setCurrentItem(lastOpenedList);
|
||||
|
||||
if (!getResources().getBoolean(R.bool.large_layout)) {
|
||||
if (!isLargeLayout) {
|
||||
|
||||
tabLayout = mView.findViewById(R.id.tabs);
|
||||
// Hide the tabs if there is only one task list
|
||||
if (taskLists.size() == 1) tabLayout.setVisibility(View.INVISIBLE);
|
||||
tabLayout.setupWithViewPager(mViewPager);
|
||||
|
||||
// Handles scroll detection (only available for SDK version >=23)
|
||||
@@ -140,6 +118,8 @@ public class MainFragment extends Fragment implements TasksFragment.TaskChangedA
|
||||
}
|
||||
else {
|
||||
ListView listView = mView.findViewById(R.id.list);
|
||||
// Hide the list if there is only one task list
|
||||
if (taskLists.size() == 1) listView.setVisibility(View.INVISIBLE);
|
||||
//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.setSelection(lastOpenedList);
|
||||
@@ -196,48 +176,12 @@ public class MainFragment extends Fragment implements TasksFragment.TaskChangedA
|
||||
View rightArrow = mView.findViewById(R.id.right_arrow);
|
||||
if (rightArrow != null) {
|
||||
Point size = new Point();
|
||||
getActivity().getWindowManager().getDefaultDisplay().getSize(size);
|
||||
Activity activity = getActivity();
|
||||
assert activity != null;
|
||||
activity.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<TaskList> getAllItems(){
|
||||
return taskLists;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -22,6 +22,7 @@ import com.wismna.geoffroy.donext.dao.TaskList;
|
||||
import com.wismna.geoffroy.donext.database.TaskListDataAccess;
|
||||
import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -53,38 +54,9 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
|
||||
mContentLayoutId = R.layout.content_tasklists;
|
||||
taskListDataAccess = new TaskListDataAccess(getContext(), TaskListDataAccess.MODE.WRITE);
|
||||
new GetTaskListsTask().execute(taskListDataAccess);
|
||||
new GetTaskListsTask(this).execute(taskListDataAccess);
|
||||
}
|
||||
|
||||
/*@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
mView = inflater.inflate(R.layout.content_tasklists, container, false);
|
||||
|
||||
Button createTaskListButton = mView.findViewById(R.id.new_task_list_button);
|
||||
createTaskListButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
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));
|
||||
return;
|
||||
}
|
||||
int position = taskListRecyclerViewAdapter.getItemCount();
|
||||
|
||||
TaskList taskList = taskListDataAccess.createTaskList(text, position);
|
||||
taskListRecyclerViewAdapter.add(taskList, position);
|
||||
|
||||
editText.setText("");
|
||||
toggleVisibleCreateNewTaskListLayout(mView);
|
||||
}
|
||||
});
|
||||
|
||||
return mView;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
@@ -223,7 +195,13 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
private class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> {
|
||||
private static class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> {
|
||||
private WeakReference<TaskListsDialogFragment> fragmentReference;
|
||||
|
||||
GetTaskListsTask(TaskListsDialogFragment context) {
|
||||
fragmentReference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<TaskList> doInBackground(TaskListDataAccess... params) {
|
||||
TaskListDataAccess taskListDataAccess = params[0];
|
||||
@@ -233,21 +211,23 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
@Override
|
||||
protected void onPostExecute(List<TaskList> taskLists) {
|
||||
super.onPostExecute(taskLists);
|
||||
taskListRecyclerViewAdapter =
|
||||
new TaskListRecyclerViewAdapter(taskLists, TaskListsDialogFragment.this);
|
||||
TaskListsDialogFragment fragment = fragmentReference.get();
|
||||
if (fragment == null) return;
|
||||
fragment.taskListRecyclerViewAdapter =
|
||||
new TaskListRecyclerViewAdapter(taskLists, fragment);
|
||||
|
||||
// Set the adapter
|
||||
Context context = getContext();
|
||||
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.task_lists_view);
|
||||
Context context = fragment.getContext();
|
||||
RecyclerView recyclerView = (RecyclerView) fragment.findViewById(R.id.task_lists_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
recyclerView.setAdapter(taskListRecyclerViewAdapter);
|
||||
recyclerView.setAdapter(fragment.taskListRecyclerViewAdapter);
|
||||
|
||||
// Set the Touch Helper
|
||||
ItemTouchHelper.Callback callback = new TaskListTouchHelper(taskListRecyclerViewAdapter);
|
||||
mItemTouchHelper = new ItemTouchHelper(callback);
|
||||
mItemTouchHelper.attachToRecyclerView(recyclerView);
|
||||
ItemTouchHelper.Callback callback = new TaskListTouchHelper(fragment.taskListRecyclerViewAdapter);
|
||||
fragment.mItemTouchHelper = new ItemTouchHelper(callback);
|
||||
fragment.mItemTouchHelper.attachToRecyclerView(recyclerView);
|
||||
|
||||
toggleVisibleCreateNewTaskListLayout();
|
||||
fragment.toggleVisibleCreateNewTaskListLayout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,17 +1,19 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -26,6 +28,9 @@ import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
||||
import com.wismna.geoffroy.donext.activities.TodayActivity;
|
||||
import com.wismna.geoffroy.donext.adapters.SectionsPagerAdapter;
|
||||
import com.wismna.geoffroy.donext.adapters.TaskRecyclerViewAdapter;
|
||||
import com.wismna.geoffroy.donext.dao.Task;
|
||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||
@@ -48,7 +53,7 @@ public class TasksFragment extends Fragment implements
|
||||
ConfirmDialogFragment.ConfirmDialogListener,
|
||||
TaskTouchHelper.TaskTouchHelperAdapter{
|
||||
|
||||
interface TaskChangedAdapter {
|
||||
public interface TaskChangedAdapter {
|
||||
void onTaskListChanged(Task task, int tabPosition);
|
||||
}
|
||||
|
||||
@@ -69,15 +74,11 @@ public class TasksFragment extends Fragment implements
|
||||
public TasksFragment() {
|
||||
}
|
||||
|
||||
public static TasksFragment newTaskListInstance(long taskListId, boolean isHistory,
|
||||
TaskChangedAdapter taskChangedAdapter) {
|
||||
public static TasksFragment newTaskListInstance(long taskListId) {
|
||||
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;
|
||||
fragment.setRetainInstance(true);
|
||||
return fragment;
|
||||
}
|
||||
@@ -88,19 +89,23 @@ public class TasksFragment extends Fragment implements
|
||||
|
||||
if (getArguments() != null) {
|
||||
taskListId = getArguments().getLong(TASK_LIST_ID);
|
||||
isHistory = getArguments().getBoolean("history");
|
||||
Activity parentActivity = getActivity();
|
||||
if (parentActivity instanceof HistoryActivity) isHistory = true;
|
||||
if (parentActivity instanceof TodayActivity) isTodayView = true;
|
||||
// TODO: check that this works!
|
||||
mAdapter = (MainFragment)getParentFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
view = inflater.inflate(R.layout.fragment_tasks, container, false);
|
||||
final Context context = view.getContext();
|
||||
|
||||
// Set the Recycler view
|
||||
recyclerView = view.findViewById(R.id.task_list_view);
|
||||
recyclerView.setLayoutManager(new NoScrollingLayoutManager(context));
|
||||
recyclerView.setLayoutManager(isHistory ? new LinearLayoutManager(context) : new NoScrollingLayoutManager(context));
|
||||
|
||||
// Set RecyclerView Adapter
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
@@ -113,14 +118,17 @@ public class TasksFragment extends Fragment implements
|
||||
}
|
||||
recyclerView.setAdapter(taskRecyclerViewAdapter);
|
||||
|
||||
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
||||
final Resources resources = getResources();
|
||||
ItemTouchHelper.Callback callback = new TaskTouchHelper(this,
|
||||
ContextCompat.getColor(context, R.color.colorPrimary),
|
||||
ContextCompat.getColor(context, R.color.colorAccent));
|
||||
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
||||
helper.attachToRecyclerView(recyclerView);
|
||||
if (!isHistory) {
|
||||
// Set ItemTouch helper in RecyclerView to handle swipe move on elements
|
||||
ItemTouchHelper.Callback callback = new TaskTouchHelper(this,
|
||||
ContextCompat.getColor(context, R.color.colorPrimary),
|
||||
ContextCompat.getColor(context, R.color.colorAccent));
|
||||
|
||||
ItemTouchHelper helper = new ItemTouchHelper(callback);
|
||||
helper.attachToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
final Resources resources = getResources();
|
||||
// Implements touch listener to add click detection
|
||||
recyclerView.addOnItemTouchListener(
|
||||
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
|
||||
@@ -131,9 +139,10 @@ public class TasksFragment extends Fragment implements
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("position", position);
|
||||
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
|
||||
args.putBoolean("neutral", true);
|
||||
args.putInt("button_count", isHistory ? 1 : 3);
|
||||
args.putString("button_positive", getString(R.string.new_task_save));
|
||||
args.putString("button_negative", getString(R.string.new_task_cancel));
|
||||
args.putString("button_negative",
|
||||
isHistory ? getString(R.string.task_list_ok) : getString(R.string.new_task_cancel));
|
||||
args.putString("button_neutral", getString(R.string.new_task_delete));
|
||||
|
||||
// Set current tab value to new task dialog
|
||||
@@ -141,7 +150,7 @@ public class TasksFragment extends Fragment implements
|
||||
List<TaskList> taskLists;
|
||||
Task task = taskRecyclerViewAdapter.getItem(position);
|
||||
if (viewPager != null) {
|
||||
taskLists = ((MainFragment.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems();
|
||||
taskLists = ((SectionsPagerAdapter) viewPager.getAdapter()).getAllItems();
|
||||
args.putInt("list", viewPager.getCurrentItem());
|
||||
}
|
||||
else {
|
||||
@@ -164,19 +173,8 @@ public class TasksFragment extends Fragment implements
|
||||
|
||||
// Open the fragment as a dialog or as full-screen depending on screen size
|
||||
String title = getString(R.string.action_edit_task);
|
||||
if (isLargeLayout) {
|
||||
taskDialogFragment.show(manager, title);
|
||||
}
|
||||
else {
|
||||
// The device is smaller, so show the fragment fullscreen
|
||||
FragmentTransaction transaction = manager.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();
|
||||
}
|
||||
assert manager != null;
|
||||
taskDialogFragment.showFragment(manager, title, isLargeLayout);
|
||||
}
|
||||
})
|
||||
);
|
||||
@@ -235,6 +233,7 @@ public class TasksFragment extends Fragment implements
|
||||
@Override
|
||||
public void onConfirmDialogClick(DialogFragment dialog, ConfirmDialogFragment.ButtonEvent event) {
|
||||
Bundle args = dialog.getArguments();
|
||||
assert args != null;
|
||||
int itemPosition = args.getInt("ItemPosition");
|
||||
int direction = args.getInt("Direction");
|
||||
|
||||
@@ -317,6 +316,7 @@ public class TasksFragment extends Fragment implements
|
||||
}
|
||||
// Update the task
|
||||
else {
|
||||
assert args != null;
|
||||
int position = args.getInt("position");
|
||||
// Check if task list was changed
|
||||
if ((isTodayView && !isToday) || (!isTodayView && task.getTaskListId() != taskList.getId()))
|
||||
@@ -340,6 +340,7 @@ public class TasksFragment extends Fragment implements
|
||||
Bundle args = dialog.getArguments();
|
||||
|
||||
// Delete task from Adapter
|
||||
assert args != null;
|
||||
final int itemPosition = args.getInt("position");
|
||||
|
||||
if (showDialog) {
|
||||
@@ -418,6 +419,7 @@ public class TasksFragment extends Fragment implements
|
||||
break;
|
||||
case -1:
|
||||
FragmentManager manager = getFragmentManager();
|
||||
assert manager != null;
|
||||
DialogFragment dialog = (DialogFragment) manager.findFragmentByTag(getString(R.string.action_edit_task));
|
||||
if (dialog != null) dialog.dismiss();
|
||||
action = resources.getString(R.string.snackabar_action_deleted);
|
||||
|
@@ -18,6 +18,7 @@ import com.wismna.geoffroy.donext.database.TaskDataAccess;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -50,7 +51,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
super.onCreate(savedInstanceState);
|
||||
mContentLayoutId = R.layout.content_today_form;
|
||||
// Load the tasks asynchronously
|
||||
new LoadTasks().execute(getActivity());
|
||||
new LoadTasks(this).execute(getActivity());
|
||||
}
|
||||
|
||||
private void setLayoutValues(List<Task> tasks) {
|
||||
@@ -94,7 +95,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
protected void onPositiveButtonClick(View view) {
|
||||
mListener.onTodayTaskDialogPositiveClick(view);
|
||||
// Only commit the updated tasks to DB
|
||||
new UpdateTasks().execute(mUpdatedTasks.toArray(new Task[mUpdatedTasks.size()]));
|
||||
new UpdateTasks(this).execute(mUpdatedTasks.toArray(new Task[mUpdatedTasks.size()]));
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@@ -108,7 +109,13 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private class LoadTasks extends AsyncTask<Context, Void, List<Task>> {
|
||||
static class LoadTasks extends AsyncTask<Context, Void, List<Task>> {
|
||||
private WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||
|
||||
LoadTasks(TodayFormDialogFragment context) {
|
||||
fragmentReference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Task> doInBackground(Context... params) {
|
||||
try(TaskDataAccess taskDataAccess = new TaskDataAccess(params[0])) {
|
||||
@@ -119,15 +126,21 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
@Override
|
||||
protected void onPostExecute(List<Task> tasks) {
|
||||
super.onPostExecute(tasks);
|
||||
setLayoutValues(tasks);
|
||||
fragmentReference.get().setLayoutValues(tasks);
|
||||
}
|
||||
}
|
||||
|
||||
private class UpdateTasks extends AsyncTask<Task, Void, Integer> {
|
||||
private static class UpdateTasks extends AsyncTask<Task, Void, Integer> {
|
||||
private WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||
|
||||
UpdateTasks(TodayFormDialogFragment context) {
|
||||
fragmentReference = new WeakReference<>(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Integer doInBackground(Task... params) {
|
||||
int elementsUpdated = 0;
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(getActivity(), TaskDataAccess.MODE.WRITE)) {
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(fragmentReference.get().getActivity(), TaskDataAccess.MODE.WRITE)) {
|
||||
for (Task task :
|
||||
params) {
|
||||
taskDataAccess.updateTodayTasks(task.getId(), task.isToday());
|
||||
@@ -140,7 +153,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
@Override
|
||||
protected void onPostExecute(Integer integer) {
|
||||
super.onPostExecute(integer);
|
||||
mListener.onTodayTasksUpdated();
|
||||
fragmentReference.get().mListener.onTodayTasksUpdated();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,6 @@ public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListen
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
|
||||
View childView = view.findChildViewUnder(e.getX(), e.getY());
|
||||
//int childId = view.getChildAdapterPosition(childView);
|
||||
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
|
||||
mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
|
||||
return true;
|
||||
|
@@ -28,6 +28,12 @@ public class NonSwipeableViewPager extends ViewPager {
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
// Never allow swiping to switch between pages
|
||||
performClick();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performClick() {
|
||||
return super.performClick();
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 331 B |
Before Width: | Height: | Size: 392 B |
BIN
app/src/main/res/drawable-hdpi/ic_history_dark.png
Normal file
After Width: | Height: | Size: 840 B |
Before Width: | Height: | Size: 961 B |
BIN
app/src/main/res/drawable-hdpi/ic_today_dark.png
Normal file
After Width: | Height: | Size: 306 B |
Before Width: | Height: | Size: 255 B |
Before Width: | Height: | Size: 304 B |
BIN
app/src/main/res/drawable-mdpi/ic_history_dark.png
Normal file
After Width: | Height: | Size: 561 B |
Before Width: | Height: | Size: 643 B |
BIN
app/src/main/res/drawable-mdpi/ic_today_dark.png
Normal file
After Width: | Height: | Size: 221 B |
Before Width: | Height: | Size: 351 B |
Before Width: | Height: | Size: 496 B |
BIN
app/src/main/res/drawable-xhdpi/ic_history_dark.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.2 KiB |
BIN
app/src/main/res/drawable-xhdpi/ic_today_dark.png
Normal file
After Width: | Height: | Size: 337 B |
Before Width: | Height: | Size: 503 B |
Before Width: | Height: | Size: 620 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_history_dark.png
Normal file
After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 437 B |
BIN
app/src/main/res/drawable-xxhdpi/ic_today_dark.png
Normal file
After Width: | Height: | Size: 572 B |
13
app/src/main/res/layout/activity_history.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout 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"
|
||||
tools:context="com.wismna.geoffroy.donext.activities.HistoryActivity">
|
||||
<fragment
|
||||
android:id="@+id/fragment_main"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:name="com.wismna.geoffroy.donext.fragments.MainFragment"
|
||||
/>
|
||||
</android.support.constraint.ConstraintLayout>
|
@@ -13,7 +13,7 @@
|
||||
android:orderInCategory="15"
|
||||
android:title="@string/action_todayList"
|
||||
android:onClick="showTodayList"
|
||||
android:icon="@drawable/ic_stat_name"
|
||||
android:icon="@drawable/ic_today_dark"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
@@ -35,7 +35,7 @@
|
||||
android:orderInCategory="25"
|
||||
android:title="@string/action_history"
|
||||
android:onClick="openHistory"
|
||||
android:icon="@drawable/ic_list_white_24dp"
|
||||
android:icon="@drawable/ic_history_dark"
|
||||
app:showAsAction="ifRoom" />
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
|
@@ -61,4 +61,5 @@
|
||||
<string name="incompatible_sdk_version">Sorry, your Android version is not supported.</string>
|
||||
<string name="action_history">Historique</string>
|
||||
<string name="task_list_ok">OK</string>
|
||||
<string name="title_activity_history">Historique</string>
|
||||
</resources>
|
@@ -20,6 +20,7 @@
|
||||
<string name="task_list_confirmation_delete">Delete task list?</string>
|
||||
<string name="task_list_drag_handle">Drag handle</string>
|
||||
<string name="task_list_no_lists">Create a new task list</string>
|
||||
<string name="task_list_ok">OK</string>
|
||||
|
||||
<!-- Strings related to new task dialog -->
|
||||
<string name="new_task_list">List</string>
|
||||
@@ -80,5 +81,7 @@
|
||||
<string name="incompatible_sdk_version">Sorry, your Android version is not supported.</string>
|
||||
<string name="action_history">History</string>
|
||||
|
||||
<string name="task_list_ok">OK</string>
|
||||
<!-- String related to History -->
|
||||
<string name="title_activity_history">History</string>
|
||||
|
||||
</resources>
|
||||
|