Last active
December 5, 2018 10:07
-
-
Save kyodgorbek/142b77beb0166b0f25c6666db18bd409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".DetailActivity"> | |
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<android.support.v7.widget.RecyclerView | |
android:id="@+id/recycler_view" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:scrollbars="vertical" /> | |
</android.support.constraint.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DetailActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_detail); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginBottom="8dp" | |
android:layout_marginLeft="8dp" | |
android:layout_marginRight="8dp" | |
android:layout_marginTop="8dp" | |
android:paddingBottom="13dp"> | |
<TextView | |
android:id="@+id/heroId" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignParentLeft="true" | |
android:layout_alignParentStart="true" | |
android:layout_alignParentTop="true" | |
android:layout_marginLeft="17dp" | |
android:layout_marginStart="17dp" | |
android:layout_marginTop="13dp" | |
android:text="Hero Id" | |
android:textColor="@color/colorPrimaryDark" | |
android:textSize="18dp" /> | |
<TextView | |
android:id="@+id/heroName" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_alignLeft="@+id/heroId" | |
android:layout_alignStart="@+id/heroId" | |
android:layout_below="@+id/heroId" | |
android:text="Hero Name" /> | |
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LeovegasAdapter extends RecyclerView.Adapter<LeovegasAdapter.CustomViewHolder> implements Filterable { | |
private List<Hero> heros; | |
private List<Hero> filtarableList; | |
public LeovegasAdapter(List<Hero> heros) { | |
this.heros = heros; | |
filtarableList = filtarableList; | |
} | |
@Override | |
public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View itemView = LayoutInflater.from(parent.getContext()) | |
.inflate(R.layout.hero_list, parent, false); | |
return new CustomViewHolder(itemView); | |
} | |
@Override | |
public void onBindViewHolder(CustomViewHolder holder, int position) { | |
Hero hero = heros.get(position); | |
holder.heroId.setText(hero.getId()); | |
holder.heroName.setText(hero.getName()); | |
holder.heroName.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
} | |
}); | |
} | |
@Override | |
public int getItemCount() { | |
return heros.size(); | |
} | |
@Override | |
public Filter getFilter() { | |
return new Filter() { | |
@Override | |
protected FilterResults performFiltering(CharSequence charSequence) { | |
String charString = charSequence.toString(); | |
if (charString.isEmpty()) { | |
filtarableList = heros; | |
} else { | |
ArrayList<Hero> filteredList = new ArrayList<>(); | |
for (Hero hero : heros) { | |
if (hero.getId().toLowerCase().contains(charString) || hero.getName().toLowerCase().contains(charString)) { | |
filteredList.add(hero); | |
} | |
} | |
filtarableList = filteredList; | |
} | |
FilterResults filterResults = new FilterResults(); | |
filterResults.values = filtarableList; | |
return filterResults; | |
} | |
@Override | |
protected void publishResults(CharSequence constraint, FilterResults results) { | |
filtarableList = (List<Hero>) results.values; | |
notifyDataSetChanged(); | |
} | |
}; | |
} | |
public class CustomViewHolder extends RecyclerView.ViewHolder { | |
public TextView heroId, heroName; | |
public CustomViewHolder(View view) { | |
super(view); | |
heroId = (TextView) view.findViewById(R.id.heroId); | |
heroName = (TextView) view.findViewById(R.id.heroName); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
public LeovegasAdapter leovegasAdapter; | |
public static final String publicKey = "4089ee37331d8211b080b047c58f6970"; | |
public static final String privateKey = "18ccbcb58fdd12c22821f8b633a06f2b433d16c3"; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
LeoVegasInterface leoVegasInterface = LeoVegasClient.getApiService(); | |
String ts = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()); | |
String hash = Hasher.md5(ts + privateKey + publicKey); | |
Call<LeoVegas> callHeroes = leoVegasInterface.getHeroes(ts, publicKey, hash); | |
callHeroes.enqueue(new Callback<LeoVegas>() { | |
@Override | |
public void onResponse(Call<LeoVegas> call, Response<LeoVegas> response) { | |
LeoVegas leoVegas = response.body(); | |
Data data = leoVegas.getData(); | |
Hero[] heroes = data.getResults(); | |
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view); | |
leovegasAdapter = new LeovegasAdapter(Arrays.asList(heroes)); | |
RecyclerView.LayoutManager eLayoutManager = new LinearLayoutManager(getApplicationContext()); | |
recyclerView.setLayoutManager(eLayoutManager); | |
recyclerView.setAdapter(leovegasAdapter); | |
} | |
@Override | |
public void onFailure(Call<LeoVegas> call, Throwable t) { | |
} | |
}); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
getMenuInflater().inflate(R.menu.menu_main, menu); | |
MenuItem search = menu.findItem(R.id.search); | |
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search); | |
search(searchView); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
return super.onOptionsItemSelected(item); | |
} | |
private void search(SearchView searchView) { | |
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
@Override | |
public boolean onQueryTextSubmit(String query) { | |
LeoVegasInterface leoVegasInterface = LeoVegasClient.getApiService(); | |
String ts = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date()); | |
String hash = Hasher.md5(ts + privateKey + publicKey); | |
Call<LeoVegas> callHeroes = leoVegasInterface.findHeroByName(ts, publicKey, hash, query); | |
callHeroes.enqueue(new Callback<LeoVegas>() { | |
@Override | |
public void onResponse(Call<LeoVegas> call, Response<LeoVegas> response) { | |
LeoVegas leoVegas = response.body(); | |
Data data = leoVegas.getData(); | |
Hero[] heroes = data.getResults(); | |
RecyclerView recyclerView = (RecyclerView)findViewById(R.id.recycler_view); | |
leovegasAdapter = new LeovegasAdapter(Arrays.asList(heroes)); | |
RecyclerView.LayoutManager eLayoutManager = new LinearLayoutManager(getApplicationContext()); | |
recyclerView.setLayoutManager(eLayoutManager); | |
recyclerView.setAdapter(leovegasAdapter); | |
} | |
@Override | |
public void onFailure(Call<LeoVegas> call, Throwable t) { | |
} | |
}); | |
return false; | |
} | |
@Override | |
public boolean onQueryTextChange(String newText) { | |
leovegasAdapter.getFilter().filter(newText); | |
return true; | |
} | |
}); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment