Pins are saved on activity pause to remember the list position.

captchafix
Florens Douwes 12 years ago
parent ad88ae0410
commit 1d14b01be8
  1. 7
      Chan/src/org/floens/chan/activity/BoardActivity.java
  2. 28
      Chan/src/org/floens/chan/manager/PinnedManager.java

@ -83,6 +83,13 @@ public class BoardActivity extends BaseActivity implements ActionBar.OnNavigatio
boardLoadable.writeToBundle(this, outState);
}
@Override
protected void onPause() {
super.onPause();
PinnedManager.getInstance().updateAll();
}
@Override
protected void initDrawer() {
pinDrawerListener = new ActionBarDrawerToggle(this, pinDrawer,

@ -53,6 +53,11 @@ public class PinnedManager {
return null;
}
/**
* Add a pin
* @param pin
* @return true if it was added, false if it wasn't (duplicated)
*/
public boolean add(Pin pin) {
// No duplicates
for (Pin e : pins) {
@ -66,14 +71,37 @@ public class PinnedManager {
return true;
}
/**
* Remove a pin
* @param pin
*/
public void remove(Pin pin) {
pins.remove(pin);
DatabaseManager.getInstance().removePin(pin);
}
/**
* Update the pin in the database
* @param pin
*/
public void update(Pin pin) {
DatabaseManager.getInstance().updatePin(pin);
}
/**
* Updates all the pins to the database.
* This will run in a new thread because it can be an expensive operation.
*/
public void updateAll() {
new Thread(new Runnable() {
@Override
public void run() {
for (Pin pin : pins) {
DatabaseManager.getInstance().updatePin(pin);
}
}
}).start();
}
}

Loading…
Cancel
Save