Skip to content

Commit

Permalink
Sorting by asc
Browse files Browse the repository at this point in the history
  • Loading branch information
CullyCross committed Nov 4, 2015
1 parent 9e6df73 commit 99439cf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import me.cullycross.test4tabs.R;
Expand Down Expand Up @@ -55,26 +50,6 @@ public class FourTabsActivity extends AppCompatActivity {
});
}

@Override public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_four_tabs, menu);
return true;
}

@Override public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

public class SectionsPagerAdapter extends FragmentPagerAdapter {

public static final String CONTACTS = "Contacts";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ContactsCursorAdapter

private Context mContext;

private int mExpandedPosition;
private int mExpandedPosition = -1;

public ContactsCursorAdapter(Context context, Cursor cursor) {
super(context, cursor);
Expand Down Expand Up @@ -81,7 +81,11 @@ public ContactsCursorAdapter(Context context, Cursor cursor) {
int prev = mExpandedPosition;
notifyItemChanged(prev);
}
mExpandedPosition = holder.getAdapterPosition();
if (mExpandedPosition != holder.getAdapterPosition()) {
mExpandedPosition = holder.getAdapterPosition();
} else {
mExpandedPosition = -1;
}
notifyItemChanged(mExpandedPosition);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import butterknife.Bind;
Expand Down Expand Up @@ -36,11 +39,14 @@ public ContactsFragment() {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_contacts, container, false);
final View view = inflater.inflate(R.layout.fragment_contacts, container, false);
ButterKnife.bind(this, view);

setHasOptionsMenu(true);

final ContentResolver cr = getContext().getContentResolver();
final Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
final Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null,
"upper(" + ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC");

final LinearLayoutManager manager = new LinearLayoutManager(getContext());
mRecyclerViewContacts.setLayoutManager(manager);
Expand All @@ -53,4 +59,23 @@ public ContactsFragment() {
super.onDestroyView();
ButterKnife.unbind(this);
}

@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.menu_search, menu);
}

@Override public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
return true;
}

return super.onOptionsItemSelected(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import me.cullycross.test4tabs.R;

public class DatabaseFragment extends Fragment {
Expand All @@ -27,6 +26,7 @@ public DatabaseFragment() {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment

return inflater.inflate(R.layout.fragment_database, container, false);
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_contacts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
android:id="@+id/recycler_view_contacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".activities.FourTabsActivity">
<item android:id="@+id/action_settings"
android:title="@string/action_settings"
android:orderInCategory="100"
app:showAsAction="never"/>
<item
android:id="@+id/action_search"
android:title="Search"
app:actionViewClass="android.support.v7.widget.SearchView"
app:showAsAction="always"/>
</menu>

0 comments on commit 99439cf

Please sign in to comment.