-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a26f8ec
commit c3b3089
Showing
62 changed files
with
2,279 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
apply plugin: 'kotlin-android-extensions' | ||
apply plugin: 'kotlin-kapt' | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "com.azhar.newsapp" | ||
minSdkVersion 23 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
androidExtensions { | ||
experimental = true | ||
} | ||
|
||
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 'androidx.appcompat:appcompat:1.2.0' | ||
implementation 'androidx.core:core-ktx:1.3.2' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
implementation 'androidx.cardview:cardview:1.0.0' | ||
implementation 'androidx.recyclerview:recyclerview:1.1.0' | ||
implementation 'androidx.legacy:legacy-support-v4:1.0.0' | ||
testImplementation 'junit:junit:4.13' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
|
||
implementation 'com.google.android.material:material:1.3.0' | ||
|
||
implementation 'com.github.bumptech.glide:glide:4.11.0' | ||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0' | ||
|
||
implementation 'com.github.ivbaranov:materialfavoritebutton:0.1.5' | ||
implementation 'com.ismaeldivita.chipnavigation:chip-navigation-bar:1.3.4' | ||
implementation 'com.airbnb.android:lottie:3.5.0' | ||
implementation 'org.ocpsoft.prettytime:prettytime:4.0.4.Final' | ||
implementation 'com.github.sharish:ShimmerRecyclerView:v1.3' | ||
implementation 'com.makeramen:roundedimageview:2.3.0' | ||
|
||
implementation 'com.squareup.retrofit2:retrofit:2.9.0' | ||
implementation 'com.squareup.retrofit2:converter-gson:2.9.0' | ||
implementation 'com.google.code.gson:gson:2.8.6' | ||
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0' | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
package="com.azhar.newsapp"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<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" | ||
android:usesCleartextTraffic="true" | ||
tools:targetApi="q"> | ||
<activity android:name=".activities.DetailNewsActivity" /> | ||
<activity android:name=".activities.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
110 changes: 110 additions & 0 deletions
110
app/src/main/java/com/azhar/newsapp/activities/DetailNewsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package com.azhar.newsapp.activities | ||
|
||
import android.content.Intent | ||
import android.graphics.Bitmap | ||
import android.os.Bundle | ||
import android.view.MenuItem | ||
import android.view.View | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.azhar.newsapp.R | ||
import com.azhar.newsapp.model.ModelArticle | ||
import kotlinx.android.synthetic.main.activity_detail_news.* | ||
|
||
/** | ||
* Created by Azhar Rivaldi on 10-04-2021 | ||
* Github : https://github.com/AzharRivaldi | ||
* Linkedin : https://www.linkedin.com/in/azhar-rivaldi | ||
* Instagram : https://www.instagram.com/azhardvls_ | ||
* Twitter : https://twitter.com/azharrvldi_ | ||
* Youtube Channel : https://bit.ly/2PJMowZ | ||
*/ | ||
|
||
class DetailNewsActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
const val DETAIL_NEWS = "DETAIL_NEWS" | ||
} | ||
|
||
var modelArticle: ModelArticle? = null | ||
var strNewsURL: String? = null | ||
var strTitle: String? = null | ||
var strSubTitle: String? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_detail_news) | ||
|
||
setSupportActionBar(toolbar) | ||
assert(supportActionBar != null) | ||
supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||
supportActionBar?.setDisplayShowTitleEnabled(false) | ||
|
||
progressBar.max = 100 | ||
|
||
//get data intent | ||
modelArticle = intent.getParcelableExtra(DETAIL_NEWS) | ||
if (modelArticle != null) { | ||
|
||
strNewsURL = modelArticle?.url | ||
strTitle = modelArticle?.title | ||
strSubTitle = modelArticle?.url | ||
|
||
tvTitle.text = strTitle | ||
tvSubTitle.text = strSubTitle | ||
|
||
//share news | ||
imageShare.setOnClickListener { | ||
val share = Intent(Intent.ACTION_SEND) | ||
share.type = "text/plain" | ||
share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET) | ||
share.putExtra(Intent.EXTRA_TEXT, strNewsURL) | ||
startActivity(Intent.createChooser(share, "Bagikan ke : ")) | ||
} | ||
|
||
//show news | ||
showWebView() | ||
} | ||
} | ||
|
||
private fun showWebView() { | ||
webView.settings.loadsImagesAutomatically = true | ||
webView.settings.javaScriptEnabled = true | ||
webView.settings.domStorageEnabled = true | ||
webView.settings.setSupportZoom(true) | ||
webView.settings.builtInZoomControls = true | ||
webView.settings.displayZoomControls = false | ||
webView.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY | ||
webView.loadUrl(strNewsURL!!) | ||
|
||
progressBar.progress = 0 | ||
|
||
webView.webViewClient = object : WebViewClient() { | ||
override fun shouldOverrideUrlLoading(view: WebView, newUrl: String): Boolean { | ||
view.loadUrl(newUrl) | ||
progressBar.progress = 0 | ||
return true | ||
} | ||
|
||
override fun onPageStarted(view: WebView, urlStart: String, favicon: Bitmap) { | ||
strNewsURL = urlStart | ||
invalidateOptionsMenu() | ||
} | ||
|
||
override fun onPageFinished(view: WebView, urlPage: String) { | ||
progressBar.visibility = View.GONE | ||
invalidateOptionsMenu() | ||
} | ||
} | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
if (item.itemId == android.R.id.home) { | ||
finish() | ||
return true | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/azhar/newsapp/activities/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.azhar.newsapp.activities | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
import com.azhar.newsapp.R | ||
import com.azhar.newsapp.fragment.* | ||
import com.ismaeldivita.chipnavigation.ChipNavigationBar | ||
import kotlinx.android.synthetic.main.activity_main.* | ||
|
||
/** | ||
* Created by Azhar Rivaldi on 10-04-2021 | ||
* Github : https://github.com/AzharRivaldi | ||
* Linkedin : https://www.linkedin.com/in/azhar-rivaldi | ||
* Instagram : https://www.instagram.com/azhardvls_ | ||
* Twitter : https://twitter.com/azharrvldi_ | ||
* Youtube Channel : https://bit.ly/2PJMowZ | ||
*/ | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
|
||
bottomNavigation.setItemSelected(R.id.menuHeadline, true) | ||
|
||
setupFragment(FragmentHeadline()) | ||
|
||
//open fragment | ||
bottomNavigation.setOnItemSelectedListener(object : ChipNavigationBar.OnItemSelectedListener { | ||
override fun onItemSelected(id: Int) { | ||
when (id) { | ||
R.id.menuHeadline -> setupFragment(FragmentHeadline()) | ||
R.id.menuSports -> setupFragment(FragmentSports()) | ||
R.id.menuTechnology -> setupFragment(FragmentTechnology()) | ||
R.id.menuBusiness -> setupFragment(FragmentBusiness()) | ||
R.id.menuHealth -> setupFragment(FragmentHealth()) | ||
R.id.menuEntertaiment -> setupFragment(FragmentEntertaiment()) | ||
R.id.menuSearch -> setupFragment(FragmentSearch()) | ||
} | ||
} | ||
}) | ||
} | ||
|
||
private fun setupFragment(fragment : Fragment) { | ||
val transaction = supportFragmentManager.beginTransaction() | ||
transaction.replace(R.id.fragmentLayout, fragment) | ||
transaction.commit() | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/azhar/newsapp/adapter/NewsAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.azhar.newsapp.adapter | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.FrameLayout | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.azhar.newsapp.R | ||
import com.azhar.newsapp.activities.DetailNewsActivity | ||
import com.azhar.newsapp.model.ModelArticle | ||
import com.azhar.newsapp.util.Utils.DateFormat | ||
import com.azhar.newsapp.util.Utils.DateTimeHourAgo | ||
import com.bumptech.glide.Glide | ||
import com.bumptech.glide.load.engine.DiskCacheStrategy | ||
import com.makeramen.roundedimageview.RoundedImageView | ||
import kotlinx.android.synthetic.main.list_item_news.view.* | ||
|
||
/** | ||
* Created by Azhar Rivaldi on 10-04-2021 | ||
* Github : https://github.com/AzharRivaldi | ||
* Linkedin : https://www.linkedin.com/in/azhar-rivaldi | ||
* Instagram : https://www.instagram.com/azhardvls_ | ||
* Twitter : https://twitter.com/azharrvldi_ | ||
* Youtube Channel : https://bit.ly/2PJMowZ | ||
*/ | ||
|
||
class NewsAdapter(private val modelArticles: MutableList<ModelArticle>, private val context: Context) : | ||
RecyclerView.Adapter<ViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
val view = LayoutInflater.from(context).inflate(R.layout.list_item_news, parent, false) | ||
return ViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
val model = modelArticles[position] | ||
|
||
if (model.urlToImage == null) { | ||
holder.imageThumbnail.setImageResource(R.drawable.ic_broken_image) | ||
} else { | ||
Glide.with(context) | ||
.load(model.urlToImage) | ||
.diskCacheStrategy(DiskCacheStrategy.ALL) | ||
.into(holder.imageThumbnail) | ||
} | ||
|
||
if (model.author == null) { | ||
holder.tvNameSource.text = model.modelSource?.name | ||
} else { | ||
holder.tvNameSource.text = model.author + " \u2022 " + model.modelSource?.name | ||
} | ||
|
||
holder.tvTimeAgo.text = DateTimeHourAgo(model.publishedAt) | ||
holder.tvTitleNews.text = model.title | ||
holder.tvDateTime.text = DateFormat(model.publishedAt) | ||
holder.frameListNews.setOnClickListener { | ||
val intent = Intent(context, DetailNewsActivity::class.java) | ||
intent.putExtra(DetailNewsActivity.DETAIL_NEWS, modelArticles[position]) | ||
context.startActivity(intent) | ||
} | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return modelArticles.size | ||
} | ||
|
||
internal class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
var frameListNews: FrameLayout | ||
var tvTimeAgo: TextView | ||
var tvNameSource: TextView | ||
var tvTitleNews: TextView | ||
var tvDateTime: TextView | ||
var imageThumbnail: RoundedImageView | ||
|
||
init { | ||
frameListNews = itemView.frameListNews | ||
tvTimeAgo = itemView.tvTimeAgo | ||
tvNameSource = itemView.tvNameSource | ||
tvTitleNews = itemView.tvTitleNews | ||
tvDateTime = itemView.tvDateTime | ||
imageThumbnail = itemView.imageThumbnail | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.