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 PagerAdapter(fragmentManager: FragmentManager) : FragmentStatePagerAdapter(fragmentManager) { | |
// Returns total number of pages | |
override fun getCount(): Int { | |
return NUM_ITEMS | |
} | |
// Returns the fragment to display for that page | |
override fun getItem(position: Int): Fragment? { | |
when (position) { |
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
lambda expressions can’t have a return statement. The return type is either inferred from the variable which stores | |
the lambda or from the last statement of the lambda body. Another missing thing is multiple return points you might | |
often need. | |
// 1 | |
private fun isValidArtist(artist: String?): Boolean { | |
// 2 | |
val artistValidator = fun(value: String?): Boolean { | |
// 3 | |
if (value.isNullOrEmpty()) { |
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
Creating observables | |
create() - Observable.create() | |
just() - Observable.just("first", "second", "third", "fourth", "fifth", "sixth", | |
"seventh", "eighth", "ninth", "tenth") | |
.subscribeOn(Schedulers.io()) // What thread to do the work on | |
.observeOn(AndroidSchedulers.mainThread()) | |
range() - Observable.range(0,11) | |
repeat() - Observable.range(0,3) | |
.repeat(2) |
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 DoubleLiveData<A, B>(a: LiveData<A>, b: LiveData<B>) : MediatorLiveData<Pair<A?, B?>>() { | |
init { | |
addSource(a) { value = it to b.value } | |
addSource(b) { value = a.value to it } | |
} | |
} |
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
//Read data change on your ref | |
exports.functionname = functions.database.ref('/Items/{itemid}') | |
.onWrite(event => { | |
const item = event.data.val(); | |
// read data once from second node | |
const locationRef = event.data.adminRef.root.child('location').child(event.params.itemid); | |
locationRef.once('value').then(snapshot =>{ | |
const location = snapshot.val(); | |
const city = location.city; | |
// data node where you want to write data |
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 Divider extends RecyclerView.ItemDecoration { | |
private Drawable mDivider; | |
private int mOrientation; | |
public Divider(Context context, int orientation) { | |
mDivider = ContextCompat.getDrawable(context, R.drawable.divider); | |
if (orientation != LinearLayoutManager.VERTICAL) { | |
throw new IllegalArgumentException("This Item Decoration can be used only with a RecyclerView that uses a LinearLayoutManager with vertical orientation"); | |
} |
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
async function addInterestedCategories(uid, categories) { | |
await User.findOneAndUpdate({ uid: uid }, | |
{ $addToSet: { interested_categories: categories } }, { new: true}).exec() | |
} | |
exports.getPost = async (req, res, next) => { | |
const postUpdate = await Post.findOneAndUpdate({ postID: req.params.postid | |
, viewedBy: { $not: { $elemMatch: { uid: req.query.uid } } } | |
}, | |
{ $addToSet: { viewedBy: USER }, $inc: { totalViews: 1} }, { new: true }) |
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
private fun setTags(tagList: List<Tag>) { | |
tagList.forEachIndexed { index, tag -> | |
val chipView = getChipView().apply { | |
configureChip(index, tag) | |
} | |
chipView.setOnCheckedChangeListener { chip, isChecked -> | |
//resId is basically a index of a tag in passed tagList |
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"?> | |
<androidx.coordinatorlayout.widget.CoordinatorLayout 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" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" > | |
<com.google.android.material.appbar.AppBarLayout | |
android:id="@+id/user_Profile_appbarlayout" | |
android:layout_width="match_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"?> | |
<shape | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
android:shape="oval"> | |
<solid | |
android:color="@color/colorGreyIcon"/> | |
<size | |
android:width="60dp" |