Auto get title in Task Dialog

Don't show keyboard on dialog show
Hide keyboard on dialog dismiss
Cleaner tasks layout
WIP: remaining tasks still not shown, top text cropped in large screens
This commit is contained in:
bg45
2017-03-17 17:11:02 -04:00
parent 9a35af7bf2
commit bfca61935b
7 changed files with 42 additions and 43 deletions

View File

@@ -16,6 +16,7 @@
<activity <activity
android:name=".activities.MainActivity" android:name=".activities.MainActivity"
android:label="@string/app_name" android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden"
android:theme="@style/AppTheme.NoActionBar"> android:theme="@style/AppTheme.NoActionBar">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@@ -196,8 +196,9 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
args.putBoolean("layout", mIsLargeLayout); args.putBoolean("layout", mIsLargeLayout);
taskDialogFragment.setArguments(args); taskDialogFragment.setArguments(args);
String title = getString(R.string.action_new_task);
if (mIsLargeLayout) if (mIsLargeLayout)
taskDialogFragment.show(fragmentManager, getString(R.string.action_new_task)); taskDialogFragment.show(fragmentManager, title);
else { else {
// The device is smaller, so show the fragment fullscreen // The device is smaller, so show the fragment fullscreen
FragmentTransaction transaction = fragmentManager.beginTransaction(); FragmentTransaction transaction = fragmentManager.beginTransaction();
@@ -205,7 +206,7 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// To make it fullscreen, use the 'content' root view as the container // To make it fullscreen, use the 'content' root view as the container
// for the fragment, which is always the root view for the activity // for the fragment, which is always the root view for the activity
transaction.replace(android.R.id.content, taskDialogFragment) transaction.add(android.R.id.content, taskDialogFragment, title)
.addToBackStack(null).commit(); .addToBackStack(null).commit();
} }
} }

View File

@@ -1,5 +1,6 @@
package com.wismna.geoffroy.donext.fragments; package com.wismna.geoffroy.donext.fragments;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
@@ -16,6 +17,7 @@ import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
@@ -54,7 +56,6 @@ public class TaskDialogFragment extends DialogFragment {
private NewTaskListener mListener; private NewTaskListener mListener;
private Task task; private Task task;
private List<TaskList> taskLists; private List<TaskList> taskLists;
private boolean isLargeLayout;
public static TaskDialogFragment newInstance(Task task, List<TaskList> taskLists, NewTaskListener newTaskListener) { public static TaskDialogFragment newInstance(Task task, List<TaskList> taskLists, NewTaskListener newTaskListener) {
TaskDialogFragment fragment = new TaskDialogFragment(); TaskDialogFragment fragment = new TaskDialogFragment();
@@ -67,14 +68,14 @@ public class TaskDialogFragment extends DialogFragment {
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
isLargeLayout = getArguments().getBoolean("layout");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
} }
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (!isLargeLayout) { // This part is only needed on small layouts (large layouts use onCreateDialog)
if (!getArguments().getBoolean("layout")) {
View view = inflater.inflate(R.layout.fragment_task_form, container, false); View view = inflater.inflate(R.layout.fragment_task_form, container, false);
AppCompatActivity activity = (AppCompatActivity) getActivity(); AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(setToolbarTitle(view)); activity.setSupportActionBar(setToolbarTitle(view));
@@ -102,7 +103,6 @@ public class TaskDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Pass null as the parent view because its going in the dialog layout // Pass null as the parent view because its going in the dialog layout
builder.setView(view) builder.setView(view)
//.setTitle(getString(task == null ? R.string.action_new_task : R.string.action_edit_task))
// Add action buttons // Add action buttons
.setPositiveButton(R.string.new_task_save, null) .setPositiveButton(R.string.new_task_save, null)
.setNegativeButton(R.string.new_task_cancel, new DialogInterface.OnClickListener() { .setNegativeButton(R.string.new_task_cancel, new DialogInterface.OnClickListener() {
@@ -122,9 +122,6 @@ public class TaskDialogFragment extends DialogFragment {
} }
setTaskValues(view); setTaskValues(view);
return builder.create(); return builder.create();
//Dialog dialog = super.onCreateDialog(savedInstanceState);
//dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//return dialog;
} }
@Override @Override
@@ -132,7 +129,7 @@ public class TaskDialogFragment extends DialogFragment {
super.onStart(); super.onStart();
Dialog dialog = getDialog(); Dialog dialog = getDialog();
if(dialog != null && dialog instanceof AlertDialog/* && isLargeLayout*/) if(dialog != null && dialog instanceof AlertDialog)
{ {
AlertDialog d = (AlertDialog) dialog; AlertDialog d = (AlertDialog) dialog;
Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE); Button positiveButton = d.getButton(Dialog.BUTTON_POSITIVE);
@@ -162,16 +159,23 @@ public class TaskDialogFragment extends DialogFragment {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
// Determine which menu item was clicked
int id = item.getItemId(); int id = item.getItemId();
View view = getView();
// Hide the keyboard if present
if (view != null) {
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().getWindowToken(), 0);
}
if (id == R.id.menu_new_task_save) { if (id == R.id.menu_new_task_save) {
onSaveClickListener(getView()); // handle save button click here
onSaveClickListener(view);
return true; return true;
} }
else if (id == R.id.menu_new_task_delete) { else if (id == R.id.menu_new_task_delete) {
// handle confirmation button click here // handle delete button click here
mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this); mListener.onNewTaskDialogNeutralClick(TaskDialogFragment.this);
dismiss();
return true; return true;
} }
else if (id == android.R.id.home) { else if (id == android.R.id.home) {
@@ -179,7 +183,6 @@ public class TaskDialogFragment extends DialogFragment {
dismiss(); dismiss();
return true; return true;
} }
dismiss();
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@@ -251,23 +254,11 @@ public class TaskDialogFragment extends DialogFragment {
private Toolbar setToolbarTitle(View view) { private Toolbar setToolbarTitle(View view) {
Toolbar toolbar = (Toolbar) view.findViewById(R.id.new_task_toolbar); Toolbar toolbar = (Toolbar) view.findViewById(R.id.new_task_toolbar);
if (task == null) { toolbar.setTitle(getTag());
toolbar.setTitle(R.string.action_new_task);
}
else {
toolbar.setTitle(R.string.action_edit_task);
}
return toolbar; return toolbar;
} }
private void onSaveClickListener(View view) { private void onSaveClickListener(View view) {
/*if (source == null) return;
EditText titleText = null;
if (source instanceof View)
titleText = (EditText) ((View)source).findViewById(R.id.new_task_name);
if (source instanceof AlertDialog)
titleText = (EditText) ((AlertDialog)source).findViewById(R.id.new_task_name);
if (titleText == null) return;*/
if (view == null) return; if (view == null) return;
EditText titleText = (EditText) view.findViewById(R.id.new_task_name); EditText titleText = (EditText) 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 hereEditText titleText = (EditText) d.findViewById(R.id.new_task_name);

View File

@@ -185,7 +185,7 @@ public class TaskListsFragment extends Fragment implements
} }
} }
public class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> { private class GetTaskListsTask extends AsyncTask<TaskListDataAccess, Void, List<TaskList>> {
@Override @Override
protected List<TaskList> doInBackground(TaskListDataAccess... params) { protected List<TaskList> doInBackground(TaskListDataAccess... params) {
TaskListDataAccess taskListDataAccess = params[0]; TaskListDataAccess taskListDataAccess = params[0];

View File

@@ -140,12 +140,12 @@ public class TasksFragment extends Fragment implements
taskRecyclerViewAdapter.getItem(position), taskRecyclerViewAdapter.getItem(position),
((MainActivity.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems(), ((MainActivity.SectionsPagerAdapter) viewPager.getAdapter()).getAllItems(),
TasksFragment.this); TasksFragment.this);
taskDialogFragment.setArguments(args); taskDialogFragment.setArguments(args);
// Open the fragment as a dialog or as full-screen depending on screen size // Open the fragment as a dialog or as full-screen depending on screen size
String title = getString(R.string.action_edit_task);
if (mIsLargeLayout) if (mIsLargeLayout)
taskDialogFragment.show(manager, getResources().getString(R.string.action_edit_task)); taskDialogFragment.show(manager, title);
else { else {
// The device is smaller, so show the fragment fullscreen // The device is smaller, so show the fragment fullscreen
FragmentTransaction transaction = manager.beginTransaction(); FragmentTransaction transaction = manager.beginTransaction();
@@ -153,7 +153,7 @@ public class TasksFragment extends Fragment implements
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// To make it fullscreen, use the 'content' root view as the container // To make it fullscreen, use the 'content' root view as the container
// for the fragment, which is always the root view for the activity // for the fragment, which is always the root view for the activity
transaction.replace(android.R.id.content, taskDialogFragment) transaction.add(android.R.id.content, taskDialogFragment, title)
.addToBackStack(null).commit(); .addToBackStack(null).commit();
} }
} }
@@ -225,6 +225,9 @@ public class TasksFragment extends Fragment implements
taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount()); taskRecyclerViewAdapter.add(task, taskRecyclerViewAdapter.getItemCount());
break; break;
case -1: case -1:
FragmentManager manager = getFragmentManager();
DialogFragment dialog = (DialogFragment) manager.findFragmentByTag(getString(R.string.action_edit_task));
if (dialog != null) dialog.dismiss();
action = resources.getString(R.string.snackabar_action_deleted); action = resources.getString(R.string.snackabar_action_deleted);
break; break;
} }
@@ -377,7 +380,6 @@ public class TasksFragment extends Fragment implements
@Override @Override
public void onNewTaskDialogNeutralClick(DialogFragment dialog) { public void onNewTaskDialogNeutralClick(DialogFragment dialog) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext()); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
String title = getResources().getString(R.string.task_confirmation_delete_text);
boolean showDialog = sharedPref.getBoolean("pref_conf_del", true); boolean showDialog = sharedPref.getBoolean("pref_conf_del", true);
Bundle args = dialog.getArguments(); Bundle args = dialog.getArguments();
@@ -385,6 +387,7 @@ public class TasksFragment extends Fragment implements
final int itemPosition = args.getInt("position"); final int itemPosition = args.getInt("position");
if (showDialog) { if (showDialog) {
String title = getResources().getString(R.string.task_confirmation_delete_text);
ConfirmDialogFragment confirmDialogFragment = ConfirmDialogFragment confirmDialogFragment =
ConfirmDialogFragment.newInstance(this); ConfirmDialogFragment.newInstance(this);
Bundle confirmArgs = new Bundle(); Bundle confirmArgs = new Bundle();
@@ -395,7 +398,9 @@ public class TasksFragment extends Fragment implements
confirmDialogFragment.setArguments(confirmArgs); confirmDialogFragment.setArguments(confirmArgs);
confirmDialogFragment.show(getFragmentManager(), title); confirmDialogFragment.show(getFragmentManager(), title);
} }
else PerformTaskAction(itemPosition, -1); else {
PerformTaskAction(itemPosition, -1);
}
} }
@Override @Override

View File

@@ -26,6 +26,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="@dimen/text_margin" android:padding="@dimen/text_margin"
android:orientation="vertical" android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
tools:context=".activities.MainActivity"> tools:context=".activities.MainActivity">
<TextView <TextView
android:id="@+id/new_task_list_label" android:id="@+id/new_task_list_label"

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@@ -8,8 +8,7 @@
<TextView <TextView
android:id="@+id/total_task_cycles" android:id="@+id/total_task_cycles"
android:layout_width="100dp" android:layout_width="100dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"/>
android:layout_alignParentStart="true"/>
<TextView <TextView
android:id="@+id/total_task_count" android:id="@+id/total_task_count"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -19,12 +18,12 @@
android:id="@+id/task_list_view" android:id="@+id/task_list_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="@dimen/text_margin" android:layout_marginStart="5dp"
android:layout_marginRight="@dimen/text_margin" android:layout_marginEnd="5dp"
android:layout_below="@id/total_task_cycles" android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:name="com.wismna.geoffroy.donext.activities.TaskFragment" android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
app:layoutManager="LinearLayoutManager" app:layoutManager="LinearLayoutManager"
app:layout_heightPercent="90%"
tools:context=".fragments.TasksFragment" tools:context=".fragments.TasksFragment"
tools:listitem="@layout/fragment_task_detailed" /> tools:listitem="@layout/fragment_task_detailed" />
<RelativeLayout <RelativeLayout
@@ -65,4 +64,4 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
android:layout_below="@id/task_list_view"/> android:layout_below="@id/task_list_view"/>
</android.support.percent.PercentRelativeLayout> </android.widget.RelativeLayout>