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">
|
||||
<value>
|
||||
<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>
|
||||
</value>
|
||||
</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">
|
||||
<component name="NullableNotNullManager">
|
||||
<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">
|
||||
<value>
|
||||
<list size="14">
|
||||
<list size="16">
|
||||
<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="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="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="14" class="java.lang.String" itemvalue="org.jspecify.nullness.Nullable" />
|
||||
<item index="15" class="java.lang.String" itemvalue="jakarta.annotation.Nullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="14">
|
||||
<list size="16">
|
||||
<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="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="12" class="java.lang.String" itemvalue="io.reactivex.rxjava3.annotations.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>
|
||||
</value>
|
||||
</option>
|
||||
|
@@ -4,13 +4,14 @@ import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
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.MenuItem;
|
||||
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.analytics.Analytics;
|
||||
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));
|
||||
}
|
||||
|
||||
private ViewPager getMainFragmentViewPager(){
|
||||
private ViewPager getMainFragmentViewPager() {
|
||||
FragmentManager manager = getSupportFragmentManager();
|
||||
MainFragment fragment = (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
||||
return fragment != null ? fragment.getViewPager() : null;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
package com.wismna.geoffroy.donext.adapters;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
|
||||
import com.wismna.geoffroy.donext.dao.TaskList;
|
||||
import com.wismna.geoffroy.donext.fragments.TasksFragment;
|
||||
@@ -10,18 +10,19 @@ import com.wismna.geoffroy.donext.fragments.TasksFragment;
|
||||
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.
|
||||
*/
|
||||
public class SectionsPagerAdapter extends SmartFragmentStatePagerAdapter {
|
||||
|
||||
private List<TaskList> taskLists;
|
||||
private final List<TaskList> taskLists;
|
||||
|
||||
public SectionsPagerAdapter(FragmentManager fm, List<TaskList> taskLists) {
|
||||
super(fm);
|
||||
this.taskLists = taskLists;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
// 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
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public class Task {
|
||||
private long id;
|
||||
private String name;
|
||||
|
@@ -7,7 +7,6 @@ import androidx.annotation.NonNull;
|
||||
* Data access object class that represents a Task List
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
public class TaskList {
|
||||
private long id;
|
||||
private String name;
|
||||
|
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
* Created by geoffroy on 15-11-27.
|
||||
* Data access class that handles Tasks
|
||||
*/
|
||||
@Deprecated
|
||||
public class TaskDataAccess implements AutoCloseable {
|
||||
public enum MODE {
|
||||
READ,
|
||||
|
@@ -14,7 +14,6 @@ import java.util.List;
|
||||
* Created by geoffroy on 15-11-25.
|
||||
* Data access class that handles Task Lists
|
||||
*/
|
||||
@Deprecated
|
||||
public class TaskListDataAccess implements AutoCloseable {
|
||||
public enum MODE {
|
||||
READ,
|
||||
|
@@ -3,16 +3,15 @@ package com.wismna.geoffroy.donext.fragments;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
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.LayoutInflater;
|
||||
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 {
|
||||
interface ConfirmDialogListener {
|
||||
@@ -33,7 +32,7 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
public void onCancel(@NonNull DialogInterface dialog) {
|
||||
super.onCancel(dialog);
|
||||
|
||||
// Allows refreshing the first item of the adapter
|
||||
@@ -43,7 +42,7 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
@NonNull
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(Objects.requireNonNull(getActivity()));
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
|
||||
|
||||
Bundle args = getArguments();
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
@@ -51,23 +50,12 @@ public class ConfirmDialogFragment extends DialogFragment {
|
||||
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) {
|
||||
confirmDialogListener.onConfirmDialogClick(ConfirmDialogFragment.this, ButtonEvent.YES);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.task_confirmation_no_button, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
.setPositiveButton(args.getInt("button"), (dialog, id) -> confirmDialogListener.onConfirmDialogClick(ConfirmDialogFragment.this, ButtonEvent.YES))
|
||||
.setNegativeButton(R.string.task_confirmation_no_button, (dialog, 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;
|
||||
}
|
||||
});
|
||||
.setOnKeyListener((dialog, keyCode, event) -> keyCode != KeyEvent.KEYCODE_BACK);
|
||||
// Create the AlertDialog object and return it
|
||||
Dialog dialog = builder.create();
|
||||
dialog.setCanceledOnTouchOutside(true);
|
||||
|
@@ -4,7 +4,6 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -76,27 +75,16 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
// Add action buttons
|
||||
builder.setView(view)
|
||||
.setNegativeButton(mNegativeButtonString, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
.setNegativeButton(mNegativeButtonString, (dialog, id) -> {
|
||||
// Send the negative button event back to the host activity
|
||||
// Canceled creation, nothing to do
|
||||
onNegativeButtonClick();
|
||||
}
|
||||
});
|
||||
if (mButtonCount >= 2) {
|
||||
builder.setPositiveButton(mPositiveButtonString, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
onPositiveButtonClick(view);
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton(mPositiveButtonString, (dialog, id) -> onPositiveButtonClick(view));
|
||||
}
|
||||
if (mButtonCount == 3) {
|
||||
builder.setNeutralButton(mNeutralButtonString, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onNeutralButtonClick(view);
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton(mNeutralButtonString, (dialog, which) -> onNeutralButtonClick(view));
|
||||
}
|
||||
setToolbarTitle(view);
|
||||
insertContentView(view, inflater);
|
||||
@@ -104,13 +92,13 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
|
||||
menu.clear();
|
||||
Objects.requireNonNull(getActivity()).getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu);
|
||||
requireActivity().getMenuInflater().inflate(R.menu.menu_dynamic_fragment, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
/*switch (mButtonCount) {
|
||||
case 1:
|
||||
menu.removeItem(R.id.menu_positive_button);
|
||||
@@ -148,7 +136,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
|
||||
// Hide the keyboard if present
|
||||
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;
|
||||
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*/
|
||||
protected <T extends View> T findViewById(int 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();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
@@ -6,22 +6,22 @@ import android.graphics.Point;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
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.activities.HistoryActivity;
|
||||
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
|
||||
// primary sections of the activity.
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), taskLists);
|
||||
mSectionsPagerAdapter = new SectionsPagerAdapter(getParentFragmentManager(), taskLists);
|
||||
mSectionsPagerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -145,12 +145,7 @@ public class MainFragment extends Fragment implements
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
toggleTabLayoutArrows(tabLayout.getScrollX());
|
||||
//tabLayout.setScrollIndicators(TabLayout.SCROLL_INDICATOR_LEFT | TabLayout.SCROLL_INDICATOR_RIGHT);
|
||||
tabLayout.setOnScrollChangeListener(new View.OnScrollChangeListener() {
|
||||
@Override
|
||||
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
|
||||
toggleTabLayoutArrows(scrollX);
|
||||
}
|
||||
});
|
||||
tabLayout.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY) -> toggleTabLayoutArrows(scrollX));
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -164,12 +159,7 @@ public class MainFragment extends Fragment implements
|
||||
// Hide the list if there is only one task list
|
||||
listView.setAdapter(new ArrayAdapter<>(activity, R.layout.list_tasklist_item, taskLists));
|
||||
//listView.setSelection(lastOpenedList);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
mViewPager.setCurrentItem(position);
|
||||
}
|
||||
});
|
||||
listView.setOnItemClickListener((parent, view, position, id) -> mViewPager.setCurrentItem(position));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,18 +2,18 @@ package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.activities.HistoryActivity;
|
||||
import com.wismna.geoffroy.donext.dao.Task;
|
||||
@@ -66,7 +66,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
mButtonCount = args.getInt("button_count");
|
||||
mPositiveButtonString = getString(R.string.new_task_save);
|
||||
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");
|
||||
isToday = args.getBoolean("today");
|
||||
}
|
||||
@@ -141,12 +141,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
final DatePicker dueDatePicker = findViewById(R.id.new_task_due_date);
|
||||
// Handle due date spinner depending on check box
|
||||
CheckBox setDueDate = findViewById(R.id.new_task_due_date_set);
|
||||
setDueDate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
dueDatePicker.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
setDueDate.setOnCheckedChangeListener((buttonView, isChecked) -> dueDatePicker.setVisibility(isChecked ? View.VISIBLE : View.GONE));
|
||||
|
||||
// Handle priority changes
|
||||
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.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* A fragment representing a list of Items.
|
||||
@@ -71,9 +70,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Button createTaskListButton = findViewById(R.id.new_task_list_button);
|
||||
createTaskListButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
createTaskListButton.setOnClickListener(v -> {
|
||||
EditText editText = findViewById(R.id.new_task_list_name);
|
||||
String text = editText.getText().toString();
|
||||
if (text.matches("")) {
|
||||
@@ -87,7 +84,6 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
|
||||
editText.setText("");
|
||||
toggleVisibleCreateNewTaskListLayout();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -127,7 +123,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
int taskListCount = taskListRecyclerViewAdapter.getItemCount();
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
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);
|
||||
else layout.setVisibility(View.VISIBLE);
|
||||
clearFocus();
|
||||
@@ -152,7 +148,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
args.putInt("ItemPosition", position);
|
||||
args.putLong("ItemId", id);
|
||||
confirmDialogFragment.setArguments(args);
|
||||
confirmDialogFragment.show(Objects.requireNonNull(getFragmentManager()), title);
|
||||
confirmDialogFragment.show(getParentFragmentManager(), title);
|
||||
}
|
||||
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 WeakReference<TaskListsDialogFragment> fragmentReference;
|
||||
private final WeakReference<TaskListsDialogFragment> fragmentReference;
|
||||
|
||||
GetTaskListsTask(TaskListsDialogFragment context) {
|
||||
fragmentReference = new WeakReference<>(context);
|
||||
|
@@ -6,20 +6,9 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
@@ -27,6 +16,17 @@ import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
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.activities.HistoryActivity;
|
||||
import com.wismna.geoffroy.donext.activities.TodayActivity;
|
||||
@@ -92,7 +92,6 @@ public class TasksFragment extends Fragment implements
|
||||
Activity parentActivity = getActivity();
|
||||
if (parentActivity instanceof HistoryActivity) isHistory = true;
|
||||
if (parentActivity instanceof TodayActivity) isTodayView = true;
|
||||
mAdapter = (MainFragment)getParentFragment();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,6 +100,10 @@ public class TasksFragment extends Fragment implements
|
||||
view = inflater.inflate(R.layout.fragment_tasks, container, false);
|
||||
final Context context = view.getContext();
|
||||
|
||||
// TODO: is null...
|
||||
FragmentManager manager = getParentFragmentManager();
|
||||
mAdapter = (MainFragment)manager.findFragmentById(R.id.fragment_main);
|
||||
|
||||
// Set the Recycler view
|
||||
recyclerView = view.findViewById(R.id.task_list_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
@@ -125,9 +128,7 @@ public class TasksFragment extends Fragment implements
|
||||
final Resources resources = getResources();
|
||||
// Implements touch listener to add click detection
|
||||
recyclerView.addOnItemTouchListener(
|
||||
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(View view, int position) {
|
||||
new RecyclerItemClickListener(context, (view, position) -> {
|
||||
boolean isLargeLayout = resources.getBoolean(R.bool.large_layout);
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
Bundle args = new Bundle();
|
||||
@@ -140,7 +141,7 @@ public class TasksFragment extends Fragment implements
|
||||
args.putInt("position", position);
|
||||
|
||||
// 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;
|
||||
Task task = taskRecyclerViewAdapter.getItem(position);
|
||||
if (viewPager != null) {
|
||||
@@ -160,32 +161,27 @@ public class TasksFragment extends Fragment implements
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
// Handle updating total counts in a listener to be sure that the layout is available
|
||||
recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
recyclerView.getViewTreeObserver().addOnPreDrawListener(() -> {
|
||||
// isAdded is tested to prevent an IllegalStateException when fast switching between tabs
|
||||
if (!isAdded()) return true;
|
||||
Resources resources = getResources();
|
||||
Resources resources1 = getResources();
|
||||
|
||||
// Update total cycle count
|
||||
int totalCycles = taskRecyclerViewAdapter.getCycleCount();
|
||||
TextView totalCyclesView = view.findViewById(R.id.total_task_cycles);
|
||||
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("");
|
||||
|
||||
// Update total tasks
|
||||
@@ -202,11 +198,10 @@ public class TasksFragment extends Fragment implements
|
||||
noMoreTasks.setVisibility(View.GONE);
|
||||
createTasks.setVisibility(View.GONE);
|
||||
totalTasksView.setVisibility(View.VISIBLE);
|
||||
totalTasksView.setText(resources.getQuantityString(R.plurals.task_total, totalTasks, totalTasks));
|
||||
totalTasksView.setText(resources1.getQuantityString(R.plurals.task_total, totalTasks, totalTasks));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
//recyclerView.addItemDecoration(new DividerItemDecoration(getActivity()));
|
||||
@@ -235,15 +230,9 @@ public class TasksFragment extends Fragment implements
|
||||
|
||||
// Set system settings
|
||||
switch (direction) {
|
||||
case ItemTouchHelper.LEFT:
|
||||
editor.putBoolean("pref_conf_done", false);
|
||||
break;
|
||||
case ItemTouchHelper.RIGHT:
|
||||
editor.putBoolean("pref_conf_next", false);
|
||||
break;
|
||||
case -1:
|
||||
editor.putBoolean("pref_conf_del", false);
|
||||
break;
|
||||
case ItemTouchHelper.LEFT -> editor.putBoolean("pref_conf_done", false);
|
||||
case ItemTouchHelper.RIGHT -> editor.putBoolean("pref_conf_next", false);
|
||||
case -1 -> editor.putBoolean("pref_conf_del", false);
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
@@ -344,11 +333,9 @@ public class TasksFragment extends Fragment implements
|
||||
confirmArgs.putInt("ItemPosition", itemPosition);
|
||||
confirmArgs.putInt("Direction", -1);
|
||||
confirmDialogFragment.setArguments(confirmArgs);
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
confirmDialogFragment.show(fragmentManager, title);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PerformTaskAction(itemPosition, -1);
|
||||
}
|
||||
@@ -361,20 +348,19 @@ public class TasksFragment extends Fragment implements
|
||||
boolean showDialog = false;
|
||||
int buttonLabel = -1;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
switch (direction) {
|
||||
// Mark item as Done
|
||||
case ItemTouchHelper.LEFT:
|
||||
case ItemTouchHelper.LEFT -> {
|
||||
title = getResources().getString(R.string.task_confirmation_done_text);
|
||||
showDialog = sharedPref.getBoolean("pref_conf_done", true);
|
||||
buttonLabel = R.string.task_confirmation_done_button;
|
||||
break;
|
||||
}
|
||||
// Increase task cycle count
|
||||
case ItemTouchHelper.RIGHT:
|
||||
case ItemTouchHelper.RIGHT -> {
|
||||
title = getResources().getString(R.string.task_confirmation_next_text);
|
||||
showDialog = sharedPref.getBoolean("pref_conf_next", true);
|
||||
buttonLabel = R.string.task_confirmation_next_button;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (showDialog) {
|
||||
ConfirmDialogFragment confirmDialogFragment =
|
||||
@@ -385,11 +371,9 @@ public class TasksFragment extends Fragment implements
|
||||
args.putInt("ItemPosition", itemPosition);
|
||||
args.putInt("Direction", direction);
|
||||
confirmDialogFragment.setArguments(args);
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
FragmentManager fragmentManager = getParentFragmentManager();
|
||||
confirmDialogFragment.show(fragmentManager, title);
|
||||
}
|
||||
}
|
||||
else PerformTaskAction(itemPosition, direction);
|
||||
}
|
||||
|
||||
@@ -402,32 +386,29 @@ public class TasksFragment extends Fragment implements
|
||||
|
||||
taskRecyclerViewAdapter.remove(itemPosition);
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
switch (direction) {
|
||||
// Mark item as Done
|
||||
case ItemTouchHelper.LEFT:
|
||||
case ItemTouchHelper.LEFT ->
|
||||
action = resources.getString(R.string.snackabar_action_done);
|
||||
break;
|
||||
|
||||
// Increase task cycle count
|
||||
case ItemTouchHelper.RIGHT:
|
||||
case ItemTouchHelper.RIGHT -> {
|
||||
action = resources.getString(R.string.snackabar_action_next);
|
||||
task.setCycle(task.getCycle() + 1);
|
||||
taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount());
|
||||
break;
|
||||
case -1:
|
||||
FragmentManager manager = getFragmentManager();
|
||||
}
|
||||
case -1 -> {
|
||||
FragmentManager manager = getParentFragmentManager();
|
||||
DialogFragment dialog = (DialogFragment) Objects.requireNonNull(manager).findFragmentByTag(getString(R.string.action_edit_task));
|
||||
if (dialog != null) dialog.dismiss();
|
||||
action = resources.getString(R.string.snackabar_action_deleted);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 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)
|
||||
.setAction(resources.getString(R.string.snackabar_button), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
.setAction(resources.getString(R.string.snackabar_button), v -> {
|
||||
// Undo adapter changes
|
||||
switch (direction) {
|
||||
// Nothing special to do for done
|
||||
@@ -445,7 +426,6 @@ public class TasksFragment extends Fragment implements
|
||||
// Reset the first item
|
||||
taskRecyclerViewAdapter.add(task, itemPosition);
|
||||
recyclerView.scrollToPosition(0);
|
||||
}
|
||||
});
|
||||
snackbar.addCallback(new Snackbar.Callback() {
|
||||
@Override
|
||||
@@ -458,15 +438,14 @@ public class TasksFragment extends Fragment implements
|
||||
try (TaskDataAccess taskDataAccess = new TaskDataAccess(view.getContext(), TaskDataAccess.MODE.WRITE)) {
|
||||
switch (direction) {
|
||||
// Mark item as Done
|
||||
case ItemTouchHelper.LEFT:
|
||||
taskDataAccess.setDone(itemId, isTodayView);
|
||||
break;
|
||||
case ItemTouchHelper.LEFT -> taskDataAccess.setDone(itemId, isTodayView);
|
||||
|
||||
// Increase task cycle count
|
||||
case ItemTouchHelper.RIGHT:
|
||||
case ItemTouchHelper.RIGHT -> {
|
||||
taskDataAccess.increaseCycle(task, isTodayView);
|
||||
taskRecyclerViewAdapter.notifyItemChanged(taskRecyclerViewAdapter.getItemCount() - 1);
|
||||
break;
|
||||
case -1:
|
||||
}
|
||||
case -1 ->
|
||||
// Delete the task
|
||||
taskDataAccess.deleteTask(itemId, isTodayView);
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@ import androidx.annotation.Nullable;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListView;
|
||||
|
||||
@@ -21,7 +20,6 @@ import org.joda.time.LocalDate;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Created by bg45 on 2017-03-21.
|
||||
@@ -61,11 +59,9 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
private void setLayoutValues(List<Task> tasks) {
|
||||
EditText editText = findViewById(R.id.today_search);
|
||||
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.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
listView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
// Set Today date for the task
|
||||
Task task = adapter.getItem(position);
|
||||
if (task == null) return;
|
||||
@@ -75,7 +71,6 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
else mUpdatedTasks.remove(task);
|
||||
// Refresh the view
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
editText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
@@ -114,7 +109,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
}
|
||||
|
||||
static class LoadTasks extends AsyncTask<Context, Void, List<Task>> {
|
||||
private WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||
private final WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||
|
||||
LoadTasks(TodayFormDialogFragment context) {
|
||||
fragmentReference = new WeakReference<>(context);
|
||||
@@ -135,7 +130,7 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
}
|
||||
|
||||
private static class UpdateTasks extends AsyncTask<Task, Void, Integer> {
|
||||
private WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||
private final WeakReference<TodayFormDialogFragment> fragmentReference;
|
||||
|
||||
UpdateTasks(TodayFormDialogFragment context) {
|
||||
fragmentReference = new WeakReference<>(context);
|
||||
|
Reference in New Issue
Block a user