Skip to content

Commit

Permalink
Replace task details fragments instead of updating them. Fixes #624 (#…
Browse files Browse the repository at this point in the history
…630)

This solution fixes a number of actual and potential bugs around changing the content of the details pane. The view fragment can be simplified further. That's subject to another story.
  • Loading branch information
Gabor Keszthelyi authored and dmfs committed Sep 25, 2018
1 parent d5496fc commit cef62e0
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 204 deletions.
4 changes: 3 additions & 1 deletion opentasks/src/main/java/org/dmfs/tasks/EditTaskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,9 @@ public void saveAndExit()
activity.finish();
if (isNewTask)
{
activity.startActivity(new Intent("android.intent.action.VIEW", mTaskUri));
activity.startActivity(
new Intent(Intent.ACTION_VIEW, mTaskUri)
.putExtra(ViewTaskActivity.EXTRA_COLOR, mListColor));
}
}
else
Expand Down
36 changes: 30 additions & 6 deletions opentasks/src/main/java/org/dmfs/tasks/EmptyTaskFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.dmfs.android.bolts.color.colors.AttributeColor;
import org.dmfs.android.bolts.color.Color;
import org.dmfs.android.bolts.color.elementary.ValueColor;
import org.dmfs.android.retentionmagic.SupportFragment;


Expand All @@ -34,22 +36,44 @@
*/
public class EmptyTaskFragment extends SupportFragment
{
private static final String ARG_COLOR = "color";

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
private Color mColor;


/**
* @param color
* The color that the toolbars should take. (If available provide the actual task list color, otherwise the primary color.)
*/
public static Fragment newInstance(Color color)
{
return inflater.inflate(R.layout.opentasks_fragment_empty_task, container, false);
EmptyTaskFragment fragment = new EmptyTaskFragment();
Bundle args = new Bundle();
args.putInt(ARG_COLOR, color.argb());
fragment.setArguments(args);
return fragment;
}


@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);

mColor = new ValueColor(getArguments().getInt(ARG_COLOR));

if (activity instanceof ViewTaskFragment.Callback)
{
((ViewTaskFragment.Callback) activity)
.updateColor(new AttributeColor(getContext(), R.attr.colorPrimary));
((ViewTaskFragment.Callback) activity).onListColorLoaded(mColor);
}
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.opentasks_fragment_empty_task, container, false);
view.findViewById(R.id.empty_task_fragment_appbar).setBackgroundColor(mColor.argb());
return view;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public class TaskGroupPagerAdapter extends FragmentStatePagerAdapter
@SuppressWarnings("unused")
private static final String TAG = "TaskGroupPager";
private final Map<Integer, AbstractGroupingFactory> mGroupingFactories = new HashMap<Integer, AbstractGroupingFactory>(16);
private boolean mTwoPaneLayout;
private final TabConfig mTabConfig;


Expand Down Expand Up @@ -94,7 +93,7 @@ public Fragment getItem(int position)
int pageId = mTabConfig.getVisibleItem(position).getId();
AbstractGroupingFactory factory = getGroupingFactoryForId(pageId);

TaskListFragment fragment = TaskListFragment.newInstance(position, mTwoPaneLayout);
TaskListFragment fragment = TaskListFragment.newInstance(position);
fragment.setExpandableGroupDescriptor(factory.getExpandableGroupDescriptor());
fragment.setPageId(pageId);
return fragment;
Expand Down Expand Up @@ -159,12 +158,6 @@ public int getCount()
}


public void setTwoPaneLayout(boolean twoPane)
{
mTwoPaneLayout = twoPane;
}


public int getTabIcon(int position)
{
return mTabConfig.getVisibleItem(position).getIcon();
Expand Down
Loading

0 comments on commit cef62e0

Please sign in to comment.