Native rewrite (#878)
* initial native rewrite commit * update gitlab CI script * add printVersionName gradle task * fix Gitlab CI script * Fix first time wallet sync. add Discover dialog to Following page. * Finish Following and All Content views. Add customize your tags view. * Wallet sync get and set preferences, update interval. * Editor's Choice. Reposts. Some ontent page tweaks. * display no related content view when none loaded * Search cache. File view updates. Floating wallet balance. * Send tip dialog. Channel page share and follow/unfollow. * Handle lbry:// url scheme. Properly set URL bar values. SDK 0.71.0. * Channel follow/unfollow fixes. Display stream cost. * Channel management and channel creation / editing * phone number verification and rewards page * add Invites page * tweak player loading and playback when loading new claims * tweak about page layout * display text and markdown content * purchase_uri for free content * don't display invites history if none exist * fix channel list adapters * change launch mode from singleInstance to singleTask * url history and player fixes * Library page. URL and view history. * bumpversion 0.15.0 --> 0.15.1 * Make file view a fragment to prevent headaches with multiple Android task recents * Better handling of file view URLs. Some issue list fixes. * Abandon channels and bulk delete files tasks. Some visual tweaks. * bumpversion 0.15.1 --> 0.15.2 * fix some events * Some visual tweaks. Wunderbar clear focus hotfix for some devices. * sdk 0.74.0. Publish and Publishes pages. * Fix displayed amounts. Send Firebase token with install_new. * Some dark theme and crash fixes. Implement publish form. * Fix minor typo for string in 'generate_address_hint'. * Publish form and publish creation flow. UI tweaks and fixes. * Basic native mobile publishing * remove closeDatabase calls causing crashes * Implement file and channel page delete actions. UI action cleanup. * publish drivers for unresolved file page and featured search result item * show URL suggestions and data network (DHT) settings * Filter own claims from downloads. Fix address input. * fix edit channel crash * fix for possible blank / invalid video thumbnails * adjust minimum deposit. fix channel edit mode. * quick skip and playback speed media controls * change play and pause icons * Fix file size display. Tweak playback speed control. * Add exoplayer mediasession extension. Set player auto attributes. * Inline publish address validation error. Increase image upload request timeout. * fix no related content display * Claim new_android reward. Use canonical_url for share links. * force US locale for amount / bid values sent with sdk requests * Afrikaans and Spanish strings * Add media player error handling policy. Use : in share links. * don't proceed with publish if optimization is in progress.
This commit is contained in:
parent
6eb20d0e08
commit
40c36df414
858 changed files with 39058 additions and 8188 deletions
app/src/main/java/io/lbry/browser/tasks
|
@ -0,0 +1,133 @@
|
|||
package io.lbry.browser.tasks;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.exceptions.LbryUriException;
|
||||
import io.lbry.browser.exceptions.LbryioRequestException;
|
||||
import io.lbry.browser.exceptions.LbryioResponseException;
|
||||
import io.lbry.browser.model.lbryinc.Subscription;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import okhttp3.Response;
|
||||
|
||||
// background task to create a diff of local and remote subscriptions and try to merge
|
||||
public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscription>> {
|
||||
private static final String TAG = "MergeSubscriptionsTask";
|
||||
private Context context;
|
||||
private List<Subscription> base;
|
||||
private List<Subscription> diff;
|
||||
private MergeSubscriptionsHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public MergeSubscriptionsTask(List<Subscription> base, Context context, MergeSubscriptionsHandler handler) {
|
||||
this.base = base;
|
||||
this.context = context;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected List<Subscription> doInBackground(Void... params) {
|
||||
List<Subscription> combined = new ArrayList<>(base);
|
||||
List<Subscription> localSubs = new ArrayList<>();
|
||||
List<Subscription> remoteSubs = new ArrayList<>();
|
||||
diff = new ArrayList<>();
|
||||
SQLiteDatabase db = null;
|
||||
try {
|
||||
// fetch local subscriptions
|
||||
if (context instanceof MainActivity) {
|
||||
db = ((MainActivity) context).getDbHelper().getWritableDatabase();
|
||||
}
|
||||
if (db != null) {
|
||||
localSubs = DatabaseHelper.getSubscriptions(db);
|
||||
for (Subscription sub : localSubs) {
|
||||
if (!combined.contains(sub)) {
|
||||
combined.add(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fetch remote subscriptions
|
||||
JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("subscription", "list", context));
|
||||
if (array != null) {
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
JSONObject item = array.getJSONObject(i);
|
||||
String claimId = item.getString("claim_id");
|
||||
String channelName = item.getString("channel_name");
|
||||
|
||||
LbryUri url = new LbryUri();
|
||||
url.setChannelName(channelName);
|
||||
url.setClaimId(claimId);
|
||||
Subscription subscription = new Subscription(channelName, url.toString());
|
||||
remoteSubs.add(subscription);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < combined.size(); i++) {
|
||||
Subscription local = combined.get(i);
|
||||
if (!remoteSubs.contains(local)) {
|
||||
// add to remote subscriptions
|
||||
try {
|
||||
LbryUri uri = LbryUri.parse(local.getUrl());
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("claim_id", uri.getChannelClaimId());
|
||||
options.put("channel_name", Helper.normalizeChannelName(local.getChannelName()));
|
||||
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context));
|
||||
} catch (LbryUriException | LbryioRequestException | LbryioResponseException ex) {
|
||||
// pass
|
||||
Log.e(TAG, String.format("subscription/new failed: %s", ex.getMessage()), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < localSubs.size(); i++) {
|
||||
Subscription local = localSubs.get(i);
|
||||
if (!base.contains(local) && !diff.contains(local)) {
|
||||
diff.add(local);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < remoteSubs.size(); i++) {
|
||||
Subscription remote = remoteSubs.get(i);
|
||||
if (!combined.contains(remote)) {
|
||||
combined.add(remote);
|
||||
if (!diff.contains(remote)) {
|
||||
diff.add(remote);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException | SQLiteException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
}
|
||||
|
||||
return combined;
|
||||
}
|
||||
protected void onPostExecute(List<Subscription> subscriptions) {
|
||||
if (handler != null) {
|
||||
if (subscriptions != null) {
|
||||
handler.onSuccess(subscriptions, diff);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface MergeSubscriptionsHandler {
|
||||
void onSuccess(List<Subscription> subscriptions, List<Subscription> diff);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue