mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 07:30:13 -04:00
Refactor some code
Fix moving existing task to antoher list
This commit is contained in:
15
.idea/deploymentTargetDropDown.xml
generated
15
.idea/deploymentTargetDropDown.xml
generated
@@ -3,7 +3,20 @@
|
|||||||
<component name="deploymentTargetDropDown">
|
<component name="deploymentTargetDropDown">
|
||||||
<value>
|
<value>
|
||||||
<entry key="app">
|
<entry key="app">
|
||||||
<State />
|
<State>
|
||||||
|
<targetSelectedWithDropDown>
|
||||||
|
<Target>
|
||||||
|
<type value="QUICK_BOOT_TARGET" />
|
||||||
|
<deviceKey>
|
||||||
|
<Key>
|
||||||
|
<type value="VIRTUAL_DEVICE_PATH" />
|
||||||
|
<value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
|
||||||
|
</Key>
|
||||||
|
</deviceKey>
|
||||||
|
</Target>
|
||||||
|
</targetSelectedWithDropDown>
|
||||||
|
<timeTargetWasSelectedWithDropDown value="2023-12-20T14:05:53.615835Z" />
|
||||||
|
</State>
|
||||||
</entry>
|
</entry>
|
||||||
</value>
|
</value>
|
||||||
</component>
|
</component>
|
||||||
|
11
.idea/misc.xml
generated
11
.idea/misc.xml
generated
@@ -1,10 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="NullableNotNullManager">
|
<component name="NullableNotNullManager">
|
||||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
<option name="myDefaultNotNull" value="androidx.annotation.NonNull" />
|
||||||
<option name="myNullables">
|
<option name="myNullables">
|
||||||
<value>
|
<value>
|
||||||
<list size="14">
|
<list size="16">
|
||||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||||
@@ -19,12 +20,14 @@
|
|||||||
<item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
|
<item index="11" class="java.lang.String" itemvalue="org.eclipse.jdt.annotation.Nullable" />
|
||||||
<item index="12" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" />
|
<item index="12" class="java.lang.String" itemvalue="io.reactivex.annotations.Nullable" />
|
||||||
<item index="13" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" />
|
<item index="13" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.Nullable" />
|
||||||
|
<item index="14" class="java.lang.String" itemvalue="org.jspecify.nullness.Nullable" />
|
||||||
|
<item index="15" class="java.lang.String" itemvalue="jakarta.annotation.Nullable" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
<option name="myNotNulls">
|
<option name="myNotNulls">
|
||||||
<value>
|
<value>
|
||||||
<list size="14">
|
<list size="16">
|
||||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||||
@@ -39,6 +42,8 @@
|
|||||||
<item index="11" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" />
|
<item index="11" class="java.lang.String" itemvalue="io.reactivex.annotations.NonNull" />
|
||||||
<item index="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" />
|
<item index="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.NonNull" />
|
||||||
<item index="13" class="java.lang.String" itemvalue="lombok.NonNull" />
|
<item index="13" class="java.lang.String" itemvalue="lombok.NonNull" />
|
||||||
|
<item index="14" class="java.lang.String" itemvalue="jakarta.annotation.Nonnull" />
|
||||||
|
<item index="15" class="java.lang.String" itemvalue="org.jspecify.nullness.NonNull" />
|
||||||
</list>
|
</list>
|
||||||
</value>
|
</value>
|
||||||
</option>
|
</option>
|
||||||
|
@@ -4,13 +4,14 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
import com.microsoft.appcenter.AppCenter;
|
import com.microsoft.appcenter.AppCenter;
|
||||||
import com.microsoft.appcenter.analytics.Analytics;
|
import com.microsoft.appcenter.analytics.Analytics;
|
||||||
import com.microsoft.appcenter.crashes.Crashes;
|
import com.microsoft.appcenter.crashes.Crashes;
|
||||||
@@ -135,7 +136,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
getString(R.string.action_new_task), getResources().getBoolean(R.bool.large_layout));
|
getString(R.string.action_new_task), getResources().getBoolean(R.bool.large_layout));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ViewPager getMainFragmentViewPager(){
|
private ViewPager getMainFragmentViewPager() {
|
||||||
FragmentManager manager = getSupportFragmentManager();
|
FragmentManager manager = getSupportFragmentManager();
|
||||||
MainFragment fragment = (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
MainFragment fragment = (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
||||||
return fragment != null ? fragment.getViewPager() : null;
|
return fragment != null ? fragment.getViewPager() : null;
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
package com.wismna.geoffroy.donext.adapters;
|
package com.wismna.geoffroy.donext.adapters;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
|
||||||
|
|
||||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||||
import com.wismna.geoffroy.donext.fragments.TasksFragment;
|
import com.wismna.geoffroy.donext.fragments.TasksFragment;
|
||||||
@@ -10,18 +10,19 @@ import com.wismna.geoffroy.donext.fragments.TasksFragment;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
|
* A {@link SmartFragmentStatePagerAdapter} that returns a fragment corresponding to
|
||||||
* one of the sections/tabs/pages.
|
* one of the sections/tabs/pages.
|
||||||
*/
|
*/
|
||||||
public class SectionsPagerAdapter extends SmartFragmentStatePagerAdapter {
|
public class SectionsPagerAdapter extends SmartFragmentStatePagerAdapter {
|
||||||
|
|
||||||
private List<TaskList> taskLists;
|
private final List<TaskList> taskLists;
|
||||||
|
|
||||||
public SectionsPagerAdapter(FragmentManager fm, List<TaskList> taskLists) {
|
public SectionsPagerAdapter(FragmentManager fm, List<TaskList> taskLists) {
|
||||||
super(fm);
|
super(fm);
|
||||||
this.taskLists = taskLists;
|
this.taskLists = taskLists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
// getItem is called to instantiate the fragment for the given page.
|
// getItem is called to instantiate the fragment for the given page.
|
||||||
|
@@ -9,7 +9,6 @@ import org.joda.time.LocalDate;
|
|||||||
* Data access object class that represents a Task
|
* Data access object class that represents a Task
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class Task {
|
public class Task {
|
||||||
private long id;
|
private long id;
|
||||||
private String name;
|
private String name;
|
||||||
|
@@ -7,7 +7,6 @@ import androidx.annotation.NonNull;
|
|||||||
* Data access object class that represents a Task List
|
* Data access object class that represents a Task List
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public class TaskList {
|
public class TaskList {
|
||||||
private long id;
|
private long id;
|
||||||
private String name;
|
private String name;
|
||||||
|
@@ -16,7 +16,6 @@ import java.util.List;
|
|||||||
* Created by geoffroy on 15-11-27.
|
* Created by geoffroy on 15-11-27.
|
||||||
* Data access class that handles Tasks
|
* Data access class that handles Tasks
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class TaskDataAccess implements AutoCloseable {
|
public class TaskDataAccess implements AutoCloseable {
|
||||||
public enum MODE {
|
public enum MODE {
|
||||||
READ,
|
READ,
|
||||||
|
@@ -14,7 +14,6 @@ import java.util.List;
|
|||||||
* Created by geoffroy on 15-11-25.
|
* Created by geoffroy on 15-11-25.
|
||||||
* Data access class that handles Task Lists
|
* Data access class that handles Task Lists
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class TaskListDataAccess implements AutoCloseable {
|
public class TaskListDataAccess implements AutoCloseable {
|
||||||
public enum MODE {
|
public enum MODE {
|
||||||
READ,
|
READ,
|
||||||
|
@@ -3,16 +3,15 @@ package com.wismna.geoffroy.donext.fragments;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.wismna.geoffroy.donext.R;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
import java.util.Objects;
|
import com.wismna.geoffroy.donext.R;
|
||||||
|
|
||||||
public class ConfirmDialogFragment extends DialogFragment {
|
public class ConfirmDialogFragment extends DialogFragment {
|
||||||
interface ConfirmDialogListener {
|
interface ConfirmDialogListener {
|
||||||
@@ -33,7 +32,7 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(@NonNull DialogInterface dialog) {
|
||||||
super.onCancel(dialog);
|
super.onCancel(dialog);
|
||||||
|
|
||||||
// Allows refreshing the first item of the adapter
|
// Allows refreshing the first item of the adapter
|
||||||
@@ -43,7 +42,7 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getActivity()));
|
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
||||||
|
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
@@ -51,23 +50,12 @@ public class ConfirmDialogFragment extends DialogFragment {
|
|||||||
View view = inflater.inflate(R.layout.fragment_task_confirmation, null);
|
View view = inflater.inflate(R.layout.fragment_task_confirmation, null);
|
||||||
assert args != null;
|
assert args != null;
|
||||||
builder.setView(view).setMessage(args.getString("message"))
|
builder.setView(view).setMessage(args.getString("message"))
|
||||||
.setPositiveButton(args.getInt("button"), new DialogInterface.OnClickListener() {
|
.setPositiveButton(args.getInt("button"), (dialog, id) -> confirmDialogListener.onConfirmDialogClick(ConfirmDialogFragment.this, ButtonEvent.YES))
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
.setNegativeButton(R.string.task_confirmation_no_button, (dialog, id) -> {
|
||||||
confirmDialogListener.onConfirmDialogClick(ConfirmDialogFragment.this, ButtonEvent.YES);
|
// User cancelled the dialog
|
||||||
}
|
ConfirmDialogFragment.this.getDialog().cancel();
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.task_confirmation_no_button, new DialogInterface.OnClickListener() {
|
.setOnKeyListener((dialog, keyCode, event) -> keyCode != KeyEvent.KEYCODE_BACK);
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
// User cancelled the dialog
|
|
||||||
ConfirmDialogFragment.this.getDialog().cancel();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
||||||
return keyCode != KeyEvent.KEYCODE_BACK;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Create the AlertDialog object and return it
|
// Create the AlertDialog object and return it
|
||||||
Dialog dialog = builder.create();
|
Dialog dialog = builder.create();
|
||||||
dialog.setCanceledOnTouchOutside(true);
|
dialog.setCanceledOnTouchOutside(true);
|
||||||
|
@@ -4,7 +4,6 @@ import android.app.Activity;
|
|||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -76,27 +75,16 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||||
// Add action buttons
|
// Add action buttons
|
||||||
builder.setView(view)
|
builder.setView(view)
|
||||||
.setNegativeButton(mNegativeButtonString, new DialogInterface.OnClickListener() {
|
.setNegativeButton(mNegativeButtonString, (dialog, id) -> {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
// Send the negative button event back to the host activity
|
||||||
// Send the negative button event back to the host activity
|
// Canceled creation, nothing to do
|
||||||
// Canceled creation, nothing to do
|
onNegativeButtonClick();
|
||||||
onNegativeButtonClick();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (mButtonCount >= 2) {
|
if (mButtonCount >= 2) {
|
||||||
builder.setPositiveButton(mPositiveButtonString, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(mPositiveButtonString, (dialog, id) -> onPositiveButtonClick(view));
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
onPositiveButtonClick(view);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (mButtonCount == 3) {
|
if (mButtonCount == 3) {
|
||||||
builder.setNeutralButton(mNeutralButtonString, new DialogInterface.OnClickListener() {
|
builder.setNeutralButton(mNeutralButtonString, (dialog, which) -> onNeutralButtonClick(view));
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
onNeutralButtonClick(view);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
setToolbarTitle(view);
|
setToolbarTitle(view);
|
||||||
insertContentView(view, inflater);
|
insertContentView(view, inflater);
|
||||||
@@ -104,13 +92,13 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
Objects.requireNonNull(getActivity()).getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu);
|
requireActivity().getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrepareOptionsMenu(Menu menu) {
|
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||||
/*switch (mButtonCount) {
|
/*switch (mButtonCount) {
|
||||||
case 1:
|
case 1:
|
||||||
menu.removeItem(R.id.menu_positive_button);
|
menu.removeItem(R.id.menu_positive_button);
|
||||||
@@ -148,7 +136,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
|
|
||||||
// Hide the keyboard if present
|
// Hide the keyboard if present
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
InputMethodManager imm = (InputMethodManager) Objects.requireNonNull(getActivity()).getSystemService(Activity.INPUT_METHOD_SERVICE);
|
InputMethodManager imm = (InputMethodManager) requireActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||||
assert imm != null;
|
assert imm != null;
|
||||||
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
|
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
@@ -201,7 +189,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
/** Helper function to get a View, without having to worry about the fact that is a Dialog or not*/
|
/** Helper function to get a View, without having to worry about the fact that is a Dialog or not*/
|
||||||
protected <T extends View> T findViewById(int id) {
|
protected <T extends View> T findViewById(int id) {
|
||||||
if (getShowsDialog()) return getDialog().findViewById(id);
|
if (getShowsDialog()) return getDialog().findViewById(id);
|
||||||
return Objects.requireNonNull(getView()).findViewById(id);
|
return requireView().findViewById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -212,7 +200,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
|||||||
view.requestFocus();
|
view.requestFocus();
|
||||||
|
|
||||||
// Hide keyboard
|
// Hide keyboard
|
||||||
InputMethodManager inputMethodManager = (InputMethodManager) Objects.requireNonNull(getContext()).getSystemService(Context.INPUT_METHOD_SERVICE);
|
InputMethodManager inputMethodManager = (InputMethodManager) requireContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
Objects.requireNonNull(inputMethodManager).hideSoftInputFromWindow(view.getWindowToken(), 0);
|
Objects.requireNonNull(inputMethodManager).hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -6,22 +6,22 @@ import android.graphics.Point;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
||||||
import androidx.constraintlayout.widget.Guideline;
|
|
||||||
import com.google.android.material.tabs.TabLayout;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||||
|
import androidx.constraintlayout.widget.Guideline;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
import com.wismna.geoffroy.donext.R;
|
import com.wismna.geoffroy.donext.R;
|
||||||
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
||||||
import com.wismna.geoffroy.donext.adapters.SectionsPagerAdapter;
|
import com.wismna.geoffroy.donext.adapters.SectionsPagerAdapter;
|
||||||
@@ -126,7 +126,7 @@ public class MainFragment extends Fragment implements
|
|||||||
|
|
||||||
// Create the adapter that will return a fragment for each of the three
|
// Create the adapter that will return a fragment for each of the three
|
||||||
// primary sections of the activity.
|
// primary sections of the activity.
|
||||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), taskLists);
|
mSectionsPagerAdapter = new SectionsPagerAdapter(getParentFragmentManager(), taskLists);
|
||||||
mSectionsPagerAdapter.notifyDataSetChanged();
|
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,12 +145,7 @@ public class MainFragment extends Fragment implements
|
|||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
toggleTabLayoutArrows(tabLayout.getScrollX());
|
toggleTabLayoutArrows(tabLayout.getScrollX());
|
||||||
//tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT);
|
//tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT);
|
||||||
tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
tabLayout.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> toggleTabLayoutArrows(scrollX));
|
||||||
@Override
|
|
||||||
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
|
||||||
toggleTabLayoutArrows(scrollX);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -164,12 +159,7 @@ public class MainFragment extends Fragment implements
|
|||||||
// Hide the list if there is only one task list
|
// Hide the list if there is only one task list
|
||||||
listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists));
|
listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists));
|
||||||
//listView.setSelection(lastOpenedList);
|
//listView.setSelection(lastOpenedList);
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
listView.setOnItemClickListener((parent, view, position, id) -> mViewPager.setCurrentItem(position));
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
||||||
mViewPager.setCurrentItem(position);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2,18 +2,18 @@ package com.wismna.geoffroy.donext.fragments;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
import com.wismna.geoffroy.donext.R;
|
import com.wismna.geoffroy.donext.R;
|
||||||
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
||||||
import com.wismna.geoffroy.donext.dao.Task;
|
import com.wismna.geoffroy.donext.dao.Task;
|
||||||
@@ -66,7 +66,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
|||||||
mButtonCount = args.getInt("button_count");
|
mButtonCount = args.getInt("button_count");
|
||||||
mPositiveButtonString = getString(R.string.new_task_save);
|
mPositiveButtonString = getString(R.string.new_task_save);
|
||||||
mNegativeButtonString = getString(R.string.new_task_cancel);
|
mNegativeButtonString = getString(R.string.new_task_cancel);
|
||||||
mNeutralButtonString = getString(mTask.isHistory() ? R.string.new_task_restore : R.string.new_task_delete);
|
if (mTask != null) mNeutralButtonString = getString(mTask.isHistory() ? R.string.new_task_restore : R.string.new_task_delete);
|
||||||
listId = args.getInt("list");
|
listId = args.getInt("list");
|
||||||
isToday = args.getBoolean("today");
|
isToday = args.getBoolean("today");
|
||||||
}
|
}
|
||||||
@@ -141,12 +141,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
|||||||
final DatePicker dueDatePicker = findViewById(R.id.new_task_due_date);
|
final DatePicker dueDatePicker = findViewById(R.id.new_task_due_date);
|
||||||
// Handle due date spinner depending on check box
|
// Handle due date spinner depending on check box
|
||||||
CheckBox setDueDate = findViewById(R.id.new_task_due_date_set);
|
CheckBox setDueDate = findViewById(R.id.new_task_due_date_set);
|
||||||
setDueDate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
setDueDate.setOnCheckedChangeListener((buttonView, isChecked) -> dueDatePicker.setVisibility(isChecked ? View.VISIBLE : View.GONE));
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
dueDatePicker.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Handle priority changes
|
// Handle priority changes
|
||||||
final TextView tooltip = findViewById(R.id.new_task_priority_tooltip);
|
final TextView tooltip = findViewById(R.id.new_task_priority_tooltip);
|
||||||
|
@@ -23,7 +23,6 @@ import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
|
|||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A fragment representing a list of Items.
|
* A fragment representing a list of Items.
|
||||||
@@ -71,23 +70,20 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
Button createTaskListButton = findViewById(R.id.new_task_list_button);
|
Button createTaskListButton = findViewById(R.id.new_task_list_button);
|
||||||
createTaskListButton.setOnClickListener(new View.OnClickListener() {
|
createTaskListButton.setOnClickListener(v -> {
|
||||||
@Override
|
EditText editText = findViewById(R.id.new_task_list_name);
|
||||||
public void onClick(View v) {
|
String text = editText.getText().toString();
|
||||||
EditText editText = findViewById(R.id.new_task_list_name);
|
if (text.matches("")) {
|
||||||
String text = editText.getText().toString();
|
editText.setError(getResources().getString(R.string.task_list_new_list_error));
|
||||||
if (text.matches("")) {
|
return;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
int position = taskListRecyclerViewAdapter.getItemCount();
|
||||||
|
|
||||||
|
TaskList taskList = taskListDataAccess.createTaskList(text, position);
|
||||||
|
taskListRecyclerViewAdapter.add(taskList, position);
|
||||||
|
|
||||||
|
editText.setText("");
|
||||||
|
toggleVisibleCreateNewTaskListLayout();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +123,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
|||||||
int taskListCount = taskListRecyclerViewAdapter.getItemCount();
|
int taskListCount = taskListRecyclerViewAdapter.getItemCount();
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "5");
|
String maxTaskListsString = sharedPref.getString("pref_conf_max_lists", "5");
|
||||||
int maxTaskLists = Integer.valueOf(maxTaskListsString);
|
int maxTaskLists = Integer.parseInt(maxTaskListsString);
|
||||||
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
|
if (taskListCount >= maxTaskLists) layout.setVisibility(View.GONE);
|
||||||
else layout.setVisibility(View.VISIBLE);
|
else layout.setVisibility(View.VISIBLE);
|
||||||
clearFocus();
|
clearFocus();
|
||||||
@@ -152,7 +148,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
|||||||
args.putInt("ItemPosition", position);
|
args.putInt("ItemPosition", position);
|
||||||
args.putLong("ItemId", id);
|
args.putLong("ItemId", id);
|
||||||
confirmDialogFragment.setArguments(args);
|
confirmDialogFragment.setArguments(args);
|
||||||
confirmDialogFragment.show(Objects.requireNonNull(getFragmentManager()), title);
|
confirmDialogFragment.show(getParentFragmentManager(), title);
|
||||||
}
|
}
|
||||||
else deleteTaskList(position, id);
|
else deleteTaskList(position, id);
|
||||||
}
|
}
|
||||||
@@ -196,7 +192,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> {
|
private static class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> {
|
||||||
private WeakReference<TaskListsDialogFragment> fragmentReference;
|
private final WeakReference<TaskListsDialogFragment> fragmentReference;
|
||||||
|
|
||||||
GetTaskListsTask(TaskListsDialogFragment context) {
|
GetTaskListsTask(TaskListsDialogFragment context) {
|
||||||
fragmentReference = new WeakReference<>(context);
|
fragmentReference = new WeakReference<>(context);
|
||||||
|
@@ -6,20 +6,9 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentManager;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewTreeObserver;
|
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.DatePicker;
|
import android.widget.DatePicker;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
@@ -27,6 +16,17 @@ import android.widget.SeekBar;
|
|||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.wismna.geoffroy.donext.R;
|
import com.wismna.geoffroy.donext.R;
|
||||||
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
||||||
import com.wismna.geoffroy.donext.activities.TodayActivity;
|
import com.wismna.geoffroy.donext.activities.TodayActivity;
|
||||||
@@ -92,7 +92,6 @@ public class TasksFragment extends Fragment implements
|
|||||||
Activity parentActivity = getActivity();
|
Activity parentActivity = getActivity();
|
||||||
if (parentActivity instanceof HistoryActivity) isHistory = true;
|
if (parentActivity instanceof HistoryActivity) isHistory = true;
|
||||||
if (parentActivity instanceof TodayActivity) isTodayView = true;
|
if (parentActivity instanceof TodayActivity) isTodayView = true;
|
||||||
mAdapter = (MainFragment)getParentFragment();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -101,6 +100,10 @@ public class TasksFragment extends Fragment implements
|
|||||||
view = inflater.inflate(R.layout.fragment_tasks, container, false);
|
view = inflater.inflate(R.layout.fragment_tasks, container, false);
|
||||||
final Context context = view.getContext();
|
final Context context = view.getContext();
|
||||||
|
|
||||||
|
// TODO: is null...
|
||||||
|
FragmentManager manager = getParentFragmentManager();
|
||||||
|
mAdapter = (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
||||||
|
|
||||||
// Set the Recycler view
|
// Set the Recycler view
|
||||||
recyclerView = view.findViewById(R.id.task_list_view);
|
recyclerView = view.findViewById(R.id.task_list_view);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||||
@@ -125,88 +128,80 @@ public class TasksFragment extends Fragment implements
|
|||||||
final Resources resources = getResources();
|
final Resources resources = getResources();
|
||||||
// Implements touch listener to add click detection
|
// Implements touch listener to add click detection
|
||||||
recyclerView.addOnItemTouchListener(
|
recyclerView.addOnItemTouchListener(
|
||||||
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
|
new RecyclerItemClickListener(context, (view, position) -> {
|
||||||
@Override
|
boolean isLargeLayout = resources.getBoolean(R.bool.large_layout);
|
||||||
public void onItemClick(View view, int position) {
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||||
boolean isLargeLayout = resources.getBoolean(R.bool.large_layout);
|
Bundle args = new Bundle();
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
|
||||||
Bundle args = new Bundle();
|
args.putInt("button_count", isHistory ? 1 : 3);
|
||||||
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
|
args.putString("button_positive", getString(R.string.new_task_save));
|
||||||
args.putInt("button_count", isHistory ? 1 : 3);
|
args.putString("button_negative",
|
||||||
args.putString("button_positive", getString(R.string.new_task_save));
|
isHistory ? getString(R.string.task_list_ok) : getString(R.string.new_task_cancel));
|
||||||
args.putString("button_negative",
|
args.putString("button_neutral", getString(R.string.new_task_delete));
|
||||||
isHistory ? getString(R.string.task_list_ok) : getString(R.string.new_task_cancel));
|
args.putInt("position", position);
|
||||||
args.putString("button_neutral", getString(R.string.new_task_delete));
|
|
||||||
args.putInt("position", position);
|
|
||||||
|
|
||||||
// Set current tab value to new task dialog
|
// Set current tab value to new task dialog
|
||||||
ViewPager viewPager = Objects.requireNonNull(getActivity()).findViewById(R.id.container);
|
ViewPager viewPager = requireActivity().findViewById(R.id.container);
|
||||||
List<TaskList> taskLists;
|
List<TaskList> taskLists;
|
||||||
Task task = taskRecyclerViewAdapter.getItem(position);
|
Task task = taskRecyclerViewAdapter.getItem(position);
|
||||||
if (viewPager != null) {
|
if (viewPager != null) {
|
||||||
taskLists = ((SectionsPagerAdapter) Objects.requireNonNull(viewPager.getAdapter())).getAllItems();
|
taskLists = ((SectionsPagerAdapter) Objects.requireNonNull(viewPager.getAdapter())).getAllItems();
|
||||||
args.putInt("list", viewPager.getCurrentItem());
|
args.putInt("list", viewPager.getCurrentItem());
|
||||||
}
|
|
||||||
else {
|
|
||||||
try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(getActivity())) {
|
|
||||||
taskLists = taskListDataAccess.getTaskLists(isHistory);
|
|
||||||
}
|
|
||||||
for (TaskList taskList :
|
|
||||||
taskLists) {
|
|
||||||
if (taskList.getId() == task.getTaskListId()) {
|
|
||||||
args.putInt("list", taskLists.indexOf(taskList));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FragmentManager manager = getFragmentManager();
|
|
||||||
TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance(
|
|
||||||
task, taskLists, TasksFragment.this);
|
|
||||||
taskDialogFragment.setArguments(args);
|
|
||||||
|
|
||||||
// Open the fragment as a dialog or as full-screen depending on screen size
|
|
||||||
assert manager != null;
|
|
||||||
taskDialogFragment.showFragment(manager,
|
|
||||||
getString(isHistory ? R.string.action_view_task : R.string.action_edit_task), isLargeLayout);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
try (TaskListDataAccess taskListDataAccess = new TaskListDataAccess(getActivity())) {
|
||||||
|
taskLists = taskListDataAccess.getTaskLists(isHistory);
|
||||||
|
}
|
||||||
|
for (TaskList taskList :
|
||||||
|
taskLists) {
|
||||||
|
if (taskList.getId() == task.getTaskListId()) {
|
||||||
|
args.putInt("list", taskLists.indexOf(taskList));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskFormDialogFragment taskDialogFragment = TaskFormDialogFragment.newInstance(
|
||||||
|
task, taskLists, TasksFragment.this);
|
||||||
|
taskDialogFragment.setArguments(args);
|
||||||
|
|
||||||
|
// Open the fragment as a dialog or as full-screen depending on screen size
|
||||||
|
taskDialogFragment.showFragment(manager,
|
||||||
|
getString(isHistory ? R.string.action_view_task : R.string.action_edit_task), isLargeLayout);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handle updating total counts in a listener to be sure that the layout is available
|
// Handle updating total counts in a listener to be sure that the layout is available
|
||||||
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
recyclerView.getViewTreeObserver().addOnPreDrawListener(() -> {
|
||||||
@Override
|
// isAdded is tested to prevent an IllegalStateException when fast switching between tabs
|
||||||
public boolean onPreDraw() {
|
if (!isAdded()) return true;
|
||||||
// isAdded is tested to prevent an IllegalStateException when fast switching between tabs
|
Resources resources1 = getResources();
|
||||||
if (!isAdded()) return true;
|
|
||||||
Resources resources = getResources();
|
|
||||||
|
|
||||||
// Update total cycle count
|
// Update total cycle count
|
||||||
int totalCycles = taskRecyclerViewAdapter.getCycleCount();
|
int totalCycles = taskRecyclerViewAdapter.getCycleCount();
|
||||||
TextView totalCyclesView = view.findViewById(R.id.total_task_cycles);
|
TextView totalCyclesView = view.findViewById(R.id.total_task_cycles);
|
||||||
if (totalCycles != 0)
|
if (totalCycles != 0)
|
||||||
totalCyclesView.setText(resources.getQuantityString(R.plurals.task_total_cycles, totalCycles, totalCycles));
|
totalCyclesView.setText(resources1.getQuantityString(R.plurals.task_total_cycles, totalCycles, totalCycles));
|
||||||
else totalCyclesView.setText("");
|
else totalCyclesView.setText("");
|
||||||
|
|
||||||
// Update total tasks
|
// Update total tasks
|
||||||
int totalTasks = taskRecyclerViewAdapter.getItemCount();
|
int totalTasks = taskRecyclerViewAdapter.getItemCount();
|
||||||
TextView totalTasksView = 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);
|
View noMoreTasks = view.findViewById(R.id.no_more_tasks);
|
||||||
View createTasks = view.findViewById(R.id.create_tasks);
|
View createTasks = view.findViewById(R.id.create_tasks);
|
||||||
if (totalTasks == 0) {
|
if (totalTasks == 0) {
|
||||||
noMoreTasks.setVisibility(View.VISIBLE);
|
noMoreTasks.setVisibility(View.VISIBLE);
|
||||||
createTasks.setVisibility(View.VISIBLE);
|
createTasks.setVisibility(View.VISIBLE);
|
||||||
totalTasksView.setVisibility(View.GONE);
|
totalTasksView.setVisibility(View.GONE);
|
||||||
}
|
|
||||||
else {
|
|
||||||
noMoreTasks.setVisibility(View.GONE);
|
|
||||||
createTasks.setVisibility(View.GONE);
|
|
||||||
totalTasksView.setVisibility(View.VISIBLE);
|
|
||||||
totalTasksView.setText(resources.getQuantityString(R.plurals.task_total, totalTasks, totalTasks));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
noMoreTasks.setVisibility(View.GONE);
|
||||||
|
createTasks.setVisibility(View.GONE);
|
||||||
|
totalTasksView.setVisibility(View.VISIBLE);
|
||||||
|
totalTasksView.setText(resources1.getQuantityString(R.plurals.task_total, totalTasks, totalTasks));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
//recyclerView.addItemDecoration(new DividerItemDecoration(getActivity()));
|
//recyclerView.addItemDecoration(new DividerItemDecoration(getActivity()));
|
||||||
@@ -235,15 +230,9 @@ public class TasksFragment extends Fragment implements
|
|||||||
|
|
||||||
// Set system settings
|
// Set system settings
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT -> editor.putBoolean("pref_conf_done", false);
|
||||||
editor.putBoolean("pref_conf_done", false);
|
case ItemTouchHelper.RIGHT -> editor.putBoolean("pref_conf_next", false);
|
||||||
break;
|
case -1 -> editor.putBoolean("pref_conf_del", false);
|
||||||
case ItemTouchHelper.RIGHT:
|
|
||||||
editor.putBoolean("pref_conf_next", false);
|
|
||||||
break;
|
|
||||||
case -1:
|
|
||||||
editor.putBoolean("pref_conf_del", false);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
editor.apply();
|
editor.apply();
|
||||||
}
|
}
|
||||||
@@ -344,10 +333,8 @@ public class TasksFragment extends Fragment implements
|
|||||||
confirmArgs.putInt("ItemPosition", itemPosition);
|
confirmArgs.putInt("ItemPosition", itemPosition);
|
||||||
confirmArgs.putInt("Direction", -1);
|
confirmArgs.putInt("Direction", -1);
|
||||||
confirmDialogFragment.setArguments(confirmArgs);
|
confirmDialogFragment.setArguments(confirmArgs);
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getParentFragmentManager();
|
||||||
if (fragmentManager != null) {
|
confirmDialogFragment.show(fragmentManager, title);
|
||||||
confirmDialogFragment.show(fragmentManager, title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PerformTaskAction(itemPosition, -1);
|
PerformTaskAction(itemPosition, -1);
|
||||||
@@ -361,20 +348,19 @@ public class TasksFragment extends Fragment implements
|
|||||||
boolean showDialog = false;
|
boolean showDialog = false;
|
||||||
int buttonLabel = -1;
|
int buttonLabel = -1;
|
||||||
|
|
||||||
switch (direction)
|
switch (direction) {
|
||||||
{
|
|
||||||
// Mark item as Done
|
// Mark item as Done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT -> {
|
||||||
title = getResources().getString(R.string.task_confirmation_done_text);
|
title = getResources().getString(R.string.task_confirmation_done_text);
|
||||||
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
||||||
buttonLabel = R.string.task_confirmation_done_button;
|
buttonLabel = R.string.task_confirmation_done_button;
|
||||||
break;
|
}
|
||||||
// Increase task cycle count
|
// Increase task cycle count
|
||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT -> {
|
||||||
title = getResources().getString(R.string.task_confirmation_next_text);
|
title = getResources().getString(R.string.task_confirmation_next_text);
|
||||||
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
||||||
buttonLabel = R.string.task_confirmation_next_button;
|
buttonLabel = R.string.task_confirmation_next_button;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
if (showDialog) {
|
if (showDialog) {
|
||||||
ConfirmDialogFragment confirmDialogFragment =
|
ConfirmDialogFragment confirmDialogFragment =
|
||||||
@@ -385,10 +371,8 @@ public class TasksFragment extends Fragment implements
|
|||||||
args.putInt("ItemPosition", itemPosition);
|
args.putInt("ItemPosition", itemPosition);
|
||||||
args.putInt("Direction", direction);
|
args.putInt("Direction", direction);
|
||||||
confirmDialogFragment.setArguments(args);
|
confirmDialogFragment.setArguments(args);
|
||||||
FragmentManager fragmentManager = getFragmentManager();
|
FragmentManager fragmentManager = getParentFragmentManager();
|
||||||
if (fragmentManager != null) {
|
confirmDialogFragment.show(fragmentManager, title);
|
||||||
confirmDialogFragment.show(fragmentManager, title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else PerformTaskAction(itemPosition, direction);
|
else PerformTaskAction(itemPosition, direction);
|
||||||
}
|
}
|
||||||
@@ -402,50 +386,46 @@ public class TasksFragment extends Fragment implements
|
|||||||
|
|
||||||
taskRecyclerViewAdapter.remove(itemPosition);
|
taskRecyclerViewAdapter.remove(itemPosition);
|
||||||
|
|
||||||
switch (direction)
|
switch (direction) {
|
||||||
{
|
|
||||||
// Mark item as Done
|
// Mark item as Done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT ->
|
||||||
action = resources.getString(R.string.snackabar_action_done);
|
action = resources.getString(R.string.snackabar_action_done);
|
||||||
break;
|
|
||||||
// Increase task cycle count
|
// Increase task cycle count
|
||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT -> {
|
||||||
action = resources.getString(R.string.snackabar_action_next);
|
action = resources.getString(R.string.snackabar_action_next);
|
||||||
task.setCycle(task.getCycle() + 1);
|
task.setCycle(task.getCycle() + 1);
|
||||||
taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount());
|
taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount());
|
||||||
break;
|
}
|
||||||
case -1:
|
case -1 -> {
|
||||||
FragmentManager manager = getFragmentManager();
|
FragmentManager manager = getParentFragmentManager();
|
||||||
DialogFragment dialog = (DialogFragment) Objects.requireNonNull(manager).findFragmentByTag(getString(R.string.action_edit_task));
|
DialogFragment dialog = (DialogFragment) Objects.requireNonNull(manager).findFragmentByTag(getString(R.string.action_edit_task));
|
||||||
if (dialog != null) dialog.dismiss();
|
if (dialog != null) dialog.dismiss();
|
||||||
action = resources.getString(R.string.snackabar_action_deleted);
|
action = resources.getString(R.string.snackabar_action_deleted);
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup the snack bar
|
// Setup the snack bar
|
||||||
View parentView = Objects.requireNonNull(getActivity()).findViewById(R.id.main_content);
|
View parentView = requireActivity().findViewById(R.id.main_content);
|
||||||
snackbar = Snackbar.make(parentView, resources.getString(R.string.snackabar_label, action), Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(parentView, resources.getString(R.string.snackabar_label, action), Snackbar.LENGTH_LONG)
|
||||||
.setAction(resources.getString(R.string.snackabar_button), new View.OnClickListener() {
|
.setAction(resources.getString(R.string.snackabar_button), v -> {
|
||||||
@Override
|
// Undo adapter changes
|
||||||
public void onClick(View v) {
|
switch (direction) {
|
||||||
// Undo adapter changes
|
// Nothing special to do for done
|
||||||
switch (direction) {
|
case ItemTouchHelper.LEFT:
|
||||||
// Nothing special to do for done
|
break;
|
||||||
case ItemTouchHelper.LEFT:
|
// Remove the last item
|
||||||
break;
|
case ItemTouchHelper.RIGHT:
|
||||||
// Remove the last item
|
taskRecyclerViewAdapter.remove(taskRecyclerViewAdapter.getItemCount() - 1);
|
||||||
case ItemTouchHelper.RIGHT:
|
task.setCycle(task.getCycle() - 1);
|
||||||
taskRecyclerViewAdapter.remove(taskRecyclerViewAdapter.getItemCount() - 1);
|
break;
|
||||||
task.setCycle(task.getCycle() - 1);
|
// Nothing special to do for delete
|
||||||
break;
|
case -1:
|
||||||
// Nothing special to do for delete
|
break;
|
||||||
case -1:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Reset the first item
|
|
||||||
taskRecyclerViewAdapter.add(task, itemPosition);
|
|
||||||
recyclerView.scrollToPosition(0);
|
|
||||||
}
|
}
|
||||||
|
// Reset the first item
|
||||||
|
taskRecyclerViewAdapter.add(task, itemPosition);
|
||||||
|
recyclerView.scrollToPosition(0);
|
||||||
});
|
});
|
||||||
snackbar.addCallback(new Snackbar.Callback() {
|
snackbar.addCallback(new Snackbar.Callback() {
|
||||||
@Override
|
@Override
|
||||||
@@ -458,17 +438,16 @@ public class TasksFragment extends Fragment implements
|
|||||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) {
|
try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) {
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
// Mark item as Done
|
// Mark item as Done
|
||||||
case ItemTouchHelper.LEFT:
|
case ItemTouchHelper.LEFT -> taskDataAccess.setDone(itemId, isTodayView);
|
||||||
taskDataAccess.setDone(itemId, isTodayView);
|
|
||||||
break;
|
|
||||||
// Increase task cycle count
|
// Increase task cycle count
|
||||||
case ItemTouchHelper.RIGHT:
|
case ItemTouchHelper.RIGHT -> {
|
||||||
taskDataAccess.increaseCycle(task, isTodayView);
|
taskDataAccess.increaseCycle(task, isTodayView);
|
||||||
taskRecyclerViewAdapter.notifyItemChanged(taskRecyclerViewAdapter.getItemCount() - 1);
|
taskRecyclerViewAdapter.notifyItemChanged(taskRecyclerViewAdapter.getItemCount() - 1);
|
||||||
break;
|
}
|
||||||
case -1:
|
case -1 ->
|
||||||
// Delete the task
|
// Delete the task
|
||||||
taskDataAccess.deleteTask(itemId, isTodayView);
|
taskDataAccess.deleteTask(itemId, isTodayView);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,6 @@ import androidx.annotation.Nullable;
|
|||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
@@ -21,7 +20,6 @@ import org.joda.time.LocalDate;
|
|||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by bg45 on 2017-03-21.
|
* Created by bg45 on 2017-03-21.
|
||||||
@@ -61,21 +59,18 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
|||||||
private void setLayoutValues(List<Task> tasks) {
|
private void setLayoutValues(List<Task> tasks) {
|
||||||
EditText editText = findViewById(R.id.today_search);
|
EditText editText = findViewById(R.id.today_search);
|
||||||
final ListView listView = findViewById(R.id.today_tasks);
|
final ListView listView = findViewById(R.id.today_tasks);
|
||||||
final TodayArrayAdapter adapter = new TodayArrayAdapter(Objects.requireNonNull(getActivity()), tasks);
|
final TodayArrayAdapter adapter = new TodayArrayAdapter(requireActivity(), tasks);
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
listView.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
@Override
|
// Set Today date for the task
|
||||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
Task task = adapter.getItem(position);
|
||||||
// Set Today date for the task
|
if (task == null) return;
|
||||||
Task task = adapter.getItem(position);
|
task.setTodayDate(task.isToday() ? "" : LocalDate.now().toString());
|
||||||
if (task == null) return;
|
// Maintain a list of actually updated tasks to commit to DB
|
||||||
task.setTodayDate(task.isToday() ? "" : LocalDate.now().toString());
|
if (!mUpdatedTasks.contains(task)) mUpdatedTasks.add(task);
|
||||||
// Maintain a list of actually updated tasks to commit to DB
|
else mUpdatedTasks.remove(task);
|
||||||
if (!mUpdatedTasks.contains(task)) mUpdatedTasks.add(task);
|
// Refresh the view
|
||||||
else mUpdatedTasks.remove(task);
|
adapter.notifyDataSetChanged();
|
||||||
// Refresh the view
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
editText.addTextChangedListener(new TextWatcher() {
|
editText.addTextChangedListener(new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
@@ -114,7 +109,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static class LoadTasks extends AsyncTask<Context, Void, List<Task>> {
|
static class LoadTasks extends AsyncTask<Context, Void, List<Task>> {
|
||||||
private WeakReference<TodayFormDialogFragment> fragmentReference;
|
private final WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||||
|
|
||||||
LoadTasks(TodayFormDialogFragment context) {
|
LoadTasks(TodayFormDialogFragment context) {
|
||||||
fragmentReference = new WeakReference<>(context);
|
fragmentReference = new WeakReference<>(context);
|
||||||
@@ -135,7 +130,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class UpdateTasks extends AsyncTask<Task, Void, Integer> {
|
private static class UpdateTasks extends AsyncTask<Task, Void, Integer> {
|
||||||
private WeakReference<TodayFormDialogFragment> fragmentReference;
|
private final WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||||
|
|
||||||
UpdateTasks(TodayFormDialogFragment context) {
|
UpdateTasks(TodayFormDialogFragment context) {
|
||||||
fragmentReference = new WeakReference<>(context);
|
fragmentReference = new WeakReference<>(context);
|
||||||
|
Reference in New Issue
Block a user