Last active
March 31, 2017 17:43
-
-
Save danilosilvadev/c74295cd01a5034a608e58e38ce6fd31 to your computer and use it in GitHub Desktop.
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
package gorick.gradesprojectandroid.MVP.Model; | |
import com.google.gson.annotations.Expose; | |
import com.google.gson.annotations.SerializedName; | |
import java.text.DecimalFormat; | |
import lombok.Data; | |
import lombok.NoArgsConstructor; | |
/** | |
* Created by sg-0036936 on 06/03/2017. | |
*/ | |
@Data | |
@NoArgsConstructor | |
public class GradeModel { | |
@SerializedName("grade") | |
@Expose | |
private DecimalFormat grades; | |
private String matter; | |
private int fault; | |
} |
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
package gorick.gradesprojectandroid.MVP.Presenter.Response; | |
import android.util.Log; | |
import java.text.DecimalFormat; | |
import javax.inject.Inject; | |
import gorick.gradesprojectandroid.MVP.Presenter.API.GradeService; | |
import gorick.gradesprojectandroid.MVP.Presenter.MyApplication; | |
import gorick.gradesprojectandroid.MVP.Presenter.Presenters.MainPresenter; | |
import retrofit2.Retrofit; | |
import rx.Observer; | |
import rx.Subscription; | |
import rx.android.schedulers.AndroidSchedulers; | |
import rx.schedulers.Schedulers; | |
import static android.content.ContentValues.TAG; | |
/** | |
* Created by sg-0036936 on 06/03/2017. | |
*/ | |
public class GradeResponse { | |
@Inject | |
Retrofit retrofit; | |
@Inject | |
MainPresenter mainPresenter; | |
public void getGradeRx() { | |
MyApplication.getMainComponent().injectIntoGradeResponse(this);// informando ao dagger sobre o uso de um component e a necessidade de injetar dependência | |
Subscription getGrade = retrofit | |
.create(GradeService.class) | |
.getGrade() | |
.subscribeOn(Schedulers.newThread()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.map(model -> { | |
// transform model | |
DecimalFormat grades = model.getGrades(); | |
return grades; | |
//return new Integer(grades.size()); | |
}) | |
.subscribe(new Observer<DecimalFormat>() { | |
@Override | |
public void onCompleted() { | |
} | |
@Override | |
public void onError(Throwable e) { | |
Log.i(TAG, "saporra vai me matar ainda"); | |
} | |
@Override | |
public void onNext(DecimalFormat grades) { | |
Log.i(TAG, "caralhoooooo " + grades); | |
//mainPresenter.setListGrades(grades); | |
} | |
}); | |
} | |
} |
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
grades: [ | |
{ | |
"class": "math" | |
"grade": 4.5, | |
"next_dates":[ | |
{ | |
"exam": "03/03/2017", | |
"homework": "03/03/2017" | |
} | |
] | |
} | |
{ | |
"class": "port" | |
"grade": 8, | |
"next_dates":[ | |
{ | |
"exam": "03/05/2017", | |
"homework": "03/03/2017" | |
} | |
] | |
} | |
] |
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
package gorick.gradesprojectandroid.MVP.Presenter.API; | |
import gorick.gradesprojectandroid.MVP.Model.GradeModel; | |
import retrofit2.http.GET; | |
import rx.Observable; | |
/** | |
* Created by sg-0036936 on 07/03/2017. | |
* Notas e faltas API | |
*/ | |
public interface GradeService { | |
@GET("grades_json.json") | |
Observable<GradeModel> getGrade(); | |
} |
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
package gorick.gradesprojectandroid.Dagger2.Module; | |
import com.google.gson.FieldNamingPolicy; | |
import com.google.gson.Gson; | |
import com.google.gson.GsonBuilder; | |
import dagger.Module; | |
import dagger.Provides; | |
import gorick.gradesprojectandroid.Dagger2.Scope.PerActivity; | |
import okhttp3.OkHttpClient; | |
import retrofit2.GsonConverterFactory; | |
import retrofit2.Retrofit; | |
import retrofit2.RxJavaCallAdapterFactory; | |
import static gorick.gradesprojectandroid.MVP.Presenter.API.UrlAPI.BASE_URL; | |
/** | |
* Created by sg-0036936 on 06/03/2017. | |
*/ | |
@Module | |
public class RetrofitModule { | |
@Provides | |
@PerActivity | |
Gson provideGson() { | |
GsonBuilder gsonBuilder = new GsonBuilder(); | |
gsonBuilder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES); | |
return gsonBuilder.create(); | |
} | |
@Provides | |
@PerActivity | |
public OkHttpClient provideHttpClient() { | |
return new OkHttpClient().newBuilder().build(); | |
} | |
@Provides | |
@PerActivity | |
public Retrofit provideRetrofit(Gson gson, OkHttpClient okHttpClient) { | |
Retrofit retrofit = new Retrofit.Builder() | |
.addConverterFactory(GsonConverterFactory.create(gson)) | |
.baseUrl(BASE_URL) | |
.client(okHttpClient) | |
//converts Retrofit response into Observable | |
.addCallAdapterFactory(RxJavaCallAdapterFactory.create()) | |
.build(); | |
return retrofit; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment