Skip to content

Instantly share code, notes, and snippets.

View ibrahimsn98's full-sized avatar

İbrahim Süren ibrahimsn98

View GitHub Profile
@ibrahimsn98
ibrahimsn98 / NetworkModule.java
Created July 6, 2018 18:30
android-mvvm-with-dagger-2-module-network
@Module
public class NetworkModule {
private static final String BASE_URL = "https://api.github.com/";
@Provides
static Retrofit provideRetrofit() {
return new Retrofit.Builder().baseUrl(BASE_URL)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
@ibrahimsn98
ibrahimsn98 / ViewModelModule.java
Last active August 19, 2018 15:37
android-mvvm-with-dagger-2
@Singleton
@Module
abstract class ViewModelModule {
@Binds
@IntoMap
@ViewModelKey(ListViewModel.class)
abstract ViewModel bindListViewModel(ListViewModel listViewModel);
@Binds
@ibrahimsn98
ibrahimsn98 / ApplicationComponent.java
Last active August 19, 2018 15:42
android-mvvm-with-dagger-2
@Singleton
@Component(modules = {ContextModule.class, ApplicationModule.class, AndroidSupportInjectionModule.class, ActivityBindingModule.class})
public interface ApplicationComponent extends AndroidInjector<DaggerApplication> {
void inject(BaseApplication application);
@Component.Builder
interface Builder {
@BindsInstance
Builder application(Application application);
@ibrahimsn98
ibrahimsn98 / RepoService.java
Last active August 19, 2018 15:41
android-mvvm-with-dagger-2
public interface RepoService {
@GET("orgs/Google/repos")
Single<List<Repo>> getRepositories();
@GET("repos/{owner}/{name}")
Single<Repo> getRepo(@Path("owner") String owner, @Path("name") String name);
}
@ibrahimsn98
ibrahimsn98 / ListViewModel.java
Last active August 19, 2018 15:41
android-mvvm-with-dagger-2
public class ListViewModel extends ViewModel {
private final RepoRepository repoRepository;
private CompositeDisposable disposable;
private final MutableLiveData<List<Repo>> repos = new MutableLiveData<>();
private final MutableLiveData<Boolean> repoLoadError = new MutableLiveData<>();
private final MutableLiveData<Boolean> loading = new MutableLiveData<>();
@Inject
@ibrahimsn98
ibrahimsn98 / RepoListAdapter.java
Last active August 19, 2018 15:41
android-mvvm-with-dagger-2
public class RepoListAdapter extends RecyclerView.Adapter<RepoListAdapter.RepoViewHolder>{
private RepoSelectedListener repoSelectedListener;
private final List<Repo> data = new ArrayList<>();
RepoListAdapter(ListViewModel viewModel, LifecycleOwner lifecycleOwner, RepoSelectedListener repoSelectedListener) {
this.repoSelectedListener = repoSelectedListener;
viewModel.getRepos().observe(lifecycleOwner, repos -> {
data.clear();
if (repos != null) {
@ibrahimsn98
ibrahimsn98 / ListFragment.java
Last active August 19, 2018 15:40
android-mvvm-with-dagger-2
public class ListFragment extends BaseFragment implements RepoSelectedListener {
@BindView(R.id.recyclerView) RecyclerView listView;
@BindView(R.id.tv_error) TextView errorTextView;
@BindView(R.id.loading_view) View loadingView;
@Inject ViewModelFactory viewModelFactory;
private ListViewModel viewModel;
@Override
@ibrahimsn98
ibrahimsn98 / ViewModelFactory.java
Last active August 19, 2018 15:40
android-mvvm-with-dagger-2
@Singleton
public class ViewModelFactory implements ViewModelProvider.Factory {
private final Map<Class<? extends ViewModel>, Provider<ViewModel>> creators;
@Inject
public ViewModelFactory(Map<Class<? extends ViewModel>, Provider<ViewModel>> creators) {
this.creators = creators;
}
@ibrahimsn98
ibrahimsn98 / django-rest-framework.py
Created August 6, 2018 12:42
django-rest-framework-jwt-get-user-from-token
jwt_decode_handler = api_settings.JWT_DECODE_HANDLER
jwt_get_username_from_payload = api_settings.JWT_PAYLOAD_GET_USERNAME_HANDLER
token = ''
try:
payload = jwt_decode_handler(token)
except jwt.ExpiredSignature:
return
except jwt.DecodeError:
@ibrahimsn98
ibrahimsn98 / gist:8115672b83abcc4b2c3bc7422c03abe6
Created August 6, 2018 16:54
linux-secure-wall-port-allow
sudo /sbin/iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8000 -j ACCEPT