Skip to content

Commit

Permalink
Replace classes with Single. #436 (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Keszthelyi authored and dmfs committed Oct 6, 2017
1 parent 0f220ad commit f3cdf94
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 245 deletions.
1 change: 1 addition & 0 deletions opentasks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dependencies {
exclude module: 'carrot'
exclude group: 'com.android.support'
}
compile 'org.dmfs:essentials:1.9'

testCompile 'junit:junit:4.12'
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.content.Context;
import android.content.Intent;

import org.dmfs.jems.single.Single;
import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.model.Model;
import org.dmfs.tasks.utils.TaskIntentFactory;
Expand All @@ -46,13 +47,13 @@ public final class ShareIntentFactory implements TaskIntentFactory
@Override
public Intent create(ContentSet contentSet, Model model, Context context)
{
CharSequence title = new TitleText(contentSet);
CharSequence body = new ShareTaskText(contentSet, model, context);
Single<CharSequence> title = new TaskShareTitle(contentSet);
Single<CharSequence> body = new TaskShareDetails(contentSet, model, context);

Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_SUBJECT, title.toString());
sendIntent.putExtra(Intent.EXTRA_TEXT, body.toString());
sendIntent.putExtra(Intent.EXTRA_SUBJECT, title.value().toString());
sendIntent.putExtra(Intent.EXTRA_TEXT, body.value().toString());
sendIntent.setType("text/plain");

return sendIntent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@

import org.dmfs.android.carrot.bindings.AndroidBindings;
import org.dmfs.android.carrot.locaters.RawResourceLocator;
import org.dmfs.jems.single.Single;
import org.dmfs.tasks.R;
import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.model.Model;
import org.dmfs.tasks.utils.charsequence.LazyCharSequence;
import org.dmfs.tasks.utils.ondemand.OnDemand;

import au.com.codeka.carrot.CarrotEngine;
import au.com.codeka.carrot.CarrotException;
Expand Down Expand Up @@ -57,37 +56,45 @@


/**
* {@link CharSequence} for sharing task information, uses <code>carrot</code> template engine.
* {@link CharSequence} detailing information about the task, used when sharing.
* <p>
* Implementation uses <code>carrot</code> template engine.
*
* @author Gabor Keszthelyi
*/
public final class ShareTaskText extends LazyCharSequence
public final class TaskShareDetails implements Single<CharSequence>
{
public ShareTaskText(final ContentSet contentSet, final Model model, final Context context)
private final ContentSet mContentSet;
private final Model mModel;
private final Context mContext;


public TaskShareDetails(ContentSet contentSet, Model model, Context context)
{
super(new OnDemand<CharSequence>()
{
@Override
public CharSequence get()
{
CarrotEngine engine = new CarrotEngine(new Configuration.Builder().setResourceLocator(new RawResourceLocator.Builder(context)).build());
try
{
String output = engine.process(String.valueOf(R.raw.sharetask),
new Composite(
new AndroidBindings(context),
new SingletonBindings("$task", new TaskBindings(contentSet, model)),
new SingletonBindings("tformat", new TimeFormatter(context, contentSet))));

Log.v("ShareTaskText", output);
return output;
}
catch (CarrotException e)
{
throw new RuntimeException("Failed to process template with carrot", e);
}
}
});
mContentSet = contentSet;
mModel = model;
mContext = context.getApplicationContext();
}


@Override
public CharSequence value()
{
CarrotEngine engine = new CarrotEngine(new Configuration.Builder().setResourceLocator(new RawResourceLocator.Builder(mContext)).build());
try
{
String output = engine.process(String.valueOf(R.raw.sharetask),
new Composite(
new AndroidBindings(mContext),
new SingletonBindings("$task", new TaskBindings(mContentSet, mModel)),
new SingletonBindings("tformat", new TimeFormatter(mContext, mContentSet))));

Log.v("TaskShareDetails", output);
return output;
}
catch (CarrotException e)
{
throw new RuntimeException("Failed to process template with carrot", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,30 @@

package org.dmfs.tasks.share;

import org.dmfs.jems.single.Single;
import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.model.TaskFieldAdapters;
import org.dmfs.tasks.utils.charsequence.DelegatingCharSequence;


/**
* {@link TaskText} for simply the title.
* {@link Single} for the title of the shared information of a task.
*
* @author Gabor Keszthelyi
*/
public final class TitleText extends DelegatingCharSequence
public final class TaskShareTitle implements Single<CharSequence>
{
public TitleText(ContentSet contentSet)
private final ContentSet mContentSet;


public TaskShareTitle(ContentSet contentSet)
{
mContentSet = contentSet;
}


@Override
public CharSequence value()
{
super(TaskFieldAdapters.TITLE.get(contentSet));
return TaskFieldAdapters.TITLE.get(mContentSet);
}
}

This file was deleted.

This file was deleted.

46 changes: 0 additions & 46 deletions opentasks/src/main/java/org/dmfs/tasks/utils/ondemand/Cached.java

This file was deleted.

This file was deleted.

0 comments on commit f3cdf94

Please sign in to comment.