I have an app that depends heavily on recyclerview.. Each activity has different model and layout for them.. So do I need to write separate adapters for all of them.?? Or could I have a base adapter which can have on create view holder, onbind view holder which would reduce the amount of repetitive code..PS. I also need onclick listener so, I wanted to include that in the base adapter..
What is the best way?? And if I can write a base adapter please give me some code samples..
Thanks in Advance...
Each activity has different model and layout for them.. So do I need
to write separate adapters for all of them
Adapters are responsible for providing views that represent items in a data set, used by the RecyclerView. Now if those items in your ReyclerView are same across all the Activities then you can just have a single RecyclerView.Adapter
I also need onclick listener so, I wanted to include that in the base
adapter.. What is the best way??
You can check this SO post for detailed implementation, but I am summarizing it briefly.
RecyclerView recyclerView = findViewById(R.id.recycler);
recyclerView.addOnItemTouchListener(
new RecyclerItemClickListener(context, new RecyclerItemClickListener.OnItemClickListener() {
#Override public void onItemClick(View view, int position) {
// do whatever
}
})
);
And provide RecyclerItemClickListener class, that implements RecyclerView.OnItemTouchListener interface
And if I can write a base adapter please give me some code samples.
You need to clarify what exactly needs to be implemented in BaseAdapter for anyone to help you
yes it is possible
enter code here holder.button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (modelArrayList.get(position).heading.equals("maps")){
Intent intent = new Intent(holder.button.getContext(),MainActivity2.class);
holder.button.getContext().startActivity(intent);
}
if (modelArrayList.get(position).heading.equals("calls")){
Intent intent = new Intent(holder.button.getContext(),MainActivity3.class);
holder.button.getContext().startActivity(intent);
}
Related
I need help on this issue. I am upgrading hybris to version 2105, I ran into the problem that the 'DefaultSetupSyncJobService' class has changed its methods from 'SyncItemJob' to 'SyncItemJobModel'. How could I adapt these classes so that the catalogs are correctly synchronized ?
The new implementation for synchronization is stored in CatalogSynchronizationService.synchronizeFully(source,target) for a full synchronization. There are other methods to perform partial syncs with a select subset of items aswell in that service.
Do note that this will always create new SyncItemCronJobModel objects instead of reusing an existing syncjob. Depending on what you want, you can modify the implementation somewhat to reuse the same syncjob. The code then becomes something like this:
catalogSynchronizationService.getSyncJob(source, target, null);
instead of calling createSyncItemJob(...)
The rest is the same as the original implementation. So customized implementation of synchronizeFully could look something like(Extend from DefaultCatalogSynchronizationService)
public void synchronizeFully(final CatalogVersionModel source, final CatalogVersionModel target) {
final SyncItemJobModel syncJob = getSyncJob(source, target, null);
final SyncItemCronJobModel syncCronJob = createSyncCronJob(syncJob);
cronJobService.performCronJob(syncCronJob, true);
}
Hi all I'm new to SO and to Springbatch. I have written a batch job with Classifer that updates a table in two different ways (i.e. two ItemWriters) depending on what's retrieved through the ItemReader and all that's working fine. Now, I want to perform some logic after the ItemWriters are done updating. I want to do some logging and update another table with the same set of data retrieved previously. How can I achieve this? I looked at ItemWriterListener but seems it cannot perform data specific logics. I did some searching but with no luck. Any help would be appreciated. Thanks in advance!!
You can try using StepExecutionListener implementing it to your Writer Class to execute logic once ItemWriter is done with the execution. Below is a snippet of the ItemWriter for your reference,
public class TestWriter implements ItemWriter<Test>, StepExecutionListener {
#Override
public void beforeStep(StepExecution stepExecution) {
}
#Override
public void write(List<? extends Test> items) throws Exception {
// Logic of Writer
}
#Override
public ExitStatus afterStep(StepExecution stepExecution) {
// You can perform post logic after writer here inside afterStep based on your requirements
// Return custom exit status based on the run
return ExitStatus.COMPLETED;
}
}
Now, I want to perform some logic after the ItemWriters are done updating. I want to do some logging and update another table with the same set of data retrieved previously. How can I achieve this? I looked at ItemWriterListener but seems it cannot perform data specific logics.
Since you want to do something with the same items retrieved previously, you need to use a ItemWriteListener#afterWrite as this method gives you access to the items that have just been written.
EDIT: Add details about the failure case based on comments
If the transaction is rolled back, the method ItemWriteListener#onWriteError will be called. Please find more details about this in the common patterns section.
I'm new at Apache Isis and I'm stuck.
I want to create my own submit form with editable parameters for search some entities and a grid with search results below.
Firstly, I created #DomainObject(nature=Nature.VIEW_MODEL) with search results collection, parameters for search and #Action for search.
After deeper research, I found out strict implementations for actions (For exapmle ActionParametersFormPanel). Can I use #Action and edit #DomainObject properties(my search parameters for action) without prompts?
Can I implement it by layout.xml?
Then I tried to change a component as described here: 6.2 Replacing page elements, but I was confused which ComponentType and IModel should I use, maybe ComponentType.PARAMETERS and ActionModel or implement my own IModel for my case.
Should I implement my own Wicket page for search and register it by PageClassList interface, as described here: 6.3 Custom pages
As I understood I need to replace page class for one of PageType, but which one should I change?
So, the question is how to implement such issues properly? Which way should I choose?
Thank you!
===================== UPDATE ===================
I've implemented HomePageViewModel in this way:
#DomainObject(
nature = Nature.VIEW_MODEL,
objectType = "homepage.HomePageViewModel"
)
#Setter #Getter
public class HomePageViewModel {
private String id;
private String type;
public TranslatableString title() {
return TranslatableString.tr("My custom search");
}
public List<SimpleObject> getObjects() {
return simpleObjectRepository.listAll();
}
#Action
public HomePageViewModel search(
#ParameterLayout(named = "Id")
String id,
#ParameterLayout(named = "Type")
String type
){
setId(id);
setType(type);
// finding objects by entered parameters is not implemented yet
return this;
}
#javax.inject.Inject
SimpleObjectRepository simpleObjectRepository;
}
And it works in this way:
I want to implement a built-in-ViewModel action with parameters without any dialog windows, smth like this:
1) Is it possible to create smth like ActionParametersFormPanel based on ComponentType.PARAMETERS and ActionModel and use this component as #Action in my ViewModel?
2) Or I should use, as you said, ComponentType.COLLECTION_CONTENTS? As I inderstand my search result grid and my search input panel will be like ONE my stub component?
Thank you.
We have a JIRA ticket in our JIRA to implement a filterable/searchable component, but it hasn't yet made it to the top of the list for implementation.
As an alternative, you could have a view model that provides the parameters you want to filter on as properties, with a table underneath. (I see you asked another question here on SO re properties on view models, so perhaps you are moving in that direction also... I've answered that question).
If you do want to have a stab at implementing that ticket, then the ComponentTYpe to use is COLLECTION_CONTENTS. If you take a look at the isisaddons, eg for excel or gmap3 then it might help get you started.
======= UPDATE TO ANSWER (based on update made to query) ==========
I have some good news for you. v1.15.0-SNAPSHOT, which should be released in the couple of weeks, has support for "inline prompts". You should find these give a user experience very similar to what you are after, with no further work needed on your part.
To try it out, check out the current trunk, and then load the simpleapp (in examples/application/simpleapp). You should see that editing properties and invoking actions uses the new inline prompt style.
HTH
Dan
In my silver light application i have two classes: Container and Field.
Container contains a list of Fields. Now,
whenever an Field(in the list) receives
a message I want to notify Container object to
perform some logic.
Field object should not contain any reference of Container. i need to achieve this using INotifyPropertyChanged.
Please suggest a simple solution using INotifyPropertyChanged.
Your Container object could subscribe to the PropertyChanged event of each of it's child Field objects.
If it's not a property change your interested in directly you could implement your own custom event for the Field object.
It's hard to given an example without knowing your exact situation... but here goes.
E.g Pseudo-code: (on the Container object)
public void AddField(Field field)
{
// attach to the new fields property changed event
field.PropertyChanged += OnFieldPropertyChanged;
// add the new field to this container's collection
this.Fields.Add(field);
}
private void OnFieldPropertyChanged(object sender, PropertyChangedEventArgs e)
{
// do something
}
You may also want to check out ObservableCollections.
I am using wicket 1.4.9 and implemented spring + wicket auth-role and using #AuthorizeInstantiation based on roles on pages. I have multiple custom roles.
I have followed this link to implement the basics:
https://cwiki.apache.org/WICKET/spring-security-and-wicket-auth-roles.html
After that I have implemented my own UserDetailsService to have my own roles/users from database.
Now, How can I impose controls on roles with components eg, Links,Buttons ? like
link A can be accessed only by SUPER_USER, DR_MANAGER. (roles comes from database).
I have done like this and it seems to work, but is that the good way to do this? OrbitWebSession is of type AuthenticatedWebSession.
#Override
public boolean isVisible() {
if(OrbitWebSession.get().getRoles().hasRole("SUPER_USER")){
return true;
}
return false;
}
thanks.
Overriding isVisible all the time is a major pain. Take a look at MetaDataRoleAuthorizationStrategy instead. You call authorize(Component component, Action action, String roles) with Action RENDER, and the roles you want to allow. This way the component, whatever it is, is automatically hidden for other roles provided that the authorization strategy is registered in your webapplication. Basically it does the same thing as Holms answer, except you don't have to subclass anything.
You are in the right track, the only change I would do is:
#Override
public boolean isVisible() {
return super.isVisible() && OrbitWebSession.get().getRoles().hasRole("SUPER_USER");
}
That way you don't accidentally override its default visible behavior for example if the parent component is not visible.
Using the #AuthorizeAction annotation you can control wether the component is rendered or not based on roles. It's quite easy to use, but you have to subclass the component that you want to authorize.
#AuthorizeAction(action = Action.RENDER, roles = { "SUPER_USER", "DR_MANAGER" })
class UserAdminPageLink extends BookmarkablePageLink<String> {
//Implementation…
}
add(new UserAdminPageLink("UserAdminPageLink", UserAdminPage.class));
Check out Wicket Examples - Authorization for some working code.