Ver código fonte

admin page in progress

dola 1 ano atrás
pai
commit
33bdb27430

+ 1 - 0
app/build.gradle

@@ -119,6 +119,7 @@ dependencies {
     implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
     implementation "com.squareup.retrofit2:converter-moshi:$retrofit_version"
     implementation 'com.squareup.okhttp3:logging-interceptor:4.9.0'
+    implementation 'com.squareup.okhttp3:okhttp:4.9.0'
     implementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.7'
 
     /*Json Serialize & Deserialize Library*/

+ 1 - 0
app/src/main/AndroidManifest.xml

@@ -17,6 +17,7 @@
         android:supportsRtl="true"
         android:theme="@style/AppTheme"
         android:usesCleartextTraffic="true"
+        android:networkSecurityConfig="@xml/network_security_config"
         tools:targetApi="m">
         <activity
             android:name=".app.AdminActivity"

+ 4 - 2
app/src/main/java/com/sambath/kunkhmer/app/App.kt

@@ -78,15 +78,17 @@ class App : Application() {
                 .addInterceptor(ServiceInterceptor(prefHelper))
                 .addInterceptor(OkHttpProfilerInterceptor())
                 .addInterceptor(ErrorInterceptor(appContext(this), prefHelper))
+                .connectTimeout(180, TimeUnit.SECONDS)
                 .readTimeout(5, TimeUnit.MINUTES)
-                .writeTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(180, TimeUnit.SECONDS)
 
         } else {
             builder
                 .addInterceptor(ServiceInterceptor(prefHelper))
                 .addInterceptor(ErrorInterceptor(appContext(this), prefHelper))
+                .connectTimeout(180, TimeUnit.SECONDS)
                 .readTimeout(5, TimeUnit.MINUTES)
-                .writeTimeout(60, TimeUnit.SECONDS)
+                .writeTimeout(180, TimeUnit.SECONDS)
         }
         val client = builder.build()
         retrofit = Retrofit.Builder()

+ 3 - 4
app/src/main/java/com/sambath/kunkhmer/screen/news/NewsViewModel.kt

@@ -94,14 +94,13 @@ class NewsViewModel(val apiService: ApiService, val prefHelper: PrefHelper) : Ba
         if (!upload.isNullOrEmpty()) {
             // Assuming 'upload' is a file path, you may need to modify this part based on your actual requirements
             val file = File(request.upload)
-            //val filePart = MultipartBody.Part.createFormData("upload", file.name, file.asRequestBody("multipart/form-data".toMediaTypeOrNull()))
-            //val filePart = MultipartBody.Part.createFormData("upload", file.name, file.asRequestBody())
+            val filePart = MultipartBody.Part.createFormData("upload", file.name, file.asRequestBody("multipart/form-data".toMediaTypeOrNull()))
+//            val filePart = MultipartBody.Part.createFormData("upload", file.name, file.asRequestBody())
 
 //            val file = File(request.upload)
 //            val fileRequestBody = RequestBody.create("multipart/form-data".toMediaTypeOrNull(), file)
 //            val filePart = MultipartBody.Part.createFormData("upload", file.name, fileRequestBody)
 //
-//            _state.value = prev().copy(isProgress = true)
 //
 //            val requestBody = MultipartBody.Builder()
 //                .setType(MultipartBody.FORM)
@@ -115,7 +114,7 @@ class NewsViewModel(val apiService: ApiService, val prefHelper: PrefHelper) : Ba
             _state.value = prev().copy(isProgress = true)
 
             disposables.add(
-                apiService.createNews(titlePart, descPart, file.asRequestBody("multipart/form-data".toMediaTypeOrNull()))
+                apiService.createNews(titlePart, descPart,filePart)
                     .timeout(60, TimeUnit.SECONDS)
                     .subscribeOn(Schedulers.io())
                     .observeOn(AndroidSchedulers.mainThread())

+ 6 - 0
app/src/main/res/xml/network_security_config.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<network-security-config>
+    <domain-config cleartextTrafficPermitted="true">
+        <domain includeSubdomains="true">143.198.207.249</domain>
+    </domain-config>
+</network-security-config>