|
|
@ -27,8 +27,8 @@ import android.support.v7.widget.RecyclerView; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.text.TextUtils; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.EditText; |
|
|
|
|
|
|
|
import android.widget.FrameLayout; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
@ -36,14 +36,12 @@ import android.widget.TextView; |
|
|
|
import org.floens.chan.Chan; |
|
|
|
import org.floens.chan.Chan; |
|
|
|
import org.floens.chan.R; |
|
|
|
import org.floens.chan.R; |
|
|
|
import org.floens.chan.controller.Controller; |
|
|
|
import org.floens.chan.controller.Controller; |
|
|
|
import org.floens.chan.controller.ControllerTransition; |
|
|
|
import org.floens.chan.controller.ControllerLogic; |
|
|
|
import org.floens.chan.controller.NavigationController; |
|
|
|
import org.floens.chan.controller.NavigationController; |
|
|
|
import org.floens.chan.core.manager.WatchManager; |
|
|
|
import org.floens.chan.core.manager.WatchManager; |
|
|
|
import org.floens.chan.core.model.Pin; |
|
|
|
import org.floens.chan.core.model.Pin; |
|
|
|
import org.floens.chan.ui.adapter.PinAdapter; |
|
|
|
import org.floens.chan.ui.adapter.PinAdapter; |
|
|
|
import org.floens.chan.ui.helper.SwipeListener; |
|
|
|
import org.floens.chan.ui.helper.SwipeListener; |
|
|
|
import org.floens.chan.ui.theme.ThemeHelper; |
|
|
|
|
|
|
|
import org.floens.chan.ui.toolbar.Toolbar; |
|
|
|
|
|
|
|
import org.floens.chan.utils.AndroidUtils; |
|
|
|
import org.floens.chan.utils.AndroidUtils; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
@ -55,16 +53,19 @@ import static org.floens.chan.utils.AndroidUtils.ROBOTO_MEDIUM; |
|
|
|
import static org.floens.chan.utils.AndroidUtils.dp; |
|
|
|
import static org.floens.chan.utils.AndroidUtils.dp; |
|
|
|
import static org.floens.chan.utils.AndroidUtils.fixSnackbarText; |
|
|
|
import static org.floens.chan.utils.AndroidUtils.fixSnackbarText; |
|
|
|
|
|
|
|
|
|
|
|
public class DrawerNavigationController extends NavigationController implements PinAdapter.Callback, View.OnClickListener { |
|
|
|
public class DrawerController extends Controller implements PinAdapter.Callback, View.OnClickListener { |
|
|
|
private WatchManager watchManager; |
|
|
|
private WatchManager watchManager; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected FrameLayout container; |
|
|
|
protected DrawerLayout drawerLayout; |
|
|
|
protected DrawerLayout drawerLayout; |
|
|
|
protected LinearLayout drawer; |
|
|
|
protected LinearLayout drawer; |
|
|
|
protected RecyclerView recyclerView; |
|
|
|
protected RecyclerView recyclerView; |
|
|
|
protected LinearLayout settings; |
|
|
|
protected LinearLayout settings; |
|
|
|
protected PinAdapter pinAdapter; |
|
|
|
protected PinAdapter pinAdapter; |
|
|
|
|
|
|
|
|
|
|
|
public DrawerNavigationController(Context context) { |
|
|
|
private NavigationController childController; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DrawerController(Context context) { |
|
|
|
super(context); |
|
|
|
super(context); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -77,8 +78,7 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
EventBus.getDefault().register(this); |
|
|
|
EventBus.getDefault().register(this); |
|
|
|
|
|
|
|
|
|
|
|
view = inflateRes(R.layout.controller_navigation_drawer); |
|
|
|
view = inflateRes(R.layout.controller_navigation_drawer); |
|
|
|
container = (ViewGroup) view.findViewById(R.id.container); |
|
|
|
container = (FrameLayout) view.findViewById(R.id.container); |
|
|
|
toolbar = (Toolbar) view.findViewById(R.id.toolbar); |
|
|
|
|
|
|
|
drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout); |
|
|
|
drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout); |
|
|
|
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT); |
|
|
|
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT); |
|
|
|
drawer = (LinearLayout) view.findViewById(R.id.drawer); |
|
|
|
drawer = (LinearLayout) view.findViewById(R.id.drawer); |
|
|
@ -89,8 +89,6 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
theme().settingsDrawable.apply((ImageView) settings.findViewById(R.id.image)); |
|
|
|
theme().settingsDrawable.apply((ImageView) settings.findViewById(R.id.image)); |
|
|
|
((TextView) settings.findViewById(R.id.text)).setTypeface(ROBOTO_MEDIUM); |
|
|
|
((TextView) settings.findViewById(R.id.text)).setTypeface(ROBOTO_MEDIUM); |
|
|
|
|
|
|
|
|
|
|
|
toolbar.setBackgroundColor(ThemeHelper.getInstance().getTheme().primaryColor.color); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pinAdapter = new PinAdapter(this); |
|
|
|
pinAdapter = new PinAdapter(this); |
|
|
|
recyclerView.setAdapter(pinAdapter); |
|
|
|
recyclerView.setAdapter(pinAdapter); |
|
|
|
|
|
|
|
|
|
|
@ -98,8 +96,6 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
|
|
|
|
|
|
|
|
pinAdapter.onPinsChanged(watchManager.getPins()); |
|
|
|
pinAdapter.onPinsChanged(watchManager.getPins()); |
|
|
|
|
|
|
|
|
|
|
|
toolbar.setCallback(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateBadge(); |
|
|
|
updateBadge(); |
|
|
|
|
|
|
|
|
|
|
|
AndroidUtils.waitForMeasure(drawer, new AndroidUtils.OnMeasuredCallback() { |
|
|
|
AndroidUtils.waitForMeasure(drawer, new AndroidUtils.OnMeasuredCallback() { |
|
|
@ -114,9 +110,19 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
public void onDestroy() { |
|
|
|
public void onDestroy() { |
|
|
|
super.onDestroy(); |
|
|
|
super.onDestroy(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (childController != null) { |
|
|
|
|
|
|
|
childController.onDestroy(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EventBus.getDefault().unregister(this); |
|
|
|
EventBus.getDefault().unregister(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setChildController(NavigationController childController) { |
|
|
|
|
|
|
|
childController.parentController = this; |
|
|
|
|
|
|
|
ControllerLogic.transition(this.childController, childController, true, true, container); |
|
|
|
|
|
|
|
this.childController = childController; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onConfigurationChanged(Configuration newConfig) { |
|
|
|
public void onConfigurationChanged(Configuration newConfig) { |
|
|
|
super.onConfigurationChanged(newConfig); |
|
|
|
super.onConfigurationChanged(newConfig); |
|
|
@ -132,14 +138,11 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
public void onClick(View v) { |
|
|
|
if (v == settings) { |
|
|
|
if (v == settings) { |
|
|
|
pushController(new MainSettingsController(context)); |
|
|
|
openController(new MainSettingsController(context)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onMenuClicked() { |
|
|
|
public void onMenuClicked() { |
|
|
|
super.onMenuClicked(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
drawerLayout.openDrawer(drawer); |
|
|
|
drawerLayout.openDrawer(drawer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -148,49 +151,31 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
if (drawerLayout.isDrawerOpen(drawer)) { |
|
|
|
if (drawerLayout.isDrawerOpen(drawer)) { |
|
|
|
drawerLayout.closeDrawer(drawer); |
|
|
|
drawerLayout.closeDrawer(drawer); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
} else if (childController != null && childController.onBack()) { |
|
|
|
|
|
|
|
return true; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return super.onBack(); |
|
|
|
return super.onBack(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void controllerPushed(Controller controller) { |
|
|
|
|
|
|
|
super.controllerPushed(controller); |
|
|
|
|
|
|
|
setDrawerEnabled(controller.navigationItem.hasDrawer); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void controllerPopped(Controller controller) { |
|
|
|
|
|
|
|
super.controllerPopped(controller); |
|
|
|
|
|
|
|
setDrawerEnabled(controller.navigationItem.hasDrawer); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onControllerTransitionCompleted(ControllerTransition transition) { |
|
|
|
|
|
|
|
super.onControllerTransitionCompleted(transition); |
|
|
|
|
|
|
|
updateHighlighted(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateHighlighted() { |
|
|
|
|
|
|
|
pinAdapter.updateHighlighted(recyclerView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onPinClicked(Pin pin) { |
|
|
|
public void onPinClicked(Pin pin) { |
|
|
|
Controller top = getTop(); |
|
|
|
drawerLayout.closeDrawer(Gravity.LEFT); |
|
|
|
if (top instanceof DrawerCallback) { |
|
|
|
|
|
|
|
((DrawerCallback) top).onPinClicked(pin); |
|
|
|
|
|
|
|
drawerLayout.closeDrawer(Gravity.LEFT); |
|
|
|
|
|
|
|
pinAdapter.updateHighlighted(recyclerView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isHighlighted(Pin pin) { |
|
|
|
if (childController instanceof StyledToolbarNavigationController) { |
|
|
|
Controller top = getTop(); |
|
|
|
if (childController.getTop() instanceof ThreadController) { |
|
|
|
if (top instanceof DrawerCallback) { |
|
|
|
((ThreadController) childController.getTop()).openPin(pin); |
|
|
|
return ((DrawerCallback) top).isPinCurrent(pin); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (childController instanceof SplitNavigationController) { |
|
|
|
|
|
|
|
SplitNavigationController splitNavigationController = (SplitNavigationController) childController; |
|
|
|
|
|
|
|
if (splitNavigationController.leftController instanceof NavigationController) { |
|
|
|
|
|
|
|
NavigationController navigationController = (NavigationController) splitNavigationController.leftController; |
|
|
|
|
|
|
|
if (navigationController.getTop() instanceof ThreadController) { |
|
|
|
|
|
|
|
ThreadController threadController = (ThreadController) navigationController.getTop(); |
|
|
|
|
|
|
|
threadController.openPin(pin); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -200,7 +185,7 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onHeaderClicked(PinAdapter.HeaderHolder holder) { |
|
|
|
public void onHeaderClicked(PinAdapter.HeaderHolder holder) { |
|
|
|
pushController(new WatchSettingsController(context)); |
|
|
|
openController(new WatchSettingsController(context)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -251,12 +236,17 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void openBoardEditor() { |
|
|
|
public void openBoardEditor() { |
|
|
|
pushController(new BoardEditController(context)); |
|
|
|
openController(new BoardEditController(context)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void openHistory() { |
|
|
|
public void openHistory() { |
|
|
|
pushController(new HistoryController(context)); |
|
|
|
openController(new HistoryController(context)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setPinHighlighted(Pin pin) { |
|
|
|
|
|
|
|
pinAdapter.setPinHighlighted(pin); |
|
|
|
|
|
|
|
pinAdapter.updateHighlighted(recyclerView); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onEvent(WatchManager.PinAddedMessage message) { |
|
|
|
public void onEvent(WatchManager.PinAddedMessage message) { |
|
|
@ -275,7 +265,7 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
updateBadge(); |
|
|
|
updateBadge(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setDrawerEnabled(boolean enabled) { |
|
|
|
public void setDrawerEnabled(boolean enabled) { |
|
|
|
drawerLayout.setDrawerLockMode(enabled ? DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT); |
|
|
|
drawerLayout.setDrawerLockMode(enabled ? DrawerLayout.LOCK_MODE_UNLOCKED : DrawerLayout.LOCK_MODE_LOCKED_CLOSED, Gravity.LEFT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -292,7 +282,14 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
toolbar.getArrowMenuDrawable().setBadge(count, color); |
|
|
|
if (childController instanceof StyledToolbarNavigationController) { |
|
|
|
|
|
|
|
((StyledToolbarNavigationController) childController).toolbar.getArrowMenuDrawable().setBadge(count, color); |
|
|
|
|
|
|
|
} else if (childController instanceof SplitNavigationController) { |
|
|
|
|
|
|
|
SplitNavigationController splitNavigationController = (SplitNavigationController) childController; |
|
|
|
|
|
|
|
if (splitNavigationController.leftController instanceof StyledToolbarNavigationController) { |
|
|
|
|
|
|
|
((StyledToolbarNavigationController) splitNavigationController.leftController).toolbar.getArrowMenuDrawable().setBadge(count, color); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean setDrawerWidth() { |
|
|
|
private boolean setDrawerWidth() { |
|
|
@ -306,36 +303,8 @@ public class DrawerNavigationController extends NavigationController implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private void openController(Controller controller) { |
|
|
|
public String getSearchHint() { |
|
|
|
childController.pushController(controller); |
|
|
|
return context.getString(R.string.search_hint); |
|
|
|
drawerLayout.closeDrawer(Gravity.LEFT); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSearchVisibilityChanged(boolean visible) { |
|
|
|
|
|
|
|
Controller top = getTop(); |
|
|
|
|
|
|
|
if (top instanceof ToolbarSearchCallback) { |
|
|
|
|
|
|
|
((ToolbarSearchCallback) top).onSearchVisibilityChanged(visible); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onSearchEntered(String entered) { |
|
|
|
|
|
|
|
Controller top = getTop(); |
|
|
|
|
|
|
|
if (top instanceof ToolbarSearchCallback) { |
|
|
|
|
|
|
|
((ToolbarSearchCallback) top).onSearchEntered(entered); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface DrawerCallback { |
|
|
|
|
|
|
|
void onPinClicked(Pin pin); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean isPinCurrent(Pin pin); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public interface ToolbarSearchCallback { |
|
|
|
|
|
|
|
void onSearchVisibilityChanged(boolean visible); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void onSearchEntered(String entered); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |