ListAndDownloadActivity.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. package com.epson.iprint.storage.gdrivev3;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.graphics.Typeface;
  5. import android.os.Build;
  6. import android.os.Bundle;
  7. import android.support.annotation.NonNull;
  8. import android.support.annotation.Nullable;
  9. import android.support.p000v4.app.Fragment;
  10. import android.support.p000v4.app.FragmentManager;
  11. import android.view.Menu;
  12. import android.view.MenuItem;
  13. import android.view.View;
  14. import android.widget.AdapterView;
  15. import android.widget.ListView;
  16. import android.widget.TextView;
  17. import com.epson.iprint.prtlogger.PrintLog;
  18. import com.epson.iprint.storage.ConfirmCancelDialog;
  19. import com.epson.iprint.storage.LocalProgressDialog;
  20. import com.epson.iprint.storage.OneButtonDialogFragment;
  21. import com.epson.iprint.storage.StorageProcessDownloadActivity;
  22. import com.epson.iprint.storage.gdrivev3.GoogleDownloadContract;
  23. import com.epson.iprint.storage.gdrivev3.IprintGoogleSignIn;
  24. import epson.print.ActivityIACommon;
  25. import epson.print.R;
  26. import java.util.ArrayList;
  27. import java.util.Iterator;
  28. import java.util.LinkedList;
  29. public class ListAndDownloadActivity extends ActivityIACommon implements ActivityWrapper, GoogleDownloadContract.View, OneButtonDialogFragment.DialogCallback, ConfirmCancelDialog.DialogCancelListener {
  30. private static final String DIALOG_TAG_CONFIRM_CANCEL = "confirm-cancel";
  31. private static final String DIALOG_TAG_DOWNLOAD_FAILED = "download_failed";
  32. private static final String DIALOG_TAG_OFFLINE_ERROR = "offline_error";
  33. private static final String DIALOG_TAG_SIGN_IN_FAILED = "sign-in_failed";
  34. private static final String FRAGMENT_TAG_PROGRESS = "fragment-progress";
  35. private static final int REQUEST_CODE_CHECK_PLAY_SERVICE = 11;
  36. private static final int REQUEST_CODE_DOWNLOAD_PREVIEW_END = 12;
  37. private static final int REQUEST_CODE_SIGN_IN = 10;
  38. private static final int REQUEST_CODE_SIGN_IN_ADD_SCOPE = 13;
  39. private boolean mActivityForeground;
  40. private FileListAdapter mFileListAdapter;
  41. private LinkedList<Runnable> mForegroundRunnableList;
  42. private GoogleDownloadContract.UserActionListener mGoogleDownloadPresenter;
  43. private boolean mIsDownloadInterruption = false;
  44. private ListView mListView;
  45. /* access modifiers changed from: private */
  46. public int mPosition = 0;
  47. private TextView mSignInMessage;
  48. private boolean mSignInOutButtonEnabled;
  49. private int mSignInOutButtonType;
  50. private IprintGoogleSignIn.StartActivityResultCallback mSignInStartActivityCallback;
  51. @NonNull
  52. public Activity getActivity() {
  53. return this;
  54. }
  55. @NonNull
  56. public ActivityWrapper getActivityWrapper() {
  57. return this;
  58. }
  59. public int getPlayServiceRequestCode() {
  60. return 11;
  61. }
  62. public int getSingInAddScopeRequestCode() {
  63. return 13;
  64. }
  65. /* access modifiers changed from: protected */
  66. public void onCreate(Bundle bundle) {
  67. super.onCreate(bundle);
  68. setContentView((int) R.layout.activity_list_and_download);
  69. setActionBar(getString(R.string.google_drive), true);
  70. this.mGoogleDownloadPresenter = Injection.provideDownloadPresenter(this);
  71. this.mSignInOutButtonEnabled = true;
  72. this.mForegroundRunnableList = new LinkedList<>();
  73. this.mListView = (ListView) findViewById(16908298);
  74. this.mListView.setCacheColorHint(0);
  75. this.mFileListAdapter = new FileListAdapter(getApplicationContext());
  76. this.mListView.setAdapter(this.mFileListAdapter);
  77. this.mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  78. public void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
  79. int unused = ListAndDownloadActivity.this.mPosition = i;
  80. ListAndDownloadActivity.this.localOnItemClick(i);
  81. }
  82. });
  83. this.mSignInMessage = (TextView) findViewById(16908292);
  84. this.mSignInMessage.setText(R.string.sign_in_request);
  85. this.mSignInMessage.setTypeface((Typeface) null, 1);
  86. this.mSignInMessage.setTextSize(18.0f);
  87. if (bundle != null) {
  88. clearFragments();
  89. }
  90. this.mGoogleDownloadPresenter.initView();
  91. }
  92. private void clearFragments() {
  93. removeProgressIfExists();
  94. deleteAllDialog();
  95. }
  96. private void deleteAllDialog() {
  97. for (String dismissDialog : new String[]{DIALOG_TAG_SIGN_IN_FAILED, DIALOG_TAG_DOWNLOAD_FAILED, DIALOG_TAG_OFFLINE_ERROR, DIALOG_TAG_CONFIRM_CANCEL}) {
  98. dismissDialog(dismissDialog);
  99. }
  100. }
  101. /* access modifiers changed from: private */
  102. public void dismissDialog(@NonNull final String str) {
  103. if (!this.mActivityForeground) {
  104. this.mForegroundRunnableList.addLast(new Runnable() {
  105. public void run() {
  106. ListAndDownloadActivity.this.dismissDialog(str);
  107. }
  108. });
  109. return;
  110. }
  111. Fragment findFragmentByTag = getSupportFragmentManager().findFragmentByTag(str);
  112. if (findFragmentByTag != null) {
  113. ((DialogFragment) findFragmentByTag).dismiss();
  114. }
  115. }
  116. /* access modifiers changed from: private */
  117. public void localOnItemClick(int i) {
  118. OnlineFile driveItem = this.mFileListAdapter.getDriveItem(i);
  119. if (driveItem != null) {
  120. this.mGoogleDownloadPresenter.itemSelected(driveItem);
  121. }
  122. }
  123. public boolean onOptionsItemSelected(MenuItem menuItem) {
  124. switch (menuItem.getItemId()) {
  125. case R.id.menu_signin /*2131231253*/:
  126. this.mGoogleDownloadPresenter.signInOrDisconnectClicked();
  127. return true;
  128. case R.id.menu_signout /*2131231254*/:
  129. this.mGoogleDownloadPresenter.signInOrDisconnectClicked();
  130. return true;
  131. default:
  132. return super.onOptionsItemSelected(menuItem);
  133. }
  134. }
  135. public boolean onCreateOptionsMenu(Menu menu) {
  136. getMenuInflater().inflate(R.C2138menu.menu_sign_inout, menu);
  137. if (this.mSignInOutButtonType == 0) {
  138. menu.removeItem(R.id.menu_signout);
  139. menu.findItem(R.id.menu_signin).setEnabled(this.mSignInOutButtonEnabled);
  140. return true;
  141. }
  142. menu.removeItem(R.id.menu_signin);
  143. menu.findItem(R.id.menu_signout).setEnabled(this.mSignInOutButtonEnabled);
  144. return true;
  145. }
  146. /* access modifiers changed from: protected */
  147. public void onActivityResult(int i, int i2, Intent intent) {
  148. switch (i) {
  149. case 10:
  150. IprintGoogleSignIn.StartActivityResultCallback startActivityResultCallback = this.mSignInStartActivityCallback;
  151. if (startActivityResultCallback != null) {
  152. startActivityResultCallback.onActivityResult(i2, intent);
  153. this.mSignInStartActivityCallback = null;
  154. return;
  155. }
  156. return;
  157. case 11:
  158. return;
  159. case 12:
  160. this.mGoogleDownloadPresenter.onPreviewActivityEnd();
  161. return;
  162. case 13:
  163. this.mGoogleDownloadPresenter.onAddScopeCompleted(i2 == -1);
  164. return;
  165. default:
  166. return;
  167. }
  168. }
  169. /* access modifiers changed from: protected */
  170. public void onPostResume() {
  171. super.onPostResume();
  172. this.mActivityForeground = true;
  173. processForegroundList();
  174. this.mGoogleDownloadPresenter.activityOnResume();
  175. }
  176. private void processForegroundList() {
  177. Iterator it = this.mForegroundRunnableList.iterator();
  178. while (it.hasNext()) {
  179. it.remove();
  180. ((Runnable) it.next()).run();
  181. }
  182. }
  183. /* access modifiers changed from: protected */
  184. public void onPause() {
  185. super.onPause();
  186. this.mGoogleDownloadPresenter.activityOnPause();
  187. this.mActivityForeground = false;
  188. }
  189. public void onBackPressed() {
  190. this.mGoogleDownloadPresenter.backKeyPressed();
  191. }
  192. public void requestSignIn(@NonNull Intent intent, @NonNull IprintGoogleSignIn.StartActivityResultCallback startActivityResultCallback) {
  193. this.mSignInStartActivityCallback = startActivityResultCallback;
  194. startActivityForResult(intent, 10);
  195. }
  196. public void setSignInButtonEnabled(boolean z) {
  197. invalidateOptionsMenu();
  198. }
  199. public void changeSignInOutButton(int i) {
  200. int i2 = 0;
  201. this.mSignInMessage.setVisibility(i == 0 ? 0 : 8);
  202. ListView listView = this.mListView;
  203. if (i == 0) {
  204. i2 = 8;
  205. }
  206. listView.setVisibility(i2);
  207. this.mSignInOutButtonType = i;
  208. invalidateOptionsMenu();
  209. }
  210. /* access modifiers changed from: private */
  211. public void showErrorDialog(final int i, final String str) {
  212. if (!this.mActivityForeground) {
  213. this.mForegroundRunnableList.addLast(new Runnable() {
  214. public void run() {
  215. ListAndDownloadActivity.this.showErrorDialog(i, str);
  216. }
  217. });
  218. } else {
  219. OneButtonDialogFragment.newInstance(i, str).show(getSupportFragmentManager(), str);
  220. }
  221. }
  222. public void showSignInFailDialog() {
  223. showErrorDialog(R.string.authenticate_error_mes, DIALOG_TAG_SIGN_IN_FAILED);
  224. }
  225. public void showDownloadErrorDialog() {
  226. showErrorDialog(R.string.download_error_mes, DIALOG_TAG_DOWNLOAD_FAILED);
  227. }
  228. public void showOfflineErrorDialog() {
  229. showErrorDialog(R.string.network_error_mes, DIALOG_TAG_OFFLINE_ERROR);
  230. }
  231. public void clearListItems() {
  232. this.mFileListAdapter.clearItems();
  233. }
  234. public void showProgress() {
  235. this.mSignInOutButtonEnabled = false;
  236. invalidateOptionsMenu();
  237. showProgressFragment(false, 0);
  238. }
  239. /* access modifiers changed from: private */
  240. public void showProgressFragment(final boolean z, final int i) {
  241. if (!this.mActivityForeground) {
  242. this.mForegroundRunnableList.addLast(new Runnable() {
  243. public void run() {
  244. ListAndDownloadActivity.this.showProgressFragment(z, i);
  245. }
  246. });
  247. return;
  248. }
  249. FragmentManager supportFragmentManager = getSupportFragmentManager();
  250. supportFragmentManager.beginTransaction().add(16908290, LocalProgressDialog.newInstance(z, i, DIALOG_TAG_CONFIRM_CANCEL), FRAGMENT_TAG_PROGRESS).commit();
  251. }
  252. public void showDownloadProgress() {
  253. this.mSignInOutButtonEnabled = false;
  254. invalidateOptionsMenu();
  255. showProgressFragment(true, R.string.downloading_notification);
  256. }
  257. public void dismissProgress() {
  258. dismissDialog(DIALOG_TAG_CONFIRM_CANCEL);
  259. removeProgressIfExists();
  260. this.mSignInOutButtonEnabled = true;
  261. invalidateOptionsMenu();
  262. }
  263. public void listFiles(@Nullable ArrayList<OnlineFile> arrayList) {
  264. if (arrayList == null) {
  265. clearListItems();
  266. showErrorDialog(R.string.unknow_error_mes, DIALOG_TAG_DOWNLOAD_FAILED);
  267. return;
  268. }
  269. this.mFileListAdapter.setDriveFile(arrayList);
  270. }
  271. public void startPreviewActivity(String str) {
  272. startActivityForResult(StorageProcessDownloadActivity.getPreviewIntent(str, getApplicationContext(), new PrintLog()), 12);
  273. }
  274. public void finishActivity() {
  275. finish();
  276. }
  277. public void buttonPressed(@Nullable String str) {
  278. if (str != null) {
  279. char c = 65535;
  280. int hashCode = str.hashCode();
  281. if (hashCode != -683930452) {
  282. if (hashCode != 156934100) {
  283. if (hashCode == 366991495 && str.equals(DIALOG_TAG_SIGN_IN_FAILED)) {
  284. c = 0;
  285. }
  286. } else if (str.equals(DIALOG_TAG_DOWNLOAD_FAILED)) {
  287. c = 1;
  288. }
  289. } else if (str.equals(DIALOG_TAG_OFFLINE_ERROR)) {
  290. c = 2;
  291. }
  292. switch (c) {
  293. case 0:
  294. return;
  295. case 1:
  296. return;
  297. case 2:
  298. startActivity(new Intent("android.settings.WIRELESS_SETTINGS"));
  299. finish();
  300. return;
  301. default:
  302. return;
  303. }
  304. }
  305. }
  306. public void cancel() {
  307. this.mGoogleDownloadPresenter.cancelDownload();
  308. }
  309. /* access modifiers changed from: protected */
  310. public void onStop() {
  311. super.onStop();
  312. if (!this.mGoogleDownloadPresenter.isDownloading() || Build.VERSION.SDK_INT < 29) {
  313. this.mIsDownloadInterruption = false;
  314. return;
  315. }
  316. this.mIsDownloadInterruption = true;
  317. cancel();
  318. }
  319. /* access modifiers changed from: protected */
  320. public void onRestart() {
  321. super.onRestart();
  322. if (this.mIsDownloadInterruption) {
  323. localOnItemClick(this.mPosition);
  324. }
  325. this.mIsDownloadInterruption = false;
  326. }
  327. /* access modifiers changed from: private */
  328. public void removeProgressIfExists() {
  329. if (!this.mActivityForeground) {
  330. this.mForegroundRunnableList.addLast(new Runnable() {
  331. public void run() {
  332. ListAndDownloadActivity.this.removeProgressIfExists();
  333. }
  334. });
  335. return;
  336. }
  337. FragmentManager supportFragmentManager = getSupportFragmentManager();
  338. Fragment findFragmentByTag = supportFragmentManager.findFragmentByTag(FRAGMENT_TAG_PROGRESS);
  339. if (findFragmentByTag != null) {
  340. supportFragmentManager.beginTransaction().remove(findFragmentByTag).commit();
  341. }
  342. }
  343. }