Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ protected int[] getRightNavigationDrawerMenuResources() {
protected void onPrepareRightNavigationDrawerMenu(Menu menu) {
if (mFragment != null) {
mFilterDrawerHelper.selectFilterType(menu, mFragment.getFilterType());
mSortDrawerHelper.selectSortType(menu,
mFragment.getSortOrder(), mFragment.getSortDirection());
mSortDrawerHelper.selectSortType(menu, mFragment.getSortOrder(),
mFragment.getSortDirection(), false);
}
}

Expand Down
16 changes: 12 additions & 4 deletions app/src/main/java/com/gh4a/activities/home/BookmarkFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,24 @@

import com.gh4a.R;
import com.gh4a.fragment.BookmarkListFragment;
import com.gh4a.fragment.StarredRepositoryListFragment;

public class BookmarkFactory extends FragmentFactory {
private static final int[] TAB_TITLES = new int[] {
R.string.bookmarks
R.string.bookmarks, R.string.starred
};

public BookmarkFactory(HomeActivity activity) {
private final String mUserLogin;

public BookmarkFactory(HomeActivity activity, String userLogin) {
super(activity);
mUserLogin = userLogin;
}

@Override
protected @StringRes int getTitleResId() {
return R.string.bookmarks;
@StringRes
protected int getTitleResId() {
return R.string.stars_and_bookmarks;
}

@Override
Expand All @@ -27,6 +32,9 @@ protected int[] getTabTitleResIds() {

@Override
protected Fragment makeFragment(int position) {
if (position == 1) {
return StarredRepositoryListFragment.newInstance(mUserLogin);
}
return BookmarkListFragment.newInstance();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private FragmentFactory getFactoryForItem(int id) {
case R.id.search:
return new SearchFactory(this);
case R.id.bookmarks:
return new BookmarkFactory(this);
return new BookmarkFactory(this, mUserLogin);
case R.id.pub_timeline:
return new TimelineFactory(this);
case R.id.blog:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected void prepareToolDrawerMenu(Menu menu) {
super.prepareToolDrawerMenu(menu);
if (mFragment != null) {
mFilterDrawerHelper.selectFilterType(menu, mFragment.getFilterType());
mSortDrawerHelper.selectSortType(menu,
mFragment.getSortOrder(), mFragment.getSortDirection());
mSortDrawerHelper.selectSortType(menu, mFragment.getSortOrder(),
mFragment.getSortDirection(), false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,6 @@ private void applyFilterTypeAndSortOrder() {
}

switch (mFilterType) {
case "starred":
mMainFragment = StarredRepositoryListFragment.newInstance(mUserLogin,
mSortOrder, mSortDirection);
break;
case "watched":
mMainFragment = WatchedRepositoryListFragment.newInstance(mUserLogin);
break;
Expand Down Expand Up @@ -364,7 +360,6 @@ public static class FilterDrawerHelper {
FILTER_LOOKUP.put(R.id.filter_type_sources, "sources");
FILTER_LOOKUP.put(R.id.filter_type_forks, "forks");
FILTER_LOOKUP.put(R.id.filter_type_watched, "watched");
FILTER_LOOKUP.put(R.id.filter_type_starred, "starred");
}

public static FilterDrawerHelper create(String userLogin, boolean isOrg) {
Expand Down Expand Up @@ -427,17 +422,20 @@ public void setFilterType(String type) {
}

public int getMenuResId() {
return TextUtils.equals(mFilterType, "starred") ? R.menu.repo_starred_sort
: TextUtils.equals(mFilterType, "watched") ? 0
: R.menu.repo_sort;
return TextUtils.equals(mFilterType, "watched") ? 0 : R.menu.repo_sort;
}

public void selectSortType(Menu menu, String order, String direction) {
public void selectSortType(Menu menu, String order, String direction,
boolean updateSingleItem) {
int selectedId = 0;
for (int i = 0; i < SORT_LOOKUP.size(); i++) {
String[] value = SORT_LOOKUP.valueAt(i);
if (value[0].equals(order) && value[1].equals(direction)) {
selectedId = SORT_LOOKUP.keyAt(i);
if (updateSingleItem) {
menu.findItem(selectedId).setChecked(true);
return;
}
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;

import com.gh4a.R;
import com.gh4a.ServiceFactory;
Expand All @@ -33,29 +36,63 @@
import retrofit2.Response;

public class StarredRepositoryListFragment extends PagedDataBaseFragment<Repository> {
public static StarredRepositoryListFragment newInstance(String login,
String sortOrder, String sortDirection) {
private static final String STATE_KEY_SORT_ORDER = "sort_order";
private static final String STATE_KEY_SORT_DIRECTION = "sort_direction";

public static StarredRepositoryListFragment newInstance(String login) {
StarredRepositoryListFragment f = new StarredRepositoryListFragment();

Bundle args = new Bundle();
args.putString("user", login);
args.putString("sort_order", sortOrder);
args.putString("sort_direction", sortDirection);
f.setArguments(args);

return f;
}

private String mLogin;
private String mSortOrder;
private String mSortDirection;
private String mSortOrder = "created";
private String mSortDirection = "desc";
private RepositoryListContainerFragment.SortDrawerHelper mSortHelper;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLogin = getArguments().getString("user");
mSortOrder = getArguments().getString("sort_order");
mSortDirection = getArguments().getString("sort_direction");

mSortHelper = new RepositoryListContainerFragment.SortDrawerHelper();

if (savedInstanceState != null && savedInstanceState.containsKey(STATE_KEY_SORT_ORDER)) {
mSortOrder = savedInstanceState.getString(STATE_KEY_SORT_ORDER);
mSortDirection = savedInstanceState.getString(STATE_KEY_SORT_DIRECTION);
}
setHasOptionsMenu(true);
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(STATE_KEY_SORT_ORDER, mSortOrder);
outState.putString(STATE_KEY_SORT_DIRECTION, mSortDirection);
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.repo_starred_list_menu, menu);
mSortHelper.selectSortType(menu, mSortOrder, mSortDirection, true);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
String[] sortOrderAndDirection = mSortHelper.handleSelectionAndGetSortOrder(item);
if (sortOrderAndDirection == null) {
return false;
}
mSortOrder = sortOrderAndDirection[0];
mSortDirection = sortOrderAndDirection[1];
item.setChecked(true);
onRefresh();
return true;
}

@Override
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/sort_order.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#ffffff"
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z" />
</vector>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/home_nav_drawer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
android:icon="@drawable/icon_search"/>
<item
android:id="@+id/bookmarks"
android:title="@string/bookmarks"
android:title="@string/stars_and_bookmarks"
android:icon="@drawable/icon_bookmark" />
</group>
<group
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/menu/repo_filter_logged_in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
<item
android:id="@+id/filter_type_watched"
android:title="@string/repo_type_watched" />
<item
android:id="@+id/filter_type_starred"
android:title="@string/repo_type_starred" />
</group>
</menu>
</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="@string/repo_sort">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item
android:id="@+id/sort_order"
android:icon="@drawable/sort_order"
android:title="@string/repo_sort"
app:showAsAction="always">

<menu>
<group android:checkableBehavior="single">
<item
Expand All @@ -17,5 +24,7 @@
android:title="@string/repo_sort_order_pushed_desc" />
</group>
</menu>

</item>

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<string name="feedback_by_email">By Email</string>
<string name="feedback_by_gh4a">By OctoDroid</string>
<string name="bookmarks">Bookmarks</string>
<string name="stars_and_bookmarks">Stars and Bookmarks</string>
<string name="other_info">Other Information</string>
<string name="view">View</string>
<string name="readme">Readme</string>
Expand Down