Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
anncode1 committed May 27, 2019
0 parents commit f055c47
Show file tree
Hide file tree
Showing 50 changed files with 1,384 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
39 changes: 39 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.anncode.offersandcoupons"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'de.hdodenhof:circleimageview:3.0.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.anncode.offersandcoupons

import android.support.test.InstrumentationRegistry
import android.support.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getTargetContext()
assertEquals("com.anncode.offersandcoupons", appContext.packageName)
}
}
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.anncode.offersandcoupons">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>

</manifest>
70 changes: 70 additions & 0 deletions app/src/main/java/com/anncode/offersandcoupons/BaseCode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.anncode.offersandcoupons

/*
*
*
* MainActivity.kt
val rvCoupons: RecyclerView = findViewById(R.id.rvCoupons)
rvCoupons.layoutManager = LinearLayoutManager(this)
val coupons = ArrayList<Coupon>()
val apiService = getClientService()
val call = apiService.getCoupons()
call.enqueue(object : Callback<JsonObject> {
override fun onFailure(call: Call<JsonObject>, t: Throwable) {
Log.e("ERROR: ", t.message)
t.stackTrace
}
override fun onResponse(call: Call<JsonObject>, response: Response<JsonObject>) {
val offersJsonArray = response.body()?.getAsJsonArray("offers")
offersJsonArray?.forEach { jsonElement: JsonElement ->
var jsonObject = jsonElement.asJsonObject
var coupon = Coupon(jsonObject)
coupons.add(coupon)
}
rvCoupons.adapter = RecyclerCouponsAdapter(coupons, R.layout.card_coupon)
}
})
val apiKey = "69d1837829128f9565368ca704c63207"
val urlApi = "http://feed.linkmydeals.com/"
fun getClientService(): ApiService {
val authInterceptor = Interceptor { chain ->
val url = chain.request().url().newBuilder()
.addQueryParameter("API_KEY", apiKey)
.addQueryParameter("format", "json")
.build()
val newRequest = chain.request()
.newBuilder()
.url(url)
.build()
chain.proceed(newRequest)
}
val client = OkHttpClient.Builder()
.addInterceptor(authInterceptor).build()
val retrofit = Retrofit.Builder()
.baseUrl(urlApi)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build()
return retrofit.create(ApiService::class.java)
}
interface ApiService {
@GET("getOffers/")
fun getCoupons(): Call<JsonObject>
}
* */
80 changes: 80 additions & 0 deletions app/src/main/java/com/anncode/offersandcoupons/Coupon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.anncode.offersandcoupons

import com.google.gson.JsonObject
import java.lang.Exception
import java.text.ParseException
import java.text.SimpleDateFormat
import java.io.Serializable
import java.util.*

class Coupon(couponJson: JsonObject?) : Serializable {

lateinit var id: String
lateinit var image_url: String
lateinit var title: String
lateinit var descriptionShort: String
lateinit var category: String
lateinit var description:String
lateinit var offer: String
lateinit var website: String
lateinit var endDate: String
lateinit var url: String

init {
try {
id = couponJson!!.get(ID).asString
image_url = couponJson!!.get(IMAGE_URL).asString
title = couponJson!!.get(TITLE).asString
descriptionShort = chunkWords(couponJson!!.get(DESCRIPTION_SHORT).asString, ' ', 5)
category = chunkWords(couponJson!!.get(CATEGORY).asString, ',', 1)
description = couponJson!!.get(DESCRIPTION).asString
offer = couponJson!!.get(OFFER).asString
website = couponJson!!.get(WEBSITE).asString
endDate = getFormatDate(couponJson!!.get(END_DATE).asString)
url = couponJson!!.get(URL).asString
}catch (e: Exception){
e.printStackTrace()
}


}

companion object {
private val ID = "lmd_id"
private val IMAGE_URL = "image_url"
private val TITLE = "title"
private val DESCRIPTION_SHORT = "offer_text"
private val CATEGORY = "categories"
private val DESCRIPTION = "description"
private val OFFER = "offer"
private val WEBSITE = "store"
private val END_DATE = "end_date"
private val URL = "url"
}

private fun getFormatDate(dateCoupon:String):String {
val format = SimpleDateFormat("yyyy-MM-dd")
val dateFormat = SimpleDateFormat("dd MMMM yyyy")
try {
val parsedDateFormat = format.parse(dateCoupon)
val cal = Calendar.getInstance()
cal.time = parsedDateFormat
return dateFormat.format(cal.time)
} catch (e: ParseException) {
e.printStackTrace()
return ""
}
}


private fun chunkWords(string: String, delimiter: Char, quantity: Int): String {
val words = string.split(delimiter)
var newString: String = ""

for (i in 0..quantity){
newString += words.get(i) + " "
}

return newString
}
}
Loading

0 comments on commit f055c47

Please sign in to comment.