Remove unused room code and references

Remove set and get retain instances since bug seems fixed
Update Settings activity
Code cleanup
This commit is contained in:
Geoffroy Bonneville
2023-12-21 16:22:52 +01:00
parent ce2c548e5b
commit 2c78ee88bc
23 changed files with 67 additions and 389 deletions

View File

@@ -9,11 +9,6 @@ android {
targetSdkVersion 34
versionCode 30
versionName "1.9"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
@@ -55,12 +50,6 @@ dependencies {
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
// Room components
def roomVersion = "2.6.1"
implementation "androidx.room:room-runtime:$roomVersion"
annotationProcessor "androidx.room:room-compiler:$roomVersion"
testImplementation "androidx.room:room-testing:$roomVersion"
// Lifecycle components
def lifecycleVersion = '2.6.2'
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycleVersion"

View File

@@ -12,6 +12,7 @@
<activity
android:name=".activities.MainActivity"
android:configChanges="screenSize|orientation"
android:theme="@style/AppTheme.NoActionBar"
android:exported="true">
<intent-filter>
@@ -31,6 +32,7 @@
<activity
android:name=".activities.TodayActivity"
android:label="@string/title_activity_today"
android:configChanges="screenSize|orientation"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
@@ -39,6 +41,7 @@
</activity>
<activity android:name=".activities.HistoryActivity"
android:label="@string/title_activity_history"
android:configChanges="screenSize|orientation"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data

View File

@@ -2,17 +2,10 @@ package com.wismna.geoffroy.donext;
import android.app.Application;
import net.danlew.android.joda.JodaTimeAndroid;
/**
* Created by bg45 on 2017-03-15.
* Application class, used to initialize Joda Time
*/
public class DoNext extends Application {
@Override
public void onCreate() {
super.onCreate();
JodaTimeAndroid.init(this);
}
}

View File

@@ -1,9 +1,11 @@
package com.wismna.geoffroy.donext.activities;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import com.wismna.geoffroy.donext.R;
@@ -14,19 +16,17 @@ public class SettingsActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
// Display the preferences fragment as the main content.
getFragmentManager().beginTransaction()
getSupportFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
}
public static class SettingsFragment extends PreferenceFragment {
public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
setPreferencesFromResource(R.xml.preferences, rootKey);
}
}
}

View File

@@ -1,7 +1,5 @@
package com.wismna.geoffroy.donext.adapters;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@@ -11,6 +9,9 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.dao.TaskList;
import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
@@ -56,42 +57,33 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
holder.mTaskNameView.setText(mValues.get(position).getName());
// TODO: correct this...
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mListener.onStartDrag(holder);
}
return false;
holder.handleView.setOnTouchListener((v, event) -> {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mListener.onStartDrag(holder);
}
return false;
});
// Handle inline name change
holder.mTaskNameView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText editText = (EditText) v;
String name = editText.getText().toString();
holder.mTaskNameView.setOnFocusChangeListener((v, hasFocus) -> {
EditText editText = (EditText) v;
String name = editText.getText().toString();
if (!hasFocus && !holder.mItem.getName().matches(name)) {
holder.mItem.setName(name);
if (!hasFocus && !holder.mItem.getName().matches(name)) {
holder.mItem.setName(name);
update(holder.mItem, holder.getAdapterPosition());
mListener.onEditTextLoseFocus(holder.mItem);
}
update(holder.mItem, holder.getBindingAdapterPosition());
mListener.onEditTextLoseFocus(holder.mItem);
}
});
// Handle click on delete button
holder.mTaskDeleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Disable the OnFocusChanged listener as it is now pointless and harmful
holder.mTaskNameView.setOnFocusChangeListener(null);
holder.mTaskDeleteButton.setOnClickListener(v -> {
// Disable the OnFocusChanged listener as it is now pointless and harmful
holder.mTaskNameView.setOnFocusChangeListener(null);
//remove(position);
mListener.onClickDeleteButton(holder.getAdapterPosition(), holder.mItem.getId());
}
//remove(position);
mListener.onClickDeleteButton(holder.getBindingAdapterPosition(), holder.mItem.getId());
});
}
@@ -136,7 +128,7 @@ public class TaskListRecyclerViewAdapter extends RecyclerView.Adapter<TaskListRe
return true;
}
class TaskViewHolder extends RecyclerView.ViewHolder {
static class TaskViewHolder extends RecyclerView.ViewHolder {
final View mView;
final ImageView handleView;
final TextView mTaskCountView;

View File

@@ -1,15 +1,17 @@
package com.wismna.geoffroy.donext.adapters;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.graphics.Typeface;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.wismna.geoffroy.donext.R;
import com.wismna.geoffroy.donext.dao.Task;
@@ -24,8 +26,8 @@ import java.util.List;
public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerViewAdapter.StandardViewHolder> {
private List<Task> mValues;
private boolean mIsToday;
private boolean mIsHistory;
private final boolean mIsToday;
private final boolean mIsHistory;
public TaskRecyclerViewAdapter(List<Task> items, boolean isToday, boolean isHistory) {
mValues = items;
@@ -56,17 +58,10 @@ public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerVi
}
// Set priority
switch (holder.mItem.getPriority())
{
case 0:
holder.mIconView.setImageResource(R.drawable.ic_low_priority_lightgray_24dp);
break;
case 2:
holder.mIconView.setImageResource(R.drawable.ic_priority_high_red_24dp);
break;
default:
holder.mIconView.setImageDrawable(null);
break;
switch (holder.mItem.getPriority()) {
case 0 -> holder.mIconView.setImageResource(R.drawable.ic_low_priority_lightgray_24dp);
case 2 -> holder.mIconView.setImageResource(R.drawable.ic_priority_high_red_24dp);
default -> holder.mIconView.setImageDrawable(null);
}
// Additional information will not be displayed in Today view
@@ -121,6 +116,7 @@ public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerVi
return count;
}
@SuppressLint("NotifyDataSetChanged")
public void setItems(List<Task> tasks) {
this.mValues = tasks;
notifyDataSetChanged();
@@ -130,7 +126,7 @@ public class TaskRecyclerViewAdapter extends RecyclerView.Adapter<TaskRecyclerVi
return mValues.get(position);
}
class StandardViewHolder extends RecyclerView.ViewHolder {
static class StandardViewHolder extends RecyclerView.ViewHolder {
final View mView;
final TextView mIdView;
final ImageView mIconView;

View File

@@ -1,32 +0,0 @@
package com.wismna.geoffroy.donext.data;
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
@Database(entities = {Task.class, TaskList.class}, views = {TodayTasksView.class}, version = 6)
@TypeConverters({Converters.class})
public abstract class AppDatabase extends RoomDatabase {
public abstract TaskDao taskDao();
public abstract TaskListDao taskListDao();
private static volatile AppDatabase INSTANCE;
public static AppDatabase getDatabase(final Context context) {
if (INSTANCE == null) {
synchronized (AppDatabase.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
AppDatabase.class, "donext.db")
.addMigrations(Migrations.MIGRATION_1_2, Migrations.MIGRATION_2_3,
Migrations.MIGRATION_3_4, Migrations.MIGRATION_4_6)
.build();
}
}
}
return INSTANCE;
}
}

View File

@@ -1,17 +0,0 @@
package com.wismna.geoffroy.donext.data;
import org.joda.time.LocalDate;
import androidx.room.TypeConverter;
public class Converters {
@TypeConverter
public static LocalDate fromDateString(String value) {
return LocalDate.parse(value);
}
@TypeConverter
public static String toLocalDate(LocalDate value) {
return value.toString();
}
}

View File

@@ -1,33 +0,0 @@
package com.wismna.geoffroy.donext.data;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
public class Migrations {
static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE tasklist ADD COLUMN displayorder INTEGER");
}
};
static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE tasklist ADD COLUMN visible INTEGER DEFAULT 1");
database.execSQL("ALTER TABLE tasks ADD COLUMN duedate DATE");
}
};
static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE tasks ADD COLUMN todaydate DATE");
}
};
static final Migration MIGRATION_4_6 = new Migration(4, 6) {
@Override
public void migrate(SupportSQLiteDatabase database) {
database.execSQL("ALTER TABLE tasks ADD COLUMN todayorder INTEGER");
}
};
}

View File

@@ -1,53 +0,0 @@
package com.wismna.geoffroy.donext.data;
import org.joda.time.LocalDate;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
@Entity(tableName = "tasks",
indices = {@Index("list")},
foreignKeys = @ForeignKey(entity = TaskList.class,
parentColumns = "_id",
childColumns = "list"))
public class Task {
@PrimaryKey(autoGenerate = true)
public long _id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "description")
public String description;
@ColumnInfo(name = "cycle")
public int cycle = 0;
@ColumnInfo(name = "priority")
public int priority = 1;
@ColumnInfo(name = "done")
public boolean done = false;
@ColumnInfo(name = "deleted")
public boolean deleted = false;
@ColumnInfo(name = "displayorder")
public int order;
@ColumnInfo(name = "todayorder")
public int todayOrder;
@ColumnInfo(name = "list")
public long taskList;
@ColumnInfo(name = "duedate")
public LocalDate dueDate;
@ColumnInfo(name = "todaydate")
public LocalDate todayDate;
}

View File

@@ -1,55 +0,0 @@
package com.wismna.geoffroy.donext.data;
import java.util.List;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
@Dao
public interface TaskDao {
@Insert()
void createTask (Task task);
@Update()
void updateTask (Task task);
@Query("SELECT " +
"tasks._id," +
"tasks.name," +
"tasks.todaydate," +
"tasklist.name AS tasklistname " +
" FROM tasks" +
" LEFT JOIN tasklist ON tasks.list = tasklist._id" +
" WHERE tasks.done = 0 AND tasks.deleted = 0")
LiveData<List<TodayTask>> getAllTasks();
@Query("SELECT * FROM tasks WHERE list = :id AND done = 0 AND deleted = 0")
LiveData<List<Task>> getAllTasksFromList(long id);
@Query("SELECT * FROM tasks WHERE list = :id AND done = 1 OR deleted = 1")
LiveData<List<Task>> getAllTasksFromHistoryList(long id);
// TODO: replace query with view
//@Query("SELECT * FROM todaytasksview WHERE done = 0 AND deleted = 0")
@Query("SELECT * FROM tasks WHERE todaydate = date('now','localtime') AND done = 0 AND deleted = 0")
LiveData<List<Task>> getTodayTasks();
// TODO: replace this with item count from recycle view
@Query("SELECT MAX(displayorder) FROM tasks WHERE list = :id")
int getMaxOrder(long id);
@Query("UPDATE tasks SET displayorder = displayorder - 1" +
" WHERE displayorder > (SELECT displayorder FROM tasks WHERE _id = :id)")
void updateRemainingRowsOrder(long id);
@Query("UPDATE tasks SET todayorder = todayorder - 1" +
" WHERE todayorder > (SELECT todayorder FROM tasks WHERE _id = :id)")
void updateRemainingRowsTodayOrder(long id);
@Query("UPDATE tasks SET deleted = 1 WHERE list = :id")
void deleteAllTasks(long id);
}

View File

@@ -1,25 +0,0 @@
package com.wismna.geoffroy.donext.data;
import androidx.annotation.NonNull;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity(tableName = "tasklist")
public class TaskList {
@PrimaryKey(autoGenerate = true)
public long _id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "visible")
public boolean visible = true;
@ColumnInfo(name = "displayorder")
public int order;
//@ColumnInfo(name = "taskcount")
public int taskCount;
}

View File

@@ -1,27 +0,0 @@
package com.wismna.geoffroy.donext.data;
import java.util.List;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
@Dao
public interface TaskListDao {
@Insert()
void createTaskList(TaskList taskList);
@Update()
void updateTaskList(TaskList taskList);
@Query("SELECT *,(SELECT COUNT(*) FROM tasks WHERE tasks.list = tasklist._id) AS taskcount" +
" FROM tasklist WHERE visible = 1 ORDER BY displayorder ASC ")
LiveData<List<TaskList>> getVisibleTaskLists();
@Query("SELECT *, (SELECT COUNT(*) FROM tasks WHERE tasks.list = tasklist._id AND (tasks.deleted = 1 OR tasks.done = 1)) AS taskcount" +
" FROM tasklist WHERE visible = 0 OR taskcount > 0 ORDER BY displayorder ASC ")
LiveData<List<TaskList>> getInvisibleTaskLists();
}

View File

@@ -1,20 +0,0 @@
package com.wismna.geoffroy.donext.data;
import org.joda.time.LocalDate;
import androidx.room.ColumnInfo;
import androidx.room.PrimaryKey;
public class TodayTask {
@PrimaryKey()
public long _id;
@ColumnInfo(name = "name")
public String name;
@ColumnInfo(name = "todaydate")
public LocalDate todayDate;
@ColumnInfo(name = "tasklistname")
public String taskListName;
}

View File

@@ -1,20 +0,0 @@
package com.wismna.geoffroy.donext.data;
import org.joda.time.LocalDate;
import androidx.room.DatabaseView;
@DatabaseView("SELECT * FROM tasks WHERE todaydate = date('now','localtime')")
public class TodayTasksView extends Task {
/*public long _id;
public String name;
public String description;
public int cycle;
public int priority;
public boolean done;
public boolean deleted;
public int order;
public int todayOrder;
public long taskList;
public LocalDate dueDate;*/
}

View File

@@ -117,14 +117,6 @@ public class TaskDataAccess implements AutoCloseable {
}
public List<Task> getAllTasksFromList(long id, boolean isHistory) {
// REMOVE THIS
/*ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelper.COLUMN_ORDER, 0);
database.update(DatabaseHelper.TASKS_TABLE_NAME, contentValues,
null, null);*/
// --
int history = isHistory ? 1 : 0;
Cursor cursor = database.query(DatabaseHelper.TASKS_TABLE_NAME, taskColumns,
DatabaseHelper.TASKS_COLUMN_LIST + " = " + id +

View File

@@ -13,6 +13,8 @@ import androidx.fragment.app.DialogFragment;
import com.wismna.geoffroy.donext.R;
import java.util.Objects;
public class ConfirmDialogFragment extends DialogFragment {
interface ConfirmDialogListener {
void onConfirmDialogClick(DialogFragment dialog, ButtonEvent event);
@@ -27,7 +29,6 @@ public class ConfirmDialogFragment extends DialogFragment {
public static ConfirmDialogFragment newInstance(ConfirmDialogListener confirmDialogListener) {
ConfirmDialogFragment fragment = new ConfirmDialogFragment();
fragment.confirmDialogListener = confirmDialogListener;
fragment.setRetainInstance(true);
return fragment;
}
@@ -45,7 +46,7 @@ public class ConfirmDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity());
Bundle args = getArguments();
LayoutInflater inflater = getActivity().getLayoutInflater();
LayoutInflater inflater = requireActivity().getLayoutInflater();
// No need for a parent in a Dialog Fragment
View view = inflater.inflate(R.layout.fragment_task_confirmation, null);
assert args != null;
@@ -53,7 +54,7 @@ public class ConfirmDialogFragment extends DialogFragment {
.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();
Objects.requireNonNull(ConfirmDialogFragment.this.getDialog()).cancel();
})
.setOnKeyListener((dialog, keyCode, event) -> keyCode != KeyEvent.KEYCODE_BACK);
// Create the AlertDialog object and return it
@@ -65,9 +66,7 @@ public class ConfirmDialogFragment extends DialogFragment {
@Override
public void onDestroyView() {
Dialog dialog = getDialog();
// Stop the dialog from being dismissed on rotation, due to a bug with the compatibility library
// https://code.google.com/p/android/issues/detail?id=17423
if (dialog != null && getRetainInstance()) {
if (dialog != null) {
dialog.setDismissMessage(null);
}
super.onDestroyView();

View File

@@ -5,14 +5,6 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -22,6 +14,15 @@ import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.wismna.geoffroy.donext.R;
import java.util.Objects;
@@ -162,9 +163,7 @@ public abstract class DynamicDialogFragment extends DialogFragment {
@Override
public void onDestroyView() {
Dialog dialog = getDialog();
// Stop the dialog from being dismissed on rotation, due to a bug with the compatibility library
// https://code.google.com/p/android/issues/detail?id=17423
if (dialog != null && getRetainInstance()) {
if (dialog != null) {
dialog.setDismissMessage(null);
}
super.onDestroyView();
@@ -188,7 +187,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);
if (getShowsDialog()) return Objects.requireNonNull(getDialog()).findViewById(id);
return requireView().findViewById(id);
}

View File

@@ -53,7 +53,6 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
fragment.mTask = task;
fragment.taskLists = taskLists;
fragment.mListener = newTaskListener;
fragment.setRetainInstance(true);
return fragment;
}

View File

@@ -23,6 +23,7 @@ import com.wismna.geoffroy.donext.helpers.TaskListTouchHelper;
import com.wismna.geoffroy.donext.utils.TaskRunner;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Callable;
/**
@@ -174,7 +175,7 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
@Override
public void onConfirmDialogClick(DialogFragment dialog, ConfirmDialogFragment.ButtonEvent event) {
// Handle never ask again checkbox
CheckBox neverAskAgainCheckBox = dialog.getDialog().findViewById(R.id.task_confirmation_never);
CheckBox neverAskAgainCheckBox = Objects.requireNonNull(dialog.getDialog()).findViewById(R.id.task_confirmation_never);
if (neverAskAgainCheckBox.isChecked()) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext());

View File

@@ -78,7 +78,6 @@ public class TasksFragment extends Fragment implements
Bundle args = new Bundle();
args.putLong(TASK_LIST_ID, taskListId);
fragment.setArguments(args);
fragment.setRetainInstance(true);
return fragment;
}
@@ -130,7 +129,7 @@ public class TasksFragment extends Fragment implements
recyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(context, (view, position) -> {
boolean isLargeLayout = resources.getBoolean(R.bool.large_layout);
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext());
Bundle args = new Bundle();
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
args.putInt("button_count", isHistory ? 1 : 3);
@@ -222,10 +221,10 @@ public class TasksFragment extends Fragment implements
int direction = args.getInt("Direction");
// Handle never ask again checkbox
CheckBox neverAskAgainCheckBox = dialog.getDialog().findViewById(R.id.task_confirmation_never);
CheckBox neverAskAgainCheckBox = Objects.requireNonNull(dialog.getDialog()).findViewById(R.id.task_confirmation_never);
if (neverAskAgainCheckBox.isChecked()) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext());
SharedPreferences.Editor editor = sharedPref.edit();
// Set system settings
@@ -315,7 +314,7 @@ public class TasksFragment extends Fragment implements
@Override
public void onNewTaskDialogNeutralClick(DialogFragment dialog) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext());
boolean showDialog = sharedPref.getBoolean("pref_conf_del", true);
Bundle args = dialog.getArguments();
@@ -343,7 +342,7 @@ public class TasksFragment extends Fragment implements
@Override
public void onItemSwiped(int itemPosition, int direction) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(requireContext());
String title = "";
boolean showDialog = false;
int buttonLabel = -1;

View File

@@ -42,7 +42,6 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
TodayFormDialogFragment fragment = new TodayFormDialogFragment();
fragment.mListener = todayTaskListener;
fragment.setRetainInstance(true);
return fragment;
}
@@ -54,7 +53,6 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
mNegativeButtonString = getString(R.string.new_task_cancel);
mContentLayoutId = R.layout.content_today_form;
// Load the tasks asynchronously
//new LoadTasks(this).execute(getActivity());
TaskRunner taskRunner = new TaskRunner();
taskRunner.executeAsync(new LoadTasks(getContext()), this::setLayoutValues);
}

View File

@@ -24,7 +24,7 @@ public class TaskListTouchHelper extends ItemTouchHelper.SimpleCallback {
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
return mAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition());
return mAdapter.onItemMove(viewHolder.getAbsoluteAdapterPosition(), target.getAbsoluteAdapterPosition());
}
@Override