Skip to content

Commit

Permalink
refactor: refactoring redirection for players
Browse files Browse the repository at this point in the history
  • Loading branch information
tara-pogancev committed Aug 23, 2022
1 parent a3f5631 commit f8d01f7
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 89 deletions.
2 changes: 1 addition & 1 deletion DeNoise/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {

defaultConfig {
applicationId "com.tarapogancev.denoise"
minSdk 31
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
Expand Down
9 changes: 4 additions & 5 deletions DeNoise/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
android:launchMode="singleInstance"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DeNoiseCalmingWhiteNoise"
tools:targetApi="31">
android:theme="@style/Theme.DeNoiseCalmingWhiteNoise">
<activity
android:name=".TimerDialog"
android:exported="false" />
Expand All @@ -29,13 +28,13 @@
android:name=".Onboarding"
android:exported="false" />
<activity
android:name=".BrownNoisePlayer"
android:name=".player.BrownNoisePlayer"
android:exported="false" />
<activity
android:name=".PinkNoisePlayer"
android:name=".player.PinkNoisePlayer"
android:exported="false" />
<activity
android:name=".WhiteNoisePlayer"
android:name=".player.WhiteNoisePlayer"
android:exported="false" />
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.tarapogancev.denoise.player.BrownNoisePlayer;
import com.tarapogancev.denoise.player.PinkNoisePlayer;
import com.tarapogancev.denoise.player.WhiteNoisePlayer;
import com.tarapogancev.denoise.service.MediaPlayerService;

import java.util.Calendar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tarapogancev.denoise;
package com.tarapogancev.denoise.player;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
Expand All @@ -20,11 +20,11 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.tarapogancev.denoise.MainActivity;
import com.tarapogancev.denoise.R;
import com.tarapogancev.denoise.service.MediaPlayerService;
import com.tarapogancev.denoise.service.TimerService;

import java.util.Objects;

public class BrownNoisePlayer extends AppCompatActivity {

CardView backButton, timerButton, whiteNoiseButton, pinkNoiseButton, nextButton, previousButton, playPauseButton;
Expand Down Expand Up @@ -68,14 +68,14 @@ protected void onCreate(Bundle savedInstanceState) {
whiteNoiseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectWhiteNoise();
redirect(WhiteNoisePlayer.class);
}
});

pinkNoiseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectPinkNoise();
redirect(PinkNoisePlayer.class);
}
});

Expand All @@ -96,14 +96,14 @@ public void onClick(View view) {
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectPinkNoise();
redirect(PinkNoisePlayer.class);
}
});

nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectWhiteNoise();
redirect(WhiteNoisePlayer.class);
}
});

Expand Down Expand Up @@ -213,7 +213,7 @@ public void onClick(View view) {
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectMainActivity();
redirect(MainActivity.class);
}
});

Expand Down Expand Up @@ -266,24 +266,8 @@ private boolean checkTimerButtonAvailability(EditText minutes, EditText hours) {
return true;
}

private void redirectMainActivity() {
Intent intent = new Intent(BrownNoisePlayer.this, MainActivity.class);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(BrownNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
startActivity(intent, bundle);
}

private void redirectWhiteNoise() {
Intent intent = new Intent(BrownNoisePlayer.this, WhiteNoisePlayer.class);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(BrownNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
startActivity(intent, bundle);
}

private void redirectPinkNoise() {
Intent intent = new Intent(BrownNoisePlayer.this, PinkNoisePlayer.class);
private void redirect(Class<?> activity) {
Intent intent = new Intent(BrownNoisePlayer.this, activity);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(BrownNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tarapogancev.denoise;
package com.tarapogancev.denoise.player;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
Expand All @@ -20,11 +20,11 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.tarapogancev.denoise.MainActivity;
import com.tarapogancev.denoise.R;
import com.tarapogancev.denoise.service.MediaPlayerService;
import com.tarapogancev.denoise.service.TimerService;

import java.util.Objects;

public class PinkNoisePlayer extends AppCompatActivity {

CardView backButton, timerButton, whiteNoiseButton, brownNoiseButton, nextButton, previousButton, playPauseButton;
Expand Down Expand Up @@ -68,14 +68,14 @@ protected void onCreate(Bundle savedInstanceState) {
whiteNoiseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectWhiteNoise();
redirect(WhiteNoisePlayer.class);
}
});

brownNoiseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectBrownNoise();
redirect(BrownNoisePlayer.class);
}
});

Expand All @@ -96,14 +96,14 @@ public void onClick(View view) {
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectWhiteNoise();
redirect(WhiteNoisePlayer.class);
}
});

nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectBrownNoise();
redirect(BrownNoisePlayer.class);
}
});

Expand Down Expand Up @@ -213,7 +213,7 @@ public void onClick(View view) {
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectMainActivity();
redirect(MainActivity.class);
}
});

Expand Down Expand Up @@ -266,24 +266,8 @@ private boolean checkTimerButtonAvailability(EditText minutes, EditText hours) {
return true;
}

private void redirectWhiteNoise() {
Intent intent = new Intent(PinkNoisePlayer.this, WhiteNoisePlayer.class);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(PinkNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
startActivity(intent, bundle);
}

private void redirectBrownNoise() {
Intent intent = new Intent(PinkNoisePlayer.this, BrownNoisePlayer.class);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(PinkNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
startActivity(intent, bundle);
}

private void redirectMainActivity() {
Intent intent = new Intent(PinkNoisePlayer.this, MainActivity.class);
private void redirect(Class<?> activity) {
Intent intent = new Intent(PinkNoisePlayer.this, activity);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(PinkNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.tarapogancev.denoise;
package com.tarapogancev.denoise.player;

import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
Expand All @@ -20,11 +20,11 @@
import android.widget.ImageView;
import android.widget.TextView;

import com.tarapogancev.denoise.MainActivity;
import com.tarapogancev.denoise.R;
import com.tarapogancev.denoise.service.MediaPlayerService;
import com.tarapogancev.denoise.service.TimerService;

import java.util.Objects;

public class WhiteNoisePlayer extends AppCompatActivity {

CardView backButton, timerButton, pinkNoiseButton, brownNoiseButton, nextButton, previousButton, playPauseButton;
Expand Down Expand Up @@ -68,14 +68,14 @@ protected void onCreate(Bundle savedInstanceState) {
pinkNoiseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectPinkNoise();
redirect(PinkNoisePlayer.class);
}
});

brownNoiseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectBrownNoise();
redirect(BrownNoisePlayer.class);
}
});

Expand All @@ -96,14 +96,14 @@ public void onClick(View view) {
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectBrownNoise();
redirect(BrownNoisePlayer.class);
}
});

nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectPinkNoise();
redirect(PinkNoisePlayer.class);
}
});

Expand Down Expand Up @@ -213,7 +213,7 @@ public void onClick(View view) {
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
redirectMainActivity();
redirect(MainActivity.class);
}
});

Expand Down Expand Up @@ -266,24 +266,8 @@ private boolean checkTimerButtonAvailability(EditText minutes, EditText hours) {
return true;
}

private void redirectPinkNoise() {
Intent intent = new Intent(WhiteNoisePlayer.this, PinkNoisePlayer.class);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(WhiteNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
startActivity(intent, bundle);
}

private void redirectBrownNoise() {
Intent intent = new Intent(WhiteNoisePlayer.this, BrownNoisePlayer.class);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(WhiteNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
startActivity(intent, bundle);
}

private void redirectMainActivity() {
Intent intent = new Intent(WhiteNoisePlayer.this, MainActivity.class);
private void redirect(Class<?> activity) {
Intent intent = new Intent(WhiteNoisePlayer.this, activity);
finish();
Bundle bundle = ActivityOptionsCompat.makeCustomAnimation(WhiteNoisePlayer.this,
android.R.anim.fade_in, android.R.anim.fade_out).toBundle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ public Notification getNotification(String sound, Boolean isPlaying) {
.setSmallIcon(R.drawable.logo)
.setLargeIcon(picture)
.setContentIntent(pendingIntent)
.addAction(R.drawable.ic_baseline_cancel_24, getString(R.string.close), actionIntent0)
// .addAction(R.drawable.ic_baseline_skip_previous_24, "Previous", actionIntent1)
// .addAction(playPauseIcon, "Play/Pause", actionIntent2)
// .addAction(R.drawable.ic_baseline_skip_next_24, "Next", actionIntent3)
.addAction(R.drawable.ic_baseline_cancel_24, getString(R.string.close), actionIntent0)
// .setStyle(new androidx.media.app.NotificationCompat.MediaStyle().setShowActionsInCompactView(0))
// .setStyle(new androidx.media.app.NotificationCompat.MediaStyle().setShowActionsInCompactView(0))
.setSilent(true)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BrownNoisePlayer"
tools:context=".player.BrownNoisePlayer"
android:background="@drawable/waterfall"
>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PinkNoisePlayer"
tools:context=".player.PinkNoisePlayer"
android:background="@drawable/sunset"
>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ocean"
tools:context=".WhiteNoisePlayer">
tools:context=".player.WhiteNoisePlayer">

<RelativeLayout
android:layout_width="match_parent"
Expand Down
Binary file added DeNoise/app/src/main/res/raw/distantwaves.mp3
Binary file not shown.
Binary file added DeNoise/app/src/main/res/raw/forest.mp3
Binary file not shown.
Binary file added DeNoise/app/src/main/res/raw/waves.mp3
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ I plan on releasing this application on Play Store, as well as working on its ex
https://www.flaticon.com/packs/music-224?word=music%20player
https://unsplash.com/
https://themeisle.com/illustrations/
https://mixkit.co/

## Screenshots
![notesByCats](Screenshots/1.jpg)
Expand Down

0 comments on commit f8d01f7

Please sign in to comment.