@Override public boolean onMenuItemClick(MenuItem menuItem) { final Metadata item = GDriveBackupsAdapter.getItem(clickedPosition); switch (menuItem.getItemId()) { case R.id.menu_gDrive_remove: { gDrive.deleteBackup( item, new GDriveRemoveTask.DoneSuccess() { @Override public void done() { gDrive.getListOfBackups(GDriveBackupsAdapter); } }); return true; } case R.id.menu_gDrive_restore: { gDrive.restoreBackup(item.getDriveId()); return true; } } return false; }
@Override public void onPause() { GDriveBackupsAdapter.clear(); gDrive.onStop(); gDrive.setObserver(null); super.onPause(); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_help: { //noinspection ConstantConditions new AlertDialog.Builder(getActivity()) .setTitle(R.string.menu_help) .setMessage(R.string.help_gDrive) .setIcon(android.R.drawable.ic_menu_help) .show(); return true; } case R.id.menu_backup: gDrive.createNewBackup( new GDriveCreateBackupTask.BackupDoneSuccess() { @Override public void done() { gDrive.getListOfBackups(GDriveBackupsAdapter); } }); return true; case R.id.menu_login: enableGDrive(true); return true; case R.id.menu_logout: enableGDrive(false); return true; case R.id.refresh: gDrive.getListOfBackups(GDriveBackupsAdapter); return true; } return false; }
private void enableGDrive(boolean enable) { if (enable) { gDrive.setObserver(this); gDrive.onStart(MainActivity.instance); } else { GDriveBackupsAdapter.clear(); gDrive.onStop(); gDrive.resetAccount(); } }
@Override public void gDriveConnected(final boolean connected, final boolean canceled) { mPullToRefreshLayout.setRefreshing(false); if (connected) { statusText.setText(R.string.gDriveConnected); gDrive.getListOfBackups(GDriveBackupsAdapter); } else if (gDrive.isError()) { GDriveBackupsAdapter.clear(); statusText.setText(gDrive.getErrorMessage()); } else { GDriveBackupsAdapter.clear(); statusText.setText(R.string.gDriveDisconnected); } getActivity().invalidateOptionsMenu(); }
public PlayList getCloudPlayList(String folderPath, Long userId) { GDrive gDrive = null; UserEntity userEntity = UserEntity.getUserById(userId); try { String driveAccessToken = userEntity.getDriveAccessToken(); String driveRefreshToken = userEntity.getDriveRefreshToken(); if (driveAccessToken != null && driveRefreshToken != null) { gDrive = new GDrive(driveAccessToken, driveRefreshToken); this.playList = gDrive.getFileList(folderPath, REQUIRED_FILE_TYPES); } } catch (UnauthorizedAccessException e) { gDrive.setAccessToken(gDrive.refreshToken(gDrive.getRefreshToken())); try { this.playList = gDrive.getFileList(folderPath, REQUIRED_FILE_TYPES); userEntity.setDriveAccessToken(gDrive.getAccessToken()); userEntity.update(); } catch (Exception e1) { Logger.error("Exception in getCloudPlayList", e1); } } catch (Exception e) { Logger.error("Exception in getCloudPlayList", e); } return this.playList; }
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.g_drive_fragment, menu); boolean connected = gDrive.isConnected(); menu.findItem(R.id.menu_login).setVisible(!connected); menu.findItem(R.id.menu_logout).setVisible(connected); menu.findItem(R.id.refresh).setVisible(connected); }
@Override public void onActivityResult(int requestCode, int resultCode, final Intent data) { gDrive.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data); }
@Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); gDrive.onSaveInstanceState(outState); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); gDrive.onCreate(savedInstanceState); }
@Override public void onRefreshStarted(View view) { gDrive.getListOfBackups(GDriveBackupsAdapter); }