-
Notifications
You must be signed in to change notification settings - Fork 417
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2b4433
commit 3f8c11e
Showing
5 changed files
with
135 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 50 additions & 55 deletions
105
app/src/main/java/com/hippo/ehviewer/ui/scene/gallery/detail/GetGalleryDetailListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,73 @@ | ||
package com.hippo.ehviewer.ui.scene.gallery.detail; | ||
package com.hippo.ehviewer.ui.scene.gallery.detail | ||
|
||
import android.content.Context; | ||
|
||
import com.hippo.ehviewer.EhApplication; | ||
import com.hippo.ehviewer.EhDB; | ||
import com.hippo.ehviewer.client.EhUtils; | ||
import com.hippo.ehviewer.client.data.GalleryDetail; | ||
import com.hippo.ehviewer.sync.GalleryDetailTagsSyncTask; | ||
import com.hippo.ehviewer.ui.scene.EhCallback; | ||
import com.hippo.scene.SceneFragment; | ||
import com.hippo.lib.yorozuya.FileUtils; | ||
|
||
public class GetGalleryDetailListener extends EhCallback<GalleryDetailScene, GalleryDetail> { | ||
|
||
public static int RESULT_DETAIL = 1; | ||
public static int RESULT_UPDATE = 0; | ||
|
||
private final int resultMode; | ||
|
||
public GetGalleryDetailListener(Context context, int stageId, String sceneTag, int resultMode) { | ||
super(context, stageId, sceneTag); | ||
this.resultMode = resultMode; | ||
} | ||
|
||
@Override | ||
public void onSuccess(GalleryDetail result) { | ||
getApplication().removeGlobalStuff(this); | ||
import android.content.Context | ||
import com.hippo.ehviewer.EhApplication | ||
import com.hippo.ehviewer.EhDB | ||
import com.hippo.ehviewer.client.EhUtils | ||
import com.hippo.ehviewer.client.data.GalleryDetail | ||
import com.hippo.ehviewer.sync.GalleryDetailTagsSyncTask | ||
import com.hippo.ehviewer.ui.scene.EhCallback | ||
import com.hippo.lib.yorozuya.FileUtils | ||
import com.hippo.scene.SceneFragment | ||
|
||
class GetGalleryDetailListener( | ||
context: Context?, | ||
stageId: Int, | ||
sceneTag: String?, | ||
private val resultMode: Int | ||
) : EhCallback<GalleryDetailScene?, GalleryDetail?>(context, stageId, sceneTag) { | ||
override fun onSuccess(result: GalleryDetail?) { | ||
application.removeGlobalStuff(this) | ||
if (result==null){ | ||
return | ||
} | ||
// Put gallery detail to cache | ||
EhApplication.getGalleryDetailCache(getApplication()).put(result.gid, result); | ||
EhApplication.getGalleryDetailCache(application).put(result.gid, result) | ||
|
||
// Add history | ||
EhDB.putHistoryInfo(result); | ||
EhDB.putHistoryInfo(result) | ||
|
||
// Save tags | ||
GalleryDetailTagsSyncTask syncTask = new GalleryDetailTagsSyncTask(result); | ||
syncTask.start(); | ||
val syncTask = GalleryDetailTagsSyncTask(result) | ||
syncTask.start() | ||
|
||
// Notify success | ||
GalleryDetailScene scene = getScene(); | ||
if (scene != null) { | ||
scene.onGetGalleryDetailSuccess(result); | ||
// if (resultMode == RESULT_DETAIL) { | ||
// scene.onGetGalleryDetailSuccess(result); | ||
// return; | ||
// } | ||
// scene.onGetGalleryDetailUpdateSuccess(result, SpiderInfo.getSpiderInfo(result), newPath(result)); | ||
} | ||
val scene = scene | ||
scene?.onGetGalleryDetailSuccess(result) | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
getApplication().removeGlobalStuff(this); | ||
GalleryDetailScene scene = getScene(); | ||
override fun onFailure(e: Exception) { | ||
application.removeGlobalStuff(this) | ||
val scene = scene | ||
if (scene != null) { | ||
if (resultMode == RESULT_DETAIL) { | ||
scene.onGetGalleryDetailFailure(e); | ||
return; | ||
scene.onGetGalleryDetailFailure(e) | ||
return | ||
} | ||
scene.onGetGalleryDetailUpdateFailure(e); | ||
scene.onGetGalleryDetailUpdateFailure(e) | ||
} | ||
} | ||
|
||
@Override | ||
public void onCancel() { | ||
getApplication().removeGlobalStuff(this); | ||
override fun onCancel() { | ||
application.removeGlobalStuff(this) | ||
} | ||
|
||
override fun isInstance(scene: SceneFragment): Boolean { | ||
return scene is GalleryDetailScene | ||
} | ||
|
||
@Override | ||
public boolean isInstance(SceneFragment scene) { | ||
return scene instanceof GalleryDetailScene; | ||
private fun newPath(result: GalleryDetail): String { | ||
return FileUtils.sanitizeFilename( | ||
result.gid.toString() + "-" + EhUtils.getSuitableTitle( | ||
result | ||
) | ||
) | ||
} | ||
|
||
private String newPath(GalleryDetail result) { | ||
return FileUtils.sanitizeFilename(result.gid + "-" + EhUtils.getSuitableTitle(result)); | ||
companion object { | ||
@JvmField | ||
var RESULT_DETAIL: Int = 1 | ||
@JvmField | ||
var RESULT_UPDATE: Int = 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters