use of com.odysee.app.model.StartupStage 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);
}
use of com.odysee.app.model.StartupStage in project odysee-android by OdyseeTeam.
the class StartupStageAdapter method getView.
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = inflater.inflate(R.layout.list_item_startupstage, viewGroup, false);
ImageView iconView = view.findViewById(R.id.startup_stage_icon);
TextView textView = view.findViewById(R.id.startup_stage_text);
StartupStage item = (StartupStage) getItem(i);
iconView.setImageResource(item.stageDone ? R.drawable.ic_check : R.drawable.ic_close);
iconView.setColorFilter(item.stageDone ? Color.WHITE : Color.RED);
textView.setText(stagesString[item.stage - 1]);
}
return view;
}
Aggregations