Skip to content

Commit

Permalink
Started task yamblz-native#2
Browse files Browse the repository at this point in the history
  • Loading branch information
aleien committed Jul 31, 2016
1 parent ba18683 commit fd1c4f1
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
3 changes: 2 additions & 1 deletion app/src/main/java/ru/yandex/yamblz/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ru.yandex.yamblz.developer_settings.DeveloperSettingsModel;
import ru.yandex.yamblz.handler.CriticalSectionsManager;
import ru.yandex.yamblz.loader.CollageLoaderManager;
import ru.yandex.yamblz.loader.ParallelCollageLoader;
import timber.log.Timber;

public class App extends Application {
Expand All @@ -34,7 +35,7 @@ public void onCreate() {
devMetricsProxy.apply();
}

CollageLoaderManager.init(null); // add implementation
CollageLoaderManager.init(new ParallelCollageLoader());
CriticalSectionsManager.init(null); // add implementation
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package ru.yandex.yamblz.handler;

/**
* Created by aleien on 31.07.16.
*/

public class DisableScrollLoadingHandler implements CriticalSectionsHandler {
@Override
public void startSection(int id) {

}

@Override
public void stopSection(int id) {

}

@Override
public void stopSections() {

}

@Override
public void postLowPriorityTask(Task task) {

}

@Override
public void postLowPriorityTaskDelayed(Task task, int delay) {

}

@Override
public void removeLowPriorityTask(Task task) {

}

@Override
public void removeLowPriorityTasks() {

}
}
12 changes: 12 additions & 0 deletions app/src/main/java/ru/yandex/yamblz/handler/LoadingTask.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package ru.yandex.yamblz.handler;

/**
* Created by aleien on 31.07.16.
*/

public class LoadingTask implements Task {
@Override
public void run() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.WeakHashMap;
Expand All @@ -22,10 +27,9 @@ public class ParallelCollageLoader implements CollageLoader {
private WeakHashMap<ImageView, Subscription> subscriptionTargets = new WeakHashMap<>();
private CompositeSubscription subs = new CompositeSubscription();
private CollageStrategy collageStrategy = new SimpleCollageStrategy();
private Context context;

public ParallelCollageLoader(Context context) {
this.context = context.getApplicationContext();
public ParallelCollageLoader() {

}

@Override
Expand Down Expand Up @@ -75,18 +79,16 @@ public void loadCollage(List<String> urls, ImageTarget imageTarget, CollageStrat

private List<Observable<Bitmap>> loadBitmaps(List<String> urls) {
List<Observable<Bitmap>> observables = new ArrayList<>();
for (String url : urls) {
for (String urlString : urls) {
observables.add(Observable.create(subscriber -> {
try {
Bitmap bitmap = Glide.with(context)
.load(url)
.asBitmap()
.into(100, 100)
.get();
URL url = new URL(urlString);
InputStream is = url.openConnection().getInputStream();
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();
subscriber.onNext(bitmap);
subscriber.onCompleted();

} catch (InterruptedException | ExecutionException e) {
} catch (IOException e) {
e.printStackTrace();
subscriber.onError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
presenter = new ArtistsLoadingPresenter(artistsApi);
presenter.bindView(this);
presenter.loadArtists();

CollageLoaderManager.init(new ParallelCollageLoader(getContext()));
}

@NonNull
Expand Down

0 comments on commit fd1c4f1

Please sign in to comment.