private void deleteTorrentRequest(boolean withFiles) { ArrayList<String> list = new ArrayList<>(); list.add(torrentId); TorrentHelper.deleteTorrents(activity.getApplicationContext(), list, withFiles); }
private void addTorrent(AddTorrentParams params) { Intent i = new Intent(activity.getApplicationContext(), TorrentTaskService.class); i.setAction(TorrentTaskService.ACTION_ADD_TORRENT); i.putExtra(TorrentTaskService.TAG_ADD_TORRENT_PARAMS, params); i.putExtra(TorrentTaskService.TAG_SAVE_TORRENT_FILE, true); activity.startService(i); }
private String makeCreator() { if (fragment.get() == null) return ""; Context context = fragment.get().activity.getApplicationContext(); String creator = context.getString(R.string.app_name); String versionName = Utils.getAppVersionName(context); if (versionName == null) return creator; return creator + " " + versionName; }
private static void openMainActivity(AppCompatActivity activity) { Intent main = new Intent(activity.getApplicationContext(), MainActivity.class); activity.startActivity(main); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == ADD_TORRENT_REQUEST && resultCode == Activity.RESULT_OK) { if (data.hasExtra(AddTorrentActivity.TAG_ADD_TORRENT_PARAMS)) { AddTorrentParams params = data.getParcelableExtra(AddTorrentActivity.TAG_ADD_TORRENT_PARAMS); if (params != null) { Intent i = new Intent(activity.getApplicationContext(), TorrentTaskService.class); i.setAction(TorrentTaskService.ACTION_ADD_TORRENT); i.putExtra(TorrentTaskService.TAG_ADD_TORRENT_PARAMS, params); activity.startService(i); } } } }
public void openFile(String relativePath) { if (relativePath == null) return; String path = torrent.getDownloadPath() + File.separator + relativePath; Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); /* Give user a choice than to open file (without determining MIME type) */ intent.setDataAndType(FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", new File(path)), "*/*"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(Intent.createChooser(intent, getString(R.string.open_using))); }
public void setDownloadPath(String path) { if (path == null) { return; } downloadDir = path; pathToUploadView.setText(path); freeSpaceView.setText(String.format(getString(R.string.free_space), Formatter.formatFileSize(activity.getApplicationContext(), FileIOUtils.getFreeSpace(path)))); }
private void updateFileSize() { if (fileTree == null) return; filesSize.setText(String.format(getString(R.string.files_size), Formatter.formatFileSize(activity.getApplicationContext(), fileTree.selectedFileSize()), Formatter.formatFileSize(activity.getApplicationContext(), fileTree.size()))); }
private void updateFileSize() { if (fileTree == null) return; filesSize.setText(String.format(getString(R.string.files_size), Formatter.formatFileSize(activity.getApplicationContext(), fileTree.selectedFileSize()), Formatter.formatFileSize(activity.getApplicationContext(), fileTree.size()))); }
private void setTabLayoutColor(int colorId) { if (tabLayout == null) return; Utils.setBackground(tabLayout, ContextCompat.getDrawable(activity.getApplicationContext(), colorId)); }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == DIR_CHOOSER_REQUEST) { if (resultCode == Activity.RESULT_OK) { if (data.hasExtra(FileManagerDialog.TAG_RETURNED_PATH)) { downloadDir = data.getStringExtra(FileManagerDialog.TAG_RETURNED_PATH); pathToUploadView.setText(downloadDir); freeSpace.setText( String.format(getString(R.string.free_space), Formatter.formatFileSize(activity.getApplicationContext(), FileIOUtils.getFreeSpace(downloadDir)))); } } } }
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == DIR_CHOOSER_REQUEST && resultCode == Activity.RESULT_OK) { if (data.hasExtra(FileManagerDialog.TAG_RETURNED_PATH)) { downloadDir = data.getStringExtra(FileManagerDialog.TAG_RETURNED_PATH); pathToUploadView.setText(downloadDir); freeSpaceView.setText(String.format(getString(R.string.free_space), Formatter.formatFileSize(activity.getApplicationContext(), FileIOUtils.getFreeSpace(downloadDir)))); if (callback != null) callback.onTorrentInfoChanged(); } } }
public DependencyHandler( @NonNull AppCompatActivity activity, @NonNull CardInputWidget cardInputWidget, @NonNull ListView outputListView) { mCardInputWidget = cardInputWidget; mContext = activity.getApplicationContext(); mProgresDialogController = new ProgressDialogController(activity.getSupportFragmentManager()); mListViewController = new ListViewController(outputListView); mErrorDialogHandler = new ErrorDialogHandler(activity.getSupportFragmentManager()); }
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); HeavyInstanceStorage storage = HeavyInstanceStorage.getInstance(getFragmentManager()); if (storage != null) { Bundle heavyInstance = storage.popData(HEAVY_STATE_TAG); if (heavyInstance != null) info = heavyInstance.getParcelable(TAG_INFO); } if (savedInstanceState != null) { downloadDir = savedInstanceState.getString(TAG_DOWNLOAD_DIR); customName = savedInstanceState.getString(TAG_CUSTOM_NAME); } else { downloadDir = TorrentUtils.getTorrentDownloadPath(activity.getApplicationContext()); } }
private void changeFilesPriorityRequest(Priority[] priorities) { if (priorities == null || torrentId == null) return; try { TorrentHelper.changeFilesPriority(activity.getApplicationContext(), torrentId, priorities); } catch (FreeSpaceException e) { Snackbar.make(coordinatorLayout, R.string.error_free_space, Snackbar.LENGTH_LONG) .show(); } }
private void fetchStates() { Bundle states = TorrentHelper.makeBasicStatesList(); List<TorrentListItem> items = statesToItems(states); if (items.isEmpty()) { states = TorrentHelper.makeOfflineStatesList(activity.getApplicationContext()); items = statesToItems(states); } reloadAdapter(items); }
private void shareStreamUrl(String fileName) { if (curDir == null) return; TorrentContentFileTree file = curDir.getChild(fileName); if (file == null || !file.isFile()) return; int fileIndex = file.getIndex(); SharedPreferences pref = SettingsManager.getPreferences(activity.getApplicationContext()); String hostname = pref.getString(getString(R.string.pref_key_streaming_hostname), SettingsManager.Default.streamingHostname); int port = pref.getInt(getString(R.string.pref_key_streaming_port), SettingsManager.Default.streamingPort); String url = TorrentStreamServer.makeStreamUrl(hostname, port, torrentId, fileIndex); Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "url"); sharingIntent.putExtra(Intent.EXTRA_TEXT, url); startActivity(Intent.createChooser(sharingIntent, getString(R.string.share_via)));; } }
private void saveErrorTorrentFileDialog(Exception e) { sentError = e; FragmentManager fm = getFragmentManager(); if (fm != null && fm.findFragmentByTag(TAG_SAVE_ERR_TORRENT_FILE_DIALOG) == null) { ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance( activity.getApplicationContext(), getString(R.string.error), getString(R.string.error_save_torrent_file), (e != null ? Log.getStackTraceString(e) : null), this); errDialog.show(fm, TAG_SAVE_ERR_TORRENT_FILE_DIALOG); } }
private void exportErrorDialog(Exception e) { sentError = e; FragmentManager fm = getFragmentManager(); if (fm == null) return; if (fm.findFragmentByTag(TAG_EXPORT_ERROR_DIALOG) == null) { ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance( activity.getApplicationContext(), getString(R.string.error), getString(R.string.error_export_feeds), (e != null ? Log.getStackTraceString(e) : null), this); errDialog.show(fm, TAG_EXPORT_ERROR_DIALOG); } }
private void addChannelDialog() { FragmentManager fm = getFragmentManager(); if (fm != null && fm.findFragmentByTag(TAG_ADD_CHANNEL_DIALOG) == null) { AddRssChannelDialog addDialog = AddRssChannelDialog.newInstance( activity.getApplicationContext(), getString(R.string.add_feed_channel), getString(R.string.ok), FeedFragment.this); addDialog.show(fm, TAG_ADD_CHANNEL_DIALOG); } }