ListAndDownloadActivity.java 13 KB

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