Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Commit

Permalink
update: build.gradle refactoring code
Browse files Browse the repository at this point in the history
  • Loading branch information
amirisback committed May 13, 2020
1 parent b8d6ad0 commit 0b88b72
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 16 deletions.
30 changes: 27 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {

def versionMajor = 1
def versionMinor = 0
def versionPatch = 4

def projectVersionCode = (versionMajor*100) + (versionMinor*10) + (versionPatch*1)
def projectVersionName = "$versionMajor.$versionMinor.$versionPatch"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

compileSdkVersion 29
buildToolsVersion "29.0.3"

defaultConfig {
applicationId "com.frogobox.newsapi"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
versionCode projectVersionCode
versionName projectVersionName

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -31,10 +45,20 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'

implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'

// Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
kapt 'com.github.bumptech.glide:compiler:4.11.0'

// library frogo-recycler-view
implementation 'com.github.amirisback:frogo-recycler-view:2.2.4'

implementation project(':frogonewsapi')

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
42 changes: 42 additions & 0 deletions app/src/main/java/com/frogobox/newsapi/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
package com.frogobox.newsapi

import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import com.frogobox.frogonewsapi.ConsumeNewsApi
import com.frogobox.frogonewsapi.callback.NewsResultCallback
import com.frogobox.frogonewsapi.data.model.Article
import com.frogobox.frogonewsapi.data.response.ArticleResponse
import com.frogobox.frogonewsapi.util.NewsConstant.CATEGORY_HEALTH
import com.frogobox.frogonewsapi.util.NewsConstant.COUNTRY_ID
import com.frogobox.frogonewsapi.util.NewsUrl
import com.frogobox.recycler.boilerplate.viewrclass.FrogoViewAdapterCallback
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupNewsApi()
}

private fun setupNewsApi() {
val consumeNewsApi = ConsumeNewsApi(NewsUrl.NEWS_API_KEY) // Your API_KEY
consumeNewsApi.usingChuckInterceptor(this)
consumeNewsApi.getTopHeadline(
Expand All @@ -27,6 +37,7 @@ class MainActivity : AppCompatActivity() {
object : NewsResultCallback<ArticleResponse> {
override fun getResultData(data: ArticleResponse) {
// Your Ui or data
data.articles?.let { setupFrogoRecyclerView(it) }
}

override fun failedResult(statusCode: Int, errorMessage: String?) {
Expand All @@ -35,14 +46,45 @@ class MainActivity : AppCompatActivity() {

override fun onShowProgress() {
// Your Progress Show
runOnUiThread {
progressView.visibility = View.VISIBLE
}
}

override fun onHideProgress() {
// Your Progress Hide
runOnUiThread {
progressView.visibility = View.GONE
}
}

})
}

private fun setupFrogoRecyclerView(data: List<Article>) {
frogorecyclerview.injector<Article>()
.addData(data)
.addCustomView(R.layout.frogo_rv_list_type_6)
.addEmptyView(null)
.addCallback(object : FrogoViewAdapterCallback<Article> {
override fun onItemClicked(data: Article) {}

override fun onItemLongClicked(data: Article) {}

override fun setupInitComponent(view: View, data: Article) {
val tvTitle = view.findViewById<TextView>(R.id.frogo_rv_type_6_tv_title)
val tvSubtitle = view.findViewById<TextView>(R.id.frogo_rv_type_6_tv_subtitle)
val tvDesc = view.findViewById<TextView>(R.id.frogo_rv_type_6_tv_description)
val ivPoster = view.findViewById<ImageView>(R.id.frogo_rv_type_6_iv_poster)

tvTitle.text = data.title ?: "No Data"
tvSubtitle.text = data.author ?: "No Data"
tvDesc.text = data.description
Glide.with(view.context).load(data.urlToImage).into(ivPoster)
}
})
.createLayoutLinearVertical(false)
.build()
}

}
16 changes: 14 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
<com.frogobox.recycler.FrogoRecyclerView
android:id="@+id/frogorecyclerview"
android:layout_width="0dp"
android:layout_height="0dp"
android:paddingTop="@dimen/frogo_rv_dimen_16dp"
android:clipToPadding="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ProgressBar
android:id="@+id/progressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.71'
ext.kotlin_version = '1.3.72'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand All @@ -20,7 +20,7 @@ allprojects {
repositories {
google()
jcenter()

maven { url 'https://jitpack.io' }
}
}

Expand Down
Binary file added docs/image/ss_main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 11 additions & 8 deletions frogonewsapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ apply plugin: 'kotlin-kapt'

android {

def versionMajor = 1
def versionMinor = 0
def versionPatch = 4

def projectVersionCode = (versionMajor*100) + (versionMinor*10) + (versionPatch*1)
def projectVersionName = "$versionMajor.$versionMinor.$versionPatch"

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
Expand All @@ -20,8 +27,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
versionCode projectVersionCode
versionName projectVersionName

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
Expand All @@ -43,13 +50,9 @@ dependencies {

implementation 'com.google.code.gson:gson:2.8.6'

implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:retrofit:2.8.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'

implementation "com.squareup.moshi:moshi:1.8.0"
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.2'
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.2'

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
Expand Down

0 comments on commit 0b88b72

Please sign in to comment.