Add feedWithFolder argument to the add feed dialog to display and edit feed data

This commit is contained in:
Shinokuni 2019-02-25 21:29:37 +00:00
parent 3b4f6fe9f0
commit 50ede215fb
5 changed files with 139 additions and 6 deletions

View File

@ -57,8 +57,12 @@ public class ManageFeedsActivity extends AppCompatActivity {
private void openEditFeedDialog(FeedWithFolder feedWithFolder) {
EditFeedDialog editFeedDialog = new EditFeedDialog();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Bundle bundle = new Bundle();
bundle.putParcelable("feedWithFolder", feedWithFolder);
editFeedDialog.setArguments(bundle);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(editFeedDialog, "").commit();
}

View File

@ -2,6 +2,8 @@ package com.readrops.app.database.entities;
import android.arch.persistence.room.*;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
@ -11,7 +13,7 @@ import com.readrops.readropslibrary.localfeed.rss.RSSChannel;
import com.readrops.readropslibrary.localfeed.rss.RSSFeed;
@Entity(foreignKeys = @ForeignKey(entity = Folder.class, parentColumns = "id", childColumns = "folder_id"))
public class Feed {
public class Feed implements Parcelable {
@PrimaryKey(autoGenerate = true)
private int id;
@ -54,6 +56,33 @@ public class Feed {
this.url = url;
}
protected Feed(Parcel in) {
id = in.readInt();
name = in.readString();
description = in.readString();
url = in.readString();
siteUrl = in.readString();
lastUpdated = in.readString();
textColor = in.readInt();
backgroundColor = in.readInt();
iconUrl = in.readString();
etag = in.readString();
lastModified = in.readString();
folderId = in.readInt();
}
public static final Creator<Feed> CREATOR = new Creator<Feed>() {
@Override
public Feed createFromParcel(Parcel in) {
return new Feed(in);
}
@Override
public Feed[] newArray(int size) {
return new Feed[size];
}
};
public int getId() {
return id;
}
@ -203,4 +232,26 @@ public class Feed {
return feed;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
dest.writeString(description);
dest.writeString(url);
dest.writeString(siteUrl);
dest.writeString(lastUpdated);
dest.writeInt(textColor);
dest.writeInt(backgroundColor);
dest.writeString(iconUrl);
dest.writeString(etag);
dest.writeString(lastModified);
dest.writeInt(folderId);
}
}

View File

@ -3,9 +3,11 @@ package com.readrops.app.database.entities;
import android.arch.persistence.room.Entity;
import android.arch.persistence.room.Ignore;
import android.arch.persistence.room.PrimaryKey;
import android.os.Parcel;
import android.os.Parcelable;
@Entity
public class Folder {
public class Folder implements Parcelable {
@PrimaryKey(autoGenerate = true)
private int id;
@ -21,6 +23,13 @@ public class Folder {
this.name = name;
}
protected Folder(Parcel in) {
id = in.readInt();
name = in.readString();
}
public int getId() {
return id;
}
@ -36,4 +45,27 @@ public class Folder {
public void setName(String name) {
this.name = name;
}
public static final Creator<Folder> CREATOR = new Creator<Folder>() {
@Override
public Folder createFromParcel(Parcel in) {
return new Folder(in);
}
@Override
public Folder[] newArray(int size) {
return new Folder[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
}
}

View File

@ -1,11 +1,13 @@
package com.readrops.app.database.pojo;
import android.arch.persistence.room.Embedded;
import android.os.Parcel;
import android.os.Parcelable;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Folder;
public class FeedWithFolder {
public class FeedWithFolder implements Parcelable {
@Embedded(prefix = "feed_")
private Feed feed;
@ -13,6 +15,38 @@ public class FeedWithFolder {
@Embedded(prefix = "folder_")
private Folder folder;
public FeedWithFolder() {
}
protected FeedWithFolder(Parcel in) {
feed = in.readParcelable(Feed.class.getClassLoader());
folder = in.readParcelable(Folder.class.getClassLoader());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(feed, flags);
dest.writeParcelable(folder, flags);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<FeedWithFolder> CREATOR = new Creator<FeedWithFolder>() {
@Override
public FeedWithFolder createFromParcel(Parcel in) {
return new FeedWithFolder(in);
}
@Override
public FeedWithFolder[] newArray(int size) {
return new FeedWithFolder[size];
}
};
public Feed getFeed() {
return feed;
}
@ -28,4 +62,6 @@ public class FeedWithFolder {
public void setFolder(Folder folder) {
this.folder = folder;
}
}

View File

@ -35,6 +35,9 @@ 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);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
@ -44,11 +47,18 @@ public class EditFeedDialog extends DialogFragment {
});
builder.setView(v);
fillData(v);
return builder.create();
}
private void fillData(View v) {
feedName = v.findViewById(R.id.edit_feed_name_edit_text);
feedUrl = v.findViewById(R.id.edit_feed_url_edit_text);
folder = v.findViewById(R.id.edit_feed_folder_spinner);
return builder.create();
feedName.setText(feedWithFolder.getFeed().getName());
feedUrl.setText(feedWithFolder.getFeed().getUrl());
}