Skip to content

Commit

Permalink
search history
Browse files Browse the repository at this point in the history
  • Loading branch information
ekibun committed Feb 22, 2019
1 parent a9e55c9 commit 2c15967
Show file tree
Hide file tree
Showing 62 changed files with 667 additions and 412 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
</activity>
<activity
android:name=".ui.setting.SettingsActivity"
android:label="@string/title_activity_settings"
android:label="@string/settings"
android:parentActivityName=".ui.main.MainActivity"
android:theme="@style/AppTheme.ActionBar">
<meta-data
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/soko/ekibun/bangumi/api/bangumi/Bangumi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.*
import soko.ekibun.bangumi.api.ApiHelper
import soko.ekibun.bangumi.api.bangumi.bean.*
import soko.ekibun.bangumi.api.bangumi.bean.Calendar
import soko.ekibun.bangumi.api.bangumi.bean.Collection
import soko.ekibun.bangumi.util.HttpUtil
import java.net.URI
Expand Down Expand Up @@ -511,22 +510,24 @@ interface Bangumi {
//userInfo
fun getUserInfo(ua: String): Call<UserInfo>{
val cookieManager = CookieManager.getInstance()
return ApiHelper.buildHttpCall(Bangumi.SERVER, mapOf("User-Agent" to ua)){
return ApiHelper.buildHttpCall("$SERVER/settings", mapOf("User-Agent" to ua)){
var needReload = false
val doc = Jsoup.parse(it.body()?.string()?:"")
val user = doc.selectFirst(".idBadgerNeue a.avatar")?: throw Exception("login failed")
val userName = doc.selectFirst("#header a")?.text()
val userName = doc.selectFirst("input[name=nickname]")?.attr("value")//doc.selectFirst("#header a")?.text()
val img = HttpUtil.getUrl(Regex("""background-image:url\('([^']*)'\)""").find(user.html()?:"")?.groupValues?.get(1)?:"", URI.create(Bangumi.SERVER))
val id = Regex("""/user/([^/]*)""").find(user.attr("href")?:"")?.groupValues?.get(1)
it.headers("set-cookie").forEach {
needReload = true
cookieManager.setCookie(Bangumi.SERVER, it) }
val formhash = doc.selectFirst("input[name=formhash]")?.attr("value")
val inbox = Regex("叮咚叮咚~你有 ([0-9]+) 条新信息!").find(doc.selectFirst("#robot_speech_js")?.text()?:"")?.groupValues?.get(1)?.toIntOrNull()?:0
val notify = doc.selectFirst("#notify_count")?.text()?.toIntOrNull()?:0
UserInfo(id?.toIntOrNull()?:0, HttpUtil.getUrl(user.attr("href")?:"", URI.create(SERVER)), id, userName,
Images(img.replace("/s/", "/l/"),
img.replace("/s/", "/l/"),
img.replace("/s/", "/m/"), img,
img.replace("/s/", "/m/")), sign = formhash, needReload = needReload)
img.replace("/s/", "/m/")), sign = formhash, needReload = needReload, notify = Pair(inbox, notify))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package soko.ekibun.bangumi.api.bangumi.bean

import android.support.annotation.StringDef
import soko.ekibun.bangumi.R

object CollectionStatusType{
const val WISH = "wish"
Expand All @@ -11,4 +12,14 @@ object CollectionStatusType{
@StringDef(WISH, COLLECT, DO, ON_HOLD, DROPPED)
annotation class CollectionStatusType
val status=arrayOf(WISH, COLLECT, DO, ON_HOLD, DROPPED)

fun getTypeNamesResId(@SubjectType.SubjectType type: Int): Int{
return when(type){
SubjectType.BOOK -> R.array.collection_status_book
SubjectType.MUSIC -> R.array.collection_status_music
SubjectType.GAME -> R.array.collection_status_game
SubjectType.REAL -> R.array.collection_status_real
else -> R.array.collection_status_anime
}
}
}
26 changes: 14 additions & 12 deletions app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/Episode.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package soko.ekibun.bangumi.api.bangumi.bean

import android.annotation.SuppressLint
import android.content.Context
import android.support.annotation.IntDef
import soko.ekibun.bangumi.R
import java.text.DecimalFormat


Expand Down Expand Up @@ -37,11 +39,11 @@ data class Episode(
* status : Air
*/

fun parseSort(): String{
fun parseSort(context: Context): String{
return if(type == TYPE_MAIN)
"${DecimalFormat("#.##").format(sort)}"
context.getString(R.string.parse_sort_ep, DecimalFormat("#.##").format(sort))
else
getTypeName(type) + " ${DecimalFormat("#.##").format(sort)}"
context.getString(getTypeName(type)) + " ${DecimalFormat("#.##").format(sort)}"
}

companion object {
Expand All @@ -58,16 +60,16 @@ data class Episode(
annotation class EpisodeType

@SuppressLint("SwitchIntDef")
fun getTypeName(@EpisodeType type: Int): String{
fun getTypeName(@EpisodeType type: Int): Int{
return when(type){
TYPE_MAIN -> "本篇"
TYPE_SP -> "特别篇"
TYPE_OP -> "OP"
TYPE_ED -> "ED"
TYPE_PV -> "PV"
TYPE_MAD -> "MAD"
TYPE_MUSIC -> "曲目"
else -> "其他"
TYPE_MAIN -> R.string.episode_type_main
TYPE_SP -> R.string.episode_type_sp
TYPE_OP -> R.string.episode_type_op
TYPE_ED -> R.string.episode_type_ed
TYPE_PV -> R.string.episode_type_pv
TYPE_MAD -> R.string.episode_type_mad
TYPE_MUSIC -> R.string.episode_type_music
else -> R.string.episode_type_main
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ data class Images(

fun getImage(context: Context): String? {
val quality = PreferenceManager.getDefaultSharedPreferences(context).getString("image_quality", "c")
return common?.replace("/c/", "/$quality/")
return when(quality){
"l" -> large
"m" -> medium
"s" -> small
"g" -> grid
else -> common
}
}
/**
* large : http://lain.bgm.tv/pic/cover/l/e5/ba/6776_bA2h2.jpg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package soko.ekibun.bangumi.api.bangumi.bean
import android.annotation.SuppressLint
import android.support.annotation.IntDef
import android.support.annotation.StringDef
import soko.ekibun.bangumi.R

object SubjectType{
const val ALL = 0
Expand Down Expand Up @@ -31,15 +32,14 @@ object SubjectType{
)

@SuppressLint("SwitchIntDef")
fun getDescription(@SubjectType type: Int): String{
fun getDescription(@SubjectType type: Int): Int{
return when (type) {
ALL -> "条目"
BOOK -> "书籍"
ANIME -> "动画"
MUSIC -> "音乐"
GAME -> "游戏"
REAL -> "三次元"
else -> ""
BOOK -> R.string.book
ANIME -> R.string.anime
MUSIC -> R.string.music
GAME -> R.string.game
REAL -> R.string.real
else -> R.string.subject
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ data class UserInfo(
var nickname: String? = null,
var avatar: Images? = null,
var sign: String? = null, //formhash
var needReload: Boolean = false
var needReload: Boolean = false,
var notify: Pair<Int, Int>? = null
): BaseRequest(){
/**
* id : 419012
Expand Down
134 changes: 0 additions & 134 deletions app/src/main/java/soko/ekibun/bangumi/api/bangumi/bean/gson.java

This file was deleted.

36 changes: 36 additions & 0 deletions app/src/main/java/soko/ekibun/bangumi/model/SearchHistoryModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package soko.ekibun.bangumi.model

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import com.google.gson.reflect.TypeToken
import soko.ekibun.bangumi.util.JsonUtil

class SearchHistoryModel(context: Context){
val sp: SharedPreferences by lazy{ PreferenceManager.getDefaultSharedPreferences(context) }

fun addHistory(searchKey: String) {
val newList = getHistoryList().toMutableList()
newList.add(0, searchKey)
sp.edit().putString(PREF_SEARCH_HISTORY, JsonUtil.toJson(newList.distinct())).apply()
}

fun removeHistory(searchKey: String): Boolean {
val newList = getHistoryList().toMutableList()
val removed = newList.remove(searchKey)
sp.edit().putString(PREF_SEARCH_HISTORY, JsonUtil.toJson(newList)).apply()
return removed
}

fun clearHistory() {
sp.edit().putString(PREF_SEARCH_HISTORY, JsonUtil.toJson(ArrayList<String>())).apply()
}

fun getHistoryList(): List<String> {
return JsonUtil.toEntity(sp.getString(PREF_SEARCH_HISTORY, JsonUtil.toJson(ArrayList<String>()))!!, object: TypeToken<List<String>>() {}.type)?:ArrayList()
}

companion object {
const val PREF_SEARCH_HISTORY="searchHistory"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CrashActivity : AppCompatActivity() {
uploadCall?.cancel()
uploadCall = Xxxlin.createInstance().crashReport(content, AppUtil.getVersionCode(this), AppUtil.getVersionName(this))
uploadCall?.enqueue(ApiHelper.buildCallback(this, {
Snackbar.make(item_upload, if(it.code == 0) "日志上传成功" else "日志上传失败:${it.msg}", Snackbar.LENGTH_SHORT).show()
Snackbar.make(item_upload, if(it.code == 0) getString(R.string.crash_upload_ok) else getString(R.string.crash_upload_failed, it.msg?:""), Snackbar.LENGTH_SHORT).show()
item_upload.setOnClickListener{}
}, {}))
}
Expand Down
Loading

0 comments on commit 2c15967

Please sign in to comment.