Search in sources :

Example 1 with Tag

use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.

the class PublishFormFragment method updateSuggestedTags.

private void updateSuggestedTags(String filter, int limit, boolean clearPrevious) {
    UpdateSuggestedTagsTask task = new UpdateSuggestedTagsTask(filter, limit, addedTagsAdapter, suggestedTagsAdapter, clearPrevious, true, new UpdateSuggestedTagsTask.KnownTagsHandler() {

        @Override
        public void onSuccess(List<Tag> tags) {
            if (suggestedTagsAdapter == null) {
                suggestedTagsAdapter = new TagListAdapter(tags, getContext());
                suggestedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
                suggestedTagsAdapter.setClickListener(PublishFormFragment.this);
                if (suggestedTagsList != null) {
                    suggestedTagsList.setAdapter(suggestedTagsAdapter);
                }
            } else {
                suggestedTagsAdapter.setTags(tags);
            }
            checkNoAddedTags();
            checkNoTagResults();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : TagListAdapter(com.odysee.app.adapter.TagListAdapter) UpdateSuggestedTagsTask(com.odysee.app.tasks.UpdateSuggestedTagsTask) Tag(com.odysee.app.model.Tag)

Example 2 with Tag

use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.

the class MainActivity method startup.

@SuppressLint("StaticFieldLeak")
private void startup() {
    final Context context = this;
    Lbry.startupInit();
    // perform some tasks before launching
    (new AsyncTask<Void, Void, Boolean>() {

        private final List<StartupStage> startupStages = new ArrayList<>(7);

        private void initStartupStages() {
            startupStages.add(new StartupStage(STARTUP_STAGE_INSTALL_ID_LOADED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_KNOWN_TAGS_LOADED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_EXCHANGE_RATE_LOADED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_USER_AUTHENTICATED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_NEW_INSTALL_DONE, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_BLOCK_LIST_LOADED, false));
            startupStages.add(new StartupStage(STARTUP_STAGE_FILTER_LIST_LOADED, false));
        }

        protected void onPreExecute() {
            hideActionBar();
            // findViewById(R.id.splash_view).setVisibility(View.VISIBLE);
            LbryAnalytics.setCurrentScreen(MainActivity.this, "Splash", "Splash");
            initStartupStages();
        }

        protected Boolean doInBackground(Void... params) {
            BufferedReader reader = null;
            try {
                // Load the installation id from the file system
                String lbrynetDir = String.format("%s/%s", getAppInternalStorageDir(), "lbrynet");
                String installIdPath = String.format("%s/install_id", lbrynetDir);
                reader = new BufferedReader(new InputStreamReader(new FileInputStream(installIdPath)));
                String installId = reader.readLine();
                if (Helper.isNullOrEmpty(installId)) {
                    // no install_id found (first run didn't start the sdk successfully?)
                    startupStages.set(STARTUP_STAGE_INSTALL_ID_LOADED - 1, new StartupStage(STARTUP_STAGE_INSTALL_ID_LOADED, false));
                    return false;
                }
                Lbry.INSTALLATION_ID = installId;
                startupStages.set(STARTUP_STAGE_INSTALL_ID_LOADED - 1, new StartupStage(STARTUP_STAGE_INSTALL_ID_LOADED, true));
                SQLiteDatabase db = dbHelper.getReadableDatabase();
                List<Tag> fetchedTags = DatabaseHelper.getTags(db);
                Lbry.knownTags = Helper.mergeKnownTags(fetchedTags);
                Collections.sort(Lbry.knownTags, new Tag());
                Lbry.followedTags = Helper.filterFollowedTags(Lbry.knownTags);
                startupStages.set(STARTUP_STAGE_KNOWN_TAGS_LOADED - 1, new StartupStage(STARTUP_STAGE_KNOWN_TAGS_LOADED, true));
                // load the exchange rate
                Lbryio.loadExchangeRate();
                if (Lbryio.LBCUSDRate == 0) {
                    return false;
                }
                startupStages.set(STARTUP_STAGE_EXCHANGE_RATE_LOADED - 1, new StartupStage(STARTUP_STAGE_EXCHANGE_RATE_LOADED, true));
                try {
                    Lbryio.authenticate(context);
                } catch (AuthTokenInvalidatedException ex) {
                    // if this happens, attempt to authenticate again, so that we can obtain a new auth token
                    // this will also result in the user having to sign in again
                    Lbryio.authenticate(context);
                }
                if (Lbryio.currentUser == null) {
                    throw new Exception("Did not retrieve authenticated user.");
                }
                startupStages.set(STARTUP_STAGE_USER_AUTHENTICATED - 1, new StartupStage(STARTUP_STAGE_USER_AUTHENTICATED, true));
                Lbryio.newInstall(context);
                startupStages.set(STARTUP_STAGE_NEW_INSTALL_DONE - 1, new StartupStage(STARTUP_STAGE_NEW_INSTALL_DONE, true));
                startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_LOADED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true));
                startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true));
                JSONObject blockedObject = (JSONObject) Lbryio.parseResponse(Lbryio.call("file", "list_blocked", context));
                JSONArray blockedArray = blockedObject.getJSONArray("outpoints");
                Lbryio.populateOutpointList(Lbryio.blockedOutpoints, blockedArray);
                startupStages.set(STARTUP_STAGE_BLOCK_LIST_LOADED - 1, new StartupStage(STARTUP_STAGE_BLOCK_LIST_LOADED, true));
                JSONObject filteredObject = (JSONObject) Lbryio.parseResponse(Lbryio.call("file", "list_filtered", context));
                JSONArray filteredArray = filteredObject.getJSONArray("outpoints");
                Lbryio.populateOutpointList(Lbryio.filteredOutpoints, filteredArray);
                startupStages.set(STARTUP_STAGE_FILTER_LIST_LOADED - 1, new StartupStage(STARTUP_STAGE_FILTER_LIST_LOADED, true));
            } catch (Exception ex) {
                // nope
                Log.e(TAG, String.format("App startup failed: %s", ex.getMessage()), ex);
                return false;
            } finally {
                Helper.closeCloseable(reader);
            }
            return true;
        }

        protected void onPostExecute(Boolean startupSuccessful) {
            if (!startupSuccessful) {
                // show which startup stage failed
                renderStartupFailed(startupStages);
                appStarted = false;
                return;
            }
            // findViewById(R.id.splash_view).setVisibility(View.GONE);
            showActionBar();
            // loadLastFragment();
            fetchRewards();
            loadRemoteNotifications(false);
            checkUrlIntent(getIntent());
            checkWebSocketClient();
            LbryAnalytics.logEvent(LbryAnalytics.EVENT_APP_LAUNCH);
            appStarted = true;
        }
    }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Context(android.content.Context) InputStreamReader(java.io.InputStreamReader) AsyncTask(android.os.AsyncTask) JSONArray(org.json.JSONArray) SpannableString(android.text.SpannableString) FileInputStream(java.io.FileInputStream) JSONException(org.json.JSONException) LbryUriException(com.odysee.app.exceptions.LbryUriException) ExecutionException(java.util.concurrent.ExecutionException) SQLiteException(android.database.sqlite.SQLiteException) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ApiCallException(com.odysee.app.exceptions.ApiCallException) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) ParseException(java.text.ParseException) StartupStage(com.odysee.app.model.StartupStage) AuthTokenInvalidatedException(com.odysee.app.exceptions.AuthTokenInvalidatedException) JSONObject(org.json.JSONObject) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) Tag(com.odysee.app.model.Tag) SuppressLint(android.annotation.SuppressLint)

Example 3 with Tag

use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.

the class SignInActivity method loadSharedUserStateAndFinish.

private void loadSharedUserStateAndFinish() {
    // load the shared user state after wallet sync is done
    LoadSharedUserStateTask loadTask = new LoadSharedUserStateTask(SignInActivity.this, new LoadSharedUserStateTask.LoadSharedUserStateHandler() {

        @Override
        public void onSuccess(List<Subscription> subscriptions, List<Tag> followedTags, List<LbryUri> blockedChannels) {
            Lbryio.subscriptions = new ArrayList<>(subscriptions);
            Lbryio.blockedChannels = new ArrayList<>(blockedChannels);
            finishSignInActivity();
        }

        @Override
        public void onError(Exception error) {
            // shouldn't happen, but if it does, finish anyway
            finishSignInActivity();
        }
    }, Lbryio.AUTH_TOKEN);
    loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : LoadSharedUserStateTask(com.odysee.app.tasks.wallet.LoadSharedUserStateTask) ArrayList(java.util.ArrayList) Tag(com.odysee.app.model.Tag) Subscription(com.odysee.app.model.lbryinc.Subscription) LbryUri(com.odysee.app.utils.LbryUri) LbryioRequestException(com.odysee.app.exceptions.LbryioRequestException) LbryioResponseException(com.odysee.app.exceptions.LbryioResponseException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with Tag

use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.

the class LoadTagsTask method doInBackground.

protected List<Tag> doInBackground(Void... params) {
    List<Tag> tags = null;
    SQLiteDatabase db = null;
    try {
        if (context instanceof MainActivity) {
            db = ((MainActivity) context).getDbHelper().getReadableDatabase();
            if (db != null) {
                tags = DatabaseHelper.getTags(db);
            }
        }
    } catch (SQLiteException ex) {
        error = ex;
    }
    return tags;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Tag(com.odysee.app.model.Tag) MainActivity(com.odysee.app.MainActivity) SQLiteException(android.database.sqlite.SQLiteException)

Example 5 with Tag

use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.

the class ChannelFormFragment method updateSuggestedTags.

private void updateSuggestedTags(String filter, int limit, boolean clearPrevious) {
    UpdateSuggestedTagsTask task = new UpdateSuggestedTagsTask(filter, limit, addedTagsAdapter, suggestedTagsAdapter, clearPrevious, false, new UpdateSuggestedTagsTask.KnownTagsHandler() {

        @Override
        public void onSuccess(List<Tag> tags) {
            if (suggestedTagsAdapter == null) {
                suggestedTagsAdapter = new TagListAdapter(tags, getContext());
                suggestedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
                suggestedTagsAdapter.setClickListener(ChannelFormFragment.this);
                if (suggestedTagsList != null) {
                    suggestedTagsList.setAdapter(suggestedTagsAdapter);
                }
            } else {
                suggestedTagsAdapter.setTags(tags);
            }
            checkNoAddedTags();
            checkNoTagResults();
        }
    });
    task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : TagListAdapter(com.odysee.app.adapter.TagListAdapter) UpdateSuggestedTagsTask(com.odysee.app.tasks.UpdateSuggestedTagsTask) Tag(com.odysee.app.model.Tag)

Aggregations

Tag (com.odysee.app.model.Tag)14 ArrayList (java.util.ArrayList)5 SQLiteException (android.database.sqlite.SQLiteException)4 MainActivity (com.odysee.app.MainActivity)4 TagListAdapter (com.odysee.app.adapter.TagListAdapter)4 SuppressLint (android.annotation.SuppressLint)3 Context (android.content.Context)3 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)3 ApiCallException (com.odysee.app.exceptions.ApiCallException)3 LbryioRequestException (com.odysee.app.exceptions.LbryioRequestException)3 LbryioResponseException (com.odysee.app.exceptions.LbryioResponseException)3 Subscription (com.odysee.app.model.lbryinc.Subscription)3 UpdateSuggestedTagsTask (com.odysee.app.tasks.UpdateSuggestedTagsTask)3 LbryUri (com.odysee.app.utils.LbryUri)3 JSONException (org.json.JSONException)3 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 AuthTokenInvalidatedException (com.odysee.app.exceptions.AuthTokenInvalidatedException)2