Skip to content

Instantly share code, notes, and snippets.

👀
Forever coding

Mitch Tabian mitchtabian

View GitHub Profile
@mitchtabian
mitchtabian / AppComponent.java
Created Apr 15, 2019
Old way to make app component
View AppComponent.java
@Component
public interface AppComponent {
void inject(BaseApplication application);
}
View LocationService.java
package com.codingwithmitch.googlemaps2018.services;
import android.Manifest;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
View sendFCM.json
//url
https://fcm.googleapis.com/fcm/send
//headers
Authorization: <Your Server Key>
Content-Type: application/json
//body
{
"to" : "< user FCM token >",
View MainActivity.java
private boolean checkMapServices(){
if(isServicesOK()){
if(isMapsEnabled()){
return true;
}
}
return false;
}
private void buildAlertMessageNoGps() {
View fragment_user_list.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/White">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
@mitchtabian
mitchtabian / AppInjector.java
Last active Apr 6, 2019
Scope example with an @singleton User object and @LoginScope User object
View AppInjector.java
@Override
public void onActivityDestroyed(Activity activity) {
if(activity instanceof LoginActivity){
loginComponent = null;
}
}
private void handleActivity(Activity activity){
if(activity instanceof HasSupportFragmentInjector){
@mitchtabian
mitchtabian / AppComponent.java
Created Apr 5, 2019
Example of making use of the Application context using @Component.Builder in AppComponent class (new way)
View AppComponent.java
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
@Component.Builder
@mitchtabian
mitchtabian / AppComponent.java
Last active Apr 5, 2019
Example of NOT making use of @Component.Builder and @BindsInstance (this is the old way)
View AppComponent.java
@Singleton
@Component(
modules = {
AndroidInjectionModule.class,
AppModule.class,
ActivityBuildersModule.class
})
public interface AppComponent extends AndroidInjector<BaseApplication> {
}
@mitchtabian
mitchtabian / AppComponent.java
Last active Apr 5, 2019
creates the "inject" method automatically with AndroidInjector<Class>
View AppComponent.java
// *** Must specify specific TYPE here. 'BaseApplication', not 'Application'. Since it generates an inject(BaseApplication app); method.
public interface AppComponent extends AndroidInjector<BaseApplication> { // no need for inject method. It's generated.
LoginComponent.Builder newLoginComponentBuilder();
// void inject(BaseApplication application);
@Component.Builder
interface Builder {
View Query.java
@Query("SELECT * FROM recipes WHERE title LIKE '%' || :query || '%' OR ingredients LIKE '%' || :query || '%' " +
"ORDER BY social_rank DESC LIMIT (:pageNumber * 30)")
LiveData<List<Recipe>> searchRecipes(String query, int pageNumber);
You can’t perform that action at this time.