Skip to content

Commit bed0370

Browse files
author
Mahalingam
committed
11-02-2020
# WORK MANAGER (one time) #Swipe to delete
1 parent af964a7 commit bed0370

File tree

8 files changed

+212
-1
lines changed

8 files changed

+212
-1
lines changed

app/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ android {
3535
}
3636
}
3737

38+
ext {
39+
supportLibrary = '28.0.0'
40+
retrofitVersion = '2.6.0'
41+
FirebaseVersion = '17.2.0'
42+
Glide = '4.9.0'
43+
}
44+
3845
dependencies {
3946
implementation fileTree(dir: 'libs', include: ['*.jar'])
4047
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
@@ -49,6 +56,11 @@ dependencies {
4956

5057
kapt "com.android.databinding:compiler:$gradle_version"
5158

59+
60+
implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
61+
implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
62+
implementation 'com.squareup.okhttp3:logging-interceptor:3.13.1'
63+
5264
testImplementation 'junit:junit:4.12'
5365
androidTestImplementation 'androidx.test:runner:1.1.1'
5466
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.example.simplework">
44

5+
6+
<uses-permission android:name="android.permission.INTERNET" />
7+
58
<application
69
android:allowBackup="true"
10+
android:hardwareAccelerated="false"
711
android:icon="@mipmap/ic_launcher"
12+
android:largeHeap="true"
813
android:label="@string/app_name"
914
android:roundIcon="@mipmap/ic_launcher_round"
1015
android:supportsRtl="true"
1116
android:theme="@style/AppTheme">
12-
<activity android:name=".activity.ThirdActivity"></activity>
17+
<activity android:name=".activity.FourthActivity"></activity>
18+
<activity android:name=".activity.ThirdActivity" />
1319
<activity android:name=".activity.SecondActivity" />
1420
<activity android:name=".activity.FirstActivity" />
1521
<activity android:name=".activity.MainActivity">
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.example.simplework.activity
2+
3+
import android.annotation.SuppressLint
4+
import androidx.appcompat.app.AppCompatActivity
5+
import android.os.Bundle
6+
import android.util.Log
7+
import com.example.simplework.R
8+
import java.text.ParseException
9+
import java.text.SimpleDateFormat
10+
import java.util.*
11+
12+
class FourthActivity : AppCompatActivity() {
13+
14+
val DATE_TIME_FORMAT_FOR_COMPLAINT_MIN = "yyyy-MM-dd HH:mm:ss"
15+
16+
val DATETIME12HRS = "dd/MM/yyyy hh:mm aa"
17+
18+
override fun onCreate(savedInstanceState: Bundle?) {
19+
super.onCreate(savedInstanceState)
20+
setContentView(R.layout.activity_fourth)
21+
22+
23+
24+
// val aDate=convertDateTime(getUTCTime(),DATETIME12HRS,DATE_TIME_FORMAT_FOR_COMPLAINT_MIN)
25+
26+
Log.e("UTC ", "" + getUTCTime())
27+
28+
29+
30+
/* TKApiClient.getService(this).getresponseData().enqueue(object : Callback<ResponseBody> {
31+
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
32+
Log.e("Print", t.toString())
33+
}
34+
35+
override fun onResponse(call: Call<ResponseBody>, response: Response<ResponseBody>) {
36+
try {
37+
val aList = response.body()?.string()
38+
val jsonObject = JSONObject(aList ?: "")
39+
Log.e("Print", jsonObject.toString())
40+
} catch (e: Exception) {
41+
e.printStackTrace()
42+
}
43+
}
44+
45+
})*/
46+
47+
48+
}
49+
50+
51+
@SuppressLint("SimpleDateFormat")
52+
fun getUTCTime(): String {
53+
val time = Calendar.getInstance().time
54+
val outputFmt = SimpleDateFormat(DATE_TIME_FORMAT_FOR_COMPLAINT_MIN)
55+
outputFmt.timeZone = TimeZone.getTimeZone("UTC")
56+
outputFmt.isLenient = false
57+
return outputFmt.format(time)
58+
}
59+
60+
61+
62+
@SuppressLint("SimpleDateFormat")
63+
fun convertDateTime(aDataValue: String, originaL_DATETIME_FORAMT: String, Target_DateFormat: String): String {
64+
65+
var formattedDate = ""
66+
try {
67+
if (aDataValue.isNotEmpty()) {
68+
val dateString = aDataValue
69+
val dateFormat = SimpleDateFormat(originaL_DATETIME_FORAMT)
70+
val targetFormat = SimpleDateFormat(Target_DateFormat)
71+
dateFormat.isLenient = false
72+
targetFormat.isLenient = false
73+
val convertedDate: Date
74+
75+
try {
76+
convertedDate = dateFormat.parse(dateString)
77+
formattedDate = targetFormat.format(convertedDate)
78+
} catch (e: ParseException) {
79+
e.printStackTrace()
80+
return aDataValue
81+
}
82+
}
83+
84+
return formattedDate
85+
} catch (ex: java.lang.Exception) {
86+
ex.printStackTrace()
87+
return formattedDate
88+
}
89+
}
90+
}

app/src/main/java/com/example/simplework/activity/MainActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,9 @@ class MainActivity : AppCompatActivity() {
8787
}
8888

8989

90+
fun button4Click(view: View) {
91+
startActivity(Intent(this, FourthActivity::class.java))
92+
}
93+
94+
9095
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.ers.tkenterprise.apiUtils
2+
3+
4+
import com.example.simplework.activity.FourthActivity
5+
import com.example.simplework.webservice.TKWebserviceInterface
6+
import com.google.gson.GsonBuilder
7+
import okhttp3.Cache
8+
import okhttp3.OkHttpClient
9+
import okhttp3.logging.HttpLoggingInterceptor
10+
import retrofit2.Retrofit
11+
import retrofit2.converter.gson.GsonConverterFactory
12+
import java.util.concurrent.TimeUnit
13+
14+
15+
/**
16+
* Created by Gowtham Raj on 17/05/2019.
17+
*/
18+
19+
object TKApiClient {
20+
21+
private var retrofit: Retrofit? = null
22+
23+
val interceptor = HttpLoggingInterceptor()
24+
25+
val cacheSize = (20 * 1024 * 1024).toLong()
26+
lateinit var myCache :Cache
27+
lateinit var okHttpClient:OkHttpClient
28+
29+
30+
var gson = GsonBuilder()
31+
.setLenient()
32+
.create()
33+
34+
//https://github.com/zemirco/sf-city-lots-json/raw/master/citylots.json
35+
36+
//Call Webservice - LIVE / LOCAL
37+
fun getService(fourthActivity: FourthActivity): TKWebserviceInterface {
38+
39+
myCache = Cache(fourthActivity.cacheDir, cacheSize)
40+
okHttpClient = OkHttpClient().newBuilder().cache(myCache).connectTimeout(5, TimeUnit.MINUTES).readTimeout(5, TimeUnit.MINUTES).writeTimeout(5, TimeUnit.MINUTES).addInterceptor(interceptor).build()
41+
42+
return client.create(TKWebserviceInterface::class.java)
43+
}
44+
45+
val client: Retrofit
46+
get() {
47+
if (retrofit == null) {
48+
//retrofit = Retrofit.Builder().baseUrl("https://raw.githubusercontent.com/").client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).build()
49+
retrofit = Retrofit.Builder().baseUrl("https://github.com/").client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).build()
50+
}
51+
return this.retrofit!!
52+
}
53+
54+
//Get Base URL from Login Screen
55+
fun changeApiBaseUrl(newApiBaseUrl: String) {
56+
57+
retrofit = Retrofit.Builder().baseUrl(newApiBaseUrl).client(okHttpClient).addConverterFactory(GsonConverterFactory.create(gson)).build()
58+
}
59+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.example.simplework.webservice
2+
3+
4+
5+
import okhttp3.ResponseBody
6+
import retrofit2.Call
7+
import retrofit2.http.GET
8+
import retrofit2.http.Streaming
9+
10+
11+
interface TKWebserviceInterface {
12+
13+
// @Streaming
14+
//@GET("thenixan-blogposts/json-streaming-data/master/one-large-file.json")
15+
@GET("zemirco/sf-city-lots-json/raw/master/citylots.json")
16+
fun getresponseData(): Call<ResponseBody>
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".activity.FourthActivity">
8+
9+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/layout/activity_main.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@
7272

7373
tools:ignore="MissingConstraints" />
7474

75+
<androidx.appcompat.widget.AppCompatButton
76+
android:id="@+id/button4"
77+
android:layout_width="match_parent"
78+
android:layout_height="wrap_content"
79+
android:layout_marginTop="10dp"
80+
android:onClick="@{v->act.button4Click(v)}"
81+
android:text="Retrofit (Streaming)"
82+
app:layout_constraintEnd_toEndOf="parent"
83+
app:layout_constraintStart_toStartOf="parent"
84+
app:layout_constraintTop_toBottomOf="@+id/button3"
85+
86+
tools:ignore="MissingConstraints" />
87+
7588
</androidx.constraintlayout.widget.ConstraintLayout>
7689

7790

0 commit comments

Comments
 (0)