Skip to content

Commit

Permalink
Feat login feature enhanchement (fabricezhang#37)
Browse files Browse the repository at this point in the history
* fix: fix online crashes

* fix: fix discover page crashes due to network time-out

* fix: fix rank list position not accurate

* feat: change article feed ui

* update: add debounce for reply/comment btn

* fix: fix lanzous extract regex rule

* fix: fix fragment diss issue

* update: update about fragment

* update: add num of reply

* fix: fix resolve image on reply error

* update: change reply title ui

* fix: fix draw table link span issue

* change: change class name to pre code

* change: change class name to pre code

* feat: add pre tag handle config

* change: change default search engine for visitors

* fix: fix crashes on bugly #1625263 #1540098 #1630252

* fix: fix crashes on bugly #1622256 #1658884

* fix: format fix

* fix: fix heat alignment

* update: update article post/reply ui
  • Loading branch information
fabricezhang authored Jul 2, 2020
1 parent fcb0736 commit d239cba
Show file tree
Hide file tree
Showing 40 changed files with 887 additions and 565 deletions.
15 changes: 14 additions & 1 deletion app/src/main/java/top/easelink/lcg/config/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences
import com.tencent.stat.StatConfig
import top.easelink.lcg.appinit.LCGApp
import top.easelink.lcg.spipedata.UserData

object AppConfig {

Expand All @@ -13,12 +14,17 @@ object AppConfig {
private const val CONFIG_JRS_URL = "jrs_page"
private const val CONFIG_ENABLE_FOLLOW_REDIRECTS = "follow_redirects"
private const val CONFIG_SEARCH_OPEN_RESULT_IN_WEBVIEW = "open_result_in_webview"
private const val CONFIG_ARTICLE_HANDLE_PRE_TAG = "handle_pre_tag_in_article"
private const val CONFIG_ARTICLE_IN_WEBVIEW = "open_article_in_webview"
private const val CONFIG_ARTICLE_SHOW_RECOMMEND_FLAG = "article_show_recommend_flag"
private const val CONFIG_DEFAULT_SEARCH_ENGINE = "default_search_engine"
private const val CONFIG_AUTO_SIGN_IN = "auto_sign_in"
private const val CONFIG_SYNC_FAVORITES = "sync_favorites"


private const val CONFIG_SEARCH_ENGINE_BAIDU = 1
private const val CONFIG_SEARCH_ENGINE_WUAI = 0
// Config from Remote
fun getAppReleaseUrl(): String {
return StatConfig.getCustomProperty(CONFIG_APP_RELEASE_URL, "thread-1073834-1-1.html")
}
Expand All @@ -41,12 +47,19 @@ object AppConfig {
get() = get(CONFIG_ARTICLE_IN_WEBVIEW, false)
set(value) = put(CONFIG_ARTICLE_IN_WEBVIEW, value)

var articleHandlePreTag: Boolean
get() = get(CONFIG_ARTICLE_HANDLE_PRE_TAG, true)
set(value) = put(CONFIG_ARTICLE_HANDLE_PRE_TAG, value)

var articleShowRecommendFlag: Boolean
get() = get(CONFIG_ARTICLE_SHOW_RECOMMEND_FLAG, true)
set(value) = put(CONFIG_ARTICLE_SHOW_RECOMMEND_FLAG, value)

var defaultSearchEngine: Int
get() = get(CONFIG_DEFAULT_SEARCH_ENGINE, 0)
get() = get(
CONFIG_DEFAULT_SEARCH_ENGINE,
if (UserData.isLoggedIn) CONFIG_SEARCH_ENGINE_WUAI else CONFIG_SEARCH_ENGINE_BAIDU
)
set(value) = put(CONFIG_DEFAULT_SEARCH_ENGINE, value)

var autoSignEnable: Boolean
Expand Down
26 changes: 12 additions & 14 deletions app/src/main/java/top/easelink/lcg/network/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,19 @@ object Client: ApiRequest {
}
}

private fun checkResponse(doc: Document) {
GlobalScope.launch(BackGroundPool){
// try update from hash which is used to send post request, ex: replay
if (formHash.isNullOrEmpty()) {
formHash = extractFormHash(doc)
}
if (System.currentTimeMillis() - lastTime > CHECK_INTERVAL) {
lastTime = System.currentTimeMillis()
try {
// TODO check login state is not stable
private fun checkResponse(doc: Document) = GlobalScope.launch(BackGroundPool){
// try update from hash which is used to send post request, ex: replay
if (formHash.isNullOrEmpty()) {
formHash = extractFormHash(doc)
}
if (System.currentTimeMillis() - lastTime > CHECK_INTERVAL) {
lastTime = System.currentTimeMillis()
try {
// TODO check login state is not stable
// checkLoginState(doc)
checkMessages(doc)
} catch (e: Exception) {
Timber.e(e)
}
checkMessages(doc)
} catch (e: Exception) {
Timber.e(e)
}
}
}
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/top/easelink/lcg/spipedata/UserData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,24 @@ object UserData {
private fun <T: Any> get(key: String, default: T): T {
SharedPreferencesHelper.getUserSp().let {
val res = when (default) {
is String -> it.getString(key, default)
is Int -> it.getInt(key, default)
is Boolean -> it.getBoolean(key, default)
is String -> it.getString(key, default as String)
is Int -> it.getInt(key, default as Int)
is Boolean -> it.getBoolean(key, default as Boolean)
else -> null
}
return res as? T?:default
}
}

@Suppress("UNCHECKED_CAST", "IMPLICIT_CAST_TO_ANY")
private fun <T: Any?> put(key: String, value: T) {
SharedPreferencesHelper
.getUserSp()
.edit()
.apply {
when (value) {
is String -> putString(key, value)
is Int -> putInt(key, value)
is Boolean -> putBoolean(key, value)
is String -> putString(key, value as String)
is Int -> putInt(key, value as Int)
is Boolean -> putBoolean(key, value as Boolean)
else -> return
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
package top.easelink.lcg.ui.main.about.view

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.lifecycle.ViewModelProvider
import top.easelink.framework.base.BaseFragment
import top.easelink.lcg.BR
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_about.*
import top.easelink.framework.topbase.ControllableFragment
import top.easelink.framework.topbase.TopFragment
import top.easelink.lcg.R
import top.easelink.lcg.databinding.FragmentAboutBinding
import top.easelink.lcg.ui.main.about.viewmodel.AboutViewModel
import top.easelink.lcg.ui.webview.view.WebViewActivity
import java.util.*

class AboutFragment : BaseFragment<FragmentAboutBinding, AboutViewModel?>() {
override fun getBindingVariable(): Int {
return BR.viewModel
}

override fun getLayoutId(): Int {
return R.layout.fragment_about
class AboutFragment : TopFragment(), ControllableFragment {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_about, container, false)
}

override fun getViewModel(): AboutViewModel {
return ViewModelProvider(this)[AboutViewModel::class.java]
override fun isControllable(): Boolean {
return true
}

override fun onViewCreated(
Expand All @@ -30,31 +33,39 @@ class AboutFragment : BaseFragment<FragmentAboutBinding, AboutViewModel?>() {
) {
super.onViewCreated(view, savedInstanceState)
syncAuthorState()
viewDataBinding!!.githubUrl.setOnClickListener {
github_url.setOnClickListener {
WebViewActivity.startWebViewWith(getString(R.string.github_url), it.context)
}
author_email.setOnClickListener {
val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_EMAIL, getString(R.string.author_email))
intent.putExtra(Intent.EXTRA_SUBJECT, "问题反馈")
// intent.putExtra(Intent.EXTRA_TEXT, "")
startActivity(Intent.createChooser(intent, "发送反馈邮件"))
}
}

private fun syncAuthorState() {
val hour = Calendar.getInstance()[Calendar.HOUR_OF_DAY]
when {
hour < 7 -> {
viewDataBinding!!.me.setAnimation(R.raw.moon_stars)
me.setAnimation(R.raw.moon_stars)
}
hour < 12 -> {
viewDataBinding!!.me.setAnimation(R.raw.personal_mac_daytime)
me.setAnimation(R.raw.personal_mac_daytime)
}
hour == 12 -> {
viewDataBinding!!.me.setAnimation(R.raw.sun)
me.setAnimation(R.raw.sun)
}
hour < 18 -> {
viewDataBinding!!.me.setAnimation(R.raw.personal_phone_daytime)
me.setAnimation(R.raw.personal_phone_daytime)
}
hour < 22 -> {
viewDataBinding!!.me.setAnimation(R.raw.personal_mac_night)
me.setAnimation(R.raw.personal_mac_night)
}
else -> {
viewDataBinding!!.me.setAnimation(R.raw.personal_phone_night)
me.setAnimation(R.raw.personal_phone_night)
}
}
}
Expand Down

This file was deleted.

Loading

0 comments on commit d239cba

Please sign in to comment.