Skip to content

Commit

Permalink
List of sample companies and new methods SearchLiveo
Browse files Browse the repository at this point in the history
  • Loading branch information
zirouan committed Mar 20, 2018
1 parent 1c12ef6 commit 2f0ed32
Show file tree
Hide file tree
Showing 20 changed files with 412 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,56 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import br.com.liveo.searchliveo.SearchLiveo;
import br.com.liveo.searchview_materialdesign.base.BaseActivity;
import br.com.liveo.searchview_materialdesign.databinding.ActivityMainBinding;
import br.com.liveo.searchview_materialdesign.model.Company;

public class MainActivity extends AppCompatActivity implements SearchLiveo.OnSearchListener {
public class MainActivity extends BaseActivity implements SearchLiveo.OnSearchListener {

private SearchLiveo mSearchLiveo;
private MainAdapter mAdapter;
private ActivityMainBinding mBinding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
this.onInitView();
}

@Override
protected void onPostCreate(@Nullable Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
this.fetchCompanies();
}

private void onInitView() {
mBinding = (ActivityMainBinding) this.bindView(R.layout.activity_main);
this.onInitToolbar(mBinding.toolbar, R.string.app_name);

mSearchLiveo = findViewById(R.id.search_liveo);
mSearchLiveo.with(this).
mBinding.searchLiveo.
with(this).
removeMinToSearch().
removeSearchDelay().
build();

if (mBinding.includeMain != null) {
mBinding.includeMain.recyclerView.setHasFixedSize(true);
mBinding.includeMain.recyclerView.setLayoutManager(new LinearLayoutManager(this));

mBinding.includeMain.swipeContainer.setEnabled(false);
mBinding.includeMain.swipeContainer.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent,
R.color.colorPrimary, R.color.colorAccent);
}
}

private void fetchCompanies() {
mAdapter = new MainAdapter(Company.getCompanies());
mBinding.includeMain.recyclerView.setAdapter(mAdapter);
}

@Override
Expand All @@ -51,9 +66,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
if (mSearchLiveo != null) {
mSearchLiveo.show();
}
mBinding.searchLiveo.show();
return true;
}

Expand All @@ -62,17 +75,17 @@ public boolean onOptionsItemSelected(MenuItem item) {

@Override
public void changedSearch(CharSequence text) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
if (mAdapter != null) {
mAdapter.searchCompanyes(text);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (data != null) {
if (requestCode == SearchLiveo.REQUEST_CODE_SPEECH_INPUT) {
if (mSearchLiveo != null) {
mSearchLiveo.resultVoice(requestCode, resultCode, data);
}
mBinding.searchLiveo.resultVoice(requestCode, resultCode, data);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package br.com.liveo.searchview_materialdesign;

import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Locale;

import br.com.liveo.searchview_materialdesign.databinding.ContentMainItemBinding;
import br.com.liveo.searchview_materialdesign.model.Company;

/**
* Created by rudsonlima on 19/03/18.
*/

public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {

private ArrayList<Company> mCompanys;
private ArrayList<Company> mSearchCompanys;

public MainAdapter(ArrayList<Company> Companys) {
this.mCompanys = Companys;
this.mSearchCompanys = new ArrayList<>();
this.mSearchCompanys.addAll(this.mCompanys);
}

static class ViewHolder extends RecyclerView.ViewHolder {
ViewHolder(View itemView) {
super(itemView);
}

ContentMainItemBinding getBinding() {
return DataBindingUtil.getBinding(itemView);
}
}

@NonNull
@Override
public MainAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder(DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()),
R.layout.content_main_item, parent, false).getRoot());
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Company company = mCompanys.get(holder.getAdapterPosition());

holder.getBinding().setVariable(BR.company, company);
holder.getBinding().executePendingBindings();
}

@Override
public int getItemCount() {
return (mCompanys == null ? 0 : mCompanys.size());
}

private static String removeAccent(String text) {
String result = Normalizer.normalize(text, Normalizer.Form.NFD);
return result.replaceAll("[^\\p{ASCII}]", "");
}

void searchCompanyes(CharSequence charText) {

charText = removeAccent((String) charText).toLowerCase(Locale.getDefault());

mCompanys.clear();
if (charText.length() == 0) {
mCompanys.addAll(mSearchCompanys);
} else {
for (Company Company : mSearchCompanys) {
String name = removeAccent(Company.getName());
if (name.toLowerCase(Locale.getDefault()).contains(charText)) {
mCompanys.add(Company);
}
}
}

notifyDataSetChanged();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package br.com.liveo.searchview_materialdesign.base;

import android.annotation.SuppressLint;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.WindowManager;

import br.com.liveo.searchview_materialdesign.R;

@SuppressLint("Registered")
public class BaseActivity extends AppCompatActivity {

public static boolean mIsTablet;
public static boolean mIsLandscape;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

protected ViewDataBinding bindView(int layout) {
return DataBindingUtil.setContentView(this, layout);
}

//region Methods Toolbar
public void onInitToolbar(Toolbar toolBar) {
onInitToolbar(toolBar, getString(R.string.clear), -1, false);
}

public void onInitToolbar(Toolbar toolBar, String title) {
onInitToolbar(toolBar, title, -1, false);
}

public void onInitToolbar(Toolbar toolBar, int title) {
onInitToolbar(toolBar, title, -1, false);
}

public void onInitToolbar(Toolbar toolBar, int title, int icon) {
onInitToolbar(toolBar, getString(title), icon, true);
}

public void onInitToolbar(Toolbar toolBar, String title, boolean displayHome) {
onInitToolbar(toolBar, title, -1, displayHome);
}

public void onInitToolbar(Toolbar toolBar, int title, boolean displayHome) {
onInitToolbar(toolBar, title, -1, displayHome);
}

public void onInitToolbar(Toolbar toolBar, int title, int icon, boolean displayHome) {
onInitToolbar(toolBar, getString(title), icon, displayHome);
}

public void onInitToolbar(Toolbar toolBar, String title, int icon, boolean displayHome) {

if (toolBar != null) {
setSupportActionBar(toolBar);
ActionBar actionBar = getSupportActionBar();

if (actionBar != null) {
actionBar.setTitle(title);
actionBar.setDisplayShowHomeEnabled(displayHome);
actionBar.setDisplayHomeAsUpEnabled(displayHome);
if (icon != -1 && displayHome) {
toolBar.setNavigationIcon(ContextCompat.getDrawable(this, icon));
}
}
}
}
//endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package br.com.liveo.searchview_materialdesign.model;

import android.databinding.BindingAdapter;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v7.widget.AppCompatImageView;

import java.util.ArrayList;

import br.com.liveo.searchview_materialdesign.R;

/**
* Created by rudsonlima on 19/03/18.
*/

public class Company implements Parcelable {

private int icon;
private String name;

@BindingAdapter("icon")
public static void icon(AppCompatImageView imageView, int icon) {
imageView.setImageResource(icon);
}

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(this.getIcon());
dest.writeString(this.getName());
}

private Company(String name, int icon) {
this.setName(name);
this.setIcon(icon);
}

private Company(Parcel in) {
this.setIcon(in.readInt());
this.setName(in.readString());
}

public static final Parcelable.Creator<Company> CREATOR = new Parcelable.Creator<Company>() {
@Override
public Company createFromParcel(Parcel source) {
return new Company(source);
}

@Override
public Company[] newArray(int size) {
return new Company[size];
}
};

public int getIcon() {
return icon;
}

public void setIcon(int icon) {
this.icon = icon;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public static ArrayList<Company> getCompanies(){
ArrayList<Company> companies = new ArrayList<>();

companies.add(new Company("Appple", R.drawable.ic_apple));
companies.add(new Company("Google", R.drawable.ic_google));
companies.add(new Company("Github", R.drawable.ic_github));
companies.add(new Company("Facebook", R.drawable.ic_facebook));
companies.add(new Company("Instagram", R.drawable.ic_instagram));
companies.add(new Company("Linkedin", R.drawable.ic_linkedin));
companies.add(new Company("Twitter", R.drawable.ic_twitter));
companies.add(new Company("Microsoft", R.drawable.ic_microsoft));

return companies;
}
}
Binary file added demo/src/main/res/drawable/ic_apple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/src/main/res/drawable/ic_facebook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/src/main/res/drawable/ic_github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/src/main/res/drawable/ic_google.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/src/main/res/drawable/ic_instagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/src/main/res/drawable/ic_linkedin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added demo/src/main/res/drawable/ic_microsoft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion demo/src/main/res/drawable/ic_search_black_24dp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
</vector>
Binary file added demo/src/main/res/drawable/ic_twitter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2f0ed32

Please sign in to comment.