Add bottomSheetDialog for feed actions (remove swipe for delete and longclick)

This commit is contained in:
Shinokuni 2019-09-22 14:37:10 +02:00
parent 9096cea9bd
commit 52fb98dee2
9 changed files with 228 additions and 73 deletions

View File

@ -3,6 +3,9 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.readrops.app">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".utils.ReadropsApp"
android:allowBackup="true"
@ -13,11 +16,13 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".activities.AboutActivity"
android:label="@string/about"
android:parentActivityName=".activities.MainActivity" />
<activity android:name=".activities.SettingsActivity" />
<activity
android:name=".activities.SplashActivity"
android:theme="@style/SplashTheme">
@ -27,32 +32,32 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".activities.AccountTypeListActivity" />
<activity
android:name=".activities.AddAccountActivity"
android:label="@string/add_account" />
<activity
android:name=".activities.ManageFeedsFoldersActivity"
android:label="@string/manage_feeds_folders"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.MainActivity"
android:label="@string/articles"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.ItemActivity"
android:parentActivityName=".activities.MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.AddFeedActivity"
android:label="@string/add_feed_title"
android:parentActivityName=".activities.MainActivity" />
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.INTERNET" />
</manifest>

View File

@ -29,7 +29,9 @@ import java.util.TreeMap;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
public class EditFeedDialog extends DialogFragment implements AdapterView.OnItemSelectedListener {
import static com.readrops.app.activities.ManageFeedsFoldersActivity.ACCOUNT;
public class EditFeedDialogFragment extends DialogFragment implements AdapterView.OnItemSelectedListener {
private TextInputEditText feedName;
private TextInputEditText feedUrl;
@ -41,6 +43,20 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
private Account account;
private ManageFeedsFoldersViewModel viewModel;
public EditFeedDialogFragment() {
}
public static EditFeedDialogFragment newInstance(FeedWithFolder feedWithFolder, Account account) {
Bundle args = new Bundle();
args.putParcelable("feedWithFolder", feedWithFolder);
args.putParcelable(ACCOUNT, account);
EditFeedDialogFragment fragment = new EditFeedDialogFragment();
fragment.setArguments(args);
return fragment;
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {

View File

@ -1,11 +1,8 @@
package com.readrops.app.fragments;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -14,17 +11,14 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.afollestad.materialdialogs.MaterialDialog;
import com.readrops.app.R;
import com.readrops.app.adapters.FeedsAdapter;
import com.readrops.app.database.entities.account.Account;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.account.Account;
import com.readrops.app.database.pojo.FeedWithFolder;
import com.readrops.app.databinding.FragmentFeedsBinding;
import com.readrops.app.fragments.settings.AccountSettingsFragment;
@ -36,7 +30,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.observers.DisposableCompletableObserver;
import io.reactivex.schedulers.Schedulers;
import static android.content.Context.VIBRATOR_SERVICE;
import static com.readrops.app.activities.ManageFeedsFoldersActivity.ACCOUNT;
@ -97,50 +90,18 @@ public class FeedsFragment extends Fragment {
adapter = new FeedsAdapter(new FeedsAdapter.ManageFeedsListener() {
@Override
public void onEdit(FeedWithFolder feedWithFolder) {
openEditFeedDialog(feedWithFolder);
openFeedOptionsFragment(feedWithFolder);
}
@Override
public void onOpenLink(FeedWithFolder feedWithFolder) {
Vibrator vibrator = (Vibrator) getActivity().getSystemService(VIBRATOR_SERVICE);
vibrator.vibrate(50);
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(feedWithFolder.getFeed().getSiteUrl()));
startActivity(urlIntent);
}
});
binding.feedsRecyclerview.setAdapter(adapter);
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {
@Override
public int getMovementFlags(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder) {
int swipeFlags = ItemTouchHelper.RIGHT;
return makeMovementFlags(0, swipeFlags);
}
@Override
public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder viewHolder1) {
return false;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
deleteFeed(adapter.getItemAt(viewHolder.getAdapterPosition()).getFeed(),
viewHolder.getAdapterPosition());
}
@Override
public boolean isItemViewSwipeEnabled() {
return true;
}
}).attachToRecyclerView(binding.feedsRecyclerview);
}
private void deleteFeed(Feed feed, int position) {
public void deleteFeed(Feed feed) {
new MaterialDialog.Builder(getContext())
.title(R.string.delete_feed)
.positiveText(R.string.validate)
@ -157,8 +118,6 @@ public class FeedsFragment extends Fragment {
@Override
public void onError(Throwable e) {
adapter.notifyItemChanged(position);
String message;
if (e instanceof Resources.NotFoundException)
message = getString(R.string.feed_doesnt_exist, feed.getName());
@ -168,19 +127,15 @@ public class FeedsFragment extends Fragment {
Utils.showSnackbar(binding.feedsRoot, message);
}
}))
.onNegative(((dialog, which) -> adapter.notifyItemChanged(position)))
.show();
}
private void openEditFeedDialog(FeedWithFolder feedWithFolder) {
EditFeedDialog editFeedDialog = new EditFeedDialog();
private void openFeedOptionsFragment(FeedWithFolder feedWithFolder) {
FeedsOptionsDialogFragment dialogFragment = FeedsOptionsDialogFragment.Companion.newInstance(feedWithFolder, account);
Bundle bundle = new Bundle();
bundle.putParcelable("feedWithFolder", feedWithFolder);
bundle.putParcelable(ACCOUNT, account);
editFeedDialog.setArguments(bundle);
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.add(editFeedDialog, "").commit();
getChildFragmentManager()
.beginTransaction()
.add(dialogFragment, "")
.commit();
}
}

View File

@ -0,0 +1,82 @@
package com.readrops.app.fragments
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.readrops.app.R
import com.readrops.app.activities.ManageFeedsFoldersActivity.ACCOUNT
import com.readrops.app.database.entities.account.Account
import com.readrops.app.database.pojo.FeedWithFolder
import com.readrops.app.databinding.FeedOptionsLayoutBinding
class FeedsOptionsDialogFragment : BottomSheetDialogFragment() {
private lateinit var feedWithFolder: FeedWithFolder
private lateinit var account: Account
private lateinit var binding: FeedOptionsLayoutBinding
companion object {
val FEED_KEY = "FEED_KEY"
fun newInstance(feedWithFolder: FeedWithFolder, account: Account): FeedsOptionsDialogFragment {
val bundle = Bundle()
bundle.putParcelable(FEED_KEY, feedWithFolder)
bundle.putParcelable(ACCOUNT, account)
val feedsOptionsDialogFragment = FeedsOptionsDialogFragment()
feedsOptionsDialogFragment.arguments = bundle
return feedsOptionsDialogFragment
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
feedWithFolder = arguments?.getParcelable(FEED_KEY)!!
account = arguments?.getParcelable(ACCOUNT)!!
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.feed_options_layout, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.feedOptionsTitle.text = feedWithFolder.feed.name
binding.feedOptionsEditLayout.setOnClickListener { openEditFeedDialog() }
binding.feedOptionsOpenRootLayout.setOnClickListener { openFeedRootUrl() }
binding.feedOptionsDeleteLayout.setOnClickListener { deleteFeed() }
}
private fun openEditFeedDialog() {
dismiss()
val editFeedDialogFragment = EditFeedDialogFragment.newInstance(feedWithFolder, account)
activity
?.supportFragmentManager
?.beginTransaction()
?.add(editFeedDialogFragment, "")
?.commit()
}
private fun openFeedRootUrl() {
dismiss()
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(feedWithFolder.feed.siteUrl)))
}
private fun deleteFeed() {
dismiss()
(parentFragment as FeedsFragment).deleteFeed(feedWithFolder.feed)
}
}

View File

@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z"/>
android:fillColor="#727272"
android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" />
</vector>

View File

@ -1,9 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h4v-2L5,18L5,8h14v10h-4v2h4c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.89,-2 -2,-2zM12,10l-4,4h3v6h2v-6h3l-4,-4z"/>
android:fillColor="#727272"
android:pathData="M19,4L5,4c-1.11,0 -2,0.9 -2,2v12c0,1.1 0.89,2 2,2h4v-2L5,18L5,8h14v10h-4v2h4c1.1,0 2,-0.9 2,-2L21,6c0,-1.1 -0.89,-2 -2,-2zM12,10l-4,4h3v6h2v-6h3l-4,-4z" />
</vector>

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp">
<LinearLayout
android:id="@+id/feed_options_edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/feed_options_title">
<TextView
android:id="@+id/feed_edit_feed"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_edit"
android:drawablePadding="16dp"
android:text="@string/edit_feed" />
</LinearLayout>
<LinearLayout
android:id="@+id/feed_options_open_root_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/feed_options_edit_layout">
<TextView
android:id="@+id/feed_open_root"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_open_in_browser"
android:drawablePadding="16dp"
android:text="@string/open_url" />
</LinearLayout>
<LinearLayout
android:id="@+id/feed_options_delete_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="horizontal"
android:paddingStart="16dp"
android:paddingTop="8dp"
android:paddingBottom="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/feed_options_open_root_layout">
<TextView
android:id="@+id/feed_options_delete"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="@drawable/ic_delete_grey"
android:drawablePadding="16dp"
android:text="@string/delete" />
</LinearLayout>
<TextView
android:id="@+id/feed_options_title"
style="@style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Feed 1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@ -80,5 +80,6 @@
<string name="local">Local</string>
<string name="feeds_number">%1$s flux</string>
<string name="feed_number">%1$s flux</string>
<string name="delete">Supprimer</string>
</resources>

View File

@ -87,4 +87,5 @@
<string name="local">Local</string>
<string name="feeds_number">%1$s feeds</string>
<string name="feed_number">%1$s feed</string>
<string name="delete">Delete</string>
</resources>