mirror of https://github.com/readrops/Readrops.git
Add feed update
This commit is contained in:
parent
50ede215fb
commit
4c538af36e
|
@ -21,6 +21,7 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
|||
|
||||
private RecyclerView recyclerView;
|
||||
private ModelAdapter<FeedWithFolder, FeedWithFolderItem> itemAdapter;
|
||||
private FastAdapter fastAdapter;
|
||||
private ManageFeedsViewModel viewModel;
|
||||
|
||||
@Override
|
||||
|
@ -48,11 +49,15 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
|||
return folderItem;
|
||||
});
|
||||
|
||||
FastAdapter fastAdapter = FastAdapter.with(itemAdapter);
|
||||
fastAdapter = FastAdapter.with(itemAdapter);
|
||||
|
||||
recyclerView.setAdapter(fastAdapter);
|
||||
|
||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ManageFeedsViewModel.class);
|
||||
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> itemAdapter.add(feedWithFolders));
|
||||
viewModel.getFeedsWithFolder().observe(this, feedWithFolders -> {
|
||||
itemAdapter.add(feedWithFolders);
|
||||
fastAdapter.notifyAdapterDataSetChanged();
|
||||
});
|
||||
}
|
||||
|
||||
private void openEditFeedDialog(FeedWithFolder feedWithFolder) {
|
||||
|
|
|
@ -21,6 +21,9 @@ public interface FeedDao {
|
|||
@Insert
|
||||
long insert(Feed feed);
|
||||
|
||||
@Update
|
||||
void update(Feed feed);
|
||||
|
||||
@Query("Select count(*) from Feed")
|
||||
int getFeedCount();
|
||||
|
||||
|
@ -33,8 +36,12 @@ public interface FeedDao {
|
|||
@Query("Update Feed set folder_id = :folderId Where id = :feedId")
|
||||
void updateFeedFolder(int feedId, int folderId);
|
||||
|
||||
@Query("Update Feed set name = :feedName, url = :feedUrl, folder_id = :folderId Where id = :feedId")
|
||||
void updateFeedFields(int feedId, String feedName, String feedUrl, int folderId);
|
||||
|
||||
@Query("Select Feed.name as feed_name, Feed.id as feed_id, Folder.name as folder_name, Folder.id as folder_id," +
|
||||
"Feed.description as feed_description, Feed.icon_url as feed_icon_url, Feed.url as feed_url" +
|
||||
"Feed.description as feed_description, Feed.icon_url as feed_icon_url, Feed.url as feed_url, Feed.folder_id as feed_folder_id" +
|
||||
" from Feed Inner Join Folder on Feed.folder_id = Folder.id Order by Feed.name")
|
||||
LiveData<List<FeedWithFolder>> getAllFeedsWithFolder();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.app.Application;
|
|||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
|
||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||
import com.readrops.app.views.SimpleCallback;
|
||||
import com.readrops.app.database.Database;
|
||||
import com.readrops.app.database.entities.Feed;
|
||||
|
@ -35,6 +36,10 @@ public abstract class ARepository {
|
|||
|
||||
public abstract void addFeed(ParsingResult result);
|
||||
|
||||
public abstract void updateFeed(Feed feed);
|
||||
|
||||
public abstract void updateFeedWithFolder(FeedWithFolder feedWithFolder);
|
||||
|
||||
public abstract void deleteFeed(Feed feed);
|
||||
|
||||
public Completable addFolder(String name) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.Bitmap;
|
|||
import android.support.v7.graphics.Palette;
|
||||
import android.util.Patterns;
|
||||
|
||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||
import com.readrops.app.database.pojo.ItemWithFeed;
|
||||
import com.readrops.app.database.entities.Feed;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
|
@ -85,6 +86,25 @@ public class LocalFeedRepository extends ARepository implements QueryCallback {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFeed(Feed feed) {
|
||||
executor.execute(() -> {
|
||||
try {
|
||||
database.feedDao().update(feed);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFeedWithFolder(FeedWithFolder feedWithFolder) {
|
||||
executor.execute(() -> {
|
||||
Feed feed = feedWithFolder.getFeed();
|
||||
database.feedDao().updateFeedFields(feed.getId(), feed.getName(), feed.getUrl(), feed.getFolderId());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteFeed(Feed feed) {
|
||||
executor.execute(() -> {
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
package com.readrops.app.viewmodels;
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.ListActivity;
|
||||
import android.arch.lifecycle.AndroidViewModel;
|
||||
import android.arch.lifecycle.LiveData;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.readrops.app.database.Database;
|
||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||
import com.readrops.app.repositories.LocalFeedRepository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -15,10 +15,12 @@ public class ManageFeedsViewModel extends AndroidViewModel {
|
|||
|
||||
private Database db;
|
||||
private LiveData<List<FeedWithFolder>> feedsWithFolder;
|
||||
private LocalFeedRepository repository;
|
||||
|
||||
public ManageFeedsViewModel(@NonNull Application application) {
|
||||
super(application);
|
||||
db = Database.getInstance(application);
|
||||
repository = new LocalFeedRepository(application);
|
||||
|
||||
feedsWithFolder = db.feedDao().getAllFeedsWithFolder();
|
||||
}
|
||||
|
@ -26,4 +28,8 @@ public class ManageFeedsViewModel extends AndroidViewModel {
|
|||
public LiveData<List<FeedWithFolder>> getFeedsWithFolder() {
|
||||
return feedsWithFolder;
|
||||
}
|
||||
|
||||
public void updateFeedWithFolder(FeedWithFolder feedWithFolder) {
|
||||
repository.updateFeedWithFolder(feedWithFolder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package com.readrops.app.views;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
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.annotation.Nullable;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import com.readrops.app.R;
|
||||
|
@ -26,7 +21,6 @@ public class EditFeedDialog extends DialogFragment {
|
|||
private TextInputEditText feedName;
|
||||
private TextInputEditText feedUrl;
|
||||
private Spinner folder;
|
||||
private Button validate;
|
||||
|
||||
private FeedWithFolder feedWithFolder;
|
||||
private ManageFeedsViewModel viewModel;
|
||||
|
@ -35,7 +29,6 @@ public class EditFeedDialog extends DialogFragment {
|
|||
@Override
|
||||
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
|
||||
viewModel = ViewModelProviders.of(getActivity()).get(ManageFeedsViewModel.class);
|
||||
|
||||
feedWithFolder = getArguments().getParcelable("feedWithFolder");
|
||||
|
||||
View v = getActivity().getLayoutInflater().inflate(R.layout.edit_feed_layout, null);
|
||||
|
@ -43,7 +36,11 @@ public class EditFeedDialog extends DialogFragment {
|
|||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
|
||||
.setTitle(getString(R.string.edit_feed))
|
||||
.setPositiveButton(getString(R.string.validate), (dialog, which) -> {
|
||||
Feed feed = feedWithFolder.getFeed();
|
||||
feed.setName(feedName.getText().toString().trim());
|
||||
feed.setUrl(feedUrl.getText().toString().trim());
|
||||
|
||||
viewModel.updateFeedWithFolder(feedWithFolder);
|
||||
});
|
||||
|
||||
builder.setView(v);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="18dp">
|
||||
|
@ -38,17 +39,27 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:hint="@string/feed_url"
|
||||
android:inputType="textUri"
|
||||
android:lines="1"/>
|
||||
android:lines="1" />
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/edit_feed_folder"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/edit_feed_url_textinputlayout"
|
||||
android:text="@string/folder"
|
||||
android:textAppearance="@style/TextAppearance.Design.Hint"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/edit_feed_folder_spinner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.514"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/edit_feed_url_textinputlayout" />
|
||||
app:layout_constraintTop_toBottomOf="@+id/edit_feed_folder" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -26,5 +26,6 @@
|
|||
<string name="feed_folder">Dossier du flux</string>
|
||||
<string name="feed_name">Nom du flux</string>
|
||||
<string name="edit_feed">Modifier le flux</string>
|
||||
<string name="folder">dossier</string>
|
||||
|
||||
</resources>
|
|
@ -28,4 +28,5 @@
|
|||
<string name="feed_folder">Feed folder</string>
|
||||
<string name="feed_name">Feed name</string>
|
||||
<string name="edit_feed">Edit feed</string>
|
||||
<string name="folder">Folder</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue