Skip to content
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
fb10b95
HyeonSeong-P May 21, 2022
ebc1dd0
HyeonSeong-P May 21, 2022
e793a5a
HyeonSeong-P May 21, 2022
b83b809
HyeonSeong-P May 21, 2022
e9a6c82
HyeonSeong-P May 21, 2022
c4458cf
HyeonSeong-P May 21, 2022
834472c
HyeonSeong-P May 21, 2022
8aef9de
HyeonSeong-P May 21, 2022
1a84ed4
Merge pull request #1 from HyeonSeong-P/dev_phs
HyeonSeong-P May 22, 2022
2a21d99
Introduce Explaining Variable
HyeonSeong-P May 21, 2022
04d74b9
Extract Method
HyeonSeong-P May 21, 2022
f4a5338
Extract Superclass, Encapsulate Field
HyeonSeong-P May 21, 2022
5a8590a
Add files via upload
MoalikhanM May 22, 2022
725cde2
Extract Method
HyeonSeong-P May 21, 2022
48bad42
Extract Method
HyeonSeong-P May 21, 2022
9cda77e
Rename
HyeonSeong-P May 21, 2022
eade284
Extract Method, Introduce Explaining Variable
HyeonSeong-P May 21, 2022
5a11ab9
Extract Method
HyeonSeong-P May 21, 2022
e33ce79
Merge remote-tracking branch 'origin/dev_phs' into dev_phs
HyeonSeong-P May 22, 2022
0ba697a
Merge pull request #3 from HyeonSeong-P/dev_phs
HyeonSeong-P May 22, 2022
6b206f3
메서드 추출을 바탕으로 메서드가 작아지며 메서드의 책임이 명확해집니다. 또한 클래스의 개수는 늘어나지 않는 점을 활용했습니다.
KiSooByeon May 22, 2022
1f87e8e
Add files via upload
MoalikhanM May 22, 2022
c9b7714
Merge pull request #2 from MorningstarMaestro/master
HyeonSeong-P May 22, 2022
b806ff8
Add files via upload
MoalikhanM May 22, 2022
d50084c
Merge branch 'master' into master
HyeonSeong-P May 22, 2022
41d46e6
Merge pull request #4 from KiSooByeon/master
HyeonSeong-P May 22, 2022
40cf3dd
Merge pull request #5 from MorningstarMaestro/master
HyeonSeong-P May 22, 2022
8ebfe6a
Add files via upload
MoalikhanM May 22, 2022
f82ece5
HyeonSeong-P May 26, 2022
ce48a9f
Singleton Pattern
HyeonSeong-P May 27, 2022
f452161
(Merge pull request #6 from MorningstarMaestro/master)
HyeonSeong-P May 27, 2022
6dd09b3
Factory Method Pattern, Singleton Pattern
HyeonSeong-P May 27, 2022
0292ddc
팩토리 메소드 패턴
KiSooByeon May 29, 2022
8a481a0
Merge remote-tracking branch 'origin/master'
KiSooByeon May 29, 2022
7d6dd09
팩토리 메소드 패턴
KiSooByeon May 31, 2022
a6a1002
Merge pull request #2 from HyeonSeong-P/master
KiSooByeon May 31, 2022
980a801
Add files via upload
MoalikhanM May 31, 2022
b0ace45
Merge pull request #7 from KiSooByeon/master
HyeonSeong-P May 31, 2022
474f89e
Merge pull request #9 from MorningstarMaestro/master
HyeonSeong-P May 31, 2022
a1e6090
Merge pull request #8 from HyeonSeong-P/dev_design_pattern_phs
HyeonSeong-P May 31, 2022
2090491
HyeonSeong-P Jun 5, 2022
12ad144
HyeonSeong-P Jun 5, 2022
47c4cfc
DialogFactory 테스트
HyeonSeong-P Jun 5, 2022
24c0f59
HyeonSeong-P Jun 5, 2022
fcbe2d7
CalendarUtil 테스트
HyeonSeong-P Jun 5, 2022
a709195
CalendarUtil 테스트
HyeonSeong-P Jun 6, 2022
a3899a7
CalendarUtil getDaysInMonth Test Edit
HyeonSeong-P Jun 8, 2022
0c13719
프로젝트 정상 동작 위한 의미없는 edit
HyeonSeong-P Jun 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ android {
applicationId 'com.kabouzeid.gramophone'
versionCode 179
versionName '1.3.5'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}
signingConfigs {
release {
Expand Down Expand Up @@ -126,4 +128,11 @@ dependencies {
implementation 'org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5'

implementation 'com.github.AdrienPoupa:jaudiotagger:2.2.3'

// Required -- JUnit 4 framework
testImplementation 'junit:junit:4.12'
// Optional -- Robolectric environment
testImplementation 'androidx.test:core:1.0.0'
// Optional -- Mockito framework
testImplementation 'org.mockito:mockito-core:1.10.19'
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,8 @@ public static AddToPlaylistDialog create(List<Song> songs) {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final List<Playlist> playlists = PlaylistLoader.getAllPlaylists(getActivity());
CharSequence[] playlistNames = new CharSequence[playlists.size() + 1];
playlistNames[0] = getActivity().getResources().getString(R.string.action_new_playlist);
for (int i = 1; i < playlistNames.length; i++) {
playlistNames[i] = playlists.get(i - 1).name;
}
CharSequence[] playlistNames = getPlaylistNames(playlists);

return new MaterialDialog.Builder(getActivity())
.title(R.string.add_playlist_title)
.items(playlistNames)
Expand All @@ -62,4 +59,13 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
})
.build();
}

private CharSequence[] getPlaylistNames(List<Playlist> playlists){
CharSequence[] playlistNames = new CharSequence[playlists.size() + 1];
playlistNames[0] = getActivity().getResources().getString(R.string.action_new_playlist);
for (int i = 1; i < playlistNames.length; i++) {
playlistNames[i] = playlists.get(i - 1).name;
}
return playlistNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,11 @@
/**
* @author Aidan Follestad (afollestad), modified by Karim Abou Zeid
*/
public class BlacklistFolderChooserDialog extends DialogFragment implements MaterialDialog.ListCallback {

private File parentFolder;
private File[] parentContents;
private boolean canGoUp = false;
public class BlacklistFolderChooserDialog extends ChooserDialog implements MaterialDialog.ListCallback {

private FolderCallback callback;

String initialPath = Environment.getExternalStorageDirectory().getAbsolutePath();

private String[] getContentsArray() {
if (parentContents == null) {
if (canGoUp) {
return new String[]{".."};
}
return new String[]{};
}
String[] results = new String[parentContents.length + (canGoUp ? 1 : 0)];
if (canGoUp) {
results[0] = "..";
}
for (int i = 0; i < parentContents.length; i++) {
results[canGoUp ? i + 1 : i] = parentContents[i].getName();
}
return results;
}

private File[] listFiles() {
File[] contents = parentFolder.listFiles();
List<File> results = new ArrayList<>();
if (contents != null) {
for (File fi : contents) {
if (fi.isDirectory()) {
results.add(fi);
}
}
Collections.sort(results, new FolderSorter());
return results.toArray(new File[results.size()]);
}
return null;
}

public static BlacklistFolderChooserDialog create() {
return new BlacklistFolderChooserDialog();
Expand All @@ -72,10 +36,8 @@ public static BlacklistFolderChooserDialog create() {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ActivityCompat.checkSelfPermission(
getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED) {
if (isSDKAboveAndroidMarshmallow
&& isNotGrantedPermissionToReadExternalStorage) {
return new MaterialDialog.Builder(getActivity())
.title(R.string.md_error_label)
.content(R.string.md_storage_perm_error)
Expand All @@ -88,18 +50,20 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
if (!savedInstanceState.containsKey("current_path")) {
savedInstanceState.putString("current_path", initialPath);
}
parentFolder = new File(savedInstanceState.getString("current_path", File.pathSeparator));

setParentFolder(new File(savedInstanceState.getString("current_path", File.pathSeparator)));

checkIfCanGoUp();
parentContents = listFiles();
setParentContents(listFiles());
MaterialDialog.Builder builder =
new MaterialDialog.Builder(getActivity())
.title(parentFolder.getAbsolutePath())
.title(getParentFolder().getAbsolutePath())
.items((CharSequence[]) getContentsArray())
.itemsCallback(this)
.autoDismiss(false)
.onPositive((dialog, which) -> {
dismiss();
callback.onFolderSelection(BlacklistFolderChooserDialog.this, parentFolder);
callback.onFolderSelection(BlacklistFolderChooserDialog.this, getParentFolder());
})
.onNegative((materialDialog, dialogAction) -> dismiss())
.positiveText(R.string.add_action)
Expand All @@ -110,37 +74,21 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
@Override
public void onSelection(MaterialDialog materialDialog, View view, int i, CharSequence s) {
if (canGoUp && i == 0) {
parentFolder = parentFolder.getParentFile();
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
parentFolder = parentFolder.getParentFile();
setParentFolder(getParentFolder().getParentFile());
if (getParentFolder().getAbsolutePath().equals("/storage/emulated")) {
setParentFolder(getParentFolder().getParentFile());
}
checkIfCanGoUp();
} else {
parentFolder = parentContents[canGoUp ? i - 1 : i];
setParentFolder(getParentContents()[canGoUp ? i - 1 : i]);
canGoUp = true;
if (parentFolder.getAbsolutePath().equals("/storage/emulated")) {
parentFolder = Environment.getExternalStorageDirectory();
if (getParentFolder().getAbsolutePath().equals("/storage/emulated")) {
setParentFolder(Environment.getExternalStorageDirectory());
}
}
reload();
}

private void checkIfCanGoUp() {
canGoUp = parentFolder.getParent() != null;
}

private void reload() {
parentContents = listFiles();
MaterialDialog dialog = (MaterialDialog) getDialog();
dialog.setTitle(parentFolder.getAbsolutePath());
dialog.setItems((CharSequence[]) getContentsArray());
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("current_path", parentFolder.getAbsolutePath());
}

public void setCallback(FolderCallback callback) {
this.callback = callback;
Expand All @@ -150,11 +98,5 @@ public interface FolderCallback {
void onFolderSelection(@NonNull BlacklistFolderChooserDialog dialog, @NonNull File folder);
}

private static class FolderSorter implements Comparator<File> {

@Override
public int compare(File lhs, File rhs) {
return lhs.getName().compareTo(rhs.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;

import android.util.Log;
import android.view.InflateException;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -61,6 +60,11 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
})
.build();

loadWebView(customView);
return dialog;
}

private void loadWebView(View customView) {
final WebView webView = customView.findViewById(R.id.web_view);
try {
// Load from phonograph-changelog.html in the assets folder
Expand All @@ -84,7 +88,6 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
} catch (Throwable e) {
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
}
return dialog;
}

public static void setChangelogRead(@NonNull Context context) {
Expand Down
111 changes: 111 additions & 0 deletions app/src/main/java/com/kabouzeid/gramophone/dialogs/ChooserDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package com.kabouzeid.gramophone.dialogs;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;

import androidx.core.app.ActivityCompat;
import androidx.fragment.app.DialogFragment;

import com.afollestad.materialdialogs.MaterialDialog;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ChooserDialog extends DialogFragment{
String initialPath = Environment.getExternalStorageDirectory().getAbsolutePath();
private File parentFolder;
private File[] parentContents;

protected File getParentFolder() {
return parentFolder;
}

protected void setParentFolder(File parentFolder) {
this.parentFolder = parentFolder;
}

protected File[] getParentContents() {
return parentContents;
}

protected void setParentContents(File[] parentContents) {
this.parentContents = parentContents;
}

protected boolean isCanGoUp() {
return canGoUp;
}

protected void setCanGoUp(boolean canGoUp) {
this.canGoUp = canGoUp;
}

protected boolean canGoUp = false;

protected final boolean isSDKAboveAndroidMarshmallow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
protected final boolean isNotGrantedPermissionToReadExternalStorage = ActivityCompat.checkSelfPermission(
getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE)
!= PackageManager.PERMISSION_GRANTED;

protected String[] getContentsArray() {
if (parentContents == null) {
if (canGoUp) {
return new String[]{".."};
}
return new String[]{};
}
String[] results = new String[parentContents.length + (canGoUp ? 1 : 0)];
if (canGoUp) {
results[0] = "..";
}
for (int i = 0; i < parentContents.length; i++) {
results[canGoUp ? i + 1 : i] = parentContents[i].getName();
}
return results;
}

protected File[] listFiles() {
File[] contents = parentFolder.listFiles();
List<File> results = new ArrayList<>();
if (contents != null) {
for (File fi : contents) {
if (fi.isDirectory()) {
results.add(fi);
}
}
Collections.sort(results, new FolderSorter());
return results.toArray(new File[results.size()]);
}
return null;
}

protected void checkIfCanGoUp() {
canGoUp = parentFolder.getParent() != null;
}

protected void reload() {
parentContents = listFiles();
MaterialDialog dialog = (MaterialDialog) getDialog();
dialog.setTitle(parentFolder.getAbsolutePath());
dialog.setItems((CharSequence[]) getContentsArray());
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString("current_path", parentFolder.getAbsolutePath());
}

protected static class FolderSorter implements Comparator<File> {
@Override
public int compare(File lhs, File rhs) {
return lhs.getName().compareTo(rhs.getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
if (!name.isEmpty()) {
if (!PlaylistsUtil.doesPlaylistExist(getActivity(), name)) {
final long playlistId = PlaylistsUtil.createPlaylist(getActivity(), name);
if (getActivity() != null) {
//noinspection unchecked
List<Song> songs = getArguments().getParcelableArrayList(SONGS);
if (songs != null && !songs.isEmpty()) {
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlistId, true);
}
}
addSongsToPlayList(playlistId);
} else {
Toast.makeText(getActivity(), getActivity().getResources().getString(
R.string.playlist_exists, name), Toast.LENGTH_SHORT).show();
Expand All @@ -77,4 +71,14 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
})
.build();
}

private void addSongsToPlayList(long playlistId) {
if (getActivity() != null) {
//noinspection unchecked
List<Song> songs = getArguments().getParcelableArrayList(SONGS);
if (songs != null && !songs.isEmpty()) {
PlaylistsUtil.addToPlaylist(getActivity(), songs, playlistId, true);
}
}
}
}
Loading