Fix Folder entity usage as its foreign key is now nullable
This commit is contained in:
parent
75a0ee4d97
commit
44f58a8aba
@ -1,16 +1,10 @@
|
||||
package com.readrops.app.activities;
|
||||
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import android.content.Intent;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
@ -18,6 +12,13 @@ import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
||||
import com.google.android.material.appbar.AppBarLayout;
|
||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.database.entities.Item;
|
||||
import com.readrops.app.database.pojo.ItemWithFeed;
|
||||
@ -123,7 +124,7 @@ public class ItemActivity extends AppCompatActivity {
|
||||
else
|
||||
toolbarLayout.setTitle(itemWithFeed.getFeedName());
|
||||
|
||||
if (itemWithFeed.getFolder().getId() != 1) {
|
||||
if (itemWithFeed.getFolder() != null) {
|
||||
toolbar.setSubtitle(itemWithFeed.getFolder().getName());
|
||||
toolbar.setSubtitleTextColor(Color.WHITE);
|
||||
}
|
||||
|
@ -1,30 +1,28 @@
|
||||
package com.readrops.app.activities;
|
||||
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Vibrator;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
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.database.entities.Folder;
|
||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||
import com.readrops.app.viewmodels.ManageFeedsViewModel;
|
||||
import com.readrops.app.views.EditFeedDialog;
|
||||
import com.readrops.app.views.FeedsAdapter;
|
||||
import com.readrops.app.viewmodels.ManageFeedsViewModel;
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.observers.DisposableCompletableObserver;
|
||||
@ -137,6 +135,8 @@ public class ManageFeedsActivity extends AppCompatActivity {
|
||||
.positiveText(R.string.validate)
|
||||
.input(R.string.folder, 0, (dialog, input) -> {
|
||||
Folder folder = new Folder(input.toString());
|
||||
folder.setAccountId(1); // TODO add account support for creating folders
|
||||
|
||||
viewModel.addFolder(folder)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
|
@ -12,8 +12,8 @@ public class ItemsListQueryBuilder {
|
||||
"read_changed", "read_it_later", "Feed.name", "text_color", "background_color", "icon_url", "read_time",
|
||||
"Feed.id as feedId", "Feed.account_id", "Folder.id as folder_id", "Folder.name as folder_name"};
|
||||
|
||||
private String SELECT_ALL_JOIN = "Item Inner Join Feed, Folder on Item.feed_id = " +
|
||||
"Feed.id And Folder.id = Feed.folder_id";
|
||||
private String SELECT_ALL_JOIN = "Item, Feed LEFT JOIN Folder on Folder.id = Feed.folder_id " +
|
||||
"And Item.feed_id = Feed.id";
|
||||
|
||||
private String ORDER_BY_ASC = "Item.id DESC";
|
||||
|
||||
|
@ -14,8 +14,8 @@ import java.util.List;
|
||||
@Dao
|
||||
public interface FeedDao {
|
||||
|
||||
@Query("Select * from Feed order by name ASC")
|
||||
List<Feed> getAllFeeds();
|
||||
@Query("Select * from Feed Where account_id = :accountId order by name ASC")
|
||||
List<Feed> getAllFeeds(int accountId);
|
||||
|
||||
@Insert
|
||||
long insert(Feed feed);
|
||||
@ -48,17 +48,17 @@ public interface FeedDao {
|
||||
void updateHeaders(String etag, String lastModified, int feedId);
|
||||
|
||||
@Query("Update Feed set folder_id = :folderId Where id = :feedId")
|
||||
void updateFeedFolder(int feedId, int folderId);
|
||||
void updateFeedFolder(int feedId, Integer 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);
|
||||
void updateFeedFields(int feedId, String feedName, String feedUrl, Integer folderId);
|
||||
|
||||
@Query("Update Feed set text_color = :textColor, background_color = :bgColor Where id = :feedId")
|
||||
void updateColors(int feedId, int textColor, int bgColor);
|
||||
|
||||
@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.folder_id as feed_folder_id" +
|
||||
", Feed.siteUrl as feed_siteUrl from Feed Inner Join Folder on Feed.folder_id = Folder.id Order by Feed.name")
|
||||
", Feed.siteUrl as feed_siteUrl from Feed Left Join Folder on Feed.folder_id = Folder.id Order by Feed.name")
|
||||
LiveData<List<FeedWithFolder>> getAllFeedsWithFolder();
|
||||
|
||||
@Query("Select * From Feed Where id in (:ids)")
|
||||
|
@ -22,8 +22,8 @@ public interface ItemDao {
|
||||
@RawQuery(observedEntities = {Item.class, Folder.class, Feed.class})
|
||||
PageKeyedDataSource.Factory<Integer, ItemWithFeed> selectAll(SupportSQLiteQuery query);
|
||||
|
||||
@Query("Select case When :guid In (Select guid from Item) Then 'true' else 'false' end")
|
||||
String guidExist(String guid);
|
||||
@Query("Select case When :guid In (Select guid From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end")
|
||||
boolean itemExists(String guid, int accountId);
|
||||
|
||||
@Query("Select case When :remoteId In (Select remoteId from Item) And :feedId In (Select feed_id From Item) Then 1 else 0 end")
|
||||
boolean remoteItemExists(int remoteId, int feedId);
|
||||
@ -58,8 +58,7 @@ public interface ItemDao {
|
||||
|
||||
@Query("Select title, Item.description, content, link, pub_date, image_link, author, read, text_color, " +
|
||||
"background_color, read_time, Feed.name, Feed.id as feedId, siteUrl, Folder.id as folder_id, " +
|
||||
"Folder.name as folder_name from Item Inner Join Feed, Folder on Item.feed_id = Feed.id And Item.id = :id " +
|
||||
"And Folder.id = Feed.folder_id")
|
||||
"Folder.name as folder_name from Item, Feed Left Join Folder on Folder.id = Feed.folder_id And Item.feed_id = Feed.id Where Item.id = :id")
|
||||
LiveData<ItemWithFeed> getItemById(int id);
|
||||
|
||||
@Query("Select remoteId From Item Where read_changed = 1 And read = 1")
|
||||
|
@ -2,18 +2,18 @@ package com.readrops.app.views;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.database.entities.Feed;
|
||||
import com.readrops.app.database.entities.Folder;
|
||||
@ -60,11 +60,10 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
|
||||
|
||||
viewModel.getFolders().observe(this, folders -> {
|
||||
values = new TreeMap<>(String::compareTo);
|
||||
values.put(getString(R.string.no_folder), 0);
|
||||
|
||||
for (Folder folder : folders) {
|
||||
if (folder.getId() != 1)
|
||||
values.put(folder.getName(), folder.getId());
|
||||
else
|
||||
values.put(getString(R.string.no_folder), 1);
|
||||
values.put(folder.getName(), folder.getId());
|
||||
}
|
||||
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
|
||||
@ -74,7 +73,7 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
|
||||
folder.setAdapter(adapter);
|
||||
folder.setOnItemSelectedListener(this);
|
||||
|
||||
if (!feedWithFolder.getFolder().getName().equals("reserved"))
|
||||
if (feedWithFolder.getFolder() != null)
|
||||
folder.setSelection(adapter.getPosition(feedWithFolder.getFolder().getName()));
|
||||
else
|
||||
folder.setSelection(adapter.getPosition(getString(R.string.no_folder)));
|
||||
@ -95,7 +94,9 @@ public class EditFeedDialog extends DialogFragment implements AdapterView.OnItem
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
String folderName = (String)parent.getAdapter().getItem(position);
|
||||
feedWithFolder.getFeed().setFolderId(values.get(folderName));
|
||||
int folderId = values.get(folderName);
|
||||
|
||||
feedWithFolder.getFeed().setFolderId(folderId == 0 ? null : folderId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,19 +1,17 @@
|
||||
package com.readrops.app.views;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.AsyncListDiffer;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
import androidx.recyclerview.widget.ListAdapter;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.readrops.app.R;
|
||||
import com.readrops.app.database.pojo.FeedWithFolder;
|
||||
@ -23,9 +21,6 @@ import java.util.List;
|
||||
|
||||
public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewHolder> {
|
||||
|
||||
public static final String FEED_NAME_KEY = "name";
|
||||
public static final String FOLDER_NAME_KEY = "folderName";
|
||||
|
||||
private ManageFeedsListener listener;
|
||||
|
||||
private static final DiffUtil.ItemCallback<FeedWithFolder> DIFF_CALLBACK = new DiffUtil.ItemCallback<FeedWithFolder>() {
|
||||
@ -36,26 +31,18 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull FeedWithFolder feedWithFolder, @NonNull FeedWithFolder t1) {
|
||||
boolean folder = false;
|
||||
if (feedWithFolder.getFolder() != null && t1.getFolder() != null)
|
||||
folder = feedWithFolder.getFolder().getName().equals(t1.getFolder().getName());
|
||||
|
||||
return feedWithFolder.getFeed().getName().equals(t1.getFeed().getName())
|
||||
&& feedWithFolder.getFolder().getName().equals(t1.getFolder().getName());
|
||||
&& folder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getChangePayload(@NonNull FeedWithFolder oldItem, @NonNull FeedWithFolder newItem) {
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
if (!oldItem.getFeed().getName().equals(newItem.getFeed().getName()))
|
||||
bundle.putString(FeedsAdapter.FEED_NAME_KEY, newItem.getFeed().getName());
|
||||
|
||||
if (!oldItem.getFolder().getName().equals(newItem.getFolder().getName()))
|
||||
bundle.putString(FeedsAdapter.FOLDER_NAME_KEY, newItem.getFolder().getName());
|
||||
|
||||
if (bundle.size() > 0)
|
||||
return bundle;
|
||||
else
|
||||
return null;
|
||||
|
||||
return newItem;
|
||||
}
|
||||
};
|
||||
|
||||
@ -97,7 +84,7 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||
} else
|
||||
viewHolder.feedDescription.setVisibility(View.GONE);
|
||||
|
||||
if (feedWithFolder.getFolder().getId() != 1)
|
||||
if (feedWithFolder.getFolder() != null)
|
||||
viewHolder.folderName.setText(feedWithFolder.getFolder().getName());
|
||||
else
|
||||
viewHolder.folderName.setText(viewHolder.itemView.getResources().getString(R.string.no_folder));
|
||||
@ -113,18 +100,15 @@ public class FeedsAdapter extends ListAdapter<FeedWithFolder, FeedsAdapter.ViewH
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull List<Object> payloads) {
|
||||
if (!payloads.isEmpty()) {
|
||||
Bundle bundle = (Bundle) payloads.get(0);
|
||||
FeedWithFolder feedWithFolder = (FeedWithFolder) payloads.get(0);
|
||||
|
||||
if (bundle.getString(FEED_NAME_KEY) != null) {
|
||||
holder.feedName.setText(bundle.getString(FEED_NAME_KEY));
|
||||
}
|
||||
holder.feedName.setText(feedWithFolder.getFeed().getName());
|
||||
|
||||
if (feedWithFolder.getFolder() != null)
|
||||
holder.folderName.setText(feedWithFolder.getFolder().getName());
|
||||
else
|
||||
holder.folderName.setText(holder.itemView.getContext().getString(R.string.no_folder));
|
||||
|
||||
if (bundle.getString(FOLDER_NAME_KEY) != null) {
|
||||
if (getItem(position).getFolder().getId() != 1)
|
||||
holder.folderName.setText(bundle.getString(FOLDER_NAME_KEY));
|
||||
else
|
||||
holder.folderName.setText(holder.itemView.getContext().getString(R.string.no_folder));
|
||||
}
|
||||
} else
|
||||
onBindViewHolder(holder, position);
|
||||
}
|
||||
|
@ -67,9 +67,13 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
|
||||
Item item = itemWithFeed.getItem();
|
||||
Item item1 = t1.getItem();
|
||||
|
||||
boolean folder = false;
|
||||
if (itemWithFeed.getFolder() != null && t1.getFolder() != null)
|
||||
folder = itemWithFeed.getFolder().getName().equals(t1.getFolder().getName());
|
||||
|
||||
return item.getTitle().equals(item1.getTitle()) &&
|
||||
itemWithFeed.getFeedName().equals(t1.getFeedName()) &&
|
||||
itemWithFeed.getFolder().getName().equals(t1.getFolder().getName()) &&
|
||||
folder &&
|
||||
item.isRead() == item1.isRead() &&
|
||||
item.isReadItLater() == item1.isReadItLater() &&
|
||||
itemWithFeed.getColor() == t1.getColor() &&
|
||||
@ -155,7 +159,7 @@ public class MainItemListAdapter extends PagedListAdapter<ItemWithFeed, MainItem
|
||||
else
|
||||
viewHolder.itemReadTime.setText(resources.getString(R.string.read_time_one_minute));
|
||||
|
||||
if (itemWithFeed.getFolder().getId() != 1)
|
||||
if (itemWithFeed.getFolder() != null)
|
||||
viewHolder.itemFolderName.setText(itemWithFeed.getFolder().getName());
|
||||
else
|
||||
viewHolder.itemFolderName.setText(resources.getString(R.string.no_folder));
|
||||
|
Loading…
x
Reference in New Issue
Block a user