ReceiveExternalFilesActivity.java 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author masensio
  6. * @author Juan Carlos González Cabrero
  7. * @author David A. Velasco
  8. * Copyright (C) 2012 Bartek Przybylski
  9. * Copyright (C) 2016 ownCloud Inc.
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. package com.owncloud.android.ui.activity;
  24. import android.accounts.Account;
  25. import android.accounts.AccountManager;
  26. import android.accounts.AuthenticatorException;
  27. import android.app.Dialog;
  28. import android.content.BroadcastReceiver;
  29. import android.content.Context;
  30. import android.content.DialogInterface;
  31. import android.content.DialogInterface.OnClickListener;
  32. import android.content.Intent;
  33. import android.content.IntentFilter;
  34. import android.content.res.Resources.NotFoundException;
  35. import android.graphics.PorterDuff;
  36. import android.graphics.drawable.ColorDrawable;
  37. import android.graphics.drawable.Drawable;
  38. import android.os.Bundle;
  39. import android.os.Handler;
  40. import android.os.Looper;
  41. import android.os.Parcelable;
  42. import android.support.annotation.DrawableRes;
  43. import android.support.annotation.NonNull;
  44. import android.support.annotation.Nullable;
  45. import android.support.annotation.StringRes;
  46. import android.support.v4.app.DialogFragment;
  47. import android.support.v4.app.FragmentManager;
  48. import android.support.v4.content.ContextCompat;
  49. import android.support.v4.graphics.drawable.DrawableCompat;
  50. import android.support.v7.app.ActionBar;
  51. import android.support.v7.app.AlertDialog;
  52. import android.support.v7.app.AlertDialog.Builder;
  53. import android.text.format.DateFormat;
  54. import android.view.LayoutInflater;
  55. import android.view.Menu;
  56. import android.view.MenuInflater;
  57. import android.view.MenuItem;
  58. import android.view.View;
  59. import android.view.WindowManager.LayoutParams;
  60. import android.widget.AdapterView;
  61. import android.widget.AdapterView.OnItemClickListener;
  62. import android.widget.ArrayAdapter;
  63. import android.widget.Button;
  64. import android.widget.EditText;
  65. import android.widget.ImageView;
  66. import android.widget.LinearLayout;
  67. import android.widget.ListView;
  68. import android.widget.ProgressBar;
  69. import android.widget.Spinner;
  70. import android.widget.TextView;
  71. import android.widget.Toast;
  72. import com.owncloud.android.MainApp;
  73. import com.owncloud.android.R;
  74. import com.owncloud.android.datamodel.OCFile;
  75. import com.owncloud.android.db.PreferenceManager;
  76. import com.owncloud.android.files.services.FileUploader;
  77. import com.owncloud.android.lib.common.operations.RemoteOperation;
  78. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  79. import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
  80. import com.owncloud.android.lib.common.utils.Log_OC;
  81. import com.owncloud.android.operations.CreateFolderOperation;
  82. import com.owncloud.android.operations.RefreshFolderOperation;
  83. import com.owncloud.android.operations.UploadFileOperation;
  84. import com.owncloud.android.syncadapter.FileSyncAdapter;
  85. import com.owncloud.android.ui.adapter.AccountListAdapter;
  86. import com.owncloud.android.ui.adapter.AccountListItem;
  87. import com.owncloud.android.ui.adapter.UploaderAdapter;
  88. import com.owncloud.android.ui.asynctasks.CopyAndUploadContentUrisTask;
  89. import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
  90. import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
  91. import com.owncloud.android.ui.fragment.TaskRetainerFragment;
  92. import com.owncloud.android.ui.helpers.UriUploader;
  93. import com.owncloud.android.utils.DataHolderUtil;
  94. import com.owncloud.android.utils.ErrorMessageAdapter;
  95. import com.owncloud.android.utils.FileStorageUtils;
  96. import com.owncloud.android.utils.ThemeUtils;
  97. import java.io.File;
  98. import java.io.FileWriter;
  99. import java.io.IOException;
  100. import java.io.UnsupportedEncodingException;
  101. import java.lang.reflect.Method;
  102. import java.util.ArrayList;
  103. import java.util.Calendar;
  104. import java.util.HashMap;
  105. import java.util.LinkedList;
  106. import java.util.List;
  107. import java.util.Stack;
  108. import java.util.Vector;
  109. /**
  110. * This can be used to upload things to an ownCloud instance.
  111. */
  112. public class ReceiveExternalFilesActivity extends FileActivity
  113. implements OnItemClickListener, View.OnClickListener, CopyAndUploadContentUrisTask.OnCopyTmpFilesTaskListener {
  114. private static final String TAG = ReceiveExternalFilesActivity.class.getSimpleName();
  115. private static final String FTAG_ERROR_FRAGMENT = "ERROR_FRAGMENT";
  116. public static final String TEXT_FILE_SUFFIX = ".txt";
  117. public static final String URL_FILE_SUFFIX = ".url";
  118. public static final String WEBLOC_FILE_SUFFIX = ".webloc";
  119. public static final String DESKTOP_FILE_SUFFIX = ".desktop";
  120. private AccountManager mAccountManager;
  121. private Stack<String> mParents;
  122. private ArrayList<Parcelable> mStreamsToUpload;
  123. private String mUploadPath;
  124. private OCFile mFile;
  125. private SyncBroadcastReceiver mSyncBroadcastReceiver;
  126. private boolean mSyncInProgress = false;
  127. private final static int REQUEST_CODE__SETUP_ACCOUNT = REQUEST_CODE__LAST_SHARED + 1;
  128. private final static String KEY_PARENTS = "PARENTS";
  129. private final static String KEY_FILE = "FILE";
  130. private boolean mUploadFromTmpFile = false;
  131. private String mSubjectText;
  132. private String mExtraText;
  133. private final static String FILENAME_ENCODING = "UTF-8";
  134. private LinearLayout mEmptyListContainer;
  135. private TextView mEmptyListMessage;
  136. private TextView mEmptyListHeadline;
  137. private ImageView mEmptyListIcon;
  138. private ProgressBar mEmptyListProgress;
  139. @Override
  140. protected void onCreate(Bundle savedInstanceState) {
  141. prepareStreamsToUpload();
  142. if (savedInstanceState == null) {
  143. mParents = new Stack<>();
  144. } else {
  145. mParents = (Stack<String>) savedInstanceState.getSerializable(KEY_PARENTS);
  146. mFile = savedInstanceState.getParcelable(KEY_FILE);
  147. }
  148. super.onCreate(savedInstanceState);
  149. // Listen for sync messages
  150. IntentFilter syncIntentFilter = new IntentFilter(RefreshFolderOperation.
  151. EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
  152. syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
  153. mSyncBroadcastReceiver = new SyncBroadcastReceiver();
  154. registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
  155. // Init Fragment without UI to retain AsyncTask across configuration changes
  156. FragmentManager fm = getSupportFragmentManager();
  157. TaskRetainerFragment taskRetainerFragment =
  158. (TaskRetainerFragment) fm.findFragmentByTag(TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT);
  159. if (taskRetainerFragment == null) {
  160. taskRetainerFragment = new TaskRetainerFragment();
  161. fm.beginTransaction()
  162. .add(taskRetainerFragment, TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT).commit();
  163. } // else, Fragment already created and retained across configuration change
  164. }
  165. @Override
  166. protected void setAccount(Account account, boolean savedAccount) {
  167. if (somethingToUpload()) {
  168. mAccountManager = (AccountManager) getSystemService(Context.ACCOUNT_SERVICE);
  169. Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAccountType());
  170. if (accounts.length == 0) {
  171. Log_OC.i(TAG, "No ownCloud account is available");
  172. DialogNoAccount dialog = new DialogNoAccount();
  173. dialog.show(getSupportFragmentManager(), null);
  174. } else {
  175. if (!savedAccount) {
  176. setAccount(accounts[0]);
  177. }
  178. }
  179. } else {
  180. showErrorDialog(
  181. R.string.uploader_error_message_no_file_to_upload,
  182. R.string.uploader_error_title_no_file_to_upload
  183. );
  184. }
  185. super.setAccount(account, savedAccount);
  186. }
  187. private void showAccountChooserDialog() {
  188. DialogMultipleAccount dialog = new DialogMultipleAccount();
  189. dialog.show(getSupportFragmentManager(), null);
  190. }
  191. @Override
  192. protected void onAccountSet(boolean stateWasRecovered) {
  193. super.onAccountSet(mAccountWasRestored);
  194. initTargetFolder();
  195. populateDirectoryList();
  196. }
  197. @Override
  198. protected void onSaveInstanceState(Bundle outState) {
  199. Log_OC.d(TAG, "onSaveInstanceState() start");
  200. super.onSaveInstanceState(outState);
  201. outState.putSerializable(KEY_PARENTS, mParents);
  202. outState.putParcelable(KEY_FILE, mFile);
  203. outState.putParcelable(FileActivity.EXTRA_ACCOUNT, getAccount());
  204. Log_OC.d(TAG, "onSaveInstanceState() end");
  205. }
  206. @Override
  207. protected void onDestroy(){
  208. if (mSyncBroadcastReceiver != null) {
  209. unregisterReceiver(mSyncBroadcastReceiver);
  210. }
  211. super.onDestroy();
  212. }
  213. public static class DialogNoAccount extends DialogFragment {
  214. @Override
  215. public Dialog onCreateDialog(Bundle savedInstanceState) {
  216. AlertDialog.Builder builder = new Builder(getActivity());
  217. builder.setIcon(R.drawable.ic_warning);
  218. builder.setTitle(R.string.uploader_wrn_no_account_title);
  219. builder.setMessage(String.format(
  220. getString(R.string.uploader_wrn_no_account_text),
  221. getString(R.string.app_name)));
  222. builder.setCancelable(false);
  223. builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
  224. @Override
  225. public void onClick(DialogInterface dialog, int which) {
  226. // using string value since in API7 this
  227. // constant is not defined
  228. // in API7 < this constant is defined in
  229. // Settings.ADD_ACCOUNT_SETTINGS
  230. // and Settings.EXTRA_AUTHORITIES
  231. Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
  232. intent.putExtra("authorities", new String[]{MainApp.getAuthTokenType()});
  233. startActivityForResult(intent, REQUEST_CODE__SETUP_ACCOUNT);
  234. }
  235. });
  236. builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
  237. @Override
  238. public void onClick(DialogInterface dialog, int which) {
  239. getActivity().finish();
  240. }
  241. });
  242. return builder.create();
  243. }
  244. }
  245. public static class DialogMultipleAccount extends DialogFragment {
  246. private AccountListAdapter mAccountListAdapter;
  247. private Drawable mTintedCheck;
  248. @NonNull
  249. @Override
  250. public Dialog onCreateDialog(Bundle savedInstanceState) {
  251. final ReceiveExternalFilesActivity parent = (ReceiveExternalFilesActivity) getActivity();
  252. AlertDialog.Builder builder = new Builder(parent);
  253. mTintedCheck = DrawableCompat.wrap(ContextCompat.getDrawable(parent,
  254. R.drawable.ic_account_circle_white_18dp));
  255. int tint = ThemeUtils.primaryColor();
  256. DrawableCompat.setTint(mTintedCheck, tint);
  257. mAccountListAdapter = new AccountListAdapter(parent, getAccountListItems(parent), mTintedCheck);
  258. builder.setTitle(R.string.common_choose_account);
  259. builder.setAdapter(mAccountListAdapter, new OnClickListener() {
  260. @Override
  261. public void onClick(DialogInterface dialog, int which) {
  262. final ReceiveExternalFilesActivity parent = (ReceiveExternalFilesActivity) getActivity();
  263. parent.setAccount(parent.mAccountManager.getAccountsByType(MainApp.getAccountType())[which], false);
  264. parent.onAccountSet(parent.mAccountWasRestored);
  265. dialog.dismiss();
  266. }
  267. });
  268. builder.setCancelable(true);
  269. return builder.create();
  270. }
  271. /**
  272. * creates the account list items list including the add-account action in case multiaccount_support is enabled.
  273. *
  274. * @return list of account list items
  275. */
  276. private ArrayList<AccountListItem> getAccountListItems(ReceiveExternalFilesActivity activity) {
  277. Account[] accountList = activity.mAccountManager.getAccountsByType(MainApp.getAccountType());
  278. ArrayList<AccountListItem> adapterAccountList = new ArrayList<>(accountList.length);
  279. for (Account account : accountList) {
  280. adapterAccountList.add(new AccountListItem(account));
  281. }
  282. return adapterAccountList;
  283. }
  284. }
  285. public static class DialogInputUploadFilename extends DialogFragment {
  286. private static final String KEY_SUBJECT_TEXT = "SUBJECT_TEXT";
  287. private static final String KEY_EXTRA_TEXT = "EXTRA_TEXT";
  288. private static final int CATEGORY_URL = 1;
  289. private static final int CATEGORY_MAPS_URL = 2;
  290. private List<String> mFilenameBase;
  291. private List<String> mFilenameSuffix;
  292. private List<String> mText;
  293. private int mFileCategory;
  294. private Spinner mSpinner;
  295. public static DialogInputUploadFilename newInstance(String subjectText, String extraText) {
  296. DialogInputUploadFilename dialog = new DialogInputUploadFilename();
  297. Bundle args = new Bundle();
  298. args.putString(KEY_SUBJECT_TEXT, subjectText);
  299. args.putString(KEY_EXTRA_TEXT, extraText);
  300. dialog.setArguments(args);
  301. return dialog;
  302. }
  303. @NonNull
  304. @Override
  305. public Dialog onCreateDialog(Bundle savedInstanceState) {
  306. mFilenameBase = new ArrayList<>();
  307. mFilenameSuffix = new ArrayList<>();
  308. mText = new ArrayList<>();
  309. String subjectText = getArguments().getString(KEY_SUBJECT_TEXT);
  310. String extraText = getArguments().getString(KEY_EXTRA_TEXT);
  311. LayoutInflater layout = LayoutInflater.from(getActivity().getBaseContext());
  312. View view = layout.inflate(R.layout.upload_file_dialog, null);
  313. ArrayAdapter<String> adapter
  314. = new ArrayAdapter<>(getActivity().getBaseContext(), android.R.layout.simple_spinner_item);
  315. adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  316. int selectPos = 0;
  317. String filename = renameSafeFilename(subjectText);
  318. if (filename == null) {
  319. filename = "";
  320. }
  321. adapter.add(getString(R.string.upload_file_dialog_filetype_snippet_text));
  322. mText.add(extraText);
  323. mFilenameBase.add(filename);
  324. mFilenameSuffix.add(TEXT_FILE_SUFFIX);
  325. if (isIntentStartWithUrl(extraText)) {
  326. String str = getString(R.string.upload_file_dialog_filetype_internet_shortcut);
  327. mText.add(internetShortcutUrlText(extraText));
  328. mFilenameBase.add(filename);
  329. mFilenameSuffix.add(URL_FILE_SUFFIX);
  330. adapter.add(String.format(str,URL_FILE_SUFFIX));
  331. mText.add(internetShortcutWeblocText(extraText));
  332. mFilenameBase.add(filename);
  333. mFilenameSuffix.add(WEBLOC_FILE_SUFFIX);
  334. adapter.add(String.format(str,WEBLOC_FILE_SUFFIX));
  335. mText.add(internetShortcutDesktopText(extraText, filename));
  336. mFilenameBase.add(filename);
  337. mFilenameSuffix.add(DESKTOP_FILE_SUFFIX);
  338. adapter.add(String.format(str,DESKTOP_FILE_SUFFIX));
  339. selectPos = PreferenceManager.getUploadUrlFileExtensionUrlSelectedPos(getActivity());
  340. mFileCategory = CATEGORY_URL;
  341. } else if (isIntentFromGoogleMap(subjectText, extraText)) {
  342. String str = getString(R.string.upload_file_dialog_filetype_googlemap_shortcut);
  343. String texts[] = extraText.split("\n");
  344. mText.add(internetShortcutUrlText(texts[2]));
  345. mFilenameBase.add(texts[0]);
  346. mFilenameSuffix.add(URL_FILE_SUFFIX);
  347. adapter.add(String.format(str,URL_FILE_SUFFIX));
  348. mText.add(internetShortcutWeblocText(texts[2]));
  349. mFilenameBase.add(texts[0]);
  350. mFilenameSuffix.add(WEBLOC_FILE_SUFFIX);
  351. adapter.add(String.format(str,WEBLOC_FILE_SUFFIX));
  352. mText.add(internetShortcutDesktopText(texts[2], texts[0]));
  353. mFilenameBase.add(texts[0]);
  354. mFilenameSuffix.add(DESKTOP_FILE_SUFFIX);
  355. adapter.add(String.format(str,DESKTOP_FILE_SUFFIX));
  356. selectPos = PreferenceManager.getUploadMapFileExtensionUrlSelectedPos(getActivity());
  357. mFileCategory = CATEGORY_MAPS_URL;
  358. }
  359. final EditText userInput = (EditText) view.findViewById(R.id.user_input);
  360. setFilename(userInput, selectPos);
  361. userInput.requestFocus();
  362. final Spinner spinner = (Spinner) view.findViewById(R.id.file_type);
  363. setupSpinner(adapter, selectPos, userInput, spinner);
  364. if (adapter.getCount() == 1) {
  365. TextView label = (TextView) view.findViewById(R.id.label_file_type);
  366. label.setVisibility(View.GONE);
  367. spinner.setVisibility(View.GONE);
  368. }
  369. mSpinner = spinner;
  370. Dialog filenameDialog = createFilenameDialog(view, userInput, spinner);
  371. filenameDialog.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
  372. return filenameDialog;
  373. }
  374. private void setupSpinner(ArrayAdapter<String> adapter, int selectPos, final EditText userInput, Spinner spinner) {
  375. spinner.setAdapter(adapter);
  376. spinner.setSelection(selectPos, false);
  377. spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
  378. @Override
  379. public void onItemSelected(AdapterView parent, View view, int position, long id) {
  380. Spinner spinner = (Spinner) parent;
  381. int selectPos = spinner.getSelectedItemPosition();
  382. setFilename(userInput, selectPos);
  383. saveSelection(selectPos);
  384. }
  385. @Override
  386. public void onNothingSelected(AdapterView<?> parent) {
  387. // nothing to do
  388. }
  389. });
  390. }
  391. @NonNull
  392. private Dialog createFilenameDialog(View view, final EditText userInput, final Spinner spinner) {
  393. Builder builder = new Builder(getActivity());
  394. builder.setView(view);
  395. builder.setTitle(R.string.upload_file_dialog_title);
  396. builder.setPositiveButton(R.string.common_ok, new OnClickListener() {
  397. public void onClick(DialogInterface dialog,int id) {
  398. int selectPos = spinner.getSelectedItemPosition();
  399. // verify if file name has suffix
  400. String filename = userInput.getText().toString();
  401. String suffix = mFilenameSuffix.get(selectPos);
  402. if (!filename.endsWith(suffix)){
  403. filename += suffix;
  404. }
  405. File file = createTempFile("tmp.tmp", mText.get(selectPos));
  406. if (file == null) {
  407. getActivity().finish();
  408. }
  409. String tmpname = file.getAbsolutePath();
  410. ((ReceiveExternalFilesActivity)getActivity()).uploadFile(tmpname, filename);
  411. }
  412. });
  413. builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
  414. public void onClick(DialogInterface dialog,int id) {
  415. dialog.cancel();
  416. }
  417. });
  418. return builder.create();
  419. }
  420. public void onPause() {
  421. hideSpinnerDropDown(mSpinner);
  422. super.onPause();
  423. }
  424. private void saveSelection(int selectPos) {
  425. switch (mFileCategory) {
  426. case CATEGORY_URL:
  427. PreferenceManager.setUploadUrlFileExtensionUrlSelectedPos(getActivity(), selectPos);
  428. break;
  429. case CATEGORY_MAPS_URL:
  430. PreferenceManager.setUploadMapFileExtensionUrlSelectedPos(getActivity(), selectPos);
  431. break;
  432. default:
  433. Log_OC.d(TAG, "Simple text snippet only: no selection to be persisted");
  434. break;
  435. }
  436. }
  437. private void hideSpinnerDropDown(Spinner spinner) {
  438. try {
  439. Method method = Spinner.class.getDeclaredMethod("onDetachedFromWindow");
  440. method.setAccessible(true);
  441. method.invoke(spinner);
  442. } catch (Exception e) {
  443. Log_OC.e(TAG, "onDetachedFromWindow", e);
  444. }
  445. }
  446. private void setFilename(EditText inputText, int selectPos)
  447. {
  448. String filename = mFilenameBase.get(selectPos) + mFilenameSuffix.get(selectPos);
  449. inputText.setText(filename);
  450. int selectionStart = 0;
  451. int extensionStart = filename.lastIndexOf(".");
  452. int selectionEnd = (extensionStart >= 0) ? extensionStart : filename.length();
  453. if (selectionEnd >= 0) {
  454. inputText.setSelection(
  455. Math.min(selectionStart, selectionEnd),
  456. Math.max(selectionStart, selectionEnd));
  457. }
  458. }
  459. private boolean isIntentFromGoogleMap(String subjectText, String extraText) {
  460. String texts[] = extraText.split("\n");
  461. if (texts.length != 3)
  462. return false;
  463. if (texts[0].length() == 0 || !subjectText.equals(texts[0]))
  464. return false;
  465. return texts[2].startsWith("https://goo.gl/maps/");
  466. }
  467. private boolean isIntentStartWithUrl(String extraText) {
  468. return (extraText.startsWith("http://") || extraText.startsWith("https://"));
  469. }
  470. @Nullable
  471. private String renameSafeFilename(String filename) {
  472. String safeFilename = filename;
  473. safeFilename = safeFilename.replaceAll("[?]", "_");
  474. safeFilename = safeFilename.replaceAll("\"", "_");
  475. safeFilename = safeFilename.replaceAll("/", "_");
  476. safeFilename = safeFilename.replaceAll("<", "_");
  477. safeFilename = safeFilename.replaceAll(">", "_");
  478. safeFilename = safeFilename.replaceAll("[*]", "_");
  479. safeFilename = safeFilename.replaceAll("[|]", "_");
  480. safeFilename = safeFilename.replaceAll(";", "_");
  481. safeFilename = safeFilename.replaceAll("=", "_");
  482. safeFilename = safeFilename.replaceAll(",", "_");
  483. try {
  484. int maxLength = 128;
  485. if (safeFilename.getBytes(FILENAME_ENCODING).length > maxLength) {
  486. safeFilename = new String(safeFilename.getBytes(FILENAME_ENCODING), 0, maxLength, FILENAME_ENCODING);
  487. }
  488. } catch (UnsupportedEncodingException e) {
  489. Log_OC.e(TAG, "rename failed ", e);
  490. return null;
  491. }
  492. return safeFilename;
  493. }
  494. private String internetShortcutUrlText(String url) {
  495. return "[InternetShortcut]\r\n" +
  496. "URL=" + url + "\r\n";
  497. }
  498. private String internetShortcutWeblocText(String url) {
  499. return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
  500. "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" +
  501. "<plist version=\"1.0\">\n" +
  502. "<dict>\n" +
  503. "<key>URL</key>\n" +
  504. "<string>" + url + "</string>\n" +
  505. "</dict>\n" +
  506. "</plist>\n";
  507. }
  508. private String internetShortcutDesktopText(String url, String filename) {
  509. return "[Desktop Entry]\n" +
  510. "Encoding=UTF-8\n" +
  511. "Name=" + filename + "\n" +
  512. "Type=Link\n" +
  513. "URL=" + url + "\n" +
  514. "Icon=text-html";
  515. }
  516. @Nullable
  517. private File createTempFile(String filename, String text) {
  518. File file = new File(getActivity().getCacheDir(), filename);
  519. FileWriter fw = null;
  520. try {
  521. fw = new FileWriter(file);
  522. fw.write(text);
  523. } catch (IOException e) {
  524. Log_OC.d(TAG, "Error ", e);
  525. return null;
  526. } finally {
  527. if (fw != null) {
  528. try {
  529. fw.close();
  530. } catch (IOException e) {
  531. Log_OC.d(TAG, "Error closing file writer ", e);
  532. }
  533. }
  534. }
  535. return file;
  536. }
  537. }
  538. @Override
  539. public void onBackPressed() {
  540. if (mParents.size() <= 1) {
  541. super.onBackPressed();
  542. } else {
  543. mParents.pop();
  544. String full_path = generatePath(mParents);
  545. startSyncFolderOperation(getStorageManager().getFileByPath(full_path));
  546. populateDirectoryList();
  547. }
  548. }
  549. @Override
  550. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  551. // click on folder in the list
  552. Log_OC.d(TAG, "on item click");
  553. Vector<OCFile> tmpfiles = getStorageManager().getFolderContent(mFile , false);
  554. sortFileList(tmpfiles);
  555. if (tmpfiles.size() <= 0) {
  556. return;
  557. }
  558. // filter on dirtype
  559. Vector<OCFile> files = new Vector<>();
  560. for (OCFile f : tmpfiles) {
  561. files.add(f);
  562. }
  563. if (files.size() < position) {
  564. throw new IndexOutOfBoundsException("Incorrect item selected");
  565. }
  566. if (files.get(position).isFolder()){
  567. OCFile folderToEnter = files.get(position);
  568. startSyncFolderOperation(folderToEnter);
  569. mParents.push(folderToEnter.getFileName());
  570. populateDirectoryList();
  571. }
  572. }
  573. @Override
  574. public void onClick(View v) {
  575. // click on button
  576. switch (v.getId()) {
  577. case R.id.uploader_choose_folder:
  578. mUploadPath = ""; // first element in mParents is root dir, represented by "";
  579. // init mUploadPath with "/" results in a "//" prefix
  580. for (String p : mParents) {
  581. mUploadPath += p + OCFile.PATH_SEPARATOR;
  582. }
  583. if (mUploadFromTmpFile){
  584. DialogInputUploadFilename dialog = DialogInputUploadFilename.newInstance(mSubjectText, mExtraText);
  585. dialog.show(getSupportFragmentManager(), null);
  586. } else {
  587. Log_OC.d(TAG, "Uploading file to dir " + mUploadPath);
  588. uploadFiles();
  589. }
  590. break;
  591. case R.id.uploader_cancel:
  592. finish();
  593. break;
  594. default:
  595. throw new IllegalArgumentException("Wrong element clicked");
  596. }
  597. }
  598. @Override
  599. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  600. super.onActivityResult(requestCode, resultCode, data);
  601. Log_OC.i(TAG, "result received. req: " + requestCode + " res: " + resultCode);
  602. if (requestCode == REQUEST_CODE__SETUP_ACCOUNT) {
  603. if (resultCode == RESULT_CANCELED) {
  604. finish();
  605. }
  606. Account[] accounts = mAccountManager.getAccountsByType(MainApp.getAuthTokenType());
  607. if (accounts.length == 0) {
  608. DialogNoAccount dialog = new DialogNoAccount();
  609. dialog.show(getSupportFragmentManager(), null);
  610. } else {
  611. // there is no need for checking for is there more then one
  612. // account at this point
  613. // since account setup can set only one account at time
  614. setAccount(accounts[0]);
  615. populateDirectoryList();
  616. }
  617. }
  618. }
  619. private void setupActionBarSubtitle() {
  620. if (isHaveMultipleAccount()) {
  621. ActionBar actionBar = getSupportActionBar();
  622. if(actionBar != null){
  623. actionBar.setSubtitle(getAccount().name);
  624. }
  625. }
  626. }
  627. private void populateDirectoryList() {
  628. setContentView(R.layout.uploader_layout);
  629. setupEmptyList();
  630. setupToolbar();
  631. ActionBar actionBar = getSupportActionBar();
  632. setupActionBarSubtitle();
  633. ListView mListView = (ListView) findViewById(android.R.id.list);
  634. String current_dir = mParents.peek();
  635. if ("".equals(current_dir)) {
  636. actionBar.setTitle(getString(R.string.uploader_top_message));
  637. } else {
  638. actionBar.setTitle(current_dir);
  639. }
  640. boolean notRoot = (mParents.size() > 1);
  641. actionBar.setDisplayHomeAsUpEnabled(notRoot);
  642. actionBar.setHomeButtonEnabled(notRoot);
  643. String full_path = generatePath(mParents);
  644. Log_OC.d(TAG, "Populating view with content of : " + full_path);
  645. mFile = getStorageManager().getFileByPath(full_path);
  646. if (mFile != null) {
  647. Vector<OCFile> files = getStorageManager().getFolderContent(mFile, false);
  648. if (files.size() == 0) {
  649. setMessageForEmptyList(
  650. R.string.file_list_empty_headline,
  651. R.string.empty,
  652. R.drawable.ic_list_empty_upload,
  653. true
  654. );
  655. } else {
  656. mEmptyListContainer.setVisibility(View.GONE);
  657. sortFileList(files);
  658. List<HashMap<String, Object>> data = new LinkedList<>();
  659. for (OCFile f : files) {
  660. HashMap<String, Object> h = new HashMap<>();
  661. h.put("dirname", f);
  662. data.add(h);
  663. }
  664. UploaderAdapter sa = new UploaderAdapter(this,
  665. data,
  666. R.layout.uploader_list_item_layout,
  667. new String[]{"dirname"},
  668. new int[]{R.id.filename},
  669. getStorageManager(), getAccount());
  670. mListView.setAdapter(sa);
  671. }
  672. Button btnChooseFolder = (Button) findViewById(R.id.uploader_choose_folder);
  673. btnChooseFolder.setOnClickListener(this);
  674. btnChooseFolder.getBackground().setColorFilter(ThemeUtils.primaryColor(getAccount()),
  675. PorterDuff.Mode.SRC_ATOP);
  676. if (getSupportActionBar() != null) {
  677. getSupportActionBar().setBackgroundDrawable(new ColorDrawable(
  678. ThemeUtils.primaryColor(getAccount())));
  679. }
  680. ThemeUtils.colorStatusBar(this, ThemeUtils.primaryDarkColor(getAccount()));
  681. ThemeUtils.colorToolbarProgressBar(this, ThemeUtils.primaryColor(getAccount()));
  682. Button btnNewFolder = (Button) findViewById(R.id.uploader_cancel);
  683. btnNewFolder.setOnClickListener(this);
  684. mListView.setOnItemClickListener(this);
  685. }
  686. }
  687. protected void setupEmptyList() {
  688. mEmptyListContainer = (LinearLayout) findViewById(R.id.empty_list_view);
  689. mEmptyListMessage = (TextView) findViewById(R.id.empty_list_view_text);
  690. mEmptyListHeadline = (TextView) findViewById(R.id.empty_list_view_headline);
  691. mEmptyListIcon = (ImageView) findViewById(R.id.empty_list_icon);
  692. mEmptyListProgress = (ProgressBar) findViewById(R.id.empty_list_progress);
  693. mEmptyListProgress.getIndeterminateDrawable().setColorFilter(ThemeUtils.primaryColor(),
  694. PorterDuff.Mode.SRC_IN);
  695. }
  696. public void setMessageForEmptyList(@StringRes final int headline, @StringRes final int message,
  697. @DrawableRes final int icon, final boolean tintIcon) {
  698. new Handler(Looper.getMainLooper()).post(new Runnable() {
  699. @Override
  700. public void run() {
  701. if (mEmptyListContainer != null && mEmptyListMessage != null) {
  702. mEmptyListHeadline.setText(headline);
  703. mEmptyListMessage.setText(message);
  704. if (tintIcon) {
  705. mEmptyListIcon.setImageDrawable(ThemeUtils.tintDrawable(icon, ThemeUtils.primaryColor()));
  706. }
  707. mEmptyListIcon.setVisibility(View.VISIBLE);
  708. mEmptyListProgress.setVisibility(View.GONE);
  709. mEmptyListMessage.setVisibility(View.VISIBLE);
  710. }
  711. }
  712. });
  713. }
  714. @Override
  715. public void onSavedCertificate() {
  716. startSyncFolderOperation(getCurrentDir());
  717. }
  718. private void startSyncFolderOperation(OCFile folder) {
  719. long currentSyncTime = System.currentTimeMillis();
  720. mSyncInProgress = true;
  721. // perform folder synchronization
  722. RemoteOperation synchFolderOp = new RefreshFolderOperation( folder,
  723. currentSyncTime,
  724. false,
  725. false,
  726. false,
  727. getStorageManager(),
  728. getAccount(),
  729. getApplicationContext()
  730. );
  731. synchFolderOp.execute(getAccount(), this, null, null);
  732. }
  733. private Vector<OCFile> sortFileList(Vector<OCFile> files) {
  734. // Read sorting order, default to sort by name ascending
  735. FileStorageUtils.mSortOrder = PreferenceManager.getSortOrder(this);
  736. FileStorageUtils.mSortAscending = PreferenceManager.getSortAscending(this);
  737. return FileStorageUtils.sortOcFolder(files);
  738. }
  739. private String generatePath(Stack<String> dirs) {
  740. String full_path = "";
  741. for (String a : dirs) {
  742. full_path += a + "/";
  743. }
  744. return full_path;
  745. }
  746. private void prepareStreamsToUpload() {
  747. Intent intent = getIntent();
  748. if (intent.getAction().equals(Intent.ACTION_SEND)) {
  749. mStreamsToUpload = new ArrayList<>();
  750. mStreamsToUpload.add(intent.getParcelableExtra(Intent.EXTRA_STREAM));
  751. } else if (intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) {
  752. mStreamsToUpload = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
  753. }
  754. if (mStreamsToUpload == null || mStreamsToUpload.get(0) == null) {
  755. mStreamsToUpload = null;
  756. saveTextsFromIntent(intent);
  757. }
  758. }
  759. private void saveTextsFromIntent(Intent intent) {
  760. if (!intent.getType().equals("text/plain")) {
  761. return;
  762. }
  763. mUploadFromTmpFile = true;
  764. mSubjectText = intent.getStringExtra(Intent.EXTRA_SUBJECT);
  765. if (mSubjectText == null) {
  766. mSubjectText = intent.getStringExtra(Intent.EXTRA_TITLE);
  767. if (mSubjectText == null) {
  768. mSubjectText = DateFormat.format("yyyyMMdd_kkmmss", Calendar.getInstance()).toString();
  769. }
  770. }
  771. mExtraText = intent.getStringExtra(Intent.EXTRA_TEXT);
  772. }
  773. private boolean somethingToUpload() {
  774. return (mStreamsToUpload != null && mStreamsToUpload.size() > 0 && mStreamsToUpload.get(0) != null ||
  775. mUploadFromTmpFile);
  776. }
  777. public void uploadFile(String tmpname, String filename) {
  778. FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
  779. requester.uploadNewFile(
  780. getBaseContext(),
  781. getAccount(),
  782. tmpname,
  783. mFile.getRemotePath() + filename,
  784. FileUploader.LOCAL_BEHAVIOUR_COPY,
  785. null,
  786. true,
  787. UploadFileOperation.CREATED_BY_USER,
  788. false,
  789. false
  790. );
  791. finish();
  792. }
  793. public void uploadFiles() {
  794. UriUploader uploader = new UriUploader(
  795. this,
  796. mStreamsToUpload,
  797. mUploadPath,
  798. getAccount(),
  799. FileUploader.LOCAL_BEHAVIOUR_FORGET,
  800. true, // Show waiting dialog while file is being copied from private storage
  801. this // Copy temp task listener
  802. );
  803. UriUploader.UriUploaderResultCode resultCode = uploader.uploadUris();
  804. // Save the path to shared preferences; even if upload is not possible, user chose the folder
  805. PreferenceManager.setLastUploadPath(this, mUploadPath);
  806. if (resultCode == UriUploader.UriUploaderResultCode.OK) {
  807. finish();
  808. } else {
  809. int messageResTitle = R.string.uploader_error_title_file_cannot_be_uploaded;
  810. int messageResId = R.string.common_error_unknown;
  811. if (resultCode == UriUploader.UriUploaderResultCode.ERROR_NO_FILE_TO_UPLOAD) {
  812. messageResId = R.string.uploader_error_message_no_file_to_upload;
  813. messageResTitle = R.string.uploader_error_title_no_file_to_upload;
  814. } else if (resultCode == UriUploader.UriUploaderResultCode.ERROR_READ_PERMISSION_NOT_GRANTED) {
  815. messageResId = R.string.uploader_error_message_read_permission_not_granted;
  816. } else if (resultCode == UriUploader.UriUploaderResultCode.ERROR_UNKNOWN) {
  817. messageResId = R.string.common_error_unknown;
  818. }
  819. showErrorDialog(
  820. messageResId,
  821. messageResTitle
  822. );
  823. }
  824. }
  825. @Override
  826. public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
  827. super.onRemoteOperationFinish(operation, result);
  828. if (operation instanceof CreateFolderOperation) {
  829. onCreateFolderOperationFinish((CreateFolderOperation) operation, result);
  830. }
  831. }
  832. /**
  833. * Updates the view associated to the activity after the finish of an operation
  834. * trying create a new folder
  835. *
  836. * @param operation Creation operation performed.
  837. * @param result Result of the creation.
  838. */
  839. private void onCreateFolderOperationFinish(CreateFolderOperation operation,
  840. RemoteOperationResult result) {
  841. if (result.isSuccess()) {
  842. String remotePath = operation.getRemotePath().substring(0, operation.getRemotePath().length() - 1);
  843. String newFolder = remotePath.substring(remotePath.lastIndexOf('/') + 1);
  844. mParents.push(newFolder);
  845. populateDirectoryList();
  846. } else {
  847. try {
  848. Toast msg = Toast.makeText(this,
  849. ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources()),
  850. Toast.LENGTH_LONG);
  851. msg.show();
  852. } catch (NotFoundException e) {
  853. Log_OC.e(TAG, "Error while trying to show fail message ", e);
  854. }
  855. }
  856. }
  857. /**
  858. * Loads the target folder initialize shown to the user.
  859. * <p/>
  860. * The target account has to be chosen before this method is called.
  861. */
  862. private void initTargetFolder() {
  863. if (getStorageManager() == null) {
  864. throw new IllegalStateException("Do not call this method before " +
  865. "initializing mStorageManager");
  866. }
  867. String lastPath = PreferenceManager.getLastUploadPath(this);
  868. // "/" equals root-directory
  869. if ("/".equals(lastPath)) {
  870. mParents.add("");
  871. } else {
  872. String[] dir_names = lastPath.split("/");
  873. mParents.clear();
  874. for (String dir : dir_names) {
  875. mParents.add(dir);
  876. }
  877. }
  878. //Make sure that path still exists, if it doesn't pop the stack and try the previous path
  879. while (!getStorageManager().fileExists(generatePath(mParents)) && mParents.size() > 1) {
  880. mParents.pop();
  881. }
  882. }
  883. private boolean isHaveMultipleAccount() {
  884. return mAccountManager.getAccountsByType(MainApp.getAccountType()).length > 1;
  885. }
  886. @Override
  887. public boolean onCreateOptionsMenu(Menu menu) {
  888. MenuInflater inflater = getMenuInflater();
  889. inflater.inflate(R.menu.receive_file_menu, menu);
  890. if (!isHaveMultipleAccount()) {
  891. MenuItem switchAccountMenu = menu.findItem(R.id.action_switch_account);
  892. switchAccountMenu.setVisible(false);
  893. }
  894. return true;
  895. }
  896. @Override
  897. public boolean onOptionsItemSelected(MenuItem item) {
  898. boolean retval = true;
  899. switch (item.getItemId()) {
  900. case R.id.action_create_dir:
  901. CreateFolderDialogFragment dialog = CreateFolderDialogFragment.newInstance(mFile);
  902. dialog.show(
  903. getSupportFragmentManager(),
  904. CreateFolderDialogFragment.CREATE_FOLDER_FRAGMENT);
  905. break;
  906. case android.R.id.home:
  907. if ((mParents.size() > 1)) {
  908. onBackPressed();
  909. }
  910. break;
  911. case R.id.action_switch_account:
  912. showAccountChooserDialog();
  913. break;
  914. default:
  915. retval = super.onOptionsItemSelected(item);
  916. break;
  917. }
  918. return retval;
  919. }
  920. private OCFile getCurrentFolder(){
  921. OCFile file = mFile;
  922. if (file != null) {
  923. if (file.isFolder()) {
  924. return file;
  925. } else if (getStorageManager() != null) {
  926. return getStorageManager().getFileByPath(file.getParentRemotePath());
  927. }
  928. }
  929. return null;
  930. }
  931. private void browseToRoot() {
  932. OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
  933. mFile = root;
  934. startSyncFolderOperation(root);
  935. }
  936. private class SyncBroadcastReceiver extends BroadcastReceiver {
  937. /**
  938. * {@link BroadcastReceiver} to enable syncing feedback in UI
  939. */
  940. @Override
  941. public void onReceive(Context context, Intent intent) {
  942. try {
  943. String event = intent.getAction();
  944. Log_OC.d(TAG, "Received broadcast " + event);
  945. String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
  946. String synchFolderRemotePath =
  947. intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
  948. RemoteOperationResult synchResult = (RemoteOperationResult)
  949. DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
  950. boolean sameAccount = (getAccount() != null &&
  951. accountName.equals(getAccount().name) && getStorageManager() != null);
  952. if (sameAccount) {
  953. if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
  954. mSyncInProgress = true;
  955. } else {
  956. OCFile currentFile = (mFile == null) ? null :
  957. getStorageManager().getFileByPath(mFile.getRemotePath());
  958. OCFile currentDir = (getCurrentFolder() == null) ? null :
  959. getStorageManager().getFileByPath(getCurrentFolder().getRemotePath());
  960. if (currentDir == null) {
  961. // current folder was removed from the server
  962. Toast.makeText(context,
  963. String.format(
  964. getString(R.string.sync_current_folder_was_removed),
  965. getCurrentFolder().getFileName()),
  966. Toast.LENGTH_LONG)
  967. .show();
  968. browseToRoot();
  969. } else {
  970. if (currentFile == null && !mFile.isFolder()) {
  971. // currently selected file was removed in the server, and now we know it
  972. currentFile = currentDir;
  973. }
  974. if (currentDir.getRemotePath().equals(synchFolderRemotePath)) {
  975. populateDirectoryList();
  976. }
  977. mFile = currentFile;
  978. }
  979. mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
  980. !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
  981. if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.
  982. equals(event) &&
  983. /// TODO refactor and make common
  984. synchResult != null && !synchResult.isSuccess()) {
  985. if(synchResult.getCode() == ResultCode.UNAUTHORIZED ||
  986. (synchResult.isException() && synchResult.getException()
  987. instanceof AuthenticatorException)) {
  988. requestCredentialsUpdate(context);
  989. } else if(RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(synchResult.getCode())) {
  990. showUntrustedCertDialog(synchResult);
  991. }
  992. }
  993. }
  994. removeStickyBroadcast(intent);
  995. Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
  996. }
  997. } catch (RuntimeException e) {
  998. // avoid app crashes after changing the serial id of RemoteOperationResult
  999. // in owncloud library with broadcast notifications pending to process
  1000. removeStickyBroadcast(intent);
  1001. DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
  1002. }
  1003. }
  1004. }
  1005. /**
  1006. * Process the result of CopyAndUploadContentUrisTask
  1007. */
  1008. @Override
  1009. public void onTmpFilesCopied(ResultCode result) {
  1010. dismissLoadingDialog();
  1011. finish();
  1012. }
  1013. /**
  1014. * Show an error dialog, forcing the user to click a single button to exit the activity
  1015. *
  1016. * @param messageResId Resource id of the message to show in the dialog.
  1017. * @param messageResTitle Resource id of the title to show in the dialog. 0 to show default alert message.
  1018. * -1 to show no title.
  1019. */
  1020. private void showErrorDialog(int messageResId, int messageResTitle) {
  1021. ConfirmationDialogFragment errorDialog = ConfirmationDialogFragment.newInstance(
  1022. messageResId,
  1023. new String[]{getString(R.string.app_name)}, // see uploader_error_message_* in strings.xml
  1024. messageResTitle,
  1025. R.string.common_back,
  1026. -1,
  1027. -1
  1028. );
  1029. errorDialog.setCancelable(false);
  1030. errorDialog.setOnConfirmationListener(
  1031. new ConfirmationDialogFragment.ConfirmationDialogFragmentListener() {
  1032. @Override
  1033. public void onConfirmation(String callerTag) {
  1034. finish();
  1035. }
  1036. @Override
  1037. public void onNeutral(String callerTag) {
  1038. // not used at the moment
  1039. }
  1040. @Override
  1041. public void onCancel(String callerTag) {
  1042. // not used at the moment
  1043. }
  1044. }
  1045. );
  1046. errorDialog.show(getSupportFragmentManager(), FTAG_ERROR_FRAGMENT);
  1047. }
  1048. }