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
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<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);
taskDialogFragment.setArguments(args);
String title = getString(R.string.action_new_task);
if (mIsLargeLayout)
taskDialogFragment.show(fragmentManager, getString(R.string.action_new_task));
taskDialogFragment.show(fragmentManager, title);
else {
// The device is smaller, so show the fragment fullscreen
FragmentTransaction transaction = fragmentManager.beginTransaction();
@@ -205,7 +206,7 @@ public class MainActivity extends AppCompatActivity implements TasksFragment.Tas
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
// To make it fullscreen, use the 'content' root view as the container
// 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();
}
}

View File

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

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
<?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:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@@ -8,23 +8,22 @@
<TextView
android:id="@+id/total_task_cycles"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"/>
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/total_task_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
android:layout_centerHorizontal="true"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/task_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/text_margin"
android:layout_marginRight="@dimen/text_margin"
android:layout_below="@id/total_task_cycles"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="15dp"
android:layout_marginBottom="15dp"
android:name="com.wismna.geoffroy.donext.activities.TaskFragment"
app:layoutManager="LinearLayoutManager"
app:layout_heightPercent="90%"
tools:context=".fragments.TasksFragment"
tools:listitem="@layout/fragment_task_detailed" />
<RelativeLayout
@@ -64,5 +63,5 @@
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="@id/task_list_view" />
</android.support.percent.PercentRelativeLayout>
android:layout_below="@id/task_list_view"/>
</android.widget.RelativeLayout>