code cleanup

This commit is contained in:
Mariotaku Lee 2016-12-15 20:15:58 +08:00
parent db607b1061
commit a8ea218f3f
17 changed files with 152 additions and 80 deletions

View File

@ -35,6 +35,7 @@ subprojects {
ext.android_support_lib_version = '25.1.0'
ext.mariotaku_commons_library_version = '0.9.11'
ext.mariotaku_restfu_version = '0.9.34'
ext.play_services_version = '10.0.1'
}
afterEvaluate { project ->

View File

@ -39,5 +39,5 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.support:wearable:1.4.0'
compile 'com.google.android.gms:play-services-wearable:9.8.0'
compile "com.google.android.gms:play-services-wearable:$play_services_version"
}

View File

@ -90,7 +90,7 @@ dependencies {
// wearApp project(':twidere.wear')
kapt 'com.bluelinelabs:logansquare-compiler:1.3.7'
kapt 'com.hannesdorfmann.parcelableplease:processor:1.0.2'
kapt 'com.google.dagger:dagger-compiler:2.6.1'
kapt 'com.google.dagger:dagger-compiler:2.8'
kapt 'com.github.mariotaku.ObjectCursor:processor:0.9.12'
compile('com.github.mariotaku:app-theme-engine:1efc6237e1@aar') {
@ -102,8 +102,8 @@ dependencies {
compile project(':twidere.component.nyan')
// START Non-FOSS component
googleCompile 'com.google.android.gms:play-services-maps:10.0.1'
googleCompile 'com.google.android.gms:play-services-auth:10.0.1'
googleCompile "com.google.android.gms:play-services-maps:$play_services_version"
googleCompile "com.google.android.gms:play-services-auth:$play_services_version"
googleCompile 'com.google.maps.android:android-maps-utils:0.4.4'
googleCompile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') { transitive = true }
googleCompile 'com.anjlab.android.iab.v3:library:1.0.36'
@ -113,9 +113,9 @@ dependencies {
fdroidCompile 'org.osmdroid:osmdroid-android:5.5:release@aar'
debugCompile 'com.facebook.stetho:stetho:1.4.1'
debugCompile 'com.facebook.stetho:stetho-okhttp3:1.4.1'
debugCompile 'com.facebook.stetho:stetho-js-rhino:1.4.1'
debugCompile 'com.facebook.stetho:stetho:1.4.2'
debugCompile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
debugCompile 'com.facebook.stetho:stetho-js-rhino:1.4.2'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
provided 'javax.annotation:jsr250-api:1.0'
@ -141,7 +141,7 @@ dependencies {
compile 'com.squareup:otto:1.3.8'
compile 'dnsjava:dnsjava:2.1.7'
compile 'com.commonsware.cwac:merge:1.1.1'
compile 'com.commonsware.cwac:layouts:0.4.2'
compile 'com.commonsware.cwac:layouts:0.4.3'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.pnikosis:materialish-progress:1.7'
compile 'com.github.mariotaku:MessageBubbleView:1.6'
@ -161,9 +161,9 @@ dependencies {
compile 'com.github.mariotaku:PickNCrop:0.9.5'
compile "com.github.mariotaku.RestFu:library:$mariotaku_restfu_version"
compile "com.github.mariotaku.RestFu:okhttp3:$mariotaku_restfu_version"
compile 'com.squareup.okhttp3:okhttp:3.4.2'
compile 'com.squareup.okhttp3:okhttp:3.5.0'
compile 'com.lnikkila:extendedtouchview:0.1.0'
compile 'com.google.dagger:dagger:2.6.1'
compile 'com.google.dagger:dagger:2.8'
compile 'org.attoparser:attoparser:2.0.1.RELEASE'
compile 'com.getkeepsafe.taptargetview:taptargetview:1.6.0'
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.17'

View File

@ -67,7 +67,7 @@
-keep class * extends org.mariotaku.twidere.util.MapFragmentFactory
-keep class * extends org.mariotaku.twidere.util.TwitterCardFragmentFactory
-keep class * extends org.mariotaku.twidere.util.BugReporter
-keep class * extends org.mariotaku.twidere.util.Analyzer
-keepclassmembers class * {
private <fields>;

View File

@ -25,10 +25,7 @@ import android.accounts.OnAccountsUpdateListener
import android.app.Application
import android.os.Build
import com.crashlytics.android.Crashlytics
import com.crashlytics.android.answers.Answers
import com.crashlytics.android.answers.AnswersEvent
import com.crashlytics.android.answers.LoginEvent
import com.crashlytics.android.answers.SearchEvent
import com.crashlytics.android.answers.*
import io.fabric.sdk.android.Fabric
import org.mariotaku.ktextension.addOnAccountsUpdatedListenerSafe
import org.mariotaku.ktextension.configure
@ -36,6 +33,7 @@ import org.mariotaku.twidere.BuildConfig
import org.mariotaku.twidere.Constants
import org.mariotaku.twidere.TwidereConstants.ACCOUNT_TYPE
import org.mariotaku.twidere.model.analyzer.Search
import org.mariotaku.twidere.model.analyzer.Share
import org.mariotaku.twidere.model.analyzer.SignIn
/**
@ -56,9 +54,18 @@ class FabricAnalyzer : Analyzer(), Constants {
when (event) {
is SignIn -> {
answers.logLogin(configure(LoginEvent()) {
putMethod(event.type)
putMethod(event.accountType)
putSuccess(event.success)
putAttributes(event)
if (event.errorReason != null) {
putCustomAttribute("Error reason", event.errorReason)
}
if (event.accountHost != null) {
putCustomAttribute("Account host", event.accountHost)
}
if (event.credentialsType != null) {
putCustomAttribute("Credentials type", event.credentialsType)
}
putCustomAttribute("Official key", event.officialKey.toString())
})
}
is Search -> {
@ -67,6 +74,21 @@ class FabricAnalyzer : Analyzer(), Constants {
putAttributes(event)
})
}
is Share -> {
answers.logShare(configure(ShareEvent()) {
putContentId(event.id)
putContentType(event.type)
putAttributes(event)
})
}
else -> {
answers.logCustom(configure(CustomEvent(event.name)) {
putAttributes(event)
event.forEachValues { name, value ->
putCustomAttribute(name, value)
}
})
}
}
}
@ -88,8 +110,11 @@ class FabricAnalyzer : Analyzer(), Constants {
}
private fun AnswersEvent<*>.putAttributes(event: Analyzer.Event) {
if (event.account != null) {
putCustomAttribute("account", event.account)
if (event.accountType != null) {
putCustomAttribute("Account type", event.accountType)
}
if (event.accountHost != null) {
putCustomAttribute("Account host", event.accountHost)
}
}
}

View File

@ -0,0 +1,17 @@
package org.mariotaku.twidere.annotation;
import android.support.annotation.StringDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Created by mariotaku on 2016/12/15.
*/
@StringDef({ContentType.STATUS, ContentType.USER})
@Retention(RetentionPolicy.SOURCE)
public @interface ContentType {
String STATUS = "status";
String USER = "user";
}

View File

@ -398,7 +398,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
startActivity(intent)
}
Analyzer.log(SignIn(true, type = result.accountType.first, account = account.name,
Analyzer.log(SignIn(true, accountType = result.accountType.first, credentialsType = apiConfig.credentialsType,
officialKey = result.accountType.second?.official ?: false))
finish()
}
@ -429,7 +429,7 @@ class SignInActivity : BaseActivity(), OnClickListener, TextWatcher {
} else {
Utils.showErrorMessage(this, getString(R.string.action_signing_in), exception, true)
}
Analyzer.log(SignIn(false, type = "unknown", authType = apiConfig.credentialsType,
Analyzer.log(SignIn(false, accountType = "unknown", credentialsType = apiConfig.credentialsType,
errorReason = errorReason))
}

View File

@ -36,6 +36,7 @@ import org.mariotaku.twidere.activity.ComposeActivity
import org.mariotaku.twidere.activity.LinkHandlerActivity
import org.mariotaku.twidere.activity.iface.IControlBarActivity.ControlBarOffsetListener
import org.mariotaku.twidere.adapter.SupportTabsAdapter
import org.mariotaku.twidere.extension.getAccountType
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback
import org.mariotaku.twidere.fragment.iface.RefreshScrollTopInterface
import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback
@ -60,10 +61,10 @@ class SearchFragment : AbsToolbarTabPagesFragment(), RefreshScrollTopInterface,
val values = ContentValues()
values.put(SearchHistory.QUERY, query)
context.contentResolver.insert(SearchHistory.CONTENT_URI, values)
val am = AccountManager.get(context)
Analyzer.log(Search(query, accountKey.convert {
AccountUtils.findByAccountKey(AccountManager.get(context), it)
}?.name))
AccountUtils.findByAccountKey(am, it)
}?.getAccountType(am)))
}
}

View File

@ -979,7 +979,7 @@ class StatusFragment : BaseSupportFragment(), LoaderCallbacks<SingleResponse<Par
} else {
itemView.twitterCard.setCardSize(0, 0)
}
val cardFragment = TwitterCardUtils.createCardFragment(status)
val cardFragment = TwitterCardFragmentFactory.createCardFragment(status)
val fm = fragment.childFragmentManager
if (cardFragment != null && !FragmentManagerAccessor.isStateSaved(fm)) {
val ft = fm.beginTransaction()

View File

@ -28,7 +28,6 @@ import android.support.v4.app.LoaderManager
import android.support.v4.content.AsyncTaskLoader
import android.support.v4.content.ContextCompat
import android.support.v4.content.Loader
import android.text.TextUtils
import android.text.format.DateUtils
import android.util.Log
import android.view.LayoutInflater
@ -56,9 +55,9 @@ import org.mariotaku.twidere.model.ParcelableStatus
import org.mariotaku.twidere.model.util.AccountUtils
import org.mariotaku.twidere.model.util.ParcelableCardEntityUtils
import org.mariotaku.twidere.util.MicroBlogAPIFactory
import org.mariotaku.twidere.util.TwitterCardUtils
import org.mariotaku.twidere.util.support.ViewSupport
import java.util.*
import java.util.regex.Pattern
/**
* Created by mariotaku on 15/12/20.
@ -85,7 +84,7 @@ class CardPollFragment : BaseSupportFragment(), LoaderManager.LoaderCallbacks<Pa
private fun initChoiceView(savedInstanceState: Bundle?) {
val card = card
val status = status
val choicesCount = getChoicesCount(card)
val choicesCount = TwitterCardUtils.getChoicesCount(card)
val inflater = getLayoutInflater(savedInstanceState)
for (i in 0 until choicesCount) {
@ -99,7 +98,7 @@ class CardPollFragment : BaseSupportFragment(), LoaderManager.LoaderCallbacks<Pa
val context = context
if (card == null || status == null || context == null) return
fetchedCard = card
val choicesCount = getChoicesCount(card)
val choicesCount = TwitterCardUtils.getChoicesCount(card)
var votesSum = 0
val countsAreFinal = ParcelableCardEntityUtils.getAsBoolean(card, "counts_are_final", false)
val selectedChoice = ParcelableCardEntityUtils.getAsInteger(card, "selected_choice", -1)
@ -209,11 +208,6 @@ class CardPollFragment : BaseSupportFragment(), LoaderManager.LoaderCallbacks<Pa
loaderManager.restartLoader(0, null, this)
}
private fun getChoicesCount(card: ParcelableCardEntity): Int {
val matcher = PATTERN_POLL_TEXT_ONLY.matcher(card.name)
if (!matcher.matches()) throw IllegalStateException()
return NumberUtils.toInt(matcher.group(1))
}
private val card: ParcelableCardEntity
get() {
@ -316,9 +310,6 @@ class CardPollFragment : BaseSupportFragment(), LoaderManager.LoaderCallbacks<Pa
companion object {
val PATTERN_POLL_TEXT_ONLY: Pattern = Pattern.compile("poll([\\d]+)choice_text_only")
fun show(status: ParcelableStatus): CardPollFragment {
val fragment = CardPollFragment()
val args = Bundle()
@ -328,8 +319,5 @@ class CardPollFragment : BaseSupportFragment(), LoaderManager.LoaderCallbacks<Pa
return fragment
}
fun isPoll(card: ParcelableCardEntity): Boolean {
return PATTERN_POLL_TEXT_ONLY.matcher(card.name).matches() && !TextUtils.isEmpty(card.url)
}
}
}

View File

@ -1,5 +1,6 @@
package org.mariotaku.twidere.model.analyzer
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.util.Analyzer
/**
@ -8,5 +9,6 @@ import org.mariotaku.twidere.util.Analyzer
data class Search(
val query: String,
override val account: String?
@AccountType override val accountType: String?,
override val accountHost: String? = null
) : Analyzer.Event

View File

@ -0,0 +1,16 @@
package org.mariotaku.twidere.model.analyzer
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.annotation.ContentType
import org.mariotaku.twidere.util.Analyzer
/**
* Created by mariotaku on 2016/12/15.
*/
data class Share(
val id: String,
@ContentType val type: String,
@AccountType override val accountType: String,
override val accountHost: String? = null
) : Analyzer.Event

View File

@ -1,6 +1,7 @@
package org.mariotaku.twidere.model.analyzer
import org.mariotaku.twidere.annotation.AccountType
import org.mariotaku.twidere.model.account.cred.Credentials
import org.mariotaku.twidere.util.Analyzer
/**
@ -8,9 +9,9 @@ import org.mariotaku.twidere.util.Analyzer
*/
data class SignIn(
val success: Boolean,
@AccountType val type: String,
override val account: String? = null,
val officialKey: Boolean = false,
val authType: String? = null,
val errorReason: String? = null
@Credentials.Type val credentialsType: String? = null,
val errorReason: String? = null,
@AccountType override val accountType: String,
override val accountHost: String? = null
) : Analyzer.Event

View File

@ -20,6 +20,7 @@
package org.mariotaku.twidere.util
import android.app.Application
import org.mariotaku.twidere.annotation.AccountType
/**
* Created by mariotaku on 15/7/8.
@ -35,7 +36,15 @@ abstract class Analyzer {
protected abstract fun init(application: Application)
interface Event {
val account: String?
val name: String
get() = "Custom Event"
@AccountType val accountType: String?
@AccountType val accountHost: String?
get() = null
fun forEachValues(action: (key: String, value: String?) -> Unit) {
}
}
companion object {

View File

@ -32,8 +32,9 @@ abstract class MapFragmentFactory {
companion object {
val instance: MapFragmentFactory
get() = ServiceLoader.load(MapFragmentFactory::class.java).first()
val instance: MapFragmentFactory by lazy {
ServiceLoader.load(MapFragmentFactory::class.java).first()
}
}
}

View File

@ -42,8 +42,9 @@ abstract class TwitterCardFragmentFactory {
companion object {
val instance: TwitterCardFragmentFactory
get() = ServiceLoader.load(TwitterCardFragmentFactory::class.java).first()
val instance: TwitterCardFragmentFactory by lazy {
ServiceLoader.load(TwitterCardFragmentFactory::class.java).first()
}
fun createGenericPlayerFragment(card: ParcelableCardEntity?, args: Bundle?): Fragment? {
if (card == null) return null
@ -54,5 +55,27 @@ abstract class TwitterCardFragmentFactory {
fun createCardPollFragment(status: ParcelableStatus): Fragment {
return CardPollFragment.show(status)
}
fun createCardFragment(status: ParcelableStatus): Fragment? {
val card = status.card
if (card == null || card.name == null) return null
if (TwitterCardUtils.CARD_NAME_PLAYER == card.name) {
val playerFragment = instance.createPlayerFragment(card)
if (playerFragment != null) return playerFragment
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null)
} else if (TwitterCardUtils.CARD_NAME_AUDIO == card.name) {
val playerFragment = instance.createAudioFragment(card)
if (playerFragment != null) return playerFragment
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null)
} else if (TwitterCardUtils.CARD_NAME_ANIMATED_GIF == card.name) {
val playerFragment = instance.createAnimatedGifFragment(card)
if (playerFragment != null) return playerFragment
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null)
} else if (TwitterCardUtils.isPoll(card)) {
return TwitterCardFragmentFactory.createCardPollFragment(status)
}
return null
}
}
}

View File

@ -20,45 +20,23 @@
package org.mariotaku.twidere.util
import android.graphics.Point
import android.support.v4.app.Fragment
import android.text.TextUtils
import org.mariotaku.twidere.fragment.card.CardPollFragment
import org.apache.commons.lang3.math.NumberUtils
import org.mariotaku.twidere.model.ParcelableCardEntity
import org.mariotaku.twidere.model.ParcelableStatus
import org.mariotaku.twidere.model.util.ParcelableCardEntityUtils
import java.util.regex.Pattern
/**
* Created by mariotaku on 15/1/1.
*/
object TwitterCardUtils {
private val sFactory = TwitterCardFragmentFactory.instance
val CARD_NAME_PLAYER = "player"
val CARD_NAME_AUDIO = "audio"
val CARD_NAME_ANIMATED_GIF = "animated_gif"
fun createCardFragment(status: ParcelableStatus): Fragment? {
val card = status.card
if (card == null || card.name == null) return null
if (CARD_NAME_PLAYER == card.name) {
val playerFragment = sFactory.createPlayerFragment(card)
if (playerFragment != null) return playerFragment
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null)
} else if (CARD_NAME_AUDIO == card.name) {
val playerFragment = sFactory.createAudioFragment(card)
if (playerFragment != null) return playerFragment
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null)
} else if (CARD_NAME_ANIMATED_GIF == card.name) {
val playerFragment = sFactory.createAnimatedGifFragment(card)
if (playerFragment != null) return playerFragment
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null)
} else if (CardPollFragment.isPoll(card)) {
return TwitterCardFragmentFactory.createCardPollFragment(status)
}
return null
}
val PATTERN_POLL_TEXT_ONLY: Pattern = Pattern.compile("poll([\\d]+)choice_text_only")
const val CARD_NAME_PLAYER = "player"
const val CARD_NAME_AUDIO = "audio"
const val CARD_NAME_ANIMATED_GIF = "animated_gif"
fun getCardSize(card: ParcelableCardEntity): Point? {
val playerWidth = ParcelableCardEntityUtils.getAsInteger(card, "player_width", -1)
@ -88,14 +66,24 @@ object TwitterCardUtils {
return true
}
}
if (CardPollFragment.isPoll(card)) {
if (isPoll(card)) {
return true
}
return false
}
fun getChoicesCount(card: ParcelableCardEntity): Int {
val matcher = PATTERN_POLL_TEXT_ONLY.matcher(card.name)
if (!matcher.matches()) throw IllegalStateException()
return NumberUtils.toInt(matcher.group(1))
}
fun isPoll(card: ParcelableCardEntity): Boolean {
return PATTERN_POLL_TEXT_ONLY.matcher(card.name).matches() && !TextUtils.isEmpty(card.url)
}
fun isPoll(status: ParcelableStatus): Boolean {
val card = status.card ?: return false
return CardPollFragment.isPoll(card)
return isPoll(card)
}
}