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;
}
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;
}
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;
}
Aggregations