StorageProcessDownloadActivity.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. package com.epson.iprint.storage;
  2. import android.content.Context;
  3. import android.content.Intent;
  4. import android.net.Uri;
  5. import android.os.Build;
  6. import android.os.Bundle;
  7. import android.support.annotation.NonNull;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.AdapterView;
  12. import android.widget.ArrayAdapter;
  13. import android.widget.ImageView;
  14. import android.widget.ListAdapter;
  15. import android.widget.ListView;
  16. import android.widget.TextView;
  17. import com.epson.iprint.prtlogger.PrintLog;
  18. import com.epson.iprint.storage.StorageActivity;
  19. import com.epson.iprint.storage.StorageItem;
  20. import com.epson.iprint.storage.StorageProcessActivity;
  21. import com.epson.iprint.storage.StorageServiceClient;
  22. import epson.common.Utils;
  23. import epson.print.ActivityDocsPrintPreview;
  24. import epson.print.ActivityPrintWeb;
  25. import epson.print.ActivityViewImageSelect;
  26. import epson.print.R;
  27. import epson.print.CommonDefine;
  28. import epson.print.Util.AsyncTaskExecutor;
  29. import java.io.File;
  30. import java.util.ArrayList;
  31. import java.util.HashMap;
  32. import java.util.List;
  33. import java.util.Stack;
  34. import org.opencv.videoio.Videoio;
  35. public class StorageProcessDownloadActivity extends StorageProcessActivity {
  36. public static final String PARAM_KEY_ONLINE_STORAGE_PRINT_LOG = "print_log";
  37. private final String DOWNLOADED_FILE_PATH = "Downloaded.File.Path";
  38. private final String DOWNLOAD_PREFERENCE = "StorageProcessDownloadActivity.Preference";
  39. private final String ITEMNAME_PARENT = "..";
  40. private final int REQUEST_CODE_DELETE_DOWNLOADED_FILE = 0;
  41. private StorageServiceClient.Enumerator mEnumerator;
  42. /* access modifiers changed from: private */
  43. public Stack<StorageItem> mFolderStack;
  44. /* access modifiers changed from: private */
  45. public boolean mIsDownloadInterruption = false;
  46. /* access modifiers changed from: private */
  47. public boolean mIsDownloading = false;
  48. /* access modifiers changed from: private */
  49. public ListView mListView;
  50. /* access modifiers changed from: private */
  51. public int mPosition = 0;
  52. /* access modifiers changed from: private */
  53. public PrintLog mPrintLog;
  54. AsyncTaskExecutor<Void, Void, Void> task = null;
  55. /* access modifiers changed from: protected */
  56. public void onCreate(Bundle bundle) {
  57. super.onCreate(bundle);
  58. setContentView((int) R.layout.folder_content_layout);
  59. setActionBar(getStorageClient().getStorageServiceName(this), true);
  60. this.mEnumerator = getStorageClient().getEnumerator(this);
  61. this.mFolderStack = new Stack<>();
  62. this.mListView = (ListView) findViewById(16908298);
  63. this.mListView.setOnItemClickListener(new StorageItemClickListener());
  64. this.mListView.setCacheColorHint(0);
  65. try {
  66. this.mPrintLog = (PrintLog) getIntent().getSerializableExtra("print_log");
  67. } catch (ClassCastException unused) {
  68. }
  69. if (this.mPrintLog == null) {
  70. this.mPrintLog = new PrintLog();
  71. }
  72. }
  73. public void onBackPressed() {
  74. StorageItemAdapter storageItemAdapter = (StorageItemAdapter) this.mListView.getAdapter();
  75. if (storageItemAdapter == null) {
  76. finish();
  77. } else if (storageItemAdapter.areAllItemsEnabled()) {
  78. if (this.mFolderStack.size() > 1) {
  79. this.mFolderStack.pop();
  80. if (isConnected()) {
  81. new EnumerateTask(this.mFolderStack.peek()).executeOnExecutor(new Void[0]);
  82. } else {
  83. showConnectionError();
  84. }
  85. } else {
  86. finish();
  87. }
  88. }
  89. }
  90. private void onSignInStatus(StorageProcessActivity.SignInStatus signInStatus) {
  91. if (signInStatus == StorageProcessActivity.SignInStatus.SIGNED_IN) {
  92. this.mListView.setVisibility(0);
  93. return;
  94. }
  95. this.mListView.setVisibility(4);
  96. this.mListView.setAdapter((ListAdapter) null);
  97. StorageServiceClient.Enumerator enumerator = this.mEnumerator;
  98. if (enumerator != null) {
  99. enumerator.cleanUpResources();
  100. }
  101. }
  102. /* access modifiers changed from: protected */
  103. public void onStop() {
  104. super.onStop();
  105. if (this.mIsDownloading && Build.VERSION.SDK_INT >= 29) {
  106. this.mIsDownloadInterruption = true;
  107. this.task.cancel(false);
  108. }
  109. }
  110. /* access modifiers changed from: protected */
  111. public void onRestart() {
  112. super.onRestart();
  113. if (this.mIsDownloadInterruption && !this.mIsDownloading) {
  114. itemClick(this.mPosition);
  115. }
  116. this.mIsDownloadInterruption = false;
  117. }
  118. private void onUpdateProcessView() {
  119. if (this.mListView.getAdapter() != null) {
  120. return;
  121. }
  122. if (isConnected()) {
  123. StorageItem rootItem = getEnumerator().getRootItem();
  124. this.mFolderStack = new Stack<>();
  125. this.mFolderStack.push(rootItem);
  126. new EnumerateTask(rootItem).executeOnExecutor(new Void[0]);
  127. return;
  128. }
  129. showConnectionError();
  130. }
  131. /* access modifiers changed from: protected */
  132. public void onActivityResult(int i, int i2, Intent intent) {
  133. if (i == 0) {
  134. String fetchDownloadedFilePath = fetchDownloadedFilePath();
  135. if (fetchDownloadedFilePath != null) {
  136. new File(fetchDownloadedFilePath).delete();
  137. }
  138. this.mIsDownloadInterruption = false;
  139. }
  140. }
  141. class DownloadTask extends AsyncTaskExecutor<Void, Void, Void> {
  142. StorageItem item = null;
  143. String localPath = null;
  144. StorageActivity.OverlayProgress progress = null;
  145. /* access modifiers changed from: protected */
  146. public void onPreExecute() {
  147. StorageProcessDownloadActivity.this.taskInvoked(true);
  148. }
  149. /* access modifiers changed from: protected */
  150. public Void doInBackground(Void... voidArr) {
  151. final StorageServiceClient.Downloader downloader = StorageProcessDownloadActivity.this.getStorageClient().getDownloader(StorageProcessDownloadActivity.this, this.item, this.localPath);
  152. C09241 r0 = downloader.isCancelable() ? new StorageActivity.CancelRequestCallback() {
  153. public void onCancelRequest(Intent intent) {
  154. downloader.cancel();
  155. }
  156. } : null;
  157. this.progress = new StorageActivity.OverlayProgress();
  158. this.progress.show(StorageProcessDownloadActivity.this.getString(R.string.downloading_notification), r0);
  159. downloader.start(new StorageServiceClient.DownloadCompletion() {
  160. public void onDownloadComplete(StorageItem storageItem, String str, StorageServiceClient.ProcessError processError) {
  161. if (str != null) {
  162. DownloadTask.this.localPath = str;
  163. }
  164. StorageProcessDownloadActivity.this.runOnUiThread(new DownloadedRun(processError));
  165. }
  166. });
  167. return null;
  168. }
  169. class DownloadedRun implements Runnable {
  170. StorageServiceClient.ProcessError error;
  171. DownloadedRun(StorageServiceClient.ProcessError processError) {
  172. this.error = processError;
  173. }
  174. public void run() {
  175. boolean unused = StorageProcessDownloadActivity.this.mIsDownloading = false;
  176. if (this.error == StorageServiceClient.ProcessError.NONE) {
  177. StorageProcessDownloadActivity storageProcessDownloadActivity = StorageProcessDownloadActivity.this;
  178. Intent previewIntent = StorageProcessDownloadActivity.getPreviewIntent(DownloadTask.this.localPath, storageProcessDownloadActivity, StorageProcessDownloadActivity.this.mPrintLog);
  179. previewIntent.setFlags(Videoio.CAP_INTELPERC_IMAGE_GENERATOR);
  180. StorageProcessDownloadActivity.this.saveDownloadedFilePath(DownloadTask.this.localPath);
  181. if (!StorageProcessDownloadActivity.this.mIsDownloadInterruption) {
  182. storageProcessDownloadActivity.startActivityForResult(previewIntent, 0);
  183. }
  184. } else if (this.error != StorageServiceClient.ProcessError.CANCELED) {
  185. StorageProcessDownloadActivity.this.showErrorDialog((int) R.string.download_error_mes);
  186. }
  187. StorageProcessDownloadActivity.this.taskInvoked(false);
  188. DownloadTask.this.progress.dismiss();
  189. }
  190. }
  191. DownloadTask(StorageItem storageItem) {
  192. this.item = storageItem;
  193. this.localPath = StorageProcessDownloadActivity.this.getStorageClient().getDownloadLocalPath(StorageProcessDownloadActivity.this, storageItem);
  194. }
  195. }
  196. public static Intent getPreviewIntent(@NonNull String str, @NonNull Context context, @NonNull PrintLog printLog) {
  197. Intent intent = new Intent();
  198. intent.putExtra("from", 4);
  199. if (StorageItem.endsWith(str, CommonDefine.FileType_PDF) || Utils.isGConvertFile(str)) {
  200. intent.putExtra(CommonDefine.SEND_DOCUMENT_VIEW, str);
  201. intent.setClass(context, ActivityDocsPrintPreview.class);
  202. printLog.originalFileExtension = PrintLog.getFileExtension(str);
  203. intent.putExtra("print_log", printLog);
  204. } else if (Utils.isPhotoFile(str)) {
  205. intent.setAction("android.intent.action.SEND");
  206. intent.putExtra("android.intent.extra.STREAM", Uri.parse(str));
  207. intent.setType(Utils.getMimeExt(str));
  208. intent.putExtra(CommonDefine.STYPE, true);
  209. intent.setClass(context, ActivityViewImageSelect.class);
  210. intent.putExtra(ActivityViewImageSelect.PARAMS_KEY_FROM_EPSON, true);
  211. printLog.originalFileExtension = PrintLog.getFileExtension(str);
  212. intent.putExtra("print_log", printLog);
  213. } else {
  214. ArrayList arrayList = new ArrayList();
  215. arrayList.add(str);
  216. intent.putStringArrayListExtra("print_web", arrayList);
  217. intent.putExtra(CommonDefine.STYPE, true);
  218. intent.setClass(context, ActivityPrintWeb.class);
  219. printLog.originalFileExtension = PrintLog.getFileExtension(str);
  220. intent.putExtra("print_log", printLog);
  221. }
  222. return intent;
  223. }
  224. class EnumerateTask extends AsyncTaskExecutor<Void, Void, Void> {
  225. List<StorageItem> enumeratedItems;
  226. StorageItem item;
  227. final StorageServiceClient.EnumerateCompletion onEnumerated = new StorageServiceClient.EnumerateCompletion() {
  228. public void onEnumerateComplete(List<StorageItem> list, final StorageServiceClient.ProcessError processError) {
  229. EnumerateTask enumerateTask = EnumerateTask.this;
  230. enumerateTask.enumeratedItems = list;
  231. int size = StorageProcessDownloadActivity.this.mFolderStack.size();
  232. if (size > 1) {
  233. StorageItem storageItem = (StorageItem) StorageProcessDownloadActivity.this.mFolderStack.get(size - 2);
  234. StorageItem storageItem2 = new StorageItem("..");
  235. storageItem2.path = storageItem.path;
  236. storageItem2.type = StorageItem.ItemType.DIRECTORY;
  237. storageItem2.userInfo = storageItem.userInfo;
  238. if (EnumerateTask.this.enumeratedItems == null) {
  239. EnumerateTask.this.enumeratedItems = new ArrayList();
  240. }
  241. EnumerateTask.this.enumeratedItems.add(0, storageItem2);
  242. }
  243. StorageProcessDownloadActivity.this.runOnUiThread(new Runnable() {
  244. public void run() {
  245. if (processError == StorageServiceClient.ProcessError.NONE && EnumerateTask.this.enumeratedItems != null) {
  246. StorageProcessDownloadActivity.this.mListView.setAdapter(new StorageItemAdapter(EnumerateTask.this.enumeratedItems));
  247. } else if (processError != StorageServiceClient.ProcessError.CANCELED) {
  248. StorageProcessDownloadActivity.this.showErrorDialog((int) R.string.unknow_error_mes);
  249. }
  250. StorageProcessDownloadActivity.this.taskInvoked(false);
  251. EnumerateTask.this.progress.dismiss();
  252. }
  253. });
  254. }
  255. };
  256. StorageServiceClient.EnumerateCompletion onLoadedMore = new StorageServiceClient.EnumerateCompletion() {
  257. public void onEnumerateComplete(final List<StorageItem> list, final StorageServiceClient.ProcessError processError) {
  258. StorageProcessDownloadActivity.this.runOnUiThread(new Runnable() {
  259. public void run() {
  260. if (processError == StorageServiceClient.ProcessError.NONE) {
  261. StorageItemAdapter storageItemAdapter = (StorageItemAdapter) StorageProcessDownloadActivity.this.mListView.getAdapter();
  262. if (storageItemAdapter != null) {
  263. storageItemAdapter.addLoaedMoreItems(list);
  264. storageItemAdapter.notifyDataSetChanged();
  265. }
  266. } else if (processError != StorageServiceClient.ProcessError.CANCELED) {
  267. StorageProcessDownloadActivity.this.showErrorDialog((int) R.string.unknow_error_mes);
  268. }
  269. StorageProcessDownloadActivity.this.taskInvoked(false);
  270. EnumerateTask.this.progress.dismiss();
  271. }
  272. });
  273. }
  274. };
  275. StorageActivity.OverlayProgress progress = new StorageActivity.OverlayProgress();
  276. /* access modifiers changed from: protected */
  277. public void onPreExecute() {
  278. StorageProcessDownloadActivity.this.taskInvoked(true);
  279. }
  280. /* access modifiers changed from: protected */
  281. public Void doInBackground(Void... voidArr) {
  282. boolean isNeedSignin = StorageProcessDownloadActivity.this.getStorageClient().isNeedSignin();
  283. if (!isNeedSignin) {
  284. this.progress.show();
  285. }
  286. if (this.item.type == StorageItem.ItemType.LOADMORE) {
  287. StorageProcessDownloadActivity.this.getEnumerator().enumerate(this.item, this.onLoadedMore);
  288. return null;
  289. } else if (!isNeedSignin) {
  290. StorageProcessDownloadActivity.this.getEnumerator().enumerate(this.item, this.onEnumerated);
  291. return null;
  292. } else {
  293. StorageProcessDownloadActivity.this.getEnumerator().enumerate(this.item, this.onEnumerated, new StorageServiceClient.SigninCompletion() {
  294. public void onSigninCompletion() {
  295. EnumerateTask.this.progress.show((String) null, (StorageActivity.CancelRequestCallback) null, false);
  296. }
  297. });
  298. return null;
  299. }
  300. }
  301. EnumerateTask(StorageItem storageItem) {
  302. this.item = storageItem;
  303. }
  304. }
  305. private class StorageItemClickListener implements AdapterView.OnItemClickListener {
  306. private StorageItemClickListener() {
  307. }
  308. public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
  309. int unused = StorageProcessDownloadActivity.this.mPosition = i;
  310. StorageProcessDownloadActivity.this.itemClick(i);
  311. }
  312. }
  313. /* access modifiers changed from: private */
  314. public void itemClick(int i) {
  315. this.mIsDownloading = true;
  316. if (isConnected()) {
  317. this.task = null;
  318. StorageItem storageItem = (StorageItem) this.mListView.getItemAtPosition(i);
  319. if (storageItem.type == StorageItem.ItemType.DIRECTORY) {
  320. if (storageItem.name.equals("..")) {
  321. this.mFolderStack.pop();
  322. } else if (!storageItem.path.equals(((StorageItem) this.mFolderStack.lastElement()).path)) {
  323. this.mFolderStack.push(storageItem);
  324. }
  325. this.task = new EnumerateTask(storageItem);
  326. int i2 = storageItem.mLoggerInfo;
  327. } else if (storageItem.type == StorageItem.ItemType.LOADMORE) {
  328. this.task = new EnumerateTask(storageItem);
  329. } else {
  330. this.task = new DownloadTask(storageItem);
  331. }
  332. AsyncTaskExecutor<Void, Void, Void> asyncTaskExecutor = this.task;
  333. if (asyncTaskExecutor != null) {
  334. asyncTaskExecutor.executeOnExecutor(new Void[0]);
  335. return;
  336. }
  337. return;
  338. }
  339. showConnectionError();
  340. }
  341. class StorageItemAdapter extends ArrayAdapter<StorageItem> {
  342. final int COMPONENT_GONE = -12345;
  343. LayoutInflater layoutInflater;
  344. List<StorageItem> storageItems;
  345. boolean taskRunningNow;
  346. HashMap<StorageItem, View> viewCache;
  347. public boolean areAllItemsEnabled() {
  348. return !this.taskRunningNow;
  349. }
  350. public boolean isEnabled(int i) {
  351. return areAllItemsEnabled();
  352. }
  353. @NonNull
  354. public View getView(int i, View view, @NonNull ViewGroup viewGroup) {
  355. StorageItem storageItem = this.storageItems.get(i);
  356. View view2 = this.viewCache.get(storageItem);
  357. if (view2 == null) {
  358. view2 = this.layoutInflater.inflate(R.layout.file_list_item, (ViewGroup) null);
  359. switch (storageItem.type) {
  360. case DIRECTORY:
  361. if (!storageItem.name.equals("..")) {
  362. setViewComponents(view2, storageItem.name, R.C2136drawable.folder, R.C2136drawable.more);
  363. break;
  364. } else {
  365. setViewComponents(view2, storageItem.name, R.C2136drawable.parent_folder, R.C2136drawable.more);
  366. break;
  367. }
  368. case LOADMORE:
  369. String str = storageItem.name;
  370. if (str == null) {
  371. str = StorageProcessDownloadActivity.this.getString(R.string.storage_item_load_more_photos);
  372. }
  373. setViewComponents(view2, str, -12345, -12345);
  374. break;
  375. case FILE:
  376. setViewComponents(view2, storageItem.name, R.C2136drawable.file, -12345);
  377. break;
  378. case PHOTO:
  379. setViewComponents(view2, storageItem.name, R.C2136drawable.image, -12345);
  380. StorageProcessDownloadActivity.this.getEnumerator().setThumbnailInBackground(storageItem, getIconView(view2));
  381. break;
  382. }
  383. this.viewCache.put(storageItem, view2);
  384. }
  385. return view2;
  386. }
  387. StorageItemAdapter(List<StorageItem> list) {
  388. super(StorageProcessDownloadActivity.this.getBaseContext(), R.layout.file_list_item, list);
  389. this.layoutInflater = (LayoutInflater) StorageProcessDownloadActivity.this.getBaseContext().getSystemService("layout_inflater");
  390. this.storageItems = list;
  391. this.viewCache = new HashMap<>();
  392. }
  393. private void setViewComponents(View view, String str, int i, int i2) {
  394. ((TextView) view.findViewById(R.id.file_folder_name)).setText(str);
  395. ImageView imageView = (ImageView) view.findViewById(R.id.file_folder_icon);
  396. if (i == -12345) {
  397. imageView.setVisibility(8);
  398. } else {
  399. imageView.setImageResource(i);
  400. imageView.setVisibility(0);
  401. }
  402. ImageView imageView2 = (ImageView) view.findViewById(R.id.browse_folder);
  403. if (i2 == -12345) {
  404. imageView2.setVisibility(8);
  405. return;
  406. }
  407. imageView2.setImageResource(i2);
  408. imageView2.setVisibility(0);
  409. }
  410. private void setTaskingStatus(boolean z) {
  411. this.taskRunningNow = z;
  412. }
  413. private void addLoaedMoreItems(List<StorageItem> list) {
  414. List<StorageItem> list2 = this.storageItems;
  415. list2.remove(list2.size() - 1);
  416. this.storageItems.addAll(list);
  417. }
  418. private ImageView getIconView(View view) {
  419. return (ImageView) view.findViewById(R.id.file_folder_icon);
  420. }
  421. }
  422. /* access modifiers changed from: private */
  423. public void taskInvoked(boolean z) {
  424. StorageItemAdapter storageItemAdapter = (StorageItemAdapter) this.mListView.getAdapter();
  425. if (storageItemAdapter != null) {
  426. storageItemAdapter.setTaskingStatus(z);
  427. }
  428. boolean z2 = true;
  429. if (z) {
  430. z2 = false;
  431. }
  432. setSignInButtonEnabled(z2);
  433. }
  434. /* access modifiers changed from: private */
  435. public void saveDownloadedFilePath(String str) {
  436. getSharedPreferences("StorageProcessDownloadActivity.Preference", 0).edit().putString("Downloaded.File.Path", str).apply();
  437. }
  438. private String fetchDownloadedFilePath() {
  439. return getSharedPreferences("StorageProcessDownloadActivity.Preference", 0).getString("Downloaded.File.Path", (String) null);
  440. }
  441. /* access modifiers changed from: private */
  442. public StorageServiceClient.Enumerator getEnumerator() {
  443. if (this.mEnumerator == null) {
  444. this.mEnumerator = getStorageClient().getEnumerator(this);
  445. }
  446. return this.mEnumerator;
  447. }
  448. @NonNull
  449. public static Intent getStartIntent(@NonNull Context context, String str) {
  450. Intent intent = new Intent(context, StorageProcessDownloadActivity.class);
  451. PrintLog printLog = new PrintLog();
  452. printLog.uiRoute = getOnlineStorageUiRouteValue(str);
  453. intent.putExtra("print_log", printLog);
  454. setCommonExtra(intent, str);
  455. return intent;
  456. }
  457. private static int getOnlineStorageUiRouteValue(String str) {
  458. if (str == null) {
  459. return -1;
  460. }
  461. if (StorageServiceClient.STORAGE_BOX.equals(str)) {
  462. return PrintLog.PRINT_SOURCE_BOX;
  463. }
  464. if (StorageServiceClient.STORAGE_DROPBOX.equals(str)) {
  465. return PrintLog.PRINT_SOURCE_DROPBOX;
  466. }
  467. if (StorageServiceClient.STORAGE_EVERNOTE.equals(str)) {
  468. return 256;
  469. }
  470. if (StorageServiceClient.STORAGE_GOOGLEDRIVE.equals(str)) {
  471. return 257;
  472. }
  473. if (StorageServiceClient.STORAGE_ONEDRIVE.equals(str)) {
  474. return PrintLog.PRINT_SOURCE_ONEDRIVE;
  475. }
  476. return -1;
  477. }
  478. }