Search in sources :

Example 1 with MODE_PRIVATE

use of android.content.Context.MODE_PRIVATE in project AntennaPod by AntennaPod.

the class QuickFeedDiscoveryFragment method loadToplist.

private void loadToplist() {
    progressBar.setVisibility(View.VISIBLE);
    discoverGridLayout.setVisibility(View.INVISIBLE);
    errorView.setVisibility(View.GONE);
    errorRetry.setVisibility(View.INVISIBLE);
    poweredByTextView.setVisibility(View.VISIBLE);
    ItunesTopListLoader loader = new ItunesTopListLoader(getContext());
    SharedPreferences prefs = getActivity().getSharedPreferences(ItunesTopListLoader.PREFS, MODE_PRIVATE);
    String countryCode = prefs.getString(ItunesTopListLoader.PREF_KEY_COUNTRY_CODE, Locale.getDefault().getCountry());
    if (countryCode.equals(ItunesTopListLoader.DISCOVER_HIDE_FAKE_COUNTRY_CODE)) {
        errorTextView.setText(String.format(getResources().getString(R.string.discover_is_hidden), getResources().getString(R.string.discover_hide)));
        errorView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.INVISIBLE);
        errorRetry.setVisibility(View.INVISIBLE);
        poweredByTextView.setVisibility(View.INVISIBLE);
        return;
    }
    disposable = loader.loadToplist(countryCode, NUM_SUGGESTIONS).subscribe(podcasts -> {
        errorView.setVisibility(View.GONE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.VISIBLE);
        if (podcasts.size() == 0) {
            errorTextView.setText(getResources().getText(R.string.search_status_no_results));
            errorView.setVisibility(View.VISIBLE);
            discoverGridLayout.setVisibility(View.INVISIBLE);
        } else {
            adapter.updateData(podcasts);
        }
    }, error -> {
        Log.e(TAG, Log.getStackTraceString(error));
        errorTextView.setText(error.getLocalizedMessage());
        errorView.setVisibility(View.VISIBLE);
        progressBar.setVisibility(View.GONE);
        discoverGridLayout.setVisibility(View.INVISIBLE);
        errorRetry.setVisibility(View.VISIBLE);
    });
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) GridView(android.widget.GridView) ProgressBar(android.widget.ProgressBar) Intent(android.content.Intent) FeedDiscoverAdapter(de.danoeh.antennapod.adapter.FeedDiscoverAdapter) ArrayList(java.util.ArrayList) Locale(java.util.Locale) EventBus(org.greenrobot.eventbus.EventBus) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Button(android.widget.Button) AdapterView(android.widget.AdapterView) Log(android.util.Log) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader) LayoutInflater(android.view.LayoutInflater) R(de.danoeh.antennapod.R) DiscoveryDefaultUpdateEvent(de.danoeh.antennapod.event.DiscoveryDefaultUpdateEvent) ThreadMode(org.greenrobot.eventbus.ThreadMode) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) MainActivity(de.danoeh.antennapod.activity.MainActivity) PodcastSearchResult(de.danoeh.antennapod.discovery.PodcastSearchResult) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) TextView(android.widget.TextView) Subscribe(org.greenrobot.eventbus.Subscribe) SharedPreferences(android.content.SharedPreferences) OnlineFeedViewActivity(de.danoeh.antennapod.activity.OnlineFeedViewActivity) SharedPreferences(android.content.SharedPreferences) ItunesTopListLoader(de.danoeh.antennapod.discovery.ItunesTopListLoader)

Example 2 with MODE_PRIVATE

use of android.content.Context.MODE_PRIVATE in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelWorker method removeUninstalledPackages.

private void removeUninstalledPackages() {
    final SharedPreferences prefs = getContext().getSharedPreferences(PREFS, MODE_PRIVATE);
    final Set<String> interactedPackages = prefs.getStringSet(PREF_KEY_INTERACTED_PACKAGES, new ArraySet());
    if (interactedPackages.isEmpty()) {
        return;
    }
    final List<PackageInfo> installedPackageInfos = getContext().getPackageManager().getInstalledPackages(0);
    final List<String> installedPackages = installedPackageInfos.stream().map(packageInfo -> packageInfo.packageName).collect(Collectors.toList());
    final Set<String> newInteractedPackages = new ArraySet<>();
    for (String packageName : interactedPackages) {
        if (installedPackages.contains(packageName)) {
            newInteractedPackages.add(packageName);
        }
    }
    prefs.edit().putStringSet(PREF_KEY_INTERACTED_PACKAGES, newInteractedPackages).apply();
}
Also used : Context(android.content.Context) PREFS(com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREFS) SliceBackgroundWorker(com.android.settings.slices.SliceBackgroundWorker) PREF_KEY_INTERACTED_PACKAGES(com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES) Uri(android.net.Uri) Set(java.util.Set) IOException(java.io.IOException) PackageInfo(android.content.pm.PackageInfo) Collectors(java.util.stream.Collectors) List(java.util.List) SharedPreferences(android.content.SharedPreferences) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) ArraySet(android.util.ArraySet) ArraySet(android.util.ArraySet) SharedPreferences(android.content.SharedPreferences) PackageInfo(android.content.pm.PackageInfo)

Aggregations

MODE_PRIVATE (android.content.Context.MODE_PRIVATE)2 SharedPreferences (android.content.SharedPreferences)2 List (java.util.List)2 Context (android.content.Context)1 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 Uri (android.net.Uri)1 Bundle (android.os.Bundle)1 ArraySet (android.util.ArraySet)1 DisplayMetrics (android.util.DisplayMetrics)1 Log (android.util.Log)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 GridView (android.widget.GridView)1 LinearLayout (android.widget.LinearLayout)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1