-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
410ed0d
commit 34adfca
Showing
21 changed files
with
367 additions
and
220 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
app/src/main/java/org/nuclearfog/twidda/backend/async/DomainLoader.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package org.nuclearfog.twidda.backend.async; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.nuclearfog.twidda.backend.api.Connection; | ||
import org.nuclearfog.twidda.backend.api.ConnectionException; | ||
import org.nuclearfog.twidda.backend.api.ConnectionManager; | ||
import org.nuclearfog.twidda.model.lists.Domains; | ||
|
||
/** | ||
* Async loader class to load blocked domains | ||
* | ||
* @author nuclearfog | ||
*/ | ||
public class DomainLoader extends AsyncExecutor<DomainLoader.Param, DomainLoader.Result> { | ||
|
||
private Connection connection; | ||
|
||
/** | ||
* | ||
*/ | ||
public DomainLoader(Context context) { | ||
connection = ConnectionManager.getDefaultConnection(context); | ||
} | ||
|
||
|
||
@Override | ||
protected Result doInBackground(@NonNull Param param) { | ||
try { | ||
Domains domains = connection.getDomainBlocks(param.cursor); | ||
return new Result(domains, param.index, null); | ||
} catch (ConnectionException exception) { | ||
return new Result(null, param.index, exception); | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public static class Param { | ||
|
||
public static final long NO_CURSOR = 0L; | ||
|
||
final long cursor; | ||
final int index; | ||
|
||
public Param(long cursor, int index) { | ||
this.cursor = cursor; | ||
this.index = index; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public static class Result { | ||
|
||
public final int index; | ||
@Nullable | ||
public final Domains domains; | ||
@Nullable | ||
public final ConnectionException exception; | ||
|
||
Result(@Nullable Domains domains, int index, @Nullable ConnectionException exception) { | ||
this.domains = domains; | ||
this.index = index; | ||
this.exception = exception; | ||
} | ||
} | ||
} |
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
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
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
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
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
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
Oops, something went wrong.