Add folders names to edit feed dialog spinner

This commit is contained in:
Shinokuni 2019-02-27 16:47:32 +00:00
parent 4c538af36e
commit bd3f279d0a
8 changed files with 69 additions and 18 deletions

View File

@ -14,7 +14,7 @@ import java.util.List;
public interface FolderDao {
@Query("Select * from Folder")
List<Folder> getAllFolders();
LiveData<List<Folder>> getAllFolders();
@Insert
long insert(Folder folder);

View File

@ -6,6 +6,7 @@ import android.arch.lifecycle.LiveData;
import android.support.annotation.NonNull;
import com.readrops.app.database.Database;
import com.readrops.app.database.entities.Folder;
import com.readrops.app.database.pojo.FeedWithFolder;
import com.readrops.app.repositories.LocalFeedRepository;
@ -15,6 +16,7 @@ public class ManageFeedsViewModel extends AndroidViewModel {
private Database db;
private LiveData<List<FeedWithFolder>> feedsWithFolder;
private LiveData<List<Folder>> folders;
private LocalFeedRepository repository;
public ManageFeedsViewModel(@NonNull Application application) {
@ -23,6 +25,7 @@ public class ManageFeedsViewModel extends AndroidViewModel {
repository = new LocalFeedRepository(application);
feedsWithFolder = db.feedDao().getAllFeedsWithFolder();
folders = db.folderDao().getAllFolders();
}
public LiveData<List<FeedWithFolder>> getFeedsWithFolder() {
@ -32,4 +35,8 @@ public class ManageFeedsViewModel extends AndroidViewModel {
public void updateFeedWithFolder(FeedWithFolder feedWithFolder) {
repository.updateFeedWithFolder(feedWithFolder);
}
public LiveData<List<Folder>> getFolders() {
return folders;
}
}

View File

@ -8,20 +8,32 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TextInputEditText;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.readrops.app.R;
import com.readrops.app.database.entities.Feed;
import com.readrops.app.database.entities.Folder;
import com.readrops.app.database.pojo.FeedWithFolder;
import com.readrops.app.viewmodels.ManageFeedsViewModel;
public class EditFeedDialog extends DialogFragment {
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
public class EditFeedDialog extends DialogFragment implements AdapterView.OnItemSelectedListener {
private TextInputEditText feedName;
private TextInputEditText feedUrl;
private Spinner folder;
Map<String, Integer> values;
private FeedWithFolder feedWithFolder;
private ManageFeedsViewModel viewModel;
@ -43,9 +55,27 @@ public class EditFeedDialog extends DialogFragment {
viewModel.updateFeedWithFolder(feedWithFolder);
});
builder.setView(v);
fillData(v);
viewModel.getFolders().observe(this, folders -> {
values = new HashMap<>();
for (Folder folder : folders) {
if (folder.getId() != 1)
values.put(folder.getName(), folder.getId());
else
values.put(getString(R.string.no_folder), 1);
}
ArrayAdapter<String> spinnerData = new ArrayAdapter<String>(getActivity(),
android.R.layout.simple_spinner_dropdown_item, new ArrayList<>(values.keySet()));
spinnerData.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
folder.setAdapter(spinnerData);
folder.setOnItemSelectedListener(this);
});
return builder.create();
}
@ -58,5 +88,14 @@ public class EditFeedDialog extends DialogFragment {
feedUrl.setText(feedWithFolder.getFeed().getUrl());
}
@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));
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}

View File

@ -49,7 +49,8 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
.diskCacheStrategy(DiskCacheStrategy.ALL)
.placeholder(R.drawable.ic_rss_feed)
.into(holder.feedIcon);
}
} else
holder.feedIcon.setImageResource(R.drawable.ic_rss_feed);
holder.feedName.setText(feedWithFolder.getFeed().getName());
if (feedWithFolder.getFeed().getDescription() != null) {
@ -58,7 +59,10 @@ public class FeedWithFolderItem extends ModelAbstractItem<FeedWithFolder, FeedWi
} else
holder.feedDescription.setVisibility(View.GONE);
holder.folderName.setText(feedWithFolder.getFolder().getName());
if (feedWithFolder.getFolder().getId() != 1)
holder.folderName.setText(feedWithFolder.getFolder().getName());
else
holder.folderName.setText(holder.itemView.getResources().getString(R.string.no_folder));
holder.editFeed.setOnClickListener(v -> listener.onEdit(feedWithFolder));
holder.deleteFeed.setOnClickListener(v -> listener.onDelete(feedWithFolder));

View File

@ -48,17 +48,16 @@
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"/>
android:textAppearance="@style/TextAppearance.Design.Hint"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_feed_url_textinputlayout" />
<Spinner
android:id="@+id/edit_feed_folder_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.514"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit_feed_folder" />

View File

@ -7,13 +7,15 @@
android:layout_marginStart="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:padding="6dp">
<RelativeLayout
@ -34,8 +36,8 @@
style="@style/Base.TextAppearance.AppCompat.Subhead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/feed_layout_icon"
android:layout_toStartOf="@id/feed_layout_delete"
android:layout_toEndOf="@id/feed_layout_icon"
android:ellipsize="end"
android:maxLines="2"
android:minLines="1"
@ -53,8 +55,8 @@
android:maxLines="3"
android:minLines="1"
android:visibility="visible"
tools:visibility="visible"
tools:text="This is a feed description" />
tools:text="This is a feed description"
tools:visibility="visible" />
<ImageView
android:id="@+id/feed_layout_delete"
@ -69,8 +71,8 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_below="@id/feed_layout_first_part">
android:layout_below="@id/feed_layout_first_part"
android:layout_marginTop="6dp">
<TextView
android:id="@+id/feed_layout_folder"
@ -79,8 +81,8 @@
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/feed_layout_edit"
android:maxLines="1"
android:ellipsize="end"
android:maxLines="1"
tools:text="Folder 1" />
<ImageView
@ -92,11 +94,9 @@
android:src="@drawable/ic_edit_grey" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>

View File

@ -26,6 +26,7 @@
<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>
<string name="folder">Dossier</string>
<string name="no_folder">Pas de dossier</string>
</resources>

View File

@ -29,4 +29,5 @@
<string name="feed_name">Feed name</string>
<string name="edit_feed">Edit feed</string>
<string name="folder">Folder</string>
<string name="no_folder">No folder</string>
</resources>