Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2b7f5e7b authored by cketti's avatar cketti
Browse files

Merge branch 'pick_attachment_fix'

Update LocalStore code to handle the newly introduced temporary files
for attachments

Conflicts:
	res/values/strings.xml
	src/com/fsck/k9/activity/MessageCompose.java
parents bfb5a5bb 677d6c92
Loading
Loading
Loading
Loading
+52 −33
Original line number Diff line number Diff line
@@ -6,31 +6,50 @@
    android:paddingRight="6dip"
    android:paddingTop="6dip"
    android:paddingBottom="6dip">

    <ImageButton
        android:id="@+id/attachment_delete"
        android:src="@drawable/ic_delete"
        android:layout_alignParentRight="true"
        android:layout_height="42dip"
        android:layout_width="42dip" />

    <LinearLayout
        android:layout_width="1dip"
        android:layout_height="42dip"
        android:layout_alignParentLeft="true"
        android:layout_toLeftOf="@id/attachment_delete"
        android:layout_marginLeft="6dip"
        android:layout_marginRight="4dip"
        android:paddingLeft="36dip"
        android:gravity="center_vertical"
        android:background="?attr/messageViewAttachmentBackground"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/attachment_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="?android:attr/textColorSecondary"
		android:layout_width="1dip"
		android:layout_height="42dip"
		android:background="?attr/messageViewAttachmentBackground"
		android:paddingLeft="36dip"
            android:singleLine="true"
		android:ellipsize="start"
		android:gravity="center_vertical"
		android:layout_marginLeft="6dip"
		android:layout_marginRight="4dip"
		android:layout_alignParentLeft="true"
		android:layout_toLeftOf="@id/attachment_delete" />
            android:ellipsize="start"/>

        <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="32dp"
            android:layout_height="fill_parent"
            android:layout_marginLeft="4dp"/>

    </LinearLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_email_attachment"
        android:layout_marginLeft="1dip"
        android:layout_centerVertical="true" />

</RelativeLayout>
+5 −0
Original line number Diff line number Diff line
@@ -1152,4 +1152,9 @@ Please submit bug reports, contribute new features and ask questions at

    <string name="global_settings_messageview_visible_refile_actions_title">Visible message actions</string>
    <string name="global_settings_messageview_visible_refile_actions_summary">Show selected actions in the message view menu</string>

    <string name="loading_attachment">Loading attachment…</string>
    <string name="fetching_attachment_dialog_title_send">Sending message</string>
    <string name="fetching_attachment_dialog_title_save">Saving draft</string>
    <string name="fetching_attachment_dialog_message">Fetching attachment…</string>
</resources>
+2 −2
Original line number Diff line number Diff line
@@ -3,12 +3,12 @@ package com.fsck.k9.activity;
import android.os.Bundle;
import android.view.MotionEvent;

import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.fsck.k9.activity.K9ActivityCommon.K9ActivityMagic;
import com.fsck.k9.activity.misc.SwipeGestureDetector.OnSwipeGestureListener;


public class K9Activity extends SherlockActivity implements K9ActivityMagic {
public class K9Activity extends SherlockFragmentActivity implements K9ActivityMagic {

    private K9ActivityCommon mBase;

+289 −73

File changed.

Preview size limit exceeded, changes collapsed.

+81 −0
Original line number Diff line number Diff line
package com.fsck.k9.activity.loader;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;
import android.util.Log;

import com.fsck.k9.K9;
import com.fsck.k9.activity.misc.Attachment;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Loader to fetch the content of an attachment.
 *
 * This will copy the data to a temporary file in our app's cache directory.
 */
public class AttachmentContentLoader extends AsyncTaskLoader<Attachment> {
    private static final String FILENAME_PREFIX = "attachment";

    private final Attachment mAttachment;

    public AttachmentContentLoader(Context context, Attachment attachment) {
        super(context);
        mAttachment = attachment;
    }

    @Override
    protected void onStartLoading() {
        if (mAttachment.state == Attachment.LoadingState.COMPLETE) {
            deliverResult(mAttachment);
        }

        if (takeContentChanged() || mAttachment.state == Attachment.LoadingState.METADATA) {
            forceLoad();
        }
    }

    @Override
    public Attachment loadInBackground() {
        Context context = getContext();

        try {
            File file = File.createTempFile(FILENAME_PREFIX, null, context.getCacheDir());
            file.deleteOnExit();

            if (K9.DEBUG) {
                Log.v(K9.LOG_TAG, "Saving attachment to " + file.getAbsolutePath());
            }

            InputStream in = context.getContentResolver().openInputStream(mAttachment.uri);
            try {
                FileOutputStream out = new FileOutputStream(file);
                try {
                    IOUtils.copy(in, out);
                } finally {
                    out.close();
                }
            } finally {
                in.close();
            }

            mAttachment.filename = file.getAbsolutePath();
            mAttachment.state = Attachment.LoadingState.COMPLETE;

            return mAttachment;
        } catch (IOException e) {
            e.printStackTrace();
        }

        mAttachment.filename = null;
        mAttachment.state = Attachment.LoadingState.CANCELLED;

        return mAttachment;
    }
}
Loading