Skip to content

Commit

Permalink
Add ability to re-tag ID3v2.2 to ID3v2.4. Fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaned1as committed Sep 30, 2017
1 parent ddb18b5 commit cffdec1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/src/main/java/com/kanedias/vanilla/audiotag/PluginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
import org.jaudiotagger.audio.generic.Utils;
import org.jaudiotagger.tag.*;
import org.jaudiotagger.tag.id3.AbstractID3v2Tag;
import org.jaudiotagger.tag.id3.valuepair.ImageFormats;
import org.jaudiotagger.tag.images.AndroidArtwork;
import org.jaudiotagger.tag.images.Artwork;
import org.jaudiotagger.tag.reference.ID3V2Version;
import org.jaudiotagger.tag.reference.PictureTypes;

import java.io.File;
Expand Down Expand Up @@ -253,6 +255,19 @@ public boolean loadFile() {
return true;
}

/**
* upgrades ID3v2.x tag to ID3v2.4 for loaded file.
* Call this method only if you know exactly that file contains ID3 tag.
*/
public void upgradeID3v2() {
mTag = mAudioFile.convertID3Tag((AbstractID3v2Tag) mTag, ID3V2Version.ID3_V24);
mAudioFile.setTag(mTag);
writeFile();
}

/**
* Writes file to backing filesystem provider, this may be either SAF-managed sdcard or internal storage.
*/
public void writeFile() {
if (SafUtils.isSafNeeded(mAudioFile.getFile())) {
if (mPrefs.contains(PREF_SDCARD_URI)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
package com.kanedias.vanilla.audiotag;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.support.annotation.NonNull;
Expand All @@ -43,6 +44,7 @@
import org.jaudiotagger.tag.FieldDataInvalidException;
import org.jaudiotagger.tag.FieldKey;
import org.jaudiotagger.tag.Tag;
import org.jaudiotagger.tag.id3.ID3v22Tag;

import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static com.kanedias.vanilla.plugins.PluginConstants.*;
Expand Down Expand Up @@ -82,6 +84,7 @@ public void onServiceConnected(ComponentName name, IBinder service) {
mService = ((PluginService.PluginBinder) service).getService();
mTag = mService.getTag();
fillInitialValues();
miscellaneousChecks();
}

@Override
Expand Down Expand Up @@ -203,6 +206,27 @@ private void fillInitialValues() {
mAlbumEdit.setText(mTag.getFirst(FieldKey.ALBUM));
}

/**
* Miscellaneous checks, e.g. re-tag requests etc.
*/
private void miscellaneousChecks() {
// check we need a re-tag
if (mTag instanceof ID3v22Tag) {
new AlertDialog.Builder(this)
.setTitle(R.string.re_tag)
.setMessage(R.string.id3_v22_to_v24)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mService.upgradeID3v2();
mTag = mService.getTag(); // tag was updated, refresh it from service
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
}

/**
* We're the good guys, we catch it back from {@link PluginUtils#checkAndRequestPermissions(Activity, String)} here.
* So, if user declined our request, just close the activity entirely.
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
<string name="file_written_successfully">File written successfully!</string>
<string name="invalid_tag_requested">Invalid tag requested</string>
<string name="invalid_artwork_provided">Invalid artwork provided</string>
<string name="re_tag">Re-tag</string>
<string name="id3_v22_to_v24">Do you want to re-tag ID3 v2.2 to v2.4 in this file for better compatibility?</string>
</resources>

0 comments on commit cffdec1

Please sign in to comment.