Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from iZettle/feature/fix_adapter
Browse files Browse the repository at this point in the history
Feature/fix adapter
  • Loading branch information
warting authored Jul 10, 2017
2 parents ede645e + 152948e commit 504281c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public ConfigurationViewHolder onCreateViewHolder(ViewGroup parent, int viewType
switch (viewType) {
case VIEW_TYPE_GENERAL: {
ConfigurationListItemBinding binding = ConfigurationListItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
return new ConfigurationViewHolder(binding);
return new ConfigurationViewHolder(binding, null);
}
default: {
throw new IllegalStateException("Unknown view type");
Expand All @@ -65,10 +65,14 @@ public void onBindViewHolder(final ConfigurationViewHolder holder, int position)

@Override
public void onBindViewHolder(final ConfigurationViewHolder viewHolder, int position, List<Object> payloads) {
final WrenchConfiguration configuration = items.get(position);
if (viewHolder.configuration != null) {
model.getConfigurationValues(viewHolder.configuration.id()).removeObservers(lifecycleOwner);
}

viewHolder.configuration = items.get(viewHolder.getAdapterPosition());

viewHolder.binding.title.setText(configuration.key());
model.getConfigurationValues(configuration.id()).observe(lifecycleOwner, wrenchConfigurationValues -> {
viewHolder.binding.title.setText(viewHolder.configuration.key());
model.getConfigurationValues(viewHolder.configuration.id()).observe(lifecycleOwner, wrenchConfigurationValues -> {
if (wrenchConfigurationValues == null) {
return;
}
Expand All @@ -79,7 +83,6 @@ public void onBindViewHolder(final ConfigurationViewHolder viewHolder, int posit
WrenchConfigurationValue defaultScopedItem = getItemForScope(defaultScope, wrenchConfigurationValues);
if (defaultScopedItem == null) {
return;
// throw new RuntimeException("Could not find a default value for configuration " + configuration.key());
}

viewHolder.binding.defaultValue.setText(defaultScopedItem.getValue());
Expand All @@ -94,9 +97,8 @@ public void onBindViewHolder(final ConfigurationViewHolder viewHolder, int posit
viewHolder.binding.defaultValue.setPaintFlags(viewHolder.binding.defaultValue.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
viewHolder.binding.customValue.setVisibility(View.GONE);
}

viewHolder.binding.getRoot().setOnClickListener(view -> listener.configurationClicked(configuration));
});
viewHolder.binding.getRoot().setOnClickListener(view -> listener.configurationClicked(items.get(viewHolder.getAdapterPosition())));
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

import android.support.v7.widget.RecyclerView;

import com.izettle.wrench.database.WrenchConfiguration;
import com.izettle.wrench.databinding.ConfigurationListItemBinding;

public class ConfigurationViewHolder extends RecyclerView.ViewHolder {
public final ConfigurationListItemBinding binding;
public WrenchConfiguration configuration;

ConfigurationViewHolder(ConfigurationListItemBinding binding) {
ConfigurationViewHolder(ConfigurationListItemBinding binding, WrenchConfiguration configuration) {
super(binding.getRoot());
this.binding = binding;
this.configuration = configuration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
});

model.getDefaultScopeLiveData().observe(this, scope -> {
if (scope != null) {
if (scope != null && fragmentConfigurationsBinding.list.getAdapter() != null) {
fragmentConfigurationsBinding.list.getAdapter().notifyDataSetChanged();
}
});

model.getSelectedScopeLiveData().observe(this, scope -> {
if (scope != null) {
if (scope != null && fragmentConfigurationsBinding.list.getAdapter() != null) {
fragmentConfigurationsBinding.list.getAdapter().notifyDataSetChanged();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public interface WrenchScopeDao {
@Query("SELECT * FROM " + ScopeTable.TABLE_NAME + " WHERE " + ScopeTable.COL_APP_ID + " = (:applicationId) AND " + ScopeTable.COL_NAME + " = '" + WrenchScope.SCOPE_DEFAULT + "'")
WrenchScope getDefaultScope(long applicationId);

@Query("SELECT * FROM " + ScopeTable.TABLE_NAME + " WHERE " + ScopeTable.COL_ID + " = (:scopeId)")
LiveData<WrenchScope> getScope(long scopeId);

@Update
void update(WrenchScope scope);
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Cursor query(@NonNull Uri uri, String[] projection, String selection, Str
cursor.close();

WrenchScope defaultScope = getDefaultScope(getContext(), wrenchDatabase, callingApplication.id());
cursor = wrenchDatabase.configurationDao().getBolt(Uri.decode(uri.getLastPathSegment()), defaultScope.id());
cursor = wrenchDatabase.configurationDao().getBolt(uri.getLastPathSegment(), defaultScope.id());
}

break;
Expand Down

0 comments on commit 504281c

Please sign in to comment.