Commit 411f0cfa authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Removed the time from each logged query roe

parent 74711941
package com.frostnerd.smokescreen.fragment.querylogfragment
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
......@@ -8,6 +9,8 @@ import androidx.fragment.app.Fragment
import com.frostnerd.smokescreen.R
import com.frostnerd.smokescreen.database.entities.DnsQuery
import kotlinx.android.synthetic.main.fragment_querylog_detail.*
import java.text.DateFormat
import java.util.*
/*
......@@ -31,8 +34,40 @@ import kotlinx.android.synthetic.main.fragment_querylog_detail.*
class QueryLogDetailFragment : Fragment() {
var currentQuery: DnsQuery? = null
private set
private lateinit var timeFormatSameDay: DateFormat
private lateinit var timeFormatDifferentDay: DateFormat
internal fun formatTimeStamp(timestamp:Long): String {
return if(isTimeStampToday(timestamp)) timeFormatSameDay.format(timestamp)
else timeFormatDifferentDay.format(timestamp)
}
private fun isTimeStampToday(timestamp:Long):Boolean {
return timestamp >= getStartOfDay()
}
private fun getStartOfDay():Long {
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar.timeInMillis
}
private fun getLocale(): Locale {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
resources.configuration.locales.get(0)!!
} else{
@Suppress("DEPRECATION")
resources.configuration.locale!!
}
}
private fun setupTimeFormat() {
val locale = getLocale()
timeFormatSameDay = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale)
timeFormatDifferentDay = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale)
}
private var viewCreated = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
......@@ -60,7 +95,7 @@ class QueryLogDetailFragment : Fragment() {
private fun updateUi() {
val query = currentQuery
if(query != null && viewCreated) {
queryTime.text = QueryLogListFragment.formatTimeStamp(query.questionTime)
queryTime.text = formatTimeStamp(query.questionTime)
if(query.responseTime >= query.questionTime) {
latency.text = (query.responseTime - query.questionTime).toString() + " ms"
} else {
......
......@@ -37,29 +37,6 @@ import java.util.*
* You can contact the developer at daniel.wolf@frostnerd.com.
*/
class QueryLogListFragment: Fragment() {
companion object {
internal lateinit var timeFormatSameDay: DateFormat
internal lateinit var timeFormatDifferentDay: DateFormat
internal fun formatTimeStamp(timestamp:Long): String {
return if(isTimeStampToday(timestamp)) timeFormatSameDay.format(timestamp)
else timeFormatDifferentDay.format(timestamp)
}
private fun isTimeStampToday(timestamp:Long):Boolean {
return timestamp >= getStartOfDay()
}
private fun getStartOfDay():Long {
val calendar = Calendar.getInstance()
calendar.set(Calendar.HOUR_OF_DAY, 0)
calendar.set(Calendar.MINUTE, 0)
calendar.set(Calendar.SECOND, 0)
calendar.set(Calendar.MILLISECOND, 0)
return calendar.timeInMillis
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
setupTimeFormat()
return layoutInflater.inflate(R.layout.fragment_querylog_list, container, false)
......@@ -81,7 +58,6 @@ class QueryLogListFragment: Fragment() {
}
bindModelView = { viewHolder, position, data ->
viewHolder.itemView.findViewById<TextView>(R.id.text).text = data.shortName
viewHolder.itemView.findViewById<TextView>(R.id.time).text = formatTimeStamp(data.questionTime)
viewHolder.itemView.tag = data
if(isDisplayingQuery(data)) displayQuery(data, false)
}
......@@ -97,21 +73,6 @@ class QueryLogListFragment: Fragment() {
list.adapter = adapter
}
private fun setupTimeFormat() {
val locale = getLocale()
timeFormatSameDay = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale)
timeFormatDifferentDay = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM, locale)
}
private fun getLocale(): Locale {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
resources.configuration.locales.get(0)!!
} else{
@Suppress("DEPRECATION")
resources.configuration.locale!!
}
}
private fun displayQuery(dnsQuery: DnsQuery, switchToDetailView:Boolean = true) {
(parentFragment as QueryLogFragment).displayQueryDetailed(dnsQuery, switchToDetailView)
}
......
......@@ -7,12 +7,6 @@
android:paddingBottom="4dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:id="@+id/time"
android:textStyle="italic"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/text"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment