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
public class EnglishNumberToNepaliNumber extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
int x = 4545645; | |
String xInNepali = Util.convertEnglishNumberToNepali(x); | |
Log.d("xInNepali",x+" : "+xInNepali); |
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
//Kotlin | |
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" | |
//Support | |
implementation 'androidx.appcompat:appcompat:1.0.2' | |
implementation 'com.google.android.material:material:1.0.0' | |
implementation 'androidx.recyclerview:recyclerview:1.0.0' | |
implementation 'androidx.cardview:cardview:1.0.0' | |
//Architecture Components |
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
data class Response( | |
@SerializedName("articles") val news: List<News> | |
) | |
data class News( | |
val title: String, | |
@SerializedName("urlToImage") val image: String | |
) |
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
interface NetworkService { | |
@GET("/everything?q=sports&apiKey=aa67d8d98c8e4ad1b4f16dbd5f3be348") | |
fun getNews(@Query("page") page: Int, @Query("pageSize") pageSize: Int): Single<Response> | |
companion object { | |
fun getService(): NetworkService { | |
val retrofit = Retrofit.Builder() | |
.baseUrl("https://newsapi.org/v2/") | |
.addCallAdapterFactory(RxJava2CallAdapterFactory.create()) |
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
enum class State { | |
DONE, LOADING, ERROR | |
} |
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
class NewsDataSource( | |
private val networkService: NetworkService, | |
private val compositeDisposable: CompositeDisposable) | |
: PageKeyedDataSource<Int, News>() { | |
var state: MutableLiveData<State> = MutableLiveData() | |
private var retryCompletable: Completable? = null | |
override fun loadInitial(params: LoadInitialParams<Int>, callback: LoadInitialCallback<Int, News>) { |
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
class NewsDataSourceFactory( | |
private val compositeDisposable: CompositeDisposable, | |
private val networkService: NetworkService) | |
: DataSource.Factory<Int, News>() { | |
val newsDataSourceLiveData = MutableLiveData<NewsDataSource>() | |
override fun create(): DataSource<Int, News> { | |
val newsDataSource = NewsDataSource(networkService, compositeDisposable) | |
newsDataSourceLiveData.postValue(newsDataSource) |
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
class NewsListViewModel : ViewModel() { | |
private val networkService = NetworkService.getService() | |
var newsList: LiveData<PagedList<News>> | |
private val compositeDisposable = CompositeDisposable() | |
private val pageSize = 5 | |
private val newsDataSourceFactory: NewsDataSourceFactory | |
init { | |
newsDataSourceFactory = NewsDataSourceFactory(compositeDisposable, networkService) |
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
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<ProgressBar | |
android:id="@+id/progress_bar" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" |
OlderNewer