This commit is contained in:
Javi Rueda 2020-12-13 21:01:44 +01:00
commit d0dd88a17b
7 changed files with 143 additions and 201 deletions

View file

@ -14,8 +14,8 @@ android {
applicationId "io.lbry.browser" applicationId "io.lbry.browser"
minSdkVersion 21 minSdkVersion 21
targetSdkVersion 29 targetSdkVersion 29
versionCode 1610 versionCode 1611
versionName "0.16.10" versionName "0.16.11"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }

View file

@ -46,6 +46,7 @@ import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView; import android.webkit.WebView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -126,6 +127,7 @@ import javax.net.ssl.SSLParameters;
import io.lbry.browser.adapter.NavigationMenuAdapter; import io.lbry.browser.adapter.NavigationMenuAdapter;
import io.lbry.browser.adapter.NotificationListAdapter; import io.lbry.browser.adapter.NotificationListAdapter;
import io.lbry.browser.adapter.StartupStageAdapter;
import io.lbry.browser.adapter.UrlSuggestionListAdapter; import io.lbry.browser.adapter.UrlSuggestionListAdapter;
import io.lbry.browser.data.DatabaseHelper; import io.lbry.browser.data.DatabaseHelper;
import io.lbry.browser.dialog.ContentScopeDialogFragment; import io.lbry.browser.dialog.ContentScopeDialogFragment;
@ -145,6 +147,7 @@ import io.lbry.browser.listener.WalletBalanceListener;
import io.lbry.browser.model.Claim; import io.lbry.browser.model.Claim;
import io.lbry.browser.model.ClaimCacheKey; import io.lbry.browser.model.ClaimCacheKey;
import io.lbry.browser.model.NavMenuItem; import io.lbry.browser.model.NavMenuItem;
import io.lbry.browser.model.StartupStage;
import io.lbry.browser.model.Tag; import io.lbry.browser.model.Tag;
import io.lbry.browser.model.UrlSuggestion; import io.lbry.browser.model.UrlSuggestion;
import io.lbry.browser.model.WalletBalance; import io.lbry.browser.model.WalletBalance;
@ -2662,22 +2665,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
actionBar.show(); actionBar.show();
} }
} }
private void renderStartupFailed(Map<Integer, Boolean> startupStages) { private void renderStartupFailed(List<StartupStage> startupStages) {
Map<Integer, Integer> startupStageIconIds = new HashMap<>(); ListView listView = findViewById(R.id.startup_stage_error_listview);
startupStageIconIds.put(STARTUP_STAGE_INSTALL_ID_LOADED, R.id.startup_stage_icon_install_id); StartupStageAdapter adapter = new StartupStageAdapter(this, startupStages);
startupStageIconIds.put(STARTUP_STAGE_KNOWN_TAGS_LOADED, R.id.startup_stage_icon_known_tags); listView.setAdapter(adapter);
startupStageIconIds.put(STARTUP_STAGE_EXCHANGE_RATE_LOADED, R.id.startup_stage_icon_exchange_rate);
startupStageIconIds.put(STARTUP_STAGE_USER_AUTHENTICATED, R.id.startup_stage_icon_user_authenticated);
startupStageIconIds.put(STARTUP_STAGE_NEW_INSTALL_DONE, R.id.startup_stage_icon_install_new);
startupStageIconIds.put(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, R.id.startup_stage_icon_subscriptions_loaded);
startupStageIconIds.put(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, R.id.startup_stage_icon_subscriptions_resolved);
for (Integer key : startupStages.keySet()) {
boolean stageDone = startupStages.get(key);
ImageView icon = findViewById(startupStageIconIds.get(key));
icon.setImageResource(stageDone ? R.drawable.ic_check : R.drawable.ic_close);
icon.setColorFilter(stageDone ? Color.WHITE : Color.RED);
}
findViewById(R.id.splash_view_loading_container).setVisibility(View.GONE); findViewById(R.id.splash_view_loading_container).setVisibility(View.GONE);
findViewById(R.id.splash_view_error_container).setVisibility(View.VISIBLE); findViewById(R.id.splash_view_error_container).setVisibility(View.VISIBLE);
@ -2690,16 +2681,16 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
// perform some tasks before launching // perform some tasks before launching
(new AsyncTask<Void, Void, Boolean>() { (new AsyncTask<Void, Void, Boolean>() {
private Map<Integer, Boolean> startupStages = new HashMap<>(); private final List<StartupStage> startupStages = new ArrayList<>(7);
private void initStartupStages() { private void initStartupStages() {
startupStages.put(STARTUP_STAGE_INSTALL_ID_LOADED, false); startupStages.add(new StartupStage(STARTUP_STAGE_INSTALL_ID_LOADED, false));
startupStages.put(STARTUP_STAGE_KNOWN_TAGS_LOADED, false); startupStages.add(new StartupStage(STARTUP_STAGE_KNOWN_TAGS_LOADED, false));
startupStages.put(STARTUP_STAGE_EXCHANGE_RATE_LOADED, false); startupStages.add(new StartupStage(STARTUP_STAGE_EXCHANGE_RATE_LOADED, false));
startupStages.put(STARTUP_STAGE_USER_AUTHENTICATED, false); startupStages.add(new StartupStage(STARTUP_STAGE_USER_AUTHENTICATED, false));
startupStages.put(STARTUP_STAGE_NEW_INSTALL_DONE, false); startupStages.add(new StartupStage(STARTUP_STAGE_NEW_INSTALL_DONE, false));
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, false); startupStages.add(new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, false));
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, false); startupStages.add(new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, false));
} }
protected void onPreExecute() { protected void onPreExecute() {
hideActionBar(); hideActionBar();
@ -2719,26 +2710,26 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
String installId = reader.readLine(); String installId = reader.readLine();
if (Helper.isNullOrEmpty(installId)) { if (Helper.isNullOrEmpty(installId)) {
// no install_id found (first run didn't start the sdk successfully?) // no install_id found (first run didn't start the sdk successfully?)
startupStages.put(STARTUP_STAGE_INSTALL_ID_LOADED, false); startupStages.set(STARTUP_STAGE_INSTALL_ID_LOADED - 1, new StartupStage(STARTUP_STAGE_INSTALL_ID_LOADED, false));
return false; return false;
} }
Lbry.INSTALLATION_ID = installId; Lbry.INSTALLATION_ID = installId;
startupStages.put(STARTUP_STAGE_INSTALL_ID_LOADED, true); startupStages.set(STARTUP_STAGE_INSTALL_ID_LOADED - 1, new StartupStage(STARTUP_STAGE_INSTALL_ID_LOADED, true));
SQLiteDatabase db = dbHelper.getReadableDatabase(); SQLiteDatabase db = dbHelper.getReadableDatabase();
List<Tag> fetchedTags = DatabaseHelper.getTags(db); List<Tag> fetchedTags = DatabaseHelper.getTags(db);
Lbry.knownTags = Helper.mergeKnownTags(fetchedTags); Lbry.knownTags = Helper.mergeKnownTags(fetchedTags);
Collections.sort(Lbry.knownTags, new Tag()); Collections.sort(Lbry.knownTags, new Tag());
Lbry.followedTags = Helper.filterFollowedTags(Lbry.knownTags); Lbry.followedTags = Helper.filterFollowedTags(Lbry.knownTags);
startupStages.put(STARTUP_STAGE_KNOWN_TAGS_LOADED, true); startupStages.set(STARTUP_STAGE_KNOWN_TAGS_LOADED - 1, new StartupStage(STARTUP_STAGE_KNOWN_TAGS_LOADED, true));
// load the exchange rate // load the exchange rate
Lbryio.loadExchangeRate(); Lbryio.loadExchangeRate();
if (Lbryio.LBCUSDRate == 0) { if (Lbryio.LBCUSDRate == 0) {
return false; return false;
} }
startupStages.put(STARTUP_STAGE_EXCHANGE_RATE_LOADED, true); startupStages.set(STARTUP_STAGE_EXCHANGE_RATE_LOADED - 1, new StartupStage(STARTUP_STAGE_EXCHANGE_RATE_LOADED, true));
try { try {
Lbryio.authenticate(context); Lbryio.authenticate(context);
@ -2750,10 +2741,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
if (Lbryio.currentUser == null) { if (Lbryio.currentUser == null) {
throw new Exception("Did not retrieve authenticated user."); throw new Exception("Did not retrieve authenticated user.");
} }
startupStages.put(STARTUP_STAGE_USER_AUTHENTICATED, true); startupStages.set(STARTUP_STAGE_USER_AUTHENTICATED - 1, new StartupStage(STARTUP_STAGE_USER_AUTHENTICATED, true));
Lbryio.newInstall(context); Lbryio.newInstall(context);
startupStages.put(STARTUP_STAGE_NEW_INSTALL_DONE, true); startupStages.set(STARTUP_STAGE_NEW_INSTALL_DONE - 1, new StartupStage(STARTUP_STAGE_NEW_INSTALL_DONE, true));
// (light) fetch subscriptions // (light) fetch subscriptions
if (Lbryio.subscriptions.size() == 0) { if (Lbryio.subscriptions.size() == 0) {
@ -2774,7 +2765,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
subUrls.add(url.toString()); subUrls.add(url.toString());
} }
Lbryio.subscriptions = subscriptions; Lbryio.subscriptions = subscriptions;
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true); startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_LOADED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true));
// resolve subscriptions // resolve subscriptions
if (subUrls.size() > 0 && Lbryio.cacheResolvedSubscriptions.size() != Lbryio.subscriptions.size()) { if (subUrls.size() > 0 && Lbryio.cacheResolvedSubscriptions.size() != Lbryio.subscriptions.size()) {
@ -2782,15 +2773,15 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
Lbryio.cacheResolvedSubscriptions = resolvedSubs; Lbryio.cacheResolvedSubscriptions = resolvedSubs;
} }
// if no exceptions occurred here, subscriptions have been loaded and resolved // if no exceptions occurred here, subscriptions have been loaded and resolved
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true); startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true));
} else { } else {
// user has not subscribed to anything // user has not subscribed to anything
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true); startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_LOADED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true));
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true); startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true));
} }
} else { } else {
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true); startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_LOADED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_LOADED, true));
startupStages.put(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true); startupStages.set(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED - 1, new StartupStage(STARTUP_STAGE_SUBSCRIPTIONS_RESOLVED, true));
} }
} catch (Exception ex) { } catch (Exception ex) {
// nopecd // nopecd

View file

@ -0,0 +1,68 @@
package io.lbry.browser.adapter;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import io.lbry.browser.R;
import io.lbry.browser.model.StartupStage;
public class StartupStageAdapter extends BaseAdapter {
private final List<StartupStage> list;
private final LayoutInflater inflater;
private final String[] stagesString;
public StartupStageAdapter(Context ctx, List<StartupStage> rows) {
this.list = rows;
this.inflater = LayoutInflater.from(ctx);
stagesString = new String[7];
stagesString[0] = ctx.getResources().getString(R.string.installation_id_loaded);
stagesString[1] = ctx.getResources().getString(R.string.known_tags_loaded);
stagesString[2] = ctx.getResources().getString(R.string.exchange_rate_loaded);
stagesString[3] = ctx.getResources().getString(R.string.user_authenticated);
stagesString[4] = ctx.getResources().getString(R.string.installation_registered);
stagesString[5] = ctx.getResources().getString(R.string.subscriptions_loaded);
stagesString[6] = ctx.getResources().getString(R.string.subscriptions_resolved);
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@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;
}
}

View file

@ -0,0 +1,11 @@
package io.lbry.browser.model;
public class StartupStage {
public Integer stage;
public Boolean stageDone;
public StartupStage(Integer stage, Boolean stageDone) {
this.stage = stage;
this.stageDone = stageDone;
}
}

View file

@ -130,6 +130,10 @@ public class LoadSharedUserStateTask extends AsyncTask<Void, Void, Boolean> {
} }
protected boolean isNotificationsDisabledForSubUrl(String url, JSONArray following) { protected boolean isNotificationsDisabledForSubUrl(String url, JSONArray following) {
if (following == null) {
return true;
}
try { try {
for (int i = 0; i < following.length(); i++) { for (int i = 0; i < following.length(); i++) {
JSONObject item = following.getJSONObject(i); JSONObject item = following.getJSONObject(i);

View file

@ -156,173 +156,16 @@
android:textColor="@color/white" android:textColor="@color/white"
android:textFontWeight="300" android:textFontWeight="300"
android:textSize="14sp" /> android:textSize="14sp" />
<LinearLayout <ListView
android:id="@+id/startup_stage_error_listview"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:orientation="horizontal"> android:divider="@android:color/transparent"
<ImageView android:dividerHeight="8dp"
android:id="@+id/startup_stage_icon_install_id" tools:listitem="@layout/list_item_startupstage">
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/installation_id_loaded"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout </ListView>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/startup_stage_icon_known_tags"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/known_tags_loaded"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/startup_stage_icon_exchange_rate"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/exchange_rate_loaded"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/startup_stage_icon_user_authenticated"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/user_authenticated"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/startup_stage_icon_install_new"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/installation_registered"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/startup_stage_icon_subscriptions_loaded"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/subscriptions_loaded"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/startup_stage_icon_subscriptions_resolved"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
android:text="@string/subscriptions_resolved"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

View file

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools">
<ImageView
android:id="@+id/startup_stage_icon"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center_vertical"
android:tint="@color/white"
android:src="@drawable/ic_check" />
<TextView
android:id="@+id/startup_stage_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_gravity="center_vertical"
android:fontFamily="@font/inter"
tools:text="@string/installation_id_loaded"
android:textColor="@color/white"
android:textFontWeight="300"
android:textSize="14sp" />
</LinearLayout>