EvernoteClient.java 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package com.epson.iprint.storage.evernote;
  2. import android.app.Activity;
  3. import android.content.Context;
  4. import android.os.AsyncTask;
  5. import com.epson.iprint.storage.StorageItem;
  6. import com.epson.iprint.storage.StorageServiceClient;
  7. import com.epson.iprint.storage.evernote.EvernoteRequest;
  8. import epson.print.CommonDefine;
  9. import epson.print.Util.AsyncTaskExecutor;
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import org.apache.commons.lang.CharEncoding;
  13. public class EvernoteClient extends StorageServiceClient {
  14. public String getStorageServiceName(Context context) {
  15. return "Evernote";
  16. }
  17. public boolean isSupportedUploadType(StorageServiceClient.UploadFileType uploadFileType) {
  18. return true;
  19. }
  20. public boolean isSignedIn(Context context) {
  21. return epson.server.service.EvernoteClient.getEvernoteSession(context).isLoggedIn();
  22. }
  23. public boolean revokeSignedInData(Activity activity) {
  24. epson.server.service.EvernoteClient.logout(activity);
  25. return true;
  26. }
  27. public boolean isValidUploadName(String str) {
  28. if (str.startsWith(CommonDefine.DOT)) {
  29. return false;
  30. }
  31. try {
  32. if (str.getBytes(CharEncoding.UTF_8).length > 256) {
  33. return false;
  34. }
  35. for (char indexOf : str.toCharArray()) {
  36. if ("\\/:,;*?<>|#、\"".indexOf(indexOf) > -1) {
  37. return false;
  38. }
  39. }
  40. return super.isValidUploadName(str);
  41. } catch (Exception unused) {
  42. return false;
  43. }
  44. }
  45. public StorageServiceClient.Uploader getUploader(final Context context, StorageServiceClient.UploadFileType uploadFileType, final String str, final String str2) {
  46. return new StorageServiceClient.Uploader() {
  47. EvernoteRequest request = new EvernoteRequest(context);
  48. StorageServiceClient.UploadCompletion uploaded;
  49. EvernoteRequest.UploadHandler uploader = this.request.getUploadHandler();
  50. public boolean isCancelable() {
  51. return false;
  52. }
  53. /* renamed from: com.epson.iprint.storage.evernote.EvernoteClient$1$UploadTask */
  54. class UploadTask extends AsyncTaskExecutor<Void, Void, Void> {
  55. UploadTask() {
  56. }
  57. /* access modifiers changed from: protected */
  58. public Void doInBackground(Void... voidArr) {
  59. StorageServiceClient.ProcessError processError;
  60. StorageServiceClient.ProcessError processError2 = StorageServiceClient.ProcessError.NONE;
  61. do {
  62. try {
  63. StorageItem uploadFolder = C09441.this.request.getUploadFolder();
  64. if (uploadFolder == null) {
  65. uploadFolder = C09441.this.request.newUploadFolder();
  66. }
  67. processError = C09441.this.uploader.upload(uploadFolder, str, str2);
  68. } catch (Exception e) {
  69. processError = C09441.this.request.handleException(e);
  70. }
  71. } while (StorageServiceClient.ProcessError.RETRY.equals(processError));
  72. C09441.this.uploaded.onUploadComplete(str, str2, processError);
  73. return null;
  74. }
  75. }
  76. public void start(StorageServiceClient.UploadCompletion uploadCompletion) {
  77. this.uploaded = uploadCompletion;
  78. new UploadTask().executeOnExecutor(new Void[0]);
  79. }
  80. public void cancel() {
  81. this.uploader.cancel();
  82. }
  83. };
  84. }
  85. public StorageServiceClient.Downloader getDownloader(final Context context, final StorageItem storageItem, final String str) {
  86. return new StorageServiceClient.Downloader() {
  87. StorageServiceClient.DownloadCompletion downloaded;
  88. EvernoteRequest.DownloadHandler downloader = this.request.getDownloadHandler();
  89. EvernoteRequest request = new EvernoteRequest(context);
  90. public boolean isCancelable() {
  91. return true;
  92. }
  93. /* renamed from: com.epson.iprint.storage.evernote.EvernoteClient$2$DownloadTask */
  94. class DownloadTask extends AsyncTask<Void, Void, Void> {
  95. DownloadTask() {
  96. }
  97. /* access modifiers changed from: protected */
  98. public Void doInBackground(Void... voidArr) {
  99. StorageServiceClient.ProcessError processError;
  100. StorageServiceClient.ProcessError processError2 = StorageServiceClient.ProcessError.NONE;
  101. do {
  102. try {
  103. processError = C09452.this.downloader.download(storageItem.path, str);
  104. } catch (Exception e) {
  105. processError = C09452.this.request.handleException(e);
  106. }
  107. } while (StorageServiceClient.ProcessError.RETRY.equals(processError));
  108. C09452.this.downloaded.onDownloadComplete(storageItem, str, processError);
  109. return null;
  110. }
  111. }
  112. public void start(StorageServiceClient.DownloadCompletion downloadCompletion) {
  113. this.downloaded = downloadCompletion;
  114. new DownloadTask().execute(new Void[0]);
  115. }
  116. public void cancel() {
  117. this.downloader.cancel();
  118. }
  119. };
  120. }
  121. public StorageServiceClient.Enumerator getEnumerator(final Context context) {
  122. return new StorageServiceClient.Enumerator() {
  123. StorageServiceClient.EnumerateCompletion enumerated;
  124. EvernoteRequest request = new EvernoteRequest(context);
  125. private List<StorageItem> getPrintableItems(List<StorageItem> list) {
  126. ArrayList arrayList = new ArrayList();
  127. for (StorageItem next : list) {
  128. if (next.type != StorageItem.ItemType.FILE || EvernoteClient.this.isPrintableFileTypes(next)) {
  129. arrayList.add(next);
  130. }
  131. }
  132. return arrayList;
  133. }
  134. /* renamed from: com.epson.iprint.storage.evernote.EvernoteClient$3$EnumerateTask */
  135. class EnumerateTask extends AsyncTask<StorageItem, Void, Void> {
  136. EnumerateTask() {
  137. }
  138. /* access modifiers changed from: protected */
  139. public Void doInBackground(StorageItem... storageItemArr) {
  140. StorageServiceClient.ProcessError processError;
  141. StorageServiceClient.ProcessError processError2 = StorageServiceClient.ProcessError.NONE;
  142. StorageItem storageItem = storageItemArr[0];
  143. List<StorageItem> list = null;
  144. do {
  145. try {
  146. processError = StorageServiceClient.ProcessError.NONE;
  147. list = C09463.this.request.getItemList(storageItem);
  148. } catch (Exception e) {
  149. processError = C09463.this.request.handleException(e);
  150. }
  151. } while (StorageServiceClient.ProcessError.RETRY.equals(processError));
  152. if (list != null) {
  153. list = C09463.this.getPrintableItems(list);
  154. } else {
  155. processError = StorageServiceClient.ProcessError.ERROR;
  156. }
  157. C09463.this.enumerated.onEnumerateComplete(list, processError);
  158. return null;
  159. }
  160. }
  161. public StorageItem getRootItem() {
  162. return this.request.getFeedItem();
  163. }
  164. public void enumerate(StorageItem storageItem, StorageServiceClient.EnumerateCompletion enumerateCompletion) {
  165. this.enumerated = enumerateCompletion;
  166. new EnumerateTask().execute(new StorageItem[]{storageItem});
  167. }
  168. };
  169. }
  170. }