diff --git a/app/src/main/java/com/danielkim/soundrecorder/DBHelper.java b/app/src/main/java/com/danielkim/soundrecorder/DBHelper.java deleted file mode 100644 index 6f0bb7a3..00000000 --- a/app/src/main/java/com/danielkim/soundrecorder/DBHelper.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.danielkim.soundrecorder; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.provider.BaseColumns; - -import com.danielkim.soundrecorder.listeners.OnDatabaseChangedListener; - -import java.util.Comparator; - -/** - * Created by Daniel on 12/29/2014. - */ -public class DBHelper extends SQLiteOpenHelper { - private Context mContext; - - private static final String LOG_TAG = "DBHelper"; - - private static OnDatabaseChangedListener mOnDatabaseChangedListener; - - public static final String DATABASE_NAME = "saved_recordings.db"; - private static final int DATABASE_VERSION = 1; - - public static abstract class DBHelperItem implements BaseColumns { - public static final String TABLE_NAME = "saved_recordings"; - - public static final String COLUMN_NAME_RECORDING_NAME = "recording_name"; - public static final String COLUMN_NAME_RECORDING_FILE_PATH = "file_path"; - public static final String COLUMN_NAME_RECORDING_LENGTH = "length"; - public static final String COLUMN_NAME_TIME_ADDED = "time_added"; - } - - private static final String TEXT_TYPE = " TEXT"; - private static final String COMMA_SEP = ","; - private static final String SQL_CREATE_ENTRIES = - "CREATE TABLE " + DBHelperItem.TABLE_NAME + " (" + - DBHelperItem._ID + " INTEGER PRIMARY KEY" + COMMA_SEP + - DBHelperItem.COLUMN_NAME_RECORDING_NAME + TEXT_TYPE + COMMA_SEP + - DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH + TEXT_TYPE + COMMA_SEP + - DBHelperItem.COLUMN_NAME_RECORDING_LENGTH + " INTEGER " + COMMA_SEP + - DBHelperItem.COLUMN_NAME_TIME_ADDED + " INTEGER " + ")"; - - @SuppressWarnings("unused") - private static final String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS " + DBHelperItem.TABLE_NAME; - - @Override - public void onCreate(SQLiteDatabase db) { - db.execSQL(SQL_CREATE_ENTRIES); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - - } - - public DBHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - mContext = context; - } - - public static void setOnDatabaseChangedListener(OnDatabaseChangedListener listener) { - mOnDatabaseChangedListener = listener; - } - - public RecordingItem getItemAt(int position) { - SQLiteDatabase db = getReadableDatabase(); - String[] projection = { - DBHelperItem._ID, - DBHelperItem.COLUMN_NAME_RECORDING_NAME, - DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH, - DBHelperItem.COLUMN_NAME_RECORDING_LENGTH, - DBHelperItem.COLUMN_NAME_TIME_ADDED - }; - Cursor c = db.query(DBHelperItem.TABLE_NAME, projection, null, null, null, null, null); - if (c.moveToPosition(position)) { - RecordingItem item = new RecordingItem(); - item.setId(c.getInt(c.getColumnIndex(DBHelperItem._ID))); - item.setName(c.getString(c.getColumnIndex(DBHelperItem.COLUMN_NAME_RECORDING_NAME))); - item.setFilePath(c.getString(c.getColumnIndex(DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH))); - item.setLength(c.getInt(c.getColumnIndex(DBHelperItem.COLUMN_NAME_RECORDING_LENGTH))); - item.setTime(c.getLong(c.getColumnIndex(DBHelperItem.COLUMN_NAME_TIME_ADDED))); - c.close(); - return item; - } - return null; - } - - public void removeItemWithId(int id) { - SQLiteDatabase db = getWritableDatabase(); - String[] whereArgs = { String.valueOf(id) }; - db.delete(DBHelperItem.TABLE_NAME, "_ID=?", whereArgs); - } - - public int getCount() { - SQLiteDatabase db = getReadableDatabase(); - String[] projection = { DBHelperItem._ID }; - Cursor c = db.query(DBHelperItem.TABLE_NAME, projection, null, null, null, null, null); - int count = c.getCount(); - c.close(); - return count; - } - - public Context getContext() { - return mContext; - } - - public class RecordingComparator implements Comparator { - public int compare(RecordingItem item1, RecordingItem item2) { - Long o1 = item1.getTime(); - Long o2 = item2.getTime(); - return o2.compareTo(o1); - } - } - - public long addRecording(String recordingName, String filePath, long length) { - - SQLiteDatabase db = getWritableDatabase(); - ContentValues cv = new ContentValues(); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_NAME, recordingName); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH, filePath); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_LENGTH, length); - cv.put(DBHelperItem.COLUMN_NAME_TIME_ADDED, System.currentTimeMillis()); - long rowId = db.insert(DBHelperItem.TABLE_NAME, null, cv); - - if (mOnDatabaseChangedListener != null) { - mOnDatabaseChangedListener.onNewDatabaseEntryAdded(); - } - - return rowId; - } - - public void renameItem(RecordingItem item, String recordingName, String filePath) { - SQLiteDatabase db = getWritableDatabase(); - ContentValues cv = new ContentValues(); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_NAME, recordingName); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH, filePath); - db.update(DBHelperItem.TABLE_NAME, cv, - DBHelperItem._ID + "=" + item.getId(), null); - - if (mOnDatabaseChangedListener != null) { - mOnDatabaseChangedListener.onDatabaseEntryRenamed(); - } - } - - public long restoreRecording(RecordingItem item) { - SQLiteDatabase db = getWritableDatabase(); - ContentValues cv = new ContentValues(); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_NAME, item.getName()); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_FILE_PATH, item.getFilePath()); - cv.put(DBHelperItem.COLUMN_NAME_RECORDING_LENGTH, item.getLength()); - cv.put(DBHelperItem.COLUMN_NAME_TIME_ADDED, item.getTime()); - cv.put(DBHelperItem._ID, item.getId()); - long rowId = db.insert(DBHelperItem.TABLE_NAME, null, cv); - if (mOnDatabaseChangedListener != null) { - //mOnDatabaseChangedListener.onNewDatabaseEntryAdded(); - } - return rowId; - } -} diff --git a/app/src/main/java/com/danielkim/soundrecorder/RecordingItem.java b/app/src/main/java/com/danielkim/soundrecorder/RecordingItem.java index 5c4b7705..bbda3b04 100644 --- a/app/src/main/java/com/danielkim/soundrecorder/RecordingItem.java +++ b/app/src/main/java/com/danielkim/soundrecorder/RecordingItem.java @@ -1,15 +1,21 @@ package com.danielkim.soundrecorder; -import android.os.Parcel; -import android.os.Parcelable; +import android.media.MediaMetadataRetriever; +import android.util.Log; + +import java.io.File; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; /** * Created by Daniel on 12/30/2014. */ -public class RecordingItem implements Parcelable { +public class RecordingItem { + private static final String LOG_TAG = "RecordingItem"; private String mName; // file name private String mFilePath; //file path - private int mId; //id in database private int mLength; // length of recording in seconds private long mTime; // date/time of the recording @@ -17,12 +23,26 @@ public RecordingItem() { } - public RecordingItem(Parcel in) { - mName = in.readString(); - mFilePath = in.readString(); - mId = in.readInt(); - mLength = in.readInt(); - mTime = in.readLong(); + public RecordingItem(String filePath) { + mFilePath = filePath; + MediaMetadataRetriever m = new MediaMetadataRetriever(); + m.setDataSource(mFilePath); + mName = new File(mFilePath).getName(); + mLength = Integer.parseInt(m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)); + String date_str = m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DATE); + try { + Date date = DateFormat.getDateTimeInstance().parse(date_str); + mTime = date.getTime(); + } catch (ParseException e) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd'T'HHmmss.SSS'Z'"); + try { + sdf.parse(date_str); + mTime = sdf.getCalendar().getTimeInMillis(); + } catch (ParseException _e) { + Log.e(LOG_TAG, "can't parse date: " + date_str); + mTime = 0; + } + } } public String getFilePath() { @@ -31,61 +51,18 @@ public String getFilePath() { public void setFilePath(String filePath) { mFilePath = filePath; + mName = new File(mFilePath).getName(); } public int getLength() { return mLength; } - public void setLength(int length) { - mLength = length; - } - - public int getId() { - return mId; - } - - public void setId(int id) { - mId = id; - } - public String getName() { return mName; } - public void setName(String name) { - mName = name; - } - public long getTime() { return mTime; } - - public void setTime(long time) { - mTime = time; - } - - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - public RecordingItem createFromParcel(Parcel in) { - return new RecordingItem(in); - } - - public RecordingItem[] newArray(int size) { - return new RecordingItem[size]; - } - }; - - @Override - public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mId); - dest.writeInt(mLength); - dest.writeLong(mTime); - dest.writeString(mFilePath); - dest.writeString(mName); - } - - @Override - public int describeContents() { - return 0; - } } \ No newline at end of file diff --git a/app/src/main/java/com/danielkim/soundrecorder/RecordingService.java b/app/src/main/java/com/danielkim/soundrecorder/RecordingService.java index a8b36a18..4ed52c60 100644 --- a/app/src/main/java/com/danielkim/soundrecorder/RecordingService.java +++ b/app/src/main/java/com/danielkim/soundrecorder/RecordingService.java @@ -4,13 +4,15 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.media.MediaRecorder; +import android.net.Uri; import android.os.Environment; import android.os.IBinder; -import android.preference.PreferenceManager; +import android.provider.MediaStore; import android.support.v4.app.NotificationCompat; import android.util.Log; import android.widget.Toast; @@ -36,10 +38,7 @@ public class RecordingService extends Service { private MediaRecorder mRecorder = null; - private DBHelper mDatabase; - private long mStartingTimeMillis = 0; - private long mElapsedMillis = 0; private int mElapsedSeconds = 0; private OnTimerChangedListener onTimerChangedListener = null; private static final SimpleDateFormat mTimerFormat = new SimpleDateFormat("mm:ss", Locale.getDefault()); @@ -59,7 +58,7 @@ public interface OnTimerChangedListener { @Override public void onCreate() { super.onCreate(); - mDatabase = new DBHelper(getApplicationContext()); + mTimer = new Timer(); } @Override @@ -100,46 +99,75 @@ public void startRecording() { //startForeground(1, createNotification()); } catch (IOException e) { - Log.e(LOG_TAG, "prepare() failed"); + Log.e(LOG_TAG, "prepare() failed", e); } } public void setFileNameAndPath(){ int count = 0; - File f; + String defaultName = getString(R.string.default_file_name); + File parent = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + + "/" + getString(R.string.storage_dir)); - do{ - count++; - - mFileName = getString(R.string.default_file_name) - + "_" + (mDatabase.getCount() + count) + ".mp4"; - mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath(); - mFilePath += "/SoundRecorder/" + mFileName; + for (File file : parent.listFiles()) { + if (file.isDirectory()) { + continue; + } + String name = file.getName(); + if (!name.startsWith(getString(R.string.default_file_name)) || !name.endsWith(".mp4")) { + continue; + } + String number = file.getName().substring((defaultName + "_").length(), + name.length() - ".mp4".length()); + try { + count = Math.max(count, Integer.parseInt(number)); + } catch (NumberFormatException nfe) { + Log.d(LOG_TAG, "unexpected file name: " + name); + continue; + } + } - f = new File(mFilePath); - }while (f.exists() && !f.isDirectory()); + mFilePath = parent + "/" + defaultName + "_" + (count + 1) + ".mp4"; } public void stopRecording() { - mRecorder.stop(); - mElapsedMillis = (System.currentTimeMillis() - mStartingTimeMillis); - mRecorder.release(); - Toast.makeText(this, getString(R.string.toast_recording_finish) + " " + mFilePath, Toast.LENGTH_LONG).show(); - //remove notification if (mIncrementTimerTask != null) { mIncrementTimerTask.cancel(); mIncrementTimerTask = null; + mTimer.purge(); } - mRecorder = null; - - try { - mDatabase.addRecording(mFileName, mFilePath, mElapsedMillis); - - } catch (Exception e){ - Log.e(LOG_TAG, "exception", e); + if (mRecorder != null) { + mRecorder.stop(); + mRecorder.reset(); + long mElapsedMillis = (System.currentTimeMillis() - mStartingTimeMillis); + mRecorder.release(); + mRecorder = null; + Toast.makeText(this, getString(R.string.toast_recording_finish) + " " + mFilePath, Toast.LENGTH_LONG).show(); + + String mimeType = "audio/mp4"; + + File outFile = new File(mFilePath); + long fileSize = outFile.length(); + + ContentValues values = new ContentValues(); + values.put(MediaStore.MediaColumns.DATA, mFilePath); + values.put(MediaStore.MediaColumns.TITLE, mFileName); + values.put(MediaStore.MediaColumns.SIZE, fileSize); + values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType); + values.put(MediaStore.MediaColumns.DATE_ADDED, System.currentTimeMillis() / 1000); + values.put(MediaStore.Audio.Media.ARTIST, getString(R.string.app_name)); + values.put(MediaStore.Audio.Media.DURATION, mElapsedMillis); + + Uri uri = MediaStore.Audio.Media.getContentUriForPath(mFilePath); + getContentResolver().insert(uri, values); + + } else { + Log.e(LOG_TAG, "MediaRecorder not initialized"); } + + stopForeground(true); } private void startTimer() { diff --git a/app/src/main/java/com/danielkim/soundrecorder/adapters/FileViewerAdapter.java b/app/src/main/java/com/danielkim/soundrecorder/adapters/FileViewerAdapter.java index 1d1418cf..3bc44576 100644 --- a/app/src/main/java/com/danielkim/soundrecorder/adapters/FileViewerAdapter.java +++ b/app/src/main/java/com/danielkim/soundrecorder/adapters/FileViewerAdapter.java @@ -6,10 +6,12 @@ import android.content.Intent; import android.net.Uri; import android.os.Environment; +import android.os.FileObserver; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentTransaction; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; +import android.text.format.DateUtils; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -17,47 +19,71 @@ import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; -import android.text.format.DateUtils; -import com.danielkim.soundrecorder.DBHelper; import com.danielkim.soundrecorder.R; import com.danielkim.soundrecorder.RecordingItem; import com.danielkim.soundrecorder.fragments.PlaybackFragment; -import com.danielkim.soundrecorder.listeners.OnDatabaseChangedListener; import java.io.File; -import java.util.Locale; import java.util.concurrent.TimeUnit; import java.util.ArrayList; /** * Created by Daniel on 12/29/2014. */ -public class FileViewerAdapter extends RecyclerView.Adapter - implements OnDatabaseChangedListener{ +public class FileViewerAdapter extends RecyclerView.Adapter { private static final String LOG_TAG = "FileViewerAdapter"; - private DBHelper mDatabase; - - RecordingItem item; Context mContext; LinearLayoutManager llm; + private final FileObserver observer; + private final String storagePath; + private final ArrayList storage = new ArrayList<>(); + public FileViewerAdapter(Context context, LinearLayoutManager linearLayoutManager) { super(); mContext = context; - mDatabase = new DBHelper(mContext); - mDatabase.setOnDatabaseChangedListener(this); + storagePath = Environment.getExternalStorageDirectory() + "/" + context.getString(R.string.storage_dir); + + observer = new FileObserver(storagePath) { + @Override + public void onEvent(int event, String file) { + if (file == null) return; + switch (event) { + case FileObserver.DELETE: + case FileObserver.MOVED_FROM: + removedFile(file); + break; + case FileObserver.CREATE: + case FileObserver.CLOSE_WRITE: + case FileObserver.MOVED_TO: + addedFile(file); + break; + } + } + }; + observer.startWatching(); + File storageDir = new File(storagePath); + + String filenames[] = storageDir.list(); + if (filenames != null) { + for (String filename : filenames) { + File r = new File(storagePath, filename); + storage.add(new RecordingItem(storagePath + "/" + filename)); + } + } + llm = linearLayoutManager; } @Override public void onBindViewHolder(final RecordingsViewHolder holder, int position) { - item = getItem(position); - long itemDuration = item.getLength(); + RecordingItem item = storage.get(position); + long itemDuration = item.getLength(); long minutes = TimeUnit.MILLISECONDS.toMinutes(itemDuration); long seconds = TimeUnit.MILLISECONDS.toSeconds(itemDuration) - TimeUnit.MINUTES.toSeconds(minutes); @@ -78,7 +104,7 @@ public void onBindViewHolder(final RecordingsViewHolder holder, int position) { public void onClick(View view) { try { PlaybackFragment playbackFragment = - new PlaybackFragment().newInstance(getItem(holder.getPosition())); + new PlaybackFragment().newInstance(storage.get(holder.getPosition())); FragmentTransaction transaction = ((FragmentActivity) mContext) .getSupportFragmentManager() @@ -103,7 +129,6 @@ public boolean onLongClick(View v) { final CharSequence[] items = entrys.toArray(new CharSequence[entrys.size()]); - // File delete confirm AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(mContext.getString(R.string.dialog_title_options)); @@ -163,69 +188,59 @@ public RecordingsViewHolder(View v) { @Override public int getItemCount() { - return mDatabase.getCount(); - } - - public RecordingItem getItem(int position) { - return mDatabase.getItemAt(position); + return storage.size(); } - @Override - public void onNewDatabaseEntryAdded() { + private void addedFile(String filename) { //item added to top of the list + storage.add(new RecordingItem(storagePath + "/" + filename)); notifyItemInserted(getItemCount() - 1); llm.scrollToPosition(getItemCount() - 1); } - @Override - //TODO - public void onDatabaseEntryRenamed() { - + private void removedFile(String filename) { + String fullPath = storagePath + "/" + filename; + for (int i = 0; i < storage.size(); i++) { + if (storage.get(i).getFilePath().equals(fullPath)) { + storage.remove(i); + notifyItemRemoved(i); + return; + } + } } - public void remove(int position) { - //remove item from database, recyclerview and storage + private void remove(int position) { - //delete file from storage - File file = new File(getItem(position).getFilePath()); + String filepath = storage.get(position).getFilePath(); + File file = new File(filepath); + String filename = file.getName(); file.delete(); - Toast.makeText( mContext, String.format( mContext.getString(R.string.toast_file_delete), - getItem(position).getName() + filename ), Toast.LENGTH_SHORT ).show(); - - mDatabase.removeItemWithId(getItem(position).getId()); - notifyItemRemoved(position); } - //TODO - public void removeOutOfApp(String filePath) { - //user deletes a saved recording out of the application through another application - } public void rename(int position, String name) { - //rename a file - - String mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath(); - mFilePath += "/SoundRecorder/" + name; + String mFilePath = storagePath + "/" + name; File f = new File(mFilePath); - if (f.exists() && !f.isDirectory()) { + if (f.exists()) { //file name is not unique, cannot rename file. Toast.makeText(mContext, String.format(mContext.getString(R.string.toast_file_exists), name), Toast.LENGTH_SHORT).show(); } else { - //file name is unique, rename file - File oldFilePath = new File(getItem(position).getFilePath()); - oldFilePath.renameTo(f); - mDatabase.renameItem(getItem(position), name, mFilePath); + RecordingItem r = storage.get(position); + File new_f = new File(r.getFilePath()); + new_f.renameTo(f); + r.setFilePath(mFilePath); notifyItemChanged(position); } } @@ -233,7 +248,7 @@ public void rename(int position, String name) { public void shareFileDialog(int position) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); - shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(getItem(position).getFilePath()))); + shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(storage.get(position).getFilePath()))); shareIntent.setType("audio/mp4"); mContext.startActivity(Intent.createChooser(shareIntent, mContext.getText(R.string.send_to))); } @@ -284,14 +299,7 @@ public void deleteFileDialog (final int position) { confirmDelete.setPositiveButton(mContext.getString(R.string.dialog_action_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { - try { - //remove item from database, recyclerview, and storage - remove(position); - - } catch (Exception e) { - Log.e(LOG_TAG, "exception", e); - } - + remove(position); dialog.cancel(); } }); diff --git a/app/src/main/java/com/danielkim/soundrecorder/fragments/FileViewerFragment.java b/app/src/main/java/com/danielkim/soundrecorder/fragments/FileViewerFragment.java index bf29e7f0..e43c95e5 100644 --- a/app/src/main/java/com/danielkim/soundrecorder/fragments/FileViewerFragment.java +++ b/app/src/main/java/com/danielkim/soundrecorder/fragments/FileViewerFragment.java @@ -1,12 +1,10 @@ package com.danielkim.soundrecorder.fragments; import android.os.Bundle; -import android.os.FileObserver; import android.support.v4.app.Fragment; import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -19,9 +17,7 @@ */ public class FileViewerFragment extends Fragment{ private static final String ARG_POSITION = "position"; - private static final String LOG_TAG = "FileViewerFragment"; - private int position; private FileViewerAdapter mFileViewerAdapter; public static FileViewerFragment newInstance(int position) { @@ -36,8 +32,6 @@ public static FileViewerFragment newInstance(int position) { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - position = getArguments().getInt(ARG_POSITION); - observer.startWatching(); } @Override @@ -61,28 +55,6 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa return v; } - - FileObserver observer = - new FileObserver(android.os.Environment.getExternalStorageDirectory().toString() - + "/SoundRecorder") { - // set up a file observer to watch this directory on sd card - @Override - public void onEvent(int event, String file) { - if(event == FileObserver.DELETE){ - // user deletes a recording file out of the app - - String filePath = android.os.Environment.getExternalStorageDirectory().toString() - + "/SoundRecorder" + file + "]"; - - Log.d(LOG_TAG, "File deleted [" - + android.os.Environment.getExternalStorageDirectory().toString() - + "/SoundRecorder" + file + "]"); - - // remove file from database and recyclerview - mFileViewerAdapter.removeOutOfApp(filePath); - } - } - }; } diff --git a/app/src/main/java/com/danielkim/soundrecorder/fragments/PlaybackFragment.java b/app/src/main/java/com/danielkim/soundrecorder/fragments/PlaybackFragment.java index 09f12135..8ab9e7aa 100644 --- a/app/src/main/java/com/danielkim/soundrecorder/fragments/PlaybackFragment.java +++ b/app/src/main/java/com/danielkim/soundrecorder/fragments/PlaybackFragment.java @@ -30,7 +30,7 @@ public class PlaybackFragment extends DialogFragment{ private static final String LOG_TAG = "PlaybackFragment"; - private static final String ARG_ITEM = "recording_item"; + private static final String ARG_ITEM = "file_path"; private RecordingItem item; private Handler mHandler = new Handler(); @@ -53,7 +53,7 @@ public class PlaybackFragment extends DialogFragment{ public PlaybackFragment newInstance(RecordingItem item) { PlaybackFragment f = new PlaybackFragment(); Bundle b = new Bundle(); - b.putParcelable(ARG_ITEM, item); + b.putString(ARG_ITEM, item.getFilePath()); f.setArguments(b); return f; @@ -62,8 +62,8 @@ public PlaybackFragment newInstance(RecordingItem item) { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - item = getArguments().getParcelable(ARG_ITEM); - + String filePath = getArguments().getString(ARG_ITEM); + item = new RecordingItem(filePath); long itemDuration = item.getLength(); minutes = TimeUnit.MILLISECONDS.toMinutes(itemDuration); seconds = TimeUnit.MILLISECONDS.toSeconds(itemDuration) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5061b9dc..27edcab4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,6 +41,7 @@ My Recording Tap the button to start recording Recording + SoundRecorder Send to