Last active
August 29, 2016 15:50
-
-
Save DANISSIMO9699/0bdf1753dbb9caa2e5f31545a01aeb47 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
// Class sending the list | |
public class ChordsListActivity extends AppCompatActivity implements PopupMenu.OnMenuItemClickListener { | |
ArrayList<Accordo> chords; | |
ImageButton cerca; | |
RecyclerView recyclerView; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_chords_list); | |
/** Lista di accordi */ | |
chords = new ArrayList<>(); | |
ChordsList list = new ChordsList(); | |
list.createList(); | |
chords = list.getList(); | |
/** gestisce le pubblicita */ | |
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544/6300978111"); | |
AdView listBanner = (AdView) findViewById(R.id.chords_list_banner); | |
AdRequest adRequest = new AdRequest.Builder().build(); | |
listBanner.loadAd(adRequest); | |
/** sistema la lista nella RecyclerView */ | |
recyclerView = (RecyclerView) findViewById(R.id.chords_recycler); | |
recyclerView.setLayoutManager(new LinearLayoutManager(ChordsListActivity.this, LinearLayoutManager.VERTICAL, false)); | |
recyclerView.setHasFixedSize(true); | |
final ChordsListAdapter adapter = new ChordsListAdapter (this, chords); | |
recyclerView.setAdapter(adapter); | |
/** gestisce cosa succede quando un elemento della RecyclerView viene toccato */ | |
ItemClickSupport.addTo(recyclerView).setOnItemClickListener(new ItemClickSupport.OnItemClickListener(){ | |
@Override | |
public void onItemClicked(RecyclerView recyclerView, int position, View v) { | |
Intent intent = new Intent(ChordsListActivity.this, ChordActivity.class); | |
Bundle bundle = new Bundle(); | |
bundle.putParcelable("selected", chords.get(position)); | |
intent.putExtras(bundle); | |
startActivity(intent); | |
} | |
}); | |
/** legge il valore di Show_Dialog e se e' falso fa apparire la legenda */ | |
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); | |
Boolean showDialog = sharedPref.getBoolean("Show_dialog", true); | |
Intent legendaIntent = new Intent(ChordsListActivity.this, PopUpInfoActivity.class); | |
if(showDialog) | |
startActivity(legendaIntent); | |
/** gestisce cosa succede quando si preme il tasto cerca */ | |
cerca = (ImageButton) findViewById(R.id.search); | |
cerca.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent intent = new Intent(ChordsListActivity.this, SearchActivity.class); | |
Bundle bundle = new Bundle(); | |
bundle.putParcelableArrayList("chords", chords); | |
intent.putExtras(bundle); | |
startActivity(intent); | |
} | |
});} | |
/** gestisce cosa succede quando clicco il tasto menu */ | |
public void showMenu(View v) { | |
PopupMenu menu = new PopupMenu(this, v); | |
menu.setOnMenuItemClickListener(this); | |
menu.inflate(R.menu.menu); | |
menu.show(); | |
} | |
@Override | |
public boolean onMenuItemClick(MenuItem item) { | |
switch (item.getItemId()) { | |
case R.id.informazioni_menu: | |
Intent intent = new Intent(ChordsListActivity.this, Info.class); | |
startActivity(intent); | |
return true; | |
case R.id.legenda_menu: | |
Intent legendaIntent = new Intent(ChordsListActivity.this, PopUpInfoActivity.class); | |
startActivity(legendaIntent); | |
return true; | |
case R.id.premium_menu: | |
Intent premiumIntent = new Intent(ChordsListActivity.this, Premium.class); | |
startActivity(premiumIntent); | |
return true; | |
case R.id.problema_menu: | |
Intent email = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( | |
"mailto", "dancam.dev@gmail.com", null)); | |
email.putExtra(Intent.EXTRA_SUBJECT, "Chords Problem"); | |
email.putExtra(Intent.EXTRA_TEXT, true); | |
startActivity(Intent.createChooser(email, "Choose an email client: ")); | |
return true; | |
default: | |
return false; | |
} | |
} | |
} |
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
//class getting the List | |
public class SearchActivity extends AppCompatActivity { | |
ArrayList<Accordo> chords; | |
int a; | |
RecyclerView rv; | |
SearchView sv; | |
ArrayList<Accordo> filteredModelList; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.search_layout); | |
/** gestisce la pubblicita */ | |
MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544/6300978111"); | |
AdView searchBanner = (AdView) findViewById(R.id.search_ad); | |
AdRequest adRequest = new AdRequest.Builder().build(); | |
searchBanner.loadAd(adRequest); | |
/**-------------------------------*/ | |
Intent intent = this.getIntent(); | |
Bundle bundle = intent.getExtras(); | |
chords = bundle.getParcelableArrayList("chords"); | |
sv = (SearchView) findViewById(R.id.testo_ricerca); | |
sv.setIconifiedByDefault(false); | |
rv = (RecyclerView) findViewById(R.id.lista_ricerca); | |
rv.setLayoutManager(new LinearLayoutManager(SearchActivity.this, LinearLayoutManager.VERTICAL, false)); | |
rv.setHasFixedSize(true); | |
final SearchAdapter adapter = new SearchAdapter(this, chords); | |
rv.setAdapter(adapter); | |
//SEARCH | |
sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() { | |
@Override | |
public boolean onQueryTextSubmit(String query) { | |
return false; | |
} | |
@Override | |
public boolean onQueryTextChange(String newText) { | |
//FILTER AS YOU TYPE | |
final List<Accordo> filteredModelList = filter(chords, newText); | |
adapter.setFilter(filteredModelList); | |
return true; | |
} | |
}); | |
/** gestisce cosa succede quando un elemento della lista viene cliccato */ | |
ItemClickSupport.addTo(rv).setOnItemClickListener(new ItemClickSupport.OnItemClickListener(){ | |
@Override | |
public void onItemClicked(RecyclerView recyclerView, int position, View v) { | |
Intent intent = new Intent(SearchActivity.this, ChordActivity.class); | |
Bundle bundle = new Bundle(); | |
bundle.putParcelable("selected", filteredModelList.get(position)); | |
intent.putExtras(bundle); | |
startActivity(intent); | |
} | |
}); | |
} | |
private List<Accordo> filter(List<Accordo> models, String query) { | |
query = query.toLowerCase(); | |
filteredModelList = new ArrayList<>(); | |
for (Accordo model : models) { | |
final String text = model.getName().toLowerCase(); | |
if (text.contains(query)) { | |
filteredModelList.add(model); | |
} | |
} | |
return filteredModelList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment