Skip to content

Instantly share code, notes, and snippets.

View FeedFragmentBad.java
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);
View FeedFragment.java
//...
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());
}
}
View CacheEnabledUseCase.java
//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;
View Snippet.java
class Foo {
public void showNotification(String _subText,
String _bigContentTitle,
String _bigText) {
String channelId = "channelId";
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId);
notificationBuilder.setAutoCancel(true);
View NavigationSnippets.swift
protocol ImageDelegate{
func onImageReceived(_ picker: ImagePickerController, didReceiveValue value: UIImage)
func onCancel(_ picker: ImagePickerController)
}
class TakePictureController : UIViewController, ImageDelegate{
func takePicture(){
let imagePicker = ImagePickerController()
imagePicker.delegate = self//self conforms to ImageDelegate protocol
@Marchuck
Marchuck / LoginViewController.swift
Last active Jan 8, 2019
passing data for new screen using prepare for segue
View LoginViewController.swift
class LoginViewController {
var userName: String = "joe@doe.com"
let HOME_SEGUE = "HOME_SEGUE"
let FORGOT_PASSWORD_SEGUE = "FORGOT_PASSWORD_SEGUE"
func startHomeScreen(){
self.performSegue(withIdentifier: HOME_SEGUE, sender: self)
View generate_resized_icons.sh
#!/bin/bash
for i in "${@:3}"
do
echo "generating $i x $i icon..."
sips -z $i $i $1 --out $2_$i.png
done
View item_swapi_person.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="personModel"
type="pl.marchuck.pagingexample.pagination.adapter.SwapiPersonViewModel" />
</data>
<android.support.v7.widget.CardView ...>
View SwapiPersonViewHolder.kt
class SwapiPersonViewHolder(private val binding: ItemSwapiPersonBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(item: Person?) {
binding.personModel = SwapiPersonViewModel(item)
binding.executePendingBindings()
}
}
View SwapiAdapter.kt
class SwapiAdapter(diffCallback: DiffUtil.ItemCallback<Person?>)
: PagedListAdapter<Person, SwapiPersonViewHolder>(diffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SwapiPersonViewHolder {
val inflater = LayoutInflater.from(parent.context)
val binding = DataBindingUtil.inflate<ItemSwapiPersonBinding>(
inflater, R.layout.item_swapi_person, parent, false)
return SwapiPersonViewHolder(binding)
}