Skip to content

Commit

Permalink
Timestamp step amount setting, LRC creator metadata
Browse files Browse the repository at this point in the history
Fix for the crash introduced in the previous version when reading certain LRC files, some other changes and tweaks
  • Loading branch information
Spikatrix committed Jul 22, 2020
1 parent 3fee517 commit 96d3f26
Show file tree
Hide file tree
Showing 35 changed files with 1,013 additions and 835 deletions.
2 changes: 1 addition & 1 deletion app/src/fdroid/java/com/cg/lrceditor/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion app/src/fdroid/res/values-de/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="view_the_app_on_f_droid">Sehen Sie sich die App auf F-Droid an</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/fdroid/res/values-in/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="view_the_app_on_f_droid">Lihat aplikasi di F-Droid</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/fdroid/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="view_the_app_on_f_droid">Wyświetl aplikację na F-Droid</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/fdroid/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="view_the_app_on_f_droid">Ver a aplicação no F-Droid</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/fdroid/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="view_the_app_on_f_droid">在F-Droid上查看应用</string>
</resources>
</resources>
2 changes: 1 addition & 1 deletion app/src/fdroid/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="view_the_app_on_f_droid">View the app on F-Droid</string>
</resources>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/java/com/cg/lrceditor/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/cg/lrceditor/CreateActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
88 changes: 49 additions & 39 deletions app/src/main/java/com/cg/lrceditor/EditorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -105,15 +106,15 @@ public class EditorActivity extends AppCompatActivity implements LyricListAdapte
@Override
public void run() {
if (!isPlaying) {
flasher.postDelayed(this, 30);
flasher.postDelayed(this, 35);
return;
}

int first = linearLayoutManager.findFirstVisibleItemPosition();
int last = linearLayoutManager.findLastVisibleItemPosition();

if (first == -1 || last == -1) {
flasher.postDelayed(this, 30);
flasher.postDelayed(this, 35);
return;
}

Expand All @@ -139,7 +140,7 @@ public void run() {
}
}

flasher.postDelayed(this, 30);
flasher.postDelayed(this, 35);
}
};

Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -254,7 +257,7 @@ protected void onCreate(Bundle savedInstanceState) {
Timestamp[] timestamps = r.getTimestamps();
ArrayList<LyricItem> lyricData = populateDataSet(lyrics, timestamps, false);

songMetaData = r.getSongMetaData();
metadata = r.getMetadata();
lrcFileName = FileUtil.getFileName(ctx, intent.getData());

adapter = new LyricListAdapter(ctx, lyricData, isDarkTheme);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand All @@ -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]) {
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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) -> {
Expand All @@ -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() {
Expand Down Expand Up @@ -1480,7 +1490,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
Intent intent = new Intent(this, FinalizeActivity.class);
intent.putExtra("LYRIC DATA", (ArrayList<LyricItem>) 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);

Expand Down
34 changes: 21 additions & 13 deletions app/src/main/java/com/cg/lrceditor/FinalizeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class FinalizeActivity extends AppCompatActivity {
private EditText artistName;
private EditText albumName;
private EditText composerName;
private EditText creatorName;

private TextView statusTextView;

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -113,7 +114,7 @@ protected void onCreate(Bundle savedInstanceState) {

Intent intent = getIntent();
lyricData = (ArrayList<LyricItem>) 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");
Expand All @@ -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());
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 96d3f26

Please sign in to comment.