@@ -12,6 +12,7 @@ import android.os.Bundle
12
12
import android.view.View
13
13
import android.widget.AdapterView
14
14
import android.widget.ArrayAdapter
15
+ import androidx.core.app.ActivityCompat.finishAffinity
15
16
import androidx.fragment.app.DialogFragment
16
17
import com.google.android.material.dialog.MaterialAlertDialogBuilder
17
18
import com.nextcloud.android.lib.resources.tos.GetTermsRemoteOperation
@@ -25,6 +26,7 @@ import com.nextcloud.utils.extensions.setHtmlContent
25
26
import com.owncloud.android.R
26
27
import com.owncloud.android.databinding.DialogShowTosBinding
27
28
import com.owncloud.android.lib.common.operations.RemoteOperationResult
29
+ import com.owncloud.android.lib.common.utils.Log_OC
28
30
import com.owncloud.android.utils.DisplayUtils
29
31
import com.owncloud.android.utils.theme.ViewThemeUtils
30
32
import kotlinx.coroutines.CoroutineScope
@@ -61,11 +63,6 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
61
63
}
62
64
63
65
private fun updateDialog () {
64
- // viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
65
- // binding.root.context,
66
- // builder
67
- // )
68
-
69
66
binding.message.setHtmlContent(terms[0 ].renderedBody)
70
67
71
68
val arrayAdapter: ArrayAdapter <String > = ArrayAdapter (
@@ -86,9 +83,7 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
86
83
.setHtmlContent(terms[position].renderedBody)
87
84
}
88
85
89
- override fun onNothingSelected (adapterView : AdapterView <* >? ) {
90
- // nothing to do
91
- }
86
+ override fun onNothingSelected (adapterView : AdapterView <* >? ) = Unit
92
87
}
93
88
94
89
if (terms.size == 1 ) {
@@ -98,6 +93,7 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
98
93
99
94
private fun fetchTerms () {
100
95
CoroutineScope (Dispatchers .IO ).launch {
96
+ // viewLifecycleOwner.lifecycleScope.launch {
101
97
try {
102
98
client = clientFactory.createNextcloudClient(accountManager.getUser())
103
99
val result = GetTermsRemoteOperation ().execute(client)
@@ -110,11 +106,12 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
110
106
terms = result.resultData.terms
111
107
112
108
CoroutineScope (Dispatchers .Main ).launch {
109
+ // withContext(Dispatchers.Main) {
113
110
updateDialog()
114
111
}
115
112
}
116
113
} catch (exception: ClientFactory .CreationException ) {
117
- TODO ( " Add error handling here " )
114
+ Log_OC .e( TAG , " Error creating client! " )
118
115
}
119
116
}
120
117
}
@@ -123,10 +120,10 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
123
120
return MaterialAlertDialogBuilder (binding.root.context)
124
121
.setView(binding.root)
125
122
.setTitle(R .string.terms_of_service_title)
126
- .setNegativeButton(R .string.dialog_close) { dialog, which ->
127
- // TODO finishAffinity()
123
+ .setNegativeButton(R .string.dialog_close) { _, _ ->
124
+ activity?. let { finishAffinity(it) }
128
125
}
129
- .setPositiveButton(R .string.terms_of_services_agree) { dialog, which ->
126
+ .setPositiveButton(R .string.terms_of_services_agree) { dialog, _ ->
130
127
dialog.dismiss()
131
128
Thread {
132
129
val id = binding.languageDropdown.selectedItemPosition
@@ -139,58 +136,7 @@ class TermsOfServiceDialog : DialogFragment(), Injectable {
139
136
}
140
137
}
141
138
142
- // private void showTermsOfServiceDialog1()
143
- // {
144
-
145
- // runOnUiThread(Runnable {
146
- // viewThemeUtils.dialog.colorMaterialAlertDialogBackground(
147
- // binding.root.context,
148
- // builder
149
- // )
150
- // builder.create()
151
- //
152
- // binding.message.setHtmlContent(terms[0].renderedBody)
153
- //
154
- // val arrayAdapter: ArrayAdapter<String> = ArrayAdapter(
155
- // binding.root.context,
156
- // android.R.layout.simple_spinner_item
157
- // )
158
- //
159
- // for ((_, _, languageCode) in terms) {
160
- // arrayAdapter.add(languages[languageCode])
161
- // }
162
- //
163
- // arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
164
- //
165
- //
166
- // binding.languageDropdown.adapter = arrayAdapter
167
- // binding.languageDropdown.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
168
- // override fun onItemSelected(
169
- // adapterView: AdapterView<*>?,
170
- // view: View,
171
- // position: Int,
172
- // l: Long
173
- // ) {
174
- // binding.message
175
- // .setHtmlContent(terms[position].renderedBody)
176
- // }
177
- //
178
- // override fun onNothingSelected(adapterView: AdapterView<*>?) {
179
- // // nothing to do
180
- // }
181
- // }
182
- //
183
- // if (terms.size == 1) {
184
- // binding.languageDropdown.visibility = View.GONE
185
- // }
186
- // if (!tosIsShown) {
187
- // tosIsShown = true
188
- // builder.create().show()
189
- // }
190
- // })
191
- // }
192
- // } catch (e: CreationException) {
193
- // showInfoBox(R.string.sign_tos_failed)
194
- // }
195
- // }.start()
139
+ companion object {
140
+ private const val TAG = " TermsOfServiceDialog"
141
+ }
196
142
}
0 commit comments