use of com.frostwire.android.gui.activities.MainActivity in project frostwire by frostwire.
the class NavigationMenu method initNavigationView.
private NavigationView initNavigationView(final MainActivity activity) {
NavigationView resultNavView = navView;
if (navView == null) {
resultNavView = activity.findViewById(R.id.activity_main_nav_view);
resultNavView.setNavigationItemSelectedListener(menuItem -> {
onMenuItemSelected(menuItem);
return true;
});
View navViewHeader = resultNavView.getHeaderView(0);
// Logo
ImageView navLogo = navViewHeader.findViewById(R.id.nav_view_header_main_app_logo);
navLogo.setOnClickListener(v -> UIUtils.openURL(v.getContext(), Constants.FROSTWIRE_GIVE_URL));
// Prep title and version
TextView title = navViewHeader.findViewById(R.id.nav_view_header_main_title);
TextView version = navViewHeader.findViewById(R.id.nav_view_header_main_version);
String basicOrPlus = (String) activity.getText(Constants.IS_GOOGLE_PLAY_DISTRIBUTION ? R.string.basic : R.string.plus);
boolean isDevelopment = Constants.IS_BASIC_AND_DEBUG;
if (isDevelopment) {
basicOrPlus = "Developer";
}
title.setText("FrostWire " + basicOrPlus);
version.setText(" v" + Constants.FROSTWIRE_VERSION_STRING);
TextView build = navViewHeader.findViewById(R.id.nav_view_header_main_build);
build.setText(activity.getText(R.string.build) + " " + BuildConfig.VERSION_CODE);
View.OnClickListener aboutActivityLauncher = v -> {
Intent intent = new Intent(v.getContext(), AboutActivity.class);
v.getContext().startActivity(intent);
};
title.setOnClickListener(aboutActivityLauncher);
version.setOnClickListener(aboutActivityLauncher);
build.setOnClickListener(aboutActivityLauncher);
// Prep update button
ImageView updateButton = navViewHeader.findViewById(R.id.nav_view_header_main_update);
updateButton.setVisibility(View.GONE);
updateButton.setOnClickListener(v -> onUpdateButtonClicked(activity));
}
return resultNavView;
}
use of com.frostwire.android.gui.activities.MainActivity in project frostwire by frostwire.
the class PromotionsAdapter method startVideoPreview.
private void startVideoPreview(String videoURL) {
// frostwire-preview is not a mobile friendly experience, let's take them straight to youtube
if (videoURL.startsWith(Constants.FROSTWIRE_PREVIEW_DOT_COM_URL)) {
videoURL = videoURL.substring(videoURL.indexOf("detailsUrl=") + "detailsUrl=".length());
}
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(videoURL));
((MainActivity) getContext()).startActivityForResult(i, MainActivity.PROMO_VIDEO_PREVIEW_RESULT_CODE);
}
use of com.frostwire.android.gui.activities.MainActivity in project frostwire by frostwire.
the class SoftwareUpdater method notifyUserAboutUpdate.
public void notifyUserAboutUpdate(final MainActivity activity) {
try {
if (update.a == null) {
// make it the old behavior
update.a = UPDATE_ACTION_OTA;
}
if (update.a.equals(UPDATE_ACTION_OTA)) {
if (!ALWAYS_SHOW_UPDATE_DIALOG && !getUpdateApk().exists()) {
LOG.info("notifyUserAboutUpdate(): " + getUpdateApk().getAbsolutePath() + " not found. Aborting.");
return;
}
// Fresh runs with fast connections might send the broadcast intent before
// MainActivity has had a chance to register the broadcast receiver (onResume)
// therefore, the menu update icon will only show on the 2nd run only
activity.updateNavigationMenu(true);
SoftwareUpdaterDialog dlg = SoftwareUpdaterDialog.newInstance(update.updateMessages, update.changelog);
dlg.show(activity.getFragmentManager());
} else if (update.a.equals(UPDATE_ACTION_MARKET)) {
String message = StringUtils.getLocaleString(update.marketMessages, activity.getString(R.string.update_message));
UIUtils.showYesNoDialog(activity.getFragmentManager(), message, R.string.update_title, (dialog, which) -> {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(update.m));
activity.startActivity(intent);
});
}
} catch (Throwable e) {
LOG.error("Failed to notify update", e);
// try again next time MainActivity is resumed
updateTimestamp = -1;
}
}
use of com.frostwire.android.gui.activities.MainActivity in project frostwire by frostwire.
the class TransfersFragment method startYouTubeSearchFromUrl.
private void startYouTubeSearchFromUrl(String ytUrl) {
// fragments are not supposed to communicate directly so I'll let my activity know
// (NOTE: This is a poor implementation of fragment to fragment communication
// despite what the android documentation says http://developer.android.com/training/basics/fragments/communicating.html
// as this could not scale if you wanted to reuse fragments on other activities)
MainActivity activity = (MainActivity) getActivity();
activity.performYTSearch(ytUrl);
}
use of com.frostwire.android.gui.activities.MainActivity in project frostwire by frostwire.
the class FileListAdapter method localPlay.
private void localPlay(FileDescriptor fd, View view, int position) {
if (fd == null) {
return;
}
onLocalPlay();
Context ctx = getContext();
if (fd.mime != null && fd.mime.contains("audio")) {
if (fd.equals(Engine.instance().getMediaPlayer().getCurrentFD(getContext()))) {
Engine.instance().getMediaPlayer().stop();
} else {
try {
UIUtils.playEphemeralPlaylist(ctx, fd);
UXStats.instance().log(UXAction.LIBRARY_PLAY_AUDIO_FROM_FILE);
} catch (RuntimeException re) {
re.printStackTrace();
UIUtils.showShortMessage(ctx, R.string.media_player_failed);
}
}
notifyDataSetChanged();
} else {
if (fd.filePath != null && fd.mime != null) {
// special treatment of ringtones
if (fd.fileType == Constants.FILE_TYPE_RINGTONES) {
playRingtone(fd);
} else if (fd.fileType == Constants.FILE_TYPE_PICTURES && ctx instanceof MainActivity) {
Intent intent = new Intent(ctx, ImageViewerActivity.class);
intent.putExtra(ImageViewerFragment.EXTRA_FILE_DESCRIPTOR_BUNDLE, fd.toBundle());
intent.putExtra(ImageViewerFragment.EXTRA_ADAPTER_FILE_OFFSET, position);
ctx.startActivity(intent);
} else if ("application/x-bittorrent".equals(fd.mime)) {
// torrents are often DOCUMENT typed
TransferManager.instance().downloadTorrent(UIUtils.getFileUri(ctx, fd.filePath, false).toString());
UIUtils.showTransfersOnDownloadStart(ctx);
} else {
UIUtils.openFile(ctx, fd.filePath, fd.mime, true);
}
} else {
// it will automatically remove the 'Open' entry.
MenuAdapter menuAdapter = getMenuAdapter(view);
if (menuAdapter != null) {
new MenuBuilder(menuAdapter).show();
UIUtils.showShortMessage(ctx, R.string.cant_open_file);
}
}
}
}
Aggregations