FileDisplayActivity.java 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * @author Bartek Przybylski
  5. * @author David A. Velasco
  6. * Copyright (C) 2011 Bartek Przybylski
  7. * Copyright (C) 2016 ownCloud Inc.
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. package com.owncloud.android.ui.activity;
  22. import android.Manifest;
  23. import android.accounts.Account;
  24. import android.accounts.AuthenticatorException;
  25. import android.annotation.TargetApi;
  26. import android.app.Activity;
  27. import android.content.BroadcastReceiver;
  28. import android.content.ComponentName;
  29. import android.content.ContentResolver;
  30. import android.content.Context;
  31. import android.content.DialogInterface;
  32. import android.content.Intent;
  33. import android.content.IntentFilter;
  34. import android.content.ServiceConnection;
  35. import android.content.SharedPreferences;
  36. import android.content.SyncRequest;
  37. import android.content.pm.PackageManager;
  38. import android.content.res.Resources.NotFoundException;
  39. import android.os.Build;
  40. import android.os.Bundle;
  41. import android.os.IBinder;
  42. import android.os.Parcelable;
  43. import android.support.annotation.NonNull;
  44. import android.support.design.widget.BottomNavigationView;
  45. import android.support.design.widget.Snackbar;
  46. import android.support.v4.app.Fragment;
  47. import android.support.v4.app.FragmentManager;
  48. import android.support.v4.app.FragmentTransaction;
  49. import android.support.v4.content.ContextCompat;
  50. import android.support.v4.view.MenuItemCompat;
  51. import android.support.v7.app.AlertDialog;
  52. import android.support.v7.widget.SearchView;
  53. import android.text.TextUtils;
  54. import android.view.Menu;
  55. import android.view.MenuInflater;
  56. import android.view.MenuItem;
  57. import android.view.View;
  58. import android.view.ViewTreeObserver;
  59. import android.widget.EditText;
  60. import android.widget.ImageView;
  61. import com.owncloud.android.MainApp;
  62. import com.owncloud.android.R;
  63. import com.owncloud.android.datamodel.FileDataStorageManager;
  64. import com.owncloud.android.datamodel.OCFile;
  65. import com.owncloud.android.datamodel.VirtualFolderType;
  66. import com.owncloud.android.db.PreferenceManager;
  67. import com.owncloud.android.files.services.FileDownloader;
  68. import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
  69. import com.owncloud.android.files.services.FileUploader;
  70. import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
  71. import com.owncloud.android.lib.common.operations.RemoteOperation;
  72. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  73. import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode;
  74. import com.owncloud.android.lib.common.utils.Log_OC;
  75. import com.owncloud.android.media.MediaService;
  76. import com.owncloud.android.media.MediaServiceBinder;
  77. import com.owncloud.android.operations.CopyFileOperation;
  78. import com.owncloud.android.operations.CreateFolderOperation;
  79. import com.owncloud.android.operations.MoveFileOperation;
  80. import com.owncloud.android.operations.RefreshFolderOperation;
  81. import com.owncloud.android.operations.RemoveFileOperation;
  82. import com.owncloud.android.operations.RenameFileOperation;
  83. import com.owncloud.android.operations.SynchronizeFileOperation;
  84. import com.owncloud.android.operations.UploadFileOperation;
  85. import com.owncloud.android.syncadapter.FileSyncAdapter;
  86. import com.owncloud.android.ui.dialog.SendShareDialog;
  87. import com.owncloud.android.ui.dialog.SortingOrderDialogFragment;
  88. import com.owncloud.android.ui.events.SyncEventFinished;
  89. import com.owncloud.android.ui.events.TokenPushEvent;
  90. import com.owncloud.android.ui.fragment.ExtendedListFragment;
  91. import com.owncloud.android.ui.fragment.FileDetailFragment;
  92. import com.owncloud.android.ui.fragment.FileFragment;
  93. import com.owncloud.android.ui.fragment.OCFileListFragment;
  94. import com.owncloud.android.ui.fragment.TaskRetainerFragment;
  95. import com.owncloud.android.ui.fragment.contactsbackup.ContactListFragment;
  96. import com.owncloud.android.ui.helpers.FileOperationsHelper;
  97. import com.owncloud.android.ui.helpers.UriUploader;
  98. import com.owncloud.android.ui.preview.PreviewImageActivity;
  99. import com.owncloud.android.ui.preview.PreviewImageFragment;
  100. import com.owncloud.android.ui.preview.PreviewMediaFragment;
  101. import com.owncloud.android.ui.preview.PreviewTextFragment;
  102. import com.owncloud.android.ui.preview.PreviewVideoActivity;
  103. import com.owncloud.android.utils.DataHolderUtil;
  104. import com.owncloud.android.utils.DisplayUtils;
  105. import com.owncloud.android.utils.ErrorMessageAdapter;
  106. import com.owncloud.android.utils.FileSortOrder;
  107. import com.owncloud.android.utils.MimeTypeUtil;
  108. import com.owncloud.android.utils.PermissionUtil;
  109. import com.owncloud.android.utils.PushUtils;
  110. import com.owncloud.android.utils.ThemeUtils;
  111. import org.greenrobot.eventbus.EventBus;
  112. import org.greenrobot.eventbus.Subscribe;
  113. import org.greenrobot.eventbus.ThreadMode;
  114. import org.parceler.Parcels;
  115. import java.io.File;
  116. import java.util.ArrayList;
  117. import java.util.Collection;
  118. import static com.owncloud.android.db.PreferenceManager.getSortOrder;
  119. /**
  120. * Displays, what files the user has available in his ownCloud. This is the main view.
  121. */
  122. public class FileDisplayActivity extends HookActivity
  123. implements FileFragment.ContainerActivity,
  124. OnEnforceableRefreshListener, SortingOrderDialogFragment.OnSortingOrderListener,
  125. SendShareDialog.SendShareDialogDownloader {
  126. private SyncBroadcastReceiver mSyncBroadcastReceiver;
  127. private UploadFinishReceiver mUploadFinishReceiver;
  128. private DownloadFinishReceiver mDownloadFinishReceiver;
  129. private RemoteOperationResult mLastSslUntrustedServerResult = null;
  130. private boolean mDualPane;
  131. private View mLeftFragmentContainer;
  132. private View mRightFragmentContainer;
  133. private static final String KEY_WAITING_TO_PREVIEW = "WAITING_TO_PREVIEW";
  134. private static final String KEY_SYNC_IN_PROGRESS = "SYNC_IN_PROGRESS";
  135. private static final String KEY_WAITING_TO_SEND = "WAITING_TO_SEND";
  136. private static final String KEY_SEARCH_QUERY = "KEY_SEARCH_QUERY";
  137. public static final String ACTION_DETAILS = "com.owncloud.android.ui.activity.action.DETAILS";
  138. public static final String DRAWER_MENU_ID = "DRAWER_MENU_ID";
  139. public static final int REQUEST_CODE__SELECT_CONTENT_FROM_APPS = REQUEST_CODE__LAST_SHARED + 1;
  140. public static final int REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM = REQUEST_CODE__LAST_SHARED + 2;
  141. public static final int REQUEST_CODE__MOVE_FILES = REQUEST_CODE__LAST_SHARED + 3;
  142. public static final int REQUEST_CODE__COPY_FILES = REQUEST_CODE__LAST_SHARED + 4;
  143. protected static final long DELAY_TO_REQUEST_REFRESH_OPERATION_LATER = DELAY_TO_REQUEST_OPERATIONS_LATER + 350;
  144. private static final String TAG = FileDisplayActivity.class.getSimpleName();
  145. private static final String TAG_LIST_OF_FILES = "LIST_OF_FILES";
  146. public static final String TAG_SECOND_FRAGMENT = "SECOND_FRAGMENT";
  147. public static final String TEXT_PREVIEW = "TEXT_PREVIEW";
  148. private OCFile mWaitingToPreview;
  149. private boolean mSyncInProgress = false;
  150. private OCFile mWaitingToSend;
  151. private Collection<MenuItem> mDrawerMenuItemstoShowHideList;
  152. private MediaServiceBinder mMediaServiceBinder = null;
  153. private MediaServiceConnection mMediaServiceConnection = null;
  154. private String searchQuery;
  155. private SearchView searchView;
  156. @Override
  157. protected void onCreate(Bundle savedInstanceState) {
  158. Log_OC.v(TAG, "onCreate() start");
  159. super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account
  160. // is valid
  161. /// Load of saved instance state
  162. if (savedInstanceState != null) {
  163. mWaitingToPreview = savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
  164. mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
  165. mWaitingToSend = savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND);
  166. searchQuery = savedInstanceState.getString(KEY_SEARCH_QUERY);
  167. } else {
  168. mWaitingToPreview = null;
  169. mSyncInProgress = false;
  170. mWaitingToSend = null;
  171. }
  172. /// USER INTERFACE
  173. // Inflate and set the layout view
  174. setContentView(R.layout.files);
  175. // setup toolbar
  176. setupToolbar();
  177. // setup drawer
  178. if (MainApp.isOnlyOnDevice()) {
  179. setupDrawer(R.id.nav_on_device);
  180. } else {
  181. setupDrawer(R.id.nav_all_files);
  182. }
  183. mDualPane = getResources().getBoolean(R.bool.large_land_layout);
  184. mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
  185. mRightFragmentContainer = findViewById(R.id.right_fragment_container);
  186. // Action bar setup
  187. getSupportActionBar().setHomeButtonEnabled(true);
  188. // Init Fragment without UI to retain AsyncTask across configuration changes
  189. FragmentManager fm = getSupportFragmentManager();
  190. TaskRetainerFragment taskRetainerFragment =
  191. (TaskRetainerFragment) fm.findFragmentByTag(TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT);
  192. if (taskRetainerFragment == null) {
  193. taskRetainerFragment = new TaskRetainerFragment();
  194. fm.beginTransaction()
  195. .add(taskRetainerFragment, TaskRetainerFragment.FTAG_TASK_RETAINER_FRAGMENT).commit();
  196. } // else, Fragment already created and retained across configuration change
  197. }
  198. @Override
  199. protected void onPostCreate(Bundle savedInstanceState) {
  200. super.onPostCreate(savedInstanceState);
  201. if (!PermissionUtil.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
  202. // Check if we should show an explanation
  203. if (PermissionUtil.shouldShowRequestPermissionRationale(this,
  204. Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
  205. // Show explanation to the user and then request permission
  206. Snackbar snackbar = Snackbar.make(findViewById(R.id.ListLayout), R.string.permission_storage_access,
  207. Snackbar.LENGTH_INDEFINITE)
  208. .setAction(R.string.common_ok, new View.OnClickListener() {
  209. @Override
  210. public void onClick(View v) {
  211. PermissionUtil.requestWriteExternalStoreagePermission(FileDisplayActivity.this);
  212. }
  213. });
  214. ThemeUtils.colorSnackbar(this, snackbar);
  215. snackbar.show();
  216. } else {
  217. // No explanation needed, request the permission.
  218. PermissionUtil.requestWriteExternalStoreagePermission(this);
  219. }
  220. }
  221. if (getIntent().getParcelableExtra(OCFileListFragment.SEARCH_EVENT) != null) {
  222. switchToSearchFragment(savedInstanceState);
  223. int menuId = getIntent().getIntExtra(DRAWER_MENU_ID, -1);
  224. if (menuId != -1) {
  225. setupDrawer(menuId);
  226. }
  227. } else {
  228. createMinFragments(savedInstanceState);
  229. refreshList(true);
  230. }
  231. setIndeterminate(mSyncInProgress);
  232. // always AFTER setContentView(...) in onCreate(); to work around bug in its implementation
  233. upgradeNotificationForInstantUpload();
  234. }
  235. private Activity getActivity() {
  236. return this;
  237. }
  238. /**
  239. * For Android 7+.
  240. * Opens a pop up info for the new instant upload and disabled the old instant upload.
  241. */
  242. private void upgradeNotificationForInstantUpload() {
  243. // check for Android 6+ if legacy instant upload is activated --> disable + show info
  244. if (PreferenceManager.instantPictureUploadEnabled(this) ||
  245. PreferenceManager.instantVideoUploadEnabled(this)) {
  246. // remove legacy shared preferences
  247. SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
  248. editor.remove("instant_uploading")
  249. .remove("instant_video_uploading")
  250. .remove("instant_upload_path")
  251. .remove("instant_upload_path_use_subfolders")
  252. .remove("instant_upload_on_wifi")
  253. .remove("instant_upload_on_charging")
  254. .remove("instant_video_upload_path")
  255. .remove("instant_video_upload_path_use_subfolders")
  256. .remove("instant_video_upload_on_wifi")
  257. .remove("instant_video_uploading")
  258. .remove("instant_video_upload_on_charging")
  259. .remove("prefs_instant_behaviour").apply();
  260. // show info pop-up
  261. new AlertDialog.Builder(this, R.style.Theme_ownCloud_Dialog)
  262. .setTitle(R.string.drawer_synced_folders)
  263. .setMessage(R.string.synced_folders_new_info)
  264. .setPositiveButton(R.string.drawer_open, new DialogInterface.OnClickListener() {
  265. public void onClick(DialogInterface dialog, int which) {
  266. // show instant upload
  267. Intent syncedFoldersIntent = new Intent(getApplicationContext(), SyncedFoldersActivity.class);
  268. dialog.dismiss();
  269. startActivity(syncedFoldersIntent);
  270. }
  271. })
  272. .setNegativeButton(R.string.drawer_close, new DialogInterface.OnClickListener() {
  273. public void onClick(DialogInterface dialog, int which) {
  274. dialog.dismiss();
  275. }
  276. })
  277. .setIcon(R.drawable.nav_synced_folders)
  278. .show();
  279. }
  280. }
  281. @Override
  282. public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
  283. @NonNull int[] grantResults) {
  284. switch (requestCode) {
  285. case PermissionUtil.PERMISSIONS_WRITE_EXTERNAL_STORAGE: {
  286. // If request is cancelled, result arrays are empty.
  287. if (grantResults.length > 0
  288. && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  289. // permission was granted
  290. EventBus.getDefault().post(new TokenPushEvent());
  291. refreshList(true);
  292. // toggle on is save since this is the only scenario this code gets accessed
  293. } else {
  294. // permission denied --> do nothing
  295. return;
  296. }
  297. return;
  298. }
  299. default:
  300. super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  301. }
  302. }
  303. /**
  304. * Called when the ownCloud {@link Account} associated to the Activity was just updated.
  305. */
  306. @Override
  307. protected void onAccountSet(boolean stateWasRecovered) {
  308. super.onAccountSet(stateWasRecovered);
  309. if (getAccount() != null) {
  310. /// Check whether the 'main' OCFile handled by the Activity is contained in the
  311. // current Account
  312. OCFile file = getFile();
  313. // get parent from path
  314. String parentPath = "";
  315. if (file != null) {
  316. if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
  317. // upload in progress - right now, files are not inserted in the local
  318. // cache until the upload is successful get parent from path
  319. parentPath = file.getRemotePath().substring(0,
  320. file.getRemotePath().lastIndexOf(file.getFileName()));
  321. if (getStorageManager().getFileByPath(parentPath) == null) {
  322. file = null; // not able to know the directory where the file is uploading
  323. }
  324. } else {
  325. file = getStorageManager().getFileByPath(file.getRemotePath());
  326. // currentDir = null if not in the current Account
  327. }
  328. }
  329. if (file == null) {
  330. // fall back to root folder
  331. file = getStorageManager().getFileByPath(OCFile.ROOT_PATH); // never returns null
  332. }
  333. setFile(file);
  334. if (mAccountWasSet) {
  335. setAccountInDrawer(getAccount());
  336. setupDrawer();
  337. }
  338. if (!stateWasRecovered) {
  339. Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
  340. initFragmentsWithFile();
  341. if (file.isFolder() && TextUtils.isEmpty(searchQuery)) {
  342. startSyncFolderOperation(file, false);
  343. }
  344. } else {
  345. updateFragmentsVisibility(!file.isFolder());
  346. updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
  347. }
  348. }
  349. }
  350. private void switchToSearchFragment(Bundle savedInstanceState) {
  351. if (savedInstanceState == null) {
  352. OCFileListFragment listOfFiles = new OCFileListFragment();
  353. Bundle args = new Bundle();
  354. args.putParcelable(OCFileListFragment.SEARCH_EVENT,
  355. getIntent().getParcelableExtra(OCFileListFragment.SEARCH_EVENT));
  356. args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
  357. listOfFiles.setArguments(args);
  358. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  359. transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
  360. transaction.commit();
  361. } else {
  362. getSupportFragmentManager().findFragmentByTag(TAG_LIST_OF_FILES);
  363. }
  364. }
  365. private void createMinFragments(Bundle savedInstanceState) {
  366. if (savedInstanceState == null) {
  367. OCFileListFragment listOfFiles = new OCFileListFragment();
  368. Bundle args = new Bundle();
  369. args.putBoolean(OCFileListFragment.ARG_ALLOW_CONTEXTUAL_ACTIONS, true);
  370. listOfFiles.setArguments(args);
  371. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  372. transaction.add(R.id.left_fragment_container, listOfFiles, TAG_LIST_OF_FILES);
  373. transaction.commit();
  374. } else {
  375. getSupportFragmentManager().findFragmentByTag(TAG_LIST_OF_FILES);
  376. }
  377. }
  378. private void initFragmentsWithFile() {
  379. if (getAccount() != null && getFile() != null) {
  380. /// First fragment
  381. OCFileListFragment listOfFiles = getListOfFilesFragment();
  382. if (listOfFiles != null && TextUtils.isEmpty(searchQuery)) {
  383. listOfFiles.listDirectory(getCurrentDir(), MainApp.isOnlyOnDevice(), false);
  384. } else {
  385. Log_OC.e(TAG, "Still have a chance to lose the initializacion of list fragment >(");
  386. }
  387. /// Second fragment
  388. OCFile file = getFile();
  389. Fragment secondFragment = getSecondFragment();
  390. if (secondFragment == null) {
  391. secondFragment = chooseInitialSecondFragment(file);
  392. }
  393. if (secondFragment != null) {
  394. setSecondFragment(secondFragment);
  395. updateFragmentsVisibility(true);
  396. updateActionBarTitleAndHomeButton(file);
  397. } else {
  398. cleanSecondFragment();
  399. if (file.isDown() && MimeTypeUtil.isVCard(file.getMimetype())) {
  400. startContactListFragment(file);
  401. } else if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) {
  402. startTextPreview(file, false);
  403. }
  404. }
  405. } else {
  406. Log_OC.e(TAG, "initFragments() called with invalid NULLs!");
  407. if (getAccount() == null) {
  408. Log_OC.e(TAG, "\t account is NULL");
  409. }
  410. if (getFile() == null) {
  411. Log_OC.e(TAG, "\t file is NULL");
  412. }
  413. }
  414. }
  415. //Is called with the flag FLAG_ACTIVITY_SINGLE_TOP and set the new file and intent
  416. @Override
  417. protected void onNewIntent(Intent intent) {
  418. super.onNewIntent(intent);
  419. if (intent.getAction() != null && intent.getAction().equalsIgnoreCase(ACTION_DETAILS)) {
  420. setIntent(intent);
  421. setFile(intent.getParcelableExtra(EXTRA_FILE));
  422. }
  423. }
  424. private Fragment chooseInitialSecondFragment(OCFile file) {
  425. Fragment secondFragment = null;
  426. if (file != null && !file.isFolder()) {
  427. if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) {
  428. int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
  429. boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
  430. secondFragment = PreviewMediaFragment.newInstance(file, getAccount(), startPlaybackPosition, autoplay);
  431. } else if (file.isDown() && PreviewTextFragment.canBePreviewed(file)) {
  432. secondFragment = null;
  433. } else {
  434. secondFragment = FileDetailFragment.newInstance(file, getAccount());
  435. }
  436. }
  437. return secondFragment;
  438. }
  439. /**
  440. * Replaces the second fragment managed by the activity with the received as
  441. * a parameter.
  442. * <p/>
  443. * Assumes never will be more than two fragments managed at the same time.
  444. *
  445. * @param fragment New second Fragment to set.
  446. */
  447. private void setSecondFragment(Fragment fragment) {
  448. if (searchView != null) {
  449. searchView.post(new Runnable() {
  450. @Override
  451. public void run() {
  452. searchView.setQuery("", true);
  453. }
  454. });
  455. }
  456. setDrawerIndicatorEnabled(false);
  457. FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
  458. transaction.replace(R.id.right_fragment_container, fragment, TAG_SECOND_FRAGMENT);
  459. transaction.commit();
  460. }
  461. private void updateFragmentsVisibility(boolean existsSecondFragment) {
  462. if (mDualPane) {
  463. if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
  464. mLeftFragmentContainer.setVisibility(View.VISIBLE);
  465. }
  466. if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
  467. mRightFragmentContainer.setVisibility(View.VISIBLE);
  468. }
  469. } else if (existsSecondFragment) {
  470. if (mLeftFragmentContainer.getVisibility() != View.GONE) {
  471. mLeftFragmentContainer.setVisibility(View.GONE);
  472. }
  473. if (mRightFragmentContainer.getVisibility() != View.VISIBLE) {
  474. mRightFragmentContainer.setVisibility(View.VISIBLE);
  475. }
  476. } else {
  477. if (mLeftFragmentContainer.getVisibility() != View.VISIBLE) {
  478. mLeftFragmentContainer.setVisibility(View.VISIBLE);
  479. }
  480. if (mRightFragmentContainer.getVisibility() != View.GONE) {
  481. mRightFragmentContainer.setVisibility(View.GONE);
  482. }
  483. }
  484. }
  485. private OCFileListFragment getListOfFilesFragment() {
  486. Fragment listOfFiles = getSupportFragmentManager().findFragmentByTag(
  487. FileDisplayActivity.TAG_LIST_OF_FILES);
  488. if (listOfFiles != null) {
  489. return (OCFileListFragment) listOfFiles;
  490. }
  491. Log_OC.e(TAG, "Access to unexisting list of files fragment!!");
  492. return null;
  493. }
  494. public FileFragment getSecondFragment() {
  495. Fragment second = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT);
  496. if (second != null) {
  497. return (FileFragment) second;
  498. }
  499. return null;
  500. }
  501. protected void cleanSecondFragment() {
  502. Fragment second = getSecondFragment();
  503. if (second != null) {
  504. FragmentTransaction tr = getSupportFragmentManager().beginTransaction();
  505. tr.remove(second);
  506. tr.commit();
  507. }
  508. updateFragmentsVisibility(false);
  509. updateActionBarTitleAndHomeButton(null);
  510. }
  511. public void refreshListOfFilesFragment(boolean fromSearch) {
  512. OCFileListFragment fileListFragment = getListOfFilesFragment();
  513. if (fileListFragment != null) {
  514. fileListFragment.listDirectory(MainApp.isOnlyOnDevice(), fromSearch);
  515. setupToolbar();
  516. }
  517. }
  518. public void resetSearchView() {
  519. OCFileListFragment fileListFragment = getListOfFilesFragment();
  520. if (fileListFragment != null) {
  521. fileListFragment.setSearchFragment(false);
  522. }
  523. }
  524. protected void refreshSecondFragment(String downloadEvent, String downloadedRemotePath,
  525. boolean success) {
  526. FileFragment secondFragment = getSecondFragment();
  527. boolean waitedPreview = (mWaitingToPreview != null &&
  528. mWaitingToPreview.getRemotePath().equals(downloadedRemotePath));
  529. if (secondFragment instanceof FileDetailFragment) {
  530. FileDetailFragment detailsFragment = (FileDetailFragment) secondFragment;
  531. OCFile fileInFragment = detailsFragment.getFile();
  532. if (fileInFragment != null &&
  533. !downloadedRemotePath.equals(fileInFragment.getRemotePath())) {
  534. // the user browsed to other file ; forget the automatic preview
  535. mWaitingToPreview = null;
  536. } else if (downloadEvent.equals(FileDownloader.getDownloadAddedMessage())) {
  537. // grant that the right panel updates the progress bar
  538. detailsFragment.listenForTransferProgress();
  539. detailsFragment.updateFileDetails(true, false);
  540. } else if (downloadEvent.equals(FileDownloader.getDownloadFinishMessage())) {
  541. // update the right panel
  542. boolean detailsFragmentChanged = false;
  543. if (waitedPreview) {
  544. if (success) {
  545. mWaitingToPreview = getStorageManager().getFileById(
  546. mWaitingToPreview.getFileId()); // update the file from database,
  547. // for the local storage path
  548. if (PreviewMediaFragment.canBePreviewed(mWaitingToPreview)) {
  549. startMediaPreview(mWaitingToPreview, 0, true, true);
  550. detailsFragmentChanged = true;
  551. } else if (MimeTypeUtil.isVCard(mWaitingToPreview.getMimetype())) {
  552. startContactListFragment(mWaitingToPreview);
  553. detailsFragmentChanged = true;
  554. } else if (PreviewTextFragment.canBePreviewed(mWaitingToPreview)) {
  555. startTextPreview(mWaitingToPreview, true);
  556. detailsFragmentChanged = true;
  557. } else {
  558. getFileOperationsHelper().openFile(mWaitingToPreview);
  559. }
  560. }
  561. mWaitingToPreview = null;
  562. }
  563. if (!detailsFragmentChanged) {
  564. detailsFragment.updateFileDetails(false, (success));
  565. }
  566. }
  567. }
  568. }
  569. @Override
  570. public boolean onPrepareOptionsMenu(Menu menu) {
  571. boolean drawerOpen = isDrawerOpen();
  572. for (MenuItem menuItem : mDrawerMenuItemstoShowHideList) {
  573. menuItem.setVisible(!drawerOpen);
  574. }
  575. return super.onPrepareOptionsMenu(menu);
  576. }
  577. @Override
  578. public boolean onCreateOptionsMenu(Menu menu) {
  579. MenuInflater inflater = getMenuInflater();
  580. inflater.inflate(R.menu.main_menu, menu);
  581. menu.findItem(R.id.action_create_dir).setVisible(false);
  582. menu.findItem(R.id.action_select_all).setVisible(false);
  583. final MenuItem item = menu.findItem(R.id.action_search);
  584. searchView = (SearchView) MenuItemCompat.getActionView(item);
  585. // hacky as no default way is provided
  586. int fontColor = ThemeUtils.fontColor();
  587. EditText editText = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
  588. editText.setHintTextColor(fontColor);
  589. editText.setTextColor(fontColor);
  590. ImageView searchClose = searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
  591. searchClose.setColorFilter(ThemeUtils.fontColor());
  592. // populate list of menu items to show/hide when drawer is opened/closed
  593. mDrawerMenuItemstoShowHideList = new ArrayList<>(4);
  594. mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_sort));
  595. mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_sync_account));
  596. mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_switch_view));
  597. mDrawerMenuItemstoShowHideList.add(menu.findItem(R.id.action_search));
  598. //focus the SearchView
  599. if (!TextUtils.isEmpty(searchQuery)) {
  600. searchView.post(new Runnable() {
  601. @Override
  602. public void run() {
  603. searchView.setIconified(false);
  604. searchView.setQuery(searchQuery, true);
  605. searchView.clearFocus();
  606. }
  607. });
  608. }
  609. final View mSearchEditFrame = searchView
  610. .findViewById(android.support.v7.appcompat.R.id.search_edit_frame);
  611. searchView.setOnCloseListener(new SearchView.OnCloseListener() {
  612. @Override
  613. public boolean onClose() {
  614. if (TextUtils.isEmpty(searchView.getQuery().toString())) {
  615. searchView.onActionViewCollapsed();
  616. setDrawerIndicatorEnabled(isDrawerIndicatorAvailable()); // order matters
  617. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  618. mDrawerToggle.syncState();
  619. } else {
  620. searchView.post(new Runnable() {
  621. @Override
  622. public void run() {
  623. searchView.setQuery("", true);
  624. }
  625. });
  626. }
  627. return true;
  628. }
  629. });
  630. ViewTreeObserver vto = mSearchEditFrame.getViewTreeObserver();
  631. vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
  632. int oldVisibility = -1;
  633. @Override
  634. public void onGlobalLayout() {
  635. int currentVisibility = mSearchEditFrame.getVisibility();
  636. if (currentVisibility != oldVisibility) {
  637. if (currentVisibility == View.VISIBLE) {
  638. setDrawerIndicatorEnabled(false);
  639. }
  640. oldVisibility = currentVisibility;
  641. }
  642. }
  643. });
  644. return true;
  645. }
  646. @Override
  647. public boolean onOptionsItemSelected(MenuItem item) {
  648. boolean retval = true;
  649. switch (item.getItemId()) {
  650. case R.id.action_sync_account: {
  651. startSynchronization();
  652. break;
  653. }
  654. case android.R.id.home: {
  655. FileFragment second = getSecondFragment();
  656. OCFile currentDir = getCurrentDir();
  657. if (isDrawerOpen()) {
  658. closeDrawer();
  659. } else if ((currentDir != null && currentDir.getParentId() != 0) ||
  660. (second != null && second.getFile() != null) || isSearchOpen()) {
  661. onBackPressed();
  662. } else {
  663. openDrawer();
  664. }
  665. break;
  666. }
  667. case R.id.action_sort: {
  668. FragmentManager fm = getSupportFragmentManager();
  669. FragmentTransaction ft = fm.beginTransaction();
  670. ft.addToBackStack(null);
  671. SortingOrderDialogFragment mSortingOrderDialogFragment = SortingOrderDialogFragment.newInstance(
  672. getSortOrder(this, getListOfFilesFragment().getCurrentFile()));
  673. mSortingOrderDialogFragment.show(ft, SortingOrderDialogFragment.SORTING_ORDER_FRAGMENT);
  674. break;
  675. }
  676. case R.id.action_switch_view: {
  677. if (isGridView()) {
  678. item.setTitle(getString(R.string.action_switch_grid_view));
  679. item.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_view_module));
  680. getListOfFilesFragment().setListAsPreferred();
  681. } else {
  682. item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
  683. item.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_view_list));
  684. getListOfFilesFragment().setGridAsPreferred();
  685. }
  686. break;
  687. }
  688. case R.id.action_select_all: {
  689. getListOfFilesFragment().selectAllFiles(true);
  690. break;
  691. }
  692. default:
  693. retval = super.onOptionsItemSelected(item);
  694. break;
  695. }
  696. return retval;
  697. }
  698. private void startSynchronization() {
  699. Log_OC.d(TAG, "Got to start sync");
  700. if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
  701. Log_OC.d(TAG, "Canceling all syncs for " + MainApp.getAuthority());
  702. ContentResolver.cancelSync(null, MainApp.getAuthority());
  703. // cancel the current synchronizations of any ownCloud account
  704. Bundle bundle = new Bundle();
  705. bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
  706. bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
  707. Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
  708. MainApp.getAuthority());
  709. ContentResolver.requestSync(
  710. getAccount(),
  711. MainApp.getAuthority(), bundle);
  712. } else {
  713. Log_OC.d(TAG, "Requesting sync for " + getAccount().name + " at " +
  714. MainApp.getAuthority() + " with new API");
  715. SyncRequest.Builder builder = new SyncRequest.Builder();
  716. builder.setSyncAdapter(getAccount(), MainApp.getAuthority());
  717. builder.setExpedited(true);
  718. builder.setManual(true);
  719. builder.syncOnce();
  720. // Fix bug in Android Lollipop when you click on refresh the whole account
  721. Bundle extras = new Bundle();
  722. builder.setExtras(extras);
  723. SyncRequest request = builder.build();
  724. ContentResolver.requestSync(request);
  725. }
  726. }
  727. /**
  728. * Called, when the user selected something for uploading
  729. */
  730. @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
  731. @Override
  732. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  733. if (requestCode == REQUEST_CODE__SELECT_CONTENT_FROM_APPS &&
  734. (resultCode == RESULT_OK ||
  735. resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE)) {
  736. requestUploadOfContentFromApps(data, resultCode);
  737. } else if (requestCode == REQUEST_CODE__SELECT_FILES_FROM_FILE_SYSTEM &&
  738. (resultCode == RESULT_OK ||
  739. resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE ||
  740. resultCode == UploadFilesActivity.RESULT_OK_AND_DO_NOTHING ||
  741. resultCode == UploadFilesActivity.RESULT_OK_AND_DELETE)) {
  742. requestUploadOfFilesFromFileSystem(data, resultCode);
  743. } else if (requestCode == REQUEST_CODE__MOVE_FILES && resultCode == RESULT_OK) {
  744. final Intent fData = data;
  745. getHandler().postDelayed(
  746. new Runnable() {
  747. @Override
  748. public void run() {
  749. requestMoveOperation(fData);
  750. }
  751. },
  752. DELAY_TO_REQUEST_OPERATIONS_LATER
  753. );
  754. } else if (requestCode == REQUEST_CODE__COPY_FILES && resultCode == RESULT_OK) {
  755. final Intent fData = data;
  756. getHandler().postDelayed(
  757. new Runnable() {
  758. @Override
  759. public void run() {
  760. requestCopyOperation(fData);
  761. }
  762. },
  763. DELAY_TO_REQUEST_OPERATIONS_LATER
  764. );
  765. } else {
  766. super.onActivityResult(requestCode, resultCode, data);
  767. }
  768. }
  769. private void requestUploadOfFilesFromFileSystem(Intent data, int resultCode) {
  770. String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES);
  771. if (filePaths != null) {
  772. String[] remotePaths = new String[filePaths.length];
  773. String remotePathBase = getCurrentDir().getRemotePath();
  774. for (int j = 0; j < remotePaths.length; j++) {
  775. remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName();
  776. }
  777. // default, as fallback
  778. int behaviour = FileUploader.LOCAL_BEHAVIOUR_FORGET;
  779. switch (resultCode) {
  780. case UploadFilesActivity.RESULT_OK_AND_MOVE:
  781. behaviour = FileUploader.LOCAL_BEHAVIOUR_MOVE;
  782. break;
  783. case UploadFilesActivity.RESULT_OK_AND_DELETE:
  784. behaviour = FileUploader.LOCAL_BEHAVIOUR_DELETE;
  785. break;
  786. case UploadFilesActivity.RESULT_OK_AND_DO_NOTHING:
  787. behaviour = FileUploader.LOCAL_BEHAVIOUR_FORGET;
  788. break;
  789. }
  790. FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
  791. requester.uploadNewFile(
  792. this,
  793. getAccount(),
  794. filePaths,
  795. remotePaths,
  796. null, // MIME type will be detected from file name
  797. behaviour,
  798. false, // do not create parent folder if not existent
  799. UploadFileOperation.CREATED_BY_USER,
  800. false,
  801. false
  802. );
  803. } else {
  804. Log_OC.d(TAG, "User clicked on 'Update' with no selection");
  805. DisplayUtils.showSnackMessage(this, R.string.filedisplay_no_file_selected);
  806. }
  807. }
  808. private void requestUploadOfContentFromApps(Intent contentIntent, int resultCode) {
  809. ArrayList<Parcelable> streamsToUpload = new ArrayList<>();
  810. //getClipData is only supported on api level 16+, Jelly Bean
  811. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN &&
  812. contentIntent.getClipData() != null &&
  813. contentIntent.getClipData().getItemCount() > 0) {
  814. for (int i = 0; i < contentIntent.getClipData().getItemCount(); i++) {
  815. streamsToUpload.add(contentIntent.getClipData().getItemAt(i).getUri());
  816. }
  817. } else {
  818. streamsToUpload.add(contentIntent.getData());
  819. }
  820. int behaviour = (resultCode == UploadFilesActivity.RESULT_OK_AND_MOVE) ? FileUploader.LOCAL_BEHAVIOUR_MOVE :
  821. FileUploader.LOCAL_BEHAVIOUR_COPY;
  822. OCFile currentDir = getCurrentDir();
  823. String remotePath = (currentDir != null) ? currentDir.getRemotePath() : OCFile.ROOT_PATH;
  824. UriUploader uploader = new UriUploader(
  825. this,
  826. streamsToUpload,
  827. remotePath,
  828. getAccount(),
  829. behaviour,
  830. false, // Not show waiting dialog while file is being copied from private storage
  831. null // Not needed copy temp task listener
  832. );
  833. uploader.uploadUris();
  834. }
  835. /**
  836. * Request the operation for moving the file/folder from one path to another
  837. *
  838. * @param data Intent received
  839. */
  840. private void requestMoveOperation(Intent data) {
  841. OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
  842. ArrayList<OCFile> files = data.getParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES);
  843. getFileOperationsHelper().moveFiles(files, folderToMoveAt);
  844. }
  845. /**
  846. * Request the operation for copying the file/folder from one path to another
  847. *
  848. * @param data Intent received
  849. */
  850. private void requestCopyOperation(Intent data) {
  851. OCFile folderToMoveAt = data.getParcelableExtra(FolderPickerActivity.EXTRA_FOLDER);
  852. ArrayList<OCFile> files = data.getParcelableArrayListExtra(FolderPickerActivity.EXTRA_FILES);
  853. getFileOperationsHelper().copyFiles(files, folderToMoveAt);
  854. }
  855. private boolean isSearchOpen() {
  856. if (searchView == null) {
  857. return false;
  858. } else {
  859. View mSearchEditFrame = searchView.findViewById(android.support.v7.appcompat.R.id.search_edit_frame);
  860. return (mSearchEditFrame != null && mSearchEditFrame.getVisibility() == View.VISIBLE);
  861. }
  862. }
  863. private void revertBottomNavigationBarToAllFiles() {
  864. if (getResources().getBoolean(R.bool.bottom_toolbar_enabled)) {
  865. BottomNavigationView bottomNavigationView = getListOfFilesFragment().getView()
  866. .findViewById(R.id.bottom_navigation_view);
  867. if (bottomNavigationView.getMenu().findItem(R.id.nav_bar_settings).isChecked()) {
  868. bottomNavigationView.getMenu().findItem(R.id.nav_bar_files).setChecked(true);
  869. }
  870. }
  871. }
  872. @Override
  873. public void onBackPressed() {
  874. boolean isFabOpen = isFabOpen();
  875. boolean isDrawerOpen = isDrawerOpen();
  876. boolean isSearchOpen = isSearchOpen();
  877. /*
  878. * BackPressed priority/hierarchy:
  879. * 1. close search view if opened
  880. * 2. close drawer if opened
  881. * 3. close FAB if open (only if drawer isn't open)
  882. * 4. navigate up (only if drawer and FAB aren't open)
  883. */
  884. if (isSearchOpen && searchView != null) {
  885. searchView.setQuery("", true);
  886. searchView.onActionViewCollapsed();
  887. setDrawerIndicatorEnabled(isDrawerIndicatorAvailable());
  888. } else if (isDrawerOpen && isFabOpen) {
  889. // close drawer first
  890. super.onBackPressed();
  891. } else if (isDrawerOpen && !isFabOpen) {
  892. // close drawer
  893. super.onBackPressed();
  894. } else if (!isDrawerOpen && isFabOpen) {
  895. // close fab
  896. getListOfFilesFragment().getFabMain().collapse();
  897. } else {
  898. // all closed
  899. //if PreviewImageActivity called this activity and mDualPane==false then calls PreviewImageActivity again
  900. if ((getIntent().getAction() != null && getIntent().getAction().equalsIgnoreCase(ACTION_DETAILS)) && !mDualPane) {
  901. getIntent().setAction(null);
  902. getIntent().putExtra(EXTRA_FILE, (OCFile) null);
  903. startImagePreview(getFile(), false);
  904. }
  905. OCFileListFragment listOfFiles = getListOfFilesFragment();
  906. if (mDualPane || getSecondFragment() == null) {
  907. OCFile currentDir = getCurrentDir();
  908. if (currentDir == null || currentDir.getParentId() == FileDataStorageManager.ROOT_PARENT_ID) {
  909. finish();
  910. return;
  911. }
  912. if (listOfFiles != null) { // should never be null, indeed
  913. listOfFiles.onBrowseUp();
  914. }
  915. }
  916. if (listOfFiles != null) { // should never be null, indeed
  917. setFile(listOfFiles.getCurrentFile());
  918. }
  919. cleanSecondFragment();
  920. }
  921. }
  922. @Override
  923. protected void onSaveInstanceState(Bundle outState) {
  924. // responsibility of restore is preferred in onCreate() before than in
  925. // onRestoreInstanceState when there are Fragments involved
  926. Log_OC.v(TAG, "onSaveInstanceState() start");
  927. super.onSaveInstanceState(outState);
  928. outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW, mWaitingToPreview);
  929. outState.putBoolean(FileDisplayActivity.KEY_SYNC_IN_PROGRESS, mSyncInProgress);
  930. //outState.putBoolean(FileDisplayActivity.KEY_REFRESH_SHARES_IN_PROGRESS,
  931. // mRefreshSharesInProgress);
  932. outState.putParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND, mWaitingToSend);
  933. if (searchView != null) {
  934. outState.putString(KEY_SEARCH_QUERY, searchView.getQuery().toString());
  935. }
  936. Log_OC.v(TAG, "onSaveInstanceState() end");
  937. }
  938. @Override
  939. protected void onResume() {
  940. Log_OC.v(TAG, "onResume() start");
  941. super.onResume();
  942. OCFile startFile = null;
  943. if (getIntent() != null && getIntent().getParcelableExtra(EXTRA_FILE) != null) {
  944. startFile = getIntent().getParcelableExtra(EXTRA_FILE);
  945. setFile(startFile);
  946. }
  947. revertBottomNavigationBarToAllFiles();
  948. // refresh list of files
  949. if (searchView != null && !TextUtils.isEmpty(searchQuery)) {
  950. searchView.setQuery(searchQuery, true);
  951. } else if (getListOfFilesFragment() != null && !getListOfFilesFragment().getIsSearchFragment()
  952. && startFile == null) {
  953. refreshListOfFilesFragment(false);
  954. } else {
  955. getListOfFilesFragment().listDirectory(startFile, false, false);
  956. updateActionBarTitleAndHomeButton(startFile);
  957. }
  958. // Listen for sync messages
  959. if (getListOfFilesFragment() != null && !getListOfFilesFragment().getIsSearchFragment()) {
  960. IntentFilter syncIntentFilter = new IntentFilter(FileSyncAdapter.EVENT_FULL_SYNC_START);
  961. syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_END);
  962. syncIntentFilter.addAction(FileSyncAdapter.EVENT_FULL_SYNC_FOLDER_CONTENTS_SYNCED);
  963. syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED);
  964. syncIntentFilter.addAction(RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED);
  965. mSyncBroadcastReceiver = new SyncBroadcastReceiver();
  966. registerReceiver(mSyncBroadcastReceiver, syncIntentFilter);
  967. //LocalBroadcastManager.getInstance(this).registerReceiver(mSyncBroadcastReceiver,
  968. // syncIntentFilter);
  969. }
  970. // Listen for upload messages
  971. IntentFilter uploadIntentFilter = new IntentFilter(FileUploader.getUploadFinishMessage());
  972. mUploadFinishReceiver = new UploadFinishReceiver();
  973. registerReceiver(mUploadFinishReceiver, uploadIntentFilter);
  974. // Listen for download messages
  975. IntentFilter downloadIntentFilter = new IntentFilter(
  976. FileDownloader.getDownloadAddedMessage());
  977. downloadIntentFilter.addAction(FileDownloader.getDownloadFinishMessage());
  978. mDownloadFinishReceiver = new DownloadFinishReceiver();
  979. registerReceiver(mDownloadFinishReceiver, downloadIntentFilter);
  980. Log_OC.v(TAG, "onResume() end");
  981. }
  982. @Override
  983. protected void onPause() {
  984. Log_OC.v(TAG, "onPause() start");
  985. if (mSyncBroadcastReceiver != null) {
  986. unregisterReceiver(mSyncBroadcastReceiver);
  987. //LocalBroadcastManager.getInstance(this).unregisterReceiver(mSyncBroadcastReceiver);
  988. mSyncBroadcastReceiver = null;
  989. }
  990. if (mUploadFinishReceiver != null) {
  991. unregisterReceiver(mUploadFinishReceiver);
  992. mUploadFinishReceiver = null;
  993. }
  994. if (mDownloadFinishReceiver != null) {
  995. unregisterReceiver(mDownloadFinishReceiver);
  996. mDownloadFinishReceiver = null;
  997. }
  998. super.onPause();
  999. Log_OC.v(TAG, "onPause() end");
  1000. }
  1001. public boolean isFabOpen() {
  1002. return (getListOfFilesFragment() != null
  1003. && getListOfFilesFragment().getFabMain() != null
  1004. && getListOfFilesFragment().getFabMain().isExpanded());
  1005. }
  1006. @Override
  1007. public void onSortingOrderChosen(FileSortOrder selection) {
  1008. getListOfFilesFragment().sortFiles(selection);
  1009. }
  1010. @Override
  1011. public void downloadFile(OCFile file, String packageName, String activityName) {
  1012. startDownloadForSending(file, OCFileListFragment.DOWNLOAD_SEND, packageName, activityName);
  1013. }
  1014. private class SyncBroadcastReceiver extends BroadcastReceiver {
  1015. /**
  1016. * {@link BroadcastReceiver} to enable syncing feedback in UI
  1017. */
  1018. @Override
  1019. public void onReceive(Context context, Intent intent) {
  1020. try {
  1021. String event = intent.getAction();
  1022. Log_OC.d(TAG, "Received broadcast " + event);
  1023. String accountName = intent.getStringExtra(FileSyncAdapter.EXTRA_ACCOUNT_NAME);
  1024. String synchFolderRemotePath =
  1025. intent.getStringExtra(FileSyncAdapter.EXTRA_FOLDER_PATH);
  1026. RemoteOperationResult synchResult = (RemoteOperationResult)
  1027. DataHolderUtil.getInstance().retrieve(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
  1028. boolean sameAccount = (getAccount() != null &&
  1029. accountName.equals(getAccount().name) && getStorageManager() != null);
  1030. if (sameAccount) {
  1031. if (FileSyncAdapter.EVENT_FULL_SYNC_START.equals(event)) {
  1032. mSyncInProgress = true;
  1033. } else {
  1034. OCFile currentFile = (getFile() == null) ? null :
  1035. getStorageManager().getFileByPath(getFile().getRemotePath());
  1036. OCFile currentDir = (getCurrentDir() == null) ? null :
  1037. getStorageManager().getFileByPath(getCurrentDir().getRemotePath());
  1038. if (currentDir == null) {
  1039. // current folder was removed from the server
  1040. DisplayUtils.showSnackMessage(
  1041. getActivity(),
  1042. R.string.sync_current_folder_was_removed,
  1043. synchFolderRemotePath
  1044. );
  1045. browseToRoot();
  1046. } else {
  1047. if (currentFile == null && !getFile().isFolder()) {
  1048. // currently selected file was removed in the server, and now we
  1049. // know it
  1050. cleanSecondFragment();
  1051. currentFile = currentDir;
  1052. }
  1053. if (currentDir.getRemotePath().equals(synchFolderRemotePath)) {
  1054. OCFileListFragment fileListFragment = getListOfFilesFragment();
  1055. if (fileListFragment != null) {
  1056. fileListFragment.listDirectory(currentDir, MainApp.isOnlyOnDevice(), false);
  1057. }
  1058. }
  1059. setFile(currentFile);
  1060. }
  1061. mSyncInProgress = (!FileSyncAdapter.EVENT_FULL_SYNC_END.equals(event) &&
  1062. !RefreshFolderOperation.EVENT_SINGLE_FOLDER_SHARES_SYNCED.equals(event));
  1063. if (RefreshFolderOperation.EVENT_SINGLE_FOLDER_CONTENTS_SYNCED.equals(event) &&
  1064. synchResult != null && !synchResult.isSuccess()) {
  1065. /// TODO refactor and make common
  1066. if (checkForRemoteOperationError(synchResult)) {
  1067. requestCredentialsUpdate(context);
  1068. } else if (RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED.equals(
  1069. synchResult.getCode())) {
  1070. showUntrustedCertDialog(synchResult);
  1071. }
  1072. }
  1073. removeStickyBroadcast(intent);
  1074. DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
  1075. Log_OC.d(TAG, "Setting progress visibility to " + mSyncInProgress);
  1076. setIndeterminate(mSyncInProgress);
  1077. setBackgroundText();
  1078. }
  1079. }
  1080. if (synchResult != null && synchResult.getCode().equals(
  1081. RemoteOperationResult.ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED)) {
  1082. mLastSslUntrustedServerResult = synchResult;
  1083. }
  1084. } catch (RuntimeException e) {
  1085. // avoid app crashes after changing the serial id of RemoteOperationResult
  1086. // in owncloud library with broadcast notifications pending to process
  1087. removeStickyBroadcast(intent);
  1088. try {
  1089. DataHolderUtil.getInstance().delete(intent.getStringExtra(FileSyncAdapter.EXTRA_RESULT));
  1090. } catch (RuntimeException re) {
  1091. // we did not send this intent, so ignoring
  1092. Log_OC.i(TAG, "Ignoring error deleting data");
  1093. }
  1094. }
  1095. }
  1096. }
  1097. private boolean checkForRemoteOperationError(RemoteOperationResult syncResult) {
  1098. return ResultCode.UNAUTHORIZED.equals(syncResult.getCode()) ||
  1099. (syncResult.isException() && syncResult.getException()
  1100. instanceof AuthenticatorException);
  1101. }
  1102. /**
  1103. * Show a text message on screen view for notifying user if content is
  1104. * loading or folder is empty
  1105. */
  1106. private void setBackgroundText() {
  1107. final OCFileListFragment ocFileListFragment = getListOfFilesFragment();
  1108. if (ocFileListFragment != null) {
  1109. if (mSyncInProgress) {
  1110. ocFileListFragment.setEmptyListLoadingMessage();
  1111. } else {
  1112. ocFileListFragment.setEmptyListMessage(ExtendedListFragment.SearchType.NO_SEARCH);
  1113. }
  1114. } else {
  1115. Log_OC.e(TAG, "OCFileListFragment is null");
  1116. }
  1117. }
  1118. /**
  1119. * Once the file upload has finished -> update view
  1120. */
  1121. private class UploadFinishReceiver extends BroadcastReceiver {
  1122. /**
  1123. * Once the file upload has finished -> update view
  1124. *
  1125. * {@link BroadcastReceiver} to enable upload feedback in UI
  1126. */
  1127. @Override
  1128. public void onReceive(Context context, Intent intent) {
  1129. try {
  1130. String uploadedRemotePath = intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH);
  1131. String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);
  1132. boolean sameAccount = getAccount() != null && accountName.equals(getAccount().name);
  1133. OCFile currentDir = getCurrentDir();
  1134. boolean isDescendant = (currentDir != null) && (uploadedRemotePath != null) &&
  1135. (uploadedRemotePath.startsWith(currentDir.getRemotePath()));
  1136. if (sameAccount && isDescendant) {
  1137. String linkedToRemotePath =
  1138. intent.getStringExtra(FileUploader.EXTRA_LINKED_TO_PATH);
  1139. if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
  1140. refreshListOfFilesFragment(false);
  1141. }
  1142. }
  1143. boolean uploadWasFine = intent.getBooleanExtra(
  1144. FileUploader.EXTRA_UPLOAD_RESULT,
  1145. false);
  1146. boolean renamedInUpload = getFile().getRemotePath().
  1147. equals(intent.getStringExtra(FileUploader.EXTRA_OLD_REMOTE_PATH));
  1148. boolean sameFile = getFile().getRemotePath().equals(uploadedRemotePath) ||
  1149. renamedInUpload;
  1150. FileFragment details = getSecondFragment();
  1151. boolean detailFragmentIsShown = (details instanceof FileDetailFragment);
  1152. if (sameAccount && sameFile && detailFragmentIsShown) {
  1153. if (uploadWasFine) {
  1154. setFile(getStorageManager().getFileByPath(uploadedRemotePath));
  1155. } else {
  1156. //TODO remove upload progress bar after upload failed.
  1157. Log_OC.d(TAG, "Remove upload progress bar after upload failed");
  1158. }
  1159. if (renamedInUpload) {
  1160. String newName = (new File(uploadedRemotePath)).getName();
  1161. DisplayUtils.showSnackMessage(
  1162. getActivity(),
  1163. R.string.filedetails_renamed_in_upload_msg,
  1164. newName
  1165. );
  1166. }
  1167. if (uploadWasFine || getFile().fileExists()) {
  1168. ((FileDetailFragment) details).updateFileDetails(false, true);
  1169. } else {
  1170. cleanSecondFragment();
  1171. }
  1172. // Force the preview if the file is an image or text file
  1173. if (uploadWasFine) {
  1174. OCFile ocFile = getFile();
  1175. if (PreviewImageFragment.canBePreviewed(ocFile)) {
  1176. startImagePreview(getFile(), true);
  1177. } else if (PreviewTextFragment.canBePreviewed(ocFile)) {
  1178. startTextPreview(ocFile, true);
  1179. }
  1180. // TODO what about other kind of previews?
  1181. }
  1182. }
  1183. setIndeterminate(false);
  1184. } finally {
  1185. if (intent != null) {
  1186. removeStickyBroadcast(intent);
  1187. }
  1188. }
  1189. }
  1190. // TODO refactor this receiver, and maybe DownloadFinishReceiver; this method is duplicated :S
  1191. private boolean isAscendant(String linkedToRemotePath) {
  1192. OCFile currentDir = getCurrentDir();
  1193. return (
  1194. currentDir != null &&
  1195. currentDir.getRemotePath().startsWith(linkedToRemotePath)
  1196. );
  1197. }
  1198. }
  1199. /**
  1200. * Class waiting for broadcast events from the {@link FileDownloader} service.
  1201. * <p/>
  1202. * Updates the UI when a download is started or finished, provided that it is relevant for the
  1203. * current folder.
  1204. */
  1205. private class DownloadFinishReceiver extends BroadcastReceiver {
  1206. @Override
  1207. public void onReceive(Context context, Intent intent) {
  1208. try {
  1209. boolean sameAccount = isSameAccount(intent);
  1210. String downloadedRemotePath = intent.getStringExtra(FileDownloader.EXTRA_REMOTE_PATH);
  1211. String downloadBehaviour = intent.getStringExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR);
  1212. boolean isDescendant = isDescendant(downloadedRemotePath);
  1213. if (sameAccount && isDescendant) {
  1214. String linkedToRemotePath = intent.getStringExtra(FileDownloader.EXTRA_LINKED_TO_PATH);
  1215. if (linkedToRemotePath == null || isAscendant(linkedToRemotePath)) {
  1216. refreshListOfFilesFragment(false);
  1217. }
  1218. refreshSecondFragment(
  1219. intent.getAction(),
  1220. downloadedRemotePath,
  1221. intent.getBooleanExtra(FileDownloader.EXTRA_DOWNLOAD_RESULT, false));
  1222. }
  1223. if (mWaitingToSend != null) {
  1224. mWaitingToSend = getStorageManager().getFileByPath(mWaitingToSend.getRemotePath());
  1225. if (mWaitingToSend.isDown() && downloadBehaviour != null) {
  1226. switch (downloadBehaviour) {
  1227. case OCFileListFragment.DOWNLOAD_SEND:
  1228. String packageName = intent.getStringExtra(SendShareDialog.PACKAGE_NAME);
  1229. String activityName = intent.getStringExtra(SendShareDialog.ACTIVITY_NAME);
  1230. sendDownloadedFile(packageName, activityName);
  1231. break;
  1232. default:
  1233. // do nothing
  1234. break;
  1235. }
  1236. }
  1237. }
  1238. } finally {
  1239. if (intent != null) {
  1240. removeStickyBroadcast(intent);
  1241. }
  1242. }
  1243. }
  1244. private boolean isDescendant(String downloadedRemotePath) {
  1245. OCFile currentDir = getCurrentDir();
  1246. return (
  1247. currentDir != null &&
  1248. downloadedRemotePath != null &&
  1249. downloadedRemotePath.startsWith(currentDir.getRemotePath())
  1250. );
  1251. }
  1252. private boolean isAscendant(String linkedToRemotePath) {
  1253. OCFile currentDir = getCurrentDir();
  1254. return (
  1255. currentDir != null &&
  1256. currentDir.getRemotePath().startsWith(linkedToRemotePath)
  1257. );
  1258. }
  1259. private boolean isSameAccount(Intent intent) {
  1260. String accountName = intent.getStringExtra(FileDownloader.ACCOUNT_NAME);
  1261. return (accountName != null && getAccount() != null &&
  1262. accountName.equals(getAccount().name));
  1263. }
  1264. }
  1265. public void browseToRoot() {
  1266. OCFileListFragment listOfFiles = getListOfFilesFragment();
  1267. if (listOfFiles != null) { // should never be null, indeed
  1268. OCFile root = getStorageManager().getFileByPath(OCFile.ROOT_PATH);
  1269. listOfFiles.listDirectory(root, MainApp.isOnlyOnDevice(), false);
  1270. setFile(listOfFiles.getCurrentFile());
  1271. startSyncFolderOperation(root, false);
  1272. }
  1273. cleanSecondFragment();
  1274. }
  1275. /**
  1276. * {@inheritDoc}
  1277. * Updates action bar and second fragment, if in dual pane mode.
  1278. */
  1279. @Override
  1280. public void onBrowsedDownTo(OCFile directory) {
  1281. setFile(directory);
  1282. cleanSecondFragment();
  1283. // Sync Folder
  1284. startSyncFolderOperation(directory, false);
  1285. }
  1286. /**
  1287. * Shows the information of the {@link OCFile} received as a
  1288. * parameter in the second fragment.
  1289. *
  1290. * @param file {@link OCFile} whose details will be shown
  1291. */
  1292. @Override
  1293. public void showDetails(OCFile file) {
  1294. Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
  1295. setSecondFragment(detailFragment);
  1296. updateFragmentsVisibility(true);
  1297. updateActionBarTitleAndHomeButton(file);
  1298. setFile(file);
  1299. }
  1300. @Override
  1301. protected void updateActionBarTitleAndHomeButton(OCFile chosenFile) {
  1302. if (chosenFile == null) {
  1303. chosenFile = getFile(); // if no file is passed, current file decides
  1304. }
  1305. if (mDualPane) {
  1306. // in dual pane mode, keep the focus of title an action bar in the current folder
  1307. super.updateActionBarTitleAndHomeButton(getCurrentDir());
  1308. } else {
  1309. super.updateActionBarTitleAndHomeButton(chosenFile);
  1310. }
  1311. }
  1312. @Override
  1313. public boolean isDrawerIndicatorAvailable() {
  1314. return isRoot(getCurrentDir());
  1315. }
  1316. @Override
  1317. protected ServiceConnection newTransferenceServiceConnection() {
  1318. return new ListServiceConnection();
  1319. }
  1320. /**
  1321. * Defines callbacks for service binding, passed to bindService()
  1322. */
  1323. private class ListServiceConnection implements ServiceConnection {
  1324. @Override
  1325. public void onServiceConnected(ComponentName component, IBinder service) {
  1326. if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
  1327. Log_OC.d(TAG, "Download service connected");
  1328. mDownloaderBinder = (FileDownloaderBinder) service;
  1329. if (mWaitingToPreview != null && getStorageManager() != null) {
  1330. // update the file
  1331. mWaitingToPreview = getStorageManager().getFileById(mWaitingToPreview.getFileId());
  1332. if (mWaitingToPreview != null && !mWaitingToPreview.isDown()) {
  1333. requestForDownload();
  1334. }
  1335. }
  1336. } else if (component.equals(new ComponentName(FileDisplayActivity.this,
  1337. FileUploader.class))) {
  1338. Log_OC.d(TAG, "Upload service connected");
  1339. mUploaderBinder = (FileUploaderBinder) service;
  1340. } else {
  1341. return;
  1342. }
  1343. // a new chance to get the mDownloadBinder through
  1344. // getFileDownloadBinder() - THIS IS A MESS
  1345. OCFileListFragment listOfFiles = getListOfFilesFragment();
  1346. if (listOfFiles != null && (getIntent() == null ||
  1347. (getIntent() != null && getIntent().getParcelableExtra(EXTRA_FILE) == null))) {
  1348. listOfFiles.listDirectory(MainApp.isOnlyOnDevice(), false);
  1349. }
  1350. FileFragment secondFragment = getSecondFragment();
  1351. if (secondFragment instanceof FileDetailFragment) {
  1352. FileDetailFragment detailFragment = (FileDetailFragment) secondFragment;
  1353. detailFragment.listenForTransferProgress();
  1354. detailFragment.updateFileDetails(false, false);
  1355. }
  1356. }
  1357. @Override
  1358. public void onServiceDisconnected(ComponentName component) {
  1359. if (component.equals(new ComponentName(FileDisplayActivity.this, FileDownloader.class))) {
  1360. Log_OC.d(TAG, "Download service disconnected");
  1361. mDownloaderBinder = null;
  1362. } else if (component.equals(new ComponentName(FileDisplayActivity.this, FileUploader.class))) {
  1363. Log_OC.d(TAG, "Upload service disconnected");
  1364. mUploaderBinder = null;
  1365. }
  1366. }
  1367. }
  1368. private MediaServiceConnection newMediaConnection(){
  1369. return new MediaServiceConnection();
  1370. }
  1371. /** Defines callbacks for service binding, passed to bindService() */
  1372. private class MediaServiceConnection implements ServiceConnection {
  1373. @Override
  1374. public void onServiceConnected(ComponentName component, IBinder service) {
  1375. if (component.equals(new ComponentName(FileDisplayActivity.this, MediaService.class))) {
  1376. Log_OC.d(TAG, "Media service connected");
  1377. mMediaServiceBinder = (MediaServiceBinder) service;
  1378. }else {
  1379. return;
  1380. }
  1381. }
  1382. @Override
  1383. public void onServiceDisconnected(ComponentName component) {
  1384. if (component.equals(new ComponentName(FileDisplayActivity.this,
  1385. MediaService.class))) {
  1386. Log_OC.e(TAG, "Media service disconnected");
  1387. mMediaServiceBinder = null;
  1388. }
  1389. }
  1390. }
  1391. /**
  1392. * Updates the view associated to the activity after the finish of some operation over files
  1393. * in the current account.
  1394. *
  1395. * @param operation Removal operation performed.
  1396. * @param result Result of the removal.
  1397. */
  1398. @Override
  1399. public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {
  1400. super.onRemoteOperationFinish(operation, result);
  1401. if (operation instanceof RemoveFileOperation) {
  1402. onRemoveFileOperationFinish((RemoveFileOperation) operation, result);
  1403. } else if (operation instanceof RenameFileOperation) {
  1404. onRenameFileOperationFinish((RenameFileOperation) operation, result);
  1405. } else if (operation instanceof SynchronizeFileOperation) {
  1406. onSynchronizeFileOperationFinish((SynchronizeFileOperation) operation, result);
  1407. } else if (operation instanceof CreateFolderOperation) {
  1408. onCreateFolderOperationFinish((CreateFolderOperation) operation, result);
  1409. } else if (operation instanceof MoveFileOperation) {
  1410. onMoveFileOperationFinish((MoveFileOperation) operation, result);
  1411. } else if (operation instanceof CopyFileOperation) {
  1412. onCopyFileOperationFinish((CopyFileOperation) operation, result);
  1413. }
  1414. }
  1415. private void refreshShowDetails() {
  1416. FileFragment details = getSecondFragment();
  1417. if (details != null) {
  1418. OCFile file = details.getFile();
  1419. if (file != null) {
  1420. file = getStorageManager().getFileByPath(file.getRemotePath());
  1421. if (details instanceof PreviewMediaFragment) {
  1422. // Refresh OCFile of the fragment
  1423. ((PreviewMediaFragment) details).updateFile(file);
  1424. } else if (details instanceof PreviewTextFragment) {
  1425. // Refresh OCFile of the fragment
  1426. ((PreviewTextFragment) details).updateFile(file);
  1427. } else {
  1428. showDetails(file);
  1429. }
  1430. }
  1431. supportInvalidateOptionsMenu();
  1432. }
  1433. }
  1434. /**
  1435. * Updates the view associated to the activity after the finish of an operation trying to
  1436. * remove a file.
  1437. *
  1438. * @param operation Removal operation performed.
  1439. * @param result Result of the removal.
  1440. */
  1441. private void onRemoveFileOperationFinish(RemoveFileOperation operation,
  1442. RemoteOperationResult result) {
  1443. DisplayUtils.showSnackMessage(
  1444. this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
  1445. );
  1446. if (result.isSuccess()) {
  1447. OCFile removedFile = operation.getFile();
  1448. tryStopPlaying(removedFile);
  1449. FileFragment second = getSecondFragment();
  1450. if (second != null && removedFile.equals(second.getFile())) {
  1451. if (second instanceof PreviewMediaFragment) {
  1452. ((PreviewMediaFragment) second).stopPreview(true);
  1453. }
  1454. setFile(getStorageManager().getFileById(removedFile.getParentId()));
  1455. cleanSecondFragment();
  1456. }
  1457. if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
  1458. refreshListOfFilesFragment(false);
  1459. }
  1460. supportInvalidateOptionsMenu();
  1461. } else {
  1462. if (result.isSslRecoverableException()) {
  1463. mLastSslUntrustedServerResult = result;
  1464. showUntrustedCertDialog(mLastSslUntrustedServerResult);
  1465. }
  1466. }
  1467. }
  1468. public void setMediaServiceConnection() {
  1469. mMediaServiceConnection = newMediaConnection();// mediaServiceConnection;
  1470. bindService(new Intent(this, MediaService.class), mMediaServiceConnection, Context.BIND_AUTO_CREATE);
  1471. }
  1472. private void tryStopPlaying(OCFile file) {
  1473. if (mMediaServiceConnection != null && MimeTypeUtil.isAudio(file) && mMediaServiceBinder.isPlaying(file)) {
  1474. mMediaServiceBinder.pause();
  1475. }
  1476. }
  1477. /**
  1478. * Updates the view associated to the activity after the finish of an operation trying to move a
  1479. * file.
  1480. *
  1481. * @param operation Move operation performed.
  1482. * @param result Result of the move operation.
  1483. */
  1484. private void onMoveFileOperationFinish(MoveFileOperation operation,
  1485. RemoteOperationResult result) {
  1486. if (result.isSuccess()) {
  1487. refreshListOfFilesFragment(false);
  1488. } else {
  1489. try {
  1490. DisplayUtils.showSnackMessage(
  1491. this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
  1492. );
  1493. } catch (NotFoundException e) {
  1494. Log_OC.e(TAG, "Error while trying to show fail message ", e);
  1495. }
  1496. }
  1497. }
  1498. /**
  1499. * Updates the view associated to the activity after the finish of an operation trying to copy a
  1500. * file.
  1501. *
  1502. * @param operation Copy operation performed.
  1503. * @param result Result of the copy operation.
  1504. */
  1505. private void onCopyFileOperationFinish(CopyFileOperation operation, RemoteOperationResult result) {
  1506. if (result.isSuccess()) {
  1507. refreshListOfFilesFragment(false);
  1508. } else {
  1509. try {
  1510. DisplayUtils.showSnackMessage(
  1511. this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
  1512. );
  1513. } catch (NotFoundException e) {
  1514. Log_OC.e(TAG, "Error while trying to show fail message ", e);
  1515. }
  1516. }
  1517. }
  1518. /**
  1519. * Updates the view associated to the activity after the finish of an operation trying to rename
  1520. * a file.
  1521. *
  1522. * @param operation Renaming operation performed.
  1523. * @param result Result of the renaming.
  1524. */
  1525. private void onRenameFileOperationFinish(RenameFileOperation operation,
  1526. RemoteOperationResult result) {
  1527. OCFile renamedFile = operation.getFile();
  1528. if (result.isSuccess()) {
  1529. FileFragment details = getSecondFragment();
  1530. if (details != null) {
  1531. if (details instanceof FileDetailFragment &&
  1532. renamedFile.equals(details.getFile())) {
  1533. ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
  1534. showDetails(renamedFile);
  1535. } else if (details instanceof PreviewMediaFragment &&
  1536. renamedFile.equals(details.getFile())) {
  1537. ((PreviewMediaFragment) details).updateFile(renamedFile);
  1538. if (PreviewMediaFragment.canBePreviewed(renamedFile)) {
  1539. int position = ((PreviewMediaFragment) details).getPosition();
  1540. startMediaPreview(renamedFile, position, true, true);
  1541. } else {
  1542. getFileOperationsHelper().openFile(renamedFile);
  1543. }
  1544. } else if (details instanceof PreviewTextFragment &&
  1545. renamedFile.equals(details.getFile())) {
  1546. ((PreviewTextFragment) details).updateFile(renamedFile);
  1547. if (PreviewTextFragment.canBePreviewed(renamedFile)) {
  1548. startTextPreview(renamedFile, true);
  1549. } else {
  1550. getFileOperationsHelper().openFile(renamedFile);
  1551. }
  1552. }
  1553. }
  1554. if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())) {
  1555. refreshListOfFilesFragment(false);
  1556. }
  1557. } else {
  1558. DisplayUtils.showSnackMessage(
  1559. this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
  1560. );
  1561. if (result.isSslRecoverableException()) {
  1562. mLastSslUntrustedServerResult = result;
  1563. showUntrustedCertDialog(mLastSslUntrustedServerResult);
  1564. }
  1565. }
  1566. }
  1567. private void onSynchronizeFileOperationFinish(SynchronizeFileOperation operation,
  1568. RemoteOperationResult result) {
  1569. if (result.isSuccess() && operation.transferWasRequested()) {
  1570. OCFile syncedFile = operation.getLocalFile();
  1571. onTransferStateChanged(syncedFile, true, true);
  1572. supportInvalidateOptionsMenu();
  1573. refreshShowDetails();
  1574. }
  1575. }
  1576. /**
  1577. * Updates the view associated to the activity after the finish of an operation trying create a
  1578. * new folder
  1579. *
  1580. * @param operation Creation operation performed.
  1581. * @param result Result of the creation.
  1582. */
  1583. private void onCreateFolderOperationFinish(CreateFolderOperation operation,
  1584. RemoteOperationResult result) {
  1585. if (result.isSuccess()) {
  1586. refreshListOfFilesFragment(false);
  1587. } else {
  1588. try {
  1589. DisplayUtils.showSnackMessage(
  1590. this, ErrorMessageAdapter.getErrorCauseMessage(result, operation, getResources())
  1591. );
  1592. } catch (NotFoundException e) {
  1593. Log_OC.e(TAG, "Error while trying to show fail message ", e);
  1594. }
  1595. }
  1596. }
  1597. /**
  1598. * {@inheritDoc}
  1599. */
  1600. @Override
  1601. public void onTransferStateChanged(OCFile file, boolean downloading, boolean uploading) {
  1602. refreshListOfFilesFragment(false);
  1603. FileFragment details = getSecondFragment();
  1604. if (details instanceof FileDetailFragment &&
  1605. file.equals(details.getFile())) {
  1606. if (downloading || uploading) {
  1607. ((FileDetailFragment) details).updateFileDetails(file, getAccount());
  1608. } else {
  1609. if (!file.fileExists()) {
  1610. cleanSecondFragment();
  1611. } else {
  1612. ((FileDetailFragment) details).updateFileDetails(false, true);
  1613. }
  1614. }
  1615. }
  1616. }
  1617. private void requestForDownload() {
  1618. Account account = getAccount();
  1619. //if (!mWaitingToPreview.isDownloading()) {
  1620. if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
  1621. Intent i = new Intent(this, FileDownloader.class);
  1622. i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
  1623. i.putExtra(FileDownloader.EXTRA_FILE, mWaitingToPreview);
  1624. startService(i);
  1625. }
  1626. }
  1627. @Override
  1628. public void onSavedCertificate() {
  1629. startSyncFolderOperation(getCurrentDir(), false);
  1630. }
  1631. /**
  1632. * Starts an operation to refresh the requested folder.
  1633. * <p/>
  1634. * The operation is run in a new background thread created on the fly.
  1635. * <p/>
  1636. * The refresh updates is a "light sync": properties of regular files in folder are updated (including
  1637. * associated shares), but not their contents. Only the contents of files marked to be kept-in-sync are
  1638. * synchronized too.
  1639. *
  1640. * @param folder Folder to refresh.
  1641. * @param ignoreETag If 'true', the data from the server will be fetched and sync'ed even if the eTag
  1642. * didn't change.
  1643. */
  1644. public void startSyncFolderOperation(final OCFile folder, final boolean ignoreETag) {
  1645. // the execution is slightly delayed to allow the activity get the window focus if it's being started
  1646. // or if the method is called from a dialog that is being dismissed
  1647. if (TextUtils.isEmpty(searchQuery)) {
  1648. getHandler().postDelayed(
  1649. new Runnable() {
  1650. @Override
  1651. public void run() {
  1652. if (hasWindowFocus()) {
  1653. long currentSyncTime = System.currentTimeMillis();
  1654. mSyncInProgress = true;
  1655. // perform folder synchronization
  1656. RemoteOperation synchFolderOp = new RefreshFolderOperation(folder,
  1657. currentSyncTime,
  1658. false,
  1659. getFileOperationsHelper().isSharedSupported(),
  1660. ignoreETag,
  1661. getStorageManager(),
  1662. getAccount(),
  1663. getApplicationContext()
  1664. );
  1665. synchFolderOp.execute(
  1666. getAccount(),
  1667. MainApp.getAppContext(),
  1668. FileDisplayActivity.this,
  1669. null,
  1670. null
  1671. );
  1672. setIndeterminate(true);
  1673. setBackgroundText();
  1674. } // else: NOTHING ; lets' not refresh when the user rotates the device but there is
  1675. // another window floating over
  1676. }
  1677. },
  1678. DELAY_TO_REQUEST_REFRESH_OPERATION_LATER
  1679. );
  1680. }
  1681. }
  1682. private void requestForDownload(OCFile file, String downloadBehaviour, String packageName, String activityName) {
  1683. Account account = getAccount();
  1684. if (!mDownloaderBinder.isDownloading(account, mWaitingToPreview)) {
  1685. Intent i = new Intent(this, FileDownloader.class);
  1686. i.putExtra(FileDownloader.EXTRA_ACCOUNT, account);
  1687. i.putExtra(FileDownloader.EXTRA_FILE, file);
  1688. i.putExtra(SendShareDialog.PACKAGE_NAME, packageName);
  1689. i.putExtra(SendShareDialog.ACTIVITY_NAME, activityName);
  1690. i.putExtra(OCFileListFragment.DOWNLOAD_BEHAVIOUR, downloadBehaviour);
  1691. startService(i);
  1692. }
  1693. }
  1694. private void sendDownloadedFile(String packageName, String activityName) {
  1695. if (mWaitingToSend != null) {
  1696. Intent sendIntent = new Intent(Intent.ACTION_SEND);
  1697. sendIntent.setType(mWaitingToSend.getMimetype());
  1698. sendIntent.putExtra(Intent.EXTRA_STREAM, mWaitingToSend.getExposedFileUri(this));
  1699. sendIntent.putExtra(Intent.ACTION_SEND, true);
  1700. sendIntent.setComponent(new ComponentName(packageName, activityName));
  1701. // Show dialog
  1702. String sendTitle = getString(R.string.activity_chooser_send_file_title);
  1703. startActivity(Intent.createChooser(sendIntent, sendTitle));
  1704. } else {
  1705. Log_OC.e(TAG, "Trying to send a NULL OCFile");
  1706. }
  1707. mWaitingToSend = null;
  1708. }
  1709. /**
  1710. * Requests the download of the received {@link OCFile} , updates the UI
  1711. * to monitor the download progress and prepares the activity to send the file
  1712. * when the download finishes.
  1713. *
  1714. * @param file {@link OCFile} to download and preview.
  1715. * @param packageName
  1716. * @param activityName
  1717. */
  1718. public void startDownloadForSending(OCFile file, String downloadBehaviour, String packageName,
  1719. String activityName) {
  1720. mWaitingToSend = file;
  1721. requestForDownload(mWaitingToSend, downloadBehaviour, packageName, activityName);
  1722. boolean hasSecondFragment = (getSecondFragment() != null);
  1723. updateFragmentsVisibility(hasSecondFragment);
  1724. }
  1725. /**
  1726. * Opens the image gallery showing the image {@link OCFile} received as parameter.
  1727. *
  1728. * @param file Image {@link OCFile} to show.
  1729. */
  1730. public void startImagePreview(OCFile file, boolean showPreview) {
  1731. Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
  1732. showDetailsIntent.putExtra(EXTRA_FILE, file);
  1733. showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
  1734. if (showPreview) {
  1735. startActivity(showDetailsIntent);
  1736. } else {
  1737. FileOperationsHelper fileOperationsHelper = new FileOperationsHelper(this);
  1738. fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent);
  1739. }
  1740. }
  1741. /**
  1742. * Opens the image gallery showing the image {@link OCFile} received as parameter.
  1743. *
  1744. * @param file Image {@link OCFile} to show.
  1745. */
  1746. public void startImagePreview(OCFile file, VirtualFolderType type, boolean showPreview) {
  1747. Intent showDetailsIntent = new Intent(this, PreviewImageActivity.class);
  1748. showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_FILE, file);
  1749. showDetailsIntent.putExtra(EXTRA_ACCOUNT, getAccount());
  1750. showDetailsIntent.putExtra(PreviewImageActivity.EXTRA_VIRTUAL_TYPE, type);
  1751. if (showPreview) {
  1752. startActivity(showDetailsIntent);
  1753. } else {
  1754. FileOperationsHelper fileOperationsHelper = new FileOperationsHelper(this);
  1755. fileOperationsHelper.startSyncForFileAndIntent(file, showDetailsIntent);
  1756. }
  1757. }
  1758. /**
  1759. * Stars the preview of an already down media {@link OCFile}.
  1760. *
  1761. * @param file Media {@link OCFile} to preview.
  1762. * @param startPlaybackPosition Media position where the playback will be started,
  1763. * in milliseconds.
  1764. * @param autoplay When 'true', the playback will start without user
  1765. * interactions.
  1766. */
  1767. public void startMediaPreview(OCFile file, int startPlaybackPosition, boolean autoplay, boolean showPreview) {
  1768. if (showPreview && file.isDown() && !file.isDownloading()) {
  1769. Fragment mediaFragment = PreviewMediaFragment.newInstance(file, getAccount(), startPlaybackPosition, autoplay);
  1770. setSecondFragment(mediaFragment);
  1771. updateFragmentsVisibility(true);
  1772. updateActionBarTitleAndHomeButton(file);
  1773. setFile(file);
  1774. } else {
  1775. Intent previewIntent = new Intent();
  1776. previewIntent.putExtra(EXTRA_FILE, file);
  1777. previewIntent.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, startPlaybackPosition);
  1778. previewIntent.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, autoplay);
  1779. FileOperationsHelper fileOperationsHelper = new FileOperationsHelper(this);
  1780. fileOperationsHelper.startSyncForFileAndIntent(file, previewIntent);
  1781. }
  1782. }
  1783. /**
  1784. * Stars the preview of a text file {@link OCFile}.
  1785. *
  1786. * @param file Text {@link OCFile} to preview.
  1787. */
  1788. public void startTextPreview(OCFile file, boolean showPreview) {
  1789. if (showPreview) {
  1790. Bundle args = new Bundle();
  1791. args.putParcelable(EXTRA_FILE, file);
  1792. args.putParcelable(EXTRA_ACCOUNT, getAccount());
  1793. Fragment textPreviewFragment = Fragment.instantiate(getApplicationContext(),
  1794. PreviewTextFragment.class.getName(), args);
  1795. setSecondFragment(textPreviewFragment);
  1796. updateFragmentsVisibility(true);
  1797. updateActionBarTitleAndHomeButton(file);
  1798. setFile(file);
  1799. } else {
  1800. Intent previewIntent = new Intent();
  1801. previewIntent.putExtra(EXTRA_FILE, file);
  1802. previewIntent.putExtra(TEXT_PREVIEW, true);
  1803. FileOperationsHelper fileOperationsHelper = new FileOperationsHelper(this);
  1804. fileOperationsHelper.startSyncForFileAndIntent(file, previewIntent);
  1805. }
  1806. }
  1807. public void startContactListFragment(OCFile file) {
  1808. Intent intent = new Intent(this, ContactsPreferenceActivity.class);
  1809. intent.putExtra(ContactListFragment.FILE_NAME, Parcels.wrap(file));
  1810. intent.putExtra(ContactListFragment.ACCOUNT, Parcels.wrap(getAccount()));
  1811. startActivity(intent);
  1812. }
  1813. /**
  1814. * Requests the download of the received {@link OCFile} , updates the UI
  1815. * to monitor the download progress and prepares the activity to preview
  1816. * or open the file when the download finishes.
  1817. *
  1818. * @param file {@link OCFile} to download and preview.
  1819. */
  1820. public void startDownloadForPreview(OCFile file) {
  1821. Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount());
  1822. setSecondFragment(detailFragment);
  1823. mWaitingToPreview = file;
  1824. requestForDownload();
  1825. updateFragmentsVisibility(true);
  1826. updateActionBarTitleAndHomeButton(file);
  1827. setFile(file);
  1828. }
  1829. /**
  1830. * Request stopping the upload/download operation in progress over the given {@link OCFile} file.
  1831. *
  1832. * @param file {@link OCFile} file which operation are wanted to be cancel
  1833. */
  1834. public void cancelTransference(OCFile file) {
  1835. getFileOperationsHelper().cancelTransference(file);
  1836. if (mWaitingToPreview != null &&
  1837. mWaitingToPreview.getRemotePath().equals(file.getRemotePath())) {
  1838. mWaitingToPreview = null;
  1839. }
  1840. if (mWaitingToSend != null &&
  1841. mWaitingToSend.getRemotePath().equals(file.getRemotePath())) {
  1842. mWaitingToSend = null;
  1843. }
  1844. onTransferStateChanged(file, false, false);
  1845. }
  1846. /**
  1847. * Request stopping all upload/download operations in progress over the given {@link OCFile} files.
  1848. *
  1849. * @param files collection of {@link OCFile} files which operations are wanted to be cancel
  1850. */
  1851. public void cancelTransference(Collection<OCFile> files) {
  1852. for (OCFile file : files) {
  1853. cancelTransference(file);
  1854. }
  1855. }
  1856. @Override
  1857. public void onRefresh(boolean ignoreETag) {
  1858. refreshList(ignoreETag);
  1859. }
  1860. @Override
  1861. public void onRefresh() {
  1862. refreshList(true);
  1863. }
  1864. private void refreshList(boolean ignoreETag) {
  1865. OCFileListFragment listOfFiles = getListOfFilesFragment();
  1866. if (listOfFiles != null && !listOfFiles.getIsSearchFragment()) {
  1867. OCFile folder = listOfFiles.getCurrentFile();
  1868. if (folder != null) {
  1869. /*mFile = mContainerActivity.getStorageManager().getFileById(mFile.getFileId());
  1870. listDirectory(mFile);*/
  1871. startSyncFolderOperation(folder, ignoreETag);
  1872. }
  1873. }
  1874. }
  1875. private boolean isGridView() {
  1876. return getListOfFilesFragment().isGridEnabled();
  1877. }
  1878. public void allFilesOption() {
  1879. browseToRoot();
  1880. }
  1881. @Override
  1882. public void showFiles(boolean onDeviceOnly) {
  1883. super.showFiles(onDeviceOnly);
  1884. getListOfFilesFragment().refreshDirectory();
  1885. }
  1886. @Subscribe(threadMode = ThreadMode.MAIN)
  1887. public void onMessageEvent(SyncEventFinished event) {
  1888. Bundle bundle = event.getIntent().getExtras();
  1889. if (event.getIntent().getBooleanExtra(TEXT_PREVIEW, false)) {
  1890. startTextPreview((OCFile) bundle.get(EXTRA_FILE), true);
  1891. } else if (bundle.containsKey(PreviewVideoActivity.EXTRA_START_POSITION)) {
  1892. startMediaPreview((OCFile)bundle.get(EXTRA_FILE),
  1893. (int)bundle.get(PreviewVideoActivity.EXTRA_START_POSITION),
  1894. (boolean)bundle.get(PreviewVideoActivity.EXTRA_AUTOPLAY), true);
  1895. } else if (bundle.containsKey(PreviewImageActivity.EXTRA_VIRTUAL_TYPE)) {
  1896. startImagePreview((OCFile)bundle.get(EXTRA_FILE),
  1897. (VirtualFolderType)bundle.get(PreviewImageActivity.EXTRA_VIRTUAL_TYPE),
  1898. true);
  1899. } else {
  1900. startImagePreview((OCFile)bundle.get(EXTRA_FILE),true);
  1901. }
  1902. }
  1903. @Subscribe(threadMode = ThreadMode.BACKGROUND)
  1904. public void onMessageEvent(TokenPushEvent event) {
  1905. if (!PreferenceManager.getKeysReInit(getApplicationContext())) {
  1906. PushUtils.reinitKeys();
  1907. } else {
  1908. PushUtils.pushRegistrationToServer();
  1909. }
  1910. }
  1911. @Override
  1912. public void onStart() {
  1913. super.onStart();
  1914. EventBus.getDefault().post(new TokenPushEvent());
  1915. checkForNewDevVersionNecessary(findViewById(R.id.root_layout), getApplicationContext());
  1916. }
  1917. @Override
  1918. protected void onRestart() {
  1919. super.onRestart();
  1920. checkForNewDevVersionNecessary(findViewById(R.id.root_layout), getApplicationContext());
  1921. }
  1922. }