Search in sources :

Example 76 with NonNull

use of androidx.annotation.NonNull in project Douya by DreaminginCodeZH.

the class TabViewPagerAdapter method instantiateItem.

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    View view = mViews[position];
    container.addView(view);
    return view;
}
Also used : View(android.view.View) NonNull(androidx.annotation.NonNull)

Example 77 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class ShareDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    if (getArguments() != null) {
        ctx = getActivity();
        item = (FeedItem) getArguments().getSerializable(ARGUMENT_FEED_ITEM);
        prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }
    View content = View.inflate(ctx, R.layout.share_episode_dialog, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle(R.string.share_label);
    builder.setView(content);
    RadioGroup radioGroup = content.findViewById(R.id.share_dialog_radio_group);
    radioGroup.setOnCheckedChangeListener((group, checkedId) -> checkBoxStartAt.setEnabled(checkedId != R.id.share_media_file_radio));
    radioLinkToEpisode = content.findViewById(R.id.share_link_to_episode_radio);
    radioMediaFile = content.findViewById(R.id.share_media_file_radio);
    checkBoxStartAt = content.findViewById(R.id.share_start_at_timer_dialog);
    setupOptions();
    builder.setPositiveButton(R.string.share_label, (dialog, id) -> {
        boolean includePlaybackPosition = checkBoxStartAt.isChecked();
        if (radioLinkToEpisode.isChecked()) {
            ShareUtils.shareFeedItemLinkWithDownloadLink(ctx, item, includePlaybackPosition);
        } else if (radioMediaFile.isChecked()) {
            ShareUtils.shareFeedItemFile(ctx, item.getMedia());
        } else {
            throw new IllegalStateException("Unknown share method");
        }
        prefs.edit().putBoolean(PREF_SHARE_EPISODE_START_AT, includePlaybackPosition).apply();
    }).setNegativeButton(R.string.cancel_label, (dialog, id) -> dialog.dismiss());
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) RadioButton(android.widget.RadioButton) FeedItem(de.danoeh.antennapod.model.feed.FeedItem) Dialog(android.app.Dialog) RadioGroup(android.widget.RadioGroup) Nullable(androidx.annotation.Nullable) SharedPreferences(android.content.SharedPreferences) CheckBox(android.widget.CheckBox) ShareUtils(de.danoeh.antennapod.core.util.ShareUtils) View(android.view.View) DialogFragment(androidx.fragment.app.DialogFragment) RadioGroup(android.widget.RadioGroup) View(android.view.View) NonNull(androidx.annotation.NonNull)

Example 78 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class SleepTimerDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View content = View.inflate(getContext(), R.layout.time_dialog, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setTitle(R.string.sleep_timer_label);
    builder.setView(content);
    builder.setPositiveButton(R.string.close_label, null);
    etxtTime = content.findViewById(R.id.etxtTime);
    spTimeUnit = content.findViewById(R.id.spTimeUnit);
    timeSetup = content.findViewById(R.id.timeSetup);
    timeDisplay = content.findViewById(R.id.timeDisplay);
    timeDisplay.setVisibility(View.GONE);
    time = content.findViewById(R.id.time);
    Button extendSleepFiveMinutesButton = content.findViewById(R.id.extendSleepFiveMinutesButton);
    extendSleepFiveMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 5));
    Button extendSleepTenMinutesButton = content.findViewById(R.id.extendSleepTenMinutesButton);
    extendSleepTenMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 10));
    Button extendSleepTwentyMinutesButton = content.findViewById(R.id.extendSleepTwentyMinutesButton);
    extendSleepTwentyMinutesButton.setText(getString(R.string.extend_sleep_timer_label, 20));
    extendSleepFiveMinutesButton.setOnClickListener(v -> {
        if (controller != null) {
            controller.extendSleepTimer(5 * 1000 * 60);
        }
    });
    extendSleepTenMinutesButton.setOnClickListener(v -> {
        if (controller != null) {
            controller.extendSleepTimer(10 * 1000 * 60);
        }
    });
    extendSleepTwentyMinutesButton.setOnClickListener(v -> {
        if (controller != null) {
            controller.extendSleepTimer(20 * 1000 * 60);
        }
    });
    etxtTime.setText(SleepTimerPreferences.lastTimerValue());
    etxtTime.postDelayed(() -> {
        InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(etxtTime, InputMethodManager.SHOW_IMPLICIT);
    }, 100);
    String[] spinnerContent = new String[] { getString(R.string.time_seconds), getString(R.string.time_minutes), getString(R.string.time_hours) };
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, spinnerContent);
    spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spTimeUnit.setAdapter(spinnerAdapter);
    spTimeUnit.setSelection(SleepTimerPreferences.lastTimerTimeUnit());
    CheckBox cbShakeToReset = content.findViewById(R.id.cbShakeToReset);
    CheckBox cbVibrate = content.findViewById(R.id.cbVibrate);
    CheckBox chAutoEnable = content.findViewById(R.id.chAutoEnable);
    cbShakeToReset.setChecked(SleepTimerPreferences.shakeToReset());
    cbVibrate.setChecked(SleepTimerPreferences.vibrate());
    chAutoEnable.setChecked(SleepTimerPreferences.autoEnable());
    cbShakeToReset.setOnCheckedChangeListener((buttonView, isChecked) -> SleepTimerPreferences.setShakeToReset(isChecked));
    cbVibrate.setOnCheckedChangeListener((buttonView, isChecked) -> SleepTimerPreferences.setVibrate(isChecked));
    chAutoEnable.setOnCheckedChangeListener((compoundButton, isChecked) -> SleepTimerPreferences.setAutoEnable(isChecked));
    Button disableButton = content.findViewById(R.id.disableSleeptimerButton);
    disableButton.setOnClickListener(v -> {
        if (controller != null) {
            controller.disableSleepTimer();
        }
    });
    Button setButton = content.findViewById(R.id.setSleeptimerButton);
    setButton.setOnClickListener(v -> {
        if (!PlaybackService.isRunning) {
            Snackbar.make(content, R.string.no_media_playing_label, Snackbar.LENGTH_LONG).show();
            return;
        }
        try {
            long time = Long.parseLong(etxtTime.getText().toString());
            if (time == 0) {
                throw new NumberFormatException("Timer must not be zero");
            }
            SleepTimerPreferences.setLastTimer(etxtTime.getText().toString(), spTimeUnit.getSelectedItemPosition());
            if (controller != null) {
                controller.setSleepTimer(SleepTimerPreferences.timerMillis());
            }
            closeKeyboard(content);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            Snackbar.make(content, R.string.time_dialog_invalid_input, Snackbar.LENGTH_LONG).show();
        }
    });
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) TextView(android.widget.TextView) Button(android.widget.Button) CheckBox(android.widget.CheckBox) ArrayAdapter(android.widget.ArrayAdapter) NonNull(androidx.annotation.NonNull)

Example 79 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class TagSettingsDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    ArrayList<FeedPreferences> feedPreferencesList = (ArrayList<FeedPreferences>) getArguments().getSerializable(ARG_FEED_PREFERENCES);
    Set<String> commonTags = new HashSet<>(feedPreferencesList.get(0).getTags());
    for (FeedPreferences preference : feedPreferencesList) {
        commonTags.retainAll(preference.getTags());
    }
    displayedTags = new ArrayList<>(commonTags);
    displayedTags.remove(FeedPreferences.TAG_ROOT);
    viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
    viewBinding.tagsRecycler.setLayoutManager(new GridLayoutManager(getContext(), 2));
    viewBinding.tagsRecycler.addItemDecoration(new ItemOffsetDecoration(getContext(), 4));
    adapter = new TagSelectionAdapter();
    adapter.setHasStableIds(true);
    viewBinding.tagsRecycler.setAdapter(adapter);
    viewBinding.rootFolderCheckbox.setChecked(commonTags.contains(FeedPreferences.TAG_ROOT));
    viewBinding.newTagButton.setOnClickListener(v -> addTag(viewBinding.newTagEditText.getText().toString().trim()));
    loadTags();
    viewBinding.newTagEditText.setThreshold(1);
    viewBinding.newTagEditText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            viewBinding.newTagEditText.showDropDown();
            viewBinding.newTagEditText.requestFocus();
            return false;
        }
    });
    if (feedPreferencesList.size() > 1) {
        viewBinding.commonTagsInfo.setVisibility(View.VISIBLE);
    }
    AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
    dialog.setView(viewBinding.getRoot());
    dialog.setTitle(R.string.feed_tags_label);
    dialog.setPositiveButton(android.R.string.ok, (d, input) -> {
        addTag(viewBinding.newTagEditText.getText().toString().trim());
        updatePreferencesTags(feedPreferencesList, commonTags);
    });
    dialog.setNegativeButton(R.string.cancel_label, null);
    return dialog.create();
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) AlertDialog(androidx.appcompat.app.AlertDialog) ArrayList(java.util.ArrayList) ItemOffsetDecoration(de.danoeh.antennapod.view.ItemOffsetDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MotionEvent(android.view.MotionEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Example 80 with NonNull

use of androidx.annotation.NonNull in project AntennaPod by AntennaPod.

the class EpisodesFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
    Toolbar toolbar = rootView.findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.episodes_label);
    toolbar.inflateMenu(R.menu.episodes);
    displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
    if (savedInstanceState != null) {
        displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
    }
    ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
    ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
    viewPager.setAdapter(new EpisodesPagerAdapter(this));
    viewPager.setOffscreenPageLimit(2);
    super.setupPagedToolbar(toolbar, viewPager);
    // Give the TabLayout the ViewPager
    tabLayout = rootView.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_NEW_EPISODES:
                tab.setText(R.string.new_episodes_label);
                break;
            case POS_ALL_EPISODES:
                tab.setText(R.string.all_episodes_short_label);
                break;
            case POS_FAV_EPISODES:
                tab.setText(R.string.favorite_episodes_label);
                break;
            default:
                break;
        }
    }).attach();
    // restore our last position
    SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
    int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
    viewPager.setCurrentItem(lastPosition, false);
    return rootView;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Context(android.content.Context) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MainActivity(de.danoeh.antennapod.activity.MainActivity) SharedPreferences(android.content.SharedPreferences) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) SharedPreferences(android.content.SharedPreferences) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) MainActivity(de.danoeh.antennapod.activity.MainActivity) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

NonNull (androidx.annotation.NonNull)1197 View (android.view.View)191 ArrayList (java.util.ArrayList)154 Context (android.content.Context)128 Nullable (androidx.annotation.Nullable)128 TextView (android.widget.TextView)117 Intent (android.content.Intent)115 List (java.util.List)110 Recipient (org.thoughtcrime.securesms.recipients.Recipient)109 IOException (java.io.IOException)103 Bundle (android.os.Bundle)102 WorkerThread (androidx.annotation.WorkerThread)94 LayoutInflater (android.view.LayoutInflater)89 RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)82 AlertDialog (androidx.appcompat.app.AlertDialog)76 Log (org.signal.core.util.logging.Log)76 Cursor (android.database.Cursor)68 ViewGroup (android.view.ViewGroup)65 LinkedList (java.util.LinkedList)64 Stream (com.annimon.stream.Stream)62