Skip to content

Commit

Permalink
redirect to https://bgm.tv
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed May 22, 2019
1 parent 6a72b87 commit a3e1515
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 27 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ interface Bangumi {

@SuppressLint("UseSparseArrays")
fun getSubject(subject: Subject, ua: String): Call<Subject>{
return ApiHelper.buildHttpCall(subject.url?:"", mapOf("User-Agent" to ua)){ response ->
return ApiHelper.buildHttpCall("$SERVER/subject/${subject.id}", mapOf("User-Agent" to ua)){ response ->
val doc = Jsoup.parse(response.body()?.string()?:"")
val type = when(doc.selectFirst("#navMenuNeue .focus").text()){
"动画" -> SubjectType.ANIME
Expand Down Expand Up @@ -324,7 +324,7 @@ interface Bangumi {
}

fun getComments(subject: Subject, page: Int, ua: String): Call<List<Comment>>{
return ApiHelper.buildHttpCall("${subject.url?:""}/comments?page=$page", mapOf("User-Agent" to ua)){
return ApiHelper.buildHttpCall("$SERVER/subject/${subject.id}/comments?page=$page", mapOf("User-Agent" to ua)){
val doc = Jsoup.parse(it.body()?.string()?:"")
val ret = ArrayList<Comment>()
doc.selectFirst("#comment_box")?.let{
Expand Down Expand Up @@ -445,7 +445,7 @@ interface Bangumi {

//讨论
fun getTopic(url: String, ua: String): Call<Topic>{
return ApiHelper.buildHttpCall(url, mapOf("User-Agent" to ua)){
return ApiHelper.buildHttpCall(url.replace(Regex("""^https?://(bgm\.tv|bangumi\.tv|chii\.in)"""), SERVER), mapOf("User-Agent" to ua)){
val doc = Jsoup.parse(it.body()?.string()?:"")
val replies = ArrayList<TopicPost>()
doc.select(".re_info")?.map{ it.parent() }?.forEach{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class DownloadCacheProvider(val context: AppCompatActivity, val onServiceConnect
context.bindService(aidlIntent, this, Context.BIND_AUTO_CREATE)
}

fun unbindService(){
if(aidl != null) context.unbindService(this)
}

fun getCacheList(onFinish: (List<SubjectCache>)->Unit, onReject: (String)->Unit){
aidl?.getCacheList("bangumi", object: IListSubjectCacheCallback.Stub() {
override fun onFinish(result: MutableList<SubjectCache>) {
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/soko/ekibun/bangumi/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainActivity : AppCompatActivity() {
Github.createInstance().releases().enqueue(ApiHelper.buildCallback(this, {
val release = it.firstOrNull()?:return@buildCallback
val current = packageManager?.getPackageInfo(packageName, 0)?.versionName?:""
if(release.tag_name?.compareTo(current)?:0 > 0 && sp.getString("ignore_tag", "") != release.tag_name)
if(!isFinishing && release.tag_name?.compareTo(current)?:0 > 0 && sp.getString("ignore_tag", "") != release.tag_name)
AlertDialog.Builder(this)
.setTitle( getString(R.string.parse_new_version, release.tag_name))
.setMessage( it.filter { it.tag_name?.compareTo(current)?:0 > 0 }.map { "${it.tag_name}\n${it.body}" }.reduce { acc, s -> "$acc\n$s" } )
Expand All @@ -61,7 +61,7 @@ class MainActivity : AppCompatActivity() {

override fun onDestroy() {
super.onDestroy()
unbindService(downloadCacheProvider)
downloadCacheProvider.unbindService()
}

val ua by lazy { WebView(this).settings.userAgentString }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import soko.ekibun.bangumi.ui.main.fragment.home.fragment.collection.CollectionF
import soko.ekibun.bangumi.ui.main.fragment.home.fragment.rakuen.RakuenFragment
import soko.ekibun.bangumi.ui.main.fragment.home.fragment.timeline.TimeLineFragment

class HomePagerAdapter(private val context: Context, fragmentManager: androidx.fragment.app.FragmentManager, pager: androidx.viewpager.widget.ViewPager): androidx.fragment.app.FragmentPagerAdapter(fragmentManager) {
class HomePagerAdapter(private val context: Context, fragmentManager: FragmentManager, pager: ViewPager): androidx.fragment.app.FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
val fragments: List<HomeTabFragment> = listOf(
TimeLineFragment(),
CollectionFragment(),
Expand All @@ -18,7 +18,7 @@ class HomePagerAdapter(private val context: Context, fragmentManager: androidx.f

init{
pager.offscreenPageLimit = 4
pager.addOnPageChangeListener(object: androidx.viewpager.widget.ViewPager.OnPageChangeListener{
pager.addOnPageChangeListener(object: ViewPager.OnPageChangeListener{
override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class SubjectPresenter(private val context: SubjectActivity){
}

private fun removeCollection(subject: Subject){
if(context.isFinishing) return
AlertDialog.Builder(context).setTitle(R.string.collection_dialog_remove)
.setNegativeButton(R.string.cancel) { _, _ -> }.setPositiveButton(R.string.ok) { _, _ ->
ApiHelper.buildHttpCall("${Bangumi.SERVER}/subject/${subject.id}/remove?gh=${context.formhash}", mapOf("User-Agent" to context.ua)){ it.code() == 200 }
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/soko/ekibun/bangumi/ui/web/WebActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import java.net.URI

class WebActivity : SwipeBackActivity() {
private val isAuth by lazy{ intent.getBooleanExtra(IS_AUTH, false)}
private val openUrl by lazy{ intent.getStringExtra(OPEN_URL)}
private val openUrl by lazy{ intent.getStringExtra(OPEN_URL).replace(Regex("""^https?://(bgm\.tv|bangumi\.tv|chii\.in)"""), Bangumi.SERVER) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -72,6 +72,12 @@ class WebActivity : SwipeBackActivity() {
e.printStackTrace()
return false }
return true
}else {
val bgmUrl = url.replace(Regex("""^https?://(bgm\.tv|bangumi\.tv|chii\.in)"""), Bangumi.SERVER)
if(bgmUrl != url){
webview.loadUrl(bgmUrl)
return true
}
}
return false
}
Expand Down
20 changes: 1 addition & 19 deletions app/src/main/java/soko/ekibun/bangumi/util/GlideUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,7 @@ object GlideUtil {
* @param fragment The fragment to use.
* @return A RequestManager for the given Fragment that can be used to start a load.
*/
fun with(fragment: androidx.fragment.app.Fragment): RequestManager? {
return try{
Glide.with(fragment)
}catch(e: IllegalArgumentException){
null
}
}

/**
* Begin a load with Glide that will be tied to the given [android.app.Fragment]'s lifecycle
* and that uses the given [android.app.Fragment]'s default options.
*
* @param fragment The fragment to use.
* @return A RequestManager for the given Fragment that can be used to start a load.
*/
@Deprecated("Prefer support Fragments and {@link #with(Fragment)} instead,\n" +
" {@link android.app.Fragment} will be deprecated. See\n" +
" https://github.com/android/android-ktx/pull/161#issuecomment-363270555.")
fun with(fragment: android.app.Fragment): RequestManager? {
fun with(fragment: Fragment): RequestManager? {
return try{
Glide.with(fragment)
}catch(e: IllegalArgumentException){
Expand Down

0 comments on commit a3e1515

Please sign in to comment.