diff --git a/app/src/fdroid/java/com/cg/lrceditor/AboutActivity.java b/app/src/fdroid/java/com/cg/lrceditor/AboutActivity.java index abf35a3..bb99885 100644 --- a/app/src/fdroid/java/com/cg/lrceditor/AboutActivity.java +++ b/app/src/fdroid/java/com/cg/lrceditor/AboutActivity.java @@ -24,7 +24,7 @@ public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = getSharedPreferences("LRC Editor Preferences", MODE_PRIVATE); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); if (theme.equals("dark")) { isDarkTheme = true; setTheme(R.style.AppThemeDark); diff --git a/app/src/fdroid/res/values-de/strings.xml b/app/src/fdroid/res/values-de/strings.xml index 96a1c4d..cd75628 100644 --- a/app/src/fdroid/res/values-de/strings.xml +++ b/app/src/fdroid/res/values-de/strings.xml @@ -1,3 +1,3 @@ Sehen Sie sich die App auf F-Droid an - \ No newline at end of file + diff --git a/app/src/fdroid/res/values-in/strings.xml b/app/src/fdroid/res/values-in/strings.xml index 61bbab5..51cd9ac 100644 --- a/app/src/fdroid/res/values-in/strings.xml +++ b/app/src/fdroid/res/values-in/strings.xml @@ -1,3 +1,3 @@ Lihat aplikasi di F-Droid - \ No newline at end of file + diff --git a/app/src/fdroid/res/values-pl/strings.xml b/app/src/fdroid/res/values-pl/strings.xml index 7e5c273..c3faca5 100644 --- a/app/src/fdroid/res/values-pl/strings.xml +++ b/app/src/fdroid/res/values-pl/strings.xml @@ -1,3 +1,3 @@ Wyświetl aplikację na F-Droid - \ No newline at end of file + diff --git a/app/src/fdroid/res/values-pt-rBR/strings.xml b/app/src/fdroid/res/values-pt-rBR/strings.xml index 0da4faa..0a8f8c4 100644 --- a/app/src/fdroid/res/values-pt-rBR/strings.xml +++ b/app/src/fdroid/res/values-pt-rBR/strings.xml @@ -1,3 +1,3 @@ Ver a aplicação no F-Droid - \ No newline at end of file + diff --git a/app/src/fdroid/res/values-zh-rTW/strings.xml b/app/src/fdroid/res/values-zh-rTW/strings.xml index e5538e2..3682dd4 100644 --- a/app/src/fdroid/res/values-zh-rTW/strings.xml +++ b/app/src/fdroid/res/values-zh-rTW/strings.xml @@ -1,3 +1,3 @@ 在F-Droid上查看应用 - \ No newline at end of file + diff --git a/app/src/fdroid/res/values/strings.xml b/app/src/fdroid/res/values/strings.xml index 6109fbc..ced628c 100644 --- a/app/src/fdroid/res/values/strings.xml +++ b/app/src/fdroid/res/values/strings.xml @@ -1,3 +1,3 @@ View the app on F-Droid - \ No newline at end of file + diff --git a/app/src/main/java/com/cg/lrceditor/Constants.java b/app/src/main/java/com/cg/lrceditor/Constants.java index 24cac7e..1d4d829 100644 --- a/app/src/main/java/com/cg/lrceditor/Constants.java +++ b/app/src/main/java/com/cg/lrceditor/Constants.java @@ -11,4 +11,11 @@ class Constants { static final long MAX_TIMESTAMP_VALUE = Timestamp.MAX_TIMESTAMP_VALUE; static final String defaultLocation = Environment.getExternalStorageDirectory().getPath() + "/Lyrics"; + + static final String READ_LOCATION_PREFERENCE = "readLocation"; + static final String SAVE_LOCATION_PREFERENCE = "saveLocation"; + static final String TIMESTAMP_STEP_AMOUNT_PREFERENCE = "timestamp_step_amount"; + static final String THREE_DIGIT_MILLISECONDS_PREFERENCE = "three_digit_milliseconds"; + static final String THEME_PREFERENCE = "current_theme"; + static final String PURCHASED_PREFERENCE = "lrceditor_purchased"; } diff --git a/app/src/main/java/com/cg/lrceditor/CreateActivity.java b/app/src/main/java/com/cg/lrceditor/CreateActivity.java index 3918068..f71b697 100644 --- a/app/src/main/java/com/cg/lrceditor/CreateActivity.java +++ b/app/src/main/java/com/cg/lrceditor/CreateActivity.java @@ -20,7 +20,7 @@ public class CreateActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = getSharedPreferences("LRC Editor Preferences", MODE_PRIVATE); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); if (theme.equals("dark")) { isDarkTheme = true; setTheme(R.style.AppThemeDark); diff --git a/app/src/main/java/com/cg/lrceditor/EditorActivity.java b/app/src/main/java/com/cg/lrceditor/EditorActivity.java index 1909e19..ba7bbfc 100644 --- a/app/src/main/java/com/cg/lrceditor/EditorActivity.java +++ b/app/src/main/java/com/cg/lrceditor/EditorActivity.java @@ -73,7 +73,7 @@ public class EditorActivity extends AppCompatActivity implements LyricListAdapte private Uri songUri = null; private String songFileName = null; - private SongMetaData songMetaData = null; + private Metadata metadata = null; private LyricItem[] clipboard = null; @@ -86,6 +86,7 @@ public class EditorActivity extends AppCompatActivity implements LyricListAdapte private MediaSession mediaSession; private float currentPlayerSpeed; private float currentPlayerPitch; + private int timestampAdjustStep; private Handler songTimeUpdater = new Handler(); private SeekBar seekbar; @@ -105,7 +106,7 @@ public class EditorActivity extends AppCompatActivity implements LyricListAdapte @Override public void run() { if (!isPlaying) { - flasher.postDelayed(this, 30); + flasher.postDelayed(this, 35); return; } @@ -113,7 +114,7 @@ public void run() { int last = linearLayoutManager.findLastVisibleItemPosition(); if (first == -1 || last == -1) { - flasher.postDelayed(this, 30); + flasher.postDelayed(this, 35); return; } @@ -139,7 +140,7 @@ public void run() { } } - flasher.postDelayed(this, 30); + flasher.postDelayed(this, 35); } }; @@ -156,9 +157,9 @@ public void run() { Timestamp timestamp = adapter.lyricData.get(longPressedPos).getTimestamp(); if (longPressed == 1) { - timestamp.alterTimestamp(100); + timestamp.alterTimestamp(timestampAdjustStep); } else if (longPressed == -1) { - timestamp.alterTimestamp(-100); + timestamp.alterTimestamp(-timestampAdjustStep); } long time = timestamp.toMilliseconds(); @@ -191,7 +192,7 @@ public void run() { @Override protected void onCreate(Bundle savedInstanceState) { SharedPreferences preferences = getSharedPreferences("LRC Editor Preferences", MODE_PRIVATE); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); if (theme.equals("dark")) { isDarkTheme = true; setTheme(R.style.AppThemeDark); @@ -216,6 +217,8 @@ protected void onCreate(Bundle savedInstanceState) { e.printStackTrace(); } + timestampAdjustStep = preferences.getInt(Constants.TIMESTAMP_STEP_AMOUNT_PREFERENCE, 100); + swipeRefreshLayout = findViewById(R.id.swiperefresh); swipeRefreshLayout.setEnabled(false); @@ -254,7 +257,7 @@ protected void onCreate(Bundle savedInstanceState) { Timestamp[] timestamps = r.getTimestamps(); ArrayList lyricData = populateDataSet(lyrics, timestamps, false); - songMetaData = r.getSongMetaData(); + metadata = r.getMetadata(); lrcFileName = FileUtil.getFileName(ctx, intent.getData()); adapter = new LyricListAdapter(ctx, lyricData, isDarkTheme); @@ -277,7 +280,7 @@ protected void onCreate(Bundle savedInstanceState) { lyricData = populateDataSet(lyrics, timestamps, false); } - songMetaData = (SongMetaData) intent.getSerializableExtra("SONG METADATA"); + metadata = (Metadata) intent.getSerializableExtra("METADATA"); lrcFileName = intent.getStringExtra("LRC FILE NAME"); adapter = new LyricListAdapter(this, lyricData, isDarkTheme); @@ -491,7 +494,7 @@ public void onIncreaseTimeClick(int position) { longPressedPos = -1; Timestamp timestamp = adapter.lyricData.get(position).getTimestamp(); - timestamp.alterTimestamp(100); + timestamp.alterTimestamp(timestampAdjustStep); adapter.notifyItemChanged(position); changedData = true; @@ -522,7 +525,7 @@ public void onDecreaseTimeClick(int position) { longPressedPos = -1; Timestamp timestamp = adapter.lyricData.get(position).getTimestamp(); - timestamp.alterTimestamp(-100); + timestamp.alterTimestamp(-timestampAdjustStep); adapter.notifyItemChanged(position); changedData = true; @@ -1216,10 +1219,12 @@ private void insertLyrics(final String[] lyrics, int optionMode) { } private void batchEditLyrics() { - LayoutInflater inflater = this.getLayoutInflater(); - final View view = inflater.inflate(R.layout.dialog_batch_edit, null); - final TextView batchTimestamp = view.findViewById(R.id.batch_item_time); + final View view = inflater.inflate(R.layout.dialog_adjust, null); + final TextView batchTitle = view.findViewById(R.id.title); + batchTitle.setText(R.string.batch_edit_prompt); + final TextView batchTimestamp = view.findViewById(R.id.content); + batchTimestamp.setText("+00:00.00"); final Timestamp timestamp = new Timestamp("00:00.00"); @@ -1237,22 +1242,25 @@ public void run() { if (longPressed[0] != 0) { if (longPressed[0] == 1) { - if (batchTimeNegative[0]) - timestamp.alterTimestamp(-100); - else - timestamp.alterTimestamp(100); + if (batchTimeNegative[0]) { + timestamp.alterTimestamp(-timestampAdjustStep); + } else { + timestamp.alterTimestamp(timestampAdjustStep); + } if (batchTimeNegative[0] && timestamp.toMilliseconds() <= 0) { batchTimeNegative[0] = false; } } else { - if (!batchTimeNegative[0] && timestamp.toMilliseconds() - 100 < 0) + if (!batchTimeNegative[0] && timestamp.toMilliseconds() - timestampAdjustStep < 0) { batchTimeNegative[0] = true; + } - if (batchTimeNegative[0]) - timestamp.alterTimestamp(100); - else - timestamp.alterTimestamp(-100); + if (batchTimeNegative[0]) { + timestamp.alterTimestamp(timestampAdjustStep); + } else { + timestamp.alterTimestamp(-timestampAdjustStep); + } } if (!batchTimeNegative[0]) { @@ -1269,16 +1277,17 @@ public void run() { }; - ImageButton increase = view.findViewById(R.id.batch_increase_time_button); + ImageButton increase = view.findViewById(R.id.increase_button); if (isDarkTheme) { increase.setImageDrawable(getDrawable(R.drawable.ic_add_light)); } increase.setOnClickListener(v -> { - if (batchTimeNegative[0]) - timestamp.alterTimestamp(-100); - else - timestamp.alterTimestamp(100); + if (batchTimeNegative[0]) { + timestamp.alterTimestamp(-timestampAdjustStep); + } else { + timestamp.alterTimestamp(timestampAdjustStep); + } if (batchTimeNegative[0] && timestamp.toMilliseconds() <= 0) { batchTimeNegative[0] = false; @@ -1304,19 +1313,21 @@ public void run() { return false; }); - ImageButton decrease = view.findViewById(R.id.batch_decrease_time_button); + ImageButton decrease = view.findViewById(R.id.decrease_button); if (isDarkTheme) { decrease.setImageDrawable(getDrawable(R.drawable.ic_minus_light)); } decrease.setOnClickListener(v -> { - if (!batchTimeNegative[0] && timestamp.toMilliseconds() - 100 < 0) + if (!batchTimeNegative[0] && timestamp.toMilliseconds() - timestampAdjustStep < 0) { batchTimeNegative[0] = true; + } - if (batchTimeNegative[0]) - timestamp.alterTimestamp(100); - else - timestamp.alterTimestamp(-100); + if (batchTimeNegative[0]) { + timestamp.alterTimestamp(timestampAdjustStep); + } else { + timestamp.alterTimestamp(-timestampAdjustStep); + } if (!batchTimeNegative[0]) { batchTimestamp.setText( @@ -1338,7 +1349,7 @@ public void run() { return false; }); - AlertDialog dialog = new AlertDialog.Builder(this) + new AlertDialog.Builder(this) .setView(view) .setTitle(R.string.batch_edit) .setPositiveButton(getString(R.string.adjust), (dialog1, which) -> { @@ -1358,9 +1369,8 @@ public void run() { }) .setNegativeButton(getString(R.string.cancel), (dialog12, which) -> longPressed[0] = 0) .setCancelable(false) - .create(); - - dialog.show(); + .create() + .show(); } private void displayPlaybackOptions() { @@ -1480,7 +1490,7 @@ public boolean onOptionsItemSelected(MenuItem item) { Intent intent = new Intent(this, FinalizeActivity.class); intent.putExtra("LYRIC DATA", (ArrayList) adapter.lyricData); intent.putExtra("SONG URI", songUri); - intent.putExtra("SONG METADATA", songMetaData); + intent.putExtra("METADATA", metadata); intent.putExtra("SONG FILE NAME", songFileName); intent.putExtra("LRC FILE NAME", lrcFileName); diff --git a/app/src/main/java/com/cg/lrceditor/FinalizeActivity.java b/app/src/main/java/com/cg/lrceditor/FinalizeActivity.java index a09517b..8ff87a7 100644 --- a/app/src/main/java/com/cg/lrceditor/FinalizeActivity.java +++ b/app/src/main/java/com/cg/lrceditor/FinalizeActivity.java @@ -50,6 +50,7 @@ public class FinalizeActivity extends AppCompatActivity { private EditText artistName; private EditText albumName; private EditText composerName; + private EditText creatorName; private TextView statusTextView; @@ -84,7 +85,7 @@ public static void hideKeyboard(Activity activity) { @Override protected void onResume() { super.onResume(); - saveLocation = preferences.getString("saveLocation", Constants.defaultLocation); + saveLocation = preferences.getString(Constants.SAVE_LOCATION_PREFERENCE, Constants.defaultLocation); String uriString = preferences.getString("saveUri", null); if (uriString != null) saveUri = Uri.parse(uriString); @@ -93,13 +94,13 @@ protected void onResume() { ((TextView) dialogView.findViewById(R.id.save_location_display)).setText(getString(R.string.save_location_displayer, saveLocation)); } - useThreeDigitMilliseconds = preferences.getBoolean("three_digit_milliseconds", false); + useThreeDigitMilliseconds = preferences.getBoolean(Constants.THREE_DIGIT_MILLISECONDS_PREFERENCE, false); } @Override protected void onCreate(Bundle savedInstanceState) { preferences = getSharedPreferences("LRC Editor Preferences", MODE_PRIVATE); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); if (theme.equals("dark")) { isDarkTheme = true; setTheme(R.style.AppThemeDark); @@ -113,7 +114,7 @@ protected void onCreate(Bundle savedInstanceState) { Intent intent = getIntent(); lyricData = (ArrayList) intent.getSerializableExtra("LYRIC DATA"); - SongMetaData songMetaData = (SongMetaData) intent.getSerializableExtra("SONG METADATA"); + Metadata metadata = (Metadata) intent.getSerializableExtra("METADATA"); Uri songUri = intent.getParcelableExtra("SONG URI"); lrcFileName = intent.getStringExtra("LRC FILE NAME"); songFileName = intent.getStringExtra("SONG FILE NAME"); @@ -122,6 +123,7 @@ protected void onCreate(Bundle savedInstanceState) { artistName = findViewById(R.id.artistName_edittext); albumName = findViewById(R.id.albumName_edittext); composerName = findViewById(R.id.composer_edittext); + creatorName = findViewById(R.id.creatorName_edittext); statusTextView = findViewById(R.id.status_textview); statusTextView.setMovementMethod(new ScrollingMovementMethod()); @@ -141,15 +143,18 @@ protected void onCreate(Bundle savedInstanceState) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) /* Marshmallow onwards require runtime permissions */ grantPermission(); - if (songMetaData != null) { - if (!songMetaData.getSongName().isEmpty()) - songName.setText(songMetaData.getSongName()); - if (!songMetaData.getArtistName().isEmpty()) - artistName.setText(songMetaData.getArtistName()); - if (!songMetaData.getAlbumName().isEmpty()) - albumName.setText(songMetaData.getAlbumName()); - if (!songMetaData.getComposerName().isEmpty()) - composerName.setText(songMetaData.getComposerName()); + if (metadata != null) { + if (!metadata.getSongName().isEmpty()) + songName.setText(metadata.getSongName()); + if (!metadata.getArtistName().isEmpty()) + artistName.setText(metadata.getArtistName()); + if (!metadata.getAlbumName().isEmpty()) + albumName.setText(metadata.getAlbumName()); + if (!metadata.getComposerName().isEmpty()) + composerName.setText(metadata.getComposerName()); + if (!metadata.getCreatorName().isEmpty()) { + creatorName.setText(metadata.getCreatorName()); + } } if (songUri != null) { @@ -354,6 +359,9 @@ private String lyricsToString(boolean useThreeDigitMilliseconds) { str = composerName.getText().toString().trim(); if (!str.isEmpty()) sb.append("[au: ").append(str).append("]\n"); + str = creatorName.getText().toString().trim(); + if (!str.isEmpty()) + sb.append("[by: ").append(str).append("]\n"); sb.append("\n") .append("[re: ").append(getString(R.string.app_name)).append(" - Android app").append("]\n") diff --git a/app/src/main/java/com/cg/lrceditor/HomePage.java b/app/src/main/java/com/cg/lrceditor/HomePage.java index 9bd7473..4ec549c 100644 --- a/app/src/main/java/com/cg/lrceditor/HomePage.java +++ b/app/src/main/java/com/cg/lrceditor/HomePage.java @@ -67,7 +67,7 @@ public class HomePage extends AppCompatActivity implements HomePageListAdapter.L @Override protected void onCreate(Bundle savedInstanceState) { preferences = getSharedPreferences("LRC Editor Preferences", MODE_PRIVATE); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); currentTheme = theme; if (theme.equals("dark")) { isDarkTheme = true; @@ -128,7 +128,7 @@ protected void onCreate(Bundle savedInstanceState) { startActivity(intent); }); - readLocation = preferences.getString("readLocation", Constants.defaultLocation); + readLocation = preferences.getString(Constants.READ_LOCATION_PREFERENCE, Constants.defaultLocation); actionModeCallback = new ActionModeCallback(); @@ -139,13 +139,13 @@ protected void onCreate(Bundle savedInstanceState) { protected void onResume() { super.onResume(); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); if (!theme.equals(currentTheme)) { recreate(); } String oldReadLocation = readLocation; - readLocation = preferences.getString("readLocation", Constants.defaultLocation); + readLocation = preferences.getString(Constants.READ_LOCATION_PREFERENCE, Constants.defaultLocation); String uriString = preferences.getString("readUri", null); if (uriString != null) { readUri = Uri.parse(uriString); @@ -312,7 +312,7 @@ private void showReadLocationResetDialog(File scanLocation) { .setPositiveButton(getString(R.string.yes), (dialog, which) -> { SharedPreferences.Editor editor = preferences.edit(); - editor.putString("readLocation", Constants.defaultLocation); + editor.putString(Constants.READ_LOCATION_PREFERENCE, Constants.defaultLocation); editor.apply(); readLocation = Constants.defaultLocation; @@ -550,7 +550,7 @@ public void fileSelected(String fileLocation, final String fileName) { Intent intent = new Intent(getApplicationContext(), EditorActivity.class); intent.putExtra("LYRICS", r.getLyrics()); intent.putExtra("TIMESTAMPS", r.getTimestamps()); - intent.putExtra("SONG METADATA", r.getSongMetaData()); + intent.putExtra("METADATA", r.getMetadata()); intent.putExtra("LRC FILE NAME", fileName); startActivity(intent); diff --git a/app/src/main/java/com/cg/lrceditor/HomePageListAdapter.java b/app/src/main/java/com/cg/lrceditor/HomePageListAdapter.java index 98bf5d5..7186a83 100644 --- a/app/src/main/java/com/cg/lrceditor/HomePageListAdapter.java +++ b/app/src/main/java/com/cg/lrceditor/HomePageListAdapter.java @@ -57,8 +57,8 @@ public void onBindViewHolder(@NonNull LyricFileListItem holder, int position) { holder.subView.setVisibility(View.VISIBLE); holder.expandableButton.setRotation(180); - if (listData.get(position).songMetaData != null) { - displaySongMetaData(holder, listData.get(position).songMetaData); + if (listData.get(position).metadata != null) { + displayMetaData(holder, listData.get(position).metadata); displayLyricContents(holder, listData.get(position).lyrics); } } else { @@ -77,7 +77,7 @@ private void applyClickEvents(final LyricFileListItem holder) { HomePageListItem item = listData.get(holder.getAdapterPosition()); if (item.isExpanded) { item.isExpanded = false; - item.songMetaData = null; + item.metadata = null; item.lyrics = null; holder.expandableButton.animate().rotation(0).setDuration(300).start(); } else { @@ -111,7 +111,7 @@ private void previewLrcFileContents(final LyricFileListItem holder, final View v String[] msg = new String[1]; msg[0] = errorMsg; - listData.get(holder.getAdapterPosition()).songMetaData = new SongMetaData(); + listData.get(holder.getAdapterPosition()).metadata = new Metadata(); listData.get(holder.getAdapterPosition()).lyrics = msg; }); return; @@ -139,41 +139,46 @@ private void previewLrcFileContents(final LyricFileListItem holder, final View v } } - final SongMetaData songMetaData = r.getSongMetaData(); + final Metadata metadata = r.getMetadata(); - listData.get(holder.getAdapterPosition()).songMetaData = songMetaData; + listData.get(holder.getAdapterPosition()).metadata = metadata; listData.get(holder.getAdapterPosition()).lyrics = lyricsToDisplay; view.post(() -> { - displaySongMetaData(holder, songMetaData); + displayMetaData(holder, metadata); displayLyricContents(holder, lyricsToDisplay); }); }).start(); } - private void displaySongMetaData(LyricFileListItem holder, SongMetaData songMetaData) { + private void displayMetaData(LyricFileListItem holder, Metadata metadata) { Context ctx = holder.linearLayout.getContext(); String string; - string = songMetaData.getSongName(); + string = metadata.getSongName(); if (string.trim().isEmpty()) string = "N/A"; holder.songName.setText(String.format(Locale.getDefault(), "%s %s", ctx.getString(R.string.song_name_prompt), string)); - string = songMetaData.getArtistName(); + string = metadata.getArtistName(); if (string.trim().isEmpty()) string = "N/A"; holder.artistName.setText(String.format(Locale.getDefault(), "%s %s", ctx.getString(R.string.artist_name_prompt), string)); - string = songMetaData.getAlbumName(); + string = metadata.getAlbumName(); if (string.trim().isEmpty()) string = "N/A"; holder.albumName.setText(String.format(Locale.getDefault(), "%s %s", ctx.getString(R.string.album_name_prompt), string)); - string = songMetaData.getComposerName(); + string = metadata.getComposerName(); if (string.trim().isEmpty()) string = "N/A"; holder.composerName.setText(String.format(Locale.getDefault(), "%s %s", ctx.getString(R.string.composer_prompt), string)); + + string = metadata.getCreatorName(); + if (string.trim().isEmpty()) + string = "N/A"; + holder.creatorName.setText(String.format(Locale.getDefault(), "%s %s", ctx.getString(R.string.creator_name_prompt), string)); } private void displayLyricContents(LyricFileListItem holder, String[] lyricsToDisplay) { @@ -190,6 +195,7 @@ private void clearExpandedData(LyricFileListItem holder) { holder.artistName.setText(ctx.getString(R.string.artist_name_prompt)); holder.albumName.setText(ctx.getString(R.string.album_name_prompt)); holder.composerName.setText(ctx.getString(R.string.composer_prompt)); + holder.creatorName.setText(ctx.getString(R.string.creator_name_prompt)); holder.lyricsTextview.setText(ctx.getString(R.string.loading_lyrics)); } @@ -218,7 +224,7 @@ void clearExpandedItems() { HomePageListItem item = listData.get(i); if (item.isExpanded) { item.isExpanded = false; - item.songMetaData = null; + item.metadata = null; item.lyrics = null; notifyItemChanged(i); } @@ -313,6 +319,7 @@ class LyricFileListItem extends RecyclerView.ViewHolder { private TextView albumName; private TextView artistName; private TextView composerName; + private TextView creatorName; private TextView lyricsTextview; @@ -337,6 +344,7 @@ class LyricFileListItem extends RecyclerView.ViewHolder { artistName = itemView.findViewById(R.id.artistname_textview); albumName = itemView.findViewById(R.id.albumname_textview); composerName = itemView.findViewById(R.id.composername_textview); + creatorName = itemView.findViewById(R.id.creatorname_textview); lyricsTextview = itemView.findViewById(R.id.lyrics_textview); diff --git a/app/src/main/java/com/cg/lrceditor/HomePageListItem.java b/app/src/main/java/com/cg/lrceditor/HomePageListItem.java index 5ee6e13..b21d0b3 100644 --- a/app/src/main/java/com/cg/lrceditor/HomePageListItem.java +++ b/app/src/main/java/com/cg/lrceditor/HomePageListItem.java @@ -5,13 +5,13 @@ public class HomePageListItem { public File file; public String[] lyrics; - SongMetaData songMetaData; + Metadata metadata; boolean isExpanded = false; boolean isSelected = false; - HomePageListItem(File file, SongMetaData songMetaData, String[] lyrics) { + HomePageListItem(File file, Metadata metadata, String[] lyrics) { this.file = file; - this.songMetaData = songMetaData; + this.metadata = metadata; this.lyrics = lyrics; } } diff --git a/app/src/main/java/com/cg/lrceditor/LyricReader.java b/app/src/main/java/com/cg/lrceditor/LyricReader.java index 8dd4098..cc139d8 100644 --- a/app/src/main/java/com/cg/lrceditor/LyricReader.java +++ b/app/src/main/java/com/cg/lrceditor/LyricReader.java @@ -17,19 +17,15 @@ import java.util.List; public class LyricReader { - private LyricItem[] lyricData; - - private SongMetaData songMetaData = new SongMetaData(); - - private String errorMsg; + private Metadata metadata = new Metadata(); private File file = null; + private InputStream in = null; + private String errorMsg; private Context ctx; - private InputStream in = null; - LyricReader(String path, String fileName, Context c) { this.file = new File(path, fileName); this.ctx = c; @@ -99,26 +95,28 @@ boolean readLyrics() { extras++; } timestamps.add(temp.substring(1, 9)); - } else if (temp.length() >= 4) { - String str = temp.substring(4, temp.length() - 1).trim(); - if (songMetaData.getSongName().isEmpty() && temp.matches("^\\[ti:.*]$")) { - songMetaData.setSongName(str); - } else if (songMetaData.getArtistName().isEmpty() && temp.matches("^\\[ar:.*]$")) { - songMetaData.setArtistName(str); - } else if (songMetaData.getAlbumName().isEmpty() && temp.matches("^\\[al:.*]$")) { - songMetaData.setAlbumName(str); - } else if (songMetaData.getComposerName().isEmpty() && temp.matches("^\\[au:.*]$")) { - songMetaData.setComposerName(str); - } else if (offset == 0 && temp.matches("^\\[offset:.*]$")) { - try { - offset = Integer.parseInt(temp.substring(8, temp.length() - 1).trim()); - } catch (NumberFormatException e) { // Ignore the offset if we couldn't scan it - e.printStackTrace(); + } else { + if (temp.length() > 4) { + String str = temp.substring(4, temp.length() - 1).trim(); + if (metadata.getSongName().isEmpty() && temp.matches("^\\[ti:.*]$")) { + metadata.setSongName(str); + } else if (metadata.getArtistName().isEmpty() && temp.matches("^\\[ar:.*]$")) { + metadata.setArtistName(str); + } else if (metadata.getAlbumName().isEmpty() && temp.matches("^\\[al:.*]$")) { + metadata.setAlbumName(str); + } else if (metadata.getComposerName().isEmpty() && temp.matches("^\\[au:.*]$")) { + metadata.setComposerName(str); + } else if (metadata.getCreatorName().isEmpty() && temp.matches("^\\[by:.*]$")) { + metadata.setCreatorName(str); + } else if (offset == 0 && temp.matches("^\\[offset:.*]$")) { + try { + offset = Integer.parseInt(temp.substring(8, temp.length() - 1).trim()); + } catch (NumberFormatException e) { // Ignore the offset if we couldn't scan it + e.printStackTrace(); + } } } - - break; - } else { + break; } } @@ -190,8 +188,8 @@ String getErrorMsg() { return errorMsg; } - SongMetaData getSongMetaData() { - return songMetaData; + Metadata getMetadata() { + return metadata; } static class LyricTimestampComparator implements Comparator { diff --git a/app/src/main/java/com/cg/lrceditor/SongMetaData.java b/app/src/main/java/com/cg/lrceditor/Metadata.java similarity index 76% rename from app/src/main/java/com/cg/lrceditor/SongMetaData.java rename to app/src/main/java/com/cg/lrceditor/Metadata.java index 88d1ae2..68117f8 100644 --- a/app/src/main/java/com/cg/lrceditor/SongMetaData.java +++ b/app/src/main/java/com/cg/lrceditor/Metadata.java @@ -2,11 +2,12 @@ import java.io.Serializable; -class SongMetaData implements Serializable { +class Metadata implements Serializable { private String artistName = ""; private String albumName = ""; private String songName = ""; private String composerName = ""; + private String creatorName = ""; String getSongName() { return this.songName; @@ -39,4 +40,12 @@ String getComposerName() { void setComposerName(String composerName) { this.composerName = composerName; } + + String getCreatorName() { + return this.creatorName; + } + + void setCreatorName(String creatorName) { + this.creatorName = creatorName; + } } diff --git a/app/src/main/java/com/cg/lrceditor/SettingsActivity.java b/app/src/main/java/com/cg/lrceditor/SettingsActivity.java index 88e9b7c..a6ee2aa 100644 --- a/app/src/main/java/com/cg/lrceditor/SettingsActivity.java +++ b/app/src/main/java/com/cg/lrceditor/SettingsActivity.java @@ -6,8 +6,10 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; +import android.widget.ImageButton; import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.Switch; @@ -18,10 +20,13 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import java.util.Locale; + public class SettingsActivity extends AppCompatActivity { private TextView saveLocation; private TextView readLocation; + private TextView timestampStep; private Switch threeDigitMillisecondsSwitch; private RadioButton light, dark, darker; @@ -33,7 +38,7 @@ public class SettingsActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { preferences = getSharedPreferences("LRC Editor Preferences", MODE_PRIVATE); - String theme = preferences.getString("current_theme", "light"); + String theme = preferences.getString(Constants.THEME_PREFERENCE, "light"); if (theme.equals("dark")) { isDarkTheme = true; setTheme(R.style.AppThemeDark); @@ -60,11 +65,15 @@ protected void onCreate(Bundle savedInstanceState) { saveLocation = findViewById(R.id.save_location); readLocation = findViewById(R.id.read_location); + timestampStep = findViewById(R.id.timestamp_step); + timestampStep.setText( + String.format(Locale.getDefault(), "%d ms", preferences.getInt(Constants.TIMESTAMP_STEP_AMOUNT_PREFERENCE, 100))); + threeDigitMillisecondsSwitch = findViewById(R.id.three_digit_milliseconds_switch); - threeDigitMillisecondsSwitch.setChecked(preferences.getBoolean("three_digit_milliseconds", false)); + threeDigitMillisecondsSwitch.setChecked(preferences.getBoolean(Constants.THREE_DIGIT_MILLISECONDS_PREFERENCE, false)); threeDigitMillisecondsSwitch.setOnCheckedChangeListener((compoundButton, checked) -> { SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("three_digit_milliseconds", checked); + editor.putBoolean(Constants.THREE_DIGIT_MILLISECONDS_PREFERENCE, checked); editor.apply(); }); @@ -92,11 +101,11 @@ protected void onCreate(Bundle savedInstanceState) { SharedPreferences.Editor editor = preferences.edit(); if (checkedId == light.getId()) { - editor.putString("current_theme", "light"); + editor.putString(Constants.THEME_PREFERENCE, "light"); } else if (checkedId == dark.getId()) { - editor.putString("current_theme", "dark"); + editor.putString(Constants.THEME_PREFERENCE, "dark"); } else if (checkedId == darker.getId()) { - editor.putString("current_theme", "darker"); + editor.putString(Constants.THEME_PREFERENCE, "darker"); } else { Toast.makeText(getApplicationContext(), getString(R.string.unexpected_error_message), Toast.LENGTH_SHORT).show(); return; @@ -107,12 +116,12 @@ protected void onCreate(Bundle savedInstanceState) { recreate(); }); - String location = preferences.getString("saveLocation", Constants.defaultLocation); + String location = preferences.getString(Constants.SAVE_LOCATION_PREFERENCE, Constants.defaultLocation); saveLocation.setText(location); - location = preferences.getString("readLocation", Constants.defaultLocation); + location = preferences.getString(Constants.READ_LOCATION_PREFERENCE, Constants.defaultLocation); readLocation.setText(location); - if (preferences.getString("lrceditor_purchased", "").equals("Y")) { + if (preferences.getString(Constants.PURCHASED_PREFERENCE, "").equals("Y")) { TextView themeTitle = findViewById(R.id.theme_title); themeGroup = findViewById(R.id.theme_group); @@ -145,9 +154,59 @@ public void changeSaveLocation(View view) { } } - public void showThreeDigitMillisecondsHelp(View view) { + public void adjustTimestampStep(View v) { + LayoutInflater inflater = this.getLayoutInflater(); + final View view = inflater.inflate(R.layout.dialog_adjust, null); + final TextView title = view.findViewById(R.id.title); + title.setVisibility(View.GONE); + final TextView timestamp = view.findViewById(R.id.content); + timestamp.setText( + String.format(Locale.getDefault(), "%d ms", preferences.getInt(Constants.TIMESTAMP_STEP_AMOUNT_PREFERENCE, 100))); + + ImageButton increase = view.findViewById(R.id.increase_button); + increase.setOnClickListener(view1 -> { + String timestampStepVal = timestamp.getText().toString(); + int value = Integer.parseInt(timestampStepVal.substring(0, timestampStepVal.length() - 3)); + value += 10; + value = Math.min(value, 200); + + timestamp.setText( + String.format(Locale.getDefault(), "%d ms", value)); + }); + + ImageButton decrease = view.findViewById(R.id.decrease_button); + decrease.setOnClickListener(view1 -> { + String timestampStepVal = timestamp.getText().toString(); + int value = Integer.parseInt(timestampStepVal.substring(0, timestampStepVal.length() - 3)); + value -= 10; + value = Math.max(value, 10); + + timestamp.setText( + String.format(Locale.getDefault(), "%d ms", value)); + }); + new AlertDialog.Builder(this) - .setMessage(R.string.three_digit_milliseconds_help) + .setView(view) + .setTitle(R.string.timestamp_step_amount_prompt) + .setPositiveButton(getString(R.string.adjust), (dialog1, which) -> { + String timestampStepVal = timestamp.getText().toString(); + int value = Integer.parseInt(timestampStepVal.substring(0, timestampStepVal.length() - 3)); + + SharedPreferences.Editor editor = preferences.edit(); + editor.putInt(Constants.TIMESTAMP_STEP_AMOUNT_PREFERENCE, value); + editor.apply(); + + timestampStep.setText(timestampStepVal); + }) + .setNegativeButton(getString(R.string.cancel), null) + .setCancelable(false) + .create() + .show(); + } + + public void showTimestampStepHelp(View view) { + new AlertDialog.Builder(this) + .setMessage(R.string.timestamp_step_help) .setNeutralButton(getString(R.string.ok), null) .create() .show(); @@ -157,6 +216,14 @@ public void toggleThreeDigitMillisecondSwitch(View view) { threeDigitMillisecondsSwitch.toggle(); } + public void showThreeDigitMillisecondsHelp(View view) { + new AlertDialog.Builder(this) + .setMessage(R.string.three_digit_milliseconds_help) + .setNeutralButton(getString(R.string.ok), null) + .create() + .show(); + } + @Override public void onActivityResult(int requestCode, int resultCode, Intent resultData) { super.onActivityResult(requestCode, resultCode, resultData); @@ -169,7 +236,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent resultData) String realPath = FileUtil.getFullPathFromTreeUri(uri, this); - editor.putString("saveLocation", realPath); + editor.putString(Constants.SAVE_LOCATION_PREFERENCE, realPath); try { editor.putString("saveUri", uri.toString()); } catch (ArrayIndexOutOfBoundsException ignored) { @@ -198,7 +265,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent resultData) String realPath = FileUtil.getFullPathFromTreeUri(uri, this); - editor.putString("readLocation", realPath); + editor.putString(Constants.READ_LOCATION_PREFERENCE, realPath); try { editor.putString("readUri", uri.toString()); } catch (ArrayIndexOutOfBoundsException ignored) { diff --git a/app/src/main/res/layout/activity_finalize.xml b/app/src/main/res/layout/activity_finalize.xml index 91424b1..699449c 100644 --- a/app/src/main/res/layout/activity_finalize.xml +++ b/app/src/main/res/layout/activity_finalize.xml @@ -134,6 +134,31 @@ + + + + + + + + + + + + + + + + + + + + +