Search in sources :

Example 1 with SoundsAdapter

use of james.alarmio.adapters.SoundsAdapter in project Alarmio by TheAndroidMaster.

the class RadioSoundChooserFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_sound_chooser_radio, container, false);
    prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    radioUrlEditText = view.findViewById(R.id.radioUrl);
    TextView errorTextView = view.findViewById(R.id.errorText);
    RecyclerView recycler = view.findViewById(R.id.recycler);
    testRadio = view.findViewById(R.id.testRadio);
    List<String> previousRadios = new ArrayList<>(prefs.getStringSet(PREF_RADIOS, new HashSet<String>()));
    Collections.sort(previousRadios, new Comparator<String>() {

        @Override
        public int compare(String o1, String o2) {
            try {
                return Integer.parseInt(o1.split(SEPARATOR)[0]) - Integer.parseInt(o2.split(SEPARATOR)[0]);
            } catch (NumberFormatException e) {
                return 0;
            }
        }
    });
    sounds = new ArrayList<>();
    for (String string : previousRadios) {
        String url = string.split(SEPARATOR)[1];
        sounds.add(new SoundData(url, url));
    }
    recycler.setLayoutManager(new LinearLayoutManager(getContext()));
    SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds);
    adapter.setListener(this);
    recycler.setAdapter(adapter);
    testRadio.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (currentSound == null) {
                currentSound = new SoundData("", radioUrlEditText.getText().toString());
                try {
                    currentSound.preview(getAlarmio());
                    testRadio.setText(R.string.title_radio_stop);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                }
            } else {
                if (currentSound.isPlaying(getAlarmio()))
                    currentSound.stop(getAlarmio());
                currentSound = null;
                testRadio.setText(R.string.title_radio_test);
            }
        }
    });
    view.findViewById(R.id.createRadio).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (URLUtil.isValidUrl(radioUrlEditText.getText().toString())) {
                onSoundChosen(new SoundData(getString(R.string.title_radio), radioUrlEditText.getText().toString()));
            }
        }
    });
    return view;
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SoundsAdapter(james.alarmio.adapters.SoundsAdapter) TextView(android.widget.TextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) SoundData(james.alarmio.data.SoundData) HashSet(java.util.HashSet) Nullable(androidx.annotation.Nullable)

Example 2 with SoundsAdapter

use of james.alarmio.adapters.SoundsAdapter in project Alarmio by TheAndroidMaster.

the class AlarmSoundChooserFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false);
    RecyclerView recyclerView = view.findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    List<SoundData> sounds = new ArrayList<>();
    RingtoneManager manager = new RingtoneManager(getContext());
    manager.setType(RingtoneManager.TYPE_ALARM);
    Cursor cursor = manager.getCursor();
    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
        do {
            sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
        } while (cursor.moveToNext());
    }
    SoundsAdapter adapter = new SoundsAdapter(getAlarmio(), sounds);
    adapter.setListener(this);
    recyclerView.setAdapter(adapter);
    return view;
}
Also used : RingtoneManager(android.media.RingtoneManager) SoundsAdapter(james.alarmio.adapters.SoundsAdapter) ArrayList(java.util.ArrayList) RecyclerView(androidx.recyclerview.widget.RecyclerView) SoundData(james.alarmio.data.SoundData) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Cursor(android.database.Cursor) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Nullable(androidx.annotation.Nullable)

Example 3 with SoundsAdapter

use of james.alarmio.adapters.SoundsAdapter in project Alarmio by TheAndroidMaster.

the class RingtoneSoundChooserFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_sound_chooser_list, container, false);
    RecyclerView recyclerView = view.findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    List<SoundData> sounds = new ArrayList<>();
    RingtoneManager manager = new RingtoneManager(getContext());
    manager.setType(RingtoneManager.TYPE_RINGTONE);
    Cursor cursor = manager.getCursor();
    int count = cursor.getCount();
    if (count > 0 && cursor.moveToFirst()) {
        do {
            sounds.add(new SoundData(cursor.getString(RingtoneManager.TITLE_COLUMN_INDEX), cursor.getString(RingtoneManager.URI_COLUMN_INDEX) + "/" + cursor.getString(RingtoneManager.ID_COLUMN_INDEX)));
        } while (cursor.moveToNext());
    }
    adapter = new SoundsAdapter(getAlarmio(), sounds);
    adapter.setListener(this);
    recyclerView.setAdapter(adapter);
    return view;
}
Also used : RingtoneManager(android.media.RingtoneManager) SoundsAdapter(james.alarmio.adapters.SoundsAdapter) ArrayList(java.util.ArrayList) RecyclerView(androidx.recyclerview.widget.RecyclerView) SoundData(james.alarmio.data.SoundData) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Cursor(android.database.Cursor) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Nullable(androidx.annotation.Nullable)

Aggregations

View (android.view.View)3 Nullable (androidx.annotation.Nullable)3 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)3 RecyclerView (androidx.recyclerview.widget.RecyclerView)3 SoundsAdapter (james.alarmio.adapters.SoundsAdapter)3 SoundData (james.alarmio.data.SoundData)3 ArrayList (java.util.ArrayList)3 Cursor (android.database.Cursor)2 RingtoneManager (android.media.RingtoneManager)2 TextView (android.widget.TextView)1 HashSet (java.util.HashSet)1