1
1
package fr.free.nrw.commons.description
2
2
3
+
3
4
import android.app.ProgressDialog
4
5
import android.content.Intent
5
6
import android.os.Bundle
@@ -8,8 +9,11 @@ import android.speech.RecognizerIntent
8
9
import android.view.View
9
10
import androidx.recyclerview.widget.LinearLayoutManager
10
11
import androidx.recyclerview.widget.RecyclerView
12
+ import fr.free.nrw.commons.CommonsApplication
11
13
import fr.free.nrw.commons.Media
12
14
import fr.free.nrw.commons.R
15
+ import fr.free.nrw.commons.auth.SessionManager
16
+ import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException
13
17
import fr.free.nrw.commons.databinding.ActivityDescriptionEditBinding
14
18
import fr.free.nrw.commons.description.EditDescriptionConstants.LIST_OF_DESCRIPTION_AND_CAPTION
15
19
import fr.free.nrw.commons.description.EditDescriptionConstants.WIKITEXT
@@ -25,6 +29,7 @@ import io.reactivex.schedulers.Schedulers
25
29
import timber.log.Timber
26
30
import javax.inject.Inject
27
31
32
+
28
33
/* *
29
34
* Activity for populating and editing existing description and caption
30
35
*/
@@ -71,6 +76,9 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
71
76
72
77
@Inject lateinit var descriptionEditHelper: DescriptionEditHelper
73
78
79
+ @Inject lateinit var sessionManager: SessionManager
80
+
81
+
74
82
override fun onCreate (savedInstanceState : Bundle ? ) {
75
83
super .onCreate(savedInstanceState)
76
84
@@ -196,32 +204,64 @@ class DescriptionEditActivity : BaseActivity(), UploadMediaDetailAdapter.EventLi
196
204
* @param uploadMediaDetails descriptions and captions
197
205
*/
198
206
private fun editDescription (media : Media , updatedWikiText : String , uploadMediaDetails : ArrayList <UploadMediaDetail >){
199
- descriptionEditHelper?.addDescription(
200
- applicationContext, media,
201
- updatedWikiText
202
- )
203
- ?.subscribeOn(Schedulers .io())
204
- ?.observeOn(AndroidSchedulers .mainThread())
205
- ?.subscribe(Consumer <Boolean > { s: Boolean? -> Timber .d(" Descriptions are added." ) })?.let {
206
- compositeDisposable.add(
207
- it
207
+
208
+ try {
209
+ descriptionEditHelper?.addDescription(
210
+ applicationContext, media,
211
+ updatedWikiText
212
+ )
213
+ ?.subscribeOn(Schedulers .io())
214
+ ?.observeOn(AndroidSchedulers .mainThread())
215
+ ?.subscribe(Consumer <Boolean > { s: Boolean? -> Timber .d(" Descriptions are added." ) })?.let {
216
+ compositeDisposable.add(
217
+ it
218
+ )
219
+ }
220
+ } catch (e : InvalidLoginTokenException ) {
221
+ val username: String? = sessionManager?.userName
222
+ val logoutListener = CommonsApplication .BaseLogoutListener (
223
+ this ,
224
+ getString(R .string.invalid_login_message),
225
+ username
208
226
)
227
+
228
+ val commonsApplication = CommonsApplication .getInstance()
229
+ if (commonsApplication != null ){
230
+ commonsApplication.clearApplicationData(this ,logoutListener)
209
231
}
232
+ }
233
+
210
234
211
235
val updatedCaptions = LinkedHashMap <String , String >()
212
236
for (mediaDetail in uploadMediaDetails) {
213
- compositeDisposable.add(
214
- descriptionEditHelper!! .addCaption(
215
- applicationContext, media,
216
- mediaDetail.languageCode, mediaDetail.captionText
237
+ try {
238
+ compositeDisposable.add(
239
+ descriptionEditHelper!! .addCaption(
240
+ applicationContext, media,
241
+ mediaDetail.languageCode, mediaDetail.captionText
242
+ )
243
+ .subscribeOn(Schedulers .io())
244
+ .observeOn(AndroidSchedulers .mainThread())
245
+ .subscribe { s: Boolean? ->
246
+ updatedCaptions[mediaDetail.languageCode!! ] = mediaDetail.captionText
247
+ media.captions = updatedCaptions
248
+ Timber .d(" Caption is added." )
249
+ })
250
+ }
251
+ catch (e : InvalidLoginTokenException ) {
252
+ val username = sessionManager.userName
253
+ val logoutListener = CommonsApplication .BaseLogoutListener (
254
+ this ,
255
+ getString(R .string.invalid_login_message),
256
+ username
217
257
)
218
- .subscribeOn( Schedulers .io())
219
- .observeOn( AndroidSchedulers .mainThread() )
220
- .subscribe { s : Boolean? ->
221
- updatedCaptions[mediaDetail.languageCode !! ] = mediaDetail.captionText
222
- media.captions = updatedCaptions
223
- Timber .d( " Caption is added. " )
224
- })
258
+
259
+ val commonsApplication = CommonsApplication .getInstance( )
260
+ if (commonsApplication != null ){
261
+ commonsApplication.clearApplicationData( this ,logoutListener)
262
+ }
263
+ }
264
+
225
265
}
226
266
}
227
267
0 commit comments