better getActivity and getSystemService null handling in encryptfilesfragment
This commit is contained in:
@@ -35,6 +35,7 @@ import android.graphics.Point;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v7.widget.DefaultItemAnimator;
|
import android.support.v7.widget.DefaultItemAnimator;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
@@ -388,6 +389,12 @@ public class EncryptFilesFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onCryptoOperationSuccess(final SignEncryptResult result) {
|
public void onCryptoOperationSuccess(final SignEncryptResult result) {
|
||||||
|
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
// it's gone, there's nothing we can do here
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mDeleteAfterEncrypt) {
|
if (mDeleteAfterEncrypt) {
|
||||||
// TODO make behavior coherent here
|
// TODO make behavior coherent here
|
||||||
DeleteFileDialogFragment deleteFileDialog =
|
DeleteFileDialogFragment deleteFileDialog =
|
||||||
@@ -400,13 +407,18 @@ public class EncryptFilesFragment
|
|||||||
// Share encrypted message/file
|
// Share encrypted message/file
|
||||||
startActivity(sendWithChooserExcludingEncrypt());
|
startActivity(sendWithChooserExcludingEncrypt());
|
||||||
} else {
|
} else {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) {
|
||||||
|
// it's gone, there's nothing we can do here
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Save encrypted file
|
// Save encrypted file
|
||||||
result.createNotify(getActivity()).show();
|
result.createNotify(activity).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
|
deleteFileDialog.show(activity.getSupportFragmentManager(), "deleteDialog");
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
switch (mAfterEncryptAction) {
|
switch (mAfterEncryptAction) {
|
||||||
@@ -417,25 +429,24 @@ public class EncryptFilesFragment
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case COPY:
|
case COPY:
|
||||||
Activity activity = getActivity();
|
|
||||||
if (activity == null) {
|
|
||||||
// it's gone, there's nothing we can do here
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager clipMan = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
if (clipMan == null) {
|
||||||
|
Notify.create(activity, R.string.error_clipboard_copy, Style.ERROR).show();
|
||||||
|
break;
|
||||||
|
}
|
||||||
ClipData clip = new ClipData(getString(R.string.label_clip_title),
|
ClipData clip = new ClipData(getString(R.string.label_clip_title),
|
||||||
// make available as application/pgp-encrypted
|
// make available as application/pgp-encrypted
|
||||||
new String[] { "text/plain" },
|
new String[] { "text/plain" },
|
||||||
new ClipData.Item(mOutputUris.get(0))
|
new ClipData.Item(mOutputUris.get(0))
|
||||||
);
|
);
|
||||||
clipMan.setPrimaryClip(clip);
|
clipMan.setPrimaryClip(clip);
|
||||||
result.createNotify(getActivity()).show();
|
result.createNotify(activity).show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SAVE:
|
case SAVE:
|
||||||
// Encrypted file was saved already, just show notification
|
// Encrypted file was saved already, just show notification
|
||||||
result.createNotify(getActivity()).show();
|
result.createNotify(activity).show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1424,5 +1424,6 @@
|
|||||||
<string name="file_delete_none">"No file deleted! (Already deleted?)"</string>
|
<string name="file_delete_none">"No file deleted! (Already deleted?)"</string>
|
||||||
<string name="file_delete_exception">"Original file could not be deleted!"</string>
|
<string name="file_delete_exception">"Original file could not be deleted!"</string>
|
||||||
<string name="error_clipboard_empty">"Clipboard is empty!"</string>
|
<string name="error_clipboard_empty">"Clipboard is empty!"</string>
|
||||||
|
<string name="error_clipboard_copy">"Error copying data to clipboard!"</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user