|
|
|
@ -34,44 +34,44 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
private ThreadFragment boardFragment; |
|
|
|
|
private ThreadFragment threadFragment; |
|
|
|
|
private boolean boardSetByIntent = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boardLoadable.mode = Loadable.Mode.BOARD; |
|
|
|
|
threadLoadable.mode = Loadable.Mode.THREAD; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boardFragment = ThreadFragment.newInstance(this); |
|
|
|
|
threadFragment = ThreadFragment.newInstance(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FragmentTransaction ft = getFragmentManager().beginTransaction(); |
|
|
|
|
ft.replace(R.id.left_pane, boardFragment); |
|
|
|
|
ft.replace(R.id.right_pane, threadFragment); |
|
|
|
|
ft.commitAllowingStateLoss(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateActionBarState(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ActionBar actionBar = getActionBar(); |
|
|
|
|
actionBar.setListNavigationCallbacks( |
|
|
|
|
new ArrayAdapter<String>( |
|
|
|
|
actionBar.getThemedContext(), |
|
|
|
|
actionBar.getThemedContext(), |
|
|
|
|
R.layout.board_select_spinner, |
|
|
|
|
android.R.id.text1, |
|
|
|
|
BoardManager.getInstance().getMyBoardsKeys() |
|
|
|
|
), this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Intent startIntent = getIntent(); |
|
|
|
|
Uri startUri = startIntent.getData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (savedInstanceState != null) { |
|
|
|
|
boardLoadable.readFromBundle(this, "board", savedInstanceState); |
|
|
|
|
boardLoadable.no = 0; |
|
|
|
|
boardLoadable.listViewIndex = 0; |
|
|
|
|
boardLoadable.listViewTop = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
threadLoadable.readFromBundle(this, "thread", savedInstanceState); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setNavigationFromBoardValue(boardLoadable.board); |
|
|
|
|
startLoadingThread(threadLoadable); |
|
|
|
|
} else if (startUri != null) { |
|
|
|
@ -80,41 +80,41 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
getActionBar().setSelectedNavigationItem(0); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onSaveInstanceState(Bundle outState) { |
|
|
|
|
super.onSaveInstanceState(outState); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boardLoadable.writeToBundle(this, "board", outState); |
|
|
|
|
threadLoadable.writeToBundle(this, "thread", outState); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onStart() { |
|
|
|
|
super.onStart(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PinnedService.onActivityStart(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onStop() { |
|
|
|
|
super.onStop(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PinnedService.onActivityStop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onPause() { |
|
|
|
|
super.onPause(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PinnedManager.getInstance().updateAll(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void initDrawer() { |
|
|
|
|
pinDrawerListener = new ActionBarDrawerToggle(this, pinDrawer, |
|
|
|
|
pinDrawerListener = new ActionBarDrawerToggle(this, pinDrawer, |
|
|
|
|
R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
super.initDrawer(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -124,16 +124,16 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
boardLoadable = new Loadable(BoardManager.getInstance().getMyBoardsValues().get(position)); |
|
|
|
|
startLoadingBoard(boardLoadable); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boardSetByIntent = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu) { |
|
|
|
|
super.onCreateOptionsMenu(menu); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -147,7 +147,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
@Override |
|
|
|
|
public void openPin(Pin pin) { |
|
|
|
|
startLoadingThread(pin.loadable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pinDrawer.closeDrawer(pinDrawerView); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -161,7 +161,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
super.onPostCreate(savedInstanceState); |
|
|
|
|
pinDrawerListener.syncState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void onBackPressed() { |
|
|
|
|
if (threadPane.isOpen()) { |
|
|
|
@ -170,10 +170,16 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
threadPane.openPane(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void updatePin(Pin pin) { |
|
|
|
|
super.updatePin(pin); |
|
|
|
|
updateActionBarState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void updateActionBarState() { |
|
|
|
|
final ActionBar actionBar = getActionBar(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (threadPane.isSlideable()) { |
|
|
|
|
if (threadPane.isOpen()) { |
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); |
|
|
|
@ -185,51 +191,51 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
actionBar.setTitle(threadLoadable.title); |
|
|
|
|
pinDrawerListener.setDrawerIndicatorEnabled(false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true); |
|
|
|
|
} else { |
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); |
|
|
|
|
pinDrawerListener.setDrawerIndicatorEnabled(true); |
|
|
|
|
actionBar.setTitle(threadLoadable.title); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
actionBar.setDisplayHomeAsUpEnabled(true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
actionBar.setDisplayShowTitleEnabled(true); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
invalidateOptionsMenu(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onPrepareOptionsMenu(Menu menu) { |
|
|
|
|
boolean open = threadPane.isOpen(); |
|
|
|
|
boolean slidable = threadPane.isSlideable(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setMenuItemEnabled(menu.findItem(R.id.action_reload_board), slidable && open); |
|
|
|
|
setMenuItemEnabled(menu.findItem(R.id.action_reload_thread), slidable && !open); |
|
|
|
|
setMenuItemEnabled(menu.findItem(R.id.action_reload_tablet), !slidable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setMenuItemEnabled(menu.findItem(R.id.action_pin), !slidable || !open); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setMenuItemEnabled(menu.findItem(R.id.action_reply), slidable); |
|
|
|
|
setMenuItemEnabled(menu.findItem(R.id.action_reply_tablet), !slidable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return super.onPrepareOptionsMenu(menu); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setMenuItemEnabled(MenuItem item, boolean enabled) { |
|
|
|
|
if (item != null) { |
|
|
|
|
item.setVisible(enabled); |
|
|
|
|
item.setEnabled(enabled); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) { |
|
|
|
|
if (pinDrawerListener.onOptionsItemSelected(item)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch(item.getItemId()) { |
|
|
|
|
case R.id.action_reload_board: |
|
|
|
|
case R.id.action_reload_tablet_board: |
|
|
|
@ -248,22 +254,22 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
return true; |
|
|
|
|
case R.id.action_reply_board: |
|
|
|
|
boardFragment.openReply(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
case R.id.action_reply_thread: |
|
|
|
|
threadFragment.openReply(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
case R.id.action_pin: |
|
|
|
|
if (threadFragment.hasLoader()) { |
|
|
|
|
Pin pin = new Pin(); |
|
|
|
|
pin.loadable = threadLoadable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addPin(pin); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pinDrawer.openDrawer(pinDrawerView); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
case R.id.action_open_browser: |
|
|
|
|
if (threadPane.isOpen()) { |
|
|
|
@ -273,14 +279,14 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
showUrlOpenPicker(ChanUrls.getThreadUrlDesktop(threadLoadable.board, threadLoadable.no)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
case android.R.id.home: |
|
|
|
|
threadPane.openPane(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -293,63 +299,63 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
public void onPanelOpened(View view) { |
|
|
|
|
updateActionBarState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void startLoadingBoard(Loadable loadable) { |
|
|
|
|
if (loadable.mode == Loadable.Mode.INVALID) return; |
|
|
|
|
|
|
|
|
|
this.boardLoadable = loadable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boardLoadable = loadable; |
|
|
|
|
|
|
|
|
|
boardFragment.bindLoadable(loadable); |
|
|
|
|
boardFragment.requestData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setShareUrl(ChanUrls.getBoardUrlDesktop(loadable.board)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateActionBarState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void startLoadingThread(Loadable loadable) { |
|
|
|
|
if (loadable.mode == Loadable.Mode.INVALID) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pin pin = PinnedManager.getInstance().findPinByLoadable(loadable); |
|
|
|
|
if (pin != null) { |
|
|
|
|
// Use the loadable from the pin.
|
|
|
|
|
// This way we can store the listview position in the pin loadable,
|
|
|
|
|
// This way we can store the listview position in the pin loadable,
|
|
|
|
|
// and not in a separate loadable instance.
|
|
|
|
|
loadable = pin.loadable; |
|
|
|
|
loadable = pin.loadable; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
threadLoadable = loadable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
threadFragment.bindLoadable(loadable); |
|
|
|
|
threadFragment.requestData(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setShareUrl(ChanUrls.getThreadUrlDesktop(loadable.board, loadable.no)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (TextUtils.isEmpty(loadable.title)) { |
|
|
|
|
loadable.title = "/" + loadable.board + "/" + loadable.no; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
threadPane.closePane(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
updateActionBarState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Handle opening from an external url. |
|
|
|
|
* @param startUri |
|
|
|
|
*/ |
|
|
|
|
private void handleIntentURI(Uri startUri) { |
|
|
|
|
List<String> parts = startUri.getPathSegments(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (parts.size() == 1) { |
|
|
|
|
// Board mode
|
|
|
|
|
String rawBoard = parts.get(0); |
|
|
|
|
|
|
|
|
|
String rawBoard = parts.get(0); |
|
|
|
|
|
|
|
|
|
if (BoardManager.getInstance().getBoardExists(rawBoard)) { |
|
|
|
|
boardSetByIntent = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startLoadingBoard(new Loadable(rawBoard)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ActionBar actionBar = getActionBar(); |
|
|
|
|
if (!setNavigationFromBoardValue(rawBoard)) { |
|
|
|
|
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); |
|
|
|
@ -357,7 +363,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
String value = BoardManager.getInstance().getBoardKey(rawBoard); |
|
|
|
|
actionBar.setTitle(value == null ? ("/" + rawBoard + "/") : value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
handleIntentURIFallback(startUri.toString()); |
|
|
|
|
} |
|
|
|
@ -366,14 +372,14 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
// First load a board and then start another activity opening the thread
|
|
|
|
|
String rawBoard = parts.get(0); |
|
|
|
|
int no = -1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
no = Integer.parseInt(parts.get(2)); |
|
|
|
|
} catch (NumberFormatException e) {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (no >= 0 && BoardManager.getInstance().getBoardExists(rawBoard)) { |
|
|
|
|
boardSetByIntent = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startLoadingBoard(new Loadable(rawBoard)); |
|
|
|
|
startLoadingThread(new Loadable(rawBoard, no)); |
|
|
|
|
} else { |
|
|
|
@ -384,7 +390,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
showUrlOpenPicker(startUri.toString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void handleIntentURIFallback(final String url) { |
|
|
|
|
new AlertDialog.Builder(this) |
|
|
|
|
.setTitle(R.string.open_unknown_title) |
|
|
|
@ -407,7 +413,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
.create() |
|
|
|
|
.show(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set the visual selector to the board. If the user has not set the board as a favorite, |
|
|
|
|
* return false. |
|
|
|
@ -423,7 +429,7 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (foundIndex >= 0) { |
|
|
|
|
getActionBar().setSelectedNavigationItem(foundIndex); |
|
|
|
|
return true; |
|
|
|
|