Skip to content

Commit

Permalink
add categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj-m01 committed Mar 18, 2022
1 parent 63526ee commit 660c9e0
Show file tree
Hide file tree
Showing 36 changed files with 675 additions and 537 deletions.
16 changes: 15 additions & 1 deletion .idea/misc.xml

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

35 changes: 3 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,16 @@
Android news app built in kotlin that fetches news data from <a href="https://newsapi.org/">news api</a> with **Retrofit** and displays news to users.
This App follow MVVM architecture carrying Room operations in Data Access Objects(DAO) and API calls in Repository, and fragments navigations implemented with Android Navigation Component.

### Problem Statement :
In Today's corporate life, people don't have enough time to watch news from different sources, thus they can miss out important opportunities, information, etc. Besides opportunites, it's a good habit to be educated about the environment we live in.

### Proposed Solution :
A News app built in kotlin with implementation of MVVM architecture and android navigation components.This news app clusters news from various sources of journalism, So that users can get aware in a glimpse. They can also share relevant news with their belongings and save important news.


### App Screenshots :

<table align="center">
<tr>
<th>News</th>
<th>Home</th>
<th>Saved News</th>
<th>News Sharing</th>
</tr>
<tr>
<td><img src="https://user-images.githubusercontent.com/79650580/148635903-616783b2-7a1d-4630-8dba-c2d4464ab322.jpg" alt="News Display" style="width:250px;height:500px;"></td>
<td><img src="https://github.com/Raj-m01/News-App/screenshots/App_home.gif" alt="News home" style="width:250px;height:500px;"></td>
<td><img src="https://user-images.githubusercontent.com/79650580/148636163-39cc92db-8472-4129-b720-a247f40dc998.jpg" alt="Saved News" style="width:250px;height:500px;"></td>
<td><img src="https://user-images.githubusercontent.com/79650580/148540369-f782a187-b760-42c8-9eb0-8cd461ae7e27.jpg" alt="Image - news sharing" style="width:250px;height:500px;"></td>
</tr>
Expand All @@ -27,13 +20,6 @@ A News app built in kotlin with implementation of MVVM architecture and android



### App features :
* Views News
* Share News
* Save News



### MVVM Architecture :

MVVM is one of the architectural patterns which enhances separation of concerns, it allows separating the user interface logic from the business (or the back-end) logic. Its target (with other MVC patterns goal) is to achieve the following principle "Keeping UI code simple and free of app logic in order to make it easier to manage".
Expand Down Expand Up @@ -62,22 +48,7 @@ MVVM is one of the architectural patterns which enhances separation of concerns,
* **LiveData:** A data holder class that can be observed. Always holds/caches the latest version of data, and notifies its observers when data has changed.


### Navigation Component :

#### The Navigation component consists of three key parts that are described below:

* **Navigation graph :** An XML resource that contains all navigation-related information in one centralized location. This includes all of the individual content areas within your app, called destinations, as well as the possible paths that a user can take through your app.

* **NavHost :** An empty container that displays destinations from your navigation graph. The Navigation component contains a default NavHost implementation, NavHostFragment, that displays fragment destinations.

* **NavController :** An object that manages app navigation within a NavHost. The NavController orchestrates the swapping of destination content in the NavHost as users move throughout your app.

### Retrofit :
Retrofit is a type-safe REST client for Android, Java and Kotlin developed by Square. The library provides a powerful framework for authenticating and interacting with APIs and sending network requests with OkHttp.

### Application link : <a href="https://drive.google.com/file/d/1hjB8vKHGF_7C7B1QBB0-E7P5eOWmux3t/view?usp=sharing">**Click here to download**</a>

### Future Scope :

* Add Quiz such as sudoku, words, etc. section in app
* Display various data, surveys, events( such as earthquake magnitude) in analytical visuals to get better idea.
### Application link : <a href="https://drive.google.com/file/d/1u0A4mCkY98cfavE32c6GH_bVp0v9wujr/view?usp=sharing">**Click here to download**</a>
20 changes: 12 additions & 8 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ plugins {
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'
}
apply plugin: 'kotlin-android'


android {
Expand Down Expand Up @@ -43,12 +44,13 @@ android {

dependencies {

def room_version = "2.4.0"
def nav_version = "2.3.5"
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
def room_version = '2.4.2'
def nav_version = '2.4.1'

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0"
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'

implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-fragment-ktx:2.4.1"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

implementation "androidx.room:room-runtime:$room_version"
Expand All @@ -57,8 +59,8 @@ dependencies {
implementation "androidx.activity:activity-ktx:1.4.0"

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.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand All @@ -74,6 +76,8 @@ dependencies {


implementation 'com.squareup.picasso:picasso:2.71828'

implementation "androidx.core:core-ktx:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

}
implementation 'com.facebook.shimmer:shimmer:0.5.0'
}
15 changes: 11 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,31 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.newsapp">

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:label="News App"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.NewsApp">
<activity
android:name=".MainActivity"
android:exported="true">
android:exported="true"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<activity
android:name=".SavedNews"
android:parentActivityName=".MainActivity"
android:label="Saved News">

</activity>
</application>

</manifest>
49 changes: 20 additions & 29 deletions app/src/main/java/com/example/newsapp/CustomAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,16 @@ import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import androidx.navigation.NavController
import androidx.navigation.findNavController
import androidx.recyclerview.widget.RecyclerView
import com.squareup.picasso.Picasso


class CustomAdapter(private val newsList: MutableList<NewsModel>, val saveListener: SaveClickListener) : RecyclerView.Adapter<CustomAdapter.ViewHolder>(){

lateinit var context: Context
private lateinit var navController: NavController
private lateinit var context: Context

companion object{
var myClickListener: SaveClickListener? = null
Expand All @@ -28,9 +26,6 @@ class CustomAdapter(private val newsList: MutableList<NewsModel>, val saveListen

val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item, parent, false)
context = parent.context

navController = parent.findNavController()

return ViewHolder(view)
}

Expand All @@ -57,41 +52,36 @@ class CustomAdapter(private val newsList: MutableList<NewsModel>, val saveListen
}


if(navController.currentDestination.toString().contains("savedNewsFragment4")){
if(context.toString().contains("com.example.newsapp.SavedNews")){
holder.saveBtn.setImageResource(R.drawable.ic_baseline_delete_outline_24)

}


holder.image.setOnClickListener( View.OnClickListener {
newsData.url?.let { it1 -> openNews(it1,context) }
})
holder.image.setOnClickListener {
newsData.url?.let { it1 -> openNews(it1, context) }
}

holder.headLine.setOnClickListener(View.OnClickListener { newsData.url?.let { it1 ->
holder.headLine.setOnClickListener{ newsData.url?.let { it1 ->
openNews(
it1, context)
} })
} }

holder.shareBtn.setOnClickListener(View.OnClickListener {
holder.shareBtn.setOnClickListener {

val intent = Intent(Intent.ACTION_SEND)
intent.putExtra(Intent.EXTRA_TEXT,"Hey, checkout this news : "+newsData.url)
intent.putExtra(Intent.EXTRA_TEXT, "Hey, checkout this news : " + newsData.url)
intent.type = "text/plain"
context.startActivity(Intent.createChooser(intent,"Share with :"))
context.startActivity(Intent.createChooser(intent, "Share with :"))

})
}

myClickListener = saveListener

holder.saveBtn.setOnClickListener(object : View.OnClickListener {

override fun onClick(v: View?) {
if (myClickListener != null) {
myClickListener?.onSaveBtnClick(holder.adapterPosition)
}
holder.saveBtn.setOnClickListener {
if (myClickListener != null) {
myClickListener?.onSaveBtnClick(holder.adapterPosition)
}
})

}
}


Expand All @@ -102,15 +92,16 @@ class CustomAdapter(private val newsList: MutableList<NewsModel>, val saveListen

class ViewHolder(ItemView: View?) : RecyclerView.ViewHolder(ItemView!!){

val saveBtn: ImageView = itemView.findViewById(R.id.save_news)
val shareBtn: ImageView = itemView.findViewById(R.id.share_btn)
val saveBtn: ImageButton = itemView.findViewById(R.id.save_news)
val shareBtn: ImageButton = itemView.findViewById(R.id.share_btn)
val image: ImageView = itemView.findViewById(R.id.news_image)
val headLine: TextView = itemView.findViewById(R.id.headline)
val description: TextView = itemView.findViewById(R.id.description)


}

open interface SaveClickListener {
interface SaveClickListener {
fun onSaveBtnClick(position: Int)
}

Expand Down
Loading

0 comments on commit 660c9e0

Please sign in to comment.