mirror of
https://github.com/wismna/DoNext.git
synced 2025-10-03 07:30:13 -04:00
About is now a DynamicDialogFragment instead of an activity
DynamicDialogFragments now set arguments values in local variables Code refactor
This commit is contained in:
@@ -33,14 +33,6 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.AboutActivity"
|
||||
android:label="@string/action_about"
|
||||
android:parentActivityName=".activities.MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activities.MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".activities.TodayActivity"
|
||||
android:label="@string/title_activity_today"
|
||||
|
@@ -1,28 +0,0 @@
|
||||
package com.wismna.geoffroy.donext.activities;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wismna.geoffroy.donext.BuildConfig;
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
|
||||
/**
|
||||
* About Activity class
|
||||
*/
|
||||
public class AboutActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_about);
|
||||
|
||||
TextView versionDonext = findViewById(R.id.version_donext);
|
||||
versionDonext.setText(getResources().getString(R.string.about_version_donext, BuildConfig.VERSION_NAME));
|
||||
|
||||
TextView versionAndroid = findViewById(R.id.version_android);
|
||||
versionAndroid.setText(getResources().getString(R.string.about_version_android, Build.VERSION.SDK_INT));
|
||||
|
||||
}
|
||||
}
|
@@ -13,6 +13,7 @@ import android.view.View;
|
||||
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
import com.wismna.geoffroy.donext.adapters.SectionsPagerAdapter;
|
||||
import com.wismna.geoffroy.donext.fragments.AboutDialogFragment;
|
||||
import com.wismna.geoffroy.donext.fragments.MainFragment;
|
||||
import com.wismna.geoffroy.donext.fragments.TaskFormDialogFragment;
|
||||
import com.wismna.geoffroy.donext.fragments.TaskListsDialogFragment;
|
||||
@@ -85,15 +86,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
// Create the fragment
|
||||
TaskListsDialogFragment taskListFragment = TaskListsDialogFragment.newInstance(
|
||||
(MainFragment)fragmentManager.findFragmentById(R.id.fragment_main));
|
||||
String title = getString(R.string.task_list_edit);
|
||||
|
||||
// Set the arguments
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("button_count", 1);
|
||||
args.putString("button_negative", getString(R.string.task_list_ok));
|
||||
taskListFragment.setArguments(args);
|
||||
|
||||
taskListFragment.showFragment(fragmentManager, title, getResources().getBoolean(R.bool.large_layout));
|
||||
taskListFragment.showFragment(fragmentManager,
|
||||
getString(R.string.task_list_edit), getResources().getBoolean(R.bool.large_layout));
|
||||
}
|
||||
|
||||
/** Called when the user clicks the History button*/
|
||||
@@ -110,8 +105,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
/** Called when the user clicks the About button */
|
||||
public void openAbout(MenuItem menuItem) {
|
||||
Intent intent = new Intent(this, AboutActivity.class);
|
||||
startActivity(intent);
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
// Create the fragment
|
||||
AboutDialogFragment taskListFragment = new AboutDialogFragment();
|
||||
taskListFragment.showFragment(fragmentManager,
|
||||
getString(R.string.action_about), getResources().getBoolean(R.bool.large_layout));
|
||||
}
|
||||
|
||||
/** Called when user clicks on the New Task floating button */
|
||||
@@ -136,10 +135,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
args.putString("button_neutral", getString(R.string.new_task_delete));
|
||||
taskDialogFragment.setArguments(args);
|
||||
|
||||
String title = getString(R.string.action_new_task);
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
taskDialogFragment.showFragment(fragmentManager, title, getResources().getBoolean(R.bool.large_layout));
|
||||
taskDialogFragment.showFragment(fragmentManager,
|
||||
getString(R.string.action_new_task), getResources().getBoolean(R.bool.large_layout));
|
||||
}
|
||||
|
||||
private ViewPager getMainFragmentViewPager(){
|
||||
|
@@ -88,18 +88,9 @@ public class TodayActivity extends ToolBarActivityBase
|
||||
TodayFormDialogFragment taskDialogFragment =
|
||||
TodayFormDialogFragment.newInstance(TodayActivity.this);
|
||||
|
||||
boolean isLargeLayout = getResources().getBoolean(R.bool.large_layout);
|
||||
// Set some configuration values for the dialog
|
||||
Bundle args = new Bundle();
|
||||
args.putBoolean("layout", isLargeLayout);
|
||||
args.putString("button_positive", getString(R.string.new_task_save));
|
||||
args.putString("button_negative", getString(R.string.new_task_cancel));
|
||||
taskDialogFragment.setArguments(args);
|
||||
|
||||
String title = getString(R.string.action_today_select);
|
||||
FragmentManager fragmentManager = getSupportFragmentManager();
|
||||
|
||||
taskDialogFragment.showFragment(fragmentManager, title, getResources().getBoolean(R.bool.large_layout));
|
||||
taskDialogFragment.showFragment(fragmentManager, getString(R.string.action_today_select), getResources().getBoolean(R.bool.large_layout));
|
||||
}
|
||||
|
||||
|
||||
|
@@ -0,0 +1,55 @@
|
||||
package com.wismna.geoffroy.donext.fragments;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.wismna.geoffroy.donext.BuildConfig;
|
||||
import com.wismna.geoffroy.donext.R;
|
||||
|
||||
/**
|
||||
* Created by GBE on 27/12/2017.
|
||||
* Shows the About page
|
||||
*/
|
||||
|
||||
public class AboutDialogFragment extends DynamicDialogFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mButtonCount = 1;
|
||||
mNegativeButtonString = getString(R.string.task_list_ok);
|
||||
mContentLayoutId = R.layout.content_about;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
|
||||
TextView versionDonext = findViewById(R.id.version_donext);
|
||||
Resources resources = getResources();
|
||||
versionDonext.setText(resources.getString(R.string.about_version_donext, BuildConfig.VERSION_NAME));
|
||||
|
||||
TextView versionAndroid = findViewById(R.id.version_android);
|
||||
versionAndroid.setText(resources.getString(R.string.about_version_android, Build.VERSION.SDK_INT));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPositiveButtonClick(View view) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNeutralButtonClick(View view) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNegativeButtonClick() {
|
||||
dismiss();
|
||||
}
|
||||
}
|
@@ -33,6 +33,9 @@ import com.wismna.geoffroy.donext.R;
|
||||
|
||||
public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
int mButtonCount = 2;
|
||||
String mPositiveButtonString = "";
|
||||
String mNeutralButtonString = "";
|
||||
String mNegativeButtonString = "";
|
||||
int mContentLayoutId = 0;
|
||||
|
||||
@Nullable
|
||||
@@ -69,12 +72,9 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
// As it is a Dialog, the root ViewGroup can be null without issues
|
||||
final View view = inflater.inflate(R.layout.fragment_dynamic_dialog, null);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
|
||||
Bundle args = getArguments();
|
||||
// Set the dialog buttons
|
||||
assert args != null;
|
||||
// Add action buttons
|
||||
builder.setView(view)
|
||||
.setNegativeButton(args.getString("button_negative"), new DialogInterface.OnClickListener() {
|
||||
.setNegativeButton(mNegativeButtonString, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
// Send the negative button event back to the host activity
|
||||
// Canceled creation, nothing to do
|
||||
@@ -82,14 +82,14 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
}
|
||||
});
|
||||
if (mButtonCount >= 2) {
|
||||
builder.setPositiveButton(args.getString("button_positive"), new DialogInterface.OnClickListener() {
|
||||
builder.setPositiveButton(mPositiveButtonString, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
onPositiveButtonClick(view);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (mButtonCount == 3) {
|
||||
builder.setNeutralButton(args.getString("button_neutral"), new DialogInterface.OnClickListener() {
|
||||
builder.setNeutralButton(mNeutralButtonString, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
onNeutralButtonClick(view);
|
||||
@@ -109,8 +109,6 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
Bundle args = getArguments();
|
||||
assert args != null;
|
||||
/*switch (mButtonCount) {
|
||||
case 1:
|
||||
menu.removeItem(R.id.menu_positive_button);
|
||||
@@ -134,8 +132,8 @@ public abstract class DynamicDialogFragment extends DialogFragment {
|
||||
|
||||
// Set titles on existing buttons
|
||||
switch (mButtonCount) {
|
||||
case 3: menu.findItem(R.id.menu_neutral_button).setTitle(args.getString("button_neutral"));
|
||||
case 2: menu.findItem(R.id.menu_positive_button).setTitle(args.getString("button_positive"));
|
||||
case 3: menu.findItem(R.id.menu_neutral_button).setTitle(mNeutralButtonString);
|
||||
case 2: menu.findItem(R.id.menu_positive_button).setTitle(mPositiveButtonString);
|
||||
}
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ import java.util.List;
|
||||
|
||||
public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
public Task getTask() {
|
||||
return task;
|
||||
return mTask;
|
||||
}
|
||||
|
||||
/** The activity that creates an instance of this dialog fragment must
|
||||
@@ -43,12 +43,14 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
}
|
||||
|
||||
private NewTaskListener mListener;
|
||||
private Task task;
|
||||
private Task mTask;
|
||||
private List<TaskList> taskLists;
|
||||
private int listId;
|
||||
private boolean isToday;
|
||||
|
||||
public static TaskFormDialogFragment newInstance(Task task, List<TaskList> taskLists, NewTaskListener newTaskListener) {
|
||||
TaskFormDialogFragment fragment = new TaskFormDialogFragment();
|
||||
fragment.task = task;
|
||||
fragment.mTask = task;
|
||||
fragment.taskLists = taskLists;
|
||||
fragment.mListener = newTaskListener;
|
||||
fragment.setRetainInstance(true);
|
||||
@@ -62,6 +64,11 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
mButtonCount = args.getInt("button_count");
|
||||
mPositiveButtonString = getString(R.string.new_task_save);
|
||||
mNegativeButtonString = getString(R.string.new_task_cancel);
|
||||
mNeutralButtonString = getString(R.string.new_task_delete);
|
||||
listId = args.getInt("list");
|
||||
isToday = args.getBoolean("today");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +92,7 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
protected void onPositiveButtonClick(View view) {
|
||||
if (view == null) return;
|
||||
EditText titleText = view.findViewById(R.id.new_task_name);
|
||||
// handle confirmation button click hereEditText titleText = (EditText) d.findViewById(R.id.new_task_name);
|
||||
// handle confirmation button click here
|
||||
if (titleText.getText().toString().matches(""))
|
||||
titleText.setError(getResources().getString(R.string.new_task_name_error));
|
||||
else {
|
||||
@@ -106,9 +113,9 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
}
|
||||
|
||||
private void setTaskValues(Activity activity) {
|
||||
// Populate spinner with task lists
|
||||
// Populate spinner with mTask lists
|
||||
Spinner spinner = findViewById(R.id.new_task_list);
|
||||
// Hide spinner if only one task list
|
||||
// Hide spinner if only one mTask list
|
||||
if (taskLists.size() <= 1) {
|
||||
spinner.setVisibility(View.GONE);
|
||||
TextView taskListLabel = findViewById(R.id.new_task_list_label);
|
||||
@@ -122,14 +129,11 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
spinner.setAdapter(adapter);
|
||||
|
||||
// Auto set list value to current tab
|
||||
Bundle args = getArguments();
|
||||
assert args != null;
|
||||
int id = args.getInt("list");
|
||||
spinner.setSelection(id);
|
||||
spinner.setSelection(listId);
|
||||
|
||||
CheckBox checkBox = findViewById(R.id.new_task_today);
|
||||
TextView todayLabel = findViewById(R.id.new_task_today_label);
|
||||
boolean isTodayActive = args.getBoolean("today");
|
||||
boolean isTodayActive = isToday;
|
||||
checkBox.setVisibility(isTodayActive ? View.VISIBLE : View.GONE);
|
||||
todayLabel.setVisibility(isTodayActive ? View.VISIBLE : View.GONE);
|
||||
|
||||
@@ -165,23 +169,23 @@ public class TaskFormDialogFragment extends DynamicDialogFragment {
|
||||
});
|
||||
tooltip.setText(getResources().getStringArray(R.array.task_priority)[seekBar.getProgress()]);
|
||||
// Set other properties if they exist
|
||||
if (task != null) {
|
||||
if (mTask != null) {
|
||||
|
||||
EditText titleText = findViewById(R.id.new_task_name);
|
||||
titleText.setText(task.getName());
|
||||
titleText.setText(mTask.getName());
|
||||
EditText descText = findViewById(R.id.new_task_description);
|
||||
descText.setText(task.getDescription());
|
||||
descText.setText(mTask.getDescription());
|
||||
|
||||
seekBar.setProgress(task.getPriority());
|
||||
seekBar.setProgress(mTask.getPriority());
|
||||
|
||||
// Set Due Date
|
||||
LocalDate dueDate = task.getDueDate();
|
||||
LocalDate dueDate = mTask.getDueDate();
|
||||
if (dueDate != null) {
|
||||
setDueDate.setChecked(true);
|
||||
dueDatePicker.updateDate(dueDate.getYear(), dueDate.getMonthOfYear() - 1, dueDate.getDayOfMonth());
|
||||
}
|
||||
|
||||
checkBox.setChecked(task.isToday());
|
||||
checkBox.setChecked(mTask.isToday());
|
||||
}
|
||||
else {
|
||||
// Disallow past dates on new tasks
|
||||
|
@@ -10,7 +10,6 @@ import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
@@ -59,13 +58,10 @@ public class TaskListsDialogFragment extends DynamicDialogFragment implements
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
mButtonCount = args.getInt("button_count");
|
||||
}
|
||||
|
||||
mButtonCount = 1;
|
||||
mNegativeButtonString = getString(R.string.task_list_ok);
|
||||
mContentLayoutId = R.layout.content_tasklists;
|
||||
|
||||
taskListDataAccess = new TaskListDataAccess(getContext(), TaskListDataAccess.MODE.WRITE);
|
||||
new GetTaskListsTask(this).execute(taskListDataAccess);
|
||||
}
|
||||
|
@@ -136,7 +136,6 @@ public class TasksFragment extends Fragment implements
|
||||
boolean isLargeLayout = resources.getBoolean(R.bool.large_layout);
|
||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("position", position);
|
||||
args.putBoolean("today", sharedPref.getBoolean("pref_conf_today_enable", false));
|
||||
args.putInt("button_count", isHistory ? 1 : 3);
|
||||
args.putString("button_positive", getString(R.string.new_task_save));
|
||||
@@ -171,9 +170,9 @@ public class TasksFragment extends Fragment implements
|
||||
taskDialogFragment.setArguments(args);
|
||||
|
||||
// Open the fragment as a dialog or as full-screen depending on screen size
|
||||
String title = getString(isHistory ? R.string.action_view_task : R.string.action_edit_task);
|
||||
assert manager != null;
|
||||
taskDialogFragment.showFragment(manager, title, isLargeLayout);
|
||||
taskDialogFragment.showFragment(manager,
|
||||
getString(isHistory ? R.string.action_view_task : R.string.action_edit_task), isLargeLayout);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
@@ -49,6 +49,9 @@ public class TodayFormDialogFragment extends DynamicDialogFragment {
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mPositiveButtonString = getString(R.string.new_task_save);
|
||||
mNegativeButtonString = getString(R.string.new_task_cancel);
|
||||
mContentLayoutId = R.layout.content_today_form;
|
||||
// Load the tasks asynchronously
|
||||
new LoadTasks(this).execute(getActivity());
|
||||
|
@@ -1,14 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="@dimen/activity_vertical_margin"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/activity_vertical_margin"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activities.AboutActivity">
|
||||
android:background="@android:color/background_light"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/description_donext"
|
||||
android:text="@string/donext_description"
|
Reference in New Issue
Block a user