Browse Source

basic setup

sumon88 3 years ago
parent
commit
7cbc546b76

+ 4 - 0
README.md

@@ -15,6 +15,10 @@ The Giphy search app will be responsible :-
 3. A basic UI which will display list of images from the result in grid form
 4. If search query is updated, the old result set should reset with new one
 5. Errors should handled with logs and shown to users
+6. We have done the initial setup for you
+7. Feel free to use any architecture paradigms you want.
+8. Fix code smell/bad usages that you see.
+
 
 
 ### Hard Requirements:-

+ 4 - 3
app/build.gradle

@@ -34,9 +34,10 @@ android {
 dependencies {
 
     implementation 'androidx.core:core-ktx:1.7.0'
-    implementation 'androidx.appcompat:appcompat:1.4.0'
-    implementation 'com.google.android.material:material:1.4.0'
-    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
+    implementation 'androidx.appcompat:appcompat:1.4.1'
+    implementation 'com.google.android.material:material:1.5.0'
+    implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
+    implementation 'com.google.code.gson:gson:2.8.9'
     testImplementation 'junit:junit:4.+'
     androidTestImplementation 'androidx.test.ext:junit:1.1.3'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

+ 26 - 0
app/src/main/java/com/livelike/livelikeandroidchallenge/MainActivity.kt

@@ -2,10 +2,36 @@ package com.livelike.livelikeandroidchallenge
 
 import androidx.appcompat.app.AppCompatActivity
 import android.os.Bundle
+import android.text.Editable
+import android.text.TextWatcher
+import android.widget.EditText
+import androidx.recyclerview.widget.RecyclerView
+import androidx.recyclerview.widget.GridLayoutManager
+
+
 
 class MainActivity : AppCompatActivity() {
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_main)
+
+        var searchString = ""
+
+        val list: RecyclerView = findViewById(R.id.gifsList)
+        val edtTxt: EditText = findViewById(R.id.edtxt)
+
+        list.layoutManager = GridLayoutManager(this, 2)
+
+        edtTxt.addTextChangedListener(object : TextWatcher {
+            override fun afterTextChanged(s: Editable?) {
+                searchString =  s.toString()
+            }
+
+            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
+            }
+
+            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
+            }
+        })
     }
 }

+ 78 - 0
app/src/main/java/com/livelike/livelikeandroidchallenge/data/GifModels.kt

@@ -0,0 +1,78 @@
+package com.livelike.livelikeandroidchallenge.data
+
+
+
+import com.google.gson.annotations.SerializedName
+
+data class GifModel(
+    @SerializedName("type")
+    val type: String? = null,
+    @SerializedName("id")
+    val id: String? = null,
+    @SerializedName("url")
+    val url: String? = null,
+    @SerializedName("slug")
+    val slug: String? = null,
+    @SerializedName("bitly_gif_url")
+    val bitlyGifUrl: String? = null,
+    @SerializedName("bitly_url")
+    val bitlyUrl: String? = null,
+    @SerializedName("embed_url")
+    val embedUrl: String? = null,
+    @SerializedName("username")
+    val username: String? = null,
+    @SerializedName("source")
+    val source: String? = null,
+    @SerializedName("title")
+    val title: String? = null,
+    @SerializedName("rating")
+    val rating: String? = null,
+    @SerializedName("content_url")
+    val contentUrl: String? = null,
+    @SerializedName("source_tld")
+    val sourceTld: String? = null,
+    @SerializedName("source_post_url")
+    val sourcePostUrl: String? = null,
+    @SerializedName("is_sticker")
+    val isSticker: Int? = null,
+    @SerializedName("import_datetime")
+    val importDatetime: String? = null,
+    @SerializedName("trending_datetime")
+    val trendingDatetime: String? = null
+)
+
+data class PaginationModel(
+    @SerializedName("offset")
+    val offset: Int?,
+    @SerializedName("total_count")
+    val totalCount: Int?,
+    @SerializedName("count")
+    val count: Int?
+)
+
+
+data class UserModel(
+    @SerializedName("avatar_url")
+    var avatarUrl: String?  = null,
+    @SerializedName("banner_image")
+    var bannerImage: String?  = null,
+    @SerializedName("banner_url")
+    var bannerUrl: String?  = null,
+    @SerializedName("profile_url")
+    var profileUrl: String?  = null,
+    @SerializedName("username")
+    var username: String?  = null,
+    @SerializedName("display_name")
+    var displayName: String?  = null,
+    @SerializedName("description")
+    var description: String?  = null,
+    @SerializedName("instagram_url")
+    var instagramUrl: String?  = null,
+    @SerializedName("website_url")
+    var websiteUrl: String?  = null,
+    @SerializedName("is_verified")
+    var isVerified: Boolean? = null
+)
+
+
+

+ 16 - 3
app/src/main/res/layout/activity_main.xml

@@ -6,13 +6,26 @@
     android:layout_height="match_parent"
     tools:context=".MainActivity">
 
-    <TextView
+    <EditText
+        android:id="@+id/edtxt"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:text="Hello World!"
-        app:layout_constraintBottom_toBottomOf="parent"
+        android:hint="Search Giphy"
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
+
+    <androidx.recyclerview.widget.RecyclerView
+                android:id="@+id/gifsList"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_marginTop="20dp"
+                android:gravity="center"
+                app:layout_constrainedHeight="true"
+                app:layout_constraintTop_toBottomOf="@id/edtxt"
+                app:layout_constraintEnd_toEndOf="parent"
+                app:layout_constraintStart_toStartOf="parent"
+                 />
+
 </androidx.constraintlayout.widget.ConstraintLayout>

+ 11 - 0
app/src/main/res/layout/grid_cell_view.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content">
+
+    <ImageView
+            android:id="@+id/imageView"
+            android:layout_width="wrap_content"
+            android:layout_height="200dp"/>
+
+</LinearLayout>

+ 2 - 1
gradle.properties

@@ -18,4 +18,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 # Kotlin code style for this project: "official" or "obsolete":
-kotlin.code.style=official
+kotlin.code.style=official
+GIPHY_API_KEY="8LtshfHp2uWb6CFpmzPtJmborDaVWu0Z"