Use some design from AndroidX preference
This commit is contained in:
parent
ecf1784629
commit
638b088781
|
@ -11,6 +11,7 @@ buildscript {
|
|||
ext.fragmentVersion = '1.2.5'
|
||||
ext.lifecycleVersion = '2.2.0'
|
||||
ext.navigationVersion = '2.3.0'
|
||||
ext.preferenceVersion = '1.1.1'
|
||||
ext.recyclerviewVersion = '1.1.0'
|
||||
|
||||
ext.androidBuildGradleVersion = '3.6.3'
|
||||
|
|
|
@ -51,6 +51,7 @@ dependencies {
|
|||
implementation "androidx.appcompat:appcompat:$appcompatVersion"
|
||||
implementation "androidx.fragment:fragment:$fragmentVersion"
|
||||
implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
|
||||
implementation "androidx.preference:preference:$preferenceVersion"
|
||||
|
||||
// Kotlin coroutine for android
|
||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
|
||||
|
@ -58,10 +59,6 @@ dependencies {
|
|||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutineVersion"
|
||||
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion"
|
||||
|
||||
// Activity result
|
||||
implementation "androidx.activity:activity:1.1.0"
|
||||
implementation "androidx.activity:activity-ktx:1.1.0"
|
||||
|
||||
// Navigation
|
||||
implementation "androidx.navigation:navigation-fragment:$navigationVersion"
|
||||
implementation "androidx.navigation:navigation-ui:$navigationVersion"
|
||||
|
|
|
@ -24,8 +24,8 @@ import org.microg.nlp.api.Constants.ACTION_LOCATION_BACKEND
|
|||
import org.microg.nlp.api.GeocoderBackend
|
||||
import org.microg.nlp.api.LocationBackend
|
||||
import org.microg.nlp.client.UnifiedLocationClient
|
||||
import org.microg.nlp.ui.viewmodel.BackendInfo
|
||||
import org.microg.nlp.ui.viewmodel.BackendType
|
||||
import org.microg.nlp.ui.model.BackendInfo
|
||||
import org.microg.nlp.ui.model.BackendType
|
||||
import java.security.MessageDigest
|
||||
import java.security.NoSuchAlgorithmException
|
||||
|
||||
|
@ -157,4 +157,4 @@ private fun sha256sum(bytes: ByteArray): String? {
|
|||
} catch (e: NoSuchAlgorithmException) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,12 +28,12 @@ import androidx.lifecycle.lifecycleScope
|
|||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.microg.nlp.client.UnifiedLocationClient
|
||||
import org.microg.nlp.ui.viewmodel.BackendType.GEOCODER
|
||||
import org.microg.nlp.ui.viewmodel.BackendType.LOCATION
|
||||
import org.microg.nlp.ui.model.BackendType.GEOCODER
|
||||
import org.microg.nlp.ui.model.BackendType.LOCATION
|
||||
import org.microg.nlp.ui.databinding.BackendDetailsBinding
|
||||
import org.microg.nlp.ui.viewmodel.BackendDetailsCallback
|
||||
import org.microg.nlp.ui.viewmodel.BackendInfo
|
||||
import org.microg.nlp.ui.viewmodel.BackendType
|
||||
import org.microg.nlp.ui.model.BackendDetailsCallback
|
||||
import org.microg.nlp.ui.model.BackendInfo
|
||||
import org.microg.nlp.ui.model.BackendType
|
||||
import java.util.*
|
||||
|
||||
class BackendDetailsFragment : Fragment(R.layout.backend_details), BackendDetailsCallback {
|
||||
|
@ -83,7 +83,6 @@ class BackendDetailsFragment : Fragment(R.layout.backend_details), BackendDetail
|
|||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = BackendDetailsBinding.inflate(inflater, container, false)
|
||||
binding.fragment = this
|
||||
binding.callbacks = this
|
||||
return binding.root
|
||||
}
|
||||
|
@ -211,4 +210,4 @@ class BackendDetailsFragment : Fragment(R.layout.backend_details), BackendDetail
|
|||
private const val TAG = "USettings"
|
||||
private const val WAIT_FOR_RESULT = 5000L
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import org.microg.nlp.api.Constants.ACTION_LOCATION_BACKEND
|
|||
import org.microg.nlp.client.UnifiedLocationClient
|
||||
import org.microg.nlp.ui.databinding.BackendListBinding
|
||||
import org.microg.nlp.ui.databinding.BackendListEntryBinding
|
||||
import org.microg.nlp.ui.viewmodel.BackendInfo
|
||||
import org.microg.nlp.ui.viewmodel.BackendListEntryCallback
|
||||
import org.microg.nlp.ui.viewmodel.BackendType
|
||||
import org.microg.nlp.ui.model.BackendInfo
|
||||
import org.microg.nlp.ui.model.BackendListEntryCallback
|
||||
import org.microg.nlp.ui.model.BackendType
|
||||
|
||||
class BackendListFragment : Fragment(R.layout.backend_list), BackendListEntryCallback {
|
||||
val locationAdapter: BackendSettingsLineAdapter = BackendSettingsLineAdapter(this)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2020, microG Project Team
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.microg.nlp.ui.binding
|
||||
|
||||
import android.content.Context
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import androidx.annotation.AttrRes
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.databinding.BindingAdapter
|
||||
|
||||
@ColorInt
|
||||
private fun Context.resolveColor(@AttrRes resid: Int): Int? {
|
||||
val typedValue = TypedValue()
|
||||
if (!theme.resolveAttribute(resid, typedValue, true)) return null
|
||||
val colorRes = if (typedValue.resourceId != 0) typedValue.resourceId else typedValue.data
|
||||
return ContextCompat.getColor(this, colorRes)
|
||||
}
|
||||
|
||||
@BindingAdapter("app:backgroundColorAttr")
|
||||
fun View.setBackgroundColorAttribute(@AttrRes resId: Int) = context.resolveColor(resId)?.let { setBackgroundColor(it) }
|
|
@ -3,11 +3,11 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.microg.nlp.ui.viewmodel
|
||||
package org.microg.nlp.ui.model
|
||||
|
||||
interface BackendDetailsCallback {
|
||||
fun onEnabledChange(entry: BackendInfo?, newValue: Boolean)
|
||||
fun onAppClicked(entry: BackendInfo?)
|
||||
fun onAboutClicked(entry: BackendInfo?)
|
||||
fun onConfigureClicked(entry: BackendInfo?)
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.microg.nlp.ui.viewmodel
|
||||
package org.microg.nlp.ui.model
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.pm.ServiceInfo
|
||||
|
@ -32,4 +32,4 @@ class BackendInfo(val serviceInfo: ServiceInfo, val type: BackendType, val first
|
|||
}
|
||||
}
|
||||
|
||||
enum class BackendType { LOCATION, GEOCODER }
|
||||
enum class BackendType { LOCATION, GEOCODER }
|
|
@ -3,9 +3,9 @@
|
|||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package org.microg.nlp.ui.viewmodel
|
||||
package org.microg.nlp.ui.model
|
||||
|
||||
interface BackendListEntryCallback {
|
||||
fun onEnabledChange(entry: BackendInfo?, newValue: Boolean)
|
||||
fun onOpenDetails(entry: BackendInfo?)
|
||||
}
|
||||
}
|
|
@ -12,19 +12,15 @@
|
|||
|
||||
<import type="android.view.View" />
|
||||
|
||||
<import type="org.microg.nlp.ui.viewmodel.BackendType" />
|
||||
|
||||
<variable
|
||||
name="fragment"
|
||||
type="org.microg.nlp.ui.BackendDetailsFragment" />
|
||||
<import type="org.microg.nlp.ui.model.BackendType" />
|
||||
|
||||
<variable
|
||||
name="callbacks"
|
||||
type="org.microg.nlp.ui.viewmodel.BackendDetailsCallback" />
|
||||
type="org.microg.nlp.ui.model.BackendDetailsCallback" />
|
||||
|
||||
<variable
|
||||
name="entry"
|
||||
type="org.microg.nlp.ui.viewmodel.BackendInfo" />
|
||||
type="org.microg.nlp.ui.model.BackendInfo" />
|
||||
|
||||
<variable
|
||||
name="lastLocationString"
|
||||
|
@ -79,7 +75,6 @@
|
|||
android:textSize="20sp"
|
||||
tools:text="Mozilla Location Service" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/app_name"
|
||||
style="@style/TextAppearance.AppCompat.Body1"
|
||||
|
@ -106,8 +101,8 @@
|
|||
android:paddingLeft="?attr/listPreferredItemPaddingLeft"
|
||||
android:paddingEnd="?attr/listPreferredItemPaddingEnd"
|
||||
android:paddingRight="?attr/listPreferredItemPaddingRight"
|
||||
app:backgroundColor="@{entry.enabled ? fragment.switchBarEnabledColor : fragment.switchBarDisabledColor}"
|
||||
tools:background="?attr/colorAccent">
|
||||
app:backgroundColorAttr="@{entry.enabled ? androidx.appcompat.R.attr.colorControlActivated : androidx.appcompat.R.attr.colorButtonNormal}"
|
||||
tools:background="?attr/colorControlActivated">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/switch_text"
|
||||
|
@ -133,6 +128,7 @@
|
|||
android:enabled="@{entry.loaded || entry.enabled}"
|
||||
app:onCheckedChangeListener="@{(view, checked) -> callbacks.onEnabledChange(entry, checked)}"
|
||||
app:thumbTint="?android:attr/textColorPrimaryInverse"
|
||||
app:trackTint="?android:attr/textColorSecondaryInverse"
|
||||
tools:checked="true" />
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -212,7 +208,8 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dividerHorizontal"
|
||||
android:visibility='@{entry == null || (entry.summary == null || entry.type != BackendType.LOCATION) || (entry.settingsIntent == null && entry.aboutIntent == null) ? View.GONE : View.VISIBLE}' />
|
||||
android:visibility='@{entry == null || (entry.summary == null || entry.type != BackendType.LOCATION) || (entry.settingsIntent == null && entry.aboutIntent == null) ? View.GONE : View.VISIBLE}'
|
||||
tools:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
@ -306,4 +303,4 @@
|
|||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
</layout>
|
||||
|
|
|
@ -32,20 +32,17 @@
|
|||
android:paddingRight="?attr/listPreferredItemPaddingRight">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Network-based Geolocation modules"
|
||||
android:ellipsize="marquee"
|
||||
android:letterSpacing="0.073"
|
||||
android:paddingStart="56dp"
|
||||
android:paddingLeft="56dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:singleLine="true"
|
||||
android:text="Network-based Geolocation modules"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:textSize="11sp" />
|
||||
android:textAppearance="?attr/preferenceCategoryTitleTextAppearance"
|
||||
android:textColor="?attr/colorAccent"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -74,20 +71,17 @@
|
|||
android:paddingRight="?attr/listPreferredItemPaddingRight">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="marquee"
|
||||
android:letterSpacing="0.073"
|
||||
android:paddingStart="56dp"
|
||||
android:paddingLeft="56dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:singleLine="true"
|
||||
android:text="Address lookup modules"
|
||||
android:textAllCaps="true"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
||||
android:textColor="?attr/colorAccent"
|
||||
android:textSize="11sp" />
|
||||
android:textAppearance="?attr/preferenceCategoryTitleTextAppearance"
|
||||
android:textColor="?attr/colorAccent"/>
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
@ -99,4 +93,4 @@
|
|||
tools:itemCount="1"
|
||||
tools:listitem="@layout/backend_list_entry" />
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
</layout>
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
|
||||
<variable
|
||||
name="callbacks"
|
||||
type="org.microg.nlp.ui.viewmodel.BackendListEntryCallback" />
|
||||
type="org.microg.nlp.ui.model.BackendListEntryCallback" />
|
||||
|
||||
<variable
|
||||
name="entry"
|
||||
type="org.microg.nlp.ui.viewmodel.BackendInfo" />
|
||||
type="org.microg.nlp.ui.model.BackendInfo" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -76,7 +76,7 @@
|
|||
android:singleLine="true"
|
||||
android:text='@{entry.name ?? "No provider installed"}'
|
||||
android:textAppearance="?attr/textAppearanceListItem"
|
||||
tools:text="Mozilla Location Service" />
|
||||
tools:text="@tools:sample/lorem" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -88,7 +88,8 @@
|
|||
android:orientation="horizontal"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="16dp"
|
||||
android:visibility='@{entry == null ? View.GONE : View.VISIBLE}'>
|
||||
android:visibility='@{entry == null ? View.GONE : View.VISIBLE}'
|
||||
tools:visibility="visible">
|
||||
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
|
@ -102,7 +103,8 @@
|
|||
android:gravity="center"
|
||||
android:minWidth="64dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility='@{entry == null ? View.GONE : View.VISIBLE}'>
|
||||
android:visibility='@{entry == null ? View.GONE : View.VISIBLE}'
|
||||
tools:visibility="visible">
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:layout_width="match_parent"
|
||||
|
@ -112,7 +114,11 @@
|
|||
android:minWidth="80dp"
|
||||
android:paddingLeft="16dp"
|
||||
android:paddingRight="16dp"
|
||||
app:onCheckedChangeListener="@{(view, checked) -> callbacks.onEnabledChange(entry, checked)}" />
|
||||
android:textOff=""
|
||||
android:textOn=""
|
||||
app:onCheckedChangeListener="@{(view, checked) -> callbacks.onEnabledChange(entry, checked)}"
|
||||
tools:checked="true"
|
||||
tools:text="​" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
</layout>
|
||||
|
|
|
@ -16,4 +16,4 @@
|
|||
android:layout_height="wrap_content"
|
||||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/nav_unlp" />
|
||||
</ScrollView>
|
||||
</ScrollView>
|
||||
|
|
|
@ -5,13 +5,15 @@
|
|||
-->
|
||||
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/nav_unlp"
|
||||
app:startDestination="@id/backendListFragment">
|
||||
|
||||
<fragment
|
||||
android:id="@+id/backendListFragment"
|
||||
android:name="org.microg.nlp.ui.BackendListFragment"
|
||||
android:label="Location modules">
|
||||
android:label="Location modules"
|
||||
tools:layout="@layout/backend_list">
|
||||
<action
|
||||
android:id="@+id/openBackendDetails"
|
||||
app:destination="@id/backendDetailsFragment"
|
||||
|
@ -23,7 +25,8 @@
|
|||
<fragment
|
||||
android:id="@+id/backendDetailsFragment"
|
||||
android:name="org.microg.nlp.ui.BackendDetailsFragment"
|
||||
android:label="Location module details">
|
||||
android:label="Location module details"
|
||||
tools:layout="@layout/backend_details">
|
||||
<argument
|
||||
android:name="type"
|
||||
app:argType="string" />
|
||||
|
@ -34,4 +37,4 @@
|
|||
android:name="name"
|
||||
app:argType="string" />
|
||||
</fragment>
|
||||
</navigation>
|
||||
</navigation>
|
||||
|
|
Loading…
Reference in New Issue