-
Notifications
You must be signed in to change notification settings - Fork 20
(@gringauz.a) Александр Грингауз #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
grin3s
wants to merge
9
commits into
yamblz-native:master
Choose a base branch
from
grin3s:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e96a94a
dummy recycler
alexandergringauz 6d0255a
genre list formed shown
alexandergringauz 1cea699
one image per genre loaded asyncronously
alexandergringauz 69f5c82
PowerOfTwoCollageStrategy
alexandergringauz fcdefbb
cache added and deadlock fixed
alexandergringauz 1d3b4b5
cache refactor
alexandergringauz da0dc52
critical sections work, images are not loaded while scrolling
alexandergringauz c7e42b7
finished critical sections
alexandergringauz 37594a4
exit crash fixed
alexandergringauz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
93 changes: 93 additions & 0 deletions
93
app/src/main/java/ru/yandex/yamblz/handler/CriticalSectionsHandlerImpl.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| package ru.yandex.yamblz.handler; | ||
|
|
||
| import android.os.Handler; | ||
| import android.os.HandlerThread; | ||
|
|
||
| import java.util.HashSet; | ||
|
|
||
| import java.util.LinkedList; | ||
| import java.util.Queue; | ||
|
|
||
|
|
||
| public class CriticalSectionsHandlerImpl implements CriticalSectionsHandler { | ||
|
|
||
| private HashSet<Integer> sectionsSet = new HashSet<>(); | ||
| private HashSet<Task> tasksInQueue = new HashSet<>(); | ||
| private Queue<Task> lowPriorityTasksQueue = new LinkedList<>(); | ||
|
|
||
| private Handler mainThreadHandler; | ||
| private Handler waitingHandler; | ||
|
|
||
| public CriticalSectionsHandlerImpl(Handler mainThreadHandler) { | ||
| this.mainThreadHandler = mainThreadHandler; | ||
| HandlerThread waitingThread = new HandlerThread("waiting"); | ||
| waitingThread.start(); | ||
| waitingHandler = new Handler(waitingThread.getLooper()); | ||
| } | ||
|
|
||
| @Override | ||
| public void startSection(int id) { | ||
| sectionsSet.add(id); | ||
| } | ||
|
|
||
| @Override | ||
| public void stopSection(int id) { | ||
| sectionsSet.remove(id); | ||
| postQueuedTasks(); | ||
| } | ||
|
|
||
| @Override | ||
| public void stopSections() { | ||
| sectionsSet.clear(); | ||
| postQueuedTasks(); | ||
| } | ||
|
|
||
| @Override | ||
| public void postLowPriorityTask(Task task) { | ||
| if (isInSection()) { | ||
| lowPriorityTasksQueue.add(task); | ||
| tasksInQueue.add(task); | ||
| } | ||
| else { | ||
| mainThreadHandler.post(task::run); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void postLowPriorityTaskDelayed(Task task, int delay) { | ||
| waitingHandler.postDelayed(() -> { | ||
| if (isInSection()) { | ||
| lowPriorityTasksQueue.add(task); | ||
| } | ||
| else { | ||
| mainThreadHandler.post(task::run); | ||
| } | ||
| }, delay); | ||
| tasksInQueue.add(task); | ||
| } | ||
|
|
||
| @Override | ||
| public void removeLowPriorityTask(Task task) { | ||
| tasksInQueue.remove(task); | ||
| } | ||
|
|
||
| @Override | ||
| public void removeLowPriorityTasks() { | ||
| tasksInQueue.clear(); | ||
| lowPriorityTasksQueue.clear(); | ||
| } | ||
|
|
||
| boolean isInSection() { | ||
| return sectionsSet.size() > 0; | ||
| } | ||
|
|
||
| void postQueuedTasks() { | ||
| while (!lowPriorityTasksQueue.isEmpty()) { | ||
| Task task = lowPriorityTasksQueue.remove(); | ||
| if (tasksInQueue.contains(task)) { | ||
| tasksInQueue.remove(task); | ||
| mainThreadHandler.post(task::run); | ||
| } | ||
| } | ||
| } | ||
| } |
17 changes: 0 additions & 17 deletions
17
app/src/main/java/ru/yandex/yamblz/handler/CriticalSectionsManager.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
app/src/main/java/ru/yandex/yamblz/handler/StubCriticalSectionsHandler.java
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package ru.yandex.yamblz.images; | ||
|
|
||
| import android.graphics.Bitmap; | ||
| import android.support.v4.util.LruCache; | ||
|
|
||
| /** | ||
| * Created by grin3s on 07.08.16. | ||
| */ | ||
|
|
||
| public class ImageCache extends LruCache<String, Bitmap> { | ||
| /** | ||
| * @param maxSize for caches that do not override {@link #sizeOf}, this is | ||
| * the maximum number of entries in the cache. For all other caches, | ||
| * this is the maximum sum of the sizes of the entries in this cache. | ||
| */ | ||
| public ImageCache(int maxSize) { | ||
| super(maxSize); | ||
| } | ||
|
|
||
| @Override | ||
| protected int sizeOf(String key, Bitmap bitmap) { | ||
| return bitmap.getByteCount() / 1024; | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/ru/yandex/yamblz/images/ImageDownloadTask.java
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package ru.yandex.yamblz.images; | ||
|
|
||
| import android.graphics.Bitmap; | ||
| import android.graphics.BitmapFactory; | ||
|
|
||
| import java.io.BufferedInputStream; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.net.URL; | ||
| import java.util.concurrent.Callable; | ||
|
|
||
| /** | ||
| * Created by grin3s on 06.08.16. | ||
| */ | ||
|
|
||
| public class ImageDownloadTask implements Callable<Bitmap> { | ||
| String url; | ||
|
|
||
| public ImageDownloadTask(String url) { | ||
| this.url = url; | ||
| } | ||
|
|
||
| @Override | ||
| public Bitmap call() throws Exception { | ||
| try { | ||
| URL url = new URL(this.url); | ||
| InputStream inputStream = new BufferedInputStream(url.openStream()); | ||
| Bitmap bitmap = BitmapFactory.decodeStream(inputStream); | ||
| return bitmap; | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package ru.yandex.yamblz.loader; | ||
|
|
||
| /** | ||
| * Created by grin3s on 07.08.16. | ||
| */ | ||
|
|
||
| // and interface describing a general class that loads something in the background | ||
| public interface AsyncLoader { | ||
| } | ||
This file contains hidden or 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
17 changes: 0 additions & 17 deletions
17
app/src/main/java/ru/yandex/yamblz/loader/CollageLoaderManager.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не понял зачем это добавилось и CollageLoader стало нужно быть классом. Для реализации этого интерфейса ты забрал попытку наследовать класс)