From a4be707b9a0bf646fa684f0b26fd95e87e195e73 Mon Sep 17 00:00:00 2001 From: axel legue Date: Tue, 29 Jan 2019 02:48:45 +0100 Subject: [PATCH 1/4] Feature : Wip Drag and Drop Recordings items - Change the way we get the recordings items in RecyclerView - Change DatabaseListener for new entries from recyclerView to Fragment. - Add Multiple interface for touch event - Create a custom ItemTouchHelperCallback for handle drag and drop Issues #23 --- app/.gitignore | 137 +++++++++++++++++- app/src/main/AndroidManifest.xml | 1 + .../adapters/FileViewerAdapter.java | 118 +++++++++------ .../fragments/FileViewerFragment.java | 58 +++++++- .../listeners/ItemTouchHelperAdapter.java | 7 + .../listeners/ItemTouchHelperViewHolder.java | 7 + .../listeners/OnStartDragListener.java | 7 + .../SwapItemTouchHelperCallback.java | 44 ++++++ 8 files changed, 328 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperAdapter.java create mode 100644 app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperViewHolder.java create mode 100644 app/src/main/java/by/naxa/soundrecorder/listeners/OnStartDragListener.java create mode 100644 app/src/main/java/by/naxa/soundrecorder/listeners/SwapItemTouchHelperCallback.java diff --git a/app/.gitignore b/app/.gitignore index 09937e99..5559a70c 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,4 +1,135 @@ -/build -/release -# Fabric plugin + +# Created by https://www.gitignore.io/api/androidstudio +# Edit at https://www.gitignore.io/?templates=androidstudio + +### AndroidStudio ### +# Covers files to be ignored for android development using Android Studio. + +# Built application files +*.apk +*.ap_ + +# Files for the ART/Dalvik VM +*.dex + +# Java class files +*.class + +# Generated files +bin/ +gen/ +out/ + +# Gradle files +.gradle +.gradle/ +build/ + +# Signing files +.signing/ + +# Local configuration file (sdk path, etc) +local.properties + +# Proguard folder generated by Eclipse +proguard/ + +# Log Files +*.log + +# Android Studio +/*/build/ +/*/local.properties +/*/out +/*/*/build +/*/*/production +captures/ +.navigation/ +*.ipr +*~ +*.swp + +# Android Patch +gen-external-apklibs + +# External native build folder generated in Android Studio 2.2 and later +.externalNativeBuild + +# NDK +obj/ + +# IntelliJ IDEA +*.iml +*.iws +/out/ + +# User-specific configurations +.idea/caches/ +.idea/libraries/ +.idea/shelf/ +.idea/workspace.xml +.idea/tasks.xml +.idea/.name +.idea/compiler.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/misc.xml +.idea/modules.xml +.idea/scopes/scope_settings.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml +.idea/datasources.xml +.idea/dataSources.ids +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml +.idea/assetWizardSettings.xml + +# OS-specific files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db + +# Legacy Eclipse project files +.classpath +.project +.cproject +.settings/ + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.war +*.ear + +# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) +hs_err_pid* + +## Plugin-specific files: + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Mongo Explorer plugin +.idea/mongoSettings.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties fabric.properties + +### AndroidStudio Patch ### + +!/gradle/wrapper/gradle-wrapper.jar + +# End of https://www.gitignore.io/api/androidstudio diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 543c1dcf..e3eab8fb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,7 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> + diff --git a/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java b/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java index 68b6623f..e1549f7b 100644 --- a/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java +++ b/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java @@ -9,6 +9,7 @@ import android.text.format.DateUtils; import android.util.Log; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; @@ -21,6 +22,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Collections; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -34,8 +36,10 @@ import by.naxa.soundrecorder.R; import by.naxa.soundrecorder.RecordingItem; import by.naxa.soundrecorder.fragments.PlaybackFragment; +import by.naxa.soundrecorder.listeners.ItemTouchHelperAdapter; import by.naxa.soundrecorder.listeners.OnDatabaseChangedListener; import by.naxa.soundrecorder.listeners.OnSingleClickListener; +import by.naxa.soundrecorder.listeners.OnStartDragListener; import by.naxa.soundrecorder.util.EventBroadcaster; import by.naxa.soundrecorder.util.Paths; import by.naxa.soundrecorder.util.TimeUtils; @@ -45,7 +49,7 @@ * Created by Daniel on 12/29/2014. */ public class FileViewerAdapter extends RecyclerView.Adapter - implements OnDatabaseChangedListener { + implements ItemTouchHelperAdapter { private static final String LOG_TAG = "FileViewerAdapter"; @@ -53,27 +57,36 @@ public class FileViewerAdapter extends RecyclerView.Adapter mRecordingItems; + private final OnStartDragListener mDragStartListener; + + public FileViewerAdapter( + Context context, + LinearLayoutManager linearLayoutManager, + ArrayList recordingItems, + OnStartDragListener dragListener) { - public FileViewerAdapter(Context context, LinearLayoutManager linearLayoutManager) { super(); mContext = context; mDatabase = new DBHelper(mContext); - DBHelper.setOnDatabaseChangedListener(this); + mDragStartListener = dragListener; + + mRecordingItems = recordingItems; llm = linearLayoutManager; } @Override - public void onBindViewHolder(@NonNull final RecordingsViewHolder holder, int position) { + public void onBindViewHolder(@NonNull final RecordingsViewHolder holder, final int position) { - RecordingItem item = getItem(position); - long itemDuration = item.getLength(); + final RecordingItem recordingItem = mRecordingItems.get(position); + long itemDuration = recordingItem.getLength(); - holder.vName.setText(item.getName()); + holder.vName.setText(recordingItem.getName()); holder.vLength.setText(TimeUtils.formatDuration(itemDuration)); holder.vDateAdded.setText( DateUtils.formatDateTime( mContext, - item.getTime(), + recordingItem.getTime(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NUMERIC_DATE | DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_YEAR ) ); @@ -84,7 +97,7 @@ public void onBindViewHolder(@NonNull final RecordingsViewHolder holder, int pos public void onSingleClick(View view) { try { PlaybackFragment playbackFragment = - new PlaybackFragment().newInstance(getItem(holder.getPosition())); + new PlaybackFragment().newInstance(recordingItem); FragmentTransaction transaction = ((FragmentActivity) mContext) .getSupportFragmentManager() @@ -116,11 +129,11 @@ public boolean onLongClick(View v) { builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { - shareFileDialog(holder.getPosition()); + shareFileDialog(recordingItem); } else if (item == 1) { - renameFileDialog(holder.getPosition()); + renameFileDialog(recordingItem, position); } else if (item == 2) { - deleteFileDialog(holder.getPosition()); + deleteFileDialog(recordingItem, position); } } }); @@ -138,6 +151,16 @@ public void onClick(DialogInterface dialog, int id) { return false; } }); + + holder.cardView.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) { + mDragStartListener.onStartDrag(holder); + } + return false; + } + }); } @Override @@ -153,6 +176,30 @@ public RecordingsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int vi return new RecordingsViewHolder(itemView); } + @Override + public boolean onItemMove(int fromPosition, int toPosition) { + + if (fromPosition < mRecordingItems.size() && toPosition < mRecordingItems.size()) { + if (fromPosition < toPosition) { + for (int i = fromPosition; i < toPosition; i++) { + Collections.swap(mRecordingItems, i, i + 1); + } + } else { + for (int i = fromPosition; i > toPosition; i--) { + Collections.swap(mRecordingItems, i, i - 1); + } + } + notifyItemMoved(fromPosition, toPosition); + } + return true; + } + + @Override + public void onItemDismiss(int position) { + mRecordingItems.remove(position); + notifyItemRemoved(position); + } + static class RecordingsViewHolder extends RecyclerView.ViewHolder { TextView vName; TextView vLength; @@ -170,35 +217,18 @@ static class RecordingsViewHolder extends RecyclerView.ViewHolder { @Override public int getItemCount() { - return mDatabase.getCount(); - } - - public RecordingItem getItem(int position) { - return mDatabase.getItemAt(position); - } - - @Override - public void onNewDatabaseEntryAdded() { - //item added to top of the list - notifyItemInserted(getItemCount() - 1); - llm.scrollToPosition(getItemCount() - 1); - } - - @Override - //TODO - public void onDatabaseEntryRenamed() { - + return mRecordingItems.size(); } - public void remove(int position) { + public void remove(RecordingItem recordingItem, int position) { //remove item from database, recyclerview and storage //delete file from storage - File file = new File(getItem(position).getFilePath()); + File file = new File(recordingItem.getFilePath()); if (!file.delete()) { Toast.makeText(mContext, String.format(mContext.getString(R.string.toast_file_delete_failed), - getItem(position).getName()), + recordingItem.getName()), Toast.LENGTH_LONG).show(); return; } @@ -207,12 +237,12 @@ public void remove(int position) { mContext, String.format( mContext.getString(R.string.toast_file_delete), - getItem(position).getName() + recordingItem.getName() ), Toast.LENGTH_SHORT ).show(); - mDatabase.removeItemWithId(getItem(position).getId()); + mDatabase.removeItemWithId(recordingItem.getId()); notifyItemRemoved(position); } @@ -224,7 +254,7 @@ public void removeOutOfApp(String filePath) { /** * rename a file */ - public void rename(int position, String name) { + public void rename(RecordingItem recordingItem, String name, int position) { final String mFilePath = Paths.combine( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC), Paths.SOUND_RECORDER_FOLDER, name); @@ -237,31 +267,31 @@ public void rename(int position, String name) { Toast.LENGTH_LONG).show(); } else { //file name is unique, rename file - File oldFilePath = new File(getItem(position).getFilePath()); + File oldFilePath = new File(recordingItem.getFilePath()); if (!oldFilePath.renameTo(f)) { Toast.makeText(mContext, String.format(mContext.getString(R.string.toast_file_rename_failed), name), Toast.LENGTH_LONG).show(); return; } - mDatabase.renameItem(getItem(position), name, mFilePath); + mDatabase.renameItem(recordingItem, name, mFilePath); notifyItemChanged(position); } } - private void shareFileDialog(int position) { + private void shareFileDialog(final RecordingItem recordingItem) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); final Uri uri = FileProvider.getUriForFile(mContext, BuildConfig.APPLICATION_ID + ".fileprovider", - new File(getItem(position).getFilePath())); + new File(recordingItem.getFilePath())); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); shareIntent.setType("audio/mp4"); mContext.startActivity(Intent.createChooser(shareIntent, mContext.getText(R.string.send_to))); } - private void renameFileDialog(final int position) { + private void renameFileDialog(final RecordingItem recordingItem, final int position) { // File rename dialog AlertDialog.Builder renameFileBuilder = new AlertDialog.Builder(mContext); @@ -280,7 +310,7 @@ public void onClick(DialogInterface dialog, int id) { if (editable == null) return; final String value = editable.toString().trim() + ".mp4"; - rename(position, value); + rename(recordingItem, value, position); } catch (Exception e) { if (Fabric.isInitialized()) Crashlytics.logException(e); Log.e(LOG_TAG, "exception", e); @@ -302,7 +332,7 @@ public void onClick(DialogInterface dialog, int id) { alert.show(); } - private void deleteFileDialog(final int position) { + private void deleteFileDialog(final RecordingItem recordingItem, final int position) { // File delete confirm AlertDialog.Builder confirmDelete = new AlertDialog.Builder(mContext); confirmDelete.setTitle(mContext.getString(R.string.dialog_title_delete)); @@ -313,7 +343,7 @@ private void deleteFileDialog(final int position) { public void onClick(DialogInterface dialog, int id) { try { //remove item from database, recyclerview, and storage - remove(position); + remove(recordingItem, position); } catch (Exception e) { Log.e(LOG_TAG, "exception", e); } diff --git a/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java b/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java index 0ec61c7b..0df10322 100644 --- a/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java +++ b/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java @@ -8,24 +8,37 @@ import android.view.View; import android.view.ViewGroup; +import java.util.ArrayList; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.DefaultItemAnimator; +import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import by.naxa.soundrecorder.DBHelper; import by.naxa.soundrecorder.R; +import by.naxa.soundrecorder.RecordingItem; import by.naxa.soundrecorder.adapters.FileViewerAdapter; +import by.naxa.soundrecorder.listeners.OnDatabaseChangedListener; +import by.naxa.soundrecorder.listeners.OnStartDragListener; +import by.naxa.soundrecorder.listeners.SwapItemTouchHelperCallback; import by.naxa.soundrecorder.util.Paths; /** * Created by Daniel on 12/23/2014. */ -public class FileViewerFragment extends Fragment { +public class FileViewerFragment extends Fragment implements OnDatabaseChangedListener, OnStartDragListener { private static final String LOG_TAG = "FileViewerFragment"; private FileViewerAdapter mFileViewerAdapter; + private ArrayList mRecordingItems; + private DBHelper mDatabase; + private LinearLayoutManager llm; + private ItemTouchHelper mItemTouchHelper; + public static FileViewerFragment newInstance() { FileViewerFragment f = new FileViewerFragment(); Bundle b = new Bundle(); @@ -50,23 +63,42 @@ public void onDestroy() { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_file_viewer, container, false); - + mDatabase = new DBHelper(getActivity()); + // instanciate new List for store recordingItems; + if (mRecordingItems == null) { + mRecordingItems = new ArrayList<>(); + } + DBHelper.setOnDatabaseChangedListener(this); + fillRecordingItemList(); RecyclerView mRecyclerView = v.findViewById(R.id.recyclerView); mRecyclerView.setHasFixedSize(true); //newest to oldest order (database stores from oldest to newest) - final LinearLayoutManager llm = new LinearLayoutManager( + llm = new LinearLayoutManager( getActivity(), RecyclerView.VERTICAL, true); llm.setStackFromEnd(true); + mFileViewerAdapter = new FileViewerAdapter(getActivity(), llm, mRecordingItems, this); + ItemTouchHelper.Callback callback = new SwapItemTouchHelperCallback(mFileViewerAdapter); + // Set Custome CallBack to ItemtoucheHelper + mItemTouchHelper = new ItemTouchHelper(callback); + // Link ItemTouchAdapter to Recyclerview + mItemTouchHelper.attachToRecyclerView(mRecyclerView); + mRecyclerView.setLayoutManager(llm); mRecyclerView.setItemAnimator(new DefaultItemAnimator()); - mFileViewerAdapter = new FileViewerAdapter(getActivity(), llm); mRecyclerView.setAdapter(mFileViewerAdapter); return v; } + private void fillRecordingItemList() { + mDatabase.getCount(); + for (int i = 0; i < mDatabase.getCount(); i++) { + mRecordingItems.add(mDatabase.getItemAt(i)); + } + } + @Override public void onDestroyView() { super.onDestroyView(); @@ -93,6 +125,24 @@ public void onEvent(int event, String file) { } } }; + + @Override + public void onNewDatabaseEntryAdded() { + fillRecordingItemList(); + mFileViewerAdapter.notifyItemInserted(mRecordingItems.size() - 1); + llm.scrollToPositionWithOffset(mRecordingItems.size() - 1, 0); + } + + @Override + //TODO + public void onDatabaseEntryRenamed() { + + } + + @Override + public void onStartDrag(RecyclerView.ViewHolder viewHolder) { + mItemTouchHelper.startDrag(viewHolder); + } } diff --git a/app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperAdapter.java b/app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperAdapter.java new file mode 100644 index 00000000..14e4bdf3 --- /dev/null +++ b/app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperAdapter.java @@ -0,0 +1,7 @@ +package by.naxa.soundrecorder.listeners; + +public interface ItemTouchHelperAdapter { + + boolean onItemMove(int fromPosition, int toPosition); + void onItemDismiss(int position); +} diff --git a/app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperViewHolder.java b/app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperViewHolder.java new file mode 100644 index 00000000..71c17779 --- /dev/null +++ b/app/src/main/java/by/naxa/soundrecorder/listeners/ItemTouchHelperViewHolder.java @@ -0,0 +1,7 @@ +package by.naxa.soundrecorder.listeners; + +public interface ItemTouchHelperViewHolder { + + void onItemSelected(); + void onItemClear(); +} diff --git a/app/src/main/java/by/naxa/soundrecorder/listeners/OnStartDragListener.java b/app/src/main/java/by/naxa/soundrecorder/listeners/OnStartDragListener.java new file mode 100644 index 00000000..7c5c3d78 --- /dev/null +++ b/app/src/main/java/by/naxa/soundrecorder/listeners/OnStartDragListener.java @@ -0,0 +1,7 @@ +package by.naxa.soundrecorder.listeners; + +import androidx.recyclerview.widget.RecyclerView; + +public interface OnStartDragListener { + void onStartDrag(RecyclerView.ViewHolder viewHolder); +} diff --git a/app/src/main/java/by/naxa/soundrecorder/listeners/SwapItemTouchHelperCallback.java b/app/src/main/java/by/naxa/soundrecorder/listeners/SwapItemTouchHelperCallback.java new file mode 100644 index 00000000..7449c629 --- /dev/null +++ b/app/src/main/java/by/naxa/soundrecorder/listeners/SwapItemTouchHelperCallback.java @@ -0,0 +1,44 @@ +package by.naxa.soundrecorder.listeners; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.RecyclerView; +import by.naxa.soundrecorder.adapters.FileViewerAdapter; + +public class SwapItemTouchHelperCallback extends ItemTouchHelper.Callback { + + private final FileViewerAdapter mFileViewerAdapter; + + public SwapItemTouchHelperCallback(FileViewerAdapter mFileViewerAdapter) { + this.mFileViewerAdapter = mFileViewerAdapter; + } + + @Override + public boolean isLongPressDragEnabled() { + return true; + } + + @Override + public boolean isItemViewSwipeEnabled() { + return true; + } + + @Override + public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) { + + int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; + int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END; + return makeMovementFlags(dragFlags,swipeFlags); + } + + @Override + public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) { + mFileViewerAdapter.onItemMove(viewHolder.getAdapterPosition(), target.getAdapterPosition()); + return true; + } + + @Override + public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) { + mFileViewerAdapter.onItemDismiss(viewHolder.getAdapterPosition()); + } +} From 6083d2191fd1bba054988fd499135a5a3ac74b2d Mon Sep 17 00:00:00 2001 From: axel legue Date: Wed, 30 Jan 2019 01:30:13 +0100 Subject: [PATCH 2/4] Feature : Wip Drag and Drop Recordings items - Update Rename item listener - Update the ReecyclerView properly when item renamed or deleted --- app/src/main/java/by/naxa/soundrecorder/DBHelper.java | 4 ++-- .../by/naxa/soundrecorder/adapters/FileViewerAdapter.java | 5 +++-- .../naxa/soundrecorder/fragments/FileViewerFragment.java | 8 ++++++-- .../listeners/OnDatabaseChangedListener.java | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/by/naxa/soundrecorder/DBHelper.java b/app/src/main/java/by/naxa/soundrecorder/DBHelper.java index 10fd30dc..dd927e59 100644 --- a/app/src/main/java/by/naxa/soundrecorder/DBHelper.java +++ b/app/src/main/java/by/naxa/soundrecorder/DBHelper.java @@ -115,7 +115,7 @@ public long addRecording(String recordingName, String filePath, long length) { return rowId; } - public void renameItem(RecordingItem item, String recordingName, String filePath) { + public void renameItem(RecordingItem item, String recordingName, String filePath,int position) { SQLiteDatabase db = getWritableDatabase(); ContentValues cv = new ContentValues(); cv.put(DBHelperItem.COLUMN_NAME_RECORDING_NAME, recordingName); @@ -124,7 +124,7 @@ public void renameItem(RecordingItem item, String recordingName, String filePath DBHelperItem._ID + "=" + item.getId(), null); if (mOnDatabaseChangedListener != null) { - mOnDatabaseChangedListener.onDatabaseEntryRenamed(); + mOnDatabaseChangedListener.onDatabaseEntryRenamed(position); } } diff --git a/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java b/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java index e1549f7b..8ec14928 100644 --- a/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java +++ b/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java @@ -243,6 +243,7 @@ public void remove(RecordingItem recordingItem, int position) { ).show(); mDatabase.removeItemWithId(recordingItem.getId()); + mRecordingItems.remove(position); notifyItemRemoved(position); } @@ -274,8 +275,8 @@ public void rename(RecordingItem recordingItem, String name, int position) { Toast.LENGTH_LONG).show(); return; } - mDatabase.renameItem(recordingItem, name, mFilePath); - notifyItemChanged(position); + mDatabase.renameItem(recordingItem, name, mFilePath,position); +// notifyItemChanged(position); } } diff --git a/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java b/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java index 0df10322..6a3ed998 100644 --- a/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java +++ b/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java @@ -94,6 +94,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c private void fillRecordingItemList() { mDatabase.getCount(); + if (mRecordingItems != null) { + mRecordingItems.clear(); + } for (int i = 0; i < mDatabase.getCount(); i++) { mRecordingItems.add(mDatabase.getItemAt(i)); } @@ -135,8 +138,9 @@ public void onNewDatabaseEntryAdded() { @Override //TODO - public void onDatabaseEntryRenamed() { - + public void onDatabaseEntryRenamed(int position) { + fillRecordingItemList(); + mFileViewerAdapter.notifyItemChanged(position); } @Override diff --git a/app/src/main/java/by/naxa/soundrecorder/listeners/OnDatabaseChangedListener.java b/app/src/main/java/by/naxa/soundrecorder/listeners/OnDatabaseChangedListener.java index d17c96cc..628ae16e 100644 --- a/app/src/main/java/by/naxa/soundrecorder/listeners/OnDatabaseChangedListener.java +++ b/app/src/main/java/by/naxa/soundrecorder/listeners/OnDatabaseChangedListener.java @@ -6,5 +6,5 @@ */ public interface OnDatabaseChangedListener{ void onNewDatabaseEntryAdded(); - void onDatabaseEntryRenamed(); + void onDatabaseEntryRenamed(int position); } \ No newline at end of file From 71fb24e61ba6329b947b91ef6e672e92a176df40 Mon Sep 17 00:00:00 2001 From: axel legue Date: Wed, 30 Jan 2019 01:42:44 +0100 Subject: [PATCH 3/4] Feature : Wip Drag and Drop Recordings items - Add code - Clean some commented code --- .../adapters/FileViewerAdapter.java | 16 +++++----------- .../fragments/FileViewerFragment.java | 7 ++++--- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java b/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java index 8ec14928..7eb131ea 100644 --- a/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java +++ b/app/src/main/java/by/naxa/soundrecorder/adapters/FileViewerAdapter.java @@ -37,7 +37,6 @@ import by.naxa.soundrecorder.RecordingItem; import by.naxa.soundrecorder.fragments.PlaybackFragment; import by.naxa.soundrecorder.listeners.ItemTouchHelperAdapter; -import by.naxa.soundrecorder.listeners.OnDatabaseChangedListener; import by.naxa.soundrecorder.listeners.OnSingleClickListener; import by.naxa.soundrecorder.listeners.OnStartDragListener; import by.naxa.soundrecorder.util.EventBroadcaster; @@ -60,17 +59,13 @@ public class FileViewerAdapter extends RecyclerView.Adapter mRecordingItems; private final OnStartDragListener mDragStartListener; - public FileViewerAdapter( - Context context, - LinearLayoutManager linearLayoutManager, - ArrayList recordingItems, - OnStartDragListener dragListener) { - + public FileViewerAdapter(Context context, LinearLayoutManager linearLayoutManager, + ArrayList recordingItems, OnStartDragListener dragListener) { super(); + mContext = context; mDatabase = new DBHelper(mContext); mDragStartListener = dragListener; - mRecordingItems = recordingItems; llm = linearLayoutManager; } @@ -91,7 +86,7 @@ public void onBindViewHolder(@NonNull final RecordingsViewHolder holder, final i ) ); - // define an on click listener to open PlaybackFragment + // Define an on click listener to open PlaybackFragment holder.cardView.setOnClickListener(new OnSingleClickListener() { @Override public void onSingleClick(View view) { @@ -122,7 +117,6 @@ public boolean onLongClick(View v) { final CharSequence[] items = entries.toArray(new CharSequence[entries.size()]); - // File delete confirm AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(mContext.getString(R.string.dialog_title_options)); @@ -152,6 +146,7 @@ public void onClick(DialogInterface dialog, int id) { } }); + // Define an OnTouchListener to keep track of drag motion holder.cardView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { @@ -276,7 +271,6 @@ public void rename(RecordingItem recordingItem, String name, int position) { return; } mDatabase.renameItem(recordingItem, name, mFilePath,position); -// notifyItemChanged(position); } } diff --git a/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java b/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java index 6a3ed998..069d21b0 100644 --- a/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java +++ b/app/src/main/java/by/naxa/soundrecorder/fragments/FileViewerFragment.java @@ -64,7 +64,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_file_viewer, container, false); mDatabase = new DBHelper(getActivity()); - // instanciate new List for store recordingItems; + // Instantiate new List for recordingItems stored in database if (mRecordingItems == null) { mRecordingItems = new ArrayList<>(); } @@ -79,9 +79,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c mFileViewerAdapter = new FileViewerAdapter(getActivity(), llm, mRecordingItems, this); ItemTouchHelper.Callback callback = new SwapItemTouchHelperCallback(mFileViewerAdapter); - // Set Custome CallBack to ItemtoucheHelper + // Set Custom Callback to ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(callback); - // Link ItemTouchAdapter to Recyclerview + // Attach ItemTouchAdapter to RecyclerView mItemTouchHelper.attachToRecyclerView(mRecyclerView); mRecyclerView.setLayoutManager(llm); @@ -92,6 +92,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c return v; } + private void fillRecordingItemList() { mDatabase.getCount(); if (mRecordingItems != null) { From 0cf6555ad535e75b1855fedbc3cf0121e82811d8 Mon Sep 17 00:00:00 2001 From: axel legue Date: Wed, 30 Jan 2019 02:17:26 +0100 Subject: [PATCH 4/4] update project configuration --- app/build.gradle | 16 +++++++++++++++- app/src/main/AndroidManifest.xml | 4 +++- .../soundrecorder/SoundRecorderApplication.java | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index fee77275..a84d8e6d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,4 +1,18 @@ +buildscript { + repositories { + maven { url 'https://maven.fabric.io/public' } + } + + dependencies { + classpath 'io.fabric.tools:gradle:1.+' + } +} apply plugin: 'com.android.application' + +repositories { + maven { url 'https://maven.fabric.io/public' } +} + apply plugin: 'io.fabric' android { @@ -72,7 +86,7 @@ dependencies { }) // tracking - implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') { + implementation('com.crashlytics.sdk.android:crashlytics:2.9.8@aar') { transitive = true } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e3eab8fb..bb76e677 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,7 +17,9 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme"> - + diff --git a/app/src/main/java/by/naxa/soundrecorder/SoundRecorderApplication.java b/app/src/main/java/by/naxa/soundrecorder/SoundRecorderApplication.java index 8e065f66..ca69405e 100644 --- a/app/src/main/java/by/naxa/soundrecorder/SoundRecorderApplication.java +++ b/app/src/main/java/by/naxa/soundrecorder/SoundRecorderApplication.java @@ -25,7 +25,7 @@ public void onCreate() { .kits(new Crashlytics.Builder().core(core).build()) .debuggable(true) .build(); - Fabric.with(fabric); + Fabric.with(this, new Crashlytics()); } }