mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-04 02:09:19 +02:00
Add clipboard button and barcode to the add device dialog
This commit is contained in:
parent
196dbcd5a0
commit
33e09be39e
4 changed files with 39 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* TimeLimit Copyright <C> 2019 Jonas Lochmann
|
* TimeLimit Copyright <C> 2019 - 2023 Jonas Lochmann
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -16,15 +16,20 @@
|
||||||
package io.timelimit.android.ui.manage.device.add
|
package io.timelimit.android.ui.manage.device.add
|
||||||
|
|
||||||
|
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.core.content.getSystemService
|
||||||
import androidx.fragment.app.FragmentManager
|
import androidx.fragment.app.FragmentManager
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import androidx.lifecycle.ViewModelProviders
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||||
import io.timelimit.android.R
|
import io.timelimit.android.R
|
||||||
|
import io.timelimit.android.barcode.BarcodeMaskDrawable
|
||||||
|
import io.timelimit.android.barcode.DataMatrix
|
||||||
import io.timelimit.android.databinding.FragmentAddDeviceBinding
|
import io.timelimit.android.databinding.FragmentAddDeviceBinding
|
||||||
import io.timelimit.android.extensions.showSafe
|
import io.timelimit.android.extensions.showSafe
|
||||||
import io.timelimit.android.ui.main.getActivityViewModel
|
import io.timelimit.android.ui.main.getActivityViewModel
|
||||||
|
@ -34,27 +39,36 @@ class AddDeviceFragment : BottomSheetDialogFragment() {
|
||||||
private const val DIALOG_TAG = "adf"
|
private const val DIALOG_TAG = "adf"
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||||
val binding = FragmentAddDeviceBinding.inflate(inflater, container, false)
|
val binding = FragmentAddDeviceBinding.inflate(inflater, container, false)
|
||||||
val model = ViewModelProviders.of(this).get(AddDeviceModel::class.java)
|
val model = ViewModelProviders.of(this).get(AddDeviceModel::class.java)
|
||||||
|
val clipboardManager = requireContext().getSystemService<ClipboardManager>()!!
|
||||||
|
|
||||||
|
binding.copyToClipboardButton.setOnClickListener {
|
||||||
|
clipboardManager.setPrimaryClip(ClipData.newPlainText("Code", binding.token))
|
||||||
|
}
|
||||||
|
|
||||||
model.status.observe(this, Observer {
|
model.status.observe(this, Observer {
|
||||||
when (it) {
|
when (it) {
|
||||||
Initializing -> {
|
Initializing -> {
|
||||||
binding.token = null
|
binding.token = null
|
||||||
binding.message = null
|
binding.message = null
|
||||||
|
binding.barcode.setImageDrawable(null)
|
||||||
}
|
}
|
||||||
Failed -> {
|
Failed -> {
|
||||||
binding.token = null
|
binding.token = null
|
||||||
binding.message = getString(R.string.error_network)
|
binding.message = getString(R.string.error_network)
|
||||||
|
binding.barcode.setImageDrawable(null)
|
||||||
}
|
}
|
||||||
is ShowingToken -> {
|
is ShowingToken -> {
|
||||||
binding.token = it.token
|
binding.token = it.token
|
||||||
binding.message = null
|
binding.message = null
|
||||||
|
binding.barcode.setImageDrawable(BarcodeMaskDrawable(DataMatrix.generate(it.token)))
|
||||||
}
|
}
|
||||||
is DidAddDevice -> {
|
is DidAddDevice -> {
|
||||||
binding.token = null
|
binding.token = null
|
||||||
binding.message = getString(R.string.add_device_success, it.deviceName)
|
binding.message = getString(R.string.add_device_success, it.deviceName)
|
||||||
|
binding.barcode.setImageDrawable(null)
|
||||||
}
|
}
|
||||||
TokenExpired -> {
|
TokenExpired -> {
|
||||||
dismissAllowingStateLoss()
|
dismissAllowingStateLoss()
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<!--
|
<!--
|
||||||
TimeLimit Copyright <C> 2019 Jonas Lochmann
|
TimeLimit Copyright <C> 2019 - 2023 Jonas Lochmann
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation version 3 of the License.
|
the Free Software Foundation version 3 of the License.
|
||||||
|
@ -45,6 +45,14 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:id="@+id/barcode"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
tools:src="@drawable/banner"
|
||||||
|
android:layout_width="128dp"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:visibility="@{TextUtils.isEmpty(message) ? View.GONE : View.VISIBLE}"
|
android:visibility="@{TextUtils.isEmpty(message) ? View.GONE : View.VISIBLE}"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
|
@ -64,6 +72,15 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:visibility="@{TextUtils.isEmpty(token) ? View.GONE : View.VISIBLE}"
|
||||||
|
style="?materialButtonOutlinedStyle"
|
||||||
|
android:id="@+id/copy_to_clipboard_button"
|
||||||
|
android:text="@string/diagnose_sync_copy_to_clipboard"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:visibility="@{TextUtils.isEmpty(token) ? View.GONE : View.VISIBLE}"
|
android:visibility="@{TextUtils.isEmpty(token) ? View.GONE : View.VISIBLE}"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
|
|
|
@ -79,8 +79,8 @@
|
||||||
|
|
||||||
<string name="add_device">Gerät hinzufügen</string>
|
<string name="add_device">Gerät hinzufügen</string>
|
||||||
<string name="add_device_info">
|
<string name="add_device_info">
|
||||||
Geben Sie diesen Code an dem Gerät ein, das Sie hinzufügen möchten.
|
Geben/scannen Sie diesen Code an dem Gerät ein, das Sie hinzufügen möchten.
|
||||||
Sie können den Code NUR bei der Einrichtung von TimeLimit angeben und müssen dafür
|
Sie können den Code NUR bei der Einrichtung von TimeLimit verwenden und müssen dafür
|
||||||
auswählen, dass Sie eine Verknüpfung mit einer bestehenden Installation mit einem Code
|
auswählen, dass Sie eine Verknüpfung mit einer bestehenden Installation mit einem Code
|
||||||
durchführen möchten. Eine spätere Verknüpfung ist nicht möglich - dann muss TimeLimit am
|
durchführen möchten. Eine spätere Verknüpfung ist nicht möglich - dann muss TimeLimit am
|
||||||
anderen Gerät neu installiert werden.
|
anderen Gerät neu installiert werden.
|
||||||
|
|
|
@ -124,9 +124,9 @@
|
||||||
|
|
||||||
<string name="add_device">Add device</string>
|
<string name="add_device">Add device</string>
|
||||||
<string name="add_device_info">
|
<string name="add_device_info">
|
||||||
Enter the code at the device which you would like to add.
|
Enter or scan the code at the device which you would like to add.
|
||||||
You can enter the code ONLY during the setup of TimeLimit and only if you chose to link
|
You can enter/scan the code ONLY during the setup of TimeLimit and only if you chose to link
|
||||||
the device using a code. You can not enter this code later - you must reinstall TimeLimit at
|
the device using a code. You can not use this code later - you must reinstall TimeLimit at
|
||||||
the other device in this case.
|
the other device in this case.
|
||||||
</string>
|
</string>
|
||||||
<string name="add_device_success">The device %s was added</string>
|
<string name="add_device_success">The device %s was added</string>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue