Initial support for jump to certain date
This commit is contained in:
1 parent
e6a3c8f165
commit
df78b45f69
5 files changed
+558
-604
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -649,6 +649,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
.build();
|
||||
datePicker.show(requireActivity().getSupportFragmentManager(), "date-picker");
|
||||
datePicker.addOnPositiveButtonClickListener(v -> {
|
||||
mHelper.goTo(v);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -863,6 +863,7 @@ public final class GalleryListScene extends BaseScene
|
||||
.build();
|
||||
datePicker.show(requireActivity().getSupportFragmentManager(), "date-picker");
|
||||
datePicker.addOnPositiveButtonClickListener(v -> {
|
||||
mHelper.goTo(v);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1702,6 +1703,8 @@ public final class GalleryListScene extends BaseScene
|
||||
mUrlBuilder.setNextGid(minGid);
|
||||
else
|
||||
mUrlBuilder.setNextGid(0);
|
||||
mUrlBuilder.setJumpTo(jumpTo);
|
||||
jumpTo = null;
|
||||
if (ListUrlBuilder.MODE_IMAGE_SEARCH == mUrlBuilder.getMode()) {
|
||||
EhRequest request = new EhRequest();
|
||||
request.setMethod(EhClient.METHOD_IMAGE_SEARCH);
|
||||
|
||||
@@ -13,116 +13,118 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.widget
|
||||
|
||||
package com.hippo.ehviewer.widget;
|
||||
import android.annotation.SuppressLint
|
||||
import android.icu.text.SimpleDateFormat
|
||||
import android.icu.util.Calendar
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.FavouriteStatusRouter
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.widget.ContentLayout.ContentHelper
|
||||
import com.hippo.yorozuya.IntIdGenerator
|
||||
import java.util.Locale
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
abstract class GalleryInfoContentHelper : ContentHelper<GalleryInfo?>() {
|
||||
@JvmField
|
||||
var maxGid = -1
|
||||
@JvmField
|
||||
var minGid = -1
|
||||
@JvmField
|
||||
var jumpTo : String? = null
|
||||
private val listener: FavouriteStatusRouter.Listener
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.FavouriteStatusRouter;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.widget.ContentLayout;
|
||||
import com.hippo.yorozuya.IntIdGenerator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class GalleryInfoContentHelper extends ContentLayout.ContentHelper<GalleryInfo> {
|
||||
public int maxGid = -1;
|
||||
public int minGid = -1;
|
||||
|
||||
private static final String KEY_DATA_MAP = "data_map";
|
||||
private static final String KEY_MAX_GID = "max_gid";
|
||||
private static final String KEY_MIN_GID = "min_gid";
|
||||
|
||||
public static final String KEY_NEXT_PAGE = "next_page";
|
||||
private final FavouriteStatusRouter.Listener listener;
|
||||
@SuppressLint("UseSparseArrays")
|
||||
private Map<Long, GalleryInfo> map = new HashMap<>();
|
||||
private var map: MutableMap<Long, GalleryInfo> = HashMap()
|
||||
|
||||
public GalleryInfoContentHelper() {
|
||||
listener = (gid, slot) -> {
|
||||
GalleryInfo info = map.get(gid);
|
||||
init {
|
||||
listener = FavouriteStatusRouter.Listener { gid: Long, slot: Int ->
|
||||
val info = map[gid]
|
||||
if (info != null) {
|
||||
info.favoriteSlot = slot;
|
||||
info.favoriteSlot = slot
|
||||
}
|
||||
};
|
||||
EhApplication.getFavouriteStatusRouter().addListener(listener);
|
||||
}
|
||||
EhApplication.getFavouriteStatusRouter().addListener(listener)
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
EhApplication.getFavouriteStatusRouter().removeListener(listener);
|
||||
fun destroy() {
|
||||
EhApplication.getFavouriteStatusRouter().removeListener(listener)
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAddData(GalleryInfo data) {
|
||||
map.put(data.gid, data);
|
||||
override fun onAddData(data: GalleryInfo?) {
|
||||
data?.let { map[data.gid] = data }
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAddData(List<GalleryInfo> data) {
|
||||
for (GalleryInfo info : data) {
|
||||
if (maxGid == -1)
|
||||
maxGid = (int) info.gid;
|
||||
if (minGid == -1)
|
||||
minGid = (int) info.gid;
|
||||
maxGid = (int) Math.max(maxGid, info.gid);
|
||||
minGid = (int) Math.min(minGid, info.gid);
|
||||
map.put(info.gid, info);
|
||||
override fun onAddData(data: List<GalleryInfo?>) {
|
||||
for (info in data) {
|
||||
info?.let {
|
||||
if (maxGid == -1) maxGid = info.gid.toInt()
|
||||
if (minGid == -1) minGid = info.gid.toInt()
|
||||
maxGid = Math.max(maxGid.toLong(), info.gid).toInt()
|
||||
minGid = Math.min(minGid.toLong(), info.gid).toInt()
|
||||
map[info.gid] = info
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRemoveData(GalleryInfo data) {
|
||||
map.remove(data.gid);
|
||||
override fun onRemoveData(data: GalleryInfo?) {
|
||||
data?.let { map.remove(data.gid) }
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onRemoveData(List<GalleryInfo> data) {
|
||||
for (GalleryInfo info : data) {
|
||||
map.remove(info.gid);
|
||||
override fun onRemoveData(data: List<GalleryInfo?>) {
|
||||
for (info in data) {
|
||||
info?.let { map.remove(info.gid) }
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClearData() {
|
||||
map.clear();
|
||||
maxGid = -1;
|
||||
minGid = -1;
|
||||
override fun onClearData() {
|
||||
map.clear()
|
||||
maxGid = -1
|
||||
minGid = -1
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable saveInstanceState(Parcelable superState) {
|
||||
Bundle bundle = (Bundle) super.saveInstanceState(superState);
|
||||
override fun saveInstanceState(superState: Parcelable): Parcelable {
|
||||
val bundle = super.saveInstanceState(superState) as Bundle
|
||||
|
||||
// TODO It's a bad design
|
||||
FavouriteStatusRouter router = EhApplication.getFavouriteStatusRouter();
|
||||
int id = router.saveDataMap(map);
|
||||
bundle.putInt(KEY_DATA_MAP, id);
|
||||
bundle.putInt(KEY_MIN_GID, minGid);
|
||||
bundle.putInt(KEY_MAX_GID, maxGid);
|
||||
|
||||
return bundle;
|
||||
val router = EhApplication.getFavouriteStatusRouter()
|
||||
val id = router.saveDataMap(map)
|
||||
bundle.putInt(KEY_DATA_MAP, id)
|
||||
bundle.putInt(KEY_MIN_GID, minGid)
|
||||
bundle.putInt(KEY_MAX_GID, maxGid)
|
||||
return bundle
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Parcelable restoreInstanceState(Parcelable state) {
|
||||
Bundle bundle = (Bundle) state;
|
||||
|
||||
int id = bundle.getInt(KEY_DATA_MAP, IntIdGenerator.INVALID_ID);
|
||||
override fun restoreInstanceState(state: Parcelable): Parcelable {
|
||||
val bundle = state as Bundle
|
||||
val id = bundle.getInt(KEY_DATA_MAP, IntIdGenerator.INVALID_ID)
|
||||
if (id != IntIdGenerator.INVALID_ID) {
|
||||
FavouriteStatusRouter router = EhApplication.getFavouriteStatusRouter();
|
||||
Map<Long, GalleryInfo> map = router.restoreDataMap(id);
|
||||
val router = EhApplication.getFavouriteStatusRouter()
|
||||
val map = router.restoreDataMap(id)
|
||||
if (map != null) {
|
||||
this.map = map;
|
||||
this.map = map
|
||||
}
|
||||
}
|
||||
minGid = bundle.getInt(KEY_MIN_GID);
|
||||
maxGid = bundle.getInt(KEY_MAX_GID);
|
||||
|
||||
return super.restoreInstanceState(state);
|
||||
minGid = bundle.getInt(KEY_MIN_GID)
|
||||
maxGid = bundle.getInt(KEY_MAX_GID)
|
||||
return super.restoreInstanceState(state)
|
||||
}
|
||||
}
|
||||
|
||||
fun goTo(time: Long) {
|
||||
val calendar = Calendar.getInstance()
|
||||
calendar.timeInMillis = time
|
||||
val date = calendar.time
|
||||
val format = SimpleDateFormat("yyyy-MM-dd", Locale.US)
|
||||
jumpTo = format.format(date)
|
||||
doRefresh()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_DATA_MAP = "data_map"
|
||||
private const val KEY_MAX_GID = "max_gid"
|
||||
private const val KEY_MIN_GID = "min_gid"
|
||||
const val KEY_NEXT_PAGE = "next_page"
|
||||
}
|
||||
}
|
||||
@@ -747,7 +747,7 @@ public class ContentLayout extends FrameLayout {
|
||||
getPageData(mCurrentTaskId, mCurrentTaskType, mCurrentTaskPage);
|
||||
}
|
||||
|
||||
private void doRefresh() {
|
||||
protected void doRefresh() {
|
||||
mStartPage = 0;
|
||||
mEndPage = 1;
|
||||
mPages = 0;
|
||||
|
||||
Reference in new issue
Block a user