Skip to content

Instantly share code, notes, and snippets.

View rahul-lohra's full-sized avatar
🎯
Focusing

Rahul Kumar Lohra rahul-lohra

🎯
Focusing
View GitHub Profile
@adam-hurwitz
adam-hurwitz / FeedViewModel.kt
Last active September 22, 2022 22:14
Android Model-View-Intent with Kotlin Flow - FeedViewModel.kt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
@ExperimentalCoroutinesApi
class FeedViewModel @AssistedInject constructor(
@mtsahakis
mtsahakis / GridFragment.java
Last active April 25, 2021 22:40
Dynamically set span count in an Android RecyclerView's GridLayoutManager. Implementation is taken from a Fragment.
private RecyclerView mRecyclerView;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_view, container, false);
mRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
// ommiting other recycler view set up, such as adapter and Layout manager set up ..
ViewTreeObserver viewTreeObserver = mRecyclerView.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@jeffjohnson9046
jeffjohnson9046 / git-ignore.sh
Created August 11, 2015 21:02
Remove unwanted files from a git repo AFTER adding a .gitignore. The files will remain on disk.
## I just ran into this after initializing a Visual Studio project _before_ adding a .gitignore file (like an idiot).
## I felt real dumb commiting a bunch of files I didn't need to, so the commands below should do the trick. The first two commands
## came from the second answer on this post: http://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files
# See the unwanted files:
git ls-files -ci --exclude-standard
# Remove the unwanted files:
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
@ferdy182
ferdy182 / CircularRevealingFragment.java
Created March 27, 2015 17:18
Make circular reveal animations on a fragment
/**
* Our demo fragment
*/
public static class CircularRevealingFragment extends Fragment {
OnFragmentTouched listener;
public CircularRevealingFragment() {
}
@skyfishjy
skyfishjy / CursorRecyclerViewAdapter.java
Last active December 16, 2023 08:55
CursorRecyclerViewAdapter
/*
* Copyright (C) 2014 skyfish.jy@gmail.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@marteinn
marteinn / volley-timeout.java
Created July 1, 2014 19:15
Android Volley Samples: Catching a timeout error.
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;
import org.json.JSONObject;
Response.Listener<JSONObject> successListener = new Response.Listener<JSONObject>() {
@tsiege
tsiege / The Technical Interview Cheat Sheet.md
Last active July 28, 2024 15:27
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

ANNOUNCEMENT

I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!






\

@butelo
butelo / callbacks.md
Created January 31, 2014 10:44
Create Callbacks on Android: A Fragment or View makes a Callback to the hosting Activity

Steps to make a Fragment or View to have a Callback to its parent Activity.

Step by step from info taken from here:

http://developer.android.com/guide/components/fragments.html#CommunicatingWithActivity


  • We have an Activity that hosts a Fragment or a View
  • We have a Fragment or View with a ListView or a Button or some element that we want the Activity to know about. i.e. we load detailed info of an element chosen on a ListView or something.
@jdeloach
jdeloach / PathToContentURI.java
Created July 24, 2012 21:22
File Path to Android Content URI, credit to http://stackoverflow.com/a/11603841/1079757. Some modifications to use as an image and more polished this way. Took forever to find. Useful for working with the Android Gallery App
/**
* Returns the Uri which can be used to delete/work with images in the photo gallery.
* @param filePath Path to IMAGE on SD card
* @return Uri in the format of... content://media/external/images/media/[NUMBER]
*/
private Uri getUriFromPath(String filePath) {
long photoId;
Uri photoUri = MediaStore.Images.Media.getContentUri("external");
String[] projection = {MediaStore.Images.ImageColumns._ID};