Convert EhCallback to kotlin
This commit is contained in:
1 parent
fc6ba3e6ad
commit
733230f037
6 files changed
+48
-52
No files matched your search
@@ -13,57 +13,53 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.hippo.ehviewer.ui.scene
|
||||
|
||||
package com.hippo.ehviewer.ui.scene;
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.hippo.ehviewer.EhApplication
|
||||
import com.hippo.ehviewer.client.EhClient
|
||||
import com.hippo.ehviewer.ui.MainActivity
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
abstract class EhCallback<E : Fragment?, T>(context: Context) : EhClient.Callback<T> {
|
||||
val application: EhApplication
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.hippo.ehviewer.EhApplication;
|
||||
import com.hippo.ehviewer.client.EhClient;
|
||||
import com.hippo.ehviewer.ui.EhActivity;
|
||||
import com.hippo.ehviewer.ui.MainActivity;
|
||||
|
||||
public abstract class EhCallback<E extends Fragment, T> implements EhClient.Callback<T> {
|
||||
|
||||
private final EhApplication mApplication;
|
||||
|
||||
public EhCallback(Context context) {
|
||||
mApplication = (EhApplication) context.getApplicationContext();
|
||||
init {
|
||||
application = context.applicationContext as EhApplication
|
||||
}
|
||||
|
||||
public Context getContent() {
|
||||
Context context = mApplication.getTopActivity();
|
||||
if (context == null) {
|
||||
context = getApplication();
|
||||
val content: Context
|
||||
get() {
|
||||
var context: Context? = application.topActivity
|
||||
if (context == null) {
|
||||
context = application
|
||||
}
|
||||
return context
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
public EhApplication getApplication() {
|
||||
return mApplication;
|
||||
}
|
||||
|
||||
public void showTip(@StringRes int id, int length) {
|
||||
EhActivity activity = mApplication.getTopActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).showTip(id, length);
|
||||
fun showTip(@StringRes id: Int, length: Int) {
|
||||
val activity = application.topActivity
|
||||
if (activity is MainActivity) {
|
||||
activity.showTip(id, length)
|
||||
} else {
|
||||
Toast.makeText(getApplication(), id,
|
||||
length == BaseScene.LENGTH_LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(
|
||||
application, id,
|
||||
if (length == BaseScene.LENGTH_LONG) Toast.LENGTH_LONG else Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
|
||||
public void showTip(String tip, int length) {
|
||||
EhActivity activity = mApplication.getTopActivity();
|
||||
if (activity instanceof MainActivity) {
|
||||
((MainActivity) activity).showTip(tip, length);
|
||||
fun showTip(tip: String, length: Int) {
|
||||
val activity = application.topActivity
|
||||
if (activity is MainActivity) {
|
||||
activity.showTip(tip, length)
|
||||
} else {
|
||||
Toast.makeText(getApplication(), tip,
|
||||
length == BaseScene.LENGTH_LONG ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT).show();
|
||||
Toast.makeText(
|
||||
application, tip,
|
||||
if (length == BaseScene.LENGTH_LONG) Toast.LENGTH_LONG else Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -700,7 +700,7 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
private class ProgressCommentHolder(inflater: LayoutInflater, parent: ViewGroup?) :
|
||||
CommentHolder(inflater, R.layout.item_gallery_comment_progress, parent)
|
||||
|
||||
private inner class RefreshCommentListener(context: Context?) :
|
||||
private inner class RefreshCommentListener(context: Context) :
|
||||
EhCallback<GalleryCommentsScene?, GalleryDetail>(context) {
|
||||
override fun onSuccess(result: GalleryDetail) {
|
||||
val scene = this@GalleryCommentsScene
|
||||
@@ -715,7 +715,7 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
override fun onCancel() {}
|
||||
}
|
||||
|
||||
private inner class CommentGalleryListener(context: Context?, private val mCommentId: Long) :
|
||||
private inner class CommentGalleryListener(context: Context, private val mCommentId: Long) :
|
||||
EhCallback<GalleryCommentsScene?, GalleryCommentList>(context) {
|
||||
override fun onSuccess(result: GalleryCommentList) {
|
||||
showTip(
|
||||
@@ -738,7 +738,7 @@ class GalleryCommentsScene : BaseToolbarScene(), View.OnClickListener, OnRefresh
|
||||
override fun onCancel() {}
|
||||
}
|
||||
|
||||
private inner class VoteCommentListener(context: Context?) :
|
||||
private inner class VoteCommentListener(context: Context) :
|
||||
EhCallback<GalleryCommentsScene?, VoteCommentParser.Result>(context) {
|
||||
override fun onSuccess(result: VoteCommentParser.Result) {
|
||||
showTip(
|
||||
|
||||
@@ -1259,7 +1259,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
@IntDef(STATE_INIT, STATE_NORMAL, STATE_REFRESH, STATE_REFRESH_HEADER, STATE_FAILED)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
private annotation class State
|
||||
private class VoteTagListener(context: Context?) :
|
||||
private class VoteTagListener(context: Context) :
|
||||
EhCallback<GalleryDetailScene?, VoteTagParser.Result>(context) {
|
||||
override fun onSuccess(result: VoteTagParser.Result) {
|
||||
if (!TextUtils.isEmpty(result.error)) {
|
||||
@@ -1277,7 +1277,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
}
|
||||
|
||||
private class DownloadArchiveListener(
|
||||
context: Context?,
|
||||
context: Context,
|
||||
private val mGalleryInfo: GalleryInfo?
|
||||
) : EhCallback<GalleryDetailScene?, String>(context) {
|
||||
override fun onSuccess(result: String) {
|
||||
@@ -1338,7 +1338,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
}
|
||||
}
|
||||
|
||||
private inner class GetGalleryDetailListener(context: Context?) :
|
||||
private inner class GetGalleryDetailListener(context: Context) :
|
||||
EhCallback<GalleryDetailScene?, GalleryDetail>(context) {
|
||||
override fun onSuccess(result: GalleryDetail) {
|
||||
application.removeGlobalStuff(this)
|
||||
@@ -1366,7 +1366,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
}
|
||||
|
||||
private inner class RateGalleryListener(
|
||||
context: Context?
|
||||
context: Context
|
||||
) : EhCallback<GalleryDetailScene?, RateGalleryParser.Result>(context) {
|
||||
override fun onSuccess(result: RateGalleryParser.Result) {
|
||||
showTip(R.string.rate_successfully, LENGTH_SHORT)
|
||||
@@ -1383,7 +1383,7 @@ class GalleryDetailScene : CollapsingToolbarScene(), View.OnClickListener, Downl
|
||||
}
|
||||
|
||||
private inner class ModifyFavoritesListener(
|
||||
context: Context?,
|
||||
context: Context,
|
||||
private val mAddOrRemove: Boolean
|
||||
) :
|
||||
EhCallback<GalleryDetailScene?, Void?>(context) {
|
||||
|
||||
@@ -208,7 +208,7 @@ class GalleryPreviewsScene : BaseToolbarScene() {
|
||||
}
|
||||
|
||||
private inner class GetPreviewSetListener(
|
||||
context: Context?,
|
||||
context: Context,
|
||||
private val mTaskId: Int
|
||||
) : EhCallback<GalleryPreviewsScene, Pair<PreviewSet, Int>>(context) {
|
||||
override fun onSuccess(result: Pair<PreviewSet, Int>) {
|
||||
|
||||
@@ -318,7 +318,7 @@ class HistoryScene : BaseToolbarScene() {
|
||||
return true
|
||||
}
|
||||
|
||||
private class AddToFavoriteListener(context: Context?) :
|
||||
private class AddToFavoriteListener(context: Context) :
|
||||
EhCallback<GalleryListScene?, Void?>(context) {
|
||||
override fun onSuccess(result: Void?) {
|
||||
showTip(R.string.add_to_favorite_success, LENGTH_SHORT)
|
||||
@@ -331,7 +331,7 @@ class HistoryScene : BaseToolbarScene() {
|
||||
override fun onCancel() {}
|
||||
}
|
||||
|
||||
private class RemoveFromFavoriteListener(context: Context?) :
|
||||
private class RemoveFromFavoriteListener(context: Context) :
|
||||
EhCallback<GalleryListScene?, Void?>(context) {
|
||||
override fun onSuccess(result: Void?) {
|
||||
showTip(R.string.remove_from_favorite_success, LENGTH_SHORT)
|
||||
|
||||
@@ -184,7 +184,7 @@ class ProgressScene : BaseScene(), View.OnClickListener {
|
||||
}
|
||||
|
||||
private inner class GetGalleryTokenListener(
|
||||
context: Context?
|
||||
context: Context
|
||||
) : EhCallback<ProgressScene, String>(context) {
|
||||
override fun onSuccess(result: String) {
|
||||
val scene = this@ProgressScene
|
||||
|
||||
Reference in new issue
Block a user