Skip to content

Instantly share code, notes, and snippets.

Avatar

Yonatan Levin parahall

View GitHub Profile
View CDataStream.kt
class CDataStream<T>(
private val taskRunner: ITaskRunner
) : IDataStream<T> {
private val channel = BroadcastChannel<T>(Channel.CONFLATED)
private var value: T? = null
override fun observe(observer: (T) -> Unit): IObservationManager {
val subscription = channel.openSubscription()
this.value?.let(observer)
View MainActivity.java
public class MainActivity extends AppCompatActivity implements MainActivityView {
@BindView(R.id.lv_am_movie_list) ListView listView;
@BindView(R.id.pb_am_loading) ProgressBar progressBar;
public static MainPresenter mainPresenter;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View AppModule.java
@Module public class AppModule {
private Application application;
public AppModule(Application application) {
this.application = application;
}
@Provides @Singleton Context providesAppContext() {
return application.getApplicationContext();
@parahall
parahall / NewOrderPresenter.java
Last active Mar 9, 2019
NewOrderPresenter.java
View NewOrderPresenter.java
public class NewOrderPresenter extends BasePresenter<NewOrderView> {
//...
private int insertOrder(Order order) {
//turn order to ContentValues object (used by SQL to insert values to Table)
ContentValues values = order.createLocalOrder(order);
//call resolver to insert data to the Order table
Uri uri = context.getContentResolver().insert(KolGeneContract.OrderEntry.CONTENT_URI, values);
//get Id for order.
if (uri != null) {
@parahall
parahall / LeakSlackUploadService.java
Created Mar 19, 2016
Sending Leak Traces to a Slack Channel using Retrofit2
View LeakSlackUploadService.java
import com.squareup.leakcanary.AnalysisResult;
import com.squareup.leakcanary.DisplayLeakService;
import com.squareup.leakcanary.HeapDump;
import android.util.Log;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
@parahall
parahall / BackgroundService.java
Created Feb 25, 2017
BackgroundService.java
View BackgroundService.java
public class BackgroundService extends Service {
@Override public int onStartCommand(Intent intent, int i, int i1) {
if (observer == null) {
observer = new OrdersObserver(new Handler());
getContext().getContentResolver()
.registerContentObserver(KolGeneContract.OrderEntry.CONTENT_URI, true, observer);
}
}
@parahall
parahall / SendOrderService.java
Created Feb 25, 2017
SendOrderService.java
View SendOrderService.java
public class SendOrderService extends IntentService {
@Override protected void onHandleIntent(Intent intent) {
int orderId = intent.getIntExtra(ORDER_ID, 0);
if (orderId == 0 || orderId == -1) {
return;
}
Cursor c = null;
try {
@parahall
parahall / SyncOrderService.java
Created Feb 25, 2017
SyncOrderService.java
View SyncOrderService.java
public class SyncOrderService extends GcmTaskService {
//...
public static void scheduleOrderSending(Context context, int id) {
GcmNetworkManager manager = GcmNetworkManager.getInstance(context);
Bundle bundle = new Bundle();
bundle.putInt(SyncOrderService.ORDER_ID, id);
OneoffTask task = new OneoffTask.Builder().setService(SyncOrderService.class)
.setTag(SyncOrderService.getTaskTag(id))
.setExecutionWindow(0L, 30L)
.setExtras(bundle)
View MainViewModel.java
public class MainViewModel extends AndroidViewModel {
private LiveData<List<StarWarsMovie>> moviesLiveData;
@Inject AppDatabase mDb;
public MainViewModel(Application application) {
super(application);
((StarWarsApplication) getApplication()).getAppComponent().inject(this);
requestDataUpdates();
View StarWarsService.java
public class StarWarsService extends IntentService {
@Inject AppDatabase db;
public StarWarsService() {
super("StarWarsService");
}
@Override public void onCreate() {
super.onCreate();
You can’t perform that action at this time.