generated from frogobox/frogo-android-sdk
-
-
Notifications
You must be signed in to change notification settings - Fork 6
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
d3cec72
commit 2bf93ae
Showing
20 changed files
with
518 additions
and
115 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
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
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
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
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
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/frogobox/appsdk/news/result/NewsResultActivity.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,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() | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
app/src/main/java/com/frogobox/appsdk/news/result/NewsResultViewModel.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,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() | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
app/src/main/java/com/frogobox/appsdk/source/AppDataSourceResult.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,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>> | ||
) | ||
|
||
} |
Oops, something went wrong.