Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unification for activities start #137

Merged
merged 3 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MainActivity :
}

override fun onErrorClick(throwableId: Long, position: Int) {
startActivity(ErrorActivity.newInstance(this, throwableId))
ErrorActivity.start(this, throwableId)
}

override fun onTransactionClick(transactionId: Long, position: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import com.chuckerteam.chucker.internal.data.entity.RecordedThrowable
import com.chuckerteam.chucker.internal.data.repository.RepositoryProvider
import java.text.DateFormat

private const val EXTRA_THROWABLE_ID = "EXTRA_THROWABLE_ID"
private const val TEXT_PLAIN = "text/plain"

internal class ErrorActivity : AppCompatActivity() {

private var throwableId: Long = 0
Expand Down Expand Up @@ -105,11 +102,14 @@ internal class ErrorActivity : AppCompatActivity() {
}

companion object {
@JvmStatic
fun newInstance(context: Context, throwableId: Long) =
Intent(context, ErrorActivity::class.java).apply {
putExtra(EXTRA_THROWABLE_ID, throwableId)
}
private const val EXTRA_THROWABLE_ID = "transaction_id"
private const val TEXT_PLAIN = "text/plain"

fun start(context: Context, throwableId: Long) {
val intent = Intent(context, ErrorActivity::class.java)
intent.putExtra(EXTRA_THROWABLE_ID, throwableId)
context.startActivity(intent)
}
}

private val RecordedThrowable.formattedDate: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal class TransactionActivity : BaseChuckerActivity() {
private lateinit var title: TextView
private lateinit var adapter: PagerAdapter

private var selectedTabPosition = 0
private var transactionId: Long = 0
private var transaction: HttpTransaction? = null

Expand All @@ -61,7 +62,7 @@ internal class TransactionActivity : BaseChuckerActivity() {
val tabLayout = findViewById<TabLayout>(R.id.tabs)
tabLayout.setupWithViewPager(viewPager)

transactionId = intent.getLongExtra(ARG_TRANSACTION_ID, 0)
transactionId = intent.getLongExtra(EXTRA_TRANSACTION_ID, 0)
}

override fun onResume() {
Expand Down Expand Up @@ -149,14 +150,11 @@ internal class TransactionActivity : BaseChuckerActivity() {
}

companion object {
private const val EXTRA_TRANSACTION_ID = "transaction_id"

private const val ARG_TRANSACTION_ID = "transaction_id"
private var selectedTabPosition = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! I just found something... interesting 👀
I guess the previous developer used selectedTabPosition as a static in order to store in memory. And used it when view needs to re-open (in setupViewPager).

For this PR, could you let selectedTabPosition in the companion? I'm not fan of the idea, but for now I just want to merge this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I also not a big fan of such idea, but let's do for this PR.


@JvmStatic
fun start(context: Context, transactionId: Long) {
val intent = Intent(context, TransactionActivity::class.java)
intent.putExtra(ARG_TRANSACTION_ID, transactionId)
intent.putExtra(EXTRA_TRANSACTION_ID, transactionId)
context.startActivity(intent)
}
}
Expand Down