FileDisplayActivity.java 91 KB

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