Skip to content

Instantly share code, notes, and snippets.

View hitherejoe's full-sized avatar
🏠
Working from home

Joe Birch hitherejoe

🏠
Working from home
View GitHub Profile
@hitherejoe
hitherejoe / MulipartRequest
Created April 9, 2015 10:39
Sending Multipart data using Volley
import android.util.Log;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.HttpHeaderParser;
import com.google.gson.Gson;
#! /bin/bash
path="./current/";
assets="./assets/";
files=( "$path"* )
files=( "${files[@]##*/}" )
for dir in $assets*; do
for file in "$dir"/*; do
filename="${file##*/}"
@hitherejoe
hitherejoe / Build.gradle
Created April 9, 2015 10:43
Android Jacoco setup with Gradle
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug {
versionNameSuffix " Debug"
debuggable true
testCoverageEnabled = true
@hitherejoe
hitherejoe / androidSinglePermission.java
Created July 7, 2015 08:20
Andriod M - Request single permission
private static final int REQUEST_LOCATION = 1503;
private void requestSinglePermission() {
String locationPermission = Manifest.permission.ACCESS_FINE_LOCATION;
int hasPermission = checkSelfPermission(locationPermission);
String[] permissions = new String[] { locationPermission };
if (hasPermission != PackageManager.PERMISSION_GRANTED) {
requestPermissions(permissions, REQUEST_LOCATION);
} else {
// Phew - we already have permission!
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case REQUEST_LOCATION:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
// Handle permission granted
} else {
// Handle permission denied
}
break;
private void requestMultiplePermissions() {
String locationPermission = Manifest.permission.ACCESS_FINE_LOCATION;
String calendarPermission = Manifest.permission.WRITE_CALENDAR;
int hasLocPermission = checkSelfPermission(locationPermission);
int hasCalPermission = checkSelfPermission(calendarPermission);
List<String> permissions = new ArrayList<String>();
if (hasLocPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(locationPermission);
}
if (hasCalPermission != PackageManager.PERMISSION_GRANTED) {
public class PostViewModel extends BaseObservable {
private Context context;
private Post post;
private Boolean isUserPosts;
public PostViewModel(Context context, Post post, boolean isUserPosts) {
this.context = context;
this.post = post;
this.isUserPosts = isUserPosts;
@RunWith(RobolectricTestRunner.class)
@Config(constants = BuildConfig.class, sdk = DefaultConfig.EMULATE_SDK, manifest = DefaultConfig.MANIFEST)
public class PostViewModelTest {
private Context mContext;
private PostViewModel mPostViewModel;
private Post mPost;
@Before
public void setUp() {
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="viewModel" type="com.hitherejoe.mvvm_hackernews.viewModel.PostViewModel" />
</data>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
public class PostAdapter extends RecyclerView.Adapter<PostAdapter.BindingHolder> {
private List<Post> mPosts;
private Context mContext;
private boolean mIsUserPosts;
public PostAdapter(Context context, boolean isUserPosts) {
mContext = context;
mIsUserPosts = isUserPosts;
mPosts = new ArrayList<>();
}