Skip to content

Commit

Permalink
remove snack bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Jul 15, 2019
1 parent c4274b7 commit 728d087
Show file tree
Hide file tree
Showing 36 changed files with 197 additions and 273 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ dependencies {
implementation 'com.nshmura:recyclertablayout:1.5.0'
implementation 'com.github.chrisbanes:PhotoView:2.1.4'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
implementation 'com.simplecityapps:recyclerview-fastscroll:1.0.18'
implementation 'am.util:viewpager:25.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
}
12 changes: 12 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,15 @@
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

# Retrofit
-dontwarn retrofit2.Platform$Java8
# okhttp
-dontwarn okio.**
-dontwarn org.conscrypt.**
-dontwarn javax.annotation.**

-dontwarn org.xmlpull.v1.**

# Gson
-keep class soko.ekibun.bangumi.api.**.bean.**{*;} # 自定义数据模型的bean目录
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.simplecityapps.recyclerview_fastscroll.interfaces;

public interface OnFastScrollStateChangeListener {

/**
* Called when fast scrolling begins
*/
void onFastScrollStart();

/**
* Called when fast scrolling ends
*/
void onFastScrollStop();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2016 Tim Malseed
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.simplecityapps.recyclerview_fastscroll.utils;

import android.annotation.TargetApi;
import android.content.res.Resources;
import android.os.Build;
import android.util.TypedValue;
import android.view.View;

public class Utils {

/**
* Converts dp to px
*
* @param res Resources
* @param dp the value in dp
* @return int
*/
public static int toPixels(Resources res, float dp) {
return (int) (dp * res.getDisplayMetrics().density);
}

/**
* Converts sp to px
*
* @param res Resources
* @param sp the value in sp
* @return int
*/
public static int toScreenPixels(Resources res, float sp) {
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, res.getDisplayMetrics());
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isRtl(Resources res) {
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) &&
(res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL);
}
}
52 changes: 7 additions & 45 deletions app/src/main/java/soko/ekibun/bangumi/api/ApiHelper.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package soko.ekibun.bangumi.api

import android.app.Activity
import android.content.Context
import android.os.Handler
import android.os.Looper
import com.google.android.material.snackbar.Snackbar
import android.util.Log
import okhttp3.Request
import okhttp3.RequestBody
Expand All @@ -15,15 +12,11 @@ import soko.ekibun.bangumi.util.HttpUtil
import java.io.IOException

object ApiHelper {
fun <T> buildCallback(context: Context?, callback: (T)->Unit, finish:(Throwable?)->Unit={}): Callback<T> {
fun <T> buildCallback(callback: (T)->Unit, finish:(Throwable?)->Unit={}): Callback<T> {
return object:Callback<T>{
override fun onFailure(call: Call<T>, t: Throwable) {
Log.e("errUrl", call.request().url().toString())
t.printStackTrace()
if(!t.toString().contains("Canceled")) {
if(context is Activity) Snackbar.make(context.window.decorView, t.toString(), Snackbar.LENGTH_SHORT).show()
finish(t)
}
}

override fun onResponse(call: Call<T>, response: Response<T>) {
Expand All @@ -35,31 +28,15 @@ object ApiHelper {
}
}

fun <T> buildCall(converter: ()->T): Call<T>{
return object: retrofit2.Call<T>{
override fun execute(): retrofit2.Response<T> {
return retrofit2.Response.success(converter())
}
override fun enqueue(callback: retrofit2.Callback<T>) {
callback.onResponse(this, execute())
}
override fun isExecuted(): Boolean { return true }
override fun clone(): retrofit2.Call<T> { return this }
override fun isCanceled(): Boolean { return false }
override fun cancel() {}
override fun request(): Request? { return null }
}
}

fun <T> buildHttpCall(url: String, header: Map<String, String> = HashMap(), body: RequestBody? = null, useCookie: Boolean = true, converter: (okhttp3.Response)->T): Call<T>{
val uiHandler = Handler(Looper.getMainLooper())
return object: retrofit2.Call<T>{
return object: Call<T>{
private val retrofitCall = this
val okHttpCall = HttpUtil.getCall(url, header, body, useCookie)
fun createResponse(response: okhttp3.Response): retrofit2.Response<T>{
return retrofit2.Response.success(converter(response))
fun createResponse(response: okhttp3.Response): Response<T>{
return Response.success(converter(response))
}
override fun enqueue(callback: retrofit2.Callback<T>) {
override fun enqueue(callback: Callback<T>) {
okHttpCall.enqueue(object: okhttp3.Callback {
override fun onFailure(call: okhttp3.Call, e: IOException) {
uiHandler.post { callback.onFailure(retrofitCall, e) }
Expand All @@ -76,27 +53,12 @@ object ApiHelper {
})
}
override fun isExecuted(): Boolean { return okHttpCall.isExecuted }
override fun clone(): retrofit2.Call<T> { return this }
override fun clone(): Call<T> { return this }
override fun isCanceled(): Boolean { return okHttpCall.isCanceled }
override fun cancel() { okHttpCall.cancel() }
override fun execute(): retrofit2.Response<T> {return createResponse(okHttpCall.execute()) }
override fun execute(): Response<T> {return createResponse(okHttpCall.execute()) }
override fun request(): Request { return okHttpCall.request() }

}
}

fun <T> buildGroupCall(calls: Array<Call<T>>): Call<T>{
return object: retrofit2.Call<T>{
override fun enqueue(callback: retrofit2.Callback<T>) { calls.forEach { it.enqueue(callback) } }
override fun isExecuted(): Boolean { return calls.count { it.isExecuted } == calls.size }
override fun clone(): retrofit2.Call<T> { return this }
override fun isCanceled(): Boolean { return calls.count { it.isCanceled } == calls.size }
override fun cancel() { calls.forEach { it.cancel() } }
override fun execute(): retrofit2.Response<T>? {
calls.forEach { it.execute() }
return null }
override fun request(): Request { return Request.Builder().build() }

}
}
}
27 changes: 0 additions & 27 deletions app/src/main/java/soko/ekibun/bangumi/api/catbox/CatBox.kt

This file was deleted.

5 changes: 5 additions & 0 deletions app/src/main/java/soko/ekibun/bangumi/api/github/GithubRaw.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import retrofit2.http.GET
import retrofit2.http.Path
import soko.ekibun.bangumi.api.github.bean.BangumiCalendarItem
import soko.ekibun.bangumi.api.github.bean.BangumiItem
import soko.ekibun.bangumi.api.github.bean.OnAirInfo

interface GithubRaw{

Expand All @@ -18,6 +19,10 @@ interface GithubRaw{
@GET("/ekibun/bangumi_calendar/master/calendar.json")
fun bangumiCalendar(): Call<List<BangumiCalendarItem>>

@GET("/ekibun/bangumi_onair/master/onair/{prefix}/{id}.json")
fun onAirInfo(@Path("prefix") prefix: Int,
@Path("id") id: Int): Call<OnAirInfo>

companion object {
private const val SERVER_API = "https://raw.githubusercontent.com"
fun createInstance(): GithubRaw{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package soko.ekibun.bangumi.api.tinygrail.bean
package soko.ekibun.bangumi.api.github.bean

import soko.ekibun.bangumi.api.bangumi.bean.Episode
import soko.ekibun.bangumi.api.bangumi.bean.Subject
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/soko/ekibun/bangumi/api/github/bean/OnAirInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package soko.ekibun.bangumi.api.github.bean

data class OnAirInfo (
val id: Int,
val name: String,
val eps: List<Ep>
){
data class Ep(
val id: Int,
val name: String,
val name_cn: String,
val sites: List<Site>
)
data class Site(
val site: String,
val title: String,
val url: String
)
}
30 changes: 0 additions & 30 deletions app/src/main/java/soko/ekibun/bangumi/api/smms/SmMs.kt

This file was deleted.

39 changes: 0 additions & 39 deletions app/src/main/java/soko/ekibun/bangumi/api/smms/bean/Response.kt

This file was deleted.

Loading

0 comments on commit 728d087

Please sign in to comment.