Skip to content

Commit

Permalink
fix bugs on crashlytic
Browse files Browse the repository at this point in the history
1. fix getVerifyCode npe issue
2. fix MemberActivity gson null issue
  • Loading branch information
fan123199 committed Jul 30, 2018
1 parent f1679dc commit 38324f8
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 58 deletions.
1 change: 1 addition & 0 deletions .idea/dictionaries/fdx.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'io.fabric'


Properties prop = getSignConfig()

android {

compileSdkVersion 28
Expand All @@ -22,11 +20,15 @@ android {
abortOnError false
}
signingConfigs {
googlePlay {
keyAlias prop['keyAlias']
keyPassword prop['keyPassword']
storeFile file(prop['storeFile'])
storePassword prop['storePassword']

googlePlay {
Properties prop = getSignConfig()
if (prop != null&&false) {
keyAlias prop['keyAlias']
keyPassword prop['keyPassword']
storeFile file(prop['storeFile'])
storePassword prop['storePassword']
}
}
}
buildTypes {
Expand Down Expand Up @@ -81,6 +83,7 @@ dependencies {
implementation "com.android.support:support-v4:$support_version"
implementation "com.android.support:customtabs:$support_version"
implementation "com.android.support:preference-v7:$support_version"
implementation "com.android.support:design:$support_version"

implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha1'

Expand All @@ -92,7 +95,6 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'de.hdodenhof:circleimageview:2.2.0'
// implementation 'com.daimajia.swipelayout:library:1.2.0@aar'
implementation "com.android.support:design:$support_version"
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
implementation 'org.jsoup:jsoup:1.11.3'
// implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
Expand All @@ -115,7 +117,12 @@ dependencies {
def getSignConfig() {
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
try {
def stream = new FileInputStream(keystorePropertiesFile)
keystoreProperties.load(stream)
}catch (FileNotFoundException e) {
return null
}
return keystoreProperties
}

Expand Down
13 changes: 7 additions & 6 deletions app/src/main/java/im/fdx/v2ex/network/Parser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Parser(private val htmlStr: String) {
fun getOnce(): String? = Regex("favorite/node/\\d{1,8}\\?once=\\d{1,10}").find(htmlStr)?.value

fun getOnceNum() = doc.getElementsByAttributeValue("name", "once").first()?.attr("value")
fun getOnceNum2() = Regex("(?<=<input type=\"hidden\" name=\"once\" value=\")(\\d+)").find(htmlStr)?.value


fun isTopicFavored(): Boolean {
Expand Down Expand Up @@ -300,14 +301,14 @@ class Parser(private val htmlStr: String) {
fun getVerifyCode(): String? {

// <a href="/favorite/topic/349111?t=eghsuwetutngpadqplmlnmbndvkycaft" class="tb">加入收藏</a>
val element: Element? = doc.getElementsByClass("topic_buttons").first().getElementsByTag("a").first()
val element: Element = doc.getElementsByClass("topic_buttons")?.first()?.getElementsByTag("a")?.first()
?: return null
val p = Pattern.compile("(?<=favorite/topic/\\d{1,10}\\?t=)\\w+")

val matcher = p.matcher(element!!.outerHtml())
if (matcher.find()) {
return matcher.group()
val matcher = p.matcher(element.outerHtml())
return if (matcher.find()) {
matcher.group()
} else
return null
null
}

fun parseResponseToTopic(topicId: String): Topic {
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/java/im/fdx/v2ex/ui/details/DetailsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DetailsActivity : BaseActivity() {
invalidateOptionsMenu()
setFootView(false)
} else if (intent.action == "im.fdx.v2ex.reply") {
XLog.tag("HEHE").d("MSG_GET LocalBroadCast")
logd("MSG_GET LocalBroadCast")
token = intent.getStringExtra("token")
val rm = intent.getParcelableArrayListExtra<ReplyModel>("replies")
mAdapter.addItems(rm)
Expand Down Expand Up @@ -344,7 +344,7 @@ class DetailsActivity : BaseActivity() {
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {

R.id.menu_favor -> favorOrNot(mTopicId, token!!, isFavored)
R.id.menu_favor -> favorOrNot(mTopicId, token, isFavored)
R.id.menu_reply -> {
et_post_reply.requestFocus()
val inputMethodManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
Expand Down Expand Up @@ -376,10 +376,9 @@ class DetailsActivity : BaseActivity() {
return super.onOptionsItemSelected(item)
}

private fun favorOrNot(topicId: String, token: String, doFavor: Boolean) {
HttpHelper.OK_CLIENT.newCall(Request.Builder()
.url("${NetManager.HTTPS_V2EX_BASE}/${if (doFavor) "un" else ""}favorite/topic/$topicId?t=$token")
.get().build()).enqueue(object : Callback {
private fun favorOrNot(topicId: String, token: String?, doFavor: Boolean) {
vCall("${NetManager.HTTPS_V2EX_BASE}/${if (doFavor) "un" else ""}favorite/topic/$topicId?t=$token")
.start(object : Callback {

override fun onFailure(call: Call, e: IOException) {
dealError(this@DetailsActivity, swipe = swipe_details)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/im/fdx/v2ex/ui/details/DetailsAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import java.io.IOException
/**
* Created by fdx on 15-9-7.
* 详情页的Adapter。
*
* todo 把 allList 分离
*/
class DetailsAdapter(private val mContext: Context,
private val callback: DetailsAdapter.AdapterCallback,
Expand Down
14 changes: 8 additions & 6 deletions app/src/main/java/im/fdx/v2ex/ui/details/MoreReplyService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ class MoreReplyService @JvmOverloads constructor(name: String = "what") : Intent
val token = parser.getVerifyCode()

if (replies.isEmpty()) return
val it = Intent()
it.action = "im.fdx.v2ex.reply"
it.putExtra("token", token)
it.putParcelableArrayListExtra("replies", replies)
val replyIntent = Intent()
replyIntent.action = "im.fdx.v2ex.reply"
token?.let {
replyIntent.putExtra("token", token)
}
replyIntent.putParcelableArrayListExtra("replies", replies)

if (i == totalPage && isToBottom) {
it.putExtra("bottom", true)
replyIntent.putExtra("bottom", true)
}
LocalBroadcastManager.getInstance(this).sendBroadcast(it)
LocalBroadcastManager.getInstance(this).sendBroadcast(replyIntent)
}

} catch (e: IOException) {
Expand Down
13 changes: 2 additions & 11 deletions app/src/main/java/im/fdx/v2ex/ui/main/NewTopicActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@ class NewTopicActivity : BaseActivity() {
NetManager.dealError(this@NewTopicActivity, response.code())
return
}
once = getOnce(response)
once = Parser(response.body()!!.string()).getOnceNum2()
if (once == null) {
toast("发布主题失败,请退出app重试")
return
}

Expand Down Expand Up @@ -259,16 +260,6 @@ class NewTopicActivity : BaseActivity() {
})
}

private fun getOnce(response: Response): String? {
val p = Pattern.compile("(?<=<input type=\"hidden\" name=\"once\" value=\")(\\d+)")
val matcher = p.matcher(response.body()!!.string())
if (!matcher.find()) {
runOnUiThread { toast("无法发布主题,请退出后重试") }
return null
}
return matcher.group()
}

private fun resetIcon(item: MenuItem) {
runOnUiThread {
item.setIcon(R.drawable.ic_send_white_24dp)
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/im/fdx/v2ex/ui/member/Member.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ data class Member(
var avatar_normal: String = "",
@ColumnInfo(name = "member_avatar_large")
var avatar_large: String = "",
var github: String = "",
var btc: String = "",
var location: String = "",
var bio: String = "",
var twitter: String = "",
var website: String = ""
var github: String? = "",
var btc: String? = "",
var location: String? = "",
var twitter: String? = "",
var website: String? = ""
) : BaseModel(), Parcelable {

val avatarNormalUrl: String
Expand Down
30 changes: 16 additions & 14 deletions app/src/main/java/im/fdx/v2ex/ui/member/MemberActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import android.view.animation.AlphaAnimation
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import com.elvishew.xlog.XLog
import im.fdx.v2ex.BuildConfig
import im.fdx.v2ex.MyApp
import im.fdx.v2ex.R
Expand All @@ -37,6 +36,7 @@ import im.fdx.v2ex.ui.main.TopicsFragment
import im.fdx.v2ex.utils.Keys
import im.fdx.v2ex.utils.TimeUtil
import im.fdx.v2ex.utils.extensions.load
import im.fdx.v2ex.utils.extensions.logd
import im.fdx.v2ex.utils.extensions.logi
import im.fdx.v2ex.utils.extensions.setUpToolbar
import im.fdx.v2ex.view.CustomChrome
Expand Down Expand Up @@ -168,7 +168,7 @@ class MemberActivity : BaseActivity() {
val html = response.body()!!.string()
isBlocked = isBlock(html)
isFollowed = isFollowed(html)
XLog.d("isBlocked: $isBlocked|isFollowed: $isFollowed")
logd("isBlocked: $isBlocked|isFollowed: $isFollowed")


runOnUiThread {
Expand Down Expand Up @@ -221,9 +221,9 @@ class MemberActivity : BaseActivity() {
when (it.id) {
R.id.tv_location -> {
}
R.id.tv_github -> if (!(member.github).isEmpty()) CustomChrome(this).load("https://www.github.com/" + member.github)
R.id.tv_github -> if (!(member.github).isNullOrEmpty()) CustomChrome(this).load("https://www.github.com/" + member.github)
R.id.tv_twitter -> {
if (!(member.twitter).isEmpty()) {
if (!(member.twitter).isNullOrEmpty()) {
val intent: Intent
try {
packageManager.getPackageInfo("com.twitter.android", 0)
Expand All @@ -237,9 +237,9 @@ class MemberActivity : BaseActivity() {
}
}
R.id.tv_website -> when {
!(member.website).isEmpty() ->
CustomChrome(this).load(if (!member.website.contains("http")) "http://"
+ member.website else member.website)
!(member.website).isNullOrEmpty() ->
CustomChrome(this).load(if (!member.website!!.contains("http")) "http://"
+ member.website else member.website!!)
}
}
}
Expand All @@ -255,15 +255,17 @@ class MemberActivity : BaseActivity() {
mTvIntro.text = member.bio
mTvUserCreatedPrefix.text = "加入于${TimeUtil.getAbsoluteTime((member.created).toLong())},${getString(R.string.the_n_member, member.id)}"

mTvBitCoin.isGone = member.btc.isEmpty()
mTvGithub.isGone = member.github.isEmpty()
mTvLocation.isGone = member.location.isEmpty()
mTvTwitter.isGone = member.twitter.isEmpty()
mTvWebsite.isGone = member.website.isEmpty()
mTvBitCoin.isGone = member.btc.isNullOrEmpty()
mTvGithub.isGone = member.github.isNullOrEmpty()
mTvLocation.isGone = member.location.isNullOrEmpty()
mTvTwitter.isGone = member.twitter.isNullOrEmpty()
mTvWebsite.isGone = member.website.isNullOrEmpty()

mTvIntro.isGone = member.bio.isEmpty()
mTvIntro.isGone = member.bio.isNullOrEmpty()

llInfo.isGone = (member.website + member.twitter + member.github + member.btc + member.location).isEmpty()
llInfo.isGone = member.btc.isNullOrEmpty() && member.github.isNullOrEmpty() &&
member.location.isNullOrEmpty() &&
member.twitter.isNullOrEmpty() && member.website.isNullOrEmpty()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand Down

0 comments on commit 38324f8

Please sign in to comment.