Kotlin. Room. Recyclerview. Сreating a recipe book application - kotlin

I need to implement the addition of ingredients. We have the first fragment of StartFragment on which the names of recipes are displayed in the recyclrewview from the Room Database. AddFragment with the creation of a recipe with the addition of photos and descriptions. There were no problems with this. But how to implement the addition of ingredients.
I tried to create a second table in Rom and another recyclerview on the AddFragment fragment with creation. The idea is that when you create a recipe, you also enter the name of the ingredient in the EditText and when you click on the button, it writes it to the database and outputs it to the recyclerview. But I don't understand how to clean the recycler view without removing the ingredients from the room, because when you click on the "create recipe" button, ingredients from the previous recipe appear in the recyclerview fragment. I also don't quite understand how to pass it to the Update Fragment, because you need to pass the ingredients of a suitable recipe. In general, tell me how you would solve this problem.

Related

Intents with extras have a series of params that we don't use - what's their purpose?

From my LandingClass (which contains a ListView called myList), whenever an item from the ListView is clicked, we want to trigger another activity (DetailedActivity), so the code should look like this:
myList.setOnItemClickListener{ view ->
val intent = Intent(this, DetailedActivity::class.java)
startActivity(intent)
}
Now, if we needed to provide additional (extra) info to the Detailed class, such as the position of the element from the ListView that we just clicked, the code would look like this:
myList.setOnItemClickListener{ parent, view, position, id ->
val intent = Intent(this, DetailedActivity::class.java)
intent.putExtra("thePosition (text)", position)
startActivity(intent)
}
So my question is why in case of sending the extra intent, we need a parent and an id, I don't see them being used anywhere... ?
I don't see some examples in the doc to help me understand. So some questions:
What do I need the parent, view and id for?
If I click the 3rd element, the position (int) sent I expect to be 2 if the list is 0-index based, right?
If I wanted to send a Bundle with more complex information than the position, how would my code (with extra) change? Considering that all params have a defined type, like id is type long. WHat if I wanted to send a paragraph of text instead of the id?
https://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener - the official docs showing the method signature
From my research (see above link) I noticed that:
parent AdapterView: The AdapterView where the click happened.
Why would we need this? Where is the assignment done, or is it implicitly known?
view View: The view within the AdapterView that was clicked (this will be a view provided by the adapter)
position int: The position of the view in the adapter.
id long: The row id of the item that was clicked.
Still this doesn't clarify how to send additional complex info to the DetailedActivity - not a position (int) or an id (long) but maybe an array of complex objects, or a paragraph of text or something else...
Say that your ListView contains the headers of some news articles.
By clicking on a list item you want to be redirected to a details activity where you can read the full text of the article.
All headers and articles are stored in a List of Article objects, each containing the header and the text of the article.
How will you identify which article's header was clicked?
This is the purpose of the arguments position and id.
Depending on your needs you will choose one or the other, so you will fetch from the List the article's text and pass it as an extra to the Intent that opens the details activity.
You know that you can create very complex ListViews where each item is a container of multiple views or a ListView itself.
This is when you will need the parent and view arguments.
All this is application specific.
If you don't need it fine, but the arguments are there for you to use if and when you will need them.
Now for:
If I wanted to send a Bundle with more complex information
and
Still this doesn't clarify how to send additional complex info to the
DetailedActivity
This is your responsibility to construct a Serializable or Parcelable Bundle and put it as an extra to the Intent and has nothing to do with the available arguments of setOnItemClickListener. There are a lot of examples here in SO and other sites for serializing objects to put as extras, like
Cannot pass custom Object in an Intent: The Method Put Extra is Ambiguous for the type Intent
and
How to send an object from one Android Activity to another using Intents?
Follow the standards and you will be able to send this complex info via intent.

MVC/Bootstrap - Render data in modal pop-up

I'm fairly new to MVC and Bootstrap and looking for some advice on what I imagine is a fairly simple scenario...
I've got two models:
Person
PersonDetails
The two models share a common primary/foreign key reference (PersonID)
The view for Person simply renders a list of names:
John
Tom
Michael
What I'm looking to do is render a modal pop-up when someone clicks on one of these names, and display the corresponding data from PersonDetails (based on the common PersonID relationship).
I've got the simple views working, as well as a quick example modal pop-up. What I'm having trouble with at the moment is how to go about getting the PersonDetails data into the modal pop-up.
Can someone give me some pointers as to how I should best go about achieving this? As I mentioned I'm fairly new to MVC/Bootstrap so any information would be much appreciated.
I would use a partial view to store the modal header, body and footer and pass the person name (or ID) to the controller using an AJAX call, returning a PartialView, which will will be placed in your modal div on success.
This SO answer explains it pretty well:
https://stackoverflow.com/a/16011752/3105807

Custom odoo module - how to make a table

I am creating a custom module with additional part numbers on a separate tab in the products screen. I have built the module, but am having trouble figuring out how to display the information so it matches the layout in the attached image. I have tried tree view but have not been able to get the fields on the same line. Can this only be accomplished through css or is there a table view that I am not aware of?
I also need to make sure that all of the information in row 1 stays tethered together for additional forms, etc. My plan is to make the field names for each row end with a different number (i.e. x_mfrname1,x_mfrpn1,x_mfrname2,x_mfrpn2, etc.). Can somebody please just tell me if I am on the right track. This is the initial Odoo setup for a client of mine and I don't want them to come back to me down the line and find out I forgot something. I have been scouring the internet and reading a few books but I am not completely confident.
Here is a link to a layout of what I am talking about:
MFG Part Number Tab
Thanks!
class sub_part_details(models.Model)
_name='sub.part.detail'
primary_pn=fields.Boolean('Primary P/N')
obsolete=fields.Boolean('Obsolete')
pn=fields.Char('P/N')
desc=fields.Char('Description')
upgrade=fields.Char('Upgrade')
part_detail_id=fields.Many2one('part.details')
class part_details(models.Model)
_name='part.details'
cat=fields.Char('CAT')
sub_ass=fields.Char('Subassembly')
main_ass=fields.Char('Main Assembly')
notes=fields.Text('Notes')
sub_details_ids=fields.One2Many(''sub.part.detail','part_detail_id')
It might be helpful

YouTrack issues list Detail Level manipulation

Question: is it possible to manipulate with issues list detail level some way other than button?
Story: there is a button in issue list where you can choose the presentation of issues in the list: TreeView, One-Line View, Compact View, Detailed View. I would like to give a link or query that specifies the view. Something like:
http://link/issues?q=in:Pro_LG view:DetailedView
http://link/issues?q=in:Documentation view:TreeView
Because if I present (share link, show people) some hierarchical task, I would like it to look like TreeView. And when I present the subset of issues (issues for build) I would like them to be in DetailedView.
And it is not very convenient to tell people "And don't forget to switch to tree view, after you open my link" =)
It's not possible now. Here's the respective request: https://youtrack.jetbrains.com/issue/JT-15305.

Inherit form view from a predefined module

I want to create my own module which is an extension of sale.order. I want to have a form view which is like sale order view with few additional fields,
My problem is that when I inherit the sale order view and add say three extra fields these fields comes by default in the Original Sale Order form view too.
is this the default behaviour or am I doing something wrong ?
What should I do to achieve what I want.
If you inherit the view and add some fields using 'xpath' , than it will change the original view by installing your new module. This is the application of view inheritance. If you want to keep the original form view as it is after the installation of your module and want to define another which have some extra fields only for your customized module, you have to make a different form view without inheriting the original one. May be in future , there will be a facility of extending an existing form view, but right now you can't do that.
I think you need to check view_id in your code may be a view_id is common so you are updating a default view of sale order.
When you are inherit one view of sale order a functionality will be added in a form not whole view will be generated.
Still this is not solution send me your code i will review it.