Add feed edit dialog

This commit is contained in:
Shinokuni 2019-02-24 14:21:06 +00:00
parent 83ca13249a
commit 706861a825
10 changed files with 175 additions and 7 deletions

Binary file not shown.

View File

@ -45,6 +45,7 @@ dependencies {
transitive = false transitive = false
} }
implementation 'android.arch.lifecycle:extensions:1.1.1'
implementation "android.arch.persistence.room:runtime:1.1.1" implementation "android.arch.persistence.room:runtime:1.1.1"
annotationProcessor "android.arch.persistence.room:compiler:1.1.1" annotationProcessor "android.arch.persistence.room:compiler:1.1.1"

View File

@ -8,7 +8,9 @@ import android.support.v7.widget.RecyclerView;
import android.view.MenuItem; import android.view.MenuItem;
import com.mikepenz.fastadapter.FastAdapter; import com.mikepenz.fastadapter.FastAdapter;
import com.mikepenz.fastadapter.IInterceptor;
import com.mikepenz.fastadapter.adapters.ModelAdapter; import com.mikepenz.fastadapter.adapters.ModelAdapter;
import com.readrops.app.views.EditFeedDialog;
import com.readrops.app.views.FeedWithFolderItem; import com.readrops.app.views.FeedWithFolderItem;
import com.readrops.app.viewmodels.ManageFeedsViewModel; import com.readrops.app.viewmodels.ManageFeedsViewModel;
import com.readrops.app.R; import com.readrops.app.R;
@ -27,7 +29,23 @@ public class ManageFeedsActivity extends AppCompatActivity {
recyclerView = findViewById(R.id.feeds_recyclerview); recyclerView = findViewById(R.id.feeds_recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
itemAdapter = new ModelAdapter<>(FeedWithFolderItem::new); itemAdapter = new ModelAdapter<>(feedWithFolder -> {
FeedWithFolderItem folderItem = new FeedWithFolderItem(feedWithFolder);
folderItem.setListener(new FeedWithFolderItem.ManageFeedsListener() {
@Override
public void onEdit(FeedWithFolder feedWithFolder) {
openEditFeedDialog(feedWithFolder);
}
@Override
public void onDelete(FeedWithFolder feedWithFolder) {
}
});
return folderItem;
});
FastAdapter fastAdapter = FastAdapter.with(itemAdapter); FastAdapter fastAdapter = FastAdapter.with(itemAdapter);
recyclerView.setAdapter(fastAdapter); recyclerView.setAdapter(fastAdapter);
@ -36,6 +54,11 @@ public class ManageFeedsActivity extends AppCompatActivity {
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> itemAdapter.add(feedWithFolders)); viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> itemAdapter.add(feedWithFolders));
} }
private void openEditFeedDialog(FeedWithFolder feedWithFolder) {
EditFeedDialog editFeedDialog = new EditFeedDialog(this, feedWithFolder);
editFeedDialog.show();
}
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {

View File

@ -0,0 +1,49 @@
package com.readrops.app.views;
import android.app.Activity;
import android.app.Dialog;
import android.arch.lifecycle.ViewModelProvider;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputEditText;
import android.support.v4.app.FragmentActivity;
import android.widget.Button;
import android.widget.Spinner;
import com.readrops.app.R;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.pojo.FeedWithFolder;
import com.readrops.app.viewmodels.ManageFeedsViewModel;
public class EditFeedDialog extends Dialog {
private TextInputEditText feedName;
private TextInputEditText feedUrl;
private Spinner folder;
private Button validate;
private FeedWithFolder feedWithFolder;
private ManageFeedsViewModel viewModel;
public EditFeedDialog(@NonNull Context context, FeedWithFolder feedWithFolder) {
super(context);
if (context instanceof Activity)
setOwnerActivity((Activity) context);
this.feedWithFolder = feedWithFolder;
viewModel = ViewModelProviders.of((FragmentActivity) getOwnerActivity()).get(ManageFeedsViewModel.class);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_feed_layout);
feedName = findViewById(R.id.edit_feed_name_edit_text);
feedUrl = findViewById(R.id.edit_feed_url_edit_text);
folder = findViewById(R.id.edit_feed_folder_spinner);
validate = findViewById(R.id.edit_feed_validate);
}
}

View File

@ -16,6 +16,8 @@ import java.util.List;
public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWithFolderItem, FeedWithFolderItem.ViewHolder> { public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWithFolderItem, FeedWithFolderItem.ViewHolder> {
private ManageFeedsListener listener;
public FeedWithFolderItem(FeedWithFolder feedWithFolder) { public FeedWithFolderItem(FeedWithFolder feedWithFolder) {
super(feedWithFolder); super(feedWithFolder);
} }
@ -57,6 +59,18 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
holder.feedDescription.setVisibility(View.GONE); holder.feedDescription.setVisibility(View.GONE);
holder.folderName.setText(feedWithFolder.getFolder().getName()); holder.folderName.setText(feedWithFolder.getFolder().getName());
holder.editFeed.setOnClickListener(v -> listener.onEdit(feedWithFolder));
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(feedWithFolder));
}
public void setListener(ManageFeedsListener listener) {
this.listener = listener;
}
public interface ManageFeedsListener {
void onEdit(FeedWithFolder feedWithFolder);
void onDelete(FeedWithFolder feedWithFolder);
} }
protected static class ViewHolder extends RecyclerView.ViewHolder { protected static class ViewHolder extends RecyclerView.ViewHolder {
@ -66,6 +80,8 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
private TextView feedDescription; private TextView feedDescription;
private TextView folderName; private TextView folderName;
private ImageView editFeed;
private ImageView deleteFeed;
public ViewHolder(View itemView) { public ViewHolder(View itemView) {
super(itemView); super(itemView);
@ -74,6 +90,8 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
feedName = itemView.findViewById(R.id.feed_layout_name); feedName = itemView.findViewById(R.id.feed_layout_name);
feedDescription = itemView.findViewById(R.id.feed_layout_description); feedDescription = itemView.findViewById(R.id.feed_layout_description);
folderName = itemView.findViewById(R.id.feed_layout_folder); folderName = itemView.findViewById(R.id.feed_layout_folder);
editFeed = itemView.findViewById(R.id.feed_layout_edit);
deleteFeed = itemView.findViewById(R.id.feed_layout_delete);
} }
} }
} }

View File

@ -31,7 +31,7 @@
android:id="@+id/add_feed_edit_text" android:id="@+id/add_feed_edit_text"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="@string/add_feed_url" /> android:hint="@string/feed_url" />
</android.support.design.widget.TextInputLayout> </android.support.design.widget.TextInputLayout>
@ -40,7 +40,7 @@
style="@style/Widget.AppCompat.Button.Borderless" style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/add_feed_validate" android:text="@string/validate"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="center" android:textAlignment="center"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout" /> app:layout_constraintTop_toBottomOf="@+id/textInputLayout" />

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="?dialogPreferredPadding">
<TextView
android:id="@+id/edit_feed_title"
style="@style/RtlOverlay.DialogWindowTitle.AppCompat"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="@string/edit_feed"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.TextInputLayout
android:id="@+id/edit_feed_name_textinputlayout"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_feed_title">
<android.support.design.widget.TextInputEditText
android:id="@+id/edit_feed_name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/feed_name" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/edit_feed_url_textinputlayout"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_feed_name_textinputlayout">
<android.support.design.widget.TextInputEditText
android:id="@+id/edit_feed_url_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/feed_url" />
</android.support.design.widget.TextInputLayout>
<Spinner
android:id="@+id/edit_feed_folder_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_feed_url_textinputlayout" />
<Button
android:id="@+id/edit_feed_validate"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/validate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_feed_folder_spinner" />
</android.support.constraint.ConstraintLayout>

View File

@ -9,8 +9,8 @@
<string name="settings">Paramètres</string> <string name="settings">Paramètres</string>
<string name="about_item">A propos</string> <string name="about_item">A propos</string>
<string name="add_feed_title">Ajouter un flux</string> <string name="add_feed_title">Ajouter un flux</string>
<string name="add_feed_url">Adresse du flux</string> <string name="feed_url">Adresse du flux</string>
<string name="add_feed_validate">Valider</string> <string name="validate">Valider</string>
<string name="add_feed_empty_field">Le champ ne peut pas être vide</string> <string name="add_feed_empty_field">Le champ ne peut pas être vide</string>
<string name="add_feed_wrong_url">La valeur n\'est pas une adresse web valide</string> <string name="add_feed_wrong_url">La valeur n\'est pas une adresse web valide</string>
<string name="add_feed_no_result">Aucune adresse de flux trouvée</string> <string name="add_feed_no_result">Aucune adresse de flux trouvée</string>
@ -23,5 +23,8 @@
<string name="share">Partager l\'article</string> <string name="share">Partager l\'article</string>
<string name="open_url">Ouvrir le lien</string> <string name="open_url">Ouvrir le lien</string>
<string name="add_folder">Ajouter un dossier</string> <string name="add_folder">Ajouter un dossier</string>
<string name="feed_folder">Dossier du flux</string>
<string name="feed_name">Nom du flux</string>
<string name="edit_feed">Modifier le flux</string>
</resources> </resources>

View File

@ -10,8 +10,8 @@
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="about_item">About</string> <string name="about_item">About</string>
<string name="add_feed_title">Add feed</string> <string name="add_feed_title">Add feed</string>
<string name="add_feed_url">Feed url</string> <string name="feed_url">Feed url</string>
<string name="add_feed_validate">Validate</string> <string name="validate">Validate</string>
<string name="add_feed_empty_field">Field can\'t be empty</string> <string name="add_feed_empty_field">Field can\'t be empty</string>
<string name="add_feed_wrong_url">Input is not a valid URL</string> <string name="add_feed_wrong_url">Input is not a valid URL</string>
<string name="add_feed_no_result">No feed url found</string> <string name="add_feed_no_result">No feed url found</string>
@ -25,4 +25,7 @@
<string name="share">Share Article</string> <string name="share">Share Article</string>
<string name="open_url">Open url</string> <string name="open_url">Open url</string>
<string name="add_folder">Add folder</string> <string name="add_folder">Add folder</string>
<string name="feed_folder">Feed folder</string>
<string name="feed_name">Feed name</string>
<string name="edit_feed">Edit feed</string>
</resources> </resources>