Search in sources :

Example 6 with MainActivity

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;
}
Also used : NavigationView(android.support.design.widget.NavigationView) SoftwareUpdater(com.frostwire.android.gui.SoftwareUpdater) AboutActivity(com.frostwire.android.gui.activities.AboutActivity) ImageView(android.widget.ImageView) BuyActivity(com.frostwire.android.gui.activities.BuyActivity) Intent(android.content.Intent) MenuItem(android.view.MenuItem) Asyncs.async(com.frostwire.android.util.Asyncs.async) BuildConfig(com.frostwire.android.BuildConfig) MainActivity(com.frostwire.android.gui.activities.MainActivity) Handler(android.os.Handler) Looper(android.os.Looper) View(android.view.View) DrawerLayout(android.support.v4.widget.DrawerLayout) Offers(com.frostwire.android.offers.Offers) Fragment(android.app.Fragment) Engine(com.frostwire.android.gui.services.Engine) R(com.frostwire.android.R) UIUtils(com.frostwire.android.gui.util.UIUtils) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar) Constants(com.frostwire.android.core.Constants) Configuration(android.content.res.Configuration) RelativeLayout(android.widget.RelativeLayout) Activity(android.app.Activity) AdMenuItemView(com.frostwire.android.gui.views.AdMenuItemView) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) NavigationView(android.support.design.widget.NavigationView) AboutActivity(com.frostwire.android.gui.activities.AboutActivity) TextView(android.widget.TextView) Intent(android.content.Intent) ImageView(android.widget.ImageView) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AdMenuItemView(com.frostwire.android.gui.views.AdMenuItemView)

Example 7 with MainActivity

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);
}
Also used : Intent(android.content.Intent) MainActivity(com.frostwire.android.gui.activities.MainActivity)

Example 8 with MainActivity

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;
    }
}
Also used : ConfigurationManager(com.frostwire.android.core.ConfigurationManager) UXStats(com.frostwire.uxstats.UXStats) BufferedInputStream(java.io.BufferedInputStream) Logger(com.frostwire.util.Logger) MessageDigest(java.security.MessageDigest) Uri(android.net.Uri) Intent(android.content.Intent) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) StringUtils(com.frostwire.util.StringUtils) BuildConfig(com.frostwire.android.BuildConfig) MainActivity(com.frostwire.android.gui.activities.MainActivity) JsonUtils(com.frostwire.util.JsonUtils) Map(java.util.Map) BigInteger(java.math.BigInteger) WeakReference(java.lang.ref.WeakReference) HttpClientFactory(com.frostwire.util.HttpClientFactory) Offers(com.frostwire.android.offers.Offers) AsyncTask(android.os.AsyncTask) UXStatsConf(com.frostwire.uxstats.UXStatsConf) R(com.frostwire.android.R) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Ref(com.frostwire.util.Ref) File(java.io.File) SoftwareUpdaterDialog(com.frostwire.android.gui.dialogs.SoftwareUpdaterDialog) UIUtils(com.frostwire.android.gui.util.UIUtils) List(java.util.List) Platforms(com.frostwire.platform.Platforms) Constants(com.frostwire.android.core.Constants) InputStream(java.io.InputStream) SoftwareUpdaterDialog(com.frostwire.android.gui.dialogs.SoftwareUpdaterDialog) Intent(android.content.Intent)

Example 9 with MainActivity

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);
}
Also used : MainActivity(com.frostwire.android.gui.activities.MainActivity)

Example 10 with MainActivity

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);
            }
        }
    }
}
Also used : Context(android.content.Context) ImageViewerActivity(com.frostwire.android.gui.activities.ImageViewerActivity) MenuAdapter(com.frostwire.android.gui.views.MenuAdapter) Intent(android.content.Intent) MainActivity(com.frostwire.android.gui.activities.MainActivity) MenuBuilder(com.frostwire.android.gui.views.MenuBuilder)

Aggregations

MainActivity (com.frostwire.android.gui.activities.MainActivity)16 Intent (android.content.Intent)8 Fragment (android.app.Fragment)2 BuildConfig (com.frostwire.android.BuildConfig)2 R (com.frostwire.android.R)2 Constants (com.frostwire.android.core.Constants)2 TransfersFragment (com.frostwire.android.gui.fragments.TransfersFragment)2 UIUtils (com.frostwire.android.gui.util.UIUtils)2 Offers (com.frostwire.android.offers.Offers)2 Activity (android.app.Activity)1 Context (android.content.Context)1 Configuration (android.content.res.Configuration)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 NavigationView (android.support.design.widget.NavigationView)1 LocalBroadcastManager (android.support.v4.content.LocalBroadcastManager)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1