Commit b64ec7ea authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Styled the list and detail view

parent f5585ede
......@@ -25,8 +25,8 @@ import java.util.*
class QueryLogDetailFragment : Fragment() {
var currentQuery: DnsQuery? = null
private set
private lateinit var timeFormatSameDay:DateFormat
private lateinit var timeFormatDifferentDay:DateFormat
private var viewCreated = false
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
......@@ -35,26 +35,9 @@ class QueryLogDetailFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
viewCreated = true
setupTimeFormat()
updateUi()
}
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!!
}
}
fun isShowingQuery(): Boolean {
return currentQuery != null
}
......@@ -71,12 +54,7 @@ class QueryLogDetailFragment : Fragment() {
private fun updateUi() {
val query = currentQuery
if(query != null && viewCreated) {
if(isTimeStampToday(query.questionTime)) {
queryTime.text = timeFormatSameDay.format(query.questionTime)
} else {
queryTime.text = timeFormatDifferentDay.format(query.questionTime)
}
queryTime.text = QueryLogListFragment.formatTimeStamp(query.questionTime)
if(query.responseTime >= query.questionTime) {
latency.text = (query.responseTime - query.questionTime).toString() + " ms"
} else {
......@@ -85,23 +63,11 @@ class QueryLogDetailFragment : Fragment() {
longName.text = query.name
type.text = query.type.name
if(query.fromCache) {
askedServer.text = "CACHE"
resolvedBy.text = "Cache"
} else {
askedServer.text = query.askedServer ?: "-"
resolvedBy.text = query.askedServer ?: "-"
}
}
}
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
}
}
\ No newline at end of file
package com.frostnerd.smokescreen.fragment.querylogfragment
import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
......@@ -15,6 +16,8 @@ import com.frostnerd.smokescreen.database.getDatabase
import com.frostnerd.smokescreen.fragment.QueryLogFragment
import com.frostnerd.smokescreen.util.LiveDataSource
import kotlinx.android.synthetic.main.fragment_querylog_list.*
import java.text.DateFormat
import java.util.*
/**
* Copyright Daniel Wolf 2018
......@@ -26,7 +29,31 @@ import kotlinx.android.synthetic.main.fragment_querylog_list.*
* development@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)
}
......@@ -48,6 +75,7 @@ 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)
}
......@@ -63,6 +91,21 @@ 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)
}
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="512"
android:viewportWidth="512"
android:width="24dp">
<path
android:fillColor="?android:attr/textColor"
android:pathData="M505,442.7L405.3,343c-4.5,-4.5 -10.6,-7 -17,-7H372c27.6,-35.3 44,-79.7 44,-128C416,93.1 322.9,0 208,0S0,93.1 0,208s93.1,208 208,208c48.3,0 92.7,-16.4 128,-44v16.3c0,6.4 2.5,12.5 7,17l99.7,99.7c9.4,9.4 24.6,9.4 33.9,0l28.3,-28.3c9.4,-9.4 9.4,-24.6 0.1,-34zM208,336c-70.7,0 -128,-57.2 -128,-128 0,-70.7 57.2,-128 128,-128 70.7,0 128,57.2 128,128 0,70.7 -57.2,128 -128,128z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="512"
android:viewportWidth="512"
android:width="24dp">
<path
android:fillColor="?android:attr/textColor"
android:pathData="M256,8C119,8 8,119 8,256s111,248 248,248 248,-111 248,-248S393,8 256,8zM313.1,358.1L224.9,294c-3.1,-2.3 -4.9,-5.9 -4.9,-9.7L220,116c0,-6.6 5.4,-12 12,-12h48c6.6,0 12,5.4 12,12v137.7l63.5,46.2c5.4,3.9 6.5,11.4 2.6,16.8l-28.2,38.8c-3.9,5.3 -11.4,6.5 -16.8,2.6z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="512"
android:viewportWidth="384"
android:width="18dp">
<path
android:fillColor="?android:attr/textColor"
android:pathData="M202.021,0C122.202,0 70.503,32.703 29.914,91.026c-7.363,10.58 -5.093,25.086 5.178,32.874l43.138,32.709c10.373,7.865 25.132,6.026 33.253,-4.148 25.049,-31.381 43.63,-49.449 82.757,-49.449 30.764,0 68.816,19.799 68.816,49.631 0,22.552 -18.617,34.134 -48.993,51.164 -35.423,19.86 -82.299,44.576 -82.299,106.405V320c0,13.255 10.745,24 24,24h72.471c13.255,0 24,-10.745 24,-24v-5.773c0,-42.86 125.268,-44.645 125.268,-160.627C377.504,66.256 286.902,0 202.021,0zM192,373.459c-38.196,0 -69.271,31.075 -69.271,69.271 0,38.195 31.075,69.27 69.271,69.27s69.271,-31.075 69.271,-69.271 -31.075,-69.27 -69.271,-69.27z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:height="27.42dp"
android:viewportHeight="512"
android:viewportWidth="448"
android:width="24dp">
<path
android:fillColor="?android:attr/textColor"
android:pathData="M0,464c0,26.5 21.5,48 48,48h352c26.5,0 48,-21.5 48,-48L448,192L0,192v272zM320,268c0,-6.6 5.4,-12 12,-12h40c6.6,0 12,5.4 12,12v40c0,6.6 -5.4,12 -12,12h-40c-6.6,0 -12,-5.4 -12,-12v-40zM320,396c0,-6.6 5.4,-12 12,-12h40c6.6,0 12,5.4 12,12v40c0,6.6 -5.4,12 -12,12h-40c-6.6,0 -12,-5.4 -12,-12v-40zM192,268c0,-6.6 5.4,-12 12,-12h40c6.6,0 12,5.4 12,12v40c0,6.6 -5.4,12 -12,12h-40c-6.6,0 -12,-5.4 -12,-12v-40zM192,396c0,-6.6 5.4,-12 12,-12h40c6.6,0 12,5.4 12,12v40c0,6.6 -5.4,12 -12,12h-40c-6.6,0 -12,-5.4 -12,-12v-40zM64,268c0,-6.6 5.4,-12 12,-12h40c6.6,0 12,5.4 12,12v40c0,6.6 -5.4,12 -12,12L76,320c-6.6,0 -12,-5.4 -12,-12v-40zM64,396c0,-6.6 5.4,-12 12,-12h40c6.6,0 12,5.4 12,12v40c0,6.6 -5.4,12 -12,12L76,448c-6.6,0 -12,-5.4 -12,-12v-40zM400,64h-48L352,16c0,-8.8 -7.2,-16 -16,-16h-32c-8.8,0 -16,7.2 -16,16v48L160,64L160,16c0,-8.8 -7.2,-16 -16,-16h-32c-8.8,0 -16,7.2 -16,16v48L48,64C21.5,64 0,85.5 0,112v48h448v-48c0,-26.5 -21.5,-48 -48,-48z"/>
</vector>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="512"
android:viewportWidth="192"
android:width="9dp">
<path
android:fillColor="?android:attr/textColor"
android:pathData="M20,424.229h20V279.771H20c-11.046,0 -20,-8.954 -20,-20V212c0,-11.046 8.954,-20 20,-20h112c11.046,0 20,8.954 20,20v212.229h20c11.046,0 20,8.954 20,20V492c0,11.046 -8.954,20 -20,20H20c-11.046,0 -20,-8.954 -20,-20v-47.771c0,-11.046 8.954,-20 20,-20zM96,0C56.235,0 24,32.235 24,72s32.235,72 72,72 72,-32.235 72,-72S135.764,0 96,0z"/>
</vector>
......@@ -2,31 +2,153 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:id="@+id/queryTime"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/latency"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/longName"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/type"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:id="@+id/askedServer"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_gravity="center"
android:textStyle="italic"
android:text="Time"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:textSize="18sp"
android:id="@+id/queryTime"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_query_time"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_gravity="center"
android:textStyle="italic"
android:text="Resolved by"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:textSize="18sp"
android:id="@+id/resolvedBy"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_query_askedserver"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_gravity="center"
android:textStyle="italic"
android:text="Latency"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:textSize="18sp"
android:id="@+id/latency"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_query_latency"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_gravity="center"
android:textStyle="italic"
android:text="Query"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:textSize="18sp"
android:id="@+id/longName"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_query_question"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_marginTop="24dp"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_gravity="center"
android:textStyle="italic"
android:text="Type"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:textSize="18sp"
android:id="@+id/type"
android:drawablePadding="8dp"
android:drawableStart="@drawable/ic_query_type"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_marginTop="12dp"
android:layout_width="match_parent"
android:orientation="vertical"
android:visibility="gone"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_marginTop="12dp"
android:background="?attr/inputElementColor"
android:layout_height="1dp"/>
<View
android:layout_width="match_parent"
android:layout_marginTop="4dp"
android:background="?attr/inputElementColor"
android:layout_height="1dp"/>
<TextView
android:layout_width="wrap_content"
android:text="Answers"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent">
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="?selectableItemBackground"
android:paddingTop="4dp"
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"
android:layout_marginStart="12dp"
android:layout_height="wrap_content"/>
</LinearLayout>
\ No newline at end of file
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