FileDisplayActivity.java 92 KB

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