Skip to content

Commit

Permalink
update: result
Browse files Browse the repository at this point in the history
  • Loading branch information
amirisback committed Dec 10, 2023
1 parent d3cec72 commit 2bf93ae
Show file tree
Hide file tree
Showing 20 changed files with 518 additions and 115 deletions.
18 changes: 6 additions & 12 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
android:name=".news.NewsActivity"
android:exported="false" />

<activity
android:name=".news.result.NewsResultActivity"
android:exported="false" />

<activity
android:name=".main.MainJavaActivity"
android:exported="false" />
Expand Down Expand Up @@ -60,12 +64,12 @@
<activity
android:name=".piracy.KotlinActivity"
android:exported="false"
android:theme="@style/AppTheme.NoActionBar"/>
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".piracy.PiracyMainActivity"
android:exported="false"
android:theme="@style/AppTheme.NoActionBar"/>
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name=".main.MainActivity"
Expand All @@ -79,16 +83,6 @@
</intent-filter>
</activity>

<receiver
android:name=".notification.custom.NotificationBroadcastReceiver"
android:enabled="true"
android:exported="false" />
<receiver android:name=".notification.simple.MainNotifReceiver" />

<service
android:name=".notification.custom.NotificationService"
android:exported="false" />

</application>

</manifest>
6 changes: 5 additions & 1 deletion app/src/main/java/com/frogobox/appsdk/di/ViewModelModule.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.frogobox.appsdk.di

import com.frogobox.appsdk.news.NewsViewModel
import org.koin.android.ext.koin.androidApplication
import com.frogobox.appsdk.news.result.NewsResultViewModel
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

Expand All @@ -25,4 +25,8 @@ val viewModelModule = module {
NewsViewModel(get())
}

viewModel {
NewsResultViewModel(get())
}

}
5 changes: 5 additions & 0 deletions app/src/main/java/com/frogobox/appsdk/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Bundle
import com.frogobox.appsdk.databinding.ActivityMainBinding
import com.frogobox.appsdk.log.LogActivity
import com.frogobox.appsdk.news.NewsActivity
import com.frogobox.appsdk.news.result.NewsResultActivity
import com.frogobox.appsdk.notification.simple.MainNotifActivity
import com.frogobox.appsdk.piracy.KotlinActivity
import com.frogobox.appsdk.piracy.PiracyMainActivity
Expand Down Expand Up @@ -44,6 +45,10 @@ class MainActivity : CoreMainActivity<ActivityMainBinding>() {
startActivityExt<NewsActivity>()
}

btnMenuNewsResult.setOnClickListener {
startActivityExt<NewsResultActivity>()
}

btnMenuJavaActivity.setOnClickListener {
startActivityExt<MainJavaActivity>()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.frogobox.appsdk.news

import android.os.Bundle
import com.frogobox.appsdk.R
import com.frogobox.appsdk.core.BaseActivity
import com.frogobox.appsdk.databinding.ActivityNewsDetailBinding
import com.frogobox.appsdk.model.Article
import com.frogobox.sdk.ext.getExtraDataExt
import com.frogobox.sdk.ext.glideLoad
import com.frogobox.sdk.ext.setImageExt

class NewsDetailActivity : BaseActivity<ActivityNewsDetailBinding>() {

Expand All @@ -21,7 +22,7 @@ class NewsDetailActivity : BaseActivity<ActivityNewsDetailBinding>() {
super.onCreateExt(savedInstanceState)
setupDetailActivity("Detail News")
binding.apply {
ivNewsDetailImage.glideLoad(extraData.urlToImage)
ivNewsDetailImage.setImageExt(extraData.urlToImage, R.drawable.ic_frogobox)
newsDetailTitle.text = extraData.title
newsDetailDescription.text = extraData.description
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/frogobox/appsdk/news/NewsViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.frogobox.appsdk.news
import androidx.recyclerview.widget.RecyclerView
import com.frogobox.appsdk.databinding.ItemNewsBinding
import com.frogobox.appsdk.model.Article
import com.frogobox.sdk.ext.glideLoad
import com.frogobox.sdk.ext.setImageExt
import com.frogobox.sdk.ext.startActivityExt


Expand All @@ -24,7 +24,7 @@ class NewsViewHolder(private val binding: ItemNewsBinding) : RecyclerView.ViewHo

fun bind(data: Article) {
binding.apply {
ivNewsImage.glideLoad(data.urlToImage)
ivNewsImage.setImageExt(data.urlToImage)
tvNewsTitle.text = data.title
tvNewsDescription.text = data.description
root.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.frogobox.appsdk.news.result

import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import com.frogobox.appsdk.core.BaseActivity
import com.frogobox.appsdk.databinding.ActivityNewsBinding
import com.frogobox.appsdk.model.Article
import com.frogobox.appsdk.news.NewsViewAdapter
import com.frogobox.coresdk.source.FrogoResult
import com.frogobox.sdk.ext.progressViewHandle
import org.koin.androidx.viewmodel.ext.android.viewModel

class NewsResultActivity : BaseActivity<ActivityNewsBinding>() {

private val newsViewModel: NewsResultViewModel by viewModel()

override fun setupViewBinding(): ActivityNewsBinding {
return ActivityNewsBinding.inflate(layoutInflater)
}

override fun setupViewModel() {
super.setupViewModel()
newsViewModel.apply {

articles.observe(this@NewsResultActivity) {
when (it) {
is FrogoResult.Error -> {}
is FrogoResult.Finish -> {}
is FrogoResult.Loading -> {
binding.progressCircular.progressViewHandle(it.isLoading)
}
is FrogoResult.Success -> {
it.result.articles?.let { list ->
setupRecyclerView(list)
}
}
}

}

}
}

override fun onCreateExt(savedInstanceState: Bundle?) {
super.onCreateExt(savedInstanceState)
setupDetailActivity("News API")
if (savedInstanceState == null) {
newsViewModel.onStart()
}
}

private fun setupRecyclerView(data: List<Article>) {
binding.recyclerView.apply {
adapter = NewsViewAdapter().apply {
setupData(data)
}
layoutManager = LinearLayoutManager(context).apply {
orientation = LinearLayoutManager.VERTICAL
stackFromEnd = false
reverseLayout = false
}
}
}

override fun onDestroy() {
super.onDestroy()
newsViewModel.onClearDisposable()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.frogobox.appsdk.news.result

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.frogobox.appsdk.model.ArticleResponse
import com.frogobox.appsdk.source.AppRepository
import com.frogobox.appsdk.util.NewsConstant
import com.frogobox.coresdk.response.FrogoDataResponse
import com.frogobox.coresdk.source.FrogoResult
import com.frogobox.sdk.view.FrogoViewModel2


/*
* Created by faisalamir on 08/04/22
* FrogoSDK
* -----------------------------------------
* Name : Muhammad Faisal Amir
* E-mail : [email protected]
* Github : github.com/amirisback
* -----------------------------------------
* Copyright (C) 2022 Frogobox Media Inc.
* All rights reserved
*
*/

class NewsResultViewModel(
private val repository: AppRepository,
) : FrogoViewModel2() {

private var _articles = MutableLiveData<FrogoResult<ArticleResponse>>()
var articles: LiveData<FrogoResult<ArticleResponse>> = _articles

private fun getData() {
repository.getTopHeadlineResult(
"",
null,
NewsConstant.CATEGORY_GENERAL,
NewsConstant.COUNTRY_ID,
null,
null,
_articles
)
}

private fun getPref() {
repository.getPrefString("KEY_PREF", object : FrogoDataResponse<String> {
override fun onFailed(statusCode: Int, errorMessage: String) {}
override fun onFinish() {}
override fun onHideProgress() {}
override fun onShowProgress() {}
override fun onSuccess(data: String) {}
})
}

override fun onStart() {
super.onStart()
getData()
getPref()
}

override fun onClearDisposable() {
super.onClearDisposable()
repository.onClearDisposables()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.frogobox.appsdk.source

import androidx.lifecycle.MutableLiveData
import com.frogobox.appsdk.model.ArticleResponse
import com.frogobox.appsdk.model.SourceResponse
import com.frogobox.coresdk.source.FrogoResult
import com.frogobox.coresdk.source.ICoreDataSource


/*
* Created by faisalamir on 08/04/22
* FrogoSDK
* -----------------------------------------
* Name : Muhammad Faisal Amir
* E-mail : [email protected]
* Github : github.com/amirisback
* -----------------------------------------
* Copyright (C) 2022 Frogobox Media Inc.
* All rights reserved
*
*/

interface AppDataSourceResult : ICoreDataSource {

// Get Top Headline
fun getTopHeadlineResult(
q: String?,
sources: String?,
category: String?,
country: String?,
pageSize: Int?,
page: Int?,
result: MutableLiveData<FrogoResult<ArticleResponse>>
)

// Get Everythings
fun getEverythingsResult(
q: String?,
from: String?,
to: String?,
qInTitle: String?,
sources: String?,
domains: String?,
excludeDomains: String?,
language: String?,
sortBy: String?,
pageSize: Int?,
page: Int?,
result: MutableLiveData<FrogoResult<ArticleResponse>>
)

// Get Sources
fun getSourcesResult(
language: String,
country: String,
category: String,
result: MutableLiveData<FrogoResult<SourceResponse>>
)

}
Loading

0 comments on commit 2bf93ae

Please sign in to comment.