mirror of
https://github.com/cmclark00/RetroMusicPlayer.git
synced 2025-05-19 16:45:20 +01:00
Removed butter knife
This commit is contained in:
parent
d5f63b91ac
commit
63e3276098
194 changed files with 5984 additions and 7491 deletions
|
@ -6,7 +6,6 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import butterknife.ButterKnife
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.loaders.PlaylistLoader
|
||||
|
@ -24,9 +23,8 @@ class AddToPlaylistDialog : RoundedBottomSheetDialogFragment() {
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
val layout = inflater.inflate(R.layout.dialog_add_to_playlist, container, false)
|
||||
ButterKnife.bind(this, layout)
|
||||
return layout
|
||||
|
||||
return inflater.inflate(R.layout.dialog_add_to_playlist, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -6,7 +6,6 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import butterknife.ButterKnife
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.retromusic.R
|
||||
|
@ -23,9 +22,8 @@ class CreatePlaylistDialog : RoundedBottomSheetDialogFragment() {
|
|||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val layout = inflater.inflate(R.layout.dialog_playlist, container, false)
|
||||
ButterKnife.bind(this, layout)
|
||||
return layout
|
||||
|
||||
return inflater.inflate(R.layout.dialog_playlist, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.text.Html
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import butterknife.ButterKnife
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
|
@ -19,9 +18,7 @@ class DeletePlaylistDialog : RoundedBottomSheetDialogFragment() {
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
val layout = inflater.inflate(R.layout.dialog_remove_from_playlist, container, false)
|
||||
ButterKnife.bind(this, layout)
|
||||
return layout
|
||||
return inflater.inflate(R.layout.dialog_remove_from_playlist, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -1,100 +0,0 @@
|
|||
package code.name.monkey.retromusic.dialogs;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||
|
||||
public class DeleteSongsDialog extends RoundedBottomSheetDialogFragment {
|
||||
@BindView(R.id.action_delete)
|
||||
MaterialButton actionDelete;
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
|
||||
@BindView(R.id.action_cancel)
|
||||
MaterialButton actionCancel;
|
||||
|
||||
@NonNull
|
||||
public static DeleteSongsDialog create(Song song) {
|
||||
ArrayList<Song> list = new ArrayList<>();
|
||||
list.add(song);
|
||||
return create(list);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static DeleteSongsDialog create(ArrayList<Song> songs) {
|
||||
DeleteSongsDialog dialog = new DeleteSongsDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelableArrayList("songs", songs);
|
||||
dialog.setArguments(args);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@OnClick({R.id.action_cancel, R.id.action_delete})
|
||||
void actions(View view) {
|
||||
//noinspection ConstantConditions
|
||||
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
switch (view.getId()) {
|
||||
case R.id.action_delete:
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
if (songs != null) {
|
||||
MusicUtil.deleteTracks(getActivity(), songs);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||
MaterialUtil.setTint(actionDelete, true);
|
||||
MaterialUtil.setTint(actionCancel, false);
|
||||
|
||||
//noinspection unchecked,ConstantConditions
|
||||
final ArrayList<Song> songs = getArguments().getParcelableArrayList("songs");
|
||||
CharSequence content;
|
||||
if (songs != null) {
|
||||
if (songs.size() > 1) {
|
||||
content = Html.fromHtml(getString(R.string.delete_x_songs, songs.size()));
|
||||
} else {
|
||||
content = Html.fromHtml(getString(R.string.delete_song_x, songs.get(0).getTitle()));
|
||||
}
|
||||
this.title.setText(content);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
View layout = inflater.inflate(R.layout.dialog_delete, container, false);
|
||||
ButterKnife.bind(this, layout);
|
||||
return layout;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,69 @@
|
|||
package code.name.monkey.retromusic.dialogs
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
|
||||
import kotlinx.android.synthetic.main.dialog_delete.*
|
||||
import java.util.*
|
||||
|
||||
class DeleteSongsDialog : RoundedBottomSheetDialogFragment() {
|
||||
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
title.setTextColor(ThemeStore.textColorPrimary(context!!))
|
||||
MaterialUtil.setTint(actionDelete, true)
|
||||
MaterialUtil.setTint(actionCancel, false)
|
||||
|
||||
//noinspection unchecked,ConstantConditions
|
||||
val songs = arguments!!.getParcelableArrayList<Song>("songs")
|
||||
val content: CharSequence
|
||||
if (songs != null) {
|
||||
content = if (songs.size > 1) {
|
||||
Html.fromHtml(getString(R.string.delete_x_songs, songs.size))
|
||||
} else {
|
||||
Html.fromHtml(getString(R.string.delete_song_x, songs[0].title))
|
||||
}
|
||||
this.title.text = content
|
||||
}
|
||||
actionDelete.setOnClickListener {
|
||||
if (songs != null) {
|
||||
MusicUtil.deleteTracks(activity!!, songs)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
actionCancel.setOnClickListener { dismiss() }
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.dialog_delete, container, false)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun create(song: Song): DeleteSongsDialog {
|
||||
val list = ArrayList<Song>()
|
||||
list.add(song)
|
||||
return create(list)
|
||||
}
|
||||
|
||||
fun create(songs: ArrayList<Song>): DeleteSongsDialog {
|
||||
val dialog = DeleteSongsDialog()
|
||||
val args = Bundle()
|
||||
args.putParcelableArrayList("songs", songs)
|
||||
dialog.arguments = args
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,7 +6,6 @@ import android.text.Html
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import butterknife.ButterKnife
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.model.PlaylistSong
|
||||
|
@ -19,9 +18,8 @@ import java.util.*
|
|||
class RemoveFromPlaylistDialog : RoundedBottomSheetDialogFragment() {
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val layout = inflater.inflate(R.layout.dialog_remove_from_playlist, container, false)
|
||||
ButterKnife.bind(this, layout)
|
||||
return layout
|
||||
|
||||
return inflater.inflate(R.layout.dialog_remove_from_playlist, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import butterknife.ButterKnife
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.retromusic.R
|
||||
|
@ -17,9 +16,8 @@ class RenamePlaylistDialog : RoundedBottomSheetDialogFragment() {
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
val layout = inflater.inflate(R.layout.dialog_playlist, container, false)
|
||||
ButterKnife.bind(this, layout)
|
||||
return layout
|
||||
|
||||
return inflater.inflate(R.layout.dialog_playlist, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
|
|
|
@ -1,193 +0,0 @@
|
|||
package code.name.monkey.retromusic.dialogs;
|
||||
|
||||
import android.app.AlarmManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.ClipDrawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.os.SystemClock;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.service.MusicService;
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil;
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||
|
||||
import static code.name.monkey.retromusic.Constants.ACTION_QUIT;
|
||||
|
||||
public class SleepTimerDialog extends RoundedBottomSheetDialogFragment {
|
||||
@BindView(R.id.seek_arc)
|
||||
SeekBar seekArc;
|
||||
|
||||
@BindView(R.id.timer_display)
|
||||
TextView timerDisplay;
|
||||
|
||||
@BindView(R.id.action_set)
|
||||
MaterialButton setButton;
|
||||
|
||||
@BindView(R.id.action_cancel)
|
||||
MaterialButton cancelButton;
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
private int seekArcProgress;
|
||||
private TimerUpdater timerUpdater;
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
timerUpdater.cancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE) != null) {
|
||||
timerUpdater.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View layout = inflater.inflate(R.layout.dialog_sleep_timer, container, false);
|
||||
ButterKnife.bind(this, layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
private void setProgressBarColor(int dark) {
|
||||
LayerDrawable ld = (LayerDrawable) seekArc.getProgressDrawable();
|
||||
ClipDrawable clipDrawable = (ClipDrawable) ld.findDrawableByLayerId(android.R.id.progress);
|
||||
clipDrawable.setColorFilter(dark, PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
MaterialUtil.setTint(setButton, true);
|
||||
MaterialUtil.setTint(cancelButton, false);
|
||||
|
||||
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||
timerDisplay.setTextColor(ThemeStore.textColorSecondary(getContext()));
|
||||
|
||||
timerUpdater = new TimerUpdater();
|
||||
|
||||
seekArcProgress = PreferenceUtil.getInstance().getLastSleepTimerValue();
|
||||
updateTimeDisplayTime();
|
||||
seekArc.setProgress(seekArcProgress);
|
||||
setProgressBarColor(ThemeStore.accentColor(getContext()));
|
||||
|
||||
seekArc.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
|
||||
if (i < 1) {
|
||||
seekArc.setProgress(1);
|
||||
return;
|
||||
}
|
||||
seekArcProgress = i;
|
||||
updateTimeDisplayTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
PreferenceUtil.getInstance().setLastSleepTimerValue(seekArcProgress);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnClick({R.id.action_cancel, R.id.action_set})
|
||||
void set(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.action_cancel:
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
final PendingIntent previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE);
|
||||
if (previous != null) {
|
||||
AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
|
||||
if (am != null) {
|
||||
am.cancel(previous);
|
||||
}
|
||||
previous.cancel();
|
||||
Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.sleep_timer_canceled), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
break;
|
||||
case R.id.action_set:
|
||||
if (getActivity() == null) {
|
||||
return;
|
||||
}
|
||||
final int minutes = seekArcProgress;
|
||||
PendingIntent pi = makeTimerPendingIntent(PendingIntent.FLAG_CANCEL_CURRENT);
|
||||
final long nextSleepTimerElapsedTime = SystemClock.elapsedRealtime() + minutes * 60 * 1000;
|
||||
PreferenceUtil.getInstance().setNextSleepTimerElapsedRealtime(nextSleepTimerElapsedTime);
|
||||
AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);
|
||||
if (am != null) {
|
||||
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextSleepTimerElapsedTime, pi);
|
||||
}
|
||||
Toast.makeText(getActivity(), getActivity().getResources().getString(R.string.sleep_timer_set, minutes), Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
private void updateTimeDisplayTime() {
|
||||
timerDisplay.setText(String.format(Locale.getDefault(), "%d min", seekArcProgress));
|
||||
}
|
||||
|
||||
private PendingIntent makeTimerPendingIntent(int flag) {
|
||||
return PendingIntent.getService(getActivity(), 0, makeTimerIntent(), flag);
|
||||
}
|
||||
|
||||
private Intent makeTimerIntent() {
|
||||
return new Intent(getActivity(), MusicService.class)
|
||||
.setAction( ACTION_QUIT);
|
||||
}
|
||||
|
||||
private class TimerUpdater extends CountDownTimer {
|
||||
TimerUpdater() {
|
||||
//noinspection ConstantConditions
|
||||
super(PreferenceUtil.getInstance().getNextSleepTimerElapsedRealTime() - SystemClock.elapsedRealtime(), 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
cancelButton.setText(String.format("%s (%s)", getString(R.string.cancel_current_timer), MusicUtil.getReadableDurationString(millisUntilFinished)));
|
||||
//materialDialog.setActionButton(DialogAction.NEUTRAL, materialDialog.getContext().getString(R.string.cancel_current_timer) + " (" + MusicUtil.getReadableDurationString(millisUntilFinished) + ")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
cancelButton.setText(null);
|
||||
cancelButton.setVisibility(View.GONE);
|
||||
//materialDialog.setActionButton(DialogAction.NEUTRAL, null);
|
||||
}
|
||||
}
|
||||
}
|
138
app/src/main/java/code/name/monkey/retromusic/dialogs/SleepTimerDialog.kt
Executable file
138
app/src/main/java/code/name/monkey/retromusic/dialogs/SleepTimerDialog.kt
Executable file
|
@ -0,0 +1,138 @@
|
|||
package code.name.monkey.retromusic.dialogs
|
||||
|
||||
import android.app.AlarmManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.content.Intent
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.drawable.ClipDrawable
|
||||
import android.graphics.drawable.LayerDrawable
|
||||
import android.os.Bundle
|
||||
import android.os.CountDownTimer
|
||||
import android.os.SystemClock
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.SeekBar
|
||||
import android.widget.Toast
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.appthemehelper.util.MaterialUtil
|
||||
import code.name.monkey.retromusic.Constants.ACTION_QUIT
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.service.MusicService
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
|
||||
import kotlinx.android.synthetic.main.dialog_sleep_timer.*
|
||||
import java.util.*
|
||||
|
||||
class SleepTimerDialog : RoundedBottomSheetDialogFragment() {
|
||||
|
||||
private var seekArcProgress: Int = 0
|
||||
private lateinit var timerUpdater: TimerUpdater
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface?) {
|
||||
super.onDismiss(dialog)
|
||||
timerUpdater.cancel()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE) != null) {
|
||||
timerUpdater.start()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
||||
return inflater.inflate(R.layout.dialog_sleep_timer, container, false)
|
||||
}
|
||||
|
||||
private fun setProgressBarColor(dark: Int) {
|
||||
val ld = seekBar.progressDrawable as LayerDrawable
|
||||
val clipDrawable = ld.findDrawableByLayerId(android.R.id.progress) as ClipDrawable
|
||||
clipDrawable.setColorFilter(dark, PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
MaterialUtil.setTint(actionSet, true)
|
||||
MaterialUtil.setTint(actionCancel, false)
|
||||
|
||||
title.setTextColor(ThemeStore.textColorPrimary(context!!))
|
||||
timerDisplay!!.setTextColor(ThemeStore.textColorSecondary(context!!))
|
||||
|
||||
timerUpdater = TimerUpdater()
|
||||
|
||||
seekArcProgress = PreferenceUtil.getInstance().lastSleepTimerValue
|
||||
updateTimeDisplayTime()
|
||||
seekBar.progress = seekArcProgress
|
||||
setProgressBarColor(ThemeStore.accentColor(context!!))
|
||||
seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||
override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) {
|
||||
if (i < 1) {
|
||||
seekBar.progress = 1
|
||||
return
|
||||
}
|
||||
seekArcProgress = i
|
||||
updateTimeDisplayTime()
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||
|
||||
}
|
||||
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
||||
PreferenceUtil.getInstance().lastSleepTimerValue = seekArcProgress
|
||||
}
|
||||
})
|
||||
|
||||
actionCancel.setOnClickListener {
|
||||
|
||||
val previous = makeTimerPendingIntent(PendingIntent.FLAG_NO_CREATE)
|
||||
if (previous != null) {
|
||||
val am = activity!!.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
am.cancel(previous)
|
||||
previous.cancel()
|
||||
Toast.makeText(activity, activity!!.resources.getString(R.string.sleep_timer_canceled), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
actionSet.setOnClickListener {
|
||||
val minutes = seekArcProgress
|
||||
val pi = makeTimerPendingIntent(PendingIntent.FLAG_CANCEL_CURRENT)
|
||||
val nextSleepTimerElapsedTime = SystemClock.elapsedRealtime() + minutes * 60 * 1000
|
||||
PreferenceUtil.getInstance().setNextSleepTimerElapsedRealtime(nextSleepTimerElapsedTime)
|
||||
val am = activity!!.getSystemService(Context.ALARM_SERVICE) as AlarmManager
|
||||
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, nextSleepTimerElapsedTime, pi)
|
||||
Toast.makeText(activity, activity!!.resources.getString(R.string.sleep_timer_set, minutes), Toast.LENGTH_SHORT).show()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateTimeDisplayTime() {
|
||||
timerDisplay!!.text = String.format(Locale.getDefault(), "%d min", seekArcProgress)
|
||||
}
|
||||
|
||||
private fun makeTimerPendingIntent(flag: Int): PendingIntent? {
|
||||
return PendingIntent.getService(activity, 0, makeTimerIntent(), flag)
|
||||
}
|
||||
|
||||
private fun makeTimerIntent(): Intent {
|
||||
return Intent(activity, MusicService::class.java)
|
||||
.setAction(ACTION_QUIT)
|
||||
}
|
||||
|
||||
private inner class TimerUpdater internal constructor() : CountDownTimer(PreferenceUtil.getInstance().nextSleepTimerElapsedRealTime - SystemClock.elapsedRealtime(), 1000) {
|
||||
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
actionCancel.text = String.format("%s (%s)", getString(R.string.cancel_current_timer), MusicUtil.getReadableDurationString(millisUntilFinished))
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
actionCancel.text = null
|
||||
actionCancel.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
package code.name.monkey.retromusic.dialogs;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
import org.jaudiotagger.audio.AudioHeader;
|
||||
import org.jaudiotagger.audio.exceptions.CannotReadException;
|
||||
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
|
||||
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
|
||||
import org.jaudiotagger.tag.TagException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import butterknife.BindViews;
|
||||
import butterknife.ButterKnife;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid), Aidan Follestad (afollestad)
|
||||
*/
|
||||
public class SongDetailDialog extends RoundedBottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = SongDetailDialog.class.getSimpleName();
|
||||
@BindViews({R.id.title,
|
||||
R.id.file_name,
|
||||
R.id.file_path,
|
||||
R.id.file_size,
|
||||
R.id.file_format,
|
||||
R.id.track_length,
|
||||
R.id.bitrate,
|
||||
R.id.sampling_rate})
|
||||
List<TextView> textViews;
|
||||
|
||||
@NonNull
|
||||
public static SongDetailDialog create(Song song) {
|
||||
SongDetailDialog dialog = new SongDetailDialog();
|
||||
Bundle args = new Bundle();
|
||||
args.putParcelable("song", song);
|
||||
dialog.setArguments(args);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
private static Spanned makeTextWithTitle(@NonNull Context context, int titleResId, String text) {
|
||||
return Html.fromHtml("<b>" + context.getResources().getString(titleResId) + ": " + "</b>" + text);
|
||||
}
|
||||
|
||||
private static String getFileSizeString(long sizeInBytes) {
|
||||
long fileSizeInKB = sizeInBytes / 1024;
|
||||
long fileSizeInMB = fileSizeInKB / 1024;
|
||||
return fileSizeInMB + " MB";
|
||||
}
|
||||
|
||||
private void setTextColor(List<TextView> textColor) {
|
||||
for (TextView textView : textColor) {
|
||||
//noinspection ConstantConditions
|
||||
textView.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View dialogView = inflater.inflate(R.layout.dialog_file_details, container, false);
|
||||
ButterKnife.bind(this, dialogView);
|
||||
Context context = getContext();
|
||||
|
||||
setTextColor(textViews);
|
||||
|
||||
textViews.get(1).setText(makeTextWithTitle(context, R.string.label_file_name, "-"));
|
||||
textViews.get(2).setText(makeTextWithTitle(context, R.string.label_file_path, "-"));
|
||||
textViews.get(3).setText(makeTextWithTitle(context, R.string.label_file_size, "-"));
|
||||
textViews.get(4).setText(makeTextWithTitle(context, R.string.label_file_format, "-"));
|
||||
textViews.get(5).setText(makeTextWithTitle(context, R.string.label_track_length, "-"));
|
||||
textViews.get(6).setText(makeTextWithTitle(context, R.string.label_bit_rate, "-"));
|
||||
textViews.get(7).setText(makeTextWithTitle(context, R.string.label_sampling_rate, "-"));
|
||||
|
||||
final Song song = getArguments().getParcelable("song");
|
||||
if (song != null) {
|
||||
final File songFile = new File(song.getData());
|
||||
if (songFile.exists()) {
|
||||
textViews.get(1).setText(makeTextWithTitle(context, R.string.label_file_name, songFile.getName()));
|
||||
textViews.get(2).setText(makeTextWithTitle(context, R.string.label_file_path, songFile.getAbsolutePath()));
|
||||
textViews.get(3).setText(makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length())));
|
||||
try {
|
||||
AudioFile audioFile = AudioFileIO.read(songFile);
|
||||
AudioHeader audioHeader = audioFile.getAudioHeader();
|
||||
|
||||
textViews.get(4).setText(makeTextWithTitle(context, R.string.label_file_format, audioHeader.getFormat()));
|
||||
textViews.get(5).setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(audioHeader.getTrackLength() * 1000)));
|
||||
textViews.get(6).setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
|
||||
textViews.get(7).setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
|
||||
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
Log.e(TAG, "error while reading the song file", e);
|
||||
// fallback
|
||||
textViews.get(5).setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.getDuration())));
|
||||
}
|
||||
} else {
|
||||
// fallback
|
||||
textViews.get(1).setText(makeTextWithTitle(context, R.string.label_file_name, song.getTitle()));
|
||||
textViews.get(5).setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.getDuration())));
|
||||
}
|
||||
}
|
||||
|
||||
return dialogView;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package code.name.monkey.retromusic.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Bundle
|
||||
import android.text.Html
|
||||
import android.text.Spanned
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
|
||||
import kotlinx.android.synthetic.main.dialog_file_details.*
|
||||
import org.jaudiotagger.audio.AudioFileIO
|
||||
import org.jaudiotagger.audio.exceptions.CannotReadException
|
||||
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
|
||||
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException
|
||||
import org.jaudiotagger.tag.TagException
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
|
||||
class SongDetailDialog : RoundedBottomSheetDialogFragment() {
|
||||
|
||||
private fun setTextColor(textColor: List<TextView>) {
|
||||
for (textView in textColor) {
|
||||
|
||||
textView.setTextColor(ThemeStore.textColorPrimary(context!!))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val dialogView = inflater.inflate(R.layout.dialog_file_details, container, false)
|
||||
val context = context
|
||||
|
||||
fileName.text = makeTextWithTitle(context!!, R.string.label_file_name, "-")
|
||||
filePath.text = makeTextWithTitle(context, R.string.label_file_path, "-")
|
||||
fileSize.text = makeTextWithTitle(context, R.string.label_file_size, "-")
|
||||
fileFormat.text = makeTextWithTitle(context, R.string.label_file_format, "-")
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, "-")
|
||||
bitrate.text = makeTextWithTitle(context, R.string.label_bit_rate, "-")
|
||||
samplingRate.text = makeTextWithTitle(context, R.string.label_sampling_rate, "-")
|
||||
|
||||
val song = arguments!!.getParcelable<Song>("song")
|
||||
if (song != null) {
|
||||
val songFile = File(song.data)
|
||||
if (songFile.exists()) {
|
||||
fileName.text = makeTextWithTitle(context, R.string.label_file_name, songFile.name)
|
||||
filePath.text = makeTextWithTitle(context, R.string.label_file_path, songFile.absolutePath)
|
||||
fileSize.text = makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length()))
|
||||
try {
|
||||
val audioFile = AudioFileIO.read(songFile)
|
||||
val audioHeader = audioFile.audioHeader
|
||||
|
||||
fileFormat.text = makeTextWithTitle(context, R.string.label_file_format, audioHeader.format)
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString((audioHeader.trackLength * 1000).toLong()))
|
||||
bitrate.text = makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.bitRate + " kb/s")
|
||||
samplingRate.text = makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.sampleRate + " Hz")
|
||||
} catch (e: CannotReadException) {
|
||||
Log.e(TAG, "error while reading the song file", e)
|
||||
// fallback
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
|
||||
} catch (e: IOException) {
|
||||
Log.e(TAG, "error while reading the song file", e)
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
|
||||
} catch (e: TagException) {
|
||||
Log.e(TAG, "error while reading the song file", e)
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
|
||||
} catch (e: ReadOnlyFileException) {
|
||||
Log.e(TAG, "error while reading the song file", e)
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
|
||||
} catch (e: InvalidAudioFrameException) {
|
||||
Log.e(TAG, "error while reading the song file", e)
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
|
||||
}
|
||||
|
||||
} else {
|
||||
// fallback
|
||||
fileName.text = makeTextWithTitle(context, R.string.label_file_name, song.title)
|
||||
trackLength.text = makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration))
|
||||
}
|
||||
}
|
||||
|
||||
return dialogView
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
val TAG = SongDetailDialog::class.java.simpleName
|
||||
|
||||
|
||||
fun create(song: Song): SongDetailDialog {
|
||||
val dialog = SongDetailDialog()
|
||||
val args = Bundle()
|
||||
args.putParcelable("song", song)
|
||||
dialog.arguments = args
|
||||
return dialog
|
||||
}
|
||||
|
||||
private fun makeTextWithTitle(context: Context, titleResId: Int, text: String?): Spanned {
|
||||
return Html.fromHtml("<b>" + context.resources.getString(titleResId) + ": " + "</b>" + text)
|
||||
}
|
||||
|
||||
private fun getFileSizeString(sizeInBytes: Long): String {
|
||||
val fileSizeInKB = sizeInBytes / 1024
|
||||
val fileSizeInMB = fileSizeInKB / 1024
|
||||
return fileSizeInMB.toString() + " MB"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,77 +0,0 @@
|
|||
package code.name.monkey.retromusic.dialogs;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import code.name.monkey.appthemehelper.ThemeStore;
|
||||
import code.name.monkey.retromusic.R;
|
||||
import code.name.monkey.retromusic.model.Song;
|
||||
import code.name.monkey.retromusic.util.MusicUtil;
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment;
|
||||
|
||||
|
||||
public class SongShareDialog extends RoundedBottomSheetDialogFragment {
|
||||
@BindView(R.id.option_1)
|
||||
TextView audioFile;
|
||||
@BindView(R.id.option_2)
|
||||
TextView audioText;
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
|
||||
@NonNull
|
||||
public static SongShareDialog create(final Song song) {
|
||||
final SongShareDialog dialog = new SongShareDialog();
|
||||
final Bundle args = new Bundle();
|
||||
args.putParcelable("song", song);
|
||||
dialog.setArguments(args);
|
||||
return dialog;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View layout = inflater.inflate(R.layout.dialog_file_share, container, false);
|
||||
ButterKnife.bind(this, layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
final Song song = getArguments().getParcelable("song");
|
||||
|
||||
audioFile.setText(getString(R.string.currently_listening_to_x_by_x, song.getTitle(), song.getArtistName()));
|
||||
audioFile.setTextColor(ThemeStore.textColorSecondary(getContext()));
|
||||
audioText.setTextColor(ThemeStore.textColorSecondary(getContext()));
|
||||
title.setTextColor(ThemeStore.textColorPrimary(getContext()));
|
||||
}
|
||||
|
||||
@OnClick({R.id.option_2, R.id.option_1})
|
||||
void onClick(View view) {
|
||||
final Song song = getArguments().getParcelable("song");
|
||||
final String currentlyListening = getString(R.string.currently_listening_to_x_by_x, song.getTitle(), song.getArtistName());
|
||||
switch (view.getId()) {
|
||||
case R.id.option_1:
|
||||
startActivity(Intent.createChooser(
|
||||
MusicUtil.createShareSongFileIntent(song, getContext()), null));
|
||||
break;
|
||||
case R.id.option_2:
|
||||
getActivity().startActivity(Intent.createChooser(new Intent().setAction(Intent.ACTION_SEND)
|
||||
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
|
||||
.setType("text/plain"), null));
|
||||
break;
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package code.name.monkey.retromusic.dialogs
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import code.name.monkey.appthemehelper.ThemeStore
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.util.MusicUtil
|
||||
import code.name.monkey.retromusic.views.RoundedBottomSheetDialogFragment
|
||||
import kotlinx.android.synthetic.main.dialog_file_share.*
|
||||
|
||||
|
||||
class SongShareDialog : RoundedBottomSheetDialogFragment() {
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.dialog_file_share, container, false)
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
val song = arguments!!.getParcelable<Song>("song")!!
|
||||
|
||||
audioFile.text = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName)
|
||||
audioFile.setTextColor(ThemeStore.textColorSecondary(context!!))
|
||||
audioText.setTextColor(ThemeStore.textColorSecondary(context!!))
|
||||
title.setTextColor(ThemeStore.textColorPrimary(context!!))
|
||||
|
||||
audioFile.setOnClickListener {
|
||||
MusicUtil.createShareSongFileIntent(song, context)
|
||||
dismiss()
|
||||
}
|
||||
audioText.setOnClickListener {
|
||||
val currentlyListening = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName)
|
||||
activity!!.startActivity(Intent.createChooser(Intent().setAction(Intent.ACTION_SEND)
|
||||
.putExtra(Intent.EXTRA_TEXT, currentlyListening)
|
||||
.setType("text/plain"), null))
|
||||
dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun create(song: Song): SongShareDialog {
|
||||
val dialog = SongShareDialog()
|
||||
val args = Bundle()
|
||||
args.putParcelable("song", song)
|
||||
dialog.arguments = args
|
||||
return dialog
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue