Skip to content

Latest commit

 

History

History
187 lines (147 loc) · 6.39 KB

README.md

File metadata and controls

187 lines (147 loc) · 6.39 KB

logo

RssNews

RssNews is an Android application that allows users to read, favorite, and manage news articles fetched from RSS feeds. The project supports user authentication through email/password and Google Sign-In, with articles stored in Firebase Realtime Database. The application was created as part of the PRM (Mobile Programming) course at PJATK.

Features

  • User authentication via email/password and Google Sign-In
  • Fetch news articles from RSS feeds
  • Mark articles as read/unread
  • Favorite/unfavorite articles
  • Persist data using Firebase Realtime Database
  • Support for local storage using SharedPreferences
  • Push notifications for new articles
  • Swipe to refresh for fetching new articles
  • TopAppBar for category selection and account management

Screenshots

Login Screen

Login Screen

Main Screen

Main Screen

Article Details

Article Details

Installation

  1. Clone the repository:

    git clone https://github.com/szwedzik/rssnews.git
  2. Open the project in Android Studio.

  3. Build the project to install all dependencies.

  4. Run the project on an Android emulator or a physical device.

Prerequisites

  • Android Studio Arctic Fox or later
  • Android SDK 30 or later
  • Firebase project with Realtime Database and Authentication enabled
  • Google services JSON file (google-services.json)

Dependencies

Getting Started

Firebase Configuration

  1. Create a new project in the Firebase Console.

  2. Enable Authentication (Email/Password and Google Sign-In).

  3. Enable Realtime Database.

  4. Download the google-services.json file and place it in the app directory of your project.

  5. Replace the placeholder in strings.xml with your Firebase key:

    <resources>
        <string name="app_name">RssNews</string>
        <string name="default_web_client_id">REPLACE_THIS_WITH_YOUR_FIREBASE_KEY</string>
    </resources>

Setting Up Authentication

We use Firebase Authentication for user login and registration.

class FirebaseAuthManager(activity: Activity) {
    private val auth: FirebaseAuth = FirebaseAuth.getInstance()
    private val googleSignInClient: GoogleSignInClient

    init {
        val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(activity.getString(R.string.default_web_client_id))
            .requestEmail()
            .build()
        googleSignInClient = GoogleSignIn.getClient(activity, gso)
    }

    // Other authentication methods...
}


### Fetching Articles
We use RssParser to fetch and parse articles from RSS feeds.
```kotlin
class RssViewModel : ViewModel() {
    private val rssParser: RssParser = RssParser()

    fun fetchArticles(url: String) {
        viewModelScope.launch {
            _isRefreshing.value = true
            try {
                val channel = rssParser.getRssChannel(url)
                val articles = channel.items.map { article ->
                    Article(
                        title = article.title ?: "",
                        link = article.link ?: "",
                        description = cleanDescription(article.description ?: ""),
                        imageUrl = article.image ?: null,
                        categories = article.categories,
                        pubDate = article.pubDate ?: "",
                        creator = article.author ?: "",
                        isRead = sharedPreferencesManager.isArticleRead(article.link ?: ""),
                        isFavorite = sharedPreferencesManager.isArticleFavorite(article.link ?: "")
                    )
                }
                _articles.value = articles
            } catch (e: Exception) {
                e.printStackTrace()
            } finally {
                _isRefreshing.value = false
            }
        }
    }
}

Handling Favorites

Favorites are stored in Firebase Realtime Database.

class FirebaseDatabaseManager {
    private val database: DatabaseReference = FirebaseDatabase.getInstance().reference

    fun saveFavoriteArticle(article: Article) {
        val articleId = article.link.hashCode().toString()
        database.child("favorite_articles").child(articleId).setValue(article)
    }

    fun getFavoriteArticles(): List<Article> {
        val snapshot = database.child("favorite_articles").get().await()
        val articles = snapshot.children.mapNotNull { it.getValue(Article::class.java) }
        return articles
    }
}

Push Notifications

Push notifications are handled using WorkManager.

class ArticleCheckWorker(appContext: Context, workerParams: WorkerParameters) : CoroutineWorker(appContext, workerParams) {

    override suspend fun doWork(): Result {
        // Check for new articles and send notifications
        return Result.success()
    }
}

Permissions

The application requires the following permissions:

  • INTERNET
  • ACCESS_NETWORK_STATE

Permissions are requested at runtime for devices running Android M (API 23) or later.

private fun checkPermissions() {
    if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.INTERNET), REQUEST_CODE)
    }
}

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin feature/my-new-feature)
  5. Create a new Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.