Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Tabs->Spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ShamylZakariya committed May 22, 2019
1 parent 2eb87cb commit 98adf51
Show file tree
Hide file tree
Showing 74 changed files with 2,732 additions and 2,768 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

/**
* Instrumented test, which will execute on an Android device.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/
public class StickyHeadersDemoApp extends Application {

RandomUserLoader randomUserLoader;
RandomUserLoader randomUserLoader;

@Override
public void onCreate() {
super.onCreate();
randomUserLoader = new RandomUserLoader();
}
@Override
public void onCreate() {
super.onCreate();
randomUserLoader = new RandomUserLoader();
}

public RandomUserLoader getRandomUserLoader() {
return randomUserLoader;
}
public RandomUserLoader getRandomUserLoader() {
return randomUserLoader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,142 +20,142 @@
*/
public class AddressBookDemoAdapter extends SectioningAdapter {

private Locale locale = Locale.getDefault();
private static final boolean USE_DEBUG_APPEARANCE = false;

private class Section {
String alpha;
ArrayList<Person> people = new ArrayList<>();
}

public class ItemViewHolder extends SectioningAdapter.ItemViewHolder {
TextView personNameTextView;

ItemViewHolder(View itemView) {
super(itemView);
personNameTextView = itemView.findViewById(R.id.personNameTextView);
}
}

public class HeaderViewHolder extends SectioningAdapter.HeaderViewHolder {
TextView titleTextView;

HeaderViewHolder(View itemView) {
super(itemView);
titleTextView = itemView.findViewById(R.id.titleTextView);
}
}


private List<Person> people;
private ArrayList<Section> sections = new ArrayList<>();

public AddressBookDemoAdapter() {
}

@SuppressWarnings("unused")
public List<Person> getPeople() {
return people;
}

public void setPeople(List<Person> people) {
this.people = people;
sections.clear();

// sort people into buckets by the first letter of last name
char alpha = 0;
Section currentSection = null;
for (Person person : people) {
if (person.name.last.charAt(0) != alpha) {
if (currentSection != null) {
sections.add(currentSection);
}

currentSection = new Section();
alpha = person.name.last.charAt(0);
currentSection.alpha = String.valueOf(alpha);
}

if (currentSection != null) {
currentSection.people.add(person);
}
}

sections.add(currentSection);
notifyAllSectionsDataSetChanged();
}

@Override
public int getNumberOfSections() {
return sections.size();
}

@Override
public int getNumberOfItemsInSection(int sectionIndex) {
return sections.get(sectionIndex).people.size();
}

@Override
public boolean doesSectionHaveHeader(int sectionIndex) {
return true;
}

@Override
public boolean doesSectionHaveFooter(int sectionIndex) {
return false;
}

@Override
public ItemViewHolder onCreateItemViewHolder(ViewGroup parent, int itemType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View v = inflater.inflate(R.layout.list_item_addressbook_person, parent, false);
return new ItemViewHolder(v);
}

@Override
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent, int headerType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View v = inflater.inflate(R.layout.list_item_addressbook_header, parent, false);
return new HeaderViewHolder(v);
}

@SuppressLint("SetTextI18n")
@Override
public void onBindItemViewHolder(SectioningAdapter.ItemViewHolder viewHolder, int sectionIndex, int itemIndex, int itemType) {
Section s = sections.get(sectionIndex);
ItemViewHolder ivh = (ItemViewHolder) viewHolder;
Person person = s.people.get(itemIndex);
ivh.personNameTextView.setText(capitalize(person.name.last) + ", " + capitalize(person.name.first));
}

@SuppressLint("SetTextI18n")
@Override
public void onBindHeaderViewHolder(SectioningAdapter.HeaderViewHolder viewHolder, int sectionIndex, int headerType) {
Section s = sections.get(sectionIndex);
HeaderViewHolder hvh = (HeaderViewHolder) viewHolder;

if (USE_DEBUG_APPEARANCE) {
hvh.itemView.setBackgroundColor(0x55ffffff);
hvh.titleTextView.setText(pad(sectionIndex * 2) + s.alpha);
} else {
hvh.titleTextView.setText(s.alpha);
}
}

private String capitalize(String s) {
if (s != null && s.length() > 0) {
return s.substring(0,1).toUpperCase(locale) + s.substring(1);
}

return "";
}

private String pad(int spaces) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < spaces; i++) {
b.append(' ');
}
return b.toString();
}
private Locale locale = Locale.getDefault();
private static final boolean USE_DEBUG_APPEARANCE = false;

private class Section {
String alpha;
ArrayList<Person> people = new ArrayList<>();
}

public class ItemViewHolder extends SectioningAdapter.ItemViewHolder {
TextView personNameTextView;

ItemViewHolder(View itemView) {
super(itemView);
personNameTextView = itemView.findViewById(R.id.personNameTextView);
}
}

public class HeaderViewHolder extends SectioningAdapter.HeaderViewHolder {
TextView titleTextView;

HeaderViewHolder(View itemView) {
super(itemView);
titleTextView = itemView.findViewById(R.id.titleTextView);
}
}


private List<Person> people;
private ArrayList<Section> sections = new ArrayList<>();

public AddressBookDemoAdapter() {
}

@SuppressWarnings("unused")
public List<Person> getPeople() {
return people;
}

public void setPeople(List<Person> people) {
this.people = people;
sections.clear();

// sort people into buckets by the first letter of last name
char alpha = 0;
Section currentSection = null;
for (Person person : people) {
if (person.name.last.charAt(0) != alpha) {
if (currentSection != null) {
sections.add(currentSection);
}

currentSection = new Section();
alpha = person.name.last.charAt(0);
currentSection.alpha = String.valueOf(alpha);
}

if (currentSection != null) {
currentSection.people.add(person);
}
}

sections.add(currentSection);
notifyAllSectionsDataSetChanged();
}

@Override
public int getNumberOfSections() {
return sections.size();
}

@Override
public int getNumberOfItemsInSection(int sectionIndex) {
return sections.get(sectionIndex).people.size();
}

@Override
public boolean doesSectionHaveHeader(int sectionIndex) {
return true;
}

@Override
public boolean doesSectionHaveFooter(int sectionIndex) {
return false;
}

@Override
public ItemViewHolder onCreateItemViewHolder(ViewGroup parent, int itemType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View v = inflater.inflate(R.layout.list_item_addressbook_person, parent, false);
return new ItemViewHolder(v);
}

@Override
public HeaderViewHolder onCreateHeaderViewHolder(ViewGroup parent, int headerType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View v = inflater.inflate(R.layout.list_item_addressbook_header, parent, false);
return new HeaderViewHolder(v);
}

@SuppressLint("SetTextI18n")
@Override
public void onBindItemViewHolder(SectioningAdapter.ItemViewHolder viewHolder, int sectionIndex, int itemIndex, int itemType) {
Section s = sections.get(sectionIndex);
ItemViewHolder ivh = (ItemViewHolder) viewHolder;
Person person = s.people.get(itemIndex);
ivh.personNameTextView.setText(capitalize(person.name.last) + ", " + capitalize(person.name.first));
}

@SuppressLint("SetTextI18n")
@Override
public void onBindHeaderViewHolder(SectioningAdapter.HeaderViewHolder viewHolder, int sectionIndex, int headerType) {
Section s = sections.get(sectionIndex);
HeaderViewHolder hvh = (HeaderViewHolder) viewHolder;

if (USE_DEBUG_APPEARANCE) {
hvh.itemView.setBackgroundColor(0x55ffffff);
hvh.titleTextView.setText(pad(sectionIndex * 2) + s.alpha);
} else {
hvh.titleTextView.setText(s.alpha);
}
}

private String capitalize(String s) {
if (s != null && s.length() > 0) {
return s.substring(0, 1).toUpperCase(locale) + s.substring(1);
}

return "";
}

private String pad(int spaces) {
StringBuilder b = new StringBuilder();
for (int i = 0; i < spaces; i++) {
b.append(' ');
}
return b.toString();
}

}
Loading

0 comments on commit 98adf51

Please sign in to comment.