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
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
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
class NewsListAdapter(private val retry: () -> Unit) | |
: PagedListAdapter<News, RecyclerView.ViewHolder>(NewsDiffCallback) { | |
private val DATA_VIEW_TYPE = 1 | |
private val FOOTER_VIEW_TYPE = 2 | |
private var state = State.LOADING | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | |
return if (viewType == DATA_VIEW_TYPE) NewsViewHolder.create(parent) else ListFooterViewHolder.create(retry, parent) |
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" |
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
abstract class BaseStatefulWidget extends StatefulWidget { | |
String getTitle(); | |
Widget body(AsyncSnapshot snapshot); | |
Future future(); | |
@override | |
State<StatefulWidget> createState() => BaseState(getTitle()); | |
} |
OlderNewer