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
//offline-first usecase for api requests | |
//one you have to do is to include rxjava to your project, | |
//some Api(could be Retrofit based), | |
//some Preferences(could SharedPreferences based / some database), | |
//some SerializerUtil (could be gson, moshi) | |
import com.google.gson.JsonSyntaxException; | |
import com.google.gson.annotations.SerializedName; | |
import io.reactivex.Observable; | |
import io.reactivex.functions.Consumer; |
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
//... | |
secondFeedAdatper = new SecondFeedAdatper(); | |
secondFeedAdatper.setClickListener(new SecondFeedAdatper.ClickListener() { | |
@Override | |
public void onArticleClick(Article article) { | |
if (article.getLink() != null && !article.getLink().isEmpty()) { | |
if (getActivity() instanceof LockscreenActivity) { | |
((LockscreenActivity) getActivity()).openURL(article.getLink()); | |
} | |
} |
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
Parser parser = new Parser(); | |
parser.execute(UrlConstant.SECOND_FEED_URL); | |
parser.onFinish(new OnTaskCompleted() { | |
@Override | |
public void onTaskCompleted(@NotNull final List<Article> list) { | |
final List<Article> filtered = new ArrayList<>(); | |
for (int i = 0; i < list.size(); i++) { | |
Article article = list.get(i); |
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
fun Fragment.createAlertDialog() = | |
AlertDialog.Builder(ContextThemeWrapper(context, R.style.custom_dialog_style)) | |
data class DialogAction( | |
var text: String, | |
var onClick: (() -> Unit)? = null | |
) |
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
ExampleTest{ | |
@BeforeEach | |
fun setUp() { | |
viewModel = SomeViewModel(...) | |
filtersObserver = viewModel.filtersLiveData.observeEvents() | |
} | |
@Test fun `test 1`(){ | |
val expected = arrayListOf<Any>() |
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
# Built application files | |
*.apk | |
*.ap_ | |
*.aab | |
# Files for the ART/Dalvik VM | |
*.dex | |
# Java class files |
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 MyViewModel @Inject constructor(private val dependency1: Dependency1, | |
private val dependency2: Dependency2, | |
... | |
private val id: Int)//hold on Dagger! I will provide this on my own | |
{ ... } |
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 MyViewModel @Inject constructor(private val dependency1: Dependency1, | |
private val dependency2: Dependency2, | |
...) | |
{ | |
private var id: Int? = null | |
fun setupId(id: Int){ | |
this.id = id | |
} | |
... |
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 SomeFragment: Fragment(){ | |
@Inject factory: AssistedViewModel.Factory | |
override fun onActivityCreated(savedInstanceState: Bundle?){ | |
super.onActivityCreated(savedInstanceState) | |
val viewModel = factory.create(301) | |
... | |
} |