Skip to content

Commit

Permalink
Removed BottomSheet for now and added app icon
Browse files Browse the repository at this point in the history
Took 1 hour 12 minutes
  • Loading branch information
shockch4rge committed Aug 17, 2021
1 parent 8ada079 commit 1ffd183
Show file tree
Hide file tree
Showing 32 changed files with 194 additions and 157 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/Dell.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:icon="@mipmap/bitjam_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:roundIcon="@mipmap/bitjam_icon_round"
android:supportsRtl="true"
android:theme="@style/Theme.BitJam.Final">
<activity android:name=".activities.SignInActivity"
Expand Down
Binary file added app/src/main/bitjam_icon-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 35 additions & 18 deletions app/src/main/java/com/example/bitjam/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,36 @@

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.fragment.NavHostFragment;
import androidx.navigation.ui.NavigationUI;

import com.example.bitjam.viewmodels.PlaylistViewModel;
import com.example.bitjam.viewmodels.SongViewModel;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.firebase.firestore.Query;

public class MainActivity extends AppCompatActivity {

@Override
protected void onStart() {
super.onStart();

}

@SuppressLint("NonConstantResourceId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_hub);

SongViewModel songVM = new ViewModelProvider(this).get(SongViewModel.class);
PlaylistViewModel playlistVM = new ViewModelProvider(this).get(PlaylistViewModel.class);

songVM.getSongsFromDb();
playlistVM.getPlaylistsFromDb(Query.Direction.ASCENDING);

// Day UI
int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE |
View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
Expand All @@ -33,24 +50,24 @@ protected void onCreate(Bundle savedInstanceState) {
decorView.setSystemUiVisibility(uiOptions);

BottomNavigationView bottomNav = findViewById(R.id.navBar);
View bottomSheet = findViewById(R.id.bottomSheet);

BottomSheetBehavior<View> mBottomSheet = BottomSheetBehavior.from(bottomSheet);

mBottomSheet.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {

}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {

}
});

bottomSheet.setOnClickListener(view ->
mBottomSheet.setState(BottomSheetBehavior.STATE_EXPANDED));
// View bottomSheet = findViewById(R.id.bottomSheet);
//
// BottomSheetBehavior<View> mBottomSheet = BottomSheetBehavior.from(bottomSheet);
//
// mBottomSheet.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
// @Override
// public void onStateChanged(@NonNull View bottomSheet, int newState) {
//
// }
//
// @Override
// public void onSlide(@NonNull View bottomSheet, float slideOffset) {
//
// }
// });
//
// bottomSheet.setOnClickListener(view ->
// mBottomSheet.setState(BottomSheetBehavior.STATE_EXPANDED));

// Fragment Navigation
NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ public void onItemClick(Song song) {

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) throws InflateException {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View Binding. Removes the need for 'findViewById(id)'
FragmentLibraryBinding B = FragmentLibraryBinding.inflate(inflater, container, false);

// UI
ui = this.requireActivity().getWindow();
ui = requireActivity().getWindow();
ui.setStatusBarColor(requireActivity().getResources().getColor(R.color.white, null));

// ViewModels
songVM = new ViewModelProvider(requireActivity()).get(SongViewModel.class);
songVM.getSongsFromDb();
// songVM.getSongsFromDb();

// Observers
songVM.getSongs().observe(getViewLifecycleOwner(), songs -> {
Expand All @@ -97,7 +97,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
@Override
public void onStop() {
super.onStop();
MainActivity.hideKeyboardIn(this.requireView());
MainActivity.hideKeyboardIn(requireView());
}

// Update adapter with filtered list for every letter
Expand Down
38 changes: 21 additions & 17 deletions app/src/main/java/com/example/bitjam/fragments/PlayingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void onUnlike(Song song) {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if (fromUser) {
B.etl.setText(getTimeFormat(progress));
B.elapsedTimeText.setText(getTimeFormat(progress));
}
}

Expand All @@ -101,14 +101,13 @@ public void onStopTrackingTouch(SeekBar seekBar) {
public void onCreatePlaylistSelected() {
DialogCreatePlaylist dialog = new DialogCreatePlaylist(textInput -> {
String title = textInput.getText().toString();
Song thisSong = playerVM.getCurrentSong();
String songId = thisSong.getId();
String songTitle = thisSong.getTitle();
Song currentSong = playerVM.getCurrentSong();
String songId = currentSong.getId();
String songTitle = currentSong.getTitle();

// Dialog automatically closes on choice click; no need to manually do it
if (title.isEmpty()) {
Misc.toast(requireView(),
"Name cannot be empty!");
Misc.toast(requireView(), "Name cannot be empty!");
} else {
playlistVM.createNewPlaylist(title, songId);
Misc.toast(requireView(), title + " created with '" + songTitle + "' added!");
Expand Down Expand Up @@ -144,11 +143,11 @@ public void onAddToExistingPlaylistSelected() {
};

// Listens to specific events defined in PlayerViewModel
private final PlayingViewModel.PlayerListener playerListener = new PlayingViewModel.PlayerListener() {
private final PlayingViewModel.Listener playerListener = new PlayingViewModel.Listener() {
@Override
public void onSongPrepared() {
B.seekBar.setMax(playerVM.getDuration());
B.rtl.setText(getTimeFormat(playerVM.getDuration()));
B.progressBar.setMax(playerVM.getDuration());
B.remainingTimeText.setText(getTimeFormat(playerVM.getDuration()));
setLikedBtnBasedOnFlag();
}

Expand Down Expand Up @@ -193,7 +192,7 @@ public void onItemClick(Song song) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// View Binding. Removes the need for 'findViewById(id)'
// View binding
B = FragmentPlayerBinding.inflate(inflater, container, false);
handler = new Handler();

Expand All @@ -211,7 +210,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
B.playerRecycler.scrollToPosition(0);
Anims.recyclerFall(B.playerRecycler);
});

songVM.selectedSong.observe(this, this::onCurrentSongChange);
playerVM.currentSong.observe(this, this::updateUiFromSong);
playerVM.isPlaying.observe(this, this::onIsPlayingChange);
Expand All @@ -221,7 +219,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
// Listeners
songVM.setOnLikedListener(onLikedListener);
playerVM.setPlayerListener(playerListener);
B.seekBar.setOnSeekBarChangeListener(onSeekBarChangeListener);
B.progressBar.setOnSeekBarChangeListener(onSeekBarChangeListener);

// Separate functions from animations to reduce unnecessary clutter
B.btnPlaylistOptions.setOnClickListener(view -> PopupBuilder.forPlayer(view, onPlayerMenuItemSelected));
Expand All @@ -230,6 +228,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
B.btnPrevious.setOnClickListener(view -> playerVM.playPrevious());
B.btnLoop.setOnClickListener(view -> playerVM.toggleLoop());
B.btnShuffle.setOnClickListener(view -> playerVM.toggleShuffle());
B.btnBackPress.setOnClickListener(this::onBackPressed);
B.btnLike.setOnClickListener(this::toggleLikeOnSong);

// Button animations
Expand All @@ -239,6 +238,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
B.btnPrevious.setOnTouchListener(Anims::smallShrink);
B.btnLoop.setOnTouchListener(Anims::smallShrink);
B.btnShuffle.setOnTouchListener(Anims::smallShrink);
B.btnBackPress.setOnTouchListener(Anims::smallShrink);
B.btnLike.setOnTouchListener(Anims::smallShrink);

// PlayerAdapter
Expand Down Expand Up @@ -281,29 +281,33 @@ private void onIsShuffledChange(boolean isShuffling) {
));
}

private void onBackPressed(View v) {
requireActivity().onBackPressed();
}

// Find bottom UI from activity
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ui = requireActivity().getWindow();
mNavBar = requireActivity().findViewById(R.id.navBar);
mBottomSheet = requireActivity().findViewById(R.id.bottomSheet);
// mBottomSheet = requireActivity().findViewById(R.id.bottomSheet);
}

// Make bottom UI visible
@Override
public void onDestroyView() {
super.onDestroyView();
mNavBar.setVisibility(View.VISIBLE);
mBottomSheet.setVisibility(View.VISIBLE);
// mBottomSheet.setVisibility(View.VISIBLE);
}

// No bottom UI while view exists
@Override
public void onResume() {
super.onResume();
mNavBar.setVisibility(View.GONE);
mBottomSheet.setVisibility(View.GONE);
// mBottomSheet.setVisibility(View.GONE);
}

private void updateUiFromSong(Song song) {
Expand Down Expand Up @@ -349,8 +353,8 @@ private String getTimeFormat(int duration) {
private final Runnable updatingSeekBar = new Runnable() {
@Override
public void run() {
B.seekBar.setProgress(playerVM.getCurrentPos());
B.etl.setText(getTimeFormat(playerVM.getCurrentPos()));
B.progressBar.setProgress(playerVM.getCurrentPos());
B.elapsedTimeText.setText(getTimeFormat(playerVM.getCurrentPos()));
handler.postDelayed(this, 500);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
songVM = new ViewModelProvider(requireActivity()).get(SongViewModel.class);

// update local cache with playlists from Firestore
playlistVM.getPlaylistsFromDb(Query.Direction.ASCENDING);
// playlistVM.getPlaylistsFromDb(Query.Direction.ASCENDING);

// When there is a change in playlists, update PlaylistAdapter
playlistVM.getPlaylists().observe(getViewLifecycleOwner(), playlists -> {
Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/com/example/bitjam/utils/PopupBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,6 @@ public class PopupBuilder {
private static OnPlayerMenuItemSelected mOnPlayerMenuItemSelectedCallback;
private static OnSortingMenuItemSelected mOnSortingMenuItemSelected;

// Creating multiple PopupMenus can and will result in a large amount of duplicated code that
// gets scattered everywhere. This results in a lot of code smell and hence we should extract
// the builder methods and compact them into a single one that we can call directly. The use of
// a static context allows us to use the method without instantiating its class, which helps to
// reduce memory usage from exposing unnecessary methods. I've done my best to delegate different
// popups into their own methods, but there is still a ton of repeated code. There is actually
// a better way to do it...

/**
* Builds a popup menu for {@link PlayingFragment}'s
* playlist button.
Expand Down Expand Up @@ -117,10 +109,6 @@ public static void forSortOrder(View v, OnSortingMenuItemSelected callback) {
popup.show();
}

// These nested interfaces allow any classes/anonymous inner classes that implement them to
// trigger any callbacks without holding any actual references to this class. This is one of the
// best ways to reduce coupling. However, too many methods in a listener can congest/dirty code
// if used for various means, making some of the forced implemented methods useless.
public interface OnPlaylistMenuItemSelected {
void onEditPlaylistNameItemSelected();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public class PlayingViewModel extends ViewModel {
public final PureLiveData<Boolean> isShuffled = new PureLiveData<>(false);
public final PureLiveData<Boolean> isLooping = new PureLiveData<>(false);
public final PureLiveData<Song> currentSong = new PureLiveData<>(Song.getEmpty());
private PlayerListener mPlayerListener;
private Listener mListener;

// Initialise self's completion listener
public PlayingViewModel() {
mp.setOnCompletionListener(mp -> mPlayerListener.onSongCompletion());
mp.setOnCompletionListener(mp -> mListener.onSongCompletion());
}

/**
Expand Down Expand Up @@ -57,7 +57,7 @@ public void prepareSong(Song song) {
e.printStackTrace();
}

mPlayerListener.onSongPrepared();
mListener.onSongPrepared();
}

public void togglePlayPause() {
Expand Down Expand Up @@ -92,7 +92,7 @@ public void playNext() {

prepareSong(mSongs.get(nextSongIndex));
play();
mPlayerListener.onNext();
mListener.onNext();
}

public void playPrevious() {
Expand All @@ -108,7 +108,7 @@ public void playPrevious() {

prepareSong(mSongs.get(prevSongIndex));
play();
mPlayerListener.onPrevious();
mListener.onPrevious();
}

/**
Expand Down Expand Up @@ -149,12 +149,12 @@ public void toggleShuffle() {
public void enableShuffle() {
Collections.shuffle(mSongs);
isShuffled.setValue(true);
mPlayerListener.onShuffled(mSongs);
mListener.onShuffled(mSongs);
}

public void disableShuffle() {
isShuffled.setValue(false);
mPlayerListener.onUnshuffled(mPermSongs);
mListener.onUnshuffled(mPermSongs);
}

/**
Expand Down Expand Up @@ -192,7 +192,7 @@ public int getCurrentPos() {
}

// PlayerFragment implements these listeners
public interface PlayerListener {
public interface Listener {

void onSongPrepared();

Expand All @@ -214,7 +214,7 @@ public interface PlayerListener {
}

// initialises the listener
public void setPlayerListener(PlayerListener listener) {
this.mPlayerListener = listener;
public void setPlayerListener(Listener listener) {
this.mListener = listener;
}
}
Loading

0 comments on commit 1ffd183

Please sign in to comment.