Skip to content

Commit

Permalink
fix(app): Move random mode to navigation menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
robercoding committed Mar 13, 2021
1 parent 077eca3 commit 9c81312
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 49 deletions.
27 changes: 27 additions & 0 deletions app/src/main/java/com/github/ashutoshgngwr/noice/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.core.content.res.ResourcesCompat
import androidx.core.view.GravityCompat
import androidx.preference.PreferenceManager
import com.github.ashutoshgngwr.noice.cast.CastAPIWrapper
import com.github.ashutoshgngwr.noice.databinding.DialogFragmentRandomPresetBinding
import com.github.ashutoshgngwr.noice.databinding.MainActivityBinding
import com.github.ashutoshgngwr.noice.fragment.AboutFragment
import com.github.ashutoshgngwr.noice.fragment.DialogFragment
Expand All @@ -25,6 +26,7 @@ import com.github.ashutoshgngwr.noice.fragment.SleepTimerFragment
import com.github.ashutoshgngwr.noice.fragment.SoundLibraryFragment
import com.github.ashutoshgngwr.noice.fragment.SupportDevelopmentFragment
import com.github.ashutoshgngwr.noice.fragment.WakeUpTimerFragment
import com.github.ashutoshgngwr.noice.sound.Sound
import com.github.ashutoshgngwr.noice.sound.player.PlayerManager
import com.google.android.material.navigation.NavigationView
import org.greenrobot.eventbus.EventBus
Expand Down Expand Up @@ -182,6 +184,31 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
override fun onNavigationItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
in NAVIGATED_FRAGMENTS -> setFragment(item.itemId)
R.id.random_preset -> {
DialogFragment.show(supportFragmentManager) {
val viewBinding = DialogFragmentRandomPresetBinding.inflate(layoutInflater)
addContentView(viewBinding.root)
title(R.string.random_preset)
negativeButton(R.string.cancel)
positiveButton(R.string.play) {
val tag = when (viewBinding.presetType.checkedRadioButtonId) {
R.id.preset_type__focus -> Sound.Tag.FOCUS
R.id.preset_type__relax -> Sound.Tag.RELAX
else -> null
}

val intensity = when (viewBinding.presetIntensity.checkedRadioButtonId) {
R.id.preset_intensity__light -> SoundLibraryFragment.RANGE_INTENSITY_LIGHT
R.id.preset_intensity__dense -> SoundLibraryFragment.RANGE_INTENSITY_DENSE
else -> SoundLibraryFragment.RANGE_INTENSITY_ANY
}

MediaPlayerService.playRandomPreset(requireContext(), tag, intensity)
// maybe show in-app review dialog to the user
InAppReviewFlowManager.maybeAskForReview(requireActivity())
}
}
}
R.id.app_theme -> {
DialogFragment.show(supportFragmentManager) {
title(R.string.app_theme)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ class SoundLibraryFragment : Fragment() {
} else {
binding.savePresetButton.hide()
}

if (event.state == PlayerManager.State.STOPPED) {
binding.randomPresetButton.show()
} else {
binding.randomPresetButton.hide()
}
}
}

Expand Down Expand Up @@ -142,37 +136,6 @@ class SoundLibraryFragment : Fragment() {
}
}

binding.randomPresetButton.setOnLongClickListener {
Toast.makeText(requireContext(), R.string.random_preset, Toast.LENGTH_LONG).show()
true
}

binding.randomPresetButton.setOnClickListener {
DialogFragment.show(childFragmentManager) {
val viewBinding = DialogFragmentRandomPresetBinding.inflate(layoutInflater)
addContentView(viewBinding.root)
title(R.string.random_preset)
negativeButton(R.string.cancel)
positiveButton(R.string.play) {
val tag = when (viewBinding.presetType.checkedRadioButtonId) {
R.id.preset_type__focus -> Sound.Tag.FOCUS
R.id.preset_type__relax -> Sound.Tag.RELAX
else -> null
}

val intensity = when (viewBinding.presetIntensity.checkedRadioButtonId) {
R.id.preset_intensity__light -> RANGE_INTENSITY_LIGHT
R.id.preset_intensity__dense -> RANGE_INTENSITY_DENSE
else -> RANGE_INTENSITY_ANY
}

MediaPlayerService.playRandomPreset(requireContext(), tag, intensity)
// maybe show in-app review dialog to the user
InAppReviewFlowManager.maybeAskForReview(requireActivity())
}
}
}

eventBus.register(this)
}

Expand Down
12 changes: 0 additions & 12 deletions app/src/main/res/layout/sound_library_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,6 @@
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/random_preset_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:contentDescription="@string/random_preset"
android:src="@drawable/ic_action_shuffle"
app:elevation="5dp"
app:fabSize="normal" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/save_preset_button"
android:layout_width="wrap_content"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/menu/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
android:title="@string/wake_up_timer"
android:checkable="true" />

<item
android:id="@+id/random_preset"
android:icon="@drawable/ic_action_shuffle"
android:title="@string/random_preset"
android:checkable="false" />

<item
android:id="@+id/app_theme"
android:icon="@drawable/ic_nav_theme"
Expand Down

0 comments on commit 9c81312

Please sign in to comment.