forked from ImangazalievM/ReActiveAndroid
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Commit to Local Forked Version of master Branch of ReactiveAndroid
Added API Fuctionality for Transactions & Pagination with sample activites (and subsequent adapters, layouts, menus, values, manifest) within reactiveandroid\sample-app For review by repository owner
- Loading branch information
Showing
17 changed files
with
1,689 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
reactiveandroid/src/main/java/com/reactiveandroid/query/api/Pagination.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,65 @@ | ||
package com.reactiveandroid.query.api; | ||
|
||
//pull request - bendothall | ||
//Pagination API | ||
|
||
import android.util.Log; | ||
|
||
import com.reactiveandroid.query.QueryBase; | ||
import com.reactiveandroid.query.Select; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Pagination<T> extends QueryBase<T> { | ||
|
||
private Pagination() { | ||
super(null, null); | ||
} | ||
|
||
public static int getTableRowCount(Class<?> table) { | ||
|
||
if (table == null) { | ||
throw new IllegalArgumentException("Database Table referenced not found."); | ||
} | ||
|
||
return Select.from(table).count(); | ||
} | ||
|
||
|
||
public static List loadPaginationData( | ||
String tableColumn, | ||
int offset, | ||
int limit, | ||
String orderBy, | ||
Class<?> table | ||
){ | ||
|
||
if (tableColumn == null) { | ||
throw new IllegalArgumentException("Database Table must be set"); | ||
} | ||
|
||
if (limit == 0) { | ||
throw new IllegalArgumentException("Limit cannot be set to 0"); | ||
} | ||
|
||
if (orderBy == null || !(orderBy.contains("DESC") || orderBy.contains("ASC")) ) { | ||
throw new IllegalArgumentException("Order must be set to DESC or ASC " + orderBy); | ||
} | ||
|
||
if (table == null) { | ||
throw new IllegalArgumentException("Database Table Class referenced not found."); | ||
} | ||
|
||
List result = new ArrayList<>(); | ||
result = Select.from(table) | ||
.orderBy(tableColumn + " " + orderBy) | ||
.limit(limit) | ||
.offset(offset) | ||
.fetch(); | ||
|
||
return result; | ||
} | ||
|
||
|
||
} |
27 changes: 27 additions & 0 deletions
27
reactiveandroid/src/main/java/com/reactiveandroid/query/api/Transactions.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,27 @@ | ||
package com.reactiveandroid.query.api; | ||
|
||
import com.reactiveandroid.ReActiveAndroid; | ||
|
||
public final class Transactions { | ||
|
||
public static void BeginTransactions(Class<?> databaseClass) { | ||
|
||
if (databaseClass == null) { | ||
throw new IllegalArgumentException("Database Class referenced not found."); | ||
} | ||
|
||
ReActiveAndroid.getDatabase(databaseClass).beginTransaction(); | ||
|
||
} | ||
|
||
public static void EndTransactions(Class<?> databaseClass) { | ||
|
||
if (databaseClass == null) { | ||
throw new IllegalArgumentException("Database Class referenced not found."); | ||
} | ||
|
||
ReActiveAndroid.getDatabase(databaseClass).getWritableDatabase().setTransactionSuccessful(); | ||
ReActiveAndroid.getDatabase(databaseClass).endTransaction(); | ||
} | ||
|
||
} |
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.